Tuning forks are made out many different materials, but most of them are calibrated to a standard pitch of 440 Hz for an A note. An article in *JOM* discusses how the frequency of a tuning fork changes with different materials and a fixed geometry (Ref. 1). This made me think: What if we change the geometry and material of a tuning fork to reach the desired frequency?

*A tuning fork.*

The Application Library contains several models featuring a tuning fork geometry, as well as a tuning fork simulation app. You can access the Application Library within the COMSOL® software GUI in the *File* menu and search the keyword “tuning fork”. For this blog post, we’ll start with the simple Tuning Fork model (and accompanying example app).

This model features a parametric geometry, material properties of steel, the *Solid Mechanics* interface, and two studies. Both studies perform an eigenfrequency analysis to search for the eigenfrequency around 440 Hz. The first study uses a parametric sweep of the tuning fork’s arm length, set as a parameter *L*, to find the optimal design for 440 Hz. In contrast, the second study applies a mathematical optimization algorithm that uses *L* as the control variable and the deviation from the target frequency as the optimization objective for fast, precise, and efficient optimization.

*Tuning Fork model showing the original settings to search for a tune of 440 Hz via two different strategies.*

Let’s return to the initial question: How does the tuning fork’s arm length depend on the material for a tune of 440 Hz?

First, we extend the model with a material switch. This option allows us to set and test various materials for the model. Further, this switch is needed to work with the material sweep in the *Study* node, as described later in this blog post. We can add available materials from the built-in Material Library, including:

- Aluminum
- Titanium beta-21S
- Copper
- Steel AISI 4340

The switch is assigned to the solid domains of the tuning fork.

*Setting the material switch for a multimaterial analysis.*

Now that we transformed the original model into a multimaterial model, we can adjust the studies. Due to the combination with a material sweep, the studies can now solve the physical model for all chosen materials and it is possible to analyze all of the results together. For example, we can look at the eigenfrequency and confirm that the eigenfrequency changes with different materials and arm lengths.

Various sweeps can be combined easily within a study, such as the extension of Study 1 with a material sweep. In contrast, when we try to add a material sweep to the optimization study for Study 2, we get an error message. The good news is that there is another way of achieving this by using *Study References*, as explained below.

Setting the material sweep directly in the study is not supported, since it is only possible to use one *Sensitivity*, *Optimization*, *Parameter Estimation*, or *Parametric/Material/Function Sweep* study step in each study. These study nodes tend to control the same solver settings and are therefore incompatible with each other. To perform a parametric or nested optimization, we can call a study containing an *Optimization* node from inside another study via a *Study Reference* node.

Therefore, we add an additional empty study and fill it with a *Material Sweep* node and a study reference pointing to the optimization study. In the *Optimization* node, we can define the settings needed for the optimization. This is possible as long as all entries are globally available. For that, we leave Study 2 containing the optimization as is.

*Use of an additional study to create nested studies.*

With all the discussed adjustments, we can now run the multimaterial optimization study by computing Study 3. This study controls the material assignment and runs individual optimization procedures for each by starting Study 2 automatically. Hence, we can extract and postprocess the individual design changes for the different materials. This can be done, for example, by a global evaluation of the parametric data set. Evaluating the tuning fork arm length, set as the control variable *L*, gives us the needed design changes to tune each tuning fork design to 440 Hz.

*Top: Settings of the global evaluation. Bottom: Results table for the different materials identified via the switch index.*

You can build an app from a tuning fork model that includes a customized user interface and restricted inputs and outputs. Take the Tuning Fork app in the Application Library as an example. This app can be used to quickly compute the frequency of a tuning fork with the prong length as an input or the optimal prong length with the frequency as an input.

*The user interface of an example tuning fork app.*

The example featured above can be used as inspiration for building apps of your own via the Application Builder tool in COMSOL Multiphysics.

In this blog post, we used material sweeps in combination with an optimization study to find the best geometry for tuning forks made of different materials. Note that the approach discussed here is generic. You might want to combine other study steps that have the same hierarchy.

With this approach, you can combine all of the *Sensitivity*, *Optimization*, *Parameter Estimation*, or *Parametric/Material/Function Sweep* features into nested studies, thus improving your simulations, results, and products.

Try it yourself: Access the Tuning Fork model and app by clicking the button below, which will take you to the Application Gallery. Then, you can download the MPH-files if you have a COMSOL Access account and valid software license.

- T.D. Burleigh and P.A. Fuierer, “Tuning Forks for Vibrant Teaching“,
*JOM*, pp. 26–27, Nov. 2005.

Current loudspeakers feature advanced connectivity and an improved frequency range. This enables them to interact with virtual assistants; stream music wirelessly; and connect to additional parts, such as subwoofers. These advancements create new design demands. For instance, some loudspeakers are waterproof so that they can be used while in the shower or by the pool. Perhaps a more serious concern is that loudspeaker designs should be durable so that consumers can start using the product right out of the box.

*Left: A loudspeaker with the grille removed, circa 1980s. Image by By PT35 — Own work. Licensed under CC BY-SA 3.0, via Wikimedia Commons. Right: Example of a modern, portable speaker with* Bluetooth® *wireless technology. Image by TAKKA@P.P.R.S. — Own work. Licensed under CC BY-SA 2.0, via Flickr Creative Commons.*

Portability is one design factor that has become almost a requirement as consumer preferences change. Engineers need to design smaller, lighter loudspeakers that maintain sound quality and performance standards. To maximize loudspeaker performance while minimizing the overall weight, you can perform a topology optimization of loudspeaker driver components using the COMSOL Multiphysics® software and add-on Optimization Module.

In a loudspeaker driver, a magnetic circuit concentrates the magnetic flux into an air gap. A coil is placed in the air gap that winds perpendicular to the magnetic flux lines and is mechanically connected to the membrane of the speaker. When a current runs through the coil, electromagnetic forces induce movement. The membrane picks up this movement and interacts with the air, generating sound waves.

The magnetic circuit is constituted by an iron yoke, which performs two important functions:

- Maximizing the flux concentrated at the coil
- Providing a uniform field across the coil

In this example, the geometry for the circuit is similar to the one in the Loudspeaker Driver model. It is convenient to formulate the iron’s constitutive relation as a nonlinear relative magnetic permeability derived from its original B-H curve. This paves the way for the topology optimization, where the permeability will easily combine with the control variable field to drive the optimization process.

*To determine the optimal shape of an iron yoke for a magnetic circuit, you can use topology optimization.*

A typical figure of merit for the performance of the magnetic circuit is the parameter *BL*, or force factor, which is the product of the magnetic flux in the air gap and length of the coil. The larger the *BL* parameter, the higher the performance of the magnetic circuit. For a multiobjective study, you can scan the optimal shape for the component as a function of *BL* together with the weight reduction of the yoke.

After the topology optimization solution is found, you can extract the optimized geometry and reconstruct it for further analysis.

The original geometry includes an iron domain with a volume of 37 cm^{3}; specifically, the lower arm of the iron yoke. In the first two studies, the magnetic fields for the initial (suboptimal) circuit configuration are analyzed and the nonlinear relative permeability approach is validated by comparing magnetic fields with the standard B-H formulation.

*Left: The original geometry (red: iron, blue: air). Right: Magnetic flux density norm and lines for the initial configuration.*

By adding an *Optimization* interface, you can further reduce the volume of the iron yoke while preserving a high magnetic performance.

The third study begins with a two-step topology optimization, always seeking the highest possible *BL* and starting from a “full” cylindrical annulus with an iron volume of about 52 cm^{3}. The former condition is implemented as an integral objective on the *Coil* domain; the latter as an integral inequality constraint, where it is required that the volume of the yoke remains as close as possible to the target volume.

A reduction to 37 cm^{3} is targeted in Study 3 and the result, very similar to the original geometry, confirms that the original geometry was indeed already nearly optimal. Study 4 seeks the best performance with an even lighter geometry, expressed as a filling factor of 50% of the full volume; i.e., 26 cm^{3}.

*Left: The optimized geometry, where the volume of the lower arm of the iron yoke is 26 cm ^{3}. Right: Magnetic flux density norm and lines for the optimized configuration.*

The results for the two studies are comparable. Although the geometry with the optimized topology is lighter, there is no drawback in performance.

*A 3D revolution plot of the magnetic flux density norm, showing the final optimized geometry.*

These studies show that topology optimization can be used to find the best possible shape and constraint parameters for a loudspeaker component.

In preparation of further analyses on the optimal configuration, the final shape of the optimization analysis can be exported as an independent geometry.

*Left: A contour plot that defines the optimized iron/air threshold. Right: The optimized shape imported as a geometry object.*

Click the button below to try the Topology Optimization of a Magnetic Circuit tutorial yourself. Doing so will take you to the Application Gallery. From there, you can download the MPH-file if you have a COMSOL Access account and a valid software license.

Read more about topology optimization:

- How to Use Acoustic Topology Optimization in Your Simulation Studies
- Acoustic Topology Optimization with Thermoviscous Losses
- How to Use Topology Optimization Results as Model Geometries

*The* Bluetooth *word mark is a registered trademark owned by the Bluetooth SIG, Inc. and any use of such marks by COMSOL is under license.*

Additive manufacturing is the process of creating a 3D object by adding one or more materials on top of each other layer by layer. To learn more about this type of manufacturing, we reached out to Professor Frédéric Roger of the Mines Telecom Institute, Lille-Douai Center. (IMT is a French public institution dedicated to higher education, research, and innovation in engineering and digital technologies.)

Professor Roger says that, in a sense, additive manufacturing is a bit like sewing or weaving. In both processes, a heterogeneous finished product is created by controlling how different raw materials are consolidated. In weaving, the materials are usually thread and yarn; however, additive manufacturing can use many materials, including polymers, metal alloys, ceramics, and composites.

*Choosing the right materials is important for creating an ideal finished product, be it a warm blanket (left, woven by my grandmother) or a customized aerospace part (right). Right image in the public domain in the United States, via Wikimedia Commons.*

This wide range of materials means that additive manufacturing can be used to design a large amount of unique objects across many industries. For instance, Roger mentions that by using the right materials and thermodynamic conditions, engineers can make objects that withstand or adapt to severe environmental conditions. Such objects could even adapt to certain temperatures or chemical conditions by changing their shape or releasing chemical species (like drugs) that are trapped in a matrix. A transformation over time would add another dimension to the printed part, resulting in “4D printing”.

*Sometimes, additive manufacturing parts are inspired by natural forms, like the bio-inspired example pictured here. Image courtesy Frédéric Roger.*

According to Roger, the many opportunities that come with additive manufacturing make it “an unavoidable manufacturing process,” as it “offers new opportunities to develop optimized structures with advanced materials.” However, before engineers can create these structures, they have to improve the additive manufacturing process.

Since additive manufacturing is a complex process, it can be difficult to study. This technique varies based on the materials involved and the specific type of additive manufacturing. Studying this process also requires accounting for many different effects, such as:

- Multiple phase transformations
- Transfer of energy, mass, and momentum
- Sintering
- Photopolymerization
- Drying
- Crystallization
- Deformation
- Stress

To account for these factors, engineers can use the COMSOL Multiphysics® software, which Roger mentions is “a unique software that has great advantages in the simulation of additive manufacturing.” The software helps engineers to not only “optimize the additive manufacturing process but also to predict the mechanical and microstructural consequences on the product.” Through this, engineers can include all of the relevant physics and determine the ideal manufacturing conditions and part geometries that balance the needs of stiffness, weight reduction, and heat dissipation.

*Left: An example of the additive manufacturing process, which involves many different physics. Image by Les Pounder — Own work. Licensed under CC BY-SA 2.0, via Flickr Creative Commons. Right: Example of an additive manufacturing part created with two materials and filled with a honeycomb inner structure. Image courtesy Frédéric Roger.*

A challenge is that analyzing the additive manufacturing process while coupling the relevant physics can result in large model sizes and long computational times. To overcome this issue, Roger implements several different simulation strategies, such as activating mesh properties, using adaptive remeshing, and performing sequential simulations.

By taking a sequential approach, Roger is able to better analyze the succession of thermodynamic states that a material experiences during additive manufacturing. At the same time, this approach helps to reduce the complexity of the multiphysics couplings by dissociating them over time. As such, sequential simulations provide a way to comprehensively model and optimize the additive manufacturing process while reducing computational costs.

For their simulations, Roger and his team focused on fused-deposition modeling (FDM®), a common additive manufacturing technique that is both affordable and enables control over process parameters. The aim of the study was to optimize the internal and external geometry of a printed thermoplastic part and achieve the best possible performance. To accomplish these goals in an efficient manner, the team split their analysis into three parts, discussed below.

For more information about this study, check out the researchers’ paper.

In the first part of the study, the researchers wanted to minimize the total weight of a printed structure while maintaining a material distribution that maximizes stiffness. To do so, they used topological optimization and structural mechanics analysis to study a mechanical structure exposed to a tensile load.

*Original geometry and boundary conditions (left) and the Young’s modulus distribution that defines the optimal shape by color contrast (right). Left image by F. Roger and P. Krawczak and taken from their COMSOL Conference 2015 Grenoble presentation. Right image courtesy Frédéric Roger.*

Through the studies, they found an optimal shape for the part, determining that the middle of the shape has the highest stress levels. As such, the researchers divided the structure into domains based on the stress concentration field: a high-stress middle area surrounded by two low-stress areas. In the following study, they used this information to apply specific manufacturing conditions to the high-stress zone

*The stress fields in the optimized geometry. Image courtesy Frédéric Roger.*

In the second study, the researchers aimed to increase the stability of the high-stress zone in their part by testing two possible infill strategies:

- Heterogeneous filling with variable densities
- Multimaterial filling

In the heterogeneous case, the team created a more resistant domain in the high-stress middle area by using a higher density of infill. At the same time, they minimized the weight of the external areas by using less material. The results indicated that the ideal geometry contains 60% material in the high-stress region and 20% material in the low-stress regions.

*Printing an optimized part using one material with varying densities. Image by F. Roger and P. Krawczak and taken from their COMSOL Conference 2015 Grenoble paper.*

As shown below, the multimaterial case involved using red ABS plastic on the ends of the part and black conductive ABS with improved mechanical properties in the middle. The team found that they could replace the conductive ABS with materials similar to ABS that have reinforced filters to increase stiffness.

*Printing an optimized part using two materials. Image by F. Roger and P. Krawczak and taken from their COMSOL Conference 2015 Grenoble paper.*

After optimizing the inner and outer designs of the 3D-printed part, the researchers modeled the fused thermoplastic deposition process and evaluated manufacturing parameters. The resulting simulations helped them to accurately predict thermal history, wetting conditions, polymer crystallization, interactions between filaments, and residual stresses and strains. One example is shown below, depicting the plastic strain during the heating and cooling process.

*The fusion and solidification of a disk that is irradiated by a laser beam as well as the resulting plastic strain evolution. This analysis takes Newtonian fluid flow and solid thermomechanical properties into account. Animation courtesy Frédéric Roger.*

The study also investigated the heat and mass transfer within the first two layers of a thin-walled tube. The researchers were then able to analyze the plastic droplet deposition process and identify areas where the filaments reached fusion temperature. The animations of the material deposition study are shown below. They depict a heat source moving along a deposition pattern and heating the filaments up to fusion temperature, ~230°C for ABS droplets. The extruder path domain in the simulations is premeshed and the meshes are continuously activated depending on the extruder’s position.

*Two-layer circular deposition (top). The moving heat source represents the hot ABS deposition. The thermal expansion of the two layers (amplified by a factor of five), showing the moving heat source activating the properties of the material (bottom). Here, blue indicates a nonactivated mesh and the physical properties (thermal conductivity and stiffness) are close to zero. Animations courtesy Frédéric Roger.*

Using these simulations, Roger and his team predicted the temperature field between the filaments during the deposition process, an important factor that affects filament adhesion. Similar analyses could help researchers compare different additive manufacturing conditions and determine the best deposition strategy for a specific application.

Roger says that these simulations enabled his team to “define an additive manufacturing part whose internal and external architectures give it the best possible industrial performance.” Of course, this is only the start of what can be achieved by combining additive manufacturing and multiphysics simulation.

If you have any tips for using COMSOL Multiphysics to study the additive manufacturing process, be sure to let us know in the comments below!

- Read more about the researchers’ work in their paper: “Optimal Design Of Fused Deposition Modeling Structures Using Comsol Multiphysics“
- Check out these related blog posts:

*FDM is a registered trademark of Stratasys, Inc.*

Topology optimization helps engineers design applications in an optimized manner with respect to certain *a priori* objectives. Mainly used in structural mechanics, topology optimization is also used for thermal, electromagnetics, and acoustics applications. One physics that was missing from this list until last year is microacoustics. This blog post describes a new method for including thermoviscous losses for microacoustics topology optimization.

A previous blog post on acoustic topology optimization outlined the introductory theory and gave a couple of examples. The description of the acoustics was the standard Helmholtz wave equation. With this formulation, we can perform topology optimization for many different applications, such as loudspeaker cabinets, waveguides, room interiors, reflector arrangements, and similar large-scale geometries.

The governing equation is the standard wave equation with material parameters given in terms of the density and the bulk modulus K. For topology optimization, the density and the bulk modulus are interpolated via a variable, . This interpolation variable ideally takes binary values: 0 represents air and 1 represents a solid. During the optimization procedure, however, its value follows an interpolation scheme, such as a solid isotropic material with penalization model (SIMP), as shown in Figure 1.

*Figure 1: The density and bulk modulus interpolation for standard acoustic topology optimization. The units have been omitted to have both values in the same plot.*

Using this approach will work for applications where the so-called thermoviscous losses (close to walls in the acoustic boundary layers) are of little importance. The optimization domain can be coupled to narrow regions described by, for example, a homogenized model (this is the *Narrow Region Acoustics* feature in the *Pressure Acoustics, Frequency Domain* interface). However, if the narrow regions where the thermoviscous losses occur change shape themselves, this procedure is no longer valid. An example is when the cross section of a waveguide changes shape.

For microacoustic applications, such as hearing aids, mobile phones, and certain metamaterial geometries, the acoustic formulation typically needs to include the so-called thermoviscous losses explicitly. This is because the main losses occur in the acoustic boundary layer near walls. Figure 2 below illustrates these effects.

*Figure 2: The volume field is the acoustic pressure, the surface field is the temperature variation, and the arrows indicate the velocity.*

An acoustic wave travels from the bottom to the top of a tube with a circular cross section. The pressure is shown in a ¾-revolution plot.

The arrows indicate the particle velocity at this particular frequency. Near the boundary, the velocity is low and tends to zero on the boundary, whereas in the bulk, it takes on the velocity expected from standard acoustics via Euler’s equation. At the boundary, the velocity is zero because of viscosity, since the air “sticks” to the boundary. Adjacent particles are slowed down, which leads to an overall loss in energy, or rather a conversion from acoustic to thermal energy (viscous dissipation due to shear). In the bulk, however, the molecules move freely.

Modeling microacoustics in detail, including the losses associated with the acoustic boundary layers, requires solving the set of linearized Navier-Stokes equations with quiescent conditions. These equations are implemented in the *Thermoviscous Acoustics* physics interfaces available in the Acoustics Module add-on to the COMSOL Multiphysics® software. However, this formulation is not suited for topology optimization where certain assumptions can be used. A formulation based on a Helmholtz decomposition is presented in Ref. 1. The formulation is valid in many microacoustic applications and allows decoupling of the thermal, viscous, and compressible (pressure) waves. An approximate, yet accurate, expression (Ref. 1) links the velocity and the pressure gradient as

\vec{v}=\Psi_{v} \frac{\nabla{p}}{ik{\rho_0}c}

where the viscous field is a scalar nondimensional field that describes the variation between bulk conditions and boundary conditions.

In the figure above, the surface color plot shows the acoustic temperature variation. The variation on the boundary is zero due to the high thermal conductivity in the solid wall, whereas in the bulk, the temperature variation can be calculated via the isentropic energy equation. Again, the relationship between temperature variation and acoustic pressure can be written in a general form (Ref. 1) as

T=\Psi_{h} \frac{p}{{\rho_0}{C_p}}

where the thermal field is a scalar, nondimensional field that describes the variation between bulk conditions and boundary conditions.

As will be shown later, these viscous and thermal fields are essential for setting up the topology optimization scheme.

For thermoviscous acoustics, there is no established interpolation scheme, as opposed to standard acoustics topology optimization. Since there is no one-equation system that accurately describes the thermoviscous physics (typically, it requires three governing equations), there are no obvious variables to interpolate. However, I will describe a novel procedure in this section.

For simplicity, we look at only wave propagation in a waveguide of constant cross section. This is equivalent to the so-called Low Reduced Frequency model, which may be known to those working with microacoustics. The viscous field can be calculated (Ref. 1) via Equation 1 as

(1)

\Psi_{v}+ k_v^{-2} \Delta_{cd} \Psi_{v}=1

where is the Laplacian in the cross-sectional direction only. For certain simple geometries, the fields can be calculated analytically (as done in the *Narrow Region Acoustics* feature in the *Pressure Acoustics, Frequency Domain* interface). However, when used for topology optimization, they must be calculated numerically for each step in the optimization procedure.

In standard acoustics topology optimization, an interpolation variable varies between 0 and 1, where 0 represents air and 1 represents a solid. To have a similar interpolation scheme for the thermoviscoacoustic topology optimization, I came up with a heuristic approach, where the thermal and viscous fields are used in the interpolation strategy. The two typical boundary conditions for the viscous field (Ref. 1) are

\Psi_{v} = 0 \thickspace (no slip)

and

\nabla_{cd}\Psi_{v} = 0 \thickspace (slip)

These boundary conditions give us insight into how to perform the optimization procedure, since an air-solid interface could be represented by the former boundary condition and an air-air interface by the latter. We write the governing equation in a more general matter:

a_{v} \Psi_{v}+k_{v}^{-2}\Delta_{cd}\Psi_{v}=f_{v}

We already know that for air domains, (a_{v},f_{v}) = (1,1), since that gives us the original equation (1). If we instead set a_{v} to a large value so that the gradient term becomes insignificant, and set f_{v} to zero, we get

a_{v} \Psi_{v} = 0

This corresponds exactly to the boundary condition for no-slip boundaries, just as a solid-air interface, but obtained via the governing equation. We need this property, since we have no way of applying explicit boundary conditions during the optimization. So, for solids, (a_{v},f_{v}) should have values of (“large”,0). Thus, we have established our interpolation extremes:

a_{v}(\epsilon)= \left\{ \begin{array}{ll}1\ \textrm{for}\ \epsilon=o \thickspace(air) \\ large\ \textrm{for} \ \epsilon=1 \thickspace (solid) \end{array} \right.

and

f_{v}(\epsilon)= \left\{ \begin{array}{ll}1\ \textrm{for}\ \epsilon=o \thickspace (air) \\ 0\ \textrm{for} \ \epsilon=1\thickspace (solid) \end{array} \right.

I carried out a comparison between the explicit boundary conditions and interpolation extremes, with the test geometry shown in Figure 3. On the left side, boundary conditions are used, whereas on the adjacent domains on the right, the suggested values of a_{v} and f_{v} are input.

*Figure 3: On the left, standard boundary conditions are applied. On the right, black domains indicate a modified field equation that mimics a solid boundary. White domains are air.*

The field in all domains is now calculated for a frequency with a boundary layer thick enough to visually take up some of the domain. It can be seen that the field is symmetric, which means that the extreme field values can describe either air or a solid. In a sense, that is comparable to using the actual corresponding boundary conditions.

*Figure 4: The resulting field with contours for the setup in Figure 3.*

The actual interpolation between the extremes is done via SIMP or RAMP schemes (Ref. 2), for example, as with the standard acoustic topology optimization. The viscous field, as well as the thermal field, can be linked to the acoustic pressure variable pressure via equations. With this, the world’s first acoustic topology optimization scheme that incorporates accurate thermoviscous losses has come to fruition.

Here, we give an example that shows how the optimization method can be used for a practical case. A tube with a hexagonally shaped cross section has a certain acoustic loss due to viscosity effects. Each side length in the hexagon is approximately 1.1 mm, which gives an area equivalent to a circular area with a radius of 1 mm. Between 100 and 1000 Hz, this acoustic loss increases by a factor of approximately 2.6, as shown in Figure 7. Now, we seek to find an optimal topology so that we obtain a flatter acoustic loss response in this frequency range, with no regards to the actual loss value. The resulting geometry looks like this:

*Figure 5: The topology for a maximally flat acoustic loss response and resulting viscous field at 1000 Hz.*

A simpler geometry that resembles the optimized topology was created, where explicit boundary conditions can be applied.

*Figure 6: A simplified representation of the optimized topology, with the viscous field at 1000 Hz.*

The normalized acoustic loss for the initial hexagonal geometry and the topology-optimized geometry are compared in Figure 7. For each tube, the loss is normalized to the value at 100 Hz.

*Figure 7: The acoustics loss normalized to the value at 100 Hz for the initial cross section (dashed) and the topology-optimized geometry (solid), respectively.*

For the optimized topology, the acoustic loss at 1000 Hz is only 1.5 times higher than at 100 Hz, compared to the 2.6 times for the initial geometry. The overall loss is larger for the optimized geometry, but as mentioned before, we do not consider this in the example.

This novel topology optimization strategy can be expanded to a more general 1D method, where pressure can be used directly in the objective function. A topology optimization scheme for general 3D geometries has also been established, but its implementation is still ongoing. It would be very advantageous for those of us working with microacoustics to focus on improving topology optimization, in both universities and industry. I hope to see many advances in this area in the future.

- W.R. Kampinga, Y.H. Wijnant, A. de Boer, “An Efficient Finite Element Model for Viscothermal Acoustics,”
*Acta Acoustica*united with*Acoustica*, vol. 97, pp. 618–631, 2011. - M.P. Bendsoe, O. Sigmund,
*Topology Optimization: Theory, Methods, and Applications*, Springer, 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 Hearing 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 Hearing as a senior acoustic engineer in 2015. In this role, he works with the design and optimization of hearing aids.

]]>

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 Hearing 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 Hearing as a senior acoustic engineer in 2015. In this role, he works with the design and optimization of hearing aids.

]]>