> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ntop.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to run a topology optimization

## Objective:

Learn how to run a topology optimization.

## Procedure:

## **What is Topology Optimization?**

Topology Optimization (TopOpt) is a numerical design operation that determines the optimal shape of a part based on a set of performance objectives and constraints. This lets you generate optimized, lightweight designs that meet specific engineering requirements.

This guide walks through the complete workflow for designing a lightweight bracket with minimum structural compliance (maximizing stiffness)

## **What You'll Learn**

* [How do you prepare a CAD part and FE mesh for TopOpt?](#h-01k1gheyr35fzzeezetra6xq46)
* [How to set up a simulation model with boundary conditions.](#h-01k1gheph7wy473g3k0mf6ndvn)
* [How to define TopOpt objectives and constraints.](#h-01k1ghsrp3w30z33kpg1kep47q)
* [How to run the optimization and interpret the results.](#h-01k1ghw04p5wccxkknv9b701sn)
* [How do we post-process the results into a final part?](#h-01k1ghyyerv0y8dcfavr5f6haj)

![A diagram showing an imported part, how the part looks after running it through a Topology Optimization simulation, and the Final Part after the Topology Optimization simulation and post processing.](https://files.learn.ntop.com/help-articles/optimization/360060726373.png)

### **Step 1: Prepare the Design Space and Material**

*

First, we need to define the maximum possible volume for our part, known as the **Design Space**. TopOpt works by removing material, so starting with a part with excess material to work with is essential.

1. Import your starting CAD part. In this example, we use a rectangular block with three holes.
2. Create variables from the CAD geometry. This makes them easy to reference later.
   * **Design Space:** The entire CAD Body.
   * **Restrained Faces:** The faces of the two outer holes.
   * **Loaded Face:** The face of the center hole.
   * **Interfaces:** All three hole features will be kept in the final design.
3. Define the material properties. For this bracket, we'll use an **Isotropic Elastic Property** with a Young's modulus of `2.1e+11 Pa` and a Poisson's Ratio of `0.33`.

### **Step 2: Create the Simulation Model**

Follow [this article](/help-articles/knowledge-base/meshing-workflows/how-to-create-an-fe-volume-mesh) to create an FE Volume Mesh from the Design Space.

* Create an **FE Volume Mesh** from the **Design Space** CAD part. An `3 mm` edge length with a Geometric Order of `Linear` is suitable for this example.
* Create a **Simulation Model** using the **FE Volume Mesh** and the **Material** defined in the previous step.

Follow [this article](/help-articles/knowledge-base/structures/how-to-create-a-simulation-model) to create a Simulation Model using the Material and FE Mesh from the steps above.

![An example simulation model setup in nTop and the resulting body.](https://files.learn.ntop.com/help-articles/optimization/41634567518483.png)

### **Step 3: Define Boundary Conditions**

Use [this article](/help-articles/knowledge-base/structures/how-to-use-boundary-conditions) for reference when creating Boundary Conditions.

In this example, we want a Force acting on the middle face and a Displacement Restraint acting on the two outer faces.

**Displacement Restraint:**

* Add a **Displacement Restraint** block
  * Input the **Restrained Faces**as the *Boundary* input

**Force:**

* Add a **Force** block
  * Input the **Loaded Face** as the *Boundary* input
  * Set the *Vector* to (0, 1000, 0) N

### **Step 4: Set Up and Run the Topology Optimization**

Now we can define the rules for the optimization.

#### **Define the Objective**

The objective is what property, or 'design response,' we hope to minimize or maximize within our part. nTop supports several design responses, including structural compliance, volume fraction, displacement, and stress. Use the **Optimization Objective** block to specify the design response(s). In this example, the objective is to minimize structural compliance.

* Add a **Structural Compliance Response** block
  * Insert the **Displacement Restraint** and the **Force** block from the last step
* Add an **Optimization Objective** block
  * Set the goal to Minimize
  * Insert the **Structural Compliance Response** into the Design Response List

![Two nTop blocks are shown in the image. A Structural Compliance Response block that contains two Boundary Conditions. The second block is an Optimization Objective block with the Structural Compliance Response populated in its Responses input.](https://files.learn.ntop.com/help-articles/optimization/41634553876755.png)

#### **Define the Constraint**

Topology optimization also requires the user to provide constraints. An under-constrained TopOpt process will simply fill in or remove all volume from the design region because those results lead to minimization or maximization of the design response. Therefore, TopOpt procedures must be properly constrained in order to achieve meaningful results.

The most commonly used constraint simply applies a minimum or maximum bound to a design response, such as compliance, volume fraction, displacement, or stress.

This TopOpt example is constrained such that the volume fraction of the final part is less than 0.2. In other words, the resulting optimized part will have a targeted volume of 20% of the whole design space. Notice that the volume fraction cutoff in the **Design Response Constraint** block is made into a variable for easy adjustment.

* Add an **Optimization Constraint List** block
  * Insert a **Design Response Constraint** block
    * Insert a **Volume Fraction Response** block into the Response input
    * Set the value to 0.2
      * Optional: Right-click on the Value input to create a variable to quickly change the Volume Fraction

![A volume fraction scalar variable with the value set to 0.2. The variable has been inserted into the value input of a Design Response Constraint block.](https://files.learn.ntop.com/help-articles/optimization/41634553887251.png)

#### **Run the Optimization**

* Add a **Topology Optimization** block,
  * Insert the Simulation Model, Objective, and Constraints

The rest of the inputs can be left as default for this example. More information on these settings can be found in the block's information panel and in [this article](/help-articles/knowledge-base/optimization/understanding-the-optimization-settings). After completion of TopOpt processing, a window pops up in the Viewport with several options for visualizing the results.

![A Topology Optimization block with the resulting body shown next to it after running the simulation.](https://files.learn.ntop.com/help-articles/optimization/41634567544211.png)

The TopOpt process works by assigning a value between 0 and 1 to all of the mesh elements. Higher values are assigned to elements that most effectively contribute to the optimization objective. These values are referred to as the TopOpt density.

For example, an element in the bottom corner of the design space, far away from the applied load, is given a density value close to 0 because placing material here does not contribute to the goal of minimizing structural compliance. On the other hand, elements close to the loaded center hole are given a density value close to 1 because having material there is necessary to support the load.

The **Thresholded Elements** option in the TopOpt viewing window lets the user see what density values have been assigned to all elements in the design space. Use the **Threshold** slider to only view elements with a value higher than the specified threshold.

![A gif showing the Topology Optimization result. The gif shows how the body changes as the Threshold slider value is adjusted. The HUD view option is set to Thresholded elements.](https://files.learn.ntop.com/help-articles/optimization/360060530293.png)

The **Iso-contour** view shows a single surface interpolated from all elements with TopOpt density values close to the specified threshold.

![A gif showing the Topology Optimization result. The gif shows how the body changes as the Threshold slider value is adjusted. The HUD view option is set to Iso-contour.](https://files.learn.ntop.com/help-articles/optimization/360059626074.png)

The **Iteration** slider allows you to see the evolution of the TopOpt throughout the optimization iterations.

![A gif showing the Topology Optimization result. The gif shows how the body changes as the Iteration slider value is adjusted. The HUD view option is set to Iso-contour elements.](https://files.learn.ntop.com/help-articles/optimization/360059626254.png)

### **Step 5: Post-Process the Results into a Final Part**

Once you have inspected your TopOpt results and found an acceptable threshold value, we can convert them into an Implicit Body.

**Convert to an Implicit Body:**

* Add an **Implicit Body from Topology Optimization Results** block
  * Input the **Topology Optimization** block
  * Set the Threshold value to 0.5 (it may be different depending on your preference)

**Smooth the Raw Output:**

The raw TopOpt output has artifacts on its surface from the mesh that can be removed using the **Smoothen Body** block. The surface artifacts are roughly the size of the FE mesh size, so to capture and remove them, a smoothing grid size of half the mesh size is used in the **Smoothen Body** block. This is done using a **Divide** block.

* Add a **Smoothen Body** block.
  * A good **Grid Size** for smoothing is half the FE mesh edge length. Use a **Divide** block with the mesh edge length (`3 mm`) as Operand A and `2` as Operand B.

![The resulting Topology Optimization body is converted to an implicit body. A Smoothen Body block is used to smoothen the result. This body is shown next to the notebook blocks.](https://files.learn.ntop.com/help-articles/optimization/360104618953.png)

#### **Consolidate the Part**

The topology-optimized volume is now ready to be recombined with the interfaces of the original CAD geometry. This step will look different depending on your part. If you are following along, do this:

* Add an **Implicit Body from CAD Body** block
  * Insert the Interfaces (all three CAD faces from Step 1)
* Add a **Thicken Body** block
  * Insert the **Implicit Body from CAD Body** block
  * Set the Thickness to 2 mm
* Add a **Boolean Union** block
  * Delete the auto-generated list and input the **Thicken Body** block

![The CAD Faces of the 3 holes from the original CAD part, are converted to implicit bodies. A Thicken Body block is used to thicken the walls. A Boolean Union block is used to merge them into a single implicit body.](https://files.learn.ntop.com/help-articles/optimization/360104619433.png)

* Add a **Boolean Union** block
  * Input the Smoothened TopOpt and the Interface Bodies
  * Set the Blend radius to 2 mm (to keep the transitions between bodies congruent)

![Using a Boolean Union block to combine the 3 hole implicit body with the Smoothened Implicit Body result of the Topology Optimization.](https://files.learn.ntop.com/help-articles/optimization/1500003561062.png)

Finally, use a **Boolean Intersect** to trim any excess material. Intersect the result from the previous step with an **Implicit Body from CAD Body** of the original **Design Space**.

* Add a Boolean Intersect block
  * Input the TopOpt and Interfaces boolean union
  * Input an Implicit Body from CAD Body block
    * Input the Design Space

![Using a Boolean Intersect block to remove unwanted material and create the final part.](https://files.learn.ntop.com/help-articles/optimization/360102442254.png)

And that's it! You've successfully performed a Topology Optimization.

Are you still having issues? Contact the [support team](https://support.ntopology.com/hc/en-us/requests/new), and we'll be happy to help!

## Download the Example file:

* [Example File](https://files.learn.ntop.com/Support%20Article%20Example%20Files/Knowledge%20Base/Optimization/topology_optimization_example.ntop)

## Keywords:

*mesh boundary body topopt smoothen how to design fe topology model optimization objective constraint condition threshold space process HUD penalty post iso contour*
