## COMSOL Blog

# How to Use Topology Optimization Results as Model Geometries

February 1, 2017

by Hanna GothällTopology optimization can be a useful step in your design process, but the generated designs often require further analysis. With the COMSOL Multiphysics® software, you can create geometries out of your topology optimization result plots and easily export them to CAD software. In this blog post, we discuss how to do so, using both 2D and 3D examples.

### Using Topology Optimization Results in the Design Workflow

Topology optimization is a useful capability because it can help us find designs that we would not have reasonably been able to think of ourselves. When developing a design, however, this is only the first step. It may not be reasonable or possible to construct a particular design found through topology optimization, either because the design is too costly to produce or it is simply not possible to manufacture.

*Topology optimization results for an MBB beam.*

To address these concerns, we can come up with new designs that are based on the results of topology optimization, and then carry out further simulation analyses on them. But how do we do this? As it turns out, COMSOL Multiphysics makes it simple to create geometries from the 2D and 3D plots of your topology optimization results, which you can continue to work with directly in COMSOL Multiphysics or export to a wide range of CAD software platforms.

### Creating a Geometry from 2D Topology Optimization Results

To view topology optimization results that are in 2D, we can create a contour plot. Let’s use the Minimizing the Flow Velocity in a Microchannel tutorial to demonstrate this process. The goal of the tutorial is to find an optimal distribution of a porous filling material to minimize the horizontal flow velocity in the center of a microchannel.

First, we open up the model file included in the tutorial and go to the *Contour 1* plot feature under the *Velocity (spf)* plot group.

*The horizontal velocity (surface plot) and velocity field (streamlines) after optimization. The black contours represent the filling material.*

In the above plot, the black contour is where the design variable, \gamma, equals 0.5. This indicates the border between the open channel and filling material. This is the result that we would like to incorporate into the geometry. In other applications, the expression and exact level to plot may differ, but the principle is the same: to find a contour that describes the limit between the solid and nonsolid materials (typically a fluid of some kind).

To create a geometry from this contour plot, we right-click the *Contour* feature node and choose *Add Plot Data to Export*. We need to make sure that we choose the data format as *Sectionwise* before we export the file.

The *Sectionwise* format describes the exported data using one section with coordinates, one with the element connectivity, and another that includes the data columns. It is important to note that the middle section, which describes how the coordinates of the first section are connected, will allow a contour plot with several closed loops or open curves.

The *Spreadsheet* export format is not suited for this particular use for several reasons, most importantly because it will assume that all coordinates are connected one after the other. This means that if there is more than one isolated contour, it will not be possible to build the *Interpolation Curve* feature. Also, the coordinates are scrambled, so the curve in the next step (discussed below) will not be drawn in the same way as seen in the contour plot.

To create the new geometry, we choose *Add Component* from the *Home* toolbar and choose a new *2D Component*. Then, we copy the geometry feature nodes from the original geometry and paste them to the geometry sequence of the new 2D component. After this, we add an *Interpolation Curve* from the *More Primitives* menu on the *Geometry* toolbar and set the type as *Open Curve*, data format as *Sectionwise*, and a tolerance of 2e-2.

A smaller tolerance will give a curve that is more true to the data, but the outcome might be an intricate or “wiggly” geometry. In turn, a higher tolerance may give a curve that is too simplified and quite far from the optimized result.

*Geometry with the interpolation curves representing the results of the topology optimization.*

The geometry can now be used to run further simulations and to verify the created geometry within COMSOL Multiphysics.

#### Exporting 2D Geometries to CAD Software

The DXF format is a 2D format that most CAD software platforms can read. DXF also describes the higher-order polygons between the points, so it usually gives a better representation than exporting only the points.

To export the optimized topology from this geometry to a DXF file, we can follow the steps below. Please note that there is an optional step for if you only want to include the shape of the optimized topology in your DXF file.

- Add a
*Union*from the*Booleans and Partitions*menu on the*Geometry*toolbar - Include all of the objects
- Use a
*Delete Entities*feature to remove the unwanted domains (optional) - Click the
*Export*button on the*Geometry*toolbar to write to the DXF format for a 2D geometry

Now, let’s see what to do when working with topology optimization results that are in 3D.

### How to Generate a Geometry of 3D Topology Optimization Results in COMSOL Multiphysics®

After performing a topology optimization in 3D, we usually view the resulting shape by creating a plot of the design variable; for example, an isosurface plot. We can directly export such a plot to a format that is compatible with COMSOL Multiphysics and CAD software and can even be used directly for 3D printing. This file format is the STL format, where the surfaces from the results plot are saved as a collection of triangles. It is a common standard file format for 3D printing and 3D scans in general.

In COMSOL Multiphysics, it is possible to export an STL file from the following plot features:

*Volume**Isosurface**Surface**Slice**Multislice**Far Field*

The software also supports adding a *Deformation* node on the plot feature, in case we want to export a deformed plot. The volume and isosurface plots are the most commonly used plot types for topology optimization, so we will focus our discussion on these two options.

To create an isosurface plot, we first add a 3D plot group to which we add an *Isosurface* feature node. In the *Expression* field, we then enter the design variable name, set the entry method as *Levels*, and fill in an appropriate value of the design variable representing the interface between the solid and nonsolid materials.

To demonstrate this process, let’s look at the example of the bridge shown below, where the optimal material distribution takes the familiar shape of an arch bridge. The optimization algorithm is maximizing the stiffness of the bridge subjected to a load to reach the displayed solution. To obtain the displayed isosurface plot, we use the expression 0.1 for the level of the design variable.

*An isosurface plot of the 3D topology optimization for a deck arch bridge.*

As you can see in the screenshot above, isosurface plots are not necessarily capped or airtight, so an exported volume plot may be a better choice, especially if we want to run further simulation analyses in COMSOL Multiphysics.

We can create a suitable plot by adding a *Volume* feature node to a 3D plot group. Then, we add a *Filter* node under *Volume* and set a suitable expression for inclusion. In this example, we use the expression rho_design > 0.1.

*A volume plot of the deck arch bridge.*

#### Exporting Plot Data in the STL Format

Exporting the data into an appropriate file format is simple. We right-click the *Volume* or *Isosurface* feature node and select *Add Plot Data to Export*. In the settings window of the resulting *Plot* node, we then select *STL Binary File (*.stl)* or *STL Text File (*.stl)* from the *Data format* drop-down list.

The exported STL file is readily readable by most CAD software platforms. To continue with the simulation of the geometry, import the STL file to a new COMSOL Multiphysics model, a process that we discuss in a previous blog post.

### Summary on Creating Geometries from Topology Optimization Results

If you want to compare actual CAD drawings with your optimized results, you need to export the data in a format that can be imported into the CAD software you are using. The DXF format (for 2D) and the STL format (for 3D) are widely used formats and should be possible to import in almost any software platform.

In this blog post, we have discussed the steps needed to export topology optimization results in the DXF and STL formats. This will enable you to more efficiently analyze your model geometries within COMSOL Multiphysics and CAD software.

### Further Resources

- Learn more about topology optimization and exporting geometries on the COMSOL Blog:

##### Trevor Munroe

February 1, 2017For Topology Optimization of the 3-D bridge, would the Level Set Method produce more well defined or delineated boundaries?

##### Hanna Gothäll

February 22, 2017Hi Trevor, Thanks for your comment. It would, in principle, be possible to use the Level-Set method to get smoother boundaries, but this is not tested. In case you come up with some results, please feel free to leave a follow-up comment.

##### Ed Bervoets

February 22, 2017Hi Hanna, thanks for the good explanation.

I tried to export the optimised geometry to STL as described above on a volume node with filter rho_design > 0.1. I get the correct optimised geometry alright in my plot window, but if I export it to STL, the whole design domain gets stored (which is just a solid block) and not the optimised geometry.

Did I miss something somewhere? Maybe you could explain step by step how it is done and post the optimised STL?

Thanks in advance!

##### Hanna Gothäll

February 23, 2017Hi Ed, I’m glad that the blog post comes in handy! Please send the mph file to COMSOL Support so that we can assist you with your particular application.

## Comments (4)