When performing laboratory experiments, you rely on the precision and accuracy of the — often used — measurement equipment. While plenty of information is available in the equipment specifications, it usually applies to new, well-calibrated systems. However, you might forget to calibrate your devices, or the system shows a systematic bias due to wear and other processes.

If you have a data set exhibiting such errors, it is important to correct them so that you can analyze the measured data accurately. An applied example is an experiment of flow through a column, where you inject a chemical and record the breakthrough curve at the outlet. For further analysis, the set flow rate of the pump is used. However, due to calcification, the flow rates are systematically biased. Performing a multiparameter optimization with various flow rates enables you to obtain a factor to correct all of the data.

This optimization problem is based on a transient model using the COMSOL Multiphysics® software and *Transport of Diluted Species* interface. A complete model is a prerequisite for the optimization step. The model discussed here is set in 1D and has a geometry with a column that is 1 m in length.

For the transport properties, you can set the flow velocity, which is simply the flow rate multiplied by the opening width of the column. Further, you can assign *Inflow* and *Outflow* boundary conditions and a *Dirichlet* boundary condition at the inlet, set to a fixed concentration.

*Setting up the physical problem prior to the optimization.*

While the true velocity of the problem is unknown, you can rewrite it as the product `u_in*tuning`

. Here, `u_in`

represents the set flow rate and tuning of the global correction factor, which derives directly from ` u_in=Q/(A*tuning)`

. Hence, tuning accounts for the area change of the system.

In optimization jargon, `u_in`

is the experimental parameter identifying the individual experimental runs. The obtained concentration is our least-squares objective, which is compared to measured data, and tuning is the control variable.

Starting with the complete physical model, you can add two items to transform it into an optimization model. First, the *Optimization* interface in our example has two nodes: *Objective* and *Control Variable*. For any optimization study, these nodes are a prerequisite.

While there are many feasible optimization objectives, the least-squares objective is well defined and from the shape `Sum_i(u_obs_i-u_sim_i)`

. Hence, it minimizes the sum of the distances between all given data points.^{ 2}

Due to the strict formal approach, there is no need to express the objective function. However, you need a data file that contains all information needed for a least-squares objective. It is important to note that the data file needs to be structured in columns. You can assign the individual columns in the subnodes.

Note that the order of nodes in the Model Builder tree (from top to bottom) corresponds to the order of columns in the data file (from left to right). It is also important that every column of the data file is identified by an appropriate subnode.

*Assign the nodes in the least-squares objective (top down) to the semicolon-separated columns (left to right) in the data file.*

The transport optimization example requires four columns:

In the example, you set the identifier `u_in`

in the parameter column. This is the flow rate of the pump used to discriminate between the different experiments as well as the same parameter that is assigned under *Global Definitions* > *Parameters*. You can also find this parameter used for the transport properties in the *Transport of Diluted Species* interface.

The times stated in the data file need to be in SI units, seconds. However, in general, these times don’t need to match the stored output times accurately. Nevertheless, good accuracy is still recommended.

In the value column, you give the expression, which is evaluated from the numerical model outcome. This should be entered in the way that it represents the exact metric of the recorded data. *Variable Name* refers to the measured data, which can be accessed during postprocessing by using such a name.

The stated coordinate in the file is the destination where measurements are made. There is also one specialty that must be considered: The number of coordinate columns in the data file must be the same as the dimension of the geometry, even when the selected *Least-Squares Objective* feature is on a lower dimension. In that case, model expressions are evaluated at the nearest points on the given selection.

Here, you make two adjustments by setting the method to the well-known Levenberg-Marquardt algorithm, designed to tackle least-square problems efficiently. Since the goal is to perform a multiparameter study, you can switch the least-squares time/parameter method to: *From least squares objective*. The other settings can be left as default for now.

The correct time-stepping and parameter sweeps are recognized directly from the data file and there is no need to set it individually in the *Step 1: Time dependent* settings. Eventually, using such settings, the solver can sum up all squared deviations for all time steps and parameters, as well as search and minimize such sums by finding a global correction factor that is appropriate for all individual experiments.

*Settings of the Optimization study step.*

With all of these settings, you have a very generic model that can be applied to many experimental runs by updating only the underlying data file. The settings automatically adjust the model to the experimental parameters. So far, this includes variations of the amount of experimental parameters’ recorded sample times.

Such models could be easily extended to consider more parameter variations; e.g., variations of input concentration or more measurement locations in an analog manner. Further steps could be used to transform a model into an application, where you can freely choose the length of the column, hence the geometry. This way, you end up with a powerful tool to evaluate your experiments and assure their quality.

*Results for a multiparameter fit based on three individual measurements (symbols) with the simulated and optimized output (lines).*

- Try a liquid chromatography tutorial model:
- Read this related blog post:

The idea behind natural selection is based on the fact that there is a great deal of variation in the world; even organisms of the same species differ from one another. The organisms with traits best suited for their environment are more likely to survive and pass those traits on to the next generation, which increases the occurrence of the beneficial traits in future generations. As a result, each successive generation becomes more adapted to their environment. That’s natural selection, in a nutshell.

*Over time, natural selection can result in the perpetuation of beneficial traits in a set of organisms, such as long necks in giraffes.*

Genetic algorithms take the principles of natural selection and apply them to optimization problems. They study a set of “individuals” in an environment that has known values and characteristics. The studied population of individuals represents potential solutions to the problem. Appropriate mathematical functions define the fitness of each individual by representing how well adapted they are to the environment.

As with natural selection, using genetic algorithms is an iterative process, with the individuals in each “generation” potentially experiencing mutations and exchanging design characteristics. The process continues until the algorithms find an optimized solution for the particular environment or reach a maximum number of generations.

A research group from Universidad Autónoma de San Luis Potosí and Instituto Tecnológico de San Luis Potosí used genetic algorithms to improve the geometry of an optical antenna (nanoantenna). They wanted a design that optimally concentrates the electromagnetic field of a dipole nanoantenna at a 500-THz resonance frequency, which is a variable that depends on the dimensions of the nanostructure.

As an additional point of study, the team investigated if conventional RF macroscopic antenna geometries can be efficiently used for nanoscale optical frequency regimes. Here’s what they found out…

In their research, the team used LiveLink™ *for* MATLAB® to seamlessly link the MATLAB® software and the COMSOL® software. In doing so, they were able to use MATLAB® software to automatically drive their COMSOL Multiphysics® simulations. Using MATLAB® software, the researchers designed a user interface and genetic algorithm. The genetic algorithm was programmed with the Global Optimization Toolbox, available as an add-on to the MATLAB® software. The algorithm performed analyses to suggest various iterative design changes for the dipole nanoantenna geometry in 2D. These genetic algorithm results were then compared with the optimal conditions to evaluate their fit.

*The lines show how mutations modify the antenna geometry during the genetic algorithm process. Image by R. Diaz de Leon-Zapata, G. Gonzalez, A.G. Rodríguez, E. Flores-García, and F.J. Gonzalez and taken from their COMSOL Conference 2016 Boston paper.*

Whenever the algorithm yielded a design possibility, the researchers could automatically solve the electromagnetic equations, generate antenna response data for a given frequency, and evaluate the fitness function without having to interact with the graphical user interface in COMSOL Multiphysics. The optimized fitness function determined the minimum loss of the electromagnetic field at a frequency of 500 THz. These findings were then used in MATLAB® software to perform further genetic algorithm adjustments. This entire iterative loop was performed automatically, increasing the efficiency of the study.

*The trend toward a minimized electromagnetic field loss for each new generation. Image by R. Diaz de Leon-Zapata et al. and taken from their COMSOL Conference 2016 Boston paper.*

The automatic process continued until the software reached convergent results for an improved antenna geometry. Using this procedure, the researchers obtained their final results at a lower computational cost and a shorter processing time than traditional analytical processes.

*The final antenna geometry attained from genetic algorithm optimization. Image by R. Diaz de Leon-Zapata et al. and taken from their COMSOL Conference 2016 Boston paper.*

Let’s take a closer look at the final design of the nanoantenna. The final design iteration (below, to the right) is quite different from the design of a conventional dipole antenna (below, to the left). The final design is the most fit in this case, since it has the lowest electromagnetic field loss at the center of the structure.

*Comparison of the electromagnetic field concentrations for a classical dipole antenna (left), the first design iteration from the genetic algorithm (middle), and the final geometry (right). Image by R. Diaz de Leon-Zapata et al. and taken from their COMSOL Conference 2016 Boston paper.*

To visualize this in a different way, the research group plotted the electromagnetic field concentration for a conventional dipole antenna and the finalized geometry over a range of frequencies. The comparison shows that while both geometries encompass the same effective area, the version created using the genetic algorithm represents an optimal concentration. Compared with previous studies, the final design also has an increased electromagnetic signal and bandwidth.

*Comparison of the electromagnetic field concentration for a classical dipole geometry (red) and the geometry generated from the genetic algorithm (blue). Image by R. Diaz de Leon-Zapata et al. and taken from their COMSOL Conference 2016 Boston paper.*

Using these findings, the researchers concluded that the genetic algorithm can enhance the maximum electromagnetic field concentration in the optical frequency regime. The team’s next step is to use the results of this analysis to study nanostructure fabrication and characterization, which could help foster the creation of renewable energy devices.

- Read the research team’s original work: “Genetic Algorithm for Geometry Optimization of Optical Antennas“
- Watch this 18-minute video to learn about using LiveLink™
*for*MATLAB® - Read a blog post to get an introduction to designing antennas in COMSOL Multiphysics

*MATLAB is a registered trademark of The MathWorks, Inc.*

Pipelines are an economic approach to transporting fluids like oil, natural gas, and water across land and sea, though they are expensive to build. These structures are comprised of steel or plastic tubes that are typically buried or run at the bottom of the sea, with pump stations distributed throughout the system to keep the fluid moving.

As a petroleum mixture is pumped through a pipeline, it generates heat as a result of internal friction forces. The origin of this heat is the energy supplied by the pump. This heat is quickly dissipated if the pipeline runs through cold environments. Eventually, the temperature of the mixture reaches the same temperature as that of the environment, if the pipeline is not insulated. At lower temperatures, oil becomes more viscous, which increases the energy consumption of the pumps. On top of that, cold petroleum mixtures require preheating before they can be used in the refinery. The preheating process consumes energy and requires investment to build and maintain.

*Pipelines are used to transport fluids throughout the world.*

It is an easy and obvious thing to insulate a pipeline to avoid the decrease in temperature of the oil by keeping the energy supplied by the pumps inside the pipe. The trick is to insulate the pipeline well enough, but not more, so that the return on investment motivates the cost of the insulation. If the petroleum mixture temperature can be kept at a high enough level, the cost of the preheating process can be eliminated and the pump’s energy consumption can be reduced substantially. The reduction of theses costs have to motivate the investment in insulation.

The fluid flow and heat transfer processes in the pipeline can be modeled and simulated accurately using the COMSOL Multiphysics® software. The models can be used to design an insulation that is as inexpensive as possible, yet as efficient as required to keep the oil at the desired temperature.

Our Insulation of a Pipeline Section tutorial model features a 150-km pipeline section that has an inlet temperature of 25°C. The oil that enters the pipeline flows at a rate of 2500 m^{3}/h. To set up and solve the energy and flow equations that describe the transport of the fluid within the pipeline, we use the *Nonisothermal Pipe Flow* interface.

This particular case involves analyzing one pipe wall and one insulation layer, as highlighted in the schematic below. Here, the dark and light gray layers represent a two-layered wall, while light blue represents the film resistances on the inside and outside of the walls. Note that the pipe wall is 2 cm thick in this example.

*Schematic of the pipeline cross section, where h _{int} and h_{ext} are the film heat transfer coefficients inside and outside of the tube and k_{ins} and k_{wall} are the thermal conductivity of the insulation and the wall, respectively.*

In the first study, we calculate the temperature along the pipeline for two different cases: one where perfect insulation is assumed and one where the pipeline has no insulation. The plot below shows that the heat resulting from friction forces in the fluid causes its temperature to increase by about 3°C over 150 km. When no insulation is added to the pipeline, the outlet temperature is similar to that of the surroundings.

*Plot comparing the fluid temperature when there is perfect insulation on the pipeline (green) and when there is no insulation (blue).*

With an understanding of the fluid flow and heat transfer processes, we can perform optimization calculations to identify the minimum insulation thickness required to keep the oil temperature at a constant level throughout the pipeline. The results from this particular optimization study indicate that the minimum insulation thickness is around 8.9 cm. We could also perform a similar optimization study, but for a minimum acceptable oil temperature level at the end of the pipeline, which could potentially reduce the insulation thickness (and the cost) even more.

Based on the calculated minimum thickness for the insulation, we may estimate the investment costs and decide if these costs are motivated by the reduced pumping and preheating costs. We can potentially reduce energy consumption in the pumping process and eliminate it for preheating, making the process more efficient and environmentally friendly.

]]>

Let’s suppose that we are tasked with designing a coil such that the magnetic field along part of the centerline is as close to a target value as possible. As we saw in an earlier blog post, we can achieve this by adjusting the current through each turn of the coil to be different. However, this requires that we include a separate current control for each turn in our physical design. Instead, we can use a single current control for the entire coil and adjust the physical spacing of the coils along the axial direction.

*A ten-turn axisymmetric coil. The objective is to alter the magnetic field at the centerline (green).*

The case that we will consider here is shown in the image above. A ten-turn axisymmetric coil is driven by a single current source; that is, the same current flows through each turn. The initial coil design spaces the 1-cm-diameter coil turns a distance of *S _{0}* = 4 cm apart. Since the coil is axisymmetric (and we are only interested in solutions that are symmetric about the

*The computational model. We want to change the five coil positions and the coil current.*

Our optimization objective is to get the *B _{z}* field as close as possible to a desired value,

More formally, these statements can be written as:

\begin{aligned}

& \underset{I, \Delta Z_1, \ldots ,\Delta Z_5}{\text{minimize:}}

& & \frac{1}{L_0} \int_0^{L_0} \left( \frac{B_z}{B_0} -1 \right) ^2 d l \\

& \text{subject to:}

& & -(S_0-G_0)/2 \le \Delta Z_1 \leq \Delta Z_{max}\\

& & & -\Delta Z_{max} \leq \Delta Z_2, \ldots ,\Delta Z_5 \leq \Delta Z_{max}\\

& & & G_0 \le (Z_5-Z_4) \\

& & & G_0 \le (Z_4-Z_3) \\

& & & G_0 \le (Z_3-Z_2) \\

& & & G_0 \le (Z_2-Z_1) \\

& & & 0 \leq I \leq I_{max}\\

\end{aligned}

& \underset{I, \Delta Z_1, \ldots ,\Delta Z_5}{\text{minimize:}}

& & \frac{1}{L_0} \int_0^{L_0} \left( \frac{B_z}{B_0} -1 \right) ^2 d l \\

& \text{subject to:}

& & -(S_0-G_0)/2 \le \Delta Z_1 \leq \Delta Z_{max}\\

& & & -\Delta Z_{max} \leq \Delta Z_2, \ldots ,\Delta Z_5 \leq \Delta Z_{max}\\

& & & G_0 \le (Z_5-Z_4) \\

& & & G_0 \le (Z_4-Z_3) \\

& & & G_0 \le (Z_3-Z_2) \\

& & & G_0 \le (Z_2-Z_1) \\

& & & 0 \leq I \leq I_{max}\\

\end{aligned}

We solve this problem with a combination of parameter and shape optimization by using the *Optimization* and *Deformed Geometry* interfaces in COMSOL Multiphysics.

We can begin our implementation by reviewing the model developed here, which optimizes for a particular field value. We start with the same *Optimization* interface and *Integral Objective* feature introduced in the previous blog post. Two *Global Control Variable* features are then used. The first sets up the displacements of the five coils, using *Control Variables Scaling* to scale the optimization variables close to unity. The second *Global Control Variables* feature similarly defines and constrains the current.

*The definitions of the variables that control the five coils’ positions.*

The five *Control Variables* shown in the screenshot above define the displacements of the coils, as well as a small square region of space around each coil, which is shown as the green domains in the illustration below. As these green domains move up and down, the surrounding yellow domains must stretch and shrink to accommodate, while the surrounding blue domain is fixed. Since we know the displacements of the green domains, we can specify a linear variation of displacement along all of the red edges. This linear displacement variation is computed using a *Coefficient Form Boundary PDE* interface, as described in an earlier blog post on modeling translational motion.

*The definitions of the deformations for the various domains in the model.*

This information about the specified displacements of the various domains is set up using the *Deformed Geometry* interface, as shown in the screenshot below. The *Prescribed Deformation* domain features move the green domains and the yellow domains are allowed to deform due to the *Free Deformation* domains. The *Prescribed Mesh Displacement* boundary features apply to the black and red edges and completely define the deformations of the yellow domains.

*The control over the coil turn displacement via the Prescribed Deformation feature in the* Deformed Geometry *interface.*

As a consequence of setting up the *Deformed Geometry* interface in this way, the five control variables for the positions of the coils now represent a shape optimization problem. Previously, we have discussed shape optimization in a more general case from structural mechanics. Shape optimization takes advantage of the ability of COMSOL Multiphysics to compute design sensitivities with respect to changes in the shape of the geometry.

We also need to define a set of *Global Inequality Constraints* to prevent the green domains surrounding the coils from getting too close to each other and intersecting. The screenshot below shows this implementation. Note that the constraint is scaled with respect to the gap size *G _{0}* so that the constraint equation is also close to one in magnitude.

*One of the four constraints that keep the coils from getting too close to each other.*

Due to the large deformations that can occur in the domains around the coils that stretch and contract, it is also helpful to use a mapped mesh.

*A mapped mesh is used in the deforming domains around the coils. The infinite element domain also has a mapped mesh.*

We can then solve this problem using a gradient-based optimization solver (SNOPT), taking advantage of the analytically computed gradients. The current through the coil and the coil positions are adjusted to minimize the above objective function. The results of the optimization are shown in the figure below.

*The magnetic flux density’s* z*-component along the centerline for the optimized coil.*

*The optimized coil positions.*

We have introduced a model that uses a combination of shape and parameter optimization to adjust the coil current and spacing between the coils in a 2D axisymmetric coil. By taking advantage of the *Optimization* and *Deformed Geometry* interfaces, we are able to analytically compute the derivatives for this problem and converge to an optimum very quickly.

- Read a blog post on modeling a linear electromagnetic plunger
- Browse the Optimization category on the COMSOL Blog

The problem we will look at today is the optimization of a ten-turn axisymmetric coil structure, as shown in the image below. Each of the five turns on either side of the *xy*-plane is symmetrically but independently driven.

*A ten-turn coil with five independently driven coil pairs. The objective is to alter the magnetic field at the centerline (green highlight).*

The coil is both rotationally symmetric and symmetric about the *z* = 0 plane, so we can reduce the computational model to a 2D axisymmetric model, as shown in the schematic below. Our modeling domain is truncated with an *infinite element* domain. We use the Perfect Magnetic Conductor boundary condition to exploit symmetry about the *z* = 0 plane. Thus, our model reduces to a quarter-circle domain with five independent coils that are modeled using the *Coil Domain* feature.

*A schematic of the computational model.*

If all of the coils are driven with the same current of 10 A, we can plot the *z*-component of the magnetic flux density along the centerline, as shown in the image below. It is this field distribution along a part of the centerline that we want to change via optimization.

*The magnetic field distribution along the coil centerline. We want to adjust the magnetic field within the optimization zone.*

From the image above, we see the magnetic field along a portion of the centerline due to a current of 10 A through each coil. It is this field distribution that we want to change by adjusting the current flowing through the coils. Our design variables are the five unique coil currents: . These design variables have bounds: . That is, the current cannot be too great in magnitude, otherwise the coils will overheat.

We will look at three different optimization problem statements:

- To have the magnetic field at the centerline be as close to a desired target value as possible
- To minimize the power needed to drive the coil, along with a constraint on the field minimum at several points
- To minimize the gradient of the magnetic field along the centerline, along with a constraint on the field at one point

Let’s state these optimization problems a bit more formally. The first optimization problem can be written as:

\begin{aligned}

& \underset{I_1, \ldots ,I_5}{\text{minimize:}}

& & \frac{1}{L_0} \int_0^{L_0} \left( \frac{B_z}{B_0} -1 \right) ^2 d l \\

& \text{subject to:}

& & -I_{max} \leq I_1, \ldots ,I_5 \leq I_{max}\\

\end{aligned}

& \underset{I_1, \ldots ,I_5}{\text{minimize:}}

& & \frac{1}{L_0} \int_0^{L_0} \left( \frac{B_z}{B_0} -1 \right) ^2 d l \\

& \text{subject to:}

& & -I_{max} \leq I_1, \ldots ,I_5 \leq I_{max}\\

\end{aligned}

The objective here is to minimize the difference between the computed *B _{z}*-field and the desired field,

Now, let’s look at the implementation of this problem within COMSOL Multiphysics. We begin by adding an *Optimization* interface to our model, which contains two features. The first feature is the *Global Control Variables*, as shown in the screenshot below. We can see that five control variables are set up: `I1,...,I5`

. These variables are used to specify the current flowing through the five *Coil* features in the *Magnetic Fields* interface.

The *Initial Value*, *Upper Bound*, and *Lower Bound* to these variables are also specified by two *Global Parameters*, `I_init`

and ` I_max`

. Also note that the *Scale factor* is set such that the optimization variables also have a magnitude close to one. We will use this same setup for the control variables in all three examples.

*Setting up the Global Control Variables feature, which specifies the coil currents.*

Next, the objective function is defined via the *Integral Objective* feature over a boundary, as shown in the screenshot below. Note that the *Multiply by 2πr* option is toggled off.

*The implementation of the objective function to achieve a desired field along one boundary.*

We include an *Optimization* step in the Study, as shown in the screenshot below. Since our objective function can be analytically differentiated with respect to the design variables, we can use the SNOPT solver. This solver takes advantage of the analytically computed gradient and solves the optimization problem in a few seconds. All of the other solver settings can be left at their defaults.

*The Optimization study step.*

After solving, we can plot the fields and results. The figure below shows that the *B _{z}*-field matches the target value very well.

*Results of optimizing for a target value of magnetic flux along the centerline.*

Our second optimization problem is to minimize the total power needed to drive the coil and to include a constraint on the field minimum at several points along the centerline. This can be expressed as:

\begin{aligned}

& \underset{I_1, \ldots ,I_5}{\text{minimize:}}

& & \frac{1}{P_o}\sum_{k=1}^{5} P_{coil}^k \\

& \text{subject to:}

& & -I_{max} \leq I_1, \ldots ,I_5 \leq I_{max}\\

& & & 1 \le B_z^i/B_{0}, i=1, \ldots, M

\end{aligned}

& \underset{I_1, \ldots ,I_5}{\text{minimize:}}

& & \frac{1}{P_o}\sum_{k=1}^{5} P_{coil}^k \\

& \text{subject to:}

& & -I_{max} \leq I_1, \ldots ,I_5 \leq I_{max}\\

& & & 1 \le B_z^i/B_{0}, i=1, \ldots, M

\end{aligned}

where *P _{o}* is the initial total power dissipated in all coils and is the power dissipated in the k

We further want to constrain the fields at *M* number of points on the centerline to be above a value of *B*_{0}.

The implementation of this problem uses the same Global Control Variables feature as before. The objective of minimizing the total dissipated coil power is implemented via the *Global Objective* feature, as shown in the screenshot below. The built-in variables for the dissipated power (`mf.PCoil_1,...,mf.PCoil5`

) in each Coil feature can be used directly. The objective is normalized with respect to the initial total power so that it is close to unity.

*Implementation of the objective to minimize total power.*

The constraint on the field minimum has to be implemented at a set of discrete points within the model. In this case, we introduce five points evenly distributed over the optimization zone. Each of these constraints has to be introduced with a separate *Point Sum Inequality Constraint* feature, as shown below. We again apply a normalization such that this constraint has a magnitude of one. Note that the *Multiply by 2πr* option is toggled off, since these points lie on the centerline.

*The implementation of the constraint on the field minimum at a point.*

We can solve this problem using the same approach as before. The results are plotted below. It is interesting to note that the minimal dissipated power solution does not result in a very uniform field distribution over the target zone.

*Results of optimizing for a minimum power dissipation with a constraint on the field minimum.*

Finally, let’s consider minimizing the gradient of the field along the optimization zone, with a constraint on the field at the centerpoint. This can be expressed as:

\begin{aligned}

& \underset{I_1, \ldots ,I_5}{\text{minimize:}}

& & \frac{1}{L_0 B_{0}} \int_0^{L_0} \left( \frac{\partial B_z}{\partial z } \right) ^2 d l \\

& \text{subject to:}

& & -I_{max} \leq I_1, \ldots ,I_5 \leq I_{max}\\

& & & B_z(r=0,z=0) = B_0 \end{aligned}

& \underset{I_1, \ldots ,I_5}{\text{minimize:}}

& & \frac{1}{L_0 B_{0}} \int_0^{L_0} \left( \frac{\partial B_z}{\partial z } \right) ^2 d l \\

& \text{subject to:}

& & -I_{max} \leq I_1, \ldots ,I_5 \leq I_{max}\\

& & & B_z(r=0,z=0) = B_0 \end{aligned}

The constraint here fixes the field at the centerpoint of the coil. Although the *Optimization* interface does have an explicit equality constraint, we can achieve the same results with an inequality constraint with equal upper and lower bounds. We again apply a normalization such that our constraint is actually , as shown in the image below.

*The implementation of an equality constraint.*

The objective of minimizing the gradient of the field within the target zone is implemented via the Integral Objective feature (shown below). The gradient of the *B _{z}*-field with respect to the

`d(mf.Bz,z)`

.

*The objective of minimizing the gradient of the field.*

We can use the same solver settings as before. The results for this case are shown below. The field within the optimization zone is quite uniform and matches the target at the centerpoint.

*Results of optimizing for a minimum field gradient with a constraint on the field at a point.*

Although the field here appears almost identical to the first case, the solution in terms of the coil currents is quite different, which raises an interesting point. There are multiple combinations of coil currents that will give nearly identical solutions in terms of minimizing the field difference or gradient. Another way of saying this is that the objective function has multiple local minimum points.

The SNOPT optimization solver uses a type of gradient-based approach and will approach different local minima for different initial conditions for the coil currents. Although a gradient-based solver will converge to a local minimum, there is no guarantee that this is in fact the global minimum. In general (unless we perform an exhaustive search of the design space), it is never possible to guarantee that the optimized solution is a global minimum.

Furthermore, if we were to increase the number of coils in this problem, we can get into the situation where multiple combinations of coil currents are nearly equivalently optimal. That is, there is no single optimal point, but rather an “optimal line” or “optimal surface” in the design space (the combination of coil currents) that is nearly equivalent. The optimization solver does not provide direct feedback of this, but will tend to converge more slowly in such cases.

We have shown three different ways to optimize the currents flowing through the different turns of a coil. These three cases introduce different types of objective functions and constraints and can be adapted for a variety of other cases. Depending upon the overall goals and objectives of your coil design problem, you may want to use any one of these or even an entirely different objective function and constraint set. These examples show the power and flexibility of the Optimization Module in combination with the AC/DC Module.

Of course, there is even more that can be done with these problems. In an upcoming blog post, we will look at adjusting the locations of the coil turns — stay tuned.

*Editor’s note: We have published the follow-up post in this blog series. Read it here: “How to Optimize the Spacing of Electromagnetic Coils“.*

- Browse the COMSOL Blog for more information on modeling electromagnetic coils:

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.

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, , 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.

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.

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 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.

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.

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

Topology optimization is a powerful tool that enables engineers to find optimal solutions to problems related to their applications. Here, we’ll take a closer look at topology optimization as it relates to acoustics and how we optimally distribute acoustic media to obtain a desired response. Several examples will further illustrate the potential of this optimization technique.

Many engineering tasks revolve around optimizing an existing design or a future design for a certain application. Best practices and experiences derived from years of working within a given industry are of great importance when it comes to improving designs. However, optimization problems are often so complex that it is impossible to know if design iterations are pushing things in the right direction. This is where *optimization* as a mathematical discipline comes into play.

Before we proceed, let’s review some important terminology. In optimization — be it parameter optimization, shape optimization, or in our case topology optimization — there is always at least one so-called *objective function*. Typically, we want to minimize this function. For acoustic problems, we may want to minimize the sound pressure in a certain region, whereas for structural mechanics problems, we may want to minimize the stresses in a part of a structure. We state this objective as

\min_{\chi} F (\chi)

with *F* being the objective function. A *design variable* is varied throughout the optimization process to reach an optimal solution. It is varied within a *design domain* denoted *Ω _{d}*, which generally does not make up the entire finite element space

*The design domain is generally a subset of the entire finite element domain.*

Note that since the design variable varies as a function of space over the finite element discretized design domain, it is as such a vector. For this particular case, we will simply address it as a variable.

The optimization problem may have more than one objective function, and so it will be up to the engineer to decide how large of a weight each of these objectives should carry. Note that because the objectives may oppose each other during the optimization, special care should be taken when setting up the problem.

In addition to the objective function(s), there will usually be some *constraints* associated with the optimization problem. These constraints reflect some inherent size and/or weight limitations for the problem in question. With the *Optimization* interface in COMSOL Multiphysics, we can input the design variable, the objective function(s), and the constraints in a systematic way.

With topology optimization, we have an iterative process where the design variable is varied throughout the design domain. The design variable is continuous throughout the domain and takes on values from zero to one over the domain:

0 < \chi \leq 1\ \forall\ (x, y)\ \varepsilon\ \Omega_d.

Ideally, we want the design variable to settle near values of either zero or one. In this way, we get a near discrete design, with two distinct (binary) states distributed over the design domain. The interpretation of these two states will depend on the physics related to our optimization. Since most literature addresses topology optimization within the context of structural mechanics, we will first look at this type of physics and address its acoustics counterpart in the next section.

Topology optimization in COMSOL Multiphysics for static structural mechanics was a previous topic of discussion on the COMSOL Blog. To give a brief overview: A so-called MBB beam is investigated with the objective of maximizing the stiffness by minimizing the total strain energy for a given load and boundary conditions. The design domain makes up the entire finite element domain. A constraint is applied to the total mass of the structure. In the design space, Young’s modulus is interpolated via the design variable as

E(\chi) = \left\{ \begin{array}{ll}E_0\ \textrm{for}\ \chi=1\\0\ \textrm{for}\ \chi=0 \end{array} \right..

To help the binary design, we can use a so-called solid isotropic material with penalization (SIMP) interpolation

E (\chi) = \chi^p E_0

where *p* is the penalization factor, typically taking on a value in the range of three to five. With this interpolation (and an implicit linear interpolation of the density), intermediate values of *X* are avoided by the solver as they provide less favorable stiffness-to-weight ratios. I have recreated the resulting MBB beam topology from the previous blog post below.

*Recreation of the optimized MBB beam.*

In this figure, black indicates a material with a user-defined Young’s modulus of *E _{0}*. Meanwhile, white corresponds to zero stiffness, indicating that there should be no material.

Let’s now move on to our discussion of acoustic topology optimization, where we have a frequency-dependent solution with wave propagation in an acoustic media. The design variable is now related to the physics of acoustics. Instead of having a binary *void-material* distribution of material, our goal is to have a binary *air-solid* distribution, where “solid” refers to a fluid with a high density and bulk modulus, which emulates a solid structure.

We define four parameters that describe the inertial and compressional behavior of the standard medium and the “solid” medium: Air is given a density of and a bulk modulus of *K _{1}*, and the “solid” medium has a higher density of and a higher bulk modulus of

\rho(\chi) = \left\{ \begin{array}{ll}\rho_2\ \textrm{for}\ \chi=1 \\ \rho_1\ \textrm{for} \ \chi=0 \end{array} \right.

and

K(\chi) = \left\{ \begin{array}{ll}K_2\ \textrm{for}\ \chi=1\\K_1\ \textrm{for}\ \chi=0 \end{array} \right..

The easiest way to obtain these characteristics is by linear interpolation between the two extreme values. This is not necessarily the best approach since intermediate values of will not be penalized and therefore the optimal design may not be binary. As such, it will not be feasible to manufacture. In the literature alternative, interpolation schemes are given. In the cases presented here, the so-called rational approximation of material properties (RAMP) interpolation is used (see Ref. 1).

Just as with structural optimization, we define a design domain where the material distribution can take place, while simultaneously satisfying the constraints. An area or volume constraints can be defined via the design variable. For example, an area constraint on the design domain can be stated as an *inequality constraint*

\int^{}_{\Omega_d} \chi d \Omega_d \leq S_r

where *S _{r}* is an area ratio between the area of the design that is assigned solid properties and the entire design domain.

Let’s first take a look at a silencer (or “muffler”) example. For simplicity, we limit ourselves to a 2D domain. A typical measure used when characterizing a silencer is the so-called transmission loss, denoted *TL*, which is a measure of power input to power output:

TL = 10 \log_{10} \left(\frac{W_i}{W_o} \right).

The transmission loss is calculated using the so-called three-point method (see Ref. 2). We use this as our objective function, seeking to maximize it at a single frequency (in this case 420 Hz):

\max_{\chi} TL (420 \text {Hz}).

Two design domains are defined above and below a tubular section. The design domain is constrained in such a way that a maximum of 5% of the 2D area is the structure and thus 95% must be air:

\int^{}_{\Omega_d} \chi d \Omega_d \leq 0.05.

The initial state for the design domain is 100% air, i.e., . The animation below shows the evolution from the initial state to the resulting topology.

*An animation depicting the evolution from the initial state to the optimized silencer topology.*

The optimized structure takes on a “double expansion chamber” (see Ref. 3) silencer topology. The transmission loss has increased by approximately 14 dB at the target frequency, as illustrated in the plot below. However, at all frequencies other than the target frequency, the transmission loss has also changed, which may be of great importance for the specific application. Therefore, a single-frequency optimization may not be the best choice for the typical design problem.

*Transmission loss for the initial state and optimized silencer.*

Shifting gears, let’s now look at how to optimize for two objective functions and two frequencies. Here, we again consider a 2D room with three hard walls and a pressure input at the left side of the room. The room also includes two objective areas, *Ω _{1}* and

- Minimize the sound pressure level at a frequency
*f*and_{1} - Minimize the sound pressure level at a frequency
*f*_{2}= 1.5 f_{1}

with the circular design domain *Ω _{d}* and an area constraint that is 10% structure. The initial state is , making the design domain 100% air.

*A square 2D room with a circular design domain and two objective domains.*

With more than one objective function, we must make some choices regarding the relative weights, or importance, of the different objectives. In this case, the two objectives are of equal weight in importance, and the problem is stated as a so-called *min-max* problem:

\begin{align}

\min_{\chi} \max_{f_1 f_2} SPL_i (\chi, f_i) \\

\text {subject to} \int^{}_{\Omega_d} \chi d\Omega_d \leq 0.1.

\end{align}

\min_{\chi} \max_{f_1 f_2} SPL_i (\chi, f_i) \\

\text {subject to} \int^{}_{\Omega_d} \chi d\Omega_d \leq 0.1.

\end{align}

The figures below show the optimized topology (blue) along with the sound pressure for both frequencies using the same pressure scale. Note how the optimized topology results in a low-pressure zone (green) appearing in the upper-right corner at the first frequency. At the same time, this optimized topology ensures a similar low-pressure zone in the lower-right corner at the second frequency. This would certainly be a challenging task if trial-and-error was the only choice.

*Sound pressure for frequency* f_{1} *(left) and for frequency* f_{2} *(right). The optimized topology is shown in blue.*

As a third and final example, we’ll optimize a single objective over a frequency range. A sound source is radiating into a 2D domain, where we initially have a cylindrical sound field. Two square design domains are present, but since there is symmetry, we only consider one half of the geometry in the simulation. In this case, we want a constant magnitude of the on-axis sound pressure of in a point 0.4 meter in front of the sound source. The optimization is carried out in a frequency range of 4,000 to 4,200 Hz (50 Hz steps, a total of five frequencies). We can accomplish this via the Global Least-Squares Objective functionality in COMSOL Multiphysics, with the problem being stated as:

\begin{align}

\min_{\chi} \sum_{i=1}^{5} (\mid p_i (\chi, f_i, 0, 0.4) \mid -\overline{p}_{obj})^2 \\

\text {subject to} \int^{}_{\Omega_d} \chi d\Omega_d \leq 0.1.

\end{align}

\min_{\chi} \sum_{i=1}^{5} (\mid p_i (\chi, f_i, 0, 0.4) \mid -\overline{p}_{obj})^2 \\

\text {subject to} \int^{}_{\Omega_d} \chi d\Omega_d \leq 0.1.

\end{align}

The initial state is again . The optimized topology is shown below, along with the sound field for both the initial state and optimized state.

*Sound pressure for the initial state (left) and optimized state (right) at 4 kHz, with the optimized topology shown in blue within the square design domains.*

Since the sound pressure magnitude in the observation point of the initial state is lower than the objective pressure, the topology optimization results in the creation of a reflector that focuses the on-axis sound. The sound pressure magnitudes before and after the optimization are shown below. The pressure magnitude is close to the desired objective pressure in the frequency range following the optimization.

*The pressure magnitude divided by for the initial and optimized topology.*

Acoustic topology optimization offers great potential for helping acoustic engineers come up with innovative designs. As I have demonstrated today, you can effectively use this technique in COMSOL Multiphysics. With proper formulations of objectives and constraints, it is possible to construct applications with new and innovative topologies — topologies that would most likely not have been found using traditional methods.

I would like to give special thanks to Niels Aage, an associate professor at the Technical University of Denmark, for several fruitful discussions on the topic of optimization.

To learn more about using acoustic topology optimization in COMSOL Multiphysics, we encourage you to download the following example from our Application Gallery: Topology Optimization of Acoustic Modes in a 2D Room.

- M.P. Bendsoe, O. Sigmund,
*Topology Optimization: Theory, Methods, and Applications*, Springer 2003. - T.W. Wu, G.C. Wan, Muffler, “Performance studies and using a direct mixed-body boundary element method and a three-point method for evaluating transmission loss”, Trans. ASME:
*J. Vib. Acoust.*118 (1996) 479-484. - Z. Tao, A.F. Seybert, “A review of current techniques for measuring muffler transmission loss”,
*SAE International*, 2003.

René Christensen has been working in the field of vibroacoustics for more than a decade, both as a consultant (iCapture ApS) and as an engineer in the hearing aid industry (Oticon A/S, GN ReSound A/S). He has a special interest in the modeling of viscothermal effects in microacoustics, which was also the topic of his PhD. René joined the hardware platform R&D acoustics team at GN ReSound as a senior acoustic engineer in 2015. In this role, he works with the design and optimization of hearing aids.

]]>

Kidneys serve an important function in the body by helping to remove excess waste and fluid from the blood. When permanent kidney failure known as *end-stage renal disease* (ESRD) transpires, these organs stop functioning at a level that is necessary for day-to-day living. To replace the function of healthy kidneys, patients are kept on dialysis. This form of treatment involves transferring a patient’s blood through a machine that cleans the blood and then recirculates it back into the body.

For dialysis to take place, vascular access is necessary. The most common method for providing vascular access is the arteriovenous fistula (AVF), a direct surgical connection between the arterial and venous sides of the vasculature that is performed in the arm. Another form of vascular access that is also growing in use is the brachiocephalic fistula (BCF), which involves joining the brachial artery with the cephalic vein near the elbow.

BCF often encounters high failure rates due to neointimal hyperplasia (NH) and eventual stenosis in the curved portion of the vein known as the *cephalic arch*. This is caused by dramatic increases in blood flow rates through the cephalic vein following fistula creation — rates that are an order of magnitude higher than normal physiological levels.

The onset of NH is an attempt by the cephalic vein to alter its shape in order to mitigate the effects of the higher blood flow rate after the fistula is placed. NH is, in particular, a physiological response to the low wall shear stresses (WSS) that happen locally within the curved portion of the cephalic vein due to the occurrence of recirculation regions. However, unable to adapt to the extreme hemodynamic conditions, stenosis commonly occurs. Stenosis can lead to thrombosis and/or the inability for the BCF to provide sufficient access for continued dialysis.

*Top: A healthy vessel wall. Bottom: A vessel wall with NH.*

In order to investigate the mechanisms behind BCF failure and develop methods to improve clinical outcomes, mechanical engineers from the Illinois Institute of Technology are collaborating with clinicians at the University of Chicago Medical Center. Patient-specific data is obtained clinically, with correlating geometric and CFD models developed in COMSOL Multiphysics.

At various intervals following vascular access surgery, the team records and processes the venous deformation and hemodynamics for each of the over 100 individual patients. The CFD results provide detailed patient-specific hemodynamic data that is used to explain the impact of the high flow rates through the cephalic arch, with particular attention paid to the onset of WSS regions that are below normal physiological values.

The team couples shape optimization with the CFD Module to test the hypothesis that low WSS leads to geometric changes via NH and stenosis. Such an approach also allows them to avoid having to implement a first-principles model of the underlying biochemical factors that enable such processes. The objective is to determine the vessel shape that comes closest to bringing the WSS values throughout the cephalic vein back within the normal physiological range, thereby mimicking the body’s attempt to do so through NH. The figure below depicts the CFD results for a particular patient, where the vessel wall regions marked in red are those for which the WSS is below the normal physiological range, therefore susceptible to NH.

*Simulation results for an actual patient-specific flow field after vascular access surgery. The interval shown here is 12 months post surgery.*

*A streamfunction plot superimposed on low WSS distribution.*

Further, the researchers are coupling BOBYQA, a gradient-free optimization method in COMSOL Multiphysics, with the CFD Module to evolve the shape of the vessel in such a way that would redistribute the WSS along the walls and readjust the blood flow rate back to a normal physiological range. Through this coupling, they are seeking to predict the evolution of the shape of the cephalic vein for patient-specific geometries, focusing on the end result. When compared to clinical data, their results have proven to be accurate in their predictions of both favorable and unfavorable adaptions of the vein. This proves that, from a topographical point of view, optimization of the shape of the vessel can capture the deformations of the vasculature that are driven by hemodynamic factors when the right cost functions and constraints are considered.

*A coupled CFD and shape optimization prediction.*

*An actual failed vascular access matching the results of the patient-specific prediction. The stenotic deformation in the arch section of the vein is evident for this patient.*

The research findings, which were presented at the VI International Conference on Computational Bioengineering and the 68^{th} American Physical Society Annual Division of Fluid Dynamics meeting last fall, have helped to create a framework for forecasting vascular access failure and making patient-specific decisions. It offers new potential in modifying current vascular access techniques to enhance their functionality and, in that process, can also increase the life expectancy for ESRD patients.

*Editor’s note on 10/26/16: Javid Mahmoudzadeh, a member of the research team, led a talk on this simulation research at an event this past August. You can watch his presentation here.*

- Our Application Gallery features a number of CFD tutorials designed to inspire and guide you in your own modeling processes. You can browse them here.
- Interested in learning more about shape optimization? Be sure to check out these blog posts:

As engineers, researchers, and scientists, we are always striving to come up with improved designs. *Optimization* is the idea of altering model inputs, such as part dimensions and material properties, with the objective of improving some metric, while also considering a set of constraints. The Optimization Module in COMSOL Multiphysics is a useful tool for addressing such problems.

Dimensional optimization is one of the more common optimization techniques. The approach involves changing CAD dimensions directly to minimize mass, as illustrated in our Multistudy Optimization of a Bracket tutorial. In the bracket example, we use so-called *gradient-free techniques* to adjust dimensions and consider constraints on the relationships between the dimensions, the peak stress, and the lowest natural eigenfrequency. These techniques are very flexible in the type of objective functions and constraints that can be addressed. However, one drawback to these techniques is having to remesh the part repeatedly to numerically approximate the sensitivities of the objective function and constraints with respect to the design variables.

As we have previously discussed on the blog, it is also possible to analytically compute the design sensitivities due to geometric changes when using the *Deformed Geometry* interface. Further, the gradient-based solvers can use the sensitivities to optimize the dimensions of a part without remeshing — an element that we highlighted in the design of a capacitor. It is helpful to review the two blog posts referenced here to understand the functionality that we will use today.

Shape optimization is an extension of the previously developed concepts, and it considers not just straightforward dimensional changes, but general changes in shape as well. The shape of the structure is controlled via a set of design parameters that use a set of basis functions, which can describe quite arbitrary shapes. Let’s take a look at an example.

We begin with a classical shape optimization problem: adjusting the thickness of a cantilevered beam to minimize the mass, while maintaining a constraint on the peak deflection of the free end. The beam of initially uniform thickness has a nonuniform load distributed over its top surface, as shown in the diagram below.

*A cantilevered beam with a nonuniform load applied. Point A should not deflect more than a specified value. The mesh is also shown.*

First, we want to choose our design variables. Both the length of the beam and the thickness at the cantilevered end are fixed. What we can vary is the thickness of the beam along the length. It is somewhat simpler to vary the change in the thickness from the initial configuration. Instead, we introduce a function, , which is initially zero along the length.

*The optimization problem studies a change in the thickness of the beam.*

Here, we choose to represent the change in thickness via a set of Bernstein polynomials of the fourth order:

DT(\bar X)=T_0\left[C_0 (1-\bar X)^4 + C_1 \bar X (1-\bar X)^3 + C_2 \bar X^2 (1-\bar X)^2 +C_3 \bar X^3 (1-\bar X)^1 +C_4 \bar X^4\right]

expressed in terms of the normalized dimension: . Note that the function is scaled such that the polynomial coefficients have an order of magnitude near unity. Again, we do this for scaling purposes.

Since the thickness of the beam at is specified, , fixing so that the term can be omitted. At the far end, we add the constraint that the beam cannot become too thin: .

In the intermediate region, we would also like to add some constraints to further limit the design space. We could add the constraint that . The constraint, however, has a drawback: It would allow the thickness of the beam to oscillate and, from first principles, we know that this is not reasonable. There is no advantage to having the thickness of the beam *increase* along the length. We can instead add a constraint on the derivative: . This forces the thickness of the beam to change monotonically along the length and has the added advantage of naturally satisfying the constraint: .

There is one more constraint to consider: the displacement of the point at the end of the beam. We want the magnitude of the displacement of point to be less than some specified value, . With such information, we now have a complete optimization problem:

\begin{aligned}& \underset{C_1 \cdots C_4}{\text{minimize:}}& Mass/M_0 \\& \text{subject to:}& C_4 < 0.9 \\& & |\mathbf{u}_A/u_{max}| < 1\end{aligned}

Here, the normalization of the objective function with respect to the initial mass of the beam, , is done to scale the objective function so that it is of order unity. Similarly, the magnitude of the displacement of the beam tip, , is normalized with respect to the peak permissible displacement, . The normalized displacement should be less than one. Let’s now look at implementing such a problem in COMSOL Multiphysics using the Optimization Module.

We can begin with our initial design, simply a beam of fixed length and uniform thickness. The design is cantilevered at one end, with a nonuniform load across the top face that varies as . We want to first introduce the change in the thickness function. The polynomial function described earlier is the variable **DT**, as shown in the screenshot below. The expression **Xg** refers to the *x*-dimension of the original, undeformed geometry. The derivative of this function, with respect to the normalized *x*-direction, is the variable **dDTdX**. Two *Global Parameters*, **L0** and **T0**, define the length and maximum thickness.

*A screenshot showing the change in the thickness function and its derivative.*

The change in the thickness variable is used within the *Deformed Geometry* interface to define how the entire volume of the beam is altered with a change in thickness. Since it is only the thickness that changes, a simple linear mapping can be used, as illustrated below.

*The displacement within the beam is completely prescribed.*

We can now set up the optimization problem via the *Optimization* interface. The interface provides an easy way of setting up more complicated optimization problems with several constraints. The relevant settings are shown in the screenshots below, starting with the objective function. The *Integral Objective* feature integrates the material density over the modeling domain and normalizes with respect to the initial part mass.

*The optimization objective is to minimize the mass.*

The settings for the *Global Control Variables* feature are shown below. The four variables, **C1**, **C2**, **C3**, and **C4**, have an initial value of zero, which is equivalent to the initial beam shape. The constraint on **C4** is imposed as an upper bound and the scaling of all variables is unity.

*The definitions of the control variables, their bounds, and scaling.*

Next, we apply the *Pointwise Inequality Constraint* feature to the bottom boundary of the domain. This feature enforces that the derivative of the displacement function remains positive at every point, thereby ensuring a monotonically increasing function.

*The constraint on the derivative along the length of the beam is enforced via a pointwise inequality constraint.*

Finally, the peak displacement of the point at the far end of the beam is constrained so that it is below a maximum specified value. This value is set via the *Point Sum Inequality Constraint* feature.

*The implementation of the constraint on the normalized peak displacement.*

Our optimization problem is now almost entirely set up. The only remaining step is to add an *Optimization* feature to the study sequence and to select the gradient-based SNOPT solver, which proves to be the fastest approach to our problem. All other settings can be left at their default values. The objective function and constraints are automatically taken from the *Optimization* interface.

*The relevant optimization solver settings.*

The results are depicted in the image below. The optimal shape within this basis has been identified. The displacement at the tip is at its maximum value, with the thickness monotonically changing along the length. Due to the expected deformation of the geometry, a mapped mesh was used.

*The optimized shape of the beam, which minimizes mass for the applied nonuniform load and constraints. The displacement field is plotted along with the applied load distribution and the mesh.*

We may ask ourselves how we know that the above structure is truly optimized. There is always the urge to perform a mesh refinement study, trying out finer and finer meshes to see how the solution converges. It is also reasonable to study convergence with respect to basis functions. We can use a higher-order Bernstein basis function and compare the results. This, however, can lead to a problem known as *Runge’s phenomenon*, along with slow convergence.

We can circumvent such issues by subdividing the original interval into multiple subintervals, using different lower-order shape functions within each interval (a piecewise polynomial). Other basis functions beyond the Bernstein basis can also be applied, such as the Chebyshev polynomials and the Fourier basis. The Optimizing the Shape of a Horn tutorial, available in our Application Gallery, features an example of the latter instance.

The cases discussed here include quite simple deformations. When considering more complicated deformations, you will need to put more effort into defining the deformation mapping. For very complicated deformations, it is also useful to add helper equations in order to compute the deformation.

If you have any questions about using these shape optimization techniques or are interested in adding the Optimization Module to your suite of modeling tools, please contact us.

]]>

Let’s begin by referring back to a previous blog post on the computation of design sensitivities that shows how we can use the *Deformed Geometry* interface and the Sensitivity study to analytically evaluate the design sensitivities of a parallel plate capacitor. For that problem, we computed the change in the capacitance with respect to geometric and material property variations. We also computed the design sensitivities to geometric changes without altering the geometry or performing any remeshing. We now want to use that same framework to change the geometry of our capacitor with the objective of minimizing a particular quantity by using the functionality of the Optimization Module.

We start with a simple extension to the previous example: a parallel plate capacitor of side length with two dielectrics, , each of the same initial thickness, . Further, we will neglect all fringing fields. This lets us model only the region between two parallel plates so that our computational model looks just like the figure shown below.

*Schematic of a parallel plate capacitor with two dielectrics between the plates. Fringing fields are ignored.*

This model can be built by sketching two geometric blocks of dimensions as described above. The *Electrostatics* physics interface allows us to apply a voltage and a *Ground* condition at the top and bottom faces as well as apply material dielectric properties. It is possible to compute the capacitance by integrating the electric energy density, as described in the previously mentioned blog post, and get a value of .

Now, let’s suppose that we want to design a 100 pF capacitor by changing the thicknesses of the two layers, without altering the overall dimensions of the device. This can be posed as an optimization problem:

\begin{aligned}& \underset{dT}{\text{minimize:}}& & \left( \frac{C_{computed}}{100\ pF}-1\right)^2 \\& \text{subject to:}& & -T_0 > dT >T_0\end{aligned}

That is, we want to get the capacitance to be as close to 100 pF as possible by varying the change in the dielectric thicknesses within limits such that neither dielectric is of zero thickness. The design parameter is the changing in the thicknesses of the two layers, as shown above. The objective function itself is formulated such that the absolute magnitude is on the order of unity. For numerical reasons, this form is preferred over or the absolute value function: .

We can begin by defining the variation of the thickness of the dielectric layers using the *Deformed Geometry* interface. The *Deformed Geometry* interface is necessary because we want to compute the analytic sensitivities without having to remesh the geometry as we change the dimensions. Since we will be changing the sizes of the two dielectrics, we want to define these deformations as completely as possible. We will do this with a *Prescribed Deformation* domain feature, as shown in the screenshot below.

The capacitor itself is originally sketched such that it is centered at the origin so the original, undeformed part has a coordinate system: **(Xg,Yg,Zg)**. For this simple Cartesian geometry, we can use this coordinate system to directly define the deformation as the thicknesses of the dielectric layers are changed. The deformations of the bottom and top layer are **dT*(1+Zg/T0)** and **dT*(1-Zg/T0)**, respectively, where **dT** and **T0** are *Global Parameters*.

*The change in the thicknesses of the dielectric layers is controlled with a* Prescribed Deformation *feature.*

Next, let’s look at the optimization user interface. For this simple problem, we can just add an *Optimization* feature to our study sequence, as shown in the screenshot below.

This minimization problem statement and scaling can be implemented entirely within the *Optimization* study node, as shown in the screenshot below. The relevant settings are the *Objective Function*, which is the expression **(C_computed/100[pF]-1)^2**, and the *Control Parameter*, **dT**, which has an initial value of **0[m]**. The upper and lower limits are specified to prevent zero, or negative, thicknesses. Lastly, we apply a scaling to , the design parameter, based upon the original thickness, , such that the optimized value will have an order of magnitude near unity.

*The optimization solver settings.*

The SNOPT method is used to solve the optimization problem. Both the SNOPT and MMA methods use the analytically computed sensitivities, but SNOPT converges the fastest to within the default tolerance of 1E-6. The resultant device capacitance is 100 pF and the thickness of the dielectrics is D_{1} = 0.1542 m and D_{2} = 0.0458 m. The voltage field in the original model and the optimized structure are shown below, along with the finite element mesh. Observe that the finite element mesh is stretched and compressed, but that no remeshing has occurred.

*The original and final structure. The voltage field and mesh are shown.*

We’ve looked at a fairly straightforward example of shape optimization, although with a little more effort, we could have found the solution to this problem by hand or by performing a parametric sweep. The geometric deformation demonstrated here is also quite simple. As you consider more complex geometries and more complex geometric changes, you will not always be able to directly use the undeformed spatial coordinates to define the deformation. In such cases, you will need to add equations to the model to help define the deformation. Of course, you may also want to consider more complex deformations, not just simple dimensional changes. We will cover this topic in an upcoming blog post on optimization.

In the meantime, if you have any questions about this technique and would like to use the Optimization Module for your design needs, please contact us.

]]>

Since 3D printing first emerged as a technology, its impact has been felt across a wide range of industries. Take automotive manufacturers, for instance. 3D printing capabilities have extended the freedom of vehicle design, enabling the development of highly customized parts while saving production time and costs. Within the medical field, the technology has led to greater innovation in the design of customized implants and devices as well as the creation of exact replicas of organs.

*A 3D printer creates a product component.*

Additive manufacturing, as we can see, is already making its mark as an efficient approach to product development. As the technology continues to advance, new freedom and flexibility is emerging, furthering its applications. One particular area of promise is the field of material design.

Material design typically tailors fine-scale structures organized in a repeating pattern to create a product with optimal performance. Depending on the requirements, the design of a single microstructure, otherwise known as a unit cell, can range from a simple monolithic geometry to a complex multimaterial geometry. In theory, the complexity, and thus the design freedom of the unit cell, is only limited by the creativity of the designer and the manufacturing capabilities.

Traditionally, 3D printing has only been capable of printing a single material product. Now, recent developments in 3D printing are showing potential for the multimaterial printing of small-scale structures. Such capabilities would provide designers with a finer control over the microstructures, with the option to combine and customize the microstructures based on their specific needs. Further, engineers would be able to select the proportion and arrangement of the individual materials included in the structure.

Researchers at TNO are using multiscale modeling and multiphysics simulation to investigate virtual material design in 3D printing. In the next section, we’ll take a closer look at their innovative research.

To begin their simulation studies, the team first designed a single unit cell with twice the stiffness in one direction as the other and analyzed the material behavior for a given geometry. The optimization capabilities in COMSOL Multiphysics allowed them to derive the appropriate value of stress corresponding to an applied strain, so as to fit their desired stiffness matrix. The simulation results were verified with a printed sample tested for the expected material behavior.

*Left: Unit cell geometry. Center: Mechanical stress for the optimized design. Right: The 3D-printed samples.*

The researchers then performed a similar study on a highly anisotropic material. In the simulation, both the spatial distribution of the material and the orientation of the anisotropic fibers could be controlled.

Speaking to the research team’s greater goal, the simulation was extended to microstructures made up of a combination of different materials. The composition and arrangement of the various materials in the structure were adjusted until the optimal level of thermal conductivity was achieved.

*The multimaterial composition for the ideal anisotropic thermal conductivity. The color white indicates regions of high conductivity, orange represents regions of low conductivity, and red depicts nonconductive material and voids.*

After optimization at the microlevel, the team at TNO focused on optimization for objects of a larger scale. While a necessary step for developing actual products, extending the results of the microstructure simulations to real-life sizes can be quite computationally expensive. Multiscale modeling provides a solution, allowing designers to simulate at the micromaterial and product scales simultaneously. The team extracted parameters for the effective structural behavior of several multimaterial cells, which could then be applied as input in the full-scale model of a device.

While topology optimization is a powerful tool for creating designs for 3D printing, there are also limitations to address for specific additive manufacturing techniques. In selective laser melting (SLM), for example, powdered material is melted into a desired shape via a laser beam. The powder that is not used must be removed from the printed object afterward, and large overhangs are not conducive to SLM designs as they have the tendency to warp.

To address such issues, the research team designed unit cells featuring different densities and then combined them to create the desired properties at the product level. Various techniques were combined in COMSOL Multiphysics, from stiffness homogenization for individual unit cell types to topology optimization at the product scale. The procedure as a whole was later applied to the development of a polymer hammer handle, shown below. The design was comprised of different unit cell types at the microlevel and optimized for proper stiffness and minimal material use.

*Left: Topology optimization simulation results. Center: Optimized hammer handle design. Right: Pattern containing multiple cell types. The densest cells, with small holes, are located near the top, and the least dense cells are located near the bottom. A few intermediate shapes can be found in between these areas.*

As the researchers at TNO demonstrated, the current limitations of additive manufacturing can be effectively addressed with multiscale modeling and multiphysics simulation. Such advancements help to extend the power and reach of 3D printing beyond conventional techniques. This enables the development of new and more complex products, further spreading the benefits of 3D printing technology.

- Read more about TNO’s simulation research on page 22 of
*COMSOL News*2015 - Browse additional blog posts on the topic of 3D printing