Quantcast
Channel: Walter Frei – COMSOL Blog
Viewing all 90 articles
Browse latest View live

Modeling the Scattering of Light Off of an Object on a Substrate

$
0
0

A frequent modeling situation encountered in wave electromagnetics modeling is to compute the scattering of light off of a structure patterned on top of a uniform dielectric substrate. In this blog post, we will present one way to model such situations in the COMSOL Multiphysics® software.

Background and Overview

The case we will consider here is of a small scatterer of light: a half-cylinder of gold patterned on top of a dielectric substrate. We are interested in the case of just a single scatterer, and we will assume that the illumination is from a beam of collimated light that is so much larger in diameter than the scatterer, so that it can be well approximated as a plane wave. The plane wave can illuminate the structure at an arbitrary angle and state of polarization. The dielectric substrate is assumed to extend infinitely in the negative z direction. 

A schematic of a light incident on a single scatterer on a dielectric substrate.
Light incident at an arbitrary angle on a single scatterer on a semi-infinite dielectric substrate.

Since we want to model just a single scatterer that represents a relatively small perturbation in a background field, it makes sense to use the Scattered Field formulation. This formulation requires that we enter a background electric field that would represent the solution to Maxwell’s equations in the absence of the scatterer. That is, we solve Maxwell’s equations in their frequency-domain form:

\nabla \times \left( \mu_r \nabla \times \mathbf{E}_{total} \right) – \frac{\omega^2}{c_0^2}\left( \epsilon_r – \frac{i \sigma}{\omega\epsilon_0}\right) \mathbf{E}_{total}= 0

But write the total electric field as:

\mathbf{E}_{total} = \mathbf{E}_{relative} + \mathbf{E}_{background}

Rather than solving for the total field, we solve for the relative field, also often called the scattered field. The background electric field is the solution to Maxwell’s equations over the domains in question in the absence of the scatterer. For the simple case of an object in free space, the background field is simply a plane wave, as used in the RF Module benchmark example Computing the Radar Cross Section of a Perfectly Conducting Sphere, which compares the solution of this method against the analytic result. A similar example from the Wave Optics Module computes the scattering off of a gold nanosphere. One might be tempted to use the same approach for a dielectric half-space, but then the background field would be wrong. 

A schematic of an electric field at a dielectric interface without a scatterer.
The electric field at a dielectric interface, absent any scatterer, is the sum of the incident, reflected, and transmitted plane waves.

For the case of a scatterer on a semi-infinite lossless dielectric substrate, the equation for the background field must incorporate the reflection and refraction at the interface. One approach is to compute the background field based upon a separate analysis and use that computed field as the background field. This approach is demonstrated in the Scatterer on Substrate example from the Application Gallery. However, here we will instead look at directly entering the background fields for a light incident upon a dielectric half-space by using the analytic solution.

Using the Fresnel Equations to Define the Background Field

The Fresnel equations, along with Snell’s law, describe the reflection and transmission of a plane wave of light when incident upon a flat interface between two materials of different refractive index. These Fresnel equations begin with the definition of the plane of incidence, which is a plane described by the vector normal to the surface between the two materials, and the wave vector of the incoming plane wave. The incident electric field can be decomposed into a component that is purely perpendicular to this plane, called an s-polarized or TE wave, and one that is purely parallel to this plane, called a p-polarized or TM wave. For example, circularly polarized light is the sum of a TE wave and TM wave of equal magnitude, but 90° out-of-phase with each other. 

In the plane of incidence, we can use Snell’s law to relate the angle of the incident () and transmitted () light relative to the surface normal in terms of the refractive indices,  and , of the two materials:

\frac{\sin \theta_t}{\sin \theta_i} = \frac{n_a}{n_b}

Then, the Fresnel equations give us the reflection and transmission coefficients for the TE- and TM-polarizations:

\begin{array}
rr_{TE} = \frac{n_a \cos \theta_i – n_b \cos \theta_t}{n_a \cos \theta_i + n_b \cos \theta_t} \\
t_{TE} = \frac{2 n_a \cos \theta_i}{n_a \cos \theta_i + n_b \cos \theta_t} \\
r_{TM} = \frac{n_b \cos \theta_i – n_a \cos \theta_t}{n_b \cos \theta_i + n_a \cos \theta_t} \\
t_{TM} = \frac{ 2 n_a \cos \theta_i }{n_b \cos \theta_i + n_a \cos \theta_t}
\end{array}

A schematic showing the TE- and TM-polarized components of the incident plane wave.
The TE- and TM-polarized components of the incident plane wave have to be transformed from the plane of incidence back to the global Cartesian coordinates.

We must next transform these from the plane of incidence back into the global Cartesian coordinates to get the k-vector of the incident and transmitted beam. Following the convention that the plane of the interface is the xy-plane, and the incident beam of wavelength  is propagating in the negative z direction, we define the angle of incidence  as the angle from the z-axis, and the angle  as the rotation about the z-axis starting from the negative x-axis, as shown in the figure above. This lets us define the k-vectors of the incident beam as:

\mathbf{k}_i = \frac{2 \pi n_a}{\lambda_0} \left \\

And the transmitted beam:

\mathbf{k}_t = \frac{2 \pi n_b}{\lambda_0} \left

The k-vector of the reflected beam, , is similar to the incident beam, but of opposite sign for the z-component. 

Given an incident beam that is composed of both a TE- and TM-polarized component,  and , the components of the electric field of the incident beam are:

E_{i,x} = (E_{i,TM} \cos \theta_i \cos \phi – E_{i,TE} \sin \phi )\exp (-i\mathbf{k}_i \cdot \mathbf{x})
E_{i,y} = (E_{i,TM} \cos \theta \sin \phi + E_{i,TE} \cos \phi )\exp (-i\mathbf{k}_i \cdot \mathbf{x})
E_{i,z} = E_{i,TM} \sin \theta_i \exp (-i\mathbf{k}_i \cdot \mathbf{x})

And for the reflected components:

E_{r,x} = (-r_{TM} E_{i,TM} \cos \theta_i \cos \phi – r_{TE} E_{i,TE} \sin \phi )\exp (-i\mathbf{k}_r \cdot \mathbf{x})
E_{r,y} = (-r_{TM} E_{i,TM} \cos \theta_i \sin \phi + r_{TE} E_{i,TE} \cos\phi )\exp (-i\mathbf{k}_r \cdot \mathbf{x})
E_{r,z} = r_{TM} E_{i,TM} \sin \theta_i \exp (-i\mathbf{k}_r \cdot \mathbf{x})

So, the total background field on the incident side is , and of the other side of the interface, the field is , with components:

E_{t,x} = (t_{TM} E_{i,TM} \cos \theta_t \cos \phi – t_{TE} E_{i,TE} \sin \phi )\exp (-i\mathbf{k}_t \cdot \mathbf{x})
E_{t,y} = (t_{TM} E_{i,TM} \cos \theta_t \sin \phi + t_{TE} E_{i,TE} \cos \phi )\exp (-i\mathbf{k}_t \cdot \mathbf{x})
E_{t,z} = t_{TM} E_{i,TM} \sin \theta_t \exp (-i\mathbf{k}_t \cdot \mathbf{x})

These expressions can be entered as sets of variables defined over different domains within the COMSOL Multiphysics® software, and used as the background field definition. 

Sample Model and Discussion for Modeling the Scattering of Light

A sample model demonstrating this approach is set up and available via the link below. The electric field magnitude and the losses in a small half-cylinder of gold are plotted.

The electric field magnitude around a gold scatterer modeled in COMSOL Multiphysics.
Electric field magnitude around a gold scatterer on a dielectric substrate.

A simulation showing the scattering of light in a gold scatterer.
Losses in the gold scatterer.

Although this approach of entering the analytic background field is a little bit more work in terms of model setup, it is faster to run than the Scatterer on Substrate example, which first has to compute the background field. The merits of the latter approach would be when considering a case where the analytic solution is more difficult, or even impossible, to write out. So, for the case of a uniform dielectric substrate, this approach is likely always preferable.

Next Step

Try modeling a scatterer on a substrate using the analytic background field by clicking the button below. Note that you must be logged into a COMSOL Access account with a valid software license to download the MPH-file.


How to Use State Variables in COMSOL Multiphysics®

$
0
0

With the release of version 5.5 of the COMSOL Multiphysics® software, there is a feature for tracking the state, or history, of your model. The State Variable feature simplifies the tracking of the history of a field over time. These variables can also be used to affect other fields, such as material properties, and can thus be used to implement hysteresis into your model. Let’s look at this new functionality and see how to use it. 

The State Variables Interface

The State Variables interface is available when you enable the Variable Utilities option within the Model Builder, as shown in the screenshot below.

A screenshot showing the Show More Options dialog box with the Variable Utilities option selected.
How to enable the Variable Utilities option.

Once the option is enabled, you’ll see a Variable Utilities button within the Definitions ribbon, and a Variable Utilities submenu when you right-click the Component > Definitions branch within the model tree. Once you’ve added this feature, you can define variables on any geometric entity level, including:

  • Domains
  • Boundaries
  • Edges
  • Points

The settings for this feature are shown in the screenshot below.

A screenshot of the Settings window for the State Variables functionality in COMSOL Multiphysics.
The State Variables settings.

There aren’t many settings here that we need to look at, but there is a lot we can do with this feature.

Let’s start from the setting at the bottom of the window. The state variable can be updated either before each time step (or parameter step) or after. If you expect complex-valued numbers, enable the Allow complex values option.

Next, the Order controls at how many points within each element the state variables are saved. This order corresponds to the Gauss Point Data element order. An order of 0 would mean that, over each element, there is only a single state variable defined. The default order of 4 corresponds to the Gaussian integration points that are used by the quadratic element order used by most physics, but if you use different element orders, adjust this setting to be twice the order of the element. 

Finally, the State Components settings allow you to define several state variables, their initial conditions, and how they should be updated.

Let’s next look at some examples of how to use this functionality. 

Tracking the Maximum of a Field

Suppose that we have a transient model where the temperature is fluctuating in time. A good example of this is the Laser Heating of a Silicon Wafer example from the Application Gallery. We can track the maximum temperature that the part gets to by defining a state variable MaxT, with an initial value of 0 (or any value lower than or equal to the initial temperature field) and use this variable to store the maximum temperature via the update expression: 

if(T > MaxT,T,MaxT)

This if statement evaluates to true whenever, and wherever in space, the temperature field, T, is greater than MaxT, and then MaxT will take on the value of the temperature. Otherwise, MaxT remains equal to its current value. In this case, we would want to update the variable after each step. So, just as the temperature field varies in space and time, the state variable will also. 

A screenshot showing how to define a state variable, MaxT, in the State Variable Settings window.
The definition of the state variable MaxT.

When plotting the MaxT field, keep in mind that these state variables do not keep track of units and that the data, which is stored at the Gauss points, is extrapolated and interpolated over the entire element, so this field can look slightly different from the temperature field, which is stored at the node points and plotted via interpolation. The plot below shows what our results will look like. 

Simulation results showing the peak temperature over an entire simulation, tracked via a state variable.
A plot of the state variable that tracks the peak temperature achieved over the entire simulation time span.

Using the State Variable to Affect the Physics

Next, let’s use the State Variable feature to affect the same laser heating model.

Suppose that our wafer has a thin coating on the top that strongly affects the surface emissivity. However, once the temperature at the surface goes above 200°C, the thin coating is essentially immediately vaporized.

Our laser heating model already defines a Global Parameter called emissivity, which is a constant value of 0.8 and is used within the model to define both the absorbed and radiated heat. We can remove this constant global definition and instead define a state variable over the top surface, of the same name, with an initial value of 0.8, and with the update expression of:

if(T > 200[degC],0.2,emissivity)

This if statement triggers a permanent change to the state variable, emissivity, which is defined over the surface of the wafer and used by the Heat Flux and Surface-to-Ambient Radiation features. We would want to update this variable before each step. 

Implementing a Hysteresis Model

Let’s finish up with the more complicated example of hysteresis.

We will stick with solving for a temperature field, a topic which we’ve already discussed in a previous blog post, Thermal Modeling of Phase-Change Materials with Hysteresis, where we show that thermal hysteresis can be modeled by using two different functions for specific heat as a function of temperature, depending upon if the material is transitioning from the solid to the liquid state, or liquid to solid. Once the material becomes fully liquid, or fully solid, we will want to switch the function used to define the material properties. 

A schematic showing the phase change process of hysteresis.

To implement such a model, we need to introduce a switching state variable to decide if we should be following the lower or the upper branch. This switch can be based upon if the temperature rises above, or falls below, the two marked transition temperatures. So, introduce a state variable, SorL, with initial value of 1 (presuming the material is initially solid) and with the update expression:

if((T>T_top),0,if(T < T_bot,1,SorL))

This nested if statement will switch the value of SorL to 0 if the temperature rises above the upper threshold, and only switch it back to 1 if the temperature drops back below the lower threshold. The material property can then be conditional upon the  SorL state variable. For example, in this case, the heat capacity can be defined via an if statement as:

if(SorL,SolidtoLiquid(T),LiquidToSolid(T))

where SolidtoLiquid(T) and LiquidToSolid(T) are two different functions of temperature associated with the two different branches. 

Closing Remarks

The State Variables functionality makes some of our modeling work a lot more convenient and easier to use. We encourage you to try it out and see what other applications you can come up with. Happy modeling!

Try It Yourself

Download two of the examples featured in this blog post by clicking the button below. Note that you will need to be logged into a COMSOL Access account and hold a valid software license to download the files.

Exploiting Hardware Parallelism with COMSOL® Batch Sweeps

$
0
0

One of the core capabilities of the COMSOL Multiphysics® software is the ability to run batch sweeps, where multiple variations of the same model are solved in parallel, but in entirely separate jobs, on the same computer. With the ubiquity of higher-core count CPUs, and computers that support multiple CPUs, you can achieve significant speedups using this Batch Sweep functionality. Let’s find out how!

A Quick Introduction to Batch Sweeps

As anyone who follows computer hardware knows, every generation of processor technology brings significant improvements. For a long time, clock speeds increased year over year, but this trend has stagnated, and now, manufacturers are trending toward putting more and more cores into each CPU.

The COMSOL® software will, by default, use all available cores to solve each model, but this is not always necessarily beneficial. Many COMSOL Multiphysics models are only partially parallelizable, or even completely serial, so having more nodes dedicated to a single model may not, in and of itself, lead to a speedup, especially if the model is relatively small in terms of its memory requirements.

Practically speaking, this means that newer-generation multicore CPUs won’t necessarily run a single, relatively small COMSOL Multiphysics job much faster than older CPUs, but they will be able to run more jobs at the same time. This gives us a significant net improvement in cases where we are solving multiple variations of the same model, such as when sweeping over geometric dimensions, different operating conditions, or operating frequencies. The Batch Sweep functionality is meant for such cases.

Before we get to the usage of the Batch Sweep interface, there are a few important things to understand about its operation. First, Batch Sweep can start multiple entirely independent COMSOL Multiphysics processes, or jobs. These jobs have no knowledge of what the other jobs are doing. If one case fails, it will not affect anything else, but we also won’t be able to pass results between cases.

Second, each job will write files to disk that contain the results of that job, and optionally, all of these results can be combined back into the original file.

Third, while running these jobs, the software will automatically divide parallel jobs between the available computational cores.

Finally, the Batch Sweep is part of the core functionality of COMSOL Multiphysics. It is meant for running on a single computer (albeit quite possibly one with multiple CPUs), and it is available with any license type. It is the complement of the Cluster Sweep functionality (only available with the Floating Network License), which provides similar functionality, but can additionally divide jobs across different compute nodes of a cluster. 

The Settings of the Batch Sweep

To be able to use the Batch Sweep functionality, you must first enable the Batch and Cluster option within the Show More Options dialog box of the Model Builder. This dialog box is shown in the screenshot below.

The Model Builder in COMSOL Multiphysics with the Show More Options dialog box open.
The Show More Options dialog box within the Model Builder.

Once this is enabled, you will be able to add a Batch Sweep feature to the Study branch. This feature will always exist at the very top of the Study, and can be thought of as a for-loop that wraps around all of the other study steps that exist beneath it within that Study branch. 

<img src="//cdn.comsol.com/wordpress/sites/1/2020/05/batch-sweep-feature-settings.png" title="" alt="The Settings Window for the Batch Sweep feature, with the relevant settings highlighted.” width=”612″ height=”792″ class=”alignnone size-full wp-image-362311″ />
The relevant Batch Sweep feature settings.

The user interface for the Batch Sweep is shown above, with relevant features highlighted. First, at the very top, we specify the name of the parameter to sweep over and the number of different values of this parameter to study. Next, enabling the Synchronize solutions option will assemble all of the results back into a single file. If this is not enabled, then the batch sweep will just write a set of different files; one for each parameter in the sweep. (This may actually be an attractive option, as you can quickly get very large files, so it may also be worth considering if you want to save less data in each file.) The last key setting is at the bottom of the window: the number of simultaneous jobs, which determines how many jobs are run in parallel.

Also, keep in mind that the Batch Sweep can wrap around any other kind of sweep: Parametric, Function, Material, Auxiliary, or Frequency sweeps, so you can use a single Batch Sweep job to solve for an arbitrary combination of cases. 

So, what number of jobs should we actually be running in parallel? That is the next question that we will look at.

How Much Batch Parallelism Can COMSOL Multiphysics® Exploit?

The answer to this question, as you’ve probably already surmised, is both hardware and model dependent.

In terms of model types, the ideal case for the Batch Sweep is a model that is small in terms of memory requirements, but takes a relatively long time to solve.  A good example of such a model is the Laser Heating of a Silicon Wafer example. This model solves for the temperature evolution over time of a laser heat source moving over a rotating wafer. It has only about 2000 degrees of freedom, but takes about a minute of wall-clock time to solve on a typical desktop computer. There are a number of different parameters that we can sweep over in this model, so let’s see how this model’s performance scales with job parallelism on a typical modern desktop computer.

The results we will present were generated on an Intel® Xeon® W-2145 8-core processor with 32 GB RAM, a typical midrange computer as suggested in the COMSOL hardware recommendations. On this hardware, the test case model takes about one minute to solve. If we do a parametric sweep over 16 variations of the model, the solution time goes up about linearly with the number of different cases being solved. If we also use Batch Sweep, we can investigate running 2, 4, 8, and even 16 jobs in parallel on this hardware, with each batch sweep job containing a sequential parametric sweep, as shown in the screenshot below.

A screenshot of the settings for performing a nested batch sweep in COMSOL Multiphysics.
Screenshot showing a nested sweep. In this example, the outer Batch Sweep sweeps over N = 0,4,8,12, while the inner sweep results in 16 cases being solved in all.

The results below are presented in terms of time it takes to solve 16 cases and the relative speedup.

Parametric Sweep Batch Sweep + Parametric Sweep
16 sequential cases 2 parallel jobs
(8 sequential cases per job)
4 jobs
(4 cases/job)
8 jobs
(2 cases/job)
16 jobs
(1 case/job)
Time (Seconds) 1010 620 416 305 267
Speedup 1 1.6x 2.4x 3.3x 3.8x

Observe from this data that as we run more jobs at the same time, we get more speedup. Most interestingly, we can see that we can solve 16 jobs in parallel on an 8-core machine and still observe speedup. In other words, each of the cores of this CPU can actually handle two COMSOL® jobs at once, at least when solving this particular model. Hyperthreading is enabled on this machine, and although that doesn’t speed up the solution itself, file opening and closing and other OS processes benefit from having hyperthreading enabled. Now, running so many cases in parallel does slow down the time that it takes to solve each single case, but the overall time taken for all 16 cases is less. 

It’s also interesting to discuss what would happen if we tried to run more jobs in parallel, in terms of memory. This model needs about 1 GB of memory per batch job, and the test computer here has 32 GB RAM, so 16 parallel cases is no problem. But, if we went up to 32 parallel cases, we could exceed the available RAM, which would lead to a slowdown, regardless of the number of cores. Of course, on a computer with more RAM, more cores, and multiple CPUs, we can get even more relative speedup. Furthermore, COMSOL Multiphysics does not limit the number of cores, or CPUs, that can be addressed on a single computer. 

Now, these data look quite nice, and you are almost certainly tempted to ask at this point if you will always get results this good. Unfortunately, the answer is: not always. The larger the model that we solve, the less speedup we will see. For very large models, there will be an overall slowdown if you run jobs in parallel. However, for a great many models, especially most 2D models and smaller 3D models, you can reasonably expect similar improvement when using Batch Sweep on multicore, multi-CPU computers. So, the Batch Sweep functionality can strongly motivate investing in such hardware. Keep in mind that this is a core capability of COMSOL Multiphysics available with all license types!

 

Intel and Xeon are trademarks of Intel Corporation or its subsidiaries.

Video Lecture Series: Modeling Electromagnetic Coils in COMSOL®

$
0
0

Looking for a quick, guided introduction to electromagnetic coil modeling with the COMSOL Multiphysics® software and the AC/DC Module? We put together a series of video lectures that walk you through the modeling of electromagnetic coils, designed to show the key aspects of building such models. Let’s quickly review what’s in these videos and how to use the series to your best advantage!

Getting Started with Modeling Electromagnetic Coils

The simplest electromagnetic coil is a single turn of current-carrying wire, as you’ll see in almost any introduction to the topic. It’s often a reasonable engineering simplification to assume that the coil can be treated as a closed loop, meaning that it is axisymmetric, or invariant around the centerline.

A 2D axisymmetric model of a simple, one-turn coil.
A simple one-turn coil can also be modeled using a 2D axisymmetric assumption. 

It is with this assumption that our coil modeling lecture series begins. The first session contains five videos in which we’ll work in the 2D axisymmetric space.

Session 1 Videos

Once completing the videos in this introductory session, you will have seen the foundations for 2D axisymmetric coil modeling techniques.

Electromagnetic Heating in Coils

One of the common uses of COMSOL Multiphysics with the AC/DC Module and Heat Transfer Module is for modeling inductive heating, the process by which a coil is used to heat up a workpiece over time. In this second lecture session, we address this topic in depth.

A model of a workpiece undergoing inductive heating.
Workpiece being inductively heated over time, with nonlinear material properties. 

Session 2 Videos

Once completing this lecture session, you should be confident in addressing most coil heating problems.

Modeling of Forces, Motion, Nonlinearities, and More

The third lecture session addresses another kind of multiphysics: the coupling of electromagnetic forces to the deformation and motion of parts, such as in solenoids.

A plot of the displacement in a solenoid actuator over time, with an inlay of the 3D model.
Displacement of a solenoid actuator over time. 

Session 3 Videos

Modeling of 3D Coils

The last session in the coil modeling lecture series addresses issues related to modeling 3D coils. Although most of the concepts of coil modeling can be learned solely on a 2D axisymmetric model, there are some unique issues that need to be addressed in 3D.

Simulation results for the current magnitude and magnetic field of a 3D coil model.
A 3D coil model showing current magnitude on the coil and the surrounding magnetic field. 

Session 4 Videos

Once you’ve gone through this last session of lectures, you’ll have the foundations to solve 3D coil models. We hope that these videos will educate and inspire you to build coil models in COMSOL Multiphysics and the AC/DC Module, and do to so faster and with confidence in your modeling!

Computational Electromagnetics Modeling: Which Module to Use?

$
0
0

A question we get asked all of the time is: “Which of the COMSOL products should be used for modeling a particular electromagnetic device or application?” In addition to the capabilities of the core package of the COMSOL Multiphysics® software, there are currently six modules within the “Electromagnetic Modules” branch of our product tree, and another six modules spread throughout the remaining product structure that address various forms of Maxwell’s equations coupled to other physics. Let’s take a look through these and see what they offer. 

Note: This blog post was originally published on September 10, 2013. It has since been updated with additional information and examples.

Computational Electromagnetics: Maxwell’s Equations

Maxwell’s equations relate the electric charge density, ; electric field, ; electric displacement field, ; and current, ; as well as the magnetic field intensity, , and the magnetic flux density, :

\nabla \cdot \mathbf{D} = \rho
\nabla \cdot \mathbf{B} = 0
\nabla \times \mathbf{E} = -\frac{\partial}{\partial t} \mathbf{B}
\nabla \times \mathbf{H} = \mathbf{J} + \frac{\partial}{\partial t} \mathbf{D}

To solve these equations, we need a set of boundary conditions, as well as material constitutive relations that relate the  to the  field, the  to the  field, and the  to the  field. Under varying assumptions, these equations are solved, and coupled to the other physics, in the different modules within the COMSOL product suite. 

Note: Most of the equations presented here are shown in an abbreviated form to convey the key concepts. To see the full form of all governing equations, and to see all of the various constitutive relationships available, please consult the Product Documentation.

Let’s start off with a few concepts…

Steady State, Time, or Frequency Domain?

When solving Maxwell’s equations, we try to make as many assumptions as are reasonable and correct, with the purpose of easing our computational burden. Although Maxwell’s equations can be solved for any arbitrary time-varying inputs, we can often reasonably assume that the inputs, and computed solutions, are either steady-state or sinusoidally time-varying. The former is also often referred to as the DC (direct current) case, and the latter is often to as the AC (alternating current), or frequency domain, case. 

The steady-state (DC) assumption holds if the fields do not vary at all in time, or vary so negligibly as to be unimportant. That is, we would say that the time-derivative terms in Maxwell’s equations are zero. For example, if your device is connected to a battery (which might take hours or longer to drain appreciably), this would be a very reasonable assumption to make. More formally, we would say that: , which immediately omits two terms from Maxwell’s equations. 

The frequency-domain assumption holds if the excitations on the system vary sinusoidally and if the response of the system also varies sinusoidally at the same frequency. Another way of saying this is that the response of the system in linear. In such cases, rather than solving the problem in the time domain, we can solve in the frequency domain using the relationship: , where  is the space- and time-varying field;  is a space-varying, complex-valued field; and  is the angular frequency. Solving Maxwell’s equations at a set of discrete frequencies is very computationally efficient as compared to the time domain, although the computational requirements grow in proportion to the number of different frequencies being solved for (with some caveats that we will discuss later).

Solving in the time domain is needed when the solution varies arbitrarily in time or when the response of the system is nonlinear (although even to this, there are exceptions, which we will discuss). Time-domain simulations are more computationally challenging than steady-state or frequency-domain simulations because their solution times increase in proportion to how long the time span of interest is, and the nonlinearities that are being considered. When solving in the time domain, it is helpful to think in terms of the frequency content of your input signal, especially the highest frequency that is present and significant. 

Electric Fields, Magnetic Fields, or Both?

Although we can solve Maxwell’s equations for both the electric and the magnetic fields, it is often sufficient to neglect one, or the other, especially in the DC case. For example, if the currents are quite small in magnitude, the magnetic fields are going to be small. Even in cases where the currents are high, we might not actually concern ourselves about the resultant magnetic fields. On the other hand, sometimes there is solely a magnetic field, but no electric field, as in the case of a device composed only of magnets and magnetic materials.

In the time- and frequency domains, though, we have to be a bit more careful. The first quantity we will want to check here is the skin depth of the materials in our model. The skin depth of a metallic material is usually approximated as , where  is the permeability and  is the conductivity. If the skin depth is much larger than the characteristic size of the object, then it is reasonable to say that skin depth effects are negligible and one can solve solely for the electric fields. However, if the skin depth is equal to, or smaller than, the size of the object, then inductive effects are important and we need to consider both the electric and magnetic fields. It’s good to do a quick check of the skin depth before starting any modeling. 

As one increases the excitation frequency, it is also important to know the first resonance of the device. At this fundamental resonant frequency, the energy in the electric fields and magnetic fields are exactly in balance, and we would say that we are in the high-frequency regime. Although it is generally difficult to estimate the resonant frequency, a good rule of thumb is to compare the characteristic object size, , to the wavelength, . If the object size approaches a significant fraction of the wavelength, , then we are approaching the high-frequency regime. In this regime, power flows primarily via radiation through dielectric media, rather than via currents within conductive materials. This leads to a slightly different form of the governing equations. Frequencies significantly lower than the first resonance are often termed the low-frequency regime. 

Let’s now look at how these various different assumptions are applied to Maxwell’s equations, and give us different sets of equations to solve, and then see which modules we would need to use for each. 

Steady-State Electric Field Modeling

Under the assumption of steady-state conditions, we can further assume that we are dealing solely with conductive materials, or perfectly insulative materials. In the former case, we can assume that current flows in all domains, and Maxwell’s equations can be rewritten as:

\nabla \cdot \left( – \sigma \nabla V \right ) = 0

This equation solves for the electric potential field, , which gives us the electric field, , and the current, . This equation can be solved with the core COMSOL Multiphysics package and is solved in the introductory example to the software. The AC/DC Module and the MEMS Module extend the capabilities of the core package, for example, by offering terminal conditions that simplify model setup and boundary conditions for modeling of relatively thin conductive and insulative regions, as well as separate physics interfaces for modeling the current flow solely through geometrically thin, possibly multilayered, structures.

On the other hand, under the assumption that we are interested in the electric fields in perfectly insulating media, with material permittivity, , we can solve the equation:

\nabla \cdot \left( – \epsilon \nabla V \right ) = 0

This computes the electric field strength in the dielectric regions between objects at different electric potentials. This equation can also be solved with the core COMSOL Multiphysics package, and again, the AC/DC and MEMS modules extend the capabilities via, for example, terminal conditions, boundary conditions for modeling thin dielectric regions, and thin gaps in dielectric materials. Furthermore, these two products additionally offer the boundary element formulation, which solves the same governing equation, but has some advantages for models composed of just wires and surfaces, as discussed in this previous blog post.

Time- and Frequency-Domain Electric Field Modeling

As soon as you want to model time-varying electric fields, there will be both conduction and displacement currents, and you will want to use either the AC/DC Module or MEMS Module. The equations here are only slightly different from the first equation, above, and in the time-domain case, are written as:

\nabla \cdot \left( \mathbf{J_c +J_d} \right ) = 0

This transient equation solves for both conduction currents, , and displacement currents, . This is appropriate to use when the source signals are nonharmonic and you wish to monitor system response over time. You can see an example of this in the Transient Modeling of a Capacitor in a Circuit model.

In the frequency domain, we can instead solve the stationary equation:

\nabla \cdot \left( – \left( \sigma + j \omega \epsilon \right) \nabla V \right ) = 0

The displacement currents in this case are . An example of the usage of this equation is the Frequency Domain Modeling of a Capacitor model.

Magnetic Field Modeling with the AC/DC Module

Modeling of magnetic fields, in the steady-state, time-domain, or low-frequency regime, is addressed within the AC/DC Module. 

For models that have no current flowing anywhere, such as models of magnets and magnetic materials, it is possible to simplify Maxwell’s equations and solve for , the magnetic scalar potential:

\nabla \cdot \left( – \mu \nabla V_m \right ) = 0

This equation can be solved using either the finite element method or the boundary element method.

Once there are steady-state currents in the model, we must instead solve for , the magnetic vector potential. 

\nabla \times \left( \mu ^ {-1} \nabla \times \mathbf{A} \right)= \mathbf{J}

This magnetic vector potential is used to compute , and the current, , can be either imposed or simultaneously computed via augmenting with the previous equation for the electric scalar potential and current. A typical example of such a case is the magnetic field of a Helmholz coil

As we move to the time domain, we solve the following equation:

\nabla \times \left( \mu ^ {-1} \nabla \times \mathbf{A} \right)=- \sigma \frac{ \partial \mathbf{A}}{\partial t}

where .

This equation considers solely the conduction currents and induced currents, but not the displacement currents. This is reasonable if the power transfer is primarily via conduction and not radiation. One strong motivation behind solving this equation is if there are material nonlinearities, such as a B-H nonlinear material, as in this example of an E-core transformer. It should be noted, though, that there are alternative ways of solving B-H nonlinear materials via an effective H-B curve approach

As we move into the frequency domain, the governing equation becomes:

\nabla \times \left( \mu ^ {-1} \nabla \times \mathbf{A} \right) = -\left( j \omega \sigma – \omega^2 \epsilon \right) \mathbf{A}

Note that this equation considers both conduction currents, , and displacement currents, , and is starting to look quite similar to a wave equation. In fact, this equation can solve up to and around the resonance of a structure under the assumption that there is negligible radiation, as demonstrated in this example: Modeling of a 3D Inductor

For a more complete introduction to the usage of the above sets of equations for magnetic field modeling, also see our lecture series on electromagnetic coil modeling

It is also possible to mix the magnetic scalar potential and vector potential equations, and this has applications for modeling of motors and generators

In addition to the above static, transient, and frequency-domain equations in terms of the magnetic vector potential and scalar potential, there also exists a separate formulation in terms of the magnetic field, which is appropriate for modeling of superconducting materials, as in this example of a superconducting wire

Wave Equation Modeling in the Frequency and Time Domains with the RF or Wave Optics Modules

As we get into the high-frequency regime, the electromagnetic fields become wave-like in nature, as in the modeling of antennas, microwave circuits, optical waveguidesmicrowave heating, and scattering in free space, as well as scattering from an object on a substrate, and we solve a slightly different form of Maxwell’s equations in the frequency domain:

\nabla \times \left( \mu_r ^ {-1} \nabla \times \mathbf{E} \right) -\omega^2 \epsilon_0 \mu_0 \left(\epsilon_r – j \sigma/\omega \epsilon_0 \right) \mathbf{E} = 0

This equation is written in terms of the electric field, , and the magnetic field is computed from: . It can be solved either at a specified set of frequencies, or as an eigenfrequency problem, which directly solves for the resonant frequency of the device. Examples of eigenfrequency analysis include several benchmarks of closed cavities, coils, and Fabry–Perot cavities, and such models compute both resonant frequencies and quality factor. 

When solving for the system response over a range of specified frequencies, one can directly solve at a set of discrete frequencies, in which case the computational cost scales linearly with number of specified frequencies. One can also instead exploit hardware parallelism on both single computers and clusters to parallelize and speed up solutions. There are also Frequency-Domain Modal and Adaptive Frequency Sweep (also called Asymptotic Waveform Evaluation) solvers that accelerate the solutions to some types of problems, as introduced in a general sense in this blog post, and demonstrated in this waveguide iris filter example.

If you’re instead solving in the time domain with the RF or Wave Optics modules, then we solve an equation that looks very similar to the earlier equation from the AC/DC Module:

\nabla \times \left( \mu_r ^ {-1} \nabla \times \mathbf{A} \right)+ \mu_0 \sigma \frac{ \partial \mathbf{A}}{\partial t} +\mu_0 \frac{ \partial}{\partial t} \left( \epsilon_0 \epsilon_r \frac{ \partial \mathbf{A}}{\partial t} \right) = 0

This equation again solves for the magnetic vector potential, but includes both first and second derivatives in time, thus considering both conduction and displacement currents. It has applicability in modeling of optical nonlinearities, dispersive materials, and signal propagation. Time domain results can also be converted into the frequency domain via a Fast Fourier Transform solver, as demonstrated in this example

The computational requirements for these equations, in terms of memory, also are a concern. The device of interest, and the space around it, are discretized via the finite element mesh, and this mesh must be fine enough to resolve the wave. That is, at a minimum, the Nyquist criterion must be fulfilled. In practice, this means that a domain size of about 10 x 10 x 10 wavelengths in size (regardless of the operating frequency) represents about the upper limit of what is addressable on a desktop computer with 64 GB of RAM. As the domain size increases (or the frequency increases), the memory requirements will grow in proportion to the number of cubic wavelengths being solved for. This means that the above equation is well suited for structures that have characteristic size roughly no larger that 10 times the wavelength at the highest operating frequency of interest. There are, however, two ways to get around this limit.

One approach for solving for the wave-like fields around an object much smaller than the wavelength is the Time Explicit formulation. This solves a different form of the time-dependent Maxwell’s equations that can be solved using much less memory. It is primarily meant for linear material modeling, and is attractive in some cases such as for computing wideband scattering off an object in a background field

Another alternative exists for certain types of optical waveguiding structures, solved in the frequency domain, where it is known that the electric field varies quite slowly in the direction of propagation. In such cases, the beam envelopes method in the Wave Optics Module becomes quite attractive. This interface solves the equation:

\left( \nabla – i \nabla \phi \right) \times \mu_r ^ {-1} \left( \left( \nabla – i \nabla \phi \right) \times \mathbf{E_e} \right) -\omega^2 \epsilon_0 \mu_0 \left(\epsilon_r – j \sigma/\omega \epsilon_0 \right) \mathbf{E_e} = 0

Where the electric field is  and  is the envelope of the electric field.

The additional field, , is a so-called phase function that must be known, at least approximately, and specified as an input. Luckily, for many optical waveguiding problems, this is indeed the case. It is possible to solve for either just one, or two, such beam envelope fields at the same time. The advantage of this approach, when it can be used, is that the memory requirements are far lower than for the full-wave equation presented at the beginning of this section. Other examples of its usage include models of a directional coupler as well as modeling of self-focusing in optical glass

Deciding Between the AC/DC Module, RF Module, and Wave Optics Module

The dividing line between the AC/DC Module and the RF Module is a bit of a fuzzy line. It’s helpful to ask yourself a few questions:

  1. Are the devices I’m working with radiating significant amounts of energy? Am I interested in computing resonances? If so, the RF Module is more appropriate.
  2. Are the devices much smaller than the wavelength at the highest operating wavelength? Am I primarily interested int the magnetic fields? If so, the AC/DC Module is more appropriate.

If you’re right at the line between these, then it can even be reasonable to have both products in your suite of modules. 

Deciding between the RF Module and Wave Optics Module involves asking yourself about your applications. Although there is a lot of overlap in functionality in terms of the full-wave form of Maxwell’s equations in the time and frequency domains, there are some small differences in the boundary conditions. There are so-called Lumped Port and Lumped Element boundary conditions, applicable for microwave device modeling, which are solely part of the RF Module. Also keep in mind that only the Wave Optics Module contains the beam envelopes formulation. 

As far as material properties, the two products come with different libraries of materials: The RF Module offers a suite of common dielectric substrates, while the Wave Optics Module includes refractive indices of over a thousand different materials in the optical and IR band. For more details on this, and the other available libraries of materials, see this blog post. Of course, if you have specific questions about your device modeling needs, contact us

A summary of the approximate dividing lines between these modules is given in the figure below. 

A graph comparing the RF, AC/DC, and Wave Optics modules for electromagnetics analyses.

Ray Tracing with the Ray Optics Module

If you are modeling devices many thousands of times the wavelength in size, then it is no longer possible to resolve the wavelength via a finite element mesh. In such cases, we also offer a geometrical optics approach in the Ray Optics Module. This approach does not directly solve Maxwell’s equations, but instead traces rays through the modeling space. This approach requires only that reflective surfaces and dielectric domains, but not uniform free space, be meshed. It is applicable for modeling of lenses, telescopes, large laser cavities, as well as structural-thermal-optical performance (STOP) analysis. It can even be combined with the output of a full-wave analysis, as demonstrated in this tutorial model

Multiphysics Modeling

In addition to solving Maxwell’s equations on their own, one of the core strengths of COMSOL Multiphysics is solving problems where there are couplings between several physics. One of the most common is the coupling between Maxwell’s equations and temperature, wherein the rise in temperature affects the electrical (as well as the thermal) properties. For an overview of the ways in which these kinds of electrothermal problems can be addressed, please see this blog post

It is also common to couple structural deformations to electric and magnetic fields. Sometimes, this just involves deformation, but sometimes, this also involves piezoelectric, piezoresistive, or magnetostrictive material response, or even a stress-optical response. The MEMS Module has a dedicated user interface for electrostatically actuated resonators, wherein an applied electric field biases a device. Structural contact and the flow of current between contacting parts can also be considered in the context of electric currents modeling. 

Beyond just temperature and deformation, though, you can also couple Maxwell’s equations for electric current to chemical processes, as addressed by the Electrochemistry, Batteries & Fuel Cells, Electrodeposition, and Corrosion modules. In the Plasma Module, you can even couple to plasma chemistry, and with the Particle Tracing Module, you can trace charged particles through electric and magnetic fields. Lastly (for now!) our Semiconductor Module solves for charge transport using the drift-diffusion equations. Each of these modules is a topic in and of itself, so we won’t try to address them all right here. 

Of course, if you would like to discuss any of these modules in greater depth, and find out how it is applicable to your device of interest, don’t hesitate to contact us via the button below.

Modeling Waveguides that Support Multiple Modes 

$
0
0

Have you ever been in the situation where you are modeling a waveguide that supports multiple different modes at its highest operating frequency? As you might already know, such cases require a bit of care to handle. You might think that you need to explicitly account for all possible modes in your model in the COMSOL Multiphysics® software, but as it turns out, there can be a simpler way. Let’s find out more! 

The Rectangular Metallic Waveguide

Let us frame this discussion in the context of a very long rectangular metallic radio frequency waveguide. This is a convenient place to start, since the solutions are easy to derive by hand, but let’s quickly review what happens within such device. 

A model of a rectangular waveguide in COMSOL Multiphysics.
A rectangular waveguide excited with a TE10 mode and a lossy inclusion. 

Assuming that the walls of our long rectangular waveguide can be modeled as lossless perfect electric conductors (an adequate approximation of reality), we know that the tangential component of the electric field must be zero, but the normal component of the electric field can be nonzero on the walls. Furthermore, let’s assume that the excitation (which we won’t be modeling) injects fields with the electric field polarized parallel to the shorter axis of the rectangular waveguide cross section. In the image above, this means that the electric field is polarized purely in the z direction, and the electromagnetic fields propagate solely in the xy-plane.

We will further restrict the discussion to a waveguide that does not go up or down in the z direction, but we will consider a single, off-centered, lossy inclusion within the waveguide that extends through the entire height of the interior that will reflect, and absorb, some of the guided signal.

Under those assumptions, it is valid to simplify our discussion to a 2D model, as shown below, of just a short section of the waveguide around the inclusion. We will start by addressing the case of a waveguide operating just a little bit above the first cutoff frequency of the TE10 mode. The correspondence between such a 2D model and a full 3D model is demonstrated in this example of an H-bend waveguide.

A waveguide model in 2D with parts labeled.
Schematic 2D waveguide model. The port at the left both launches a TE10 mode and monitors reflection, while the port at the right monitors transmission. There is some loss within the off-center inclusion due to finite material conductivity. 

Such a model can be set up by drawing the geometry as shown, applying representative material properties, and using two Port boundary conditions — one at either end. The Port boundary condition imposes that the boundary is transparent to the specified mode, and also computes S-parameters when there is a single excited port.

The ports should be placed sufficiently far away from the inclusion such that the actual fields at that section of the waveguide are solely the guided modes, and not the evanescent component of the fields that will exist near the inclusion. It is unfortunately not possible to determine how far these evanescent fields extend, but a good rule of thumb is to place the port at least one-half wavelength away from any inclusions, and to study increasing this distance to see if this has any significant effect upon the results.

The settings for the excitation port are shown in the screenshot below. The only difference between the two ports is that, in the second port, Wave excitation at this port is set to Off

A screenshot of the Port Settings window used for modeling waveguides in 2D.
Relevant settings for exciting a 2D waveguide model with a rectangular mode.

Once we solve such a model, we can evaluate S-parameters, or we can integrate over the two port boundaries the power inflow/outflow. The sum of transmitted, reflected, and absorbed power within the inclusion should sum up the imposed power at the input port. If these integrals need to be computed very accurately, then a boundary layer mesh of one very thin element at the port boundaries is called for, as shown in the image below. This is only necessary for computing the power flow accurately; the S-parameter calculations are not as sensitive to the mesh.

The single boundary layer mesh, highlighted in magenta.
Mesh showing the single boundary layer mesh (magenta) at the two port boundaries. 

Multiple Waveguide Modes at Higher Frequencies

As we increase the operating frequency high enough, we get to the point where the next highest supported mode, the TE20 mode, can exist within this waveguide. We are still injecting solely the TE10 mode, but the off-center inclusion will interact with the TE10 mode and cause conversion into higher-order TE20 modes that will be both reflected and transmitted. 

The 2D waveguide model with off-center inclusion causing higher-order mode scattering.
At higher frequencies, the off-center inclusion causes scattering into higher-order modes. 

Accounting for this situation is really quite simple. We just have to add two more Port boundary conditions, one at either end, that allow the TE20 mode to pass through and monitor the fraction of the signal that goes into this mode.  

A screenshot of the settings for a Port boundary condition monitoring the TE20 mode.
Settings for a port that monitors the TE20 mode. 

Adding multiple Port boundary conditions to the same boundary is perfectly acceptable, and in fact necessary for correctness. If you do not do so, then the boundary will actually perfectly reflect any TE20 mode that propagates toward it, which would mean the results are incorrect. 

You may already see a difficulty: If the frequency is so high that there are many possible modes, you would have to add a Port boundary condition for each one. This is not a big problem for this 2D rectangular waveguide with only two modes supported, but suppose you have a 3D circular waveguide? This supports many more modes and might be quite tedious to keep track of.

Let’s now look at a different approach for this case.

Truncating with a PML Rather than with Multiple Ports

Rather than truncating the modeling domain with several Port boundary conditions, you can also truncate the modeling domain with a perfectly matched layer (PML) domain, which can absorb almost any type of field very well, as discussed in this previous blog post. The model is extended a small bit on either side, with an additional PML domain that acts to absorb any fields that are incident upon it, regardless of mode. By adding this PML, we no longer need to add any ports, other than the port launching our mode of interest. We do, however, need to add additional boundaries at which to monitor the transmitted and reflected fields, as shown in the schematic below. 

The 2D waveguide model when truncated with perfectly matched layers.
Schematic of model truncated with PMLs and using an interior port. 

The launching port does also have to be treated in a special way. We need to launch the wave from inside of the modeling domain. This requires that you enable the Activate slit condition on interior port option. When this option is enabled, you can apply the port to an interior boundary, switch the Power Flow Direction, and set the Port type to be Domain-backed, meaning that any waves reflected back toward the port will propagate through it, and into the domain behind the port. 

A screenshot of the Settings window for the slit port.
Settings for the interior domain-backed slit port.

Although we lose the ability to determine the fraction of energy reflected and transmitted into all of the different modes, we simplify our model setup by not having to account for each mode via a different boundary condition. If we are interested in finding just the transmission/reflection into one, or a few, of many modes, we could even combine the two approaches, adding interior slit ports to monitor only those modes of interest, since the PML will absorb all other modes.

Stacked images showing the simulation results for a 2D waveguide when using multiple ports or a single interior port and PMLs.
Results show agreement between these approaches of using multiple Ports (top) and a PML-truncated domain with a single interior Port (bottom).

The image above compares the results of the two approaches presented here, and shows agreement. This technique can be useful for any case where you have the possibility of multiple modes, or even other scattered fields, present at a boundary. The model developed here is also available via the link below.

Try Modeling Waveguides in COMSOL Multiphysics®

Modeling a Scatterer Near an Optical Waveguide

$
0
0

The dielectric slab waveguide is one of the conceptual building blocks in photonic structure design. Although most real structures are more complex than just a two-dimensional dielectric slab, we can still learn a lot about modeling from this case. Here, we will look at the case of a small lossy scatterer in the proximity of an optical waveguide, show how this interacts with the fields, and compute reflection and transmission along the waveguide, as well as losses and scattering.

Background

The schematic of the example case is shown below. A dielectric slab waveguide has a small circular metallic object nearby that will interact with the fields, lead to some losses within the material, and cause scattering of light into all directions. For the example of a waveguide without the nearby object, this case would reduce to a perfect dielectric slab waveguide, which is discussed in this model.

A dielectric slab waveguide in 2D, with parts including a lossy material, dielectric core, and dielectric cladding.
Schematic of a 2D dielectric slab waveguide with a lossy material in proximity to the core.

We will consider the case of a waveguide that is wide enough to support multiple modes, although we will restrict ourselves to just the example of the electric field polarized out of the modeling plane. (We can reasonably assume that either the electric or the magnetic field is polarized purely out-of-plane, and that there is no coupling between these two, as long as all materials are isotropic.) This simplifies our analysis a little bit.

A schematic showing the different ways the incident light guided along a waveguide can behave.
The incident light guided along the waveguide can be reflected, transmitted, absorbed, and scattered.

Before starting our modeling, it is worth doing a bit of manual bookkeeping, thinking of where the light is coming from, and where it is going. We will consider light propagating along the waveguide toward the scatterer, and that this incident light is the first, fundamental, mode. Due to the scatterer, some fraction of the incident light will be:

  1. Transmitted forward and of the same fundamental mode
  2. Transmitted forward, but converted into the second mode
  3. Reflected backward, and into the fundamental mode
  4. Reflected backward, and into the second mode
  5. Absorbed by the lossy metallic inclusion
  6. Scattered into other directions

Computing the transmission into the four possible guided modes of the waveguide (items 1–4) requires solely that we introduce four different numerical ports into the model, two on either side. As already discussed in a previous blog post, it is possible to introduce multiple interior slit port boundary conditions at boundaries within the modeling space. Modeling the absorption into the lossy material simply involves integrating the loss within the metallic object. It is the last quantity, the computation of the scattered light, that requires some special attention.

Computing Scattered Light

In general, the scattered light from the object near the waveguide can go in any direction. We do know, however, that light propagating along the axis of the waveguide must be one of the guided modes. So, if we draw a boundary normal to the propagation direction of light within the waveguide and integrate the power flow crossing this boundary, we know that this integral will be the sum of the guided light plus whatever scattered light is propagating nearly but not exactly parallel to the waveguide. The light that is guided along the waveguides is computed by the port transmittances and reflectances. So if we subtract this away, we are left with the scattered fraction. Now, since we are integrating across an interior boundary, we will want to make use of the up() or down() operators to evaluate the flux only on one side of the boundary. To integrate these accurately, we use a boundary layer mesh.

We can insert additional interior boundaries that are tangential to the waveguide, and also monitor the power flow across them. They will form a rectangular box along with the previous two boundaries. Integrating the power flowing out of this box gives us the total of all scattering and all light leaving as a guided mode.

The computational model for the optical waveguide scattering problem, with parts labeled.
Schematic of our computational model.

Along with monitoring the scattered light, we also need to make sure that the light that is propagating out of the modeling domain does not get reflected back. We do so via the usage of perfectly matched layers (PML), which do a very good job of absorbing most outgoing radiation with their default settings. However, for the PML’s adjacent to the waveguide, we can get a little bit better performance by adjusting the characteristic wavelength in the PML settings to be based upon the propagation constant of the first guided mode of the waveguide, because we do know that most of the power is still carried in this mode. This setting is shown in the screenshot below.

A screenshot of the settings for adjusting the perfectly matched layer (PML) wavelength in COMSOL Multiphysics.
Manual adjustment of the PML wavelength settings.

Simulation results showing a lossy dielectric scatterer near an optical waveguide.
Sample results showing a lossy metallic scatterer near a dielectric slab waveguide.

The results of our model are shown in the image above, and the model file is available for download via the link below. Whenever you are modeling a scatterer near a dielectric waveguide you will want to use the combination of modeling techniques developed here.

Try It Yourself

Get the model discussed in this blog post by clicking the button below, which will take you to the Application Gallery (note that you must be logged into COMSOL Access with a valid software license to download MPH-files).

Video Lecture Series: Modeling Joule Heating with Thermal Expansion

$
0
0

As part of our recurring video lecture series, we posted a five-part tutorial video that covers the usage of the COMSOL Multiphysics® software for modeling Joule heating and thermal expansion. Over five video chapters, we provide a complete tutorial of how to get started in this area, and the series is a great resource for anyone interested in learning the software in general. Let’s review this lecture series and point out some related resources as well.

Getting Started with Joule Heating and Thermal Expansion

Many common engineering problems involve Joule heating, the rise in temperature of a conductive material as current passes through it. We start off this lecture series by introducing a relevant problem of interest, the heating of a set of bond wires connecting a chip to a circuit board. For this example, we concern ourselves solely with these bond wires.

A square chip with bond wires, where thermal stresses are visualized in a blue, teal, magenta, and red color gradient.
Bond wires on a chip. As current passes through the wires due to an applied electric potential difference, there is Joule heating, which leads to a variation in temperature, and resultant structural expansion and thermal stresses.

Watch the Electro-Thermal-Mechanical Modeling lecture series here.

Chapter 1

The first chapter begins by demonstrating how to import the CAD geometry of the chip. In this example, we work with a COMSOL native CAD file, although there are other options for working with CAD files.

Next, we set up the problem of computing the electric currents through the wire by applying a potential difference. From there, we examine the mesh and use virtual operations to remove some small geometry features to simplify the mesh, and then we solve and visualize the results.

Chapter 2

The second chapter builds upon the first. We use integration to extract numerical data from the model and investigate the mesh refinement of the model, a necessary part of building any finite element model. From there, we expand our model to solve for the temperature field within the bond wire. We use coordinate-based and Boolean selections to define the thermal boundary conditions that prescribe temperature and radiation, and also approximate free convection.

Chapter 3

In the third chapter, we introduce material nonlinearities by making both the electrical and the thermal conductivity functions of the temperature field. This can lead to some surprising results, which we discuss in more detail during the lecture. We also introduce some more options for electrical excitation and for evaluating the results.

Chapter 4

In the fourth chapter, we give an overview of the solver algorithms and how to interpret the information the software is reporting. For those interested in more details on this topic, see this Knowledge Base entry. We also discuss the limitations of the stationary assumption and when you should switch to a transient analysis and demonstrate how to compute the temperature rise over time. Lastly, we extend our model to include thermal expansion and discuss different solution approaches.

Chapter 5

Finally, in the fifth chapter, we continue modeling the deformation and also incorporate user-defined meshing, as well as adaptive mesh refinement, to gain confidence in our solution. From there, we move on to consider other geometries and also show how to present visually attractive results. Then, we turn the model file into a standalone application using the Application Builder (see the Introduction to Application Builder documentation to learn all about it).

Closing Remarks

The Electro-Thermal-Mechanical Modeling lecture series is meant to provide not only an introduction to the topics of Joule heating and thermal expansion but also to give a thorough overview of the usage of the software, so it will be useful to anybody who is just getting started.

The example chosen here is quite similar to one of the examples we use in the Introduction to COMSOL Multiphysics user’s guide, which is another great resource if you prefer to follow a written approach as an introduction to the software. Once you’ve gone through this material, you will have a firm foundation in the usage of COMSOL Multiphysics and will be ready to tackle even more challenging topics!

Try It Yourself

The geometry files and the model files used during this lecture series are available in the Application Gallery. To access the MPH-files, you will need to be logged into a COMSOL Access account with a valid software license.


Equation-Based Modeling with a Space-Time Discretization

$
0
0

One of the core strengths of the COMSOL Multiphysics® software is that you can modify almost any expression in your computational model. This functionality must be used with care, but you can do great things with it. Let’s take a two-dimensional (2D) thermal model with translation, set some material properties to zero, and observe that this is analogous to solving a 1D transient model. We will then see how this makes some types of optimization problems easy and fast to implement.

Going from 2 Spatial Dimensions to 1 Spatial Dimension and 1 Time Dimension

A schematic showing a 2D stationary thermal model that is analogous to a 1D transient model, which illustrates a space-time discretization problem.
Schematic of a 2D stationary thermal model that is analogous to a 1D transient model.

Let’s consider a very simple-looking 2D heat transfer model of a rectangle. We will solve the stationary (time-invariant) heat transfer governing equation for temperature, , in the absence of volumetric heating but with a convective term, , as follows:

\rho C_p \mathbf{u} \nabla T + \nabla \cdot \mathbf{k} \nabla T = 0

Where is the material density; the specific heat; and is the thermal conductivity, which in this case is a diagonal matrix of the form:

\mathbf{k}= \begin{bmatrix}k_{xx} & 0\\0 & k_{yy}\end{bmatrix}

It is helpful to write out the governing equation in a little bit more detail by expanding out all terms:

\rho C_p \left( u_x \frac{\partial T}{\partial x}+ u_y \frac{\partial T}{\partial y}\right) + \frac{\partial}{\partial x} \left(k_{xx} \frac{\partial T}{\partial x}\right)+ \frac{\partial}{\partial y} \left(k_{yy} \frac{\partial T}{\partial y}\right)= 0

Now we will do something interesting: We will assume that the velocity vector is purely in the +y direction, so , and we will set the y-component of the diagonal thermal conductivity tensor to zero, . Now the above equation reduces to:

\rho C_p u_y \frac{\partial T}{\partial y} + \frac{\partial}{\partial x} \left(k_{xx} \frac{\partial T}{\partial x}\right) = 0

Setting a term in the thermal conductivity tensor to zero might seem quite unusual, but it gives us an interesting benefit, which becomes apparent when we write out the 1D, transient, heat transfer governing equation without volumetric heating or a convective term:

\rho C_p \frac{\partial T}{\partial t} + \frac{\partial}{\partial x} \left(k_{xx} \frac{\partial T}{\partial x}\right) = 0

Note that the first terms in the two equations above look almost identical, and if we choose the velocity term correctly, the two equations will be identical. So now we have something quite interesting: Our 2D stationary model appears to be the same as a 1D transient model.

In fact, the equations are identical, but when we solve them numerically, there are some things to be aware of. First, applying a fixed temperature condition at the bottom boundary of the 2D domain is analogous to the initial condition for the transient 1D case. Second, for such a 2D model it makes sense to have a mapped mesh (aligned with the y-axis) and the number of elements in the y direction can be thought of as a fixed time step. This is quite different from the time-domain model, which uses adaptive time stepping by default. The 2D model will also (by default) include numerical stabilization terms that will make the results slightly different between the two, unless one of the models went to a high level of mesh and tolerance refinement.

The next question is, of course: What can we do with this? To see how this can be useful, let’s look at a classic 1D heat transfer model where a slab of material is heated, as shown in the image below. Despite its apparent simplicity, a great many problems of engineering interest reduce to this classic case. As we heat the material from the left surface, the entire volume of material gets gradually, but nonuniformly, hotter. There is also radiative cooling and some free convection from the left side, approximated as a constant heat transfer coefficient.

An illustration showing how transient heating problem can be reduced to a 1D model.
The transient heating of a slab of material can be reduced to a 1D model.

This problem can be solved in COMSOL Multiphysics by setting up a 2D rectangular domain and using the Heat Transfer in Solids and Fluids physics interface. Within this interface, you can apply a Translational Motion subfeature to the Solid feature, a Temperature boundary condition at the bottom boundary, Heat Flux and Surface-to-Ambient Radiation features along the left side to model convective and radiative cooling, and another Heat Flux condition to impose a heat load. Sample results with a uniform heat load over the time axis are shown below.

2D simulation results for the transient heating in a 1D material slab model, as well as the mesh.
Sample results of a 2D stationary model representing the transient heating of a 1D slab. The mesh is shown as well.

Suppose now that we want to optimize this heating process. Let’s try to vary the imposed heat load over time with the objective that the temperature throughout the entire slab be as close to a target temperature as possible at the end of our simulation time, and also consider a constraint that the peak temperature never gets over a specified limit. By having a 2D version of our 1D slab, it turns out that this optimization problem is quite easy to set up. Let’s find out how!

Defining the Optimization Problem

The Density Model feature within the Topology Optimization branch of the Definitions is used to define the variable controlling the heat flux over time. This feature defines a field over a boundary that is constrained to be between 0 and 1, representing no heating and maximum heating. The discretization of this field is linear, meaning that over each element along the time axis the heat load can vary linearly, and thus the heat load could vary over a timespan determined by our mesh size in the y direction. This is not ideal — It implies the heat load is changing as quickly as our time step. We instead want the heat load to vary in time slower than our discretization. So we need to take one more step, and that is to introduce a Helmholtz filter. This is a popular idea in the field of topology optimization, and it available within the Filtering section of the settings. The Filter radius need simply be larger than the mesh size, and represents a smoothing time. The name of this filtered control variable field is dtopo1.theta, and multiplies the incident heat flux.

A screenshot of the Topology Optimization Density Model feature Settings window.
Screenshot of the Topology Optimization Density Model feature, defined along the heated side of the slab, and over the entire axis representing time.

Our objective expression is shown in the screenshot below, it is an Integral Probe over the top boundary (representing the final time.) The expression that is integrated is based upon the computed solution, T, and T_target, the temperature we want to get to. By defining an objective that is the integral of the squared difference between the computed and target temperature over this boundary, we have a differentiable function that has a minimum when the final temperature is as close as possible to the target. The name of our objective is comp1.obj, which we will refer to from the Optimization study step.

A screenshot of the Settings window for the Objective Probe feature in COMSOL Multiphysics.
Screenshot of the Objective Probe feature, defined over the top boundary, defining the expression that is our objective to minimize.

We have a constraint, defined within the Optimization interface, that is:

comp1.constr < 1

This expression, comp1.constr, is defined via a Global Variable Probe, as shown in the screenshot above. The expression takes first the average of:

\left( \left( \frac{T}{T_{max}}\right)^{p_{exp}} \right)

over the heated boundary, and then takes the -th root. This is the P-norm. As approaches infinity, this constraint will enforce that the temperature not rise above a maximum temperature along the heated boundary. Now, for numerical reasons, cannot be infinity and this constraint cannot be exactly satisfied, but if is large enough, then the constraint is nearly satisfied. If is set too large, then we introduce a very nonlinear constraint function that slows convergence and also some possible numerical overflow issues, so think of this value as a tuning parameter in the model.

A screenshot of the Global Variable Probe settings for the probe used to define the constraint expression.
Screenshot showing the probe that defines the constraint expression.

The Optimization study step within the Study branch, which you get as part of the Optimization Module, allows us to introduce objectives, constraints, and control parameters. The objectives and constraints can be global variables, such as the probes mentioned above. Let's look at the setup for this case.

A screenshot of the Settings window for the Optimization study step.
Screenshot of the Optimization study step within the Study branch, defining the Optimization solver type, the objective, the design variables, and constraints.

The screenshot above shows the Optimization study step within the Study branch. It is within this feature that we define the optimization solver, the objective function, the design variables, and the constraints. At the top of the settings, we see that the SNOPT solver is used. This solver expects that the objective function, and constraints, are differentiable with respect to the design variables. The Optimality tolerance and Maximum number of model evaluations govern how many iterations the solver will take it its attempts to find the optimum. The next three sections define the Objective Function, the Control Variables and Parameters, and the Constraints.

With the objective function, design variables, and constraints defined, it is now just a matter of solving the model.

A graph plotting the results for design variable, filtered design variable, and temperature.
Plot of the design variable, filtered design variable, and temperature along the axis representing time.

A plot comparing the temperature to the target temperature of the material slab at the final time in the simulation.
Temperature (in blue) compared to the target temperature (in black) at the final time, showing that the temperature field is very near to the target temperature over the 1D domain.

This model, which includes a material nonlinearity in the thermal conductivity, takes about a minute to optimize to the solution shown in the figures above, which plot the temperature of the heated side of the slab over time, the filtered variable and unfiltered design variable, as well as the final temperature through the cross section of the slab. It is particularly interesting to observe that the optimization solver finds a solution that leads to peak heating at the very beginning, with a heat load gradually decreasing so as not to exceed the constraint on peak temperature, and then going to zero as the temperature field equilibrates toward the optimum throughout the slab, with a final short duration increased heating to counteract the cooling to ambient. Thus, it is possible to explain the solution in a qualitative sense, but it would be difficult to get it right for a specific situation without optimization.

At this point, you might be asking yourself what the advantage of this approach is. In fact, you could just as well solve the entire optimization problem purely in the time domain, so what has been gained? Speed and simplicity.

By reformulating into space-time, we now solve a stationary optimization problem, which is faster to solve than a transient optimization problem. We can also use the built-in topology optimization features including the Helmholtz filter, thus making it very easy to set up an arbitrary, constrained, smoothed, forcing function over time. So what is the drawback, other than some conceptual complexity? This technique will use more memory. By solving in space and time simultaneously, our system matrix gets larger in proportion to the mesh along the time axis, and this mesh has to be fixed prior to the simulation. For such a 2D model, though, the memory requirements are quite modest, even with a very fine mesh.

The memory requirements for a model with two spatial dimensions do get larger, but still not exorbitantly so. An example of such a case of optimizing a 2D model with the third dimension being time is also presented via the link below and includes the Electric Currents physics in addition to heat transfer to model Joule Heating optimized over time. Otherwise, it uses the same techniques developed here. Happy modeling!

Try It Yourself

Try optimizing a heat load over time using a space-time model. Click the button below to access the model file. (Note: You need to be logged into a COMSOL Access account with a valid software license in order to download MPH-files.)

Using Discontinuous Meshes for Conjugate Heat Transfer Modeling

$
0
0

Did you know that the COMSOL Multiphysics® software allows you to have different discontinuous meshes in neighboring domains? Although the usual default behavior of the software is to use aligned meshes, there are times when we might like to have discontinuous meshes, such as for modeling conjugate heat transfer. Let’s delve deeper into this topic and see how these meshes can save us time and memory in our initial model development with just a little bit more effort.

Maintaining the Continuity of the Fields and Balancing the Fluxes Between Aligned Elements

The basic theory behind the finite element method (FEM) has been covered several times (such as in this blog post on the weak form), so we won’t go over it all here. Instead, we will review one key point: What happens at the interface between different finite elements? In short: When the standard FEM is used, adjacent aligned elements share the same node points (the node points are the points at which the solution to the problem is computed). Since these elements share nodes, the fields being solved for (such as temperature, solid displacement, fluid velocity, etc.) are automatically continuous.

A schematic showing the flux between two aligned mesh elements.
Fluxes are automatically balanced between elements of different domains and these elements share the same nodes, so the fields are continuous.

Furthermore, the fluxes are naturally enforced to be equal (although this requires a bit more thorough understanding of the derivation of the FEM). Now, the term flux can refer to different quantities, depending upon the physics we are working with. For brevity, we will just consider heat transfer, where we naturally speak of the heat flux, which is the thermal conductivity times the negative of the gradient of the temperature field, or . At boundaries between elements, the FEM automatically (that is, without needing any user input or additional internal equations) enforces the condition that , where is the normal vector to the boundary between elements. That is, the standard FEM naturally enforces the continuity of the fields and balances fluxes. Do keep in mind that, regardless of this, you will always need to do a mesh refinement study to gain confidence in the overall accuracy of your model.

A schematic of a cross-flow heat exchanger submodel.
Schematic of a submodel of a cross-flow heat exchanger.

Let’s now take a look at a sample model from the Application Gallery, the Cross-Flow Heat Exchanger, which is schematically pictured above. This is a submodel of a larger heat exchanger consisting of straight rectangular channels. The fluid flow through the channels is modeled, as is the temperature field in the fluid and the surrounding solid. The temperature field is plotted below. The temperature is also plotted along a representative line along the length of the flow channel. Observe from these plots that the temperature variation along the flow channel is varying quite slowly along the length, quickly over the cross section of the flow channel, and in a quite complicated way through the metal part.

Results plots showing the temperature field in different parts of a cross-flow heat exchanger.
Temperature field at the walls and isosurfaces of temperature in the solid (top) and the plots of temperature along the flow channel directions (bottom).

The mesh is plotted below, and we can see that it is continuous between the fluid domain and the solid domain. The mesh is composed primarily of tetrahedral elements, with a boundary layer mesh applied on the fluid side of the channel walls to resolve the high velocity and thermal gradients near the wall.

An image showing the default mesh of a heat exchanger model in COMSOL Multiphysics.
Default mesh of the cross-flow heat exchanger that is continuous between the fluid and solid.

Now, this default mesh is generated with no user interaction at all. But what if we wanted to manually build the mesh, and what if we allowed the mesh to be discontinuous — what could we do then? Before we get to how to implement that, let’s take a look at what the software will need to do.

Maintaining the Continuity of the Fields and Balancing the Fluxes Between Nonaligned Elements

Suppose we have a set of elements on two adjacent domains, as shown in the image below. The elements have adjacent boundaries, but the nodes are nonaligned. This kind of mesh is automatically generated when the Form Assembly geometry finalization step is used. The meshes of separate objects will not be connected, so as a consequence, the fields across this boundary will be as discontinuous, with no flux between the domains.

A schematic of the equations required for COMSOL to handle nonaligned meshes.
For nonaligned meshes, additional equations must be introduced to approximately balance fluxes and fields.

However, the Form Assembly operation can also automatically create so-called Identity pairs at the adjacent boundaries between objects. Within each physics, you can then apply boundary conditions to these pair boundaries. Depending upon the physics interface, different boundary conditions will be available, but in all cases, the Pair Continuity condition will be available. This condition enforces the continuity of the fields, and the fluxes, across the boundary in an element-averaged sense. It does so by adding an additional set of equations behind the scenes, which we won’t go into here. Since the elements are not exactly aligned, the fields and fluxes cannot be pointwise continuous, which is a drawback; however, we can now have different meshes in adjacent domains, which has advantages. Let’s look at how this benefits us in the case of this cross-flow heat exchanger.

As we saw earlier, the temperature variation along the flow channel is quite gradual. Since the flow is laminar and the channels are uniform in cross section, we also know that the flow field is nearly invariant along the flow directions. Therefore, we can apply a swept mesh in the channels along the direction of the flow, as shown in the image below. Observe that far fewer elements are used in the flow direction, thereby reducing the problem size with only a small loss in accuracy as compared to the previous mesh.

An image of a heat exchanger model meshed with assembly meshing.
With assembly meshing, a swept mesh in the fluid channels allows for an elongated mesh with fewer elements.

Now, there are a few additional manual steps that we have to take to set up this mesh. First, within the Geometry sequence, we have to define two different objects. The first object is the metal part, the solid through which the fluid flows. The second object is the combination of all of the fluid flow domains; that is, a single object that is composed of several different domains, which are created via Boolean Union operations in the geometry sequence. We do need to ensure that these domains are nonoverlapping for the Form Assembly finalization operation to be valid, and then the software will automatically recognize all mating faces between these objects as identity pairs.

A screenshot of the settings for a feature with discontinuous meshes.
The Form Assembly geometry finalization that automatically creates Identity pairs.

Next, within the Heat Transfer in Solids and Fluids interface, we need to add a Pair Continuity boundary condition. Since we only have two adjacent objects (the solid and all of the fluid domains), this condition needs to be applied just to a single Identity Boundary Pair. No other changes to the physics are necessary.

A screenshot of the Pair Continuity boundary condition settings.
The Pair Continuity boundary condition that enforces continuity of fields and balances fluxes.

Finally, the Mesh sequence has to be manually modified. The default meshing sequence will copy the elements on the mating faces of the pair boundary, but we will want to disable this and apply a swept mesh that is elongated along the length of the flow channels. Since we know the solution varies quite gradually in this direction, the modification is justified. No other significant changes are made to the mesh, as compared to the automatically generated mesh shown earlier.

A screenshot of the meshing sequence for the heat exchanger model.
The meshing sequence used to control the number of elements along the flow directions in the channels.

The temperature field and the difference in the temperature field are plotted below. The model using the swept mesh is, of course, going to be different. In this case, the temperature field differs by about 2°C in some regions compared to the previous case. This difference is primarily due to the difference in the mesh across the interface. It is not due to the additional pair continuity equations. In the limit of mesh refinement, both approaches will converge to the same solution. The primary advantage of using assembly meshing is that you can begin with a relatively coarser mesh that will still give reasonable results, thereby saving time and computational resources in your initial model development.

Results plots comparing the temperature field found via assembly and default meshing.
Temperature field (top) using assembly meshing and the difference in this temperature field (bottom) as compared to the default mesh.

In the case of this geometry, we could also divide our geometry in a different way. We could split our model up into two objects along the plane between the flow channels, as shown in the image below. Now, we can lower the element count even more. Although not all geometries lend themselves to this subdivision, this approach can even further reduce the element count.

A conjugate heat transfer model meshed using identity pairs within the solid.
An alternative meshing strategy would introduce the identity pair within the solid rather than at the fluid-solid boundary.

Closing Remarks

We have shown here that assembly meshing is a useful technique for reducing the number of mesh elements. This is particularly applicable for conjugate heat transfer problems, since these often contain relatively uniform flow channels that lend themselves to swept meshing. Although here we have considered a model involving laminar flow, this approach will also work for turbulent flow problems. Keep in mind, though, that this technique has its place in preliminary model development: You’ll usually want to verify these models against a model with a congruent mesh and, of course, always do a mesh refinement study. The key advantage is that you can more quickly do preliminary analyses.

The model using the assembly meshing capability is available for download here:

Accelerating Model Convergence with Symbolic Differentiation

$
0
0

Did you know that the COMSOL Multiphysics® software includes a symbolic differentiation engine that is automatically used whenever you set up and solve a nonlinear problem? This feature ensures high robustness of the software when solving such models, but it does come with some costs. Today, we will look at this capability in a few different examples and examine its benefits and tradeoffs.

Solving a Simple Nonlinear Problem with Symbolic Differentiation

Let’s start by looking at a relatively simple, single degree of freedom, nonlinear problem — the implicit equation:

T=Q/(1+T^2/100)

We can say that represents a lumped temperature of a system; represents a heat load; and the denominator of the above equation, , represents a system thermal conductance.

We want to solve for different values of the parameter . The solution to such a nonlinear problem can be found via the damped Newton’s method, which can be done in COMSOL Multiphysics by writing out the residual:

r(T)=T-Q/(1+T^2/100)

and then entering it into the Global Equation interface, as shown in the screenshot below.

A screenshot of the Global Equation interface in COMSOL Multiphysics, with a residual to solve a nonlinear equation.
The Global Equation interface, used to solve our nonlinear equation.

We can solve this equation for a range of different values of and plot the solution, as shown below.

A graph plotting the solution to a nonlinear problem with a single degree of freedom.
Solution to a single degree of freedom nonlinear problem.

For illustrative purposes, let’s plot out the residual for a range of values of , and for select values of , in the plots below. The dots at the zero crossing are the solution from the above plot.

A graph plotting the residual for different values of Q, which represents the heat load in a nonlinear problem.
Plot of the residual for different values of the parameter . The value of from the zero crossing is the solution to the nonlinear equation.

Let’s also plot out the corresponding derivative of the residual (the Jacobian) for the same range of and values of below.

A graph plotting the derivative of the residual for different values of the heat load, Q.
Plot of the derivative of the residual for different values of .

We see that, for increasing values of , the Jacobian is a more nonlinear function. We can also (for this simple case) manually write out the derivative:

\frac{\partial r(T)}{\partial T}=1+\frac{2TQ}{100(1+T^2/100)^2}

Keep in mind that the software is automatically able to take this derivative via symbolic differentiation and use it within the Newton steps.

Now, it is the denominator of the second part of the residual that makes this expression a bit complicated (recall that this term can be thought of as the thermal resistance of the system). It turns out that we can ignore this term, if we want, by wrapping the nojac() operator about the term in the denominator:

R(T) =(T – Q/nojac(1+T^2/100))

and modifying the Global Equation, as shown in the screenshot below.

The Global Equations Settings window in COMSOL Multiphysics demonstrating how to use the nojac() operator.
Screenshot showing how to use the nojac() operator.

As a result, everything within the nojac() operator will be ignored by the symbolic differentiation engine. That is, the terms within this operator have no contribution to the Jacobian. The derivative of the residual with respect to is now simply:

\frac{\partial r(T)}{\partial T}=1

We can see by examination that this simplified derivative is only a good approximation for low values of , and the effect is that the solver is not able to converge to the solution for all values of . So, we have made the problem a bit simpler by avoiding the (in this case very small) overhead of taking the derivative of some terms, but we have made it unsolvable in some cases.

Using the nojac() Operator in COMSOL Multiphysics®

Let’s also consider a couple of other ways in which we could use the nojac() operator.

If we were to write our global equation as:

R(T) = nojac(T – Q/(1+T^2/100))

Then the derivative will be exactly zero, and this problem cannot be solved at all, so this case isn’t interesting.

Let’s also try applying nojac() to just one term:

R(T) = T – Q/(1+nojac(T)*T/100)

Now, our derivative is:

\frac{\partial r(T)}{\partial T}=1+\frac{TQ}{100(1+T^2/100)^2}

This is very close to the exact residual, and, at least in this case, the solver will converge for all values of , even with this approximation of the Jacobian. Although the computational cost hasn’t gone down, the notable point here is that we can apply the nojac() operator to any subset of the terms for our residual.

So, what have we learned so far?

  1. You can use the nojac() operator to omit terms from contribution to the Jacobian
  2. Omitting terms will have an effect upon the convergence of the nonlinear solver
  3. Omitting terms reduces the size of the computational model

The last point, though, is not all that apparent on this small example.

Reducing the Size of a Large Nonlinear Model

Let’s look now at a larger model in three dimensions. We solve a heat transfer problem on a 1-cm cube and apply an Extremely Fine mesh on this part, giving us a larger model; about 3 million degrees of freedom.

A schematic of a heat transfer problem with parameters labeled.
Schematic of a simple heat transfer problem to investigate with an extremely fine mesh.

We also make the material properties a function of temperature, and using a material property similar to what we’ve already seen, we define the material thermal conductivity via the user-defined expression:

(1+(T[1/K])^2/100)[W/m/K]

This is done directly within the physics interface, as shown in the screenshot below.

The Settings window for the Heat Transfer in Solids interface with manually defined settings for thermal conductivity.
The thermal conductivity manually defined as a function of temperature.

When we solve this problem using all of the default settings, the model will need four iterations of the damped Newton method to solve, take about 135 seconds of wall-clock time, and use a bit over 12 GB of memory on a typical desktop computer. During the solution process, we also get a message in the log that says:

Nonsymmetric matrix found.

This message is a consequence of the temperature-dependent terms in the material properties. That is, the nonlinear terms within the material property make the Jacobian matrix nonsymmetric, and the model will as a consequence take more memory to solve. Let’s now wrap the entire material property expression in the nojac() operator:

nojac(1+(T[1/K])^2/100)[W/m/K]

Rerunning the model, we see that the model does still converge and takes about 10 GB to solve, but now takes five iterations of the default damped Newton method. That is, memory requirements have gone down, but the number of iterations to convergence has gone up. Most interestingly, the wall-clock solution time is 125 seconds, a bit less than before! Why is this? The solver needs more iterations to converge, but each iteration takes less time, since the Jacobian matrix is symmetric and less data needs to be worked with.

So, in this case, using the nojac() operator reduces both the wall-clock solution time and reduces the memory needed, despite the fact that more iterations are needed to converge to the solution! Also note that we converge to the same solution, since the material properties themselves are still correctly evaluated, using the updated material property expression.

Avoiding Nonlocal Coupling Terms

Let’s finish up with one more example: the crushing of a thin-walled container containing a compressible gas, as shown in the figure below. This can be modeled with the Shell formulation available within the Structural Mechanics Module.

A model of a tank with thin walls that contains compressible gas and is subject to an external load, demonstrating how to use symbolic differentiation to accelerate model convergence.
A thin-walled tank containing compressible gas with an applied external crushing load.

By exploiting symmetry, we can reduce our model to 1/8 of the full model. We apply a distributed load that approximates the crushing, as well as a pressure load representing the internal compressible gas. To represent the compressible gas, we use the approach of computing the volume of the deformed container, similar to what is done in our example of the compression of an air-filled hyperelastic seal. That is, by using an integration coupling operator, we apply a uniform pressure load over the entire surface of the tank, and this pressure is computed based upon the deformation of the entire tank.

The effect of this nonlocal coupling is that the deformation of every part of the tank affects the pressure, and the pressure affects the deformation everywhere, so our Jacobian matrix becomes quite dense. When this is solved using the default Extremely Fine mesh setting, the model takes about 12 GB of memory and 400 seconds to solve this ~22,000 degree of freedom model.

The Face Load Settings window showing the modified pressure as an input to the crushed tank model.
Screenshot showing the modified pressure within a model of a crushed tank.

However, simply by wrapping the nojac() operator about our applied pressure, we omit the nonlocal coupling and the memory requirements and solution time go down. This way, we need only 3 GB of memory and 10 seconds to converge to the same solution!

Concluding Thoughts

By default, the software will always take the exact Jacobian, since this gives us the greatest possibility of convergence. In general, we would rather sacrifice some time and memory to get a solution as robustly as possible. However, we see that we do have the ability and flexibility to omit selected terms from the Jacobian matrix. If we want to use this capability, we have to explicitly modify material properties, modify the underlying governing equations, or write our own variable expressions within the model, so this is a bit of an advanced user feature.

Of course, using this functionality will approximate the Jacobian, and this will sometimes slow down, or even prevent, convergence, so don’t use it in those cases. However, if the model does converge with the nojac() operator being used, then it will still converge to the same solution as with the full Jacobian evaluation, and may use less time and memory, so it is a good feature to be aware of as you build complex multiphysics models.

How to Run COMSOL Multiphysics® from the Command Line

$
0
0

Have you ever wanted to run repeated variations of the same model file from the command line and automatically export data? With just a little bit of preparation work within the user interface (UI) of the COMSOL Multiphysics® software, you can augment your model file with a method that can automate quite a bit of model setup and evaluation from the command line. Let’s find out how…

Writing Out Data from a Model

To put this workflow into context, let’s look at a tutorial model of a busbar, which we use in our introduction to the COMSOL® software. This model has several parameterized inputs to study as well as outputs to report.

Let’s begin by writing some data out of our model to disk. Our model has several plots already set up, including one of the temperature field. Right-click on this feature and select the Add Image to Export option. You will get a Results > Export > Image feature, with settings as shown in the screenshot below. Within these settings, enter an output filename. Note that you can also adjust the Image and Layout settings as desired. You can add several of these features, and export other types of data, including animations, mesh information, and more. To write out all of these data at once, right-click on the Export branch and select the Export All option.

A screenshot of the COMSOL Multiphysics model tree with the Results node opened to the Export branch and the image export settings opened.
Screenshot showing the Export branch within the Results used to write out an image file.

Let’s also extract some scalar values. Add an Evaluation Group feature to the Results branch, and add to it any number of different derived scalar values. For example, take the integral of the losses over all domains and evaluate maximum temperature. Within the settings for the Evaluation Group, also specify the filename, as shown below.

A screenshot of the Evaluation Group node opened to the settings that specify writing numerical data to a file.
Screenshot showing the Evaluation group, which will write a combination of numerical data out to a file.

With the combination of the Evaluation Group and the Export features, we can write out any amount of data from our model. Now, let’s look at how we can automate this a bit further.

Automating Operations via a Model Method

To get started with using methods, we need to be working on the Microsoft® Windows™ operating system, since we will be using the Application Builder functionality. Click on the Application Builder button in the ribbon, or use the keyboard shortcut Control+Shift+A, and you’ll be brought to the interface shown below. The one task that we will do here is add a new method with the Methods branch. Give it a name, e.g., my_method, but let’s not put anything into it yet. Return to the Model Builder via the button in the top left, or via the keyboard shortcut Control+Shift+M.

The Application Builder zoomed in and open on a blank Method Editor window for writing a method to run COMSOL Multiphysics from the command line.
Screenshot of the Application Builder with a method.

Once back in the Model Builder, let’s add in a call to our method. Right-click on the Global Definitions and go to the Method Calls submenu, where you’ll see the method we just created. Add this, and make sure to also alter the Tag field. Usually, you can just use the same name as the name used in the Application Builder. You can see in the screenshot below that the Method Call feature has three buttons:

  1. Run
  2. Pause
  3. Edit Method

The Edit Method button is a convenient shortcut to take us back to the Application Builder, which is what we’ll do as soon as we have some code to put into our method.

A screenshot of a Settings window showing how to add a call to a method in the Model Builder.
Adding a call to our method within the Model Builder, which will let us run and edit the method.

If you’re not very familiar with coding, there’s really just one thing that you’ll need to know for what we’re about to do: A method contains snippets of code, with each line containing some kind of modification or action on the model. There are two ways to extract these code snippets from the Model Builder.

The first approach is to go to the Developer tab and click on Record Method. You can then perform a whole series of actions within the Model Builder, until you click the Stop Recording button. The related code will be saved into the new method.

In the second approach, right-click on a feature within the model tree, and (in most cases) you’ll see a Copy as Code to Clipboard submenu. Try this on the Study branch of the model, where one of the options is Run. Select this option to copy the code snippet for running the study to the clipboard. Go to the Method Editor and paste (Control+V) to see the code:

model.study("std1").run();

This second approach is a bit simpler, so let’s use this approach within this blog post.

A screenshot of the export settings with a menu expanded and the option Copy as Code to Clipboard selected.
Copying the code to run a particular node of the model tree.

We can add more code that automates the data extraction. We already set up features that write data out to disk, and now we just need to include the running of these features in our method. Right-click on the Export feature and again use Copy as Code to Clipboard in the Run command, as shown above. Paste these into your method, and repeat this for the Evaluation Group. Your completed method will look like this:

model.study("std1").run();
model.result().export().run();
model.result().evaluationGroup("eg1").run();

Since we are now writing to disk via a method, we probably also need to change some of the default security preferences. Go to the File Menu > Preferences > Security, and allow File system access for all files. This setting is shown in the screenshot below. Otherwise, you will only be able to write to the Temporary and Application Files locations, which are specified via File Menu > Preferences > Files.

A screenshot of the Preferences window opened to the Security options.
Modify the security preferences to allow a method to write to files, if needed.

Now when you run this method, the entire model is re-solved, and new data and image files are written out to disk. The last step is to do this all from the command line, without using the UI at all.

Running from the Command Line

Save this modified file, call it my_file.mph, and close out of the COMSOL Multiphysics UI. Bring up the Windows Command Prompt and navigate to the directory containing your file. Make sure that the path to the COMSOL® executables is added to the PATH environment variable, and enter the following command:

comsolbatch -inputfile my_file.mph -pname tbb,Vtot -plist "1[cm]","10[mV]"  -methodcall my_method -nosave

This will open the model and modify the value of two of the Global Parameters, due to the combination of the -pname and -plist arguments. In this case, the parameter tbb alters the bar thickness and Vtot is the applied voltage.

Our customized method will be called (due to the -methodcall argument) and will run the model and write out data. The additional optional argument -nosave means that the model file isn’t saved. For full details of this and all other optional arguments, see the section “The COMSOL Commands” in the COMSOL Multiphysics Reference Manual.

There we go: The entire process of modifying the model, and writing out data, is reduced to a single command!

What Else Can We Do?

Of course, what we’ve done here is a very minimal example to demonstrate the automation of running a model and writing outputs, but there is so much more we can do. You can put essentially any code that you want into the model method. For example, you can include code that will:

In addition, it’s worth mentioning that there is an alternative workflow that can achieve much of the same data extraction via the Job Sequences functionality (this approach does not use methods).

Finally, it’s worth remarking that you can run multiple different batch jobs in parallel at the same time, which is particularly attractive if you have a machine with a lot of memory and cores.

 

Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.

Modeling Parts Without Constraints in Your Structural Analyses

$
0
0

When building models in solid mechanics, we often have a part where there are prescribed loads but no constraints that we can reasonably apply. There are a number of different strategies that we can employ in such cases, depending on the geometry. Let’s look at how to use these different approaches and their nuances.

A Solid Mechanics Problem

We will start by considering a simple model of a flat plate with a hole through it — a classic problem in solid mechanics. Let’s assume that there are equal and opposite forces applied at the top and bottom. Imagine, perhaps, that this part is connected to some cables via some fixturing and put in tension.

A schematic of a classic problem in solid mechanics, in which a flat plate with a hole (shown in gray) is under a tension load (shown with red arrows).
Free-body diagram of a flat plate with a hole in the center, under a tension load.

Although we could build a model of the fixturing and the cables, and a model of whatever the cables are connected to, this is likely much more effort than we want to expend. We really just want to focus our analysis on this one part of a larger system, so it makes sense to approximate all of these other parts as a boundary load that is normal to the ends of the plate.

Now, we intuitively know that a part with equal and opposite forces on it will not experience any accelerations, so although the part will deform, it won’t be in motion. That is, we can say with confidence that a stationary solution to this problem exists, even if we don’t know where the part is or how it is oriented. That is, the applied forces could be aligned with any arbitrary direction and the solution in terms of the stresses and strains would still be the same.

Now, when we solve a solid mechanics problem via the finite element method, we aren’t directly solving for the stresses or strains. Instead, we solve for the displacements (or deformations) from the undeformed state. The stresses and strains are computed from the displacement field. For the purposes of this blog post, it is sufficient to address solely the linear case, but if you’re interested in some more advanced topics, see the following blog posts:

To get a solution for the deformations, we do need to introduce a set of constraints on the displacement field, and these must be sufficient to constrain all free-body displacements and rotations, but they cannot affect the stresses and strains. This blog post will describe various ways in which this can be achieved, depending on the geometry that we’re dealing with.

Using Symmetry Planes

For this geometry, the experienced structural analyst will immediately see that there are three planes of symmetry that can be exploited. We can draw the part aligned with the global Cartesian coordinate system and use partitioning along workplanes parallel to the xy-, yz-, and xz-planes. This reduces our model to a 1/8 submodel of our original model. We apply the symmetry condition to the three faces along these planes, and this will have the effect of completely constraining our part. In addition, this has the beneficial side effect of reducing the computational size of our model.

A view of the solid mechanics model when fully constrained by exploiting symmetry along three orthogonal planes shown in purple.
Exploiting symmetry along three orthogonal planes fully constrains the model.

Let’s think about exactly how these three symmetry conditions constrain the part. The symmetry condition imposes that there be no displacement in the normal direction to the selected (planar) boundaries. Thus, the symmetry condition applied on the face parallel to the xy-plane will impose the condition that this face has zero displacement in the z direction, and that there can be no rotations about the x-axis and the y-axis.

Next, the symmetry condition on the yz-parallel face imposes the additional conditions that there can be no displacement in the x direction and no rotation about the z-axis. The rotation around the y-axis is once more constrained, but this is not a problem.

Finally, the symmetry condition on the xz-parallel face imposes the additional constraint of no displacement in the y direction.

Thus, we have applied a set of three orthogonal constraints on the displacements and rotations, so the part is sufficiently constrained and the model can be solved. To visualize the results, it is helpful to use a set of three Mirror 3D datasets, which can mirror any dataset about a plane such that the complete part can be visualized.

Parts with No Symmetry

Unfortunately, we usually aren’t so lucky as to have a part with three planes of symmetry. Let’s modify our part by introducing a taper to the hole, and changing its location, as shown below.

The classical solid mechanics model with the tapered hole off center in the flat plate.
Free-body diagram of a flat plate under tension with an off-centered tapered hole.

There is no way to exploit any symmetry in this case, so what can we do? There are actually four different approaches we could take!

A screenshot of the Rigid Motion Suppression feature Settings window, with the Domain Selection and Equation sections expanded.
Applying the Rigid Motion Suppression feature to all domains to constrain displacements and rotations.

The first, simplest approach is to use the Rigid Motion Suppression domain constraint feature. This feature simply needs to be applied to any one, or all, subdomains of the model, and it will apply a set of constraints behind the scenes that removes all rigid-body displacement and rotation. All we need to do is apply this feature and the model will solve.

A screenshot of the settings for the Prescribed Displacement point condition in COMSOL Multiphysics.
A Prescribed Displacement point condition that constrains all free-body displacements.

The second approach is to manually constrain displacements and rotations via a set of three different point constraints. To do so, begin by choosing a point on the geometry, and impose a Prescribed Displacement condition on that point that sets the x-, y-, and z-displacements to be zero.

Although the point that we choose could be arbitrary, we will see shortly that it is best to choose a point at one of the corners of this rectangular-shaped part. This single constraint is sufficient to remove all rigid-body displacement and will have no effect on the stress and strain fields.

The flat plate model with the off-center hole and three point displacement constraints visualized with blue arrows.
Visualization of three point displacement constraints that constrain all free-body rotations and displacements, but have no effect upon the strain field.

Next, we need to remove rotations about three orthogonal axes. This can be a bit trickier, although in this case, we are lucky in that our geometry is aligned with the global Cartesian axes. So, we can start from our fully constrained point and look along the Cartesian directions.

Let’s first look along the x-axis from this point until we find another point. There, we apply another Prescribed Displacement condition to remove a rigid-body rotation, but we need to make sure that we do not impose a constraint that will affect the strains and stresses. Another way of saying this is that we don’t want to impose a constraint on the distance between these two points. So, at this second point, we will constrain the displacement in the y– and z directions, but leave the x-displacement unconstrained. This constraint removes rotation about the z-axis and the y-axis, respectively. The part is now only free to rotate about the x-axis, and we can remove this freedom with one more point constraint.

If we go back to our original fully constrained point, we can now look along either the y-axis or the z-axis until we find a point. Let’s search along the z direction, and, once we’ve found a point, we can apply a Prescribed Displacement condition such that there is zero displacement in the y direction. This will prevent rotation of the part about the x-axis. Again, we need to make sure we aren’t constraining the distance between any of these points. If you do so by accident, you’ll see locally high stresses.

This second approach is actually a manual implementation of what is being done automatically by the first approach. It might, though, raise a question: What happens when we don’t have three points aligned with the Cartesian axes? If using the first approach, of the Rigid Motion Suppression, that feature will automatically be able to select any three points that form a plane and apply a consistent set of constraints. Let’s also look at how we can use any three points, as long as they describe a plane.

In our third approach, let’s work with the same geometry, but constrain using three points that aren’t aligned with the Cartesian axes. We will need to first define a Workplane, then define a Coordinate System using that workplane, and finally use that Coordinate System within our Prescribed Displacement conditions.

A screenshot of the Work Plane Settings window next to the flat plate model with the defined workplane highlighted in blue.
Three arbitrary points can be used to define a new workplane.

Start by defining a new Workplane within the Geometry, of Plane type Vertices, and choose three points that define a plane and that aren’t colinear. Note that the first two vertices that we select will define the first local axis of this plane. Next, define a Coordinate System from Geometry. Set the Frame of this coordinate system to be Spatial and choose the new Workplane in the System from Geometry setting.

A screenshot of the System from Geometry Settings window with settings for defining a coordinate system based on a workplane.
Defining a coordinate system based upon a workplane.

Then, as before, add three Prescribed Displacement point conditions, and for each, set the coordinate system to the System from Geometry. These three points should correspond to the three points selected within the Workplane feature. At the first point, constrain all three displacements. At the second point (the one that defines the first local axis), constrain the displacement in the second and third directions. At the third point, constrain displacement in the third axis (normal to the plane) direction. The advantage of this approach is that it doesn’t require the part to be aligned with the Cartesian axes. Again, the Rigid Motion Suppression feature provides the equivalent capability.

The flat plate solid mechanics model with the three point displacement constraints visualized in a blue transparent box.
Visualization of three point displacement constraints that constrain all free-body rotations and displacements, in a coordinate system defined by these three points.

The fourth approach addresses the special case of a geometry that does not have three points that define a plane. This can occur when we are dealing with imported mesh files, as in this model of a vertebrae, which does not have any points defined on the original mesh. Although it is possible to manually create vertices on an imported mesh, and it is possible to partition edges of a geometry to introduce additional points, it is worth knowing about this last alternative.

A screenshot of the Spring Foundation feature Settings window with the Domain Selection and Spring sections expanded.
Using the Spring Foundation feature also constrains displacements and rotations, but does not affect the solution if the spring constant is small enough.

In this fourth approach, we use the Spring Foundation domain feature and apply it to all domains of the model. This feature introduces an artificial additional stiffness at every degree of freedom of the structural model, relative to its undeformed position. The magnitude of this spring constant is a tuning factor within the model. If it is too small, then it will not provide sufficient numerical stiffness, and the model will not solve, but it shouldn’t be too large either, as this also affects the results. In practice, start with a very low value, and make it bigger until the model solves. Although there are only very rare conditions where this technique is strictly necessary, it is still worth knowing about.

Parts with Partial Symmetry

Let’s also consider the quite common situation of a part with some symmetry, in which case the Rigid Motion Suppression feature cannot be used.

Side-by-side views of the flat plate model before and after exploiting half-symmetry.
Exploiting half-symmetry requires two point displacement constraints that remove translation in the plane and rotation about the axis normal to the plane.

For the case of a single symmetry plane in the model (or two parallel planes of symmetry), we have to choose two points on the plane and use the Prescribed Displacement point condition to constrain them such that there is no displacement in that plane and no rotation about the normal to that plane. If there are two planes of symmetry at an angle to each other, then choose a single point on one of the planes, and constrain it such that it cannot move in the direction described by the intersection line of the two planes.

Side-by-side views of the flat plate model when using two planes of symmetry.
With two planes of symmetry, remove translation along the intersection line of the planes via a single point constraint.

In terms of presenting the results of such models, it is also good to know how to center the visualization of the displacements. Suppose we want our model to be visualized with the displacement centered about the hole. What we can do is introduce an average component coupling operator and define it over the boundaries of the hole. Then, when visualizing the displaced results, we can subtract out this averaged location in the Displacement subfeature, as shown in the screenshot below.

A screenshot of the Deformation Settings window with the average operator used for modeling parts without constraints.
Using the average operator to recenter the visualization of the displacement about the center of the hole.

Concluding Thoughts on Modeling Parts Without Constraints

In summary, we have shown a set of techniques to use for modeling 3D parts where we only have a set of balanced loads, but no constraints. The simplest approach is to use the Rigid Motion Suppression feature, but we sometimes need to constrain via a set of points due to other symmetry conditions.

For the case of 2D structural models, a similar but simpler approach is applied. For parts without symmetry, one point has to be fully constrained in the xy-plane and another point must be constrained to prevent rotation about the out-of-plane z-axis. For a 2D model with one plane of symmetry, or parallel symmetry planes, only one point displacement constraint is needed to prevent motion along the symmetry plane. For a 2D model with intersecting symmetry planes, no additional constraints are needed. For the case of 2D axisymmetric models, only the displacement along the z direction (parallel to the axis of symmetry) must be constrained at any single point.

These techniques are particularly useful when dealing with problems involving thermal expansion, and can be used in any study type, including stationary, time-domain, frequency-domain, or eigenfrequency. These methods are a powerful tool for all structural analysts.

Introducing Goal Seeking into the Segregated Solver

$
0
0

One of the core technologies within the COMSOL Multiphysics® software is the segregated solution approach, which is used within nonlinear multiphysics (and single-physics) problems to rapidly converge to a solution. Did you know it is possible to augment this solver with an additional global equation that can be used to adjust a model input to achieve a desired output? Let’s find out more!

Accelerating Solver Convergence

Whenever you are working on a multiphysics problem, you are solving a system of nonlinear equations. This system of equations is usually quite large, meaning it will take a lot of time, and computational resources, to solve.

One approach to accelerate the convergence of the solver is to use a so-called segregated solver. This solver takes the entire large system of equations, or matrix of equations, and breaks it up (or segregates) into several smaller matrices. Usually, each of these submatrices corresponds to a single physics. During the solution approach, the software will solve one of these submatrices in a so-called segregated step. After stepping through all of the submatrices, the solver will check for convergence and keep iterating as necessary until convergence is achieved.

This approach works robustly for a wide class of problems, is particularly attractive for 3D models that have high computational requirements, and is almost always the default in those cases.

A line graph plotting a sweep over a range of input values, with annotations for the Desired Model Output and Estimated Desired Operating Point.
A sweep over a range of input values can be used to predict the model response and estimate the desired operating point.

Often, when solving models, we are in a situation where we don’t want to change the geometry at all, but do want to change some other model input with a single specific goal in mind. That is, we want the model to produce a particular output.

For example, we might want to achieve a desired temperature, heat load, flow rate, or any other derived value. Formally speaking, this is an optimization problem that can easily be addressed using the Optimization Module. However, for the case of only a single model input to vary, using the Optimization Module can be a bit of overkill and we will here look at a few alternative approaches to adjusting an input to get a desired output.

The simplest way of finding this model input is via a parametric sweep. That is, we specify the input that we want to change, give a range of values to sweep over, and then plot the resultant graph of our output vs. input. From this graph, we can visually select the operating point that we are trying to get to.

This is a quite traditional approach, but it is somewhat expensive. Often, the response curves are quite nonlinear, albeit usually monotonic, so you usually need to solve for significantly more than two values within your range of interest, and the solution time will scale with the number of values that you’re solving for. (There is a caveat to this: You can use the Cluster Sweep or Batch Sweep functionalities, but both of these require substantial hardware resources, and this blog post will assume we have some hardware constraints.)

Using a Goal-Seeking Global Equation

Today, let’s look at an alternative, and very efficient, approach to this problem. We will introduce a goal-seeking equation into the segregated solver. This can be done quite simply with:

  • A single Global ODE and DAEs interface
  • A bit of careful construction of an equation
  • Some tweaks to the solver settings

Let’s look at a representative example.

A schematic of a typical Joule heating problem, an inclusion in the material between two electrodes with parts labeled.
Schematic of a Joule heating problem, an inclusion in the material between two electrodes. All material properties are functions of temperature.

Consider the Joule heating problem illustrated above: two electrodes applied to a medium that contains an inclusion of different conductivity, as might arise in a tissue ablation model. Due to temperature nonlinearities that we will consider in the material properties, such a model can actually produce some quite complicated results.

The Global Equation Settings window with an additional global equation shown in the expanded Global Equations section.
How to introduce an additional global equation to the model.

Let us support that what we would like to do is adjust the potential of one electrode relative to the other grounded electrode such that exactly 3 Watts is dissipated within the inclusion. The applied electric potential on the electrode is the variable V_applied, which we will control via the addition of a Global Equation into our model, as shown in the screenshot above. The equation that we enter appears quite simple:

V_applied-nojac(sqrt(3[W]/intop(ec.Qrh))*V_applied)

This equation, which will be solved for within each segregated iteration, will update V_applied. The applied voltage is scaled based upon the dissipation computed via an integration operator. The square root is used, since we know that, at least in a lumped model, losses are proportional to the square of the potential difference. Everything within the nojac() operator does not contribute to the Jacobian, and the terms within it are based upon the values at the previous segregated step, or the initial value if at the first step. Note that the initial value of V_applied must be nonzero, and a decent initial value will lead to faster convergence.

A screenshot of the Settings window for the segregated solver, with the General and Method and Termination sections expanded to implement the global equation.
Segregated solver settings with the Global Equation solved after the Electric Potential.

Within the segregated solver settings, we do need to make sure that this segregated step is solved after the segregated step for the electric currents, since the update expression is based upon the computed electrical losses. We also want to make sure that the temperature fields are computed either prior to the electric currents or after the global equation is solved, since these can affect the loss computation when the material conductivities are nonlinear with temperature.

A screenshot of the Lower Limit Settings window used to implement a lower limit in the segregated solver.
Upper and lower limits features in the segregated solver.

The segregated solver additionally gives us the option of providing both upper and lower limits to variables being solved for. That is, if any iteration would compute a V_applied that is larger, or smaller, than the specified values, the solver will simply use the limiting values instead. This is particularly helpful in terms of a lower limit, as we would never want the applied potential to go to zero, as further updates from that point would not be possible. An upper limit is also helpful if we know that there is some value above which the potential cannot be set.

As we solve this model using the segregated approach, we likely also want to monitor V_applied to see how it is being updated at each iteration. We can achieve this via a probe and via the settings shown in the screenshot below. The segregated solver also includes a Tolerance Factor, which multiplies the default tolerance of 0.001 as defined within the Stationary Solver feature. Making this number smaller than its default of 1 will tighten the convergence criterion of the solver. Note also that you can increase the number of iterations that the segregated solver takes if convergence is very slow.

A screenshot of the segregated solver settings with the General and Results While Solving sections expanded to show how to plot probes at every iteration.
How to plot probes at every segregated iteration, as well as the tolerance factor setting.

For the problem that we have here, convergence is quite rapid. The convergence plot of the segregated solver, and the probe plot, are shown below. Of course, convergence for a nonlinear problem is never guaranteed, and this additional update of the global equation does typically slow convergence, but in a great many cases, this technique can be used robustly, especially when a reasonable initial value is chosen. It should be noted that, depending upon the physics and the value that you are controlling on, different forms of the update equation might be needed. In this case, we use a square root of a ratio, but you could also use a linear, or an exponential, scaling between iterations. We can also think of this approach as a kind of a proportional controller, or a fixed-point iteration scheme.

Side-by-side line plots showing the segregated solver convergence on the left and probe for the global equation on the right.
Convergence of the segregated solver, and the probe plot of the additional global equation.

The great advantage of this approach is that we get to our design point using just one solution, using the computationally efficient segregated approach. This one solution might take a few more iterations than without the global equation, but the advantage of getting to the desired solution quickly almost always outweighs this cost. Also, if you want to solve in the time domain, then this approach can be used without modification as long as the global equation can be satisfied at each time step.

There may be, of course, cases where this approach does fail, in which case you can employ an alternative method that uses a fully coupled, rather than a segregated approach, but that is a topic for an upcoming blog, so stay tuned!

Try It Yourself

The model file associated with this example is available via the button below:

Using Global Equations to Introduce Fully Coupled Goal Seeking

$
0
0

Today, we will introduce a goal-seeking equation into a model in the COMSOL Multiphysics® software that is used in combination with a fully coupled approach to solving a nonlinear problem. This approach, albeit more computationally expensive than the segregated approach we introduced previously, has some interesting advantages in terms of robustness and highlights one of the core strengths of the COMSOL® software.

Background

As discussed in a previous blog post on introducing goal seeking into the segregated solver, one can augment a multiphysics model with an additional global equation within which we define how to update an input to a model such that a particular output is achieved. This approach takes advantage of the segregated solution approach, solving one part of the problem after another (solving all of the various physics) and then updating the input via the global equation.

Although this approach is very computationally efficient, due to the use of the segregated solver, it relies on an ad hoc update equation that needs to be constructed with some knowledge of the underlying physics of the problem.

Here, we will introduce an alternative approach, wherein the equation for the input is updated based upon an equation that lets the software symbolically compute derivatives. This approach can be much more robust and general, but does come with a computational cost. Let’s first look at how to implement this method, and then address the relative merits.

Here, we will look at the same example we considered before, of a Joule heating problem of two electrodes applied to a medium with an inclusion. The electric and thermal conductivities of the material are nonlinear with temperature. The objective of our model is to adjust the potential difference between the top electrode and the ground electrode such that 3 watts are dissipated within the inclusion.

Using the Fully Coupled Solver to Introduce Goal Seeking

Just like in our previous blog post, this can be achieved via a Global Equation, although this time, we add the Global Equation within the physics that it affects. However, recall that in the former case, this extra equation updates the applied potential using an ad hoc scaling within a separate segregated solver iteration. Here, we will use an equation that contributes terms to the Jacobian matrix when solved simultaneously with the affected physics.

A screenshot of the Global Equations settings within the Electric Currents interface node.
Introducing a Global Equation within a physics interface.

Let’s modify our previous example to demonstrate. We still need to introduce a Global Equation for the applied potential, V_applied, but now we need an equation that is satisfied and solved for at the same time as the equations for the electric potential. To do so, we add a Global Equation feature within the Electric Currents physics. Note that we are entering a residual equation that must equal zero at the solution point. The equation that we enter is:

intop(ec.Qrh)/3[W] – 1

Where intop() is an integration operator defined over the inclusion. We will see later that there are some advantages to the nondimensionalization of this equation. Rearranging, this is equivalent to:

intop(ec.Qrh) = 3[W]

This can be read as: Compute the value of V_applied such that the losses in the inclusion equal 3 watts. We can also write out what this residual equation represents:

r\left( V,T,V_{applied}\right) = \left (\frac{1}{3W}\int\sigma(T)\nabla V \cdot \nabla V d\Omega-1 \right)

When computing the Jacobian contribution, we take the symbolic derivative of this with respect to all of the unknowns in the model. By examination, we can we see that:

\frac{\partial r}{\partial V_{applied}} = 0

whereas the other two derivatives with respect to the electric potential, , and the temperature fields, , will be nonzero.

This means that the global equation introduces a zero on the diagonal of the Jacobian, but many nonzero terms in the corresponding row. This affects the kind of linear system solver that we will have to use within the nonlinear iterations.

It is these additional terms that are the really interesting and useful contribution. These terms tell the nonlinear solver how to update V_applied such that our global equation will equal zero. That is, the software figures out the update to V_applied automatically. (Recall in our previous approach we had to construct our own update equation based upon some knowledge of the physics.)

Introducing Nonzero Gradients

There is, however, a cost to these additional terms. They do require that we simultaneously solve for the global equation and the electric potential equations, and, since they introduce both off-diagonal terms and a zero on the diagonal, they require that the fully coupled approach use a direct linear system solver when solving for the electric potential field and the global equation. In addition, the derivatives shown above have to be nonzero at the initial conditions, otherwise the entire row of the Jacobian would be zero. This turns out to be a bit nontrivial in this case, in that there must be a nonzero gradient in the electric potential at the specified initial values.

There are two ways to introduce a nonzero gradient in the electric potential. The simplest way is to specify a spatially varying initial condition, as shown in the screenshot below, in the Electric Currents physics. This is simple to do, at least in this case, but might not always work, since we do introduce a nonphysical initial value.

A screenshot of the Initial Values Settings window within the Electric Currents physics interface.
Introducing an initial value into the Electric Currents physics that will lead to a nonzero gradient on the electric potential field.

A more elegant approach is to introduce a variation of our Global Equation for V_applied that solves the equation:

V_applied/1[V] – 1

This equation simply sets V_applied equal to 1[V], and the software will then solve the system of equations and compute a consistent electric potential field. Note that this is why it is helpful to have a nondimensionalized residual equation. This is shown in the screenshot below.

A screenshot of the settings for introducing an additional global equation for goal seeking.
Introducing an additional Global Equation to find an initial value.

Adjusting Solver Settings for the Global Equation

Once we solve for this fixed value of V_applied, the solution to this problem can be used as the initial value once we switch back to using our original Global Equation. This can be achieved via the Modify model configuration for study step check box and then enabling/disabling the two different Global Equations within the two study steps. That is, within the first study step, we simply specify V_applied, and in the second step, V_applied is solved for such that there is the desired dissipation within the inclusion. This is shown in the screenshot below.

A screenshot of the Stationary study settings with the option selected to modify the model configuration for the study step.
Modifying the model configuration for the first study step, where the Global Equation for the initial value is solved. In the second step, the opposite settings are applied.

This second step does require an adjustment to the default solver settings. There are two choices:

  1. Use a fully coupled approach for the entire problem, and use a direct solver. This requires the least changes to the solver settings, but solving a large system of equations with a direct solver is going to require a lot of memory.
  2. Use a segregated solver, but combine the global equations and the electric potential equations into one step, which is solved to convergence using the automatic Newton approach and a direct solver. The temperature solution can still be solved in a segregated fashion using an iterative solver. This approach requires more changes to the settings, but will require less memory to solve. Note that this segregation will lead to the terms being ignored (if they exist at all), which might sometimes negatively affect convergence. These changes to the settings are shown in the screenshot below.

A screenshot of the Segregated Step Settings window with the General and Method and Termination sections expanded.
The global equation and the electric potential must be solved simultaneously and using a direct solver.

It is suggested to start with the first approach and try the second if the memory requirements are too high. Note that for 3D models, the memory requirements of the direct solvers go up very quickly with problem size, which is the primary limitation.

Concluding Thoughts

The approach shown here is one of several approaches that can be used to address goal-seeking problems within the GUI without having to resort to any programming. Other approaches for solving this class of problems, discussed in our previous post, are:

  1. Using the Optimization Module
  2. Using a parametric sweep and manually identifying the approximate target value
  3. Augmenting the segregated solver with an additional update equation

The significant advantage of the approach shown here, despite its higher memory requirements, is that it converges quickly and robustly. Note that this technique can also be using in the time domain, as long as the global equation can be satisfied at each time step.

This robust and rapid convergence is a consequence of the additional terms within the Jacobian matrix and highlights another one the strengths of COMSOL Multiphysics for solving highly nonlinear coupled multiphysics problems. This technique, along with the ones discussed previously, are great tools for an analyst to have in their toolbelt.

Try It Yourself


How to Model a Hall Effect Sensor with COMSOL Multiphysics®

$
0
0

The Hall effect sensor is commonly used for position sensing. The basic working principle is that a nearby magnetic field deflects the path of current through a semiconductive sensor. This deflection of current causes a change in potential, which can be measured. Despite the multiphysics nature of this device, with a couple of assumptions, it’s actually possible to model it very simply in the COMSOL Multiphysics® software. Keep reading to find out more…

Basic Working Principle of a Hall Effect Sensor

We will start with the definition of the Lorentz force, the expression for the total force on a charged particle moving through an electric field, , and a magnetic field, , at a velocity, . The total force on a particle, of charge , is:

\mathbf{F}=q \left ( \mathbf{E+ v \times B} \right)

Let’s consider a slab of semiconductive material with an electric potential difference applied across two ends that causes current to flow. For a uniform slab, the current will flow in a straight line between the two terminals. However, due to the Lorentz force, any nearby magnetic field will deflect this current path, thus altering the electric potential distribution within the material, and this can be measured. For typical Hall effect sensors, the magnetic field is due to a nearby magnet.

A schematic of a slab of semiconductive material with a floating terminal on each long end and a current running through it that is deflected by the magnetic field.
A slab of semiconductive material. Current passing through the material will be deflected by the magnetic field, which will change the electric potential between the two floating terminals.

In terms of the equations that we will use within our computational model, we start with the above equation and write the current density through the semiconductive material as a function of the electric field and the magnetic field, as well as two additional material constants, the electric conductivity, , and , the Hall coefficient:

\mathbf{J}=\sigma \left( \mathbf{E}+ \sigma R_H \left( \mathbf{E \times B} \right) \right)

We can rewrite the above as a matrix-vector multiplication:

\begin{Bmatrix}J_x \\ J_y \\ J_z\end{Bmatrix}=\begin{bmatrix}\sigma & \sigma^2R_H B_z & -\sigma^2 R_H B_y\\-\sigma^2R_H B_z & \sigma & \sigma^2 R_H B_x\\\sigma^2 R_H B_y & -\sigma^2R_H B_x & \sigma\end{bmatrix} \begin{Bmatrix}E_x \\ E_y \\ E_z\end{Bmatrix}

That is, the Hall effect can be modeled simply by defining an anisotropic electric conductivity that is a function of the magnetic field. For brevity, we will omit discussion of sign conventions and the derivation of the Hall coefficient in different materials. This is the unique constitutive relation that we need to incorporate into our computational model.

Now, in the simplest situation, we could just assume a given magnetic field, and use that to compute the electric conductivity, but what we will do here is compute the varying magnetic field and use that to create a true multiphysics model.

Before we start any modeling, though, we will make a few assumptions to simplify things. We will assume that the time rate of change in the magnetic field is sufficiently slow enough that it can be ignored. That is, although the Maxwell–Faraday equation states that:

\nabla \times \mathbf{E}=-\frac{\partial \mathbf{B} }{\partial t}

we will assume that is negligible and can be ignored.

This is equivalent to saying that there are no significant induced eddy currents in the semiconductive slab due to the motion of the magnet. That is, the electric field in the material is due solely to the applied electric potential and aforementioned constitutive relationship, and not directly due to any time variation of the magnetic field. This assumption lets us reduce the problem to solving for the magnetostatic fields.

Next, we will also assume that the currents flowing through the semiconductor are small enough that they do not themselves produce any significant magnetic field as compared to the magnetic field due to the magnet. This reduces the magnetostatic problem to the so-called current-free form, wherein we only need to solve for a magnetic scalar potential. Note, however, that these assumptions are not necessary for what we’re about to do. We could also solve for the magnetic fields due to currents, such as from a nearby coil. This would only make our model a bit more computationally expensive.

Lastly, we will also assume that the conductivity of the material is large enough such that the RC time constant is much shorter than any time variation that we are interested in. That is, we can, at any instant in time, treat the electric currents model as a purely static situation, since we’ve assumed that all time derivative terms are unimportant. So, the electric problem reduces to solving for the stationary electric potential equation, albeit with a spatially varying anisotropic electric conductivity that is a function of the magnetic field.

With all that said, we are ready to begin our modeling!

Implementing the Model in COMSOL Multiphysics®

We will consider the situation in the image below. A small cylindrical magnet is mounted on a rotating iron wheel. Below, there is a rectangular domain representing the sensor.

A Hall effect sensor schematic, with the sensor shown in blue and a rotating iron wheel with a magnetic on top, shown in gray.
Schematic of a Hall effect sensor placed underneath a rotating iron wheel with a magnet mounted on the rim.

We will solve first for the magnetic fields, using the Magnetic Fields, No Currents interface. In addition to the domains pictured above, we model the air space surrounding these, as well as an Infinite Element truncation domain.

Solving this problem, we compute the magnetic fields, and can then move on to the model of the Hall effect sensor. In the semiconductor domain, we use the Electric Currents interface. The Ground and Terminal conditions are applied at opposite ends of the material, and two Floating Potential conditions are applied on either side.

For a quick introduction to the usage of the Electric Currents interface, see our series of tutorial videos on resistive device modeling.

The electric conductivity can be made a function of the spatially varying magnetic field, which we just computed, but we would also like to consider the rotation of the wheel. The simplest way of considering rotation is to perform a Parametric Sweep, but that is actually a bit more than we need to do here. The magnetic fields are rotating through the sensor, but we assumed that they are unaffected by the sensor itself.

In this situation, we can just use a rotational mapping to change the magnetic field as a function of a global parameter, Angle, via the General Extrusion operator, similar to as described in this previous blog post. In this case, though, we’re rotating a vector field, so we also rotate the vectors themselves, via a 3D rotation matrix. The two screenshots below show the implementation and define a set of rotated magnetic field variables.

A screenshot of the General Extrusion Settings window, with the Destination Map section expanded to define a y-axis rotation.
The General Extrusion operator defines a rotation about the y-axis.

A screenshot of the Variables Settings window with the Variables section expanded to define the rotated magnetic field components.
The variables defining the rotated magnetic field components.

Once we have these rotated magnetic field components, we can use them to define the electric conductivity tensor within the Electric Currents interface, as shown in the screenshot below.

A screenshot of the settings for the Current Conservation feature, with the Coordinate System Selection and Constitutive Relation sections expanded.
Defining the anisotropic electric conductivity within the Hall effect sensor.

With that, we are ready to solve the model. We can solve in two steps, first solving for the steady-state magnetic field, and then solving for the steady-state current, but with the magnetic field rotated through different angles via an auxiliary sweep, as shown in the screenshot below.

A screenshot of the settings for the stationary solver, which computes the magnetic fields in Step 1 and electric potential of the Hall effect sensor in Step 2.
Setup of the solver. The magnetic fields are computed in the first step, and in the second step, the electric potential in the sensor is computed for different rotation angles of the magnet.

After solving, we can animate the rotating fields, to confirm our approach, and examine a plot of the difference in the electric potential between the two floating potential boundary conditions on either side of the sensor.

 

Animation of the rotation of the magnet and the magnetic field through the Hall effect sensor.

A line graph plotting the variation in electric potential between the two floating potentials on the Hall effect sensor.
Variation in the electric potential between the two floating potentials on the sensor with respect to angle.

Try It Yourself

We’ve shown a simple way of modeling a Hall effect sensor. The ability to enter an anisotropic electric conductivity that is a function of any other variable in the model makes this kind of simulation very easy. By manually rotating the fields via a set of transforms, we can also greatly reduce the computational cost. The model is available for download via the link below.

Using Data Filtering to Improve Model Performance

$
0
0

Have you ever been in the situation where you want to use some experimental data as a load or boundary condition? If this data varies over space or time and is noisy, you might need a very fine mesh, or the solver might need very short time steps. Practically speaking, we often don’t want or need this. One possible solution is to filter the input data to make it smoother. Let’s find out more!

Filtering Noisy Data with Equation-Based Modeling

We will start by considering some sample input data, as shown in the figure below. For now, let’s not concern ourselves with what the data represents, and imagine that the horizontal axis could represent either space or time. We can observe that the data has some significant noise, as well as apparent trends. We would like to reduce this noise before using this data in our model.

A simple line graph with three noticeable peaks and a lot of small curves, showing a sample of input data with significant noise.
Sample of data with significant noise.

What we can do here is use a so-called Helmholtz filter. This type of filter was recently proposed and proved quite useful in the area of topology optimization. In fact, this functionality is a built-in feature of the Optimization Module, but it can also be manually implemented, which is what we will do here.

The Helmholtz filter simply solves the governing partial differential equation:

\nabla \cdot \left( – R^2 u \right) + u = D

where is the input data and is the filtered data.

There is one parameter to this equation, , which we will call the filter radius.

Along with the governing equation, we need boundary conditions. For reasons discussed below, we will start with the homogeneous Neumann condition, meaning that the gradient of the fields at the boundaries is zero. To solve this equation along with this boundary condition, we will use equation-based modeling via the Coefficient Form PDE interface in a 1D Component.

To get started, let’s read our experimental data into an Interpolation table feature, as shown in the screenshot below. Note that the Extrapolation is set to Constant. As we will see shortly, due to the boundary conditions in our Helmholtz filter, we need to have some data for the buffer region of space or time outside of our range of interest.

A screenshot of the Model Builder tree with the Interpolation settings open to set the Extrapolation method and a Function Plot window with a graph of sample data.
Reading in the experimental data and setting the Extrapolation method.

Next, let’s introduce a 1D Component into our model and set the Unit system to None.

Then, create an Interval feature into the Geometry, as shown in the screenshot below. Note the additional regions on the sides of the data range of interest.

A screenshot of the Interval Settings window in COMSOL Multiphysics, with the Interval section expanded open and a list of coordinates in a table.
Defining the domain over which the filter is applied.

Now we introduce a Coefficient Form PDE interface into the Component, in terms of a single unknown, u, as shown in the screenshot below. We will leave the Discretization at the default Lagrange Quadratic. Again, let’s keep everything dimensionless.

A screenshot of the settings for the Coefficient Form PDE feature with the Domain Selection, Units, and Dependent Variables sections expanded.

Within the settings for the Coefficient Form PDE feature, we define the settings as shown below. The Diffusion Coefficient is set to the square of the global parameter FilterSize, and the Absorption Coefficient is 1. The source is our experimental data, and all other terms are set to zero.

The default boundary condition of Zero Flux is the desired homogeneous Neumann condition, and we will fix the derivative of our filtered data set to be zero at the ends of the computational domain. This does introduce an end effect to the filter, which is why we introduced the additional padding region to the geometry, and to the data.

We could alternatively use the Dirichlet boundary condition, which would fix the value of u at the boundary. We also need to manually set the mesh size to be smaller than the resolution of our experimental data.

A screenshot of the Coefficient Form PDE Settings window with the Diffusion Coefficient and Absorption Coefficient sections expanded.
Using equation-based modeling to define the Helmholtz filter equation.

Using the Helmholtz Filter Equation for Model Data

We can now solve for different values of the filter size and compare results. As we see below, a very small filter size has almost no effect. Larger filter sizes lead to more smoothing, and as the filter radius gets large, the filtered data approaches the average of the original.

It is important to realize this key property of the Helmholtz filter: It is energy preserving as long as the homogeneous Neumann boundary conditions are used. This means that the integral of the original data and the filtered data over the entire computational domain will be the same.

Note that this is not precisely true over the subdomain without the buffer zones at either end. It is also important to note that the Dirichlet boundary condition is not energy preserving and should thus be used with caution.

A line plot showing three examples of filtered data, with a blue line showing a 0.01 radius, red line showing 1, and black line showing 100.
Examples of filtered data with various filter radii.

Now that we have filtered the data, let’s use it in a model. We will consider the transient heating of a 2D axisymmetric piece of material, and the filtered data will represent the applied heat load on the exposed surfaces. Since our thermal model is going to be in a different component within our model, we need to introduce a way to move our data from our 1D component into the time dimension for use within a 2D axisymmetric component. This is done via the General Extrusion operator, where we define a Destination Map for the x-expression of t. This feature will map, or extrude, the data from the 1D component onto the time axis, and make it generally available everywhere within the model.

A screenshot of the Settings window for the General Extrusion operator, with the Source Selection section expanded.
Screenshot showing the settings within the General Extrusion operator.

Within the thermal model in the 2D axisymmetric component, we can apply a heat source, as shown in the screenshot below, where the heat load is comp1.genext1(u)[W/m^2]. Note that we add units to this, as u is dimensionless.

A screenshot of the settings for the Heat Flux feature with the Boundary Selection, Material Type, and Heat Flux sections expanded.
Calling the filtered data defined in Component 1 from the thermal model in Component 2.

We can modify our study to contain two steps. The first step is a Stationary step, solving for the filtering equation, and the second is a Time Dependent step, solving the thermal problem. We will solve to a tighter relative tolerance of 1e-4 and output the results at all time steps taken by the solver, as described in this Knowledge Base entry.

As an aside, it is also worth noting that if the data instead had distinct, sharp changes in magnitude without noise, you should instead use the Events interface to inform the solver.

Solving for different values of filter radius, and plotting peak temperature within the domain over time, we can see the effect of the filtering on the thermal solution. We see that for this case, there’s only a very small effect on the peak temperature over time.

A line graph plotting the results of a thermal model with data filtering has been applied to the input data.

A graph plotting the results of a thermal model, with a red line showing a large filter radius and a thicker gray line showing a small filter radius, and part of the graph peak expanded in a separate window.
Results of the thermal model, solved with different filtering applied to the transient heat load.

The dramatic difference here is in the solution time. Solving for a model without filtering takes about 700 adaptive time steps in all, while solving the model with a moderate filter size takes about 130 time steps, leading to over a five-fold improvement in solution time!

Concluding Thoughts

Here, we have shown how an additional component and equation can be used to implement a Helmholz filter on data that we want to input into our model. We can do this not only with 1D data, but also with 2D or 3D data, and we can implement this filter over any arbitrary geometric shape and with any arbitrary density of input data. In 2D and 3D especially, this method will outperform most other filtering techniques, because it takes advantage of the local compact support of the finite element basis functions and permits a nonuniform spatial mesh discretization. This thereby results in sparse linear matrices that can be solved very efficiently.

Four views of an arbitrary surface where the data has undergone spatial filtering, including two plots in a red-blue color table and two mesh images, one course and one fine.
Spatial filtering via a Helmholtz filter on an arbitrary surface. The filtered data can be well-represented with a coarser mesh.

An example of 2D smoothing is visualized in the image above of unfiltered and filtered fields over an arbitrary surface. Note that filtering the data would allow a model that uses this data to be solved on a relatively coarser mesh, giving us an additional computational benefit. It turns out that we can even use this Helmholtz filter to design a mesh that conforms well to the variations in our input data, but that is a topic for another day!

Try It Yourself

The files associated with these approaches are available for download here:

Combining Adaptive Mesh Refinement with Data Filtering

$
0
0

When working with imported data that varies over space, we often face the challenge of determining what level of mesh refinement is needed to accurately resolve the input data and how it affects the solution to our multiphysics problem. We can use adaptive mesh refinement in these cases to refine the mesh based upon the model results. As it turns out, we can also use adaptive mesh refinement to refine based upon the input data. Let’s learn more!

Modeling a Nonuniform Heat Load

Consider the problem shown below of a plate of material that is heated from above with a spatially varying heat load that comes from an external data file and has some distinct, but quite nonuniform, structure to it.

A schematic of a nonuniform heat load, shown in red with black arrows, applied on a piece of material shown as a gray square.
Visualization of a nonuniform applied heat load that is read in from an external data file.

This actually doesn’t present a problem for the COMSOL Multiphysics® software at all. We can simply use adaptive mesh refinement and the COMSOL® software will automatically refine the mesh several times, as specified by the user, to give us a more accurate solution to the problem. Several iterations of this algorithm are plotted below.

6 mesh plots for a model of a nonuniform heat load, starting with a uniform mesh in the top left square and the mesh getting finer and finer.
Results showing the mesh (top view) when using adaptive mesh refinement. Starting with a uniform mesh, the software adapts the element size to accurately resolve the variations in the solution due to the spatially varying applied heat load. This reproduces the spatial variation of the applied load, but it takes several iterations for this structure to become apparent.

What we can observe is that the adaptive mesh refinement algorithm started from the default mesh, which has no knowledge of the shape of the applied heat loads. Only after several iterations does the algorithm really start to identify the distribution of the load very well, and there is some computational expense to these initial iterations.

What if there was a better way? What if we could tell the software that we want to start with a mesh that is already adapted to the shape of the experimental data? We still want to perform adaptive mesh refinement, of course, but we want to start this refinement process from a more reasonable initial mesh.

It turns out that this is very easy to do by implementing a Helmholtz filter over just the imported data and adapting the mesh on that. We’ve already introduced the concept and implementation and some benefits of the Helmholtz filter in a previous blog post. Now let’s look at another capability that it gives us.

Implementing Adaptive Mesh Refinement and Data Filtering

We can implement a Helmholtz filter equation on just the top surface of our model, with quite a small filter radius (think of this radius as akin to the spatial resolution of the input data) and solve it on a quite coarse mesh, just on the surface. The Helmholtz filter equation itself is linear, so it can be solved on any mesh, and the adaptive mesh algorithm will be able to identify where this mesh needs to be refined. We just need to make a few small tweaks to the solver and mesh settings.

A model with a square geometry and an adaptive mesh applied to its top surface.
The mesh that is used to start the adaptive mesh refinement is applied to just the top surface of the part.

Within the Stationary step, where we solve for the Helmholtz filter, there is just one required change. The Geometry Entity Selection for Adaption must be modified so that the adaptation is performed only over the regions where the filter is defined (in this case, just a single boundary). You can also optionally increase the Maximum number of adaptations and experiment with the adaptation method, especially the General Modification and Rebuild Mesh options.

A screenshot of the Settings window for the adaptive mesh refinement, with the Adaptation and Error Estimates and Geometric Entity Selection for Adaptation sections expanded.
Settings that define the adaptive mesh refinement of the boundary.

All other settings can be left at the defaults. When solving, you’ll get a sequence of meshes that adapt solely based upon the filter solution on the boundary, as shown below. There may be some messages in the solver that there is no mesh within the volume, but this is desired: We want to adapt only the mesh on the surface, not do any remeshing of the volume — yet.

4 boxes showing the sequence for the first 4 meshes generated with an adaptive mesh refinement algorithm for a nonuniform heating model.
The sequence of the first four meshes generated by the adaptive mesh refinement algorithm. These exist solely on the top boundary.

Using the Adapted Mesh to Solve the Problem

Next, we want to use one of the adapted surface meshes within the definition of the volumetric mesh used to solve the heat transfer problem. All we need to do is add another mesh, of the type User-Defined, and add a Reference feature within it, immediately after the global Size feature that is always present in a mesh sequence. After that, we add a Free Tetrahedral feature, and we have a complete mesh that can be used to solve the heat transfer problem.

A screenshot of the Reference Settings window for setting up a volumetric mesh, with the Reference mesh set to be Level 2 Adapted Mesh.
Building a new volumetric mesh based upon the results of one of the previous adaptively refined boundary meshes.

In fact, we could even perform additional mesh refinement, working forward from this mesh. The advantage is that we’ve already started with a mesh that is quite well adapted to the applied loads. So, for this problem, we don’t need to do very much adaptive mesh refinement of the thermal solution.

Simulation results showing the temperature for a nonuniform heat load problem after implementing adaptive mesh refinement and data filtering.
Starting from the mesh refined based upon the input data, we don’t need to refine the mesh as many times to get confidence in the model solution.

We can see here that there’s a clear computational benefit in this case. Any time that you are reading in experimental data that varies quite sharply in space, it will be worth investigating this technique, as it can save significant computational effort. If, on the other hand, the data is relatively smooth, without sharp transitions, then this technique is not as strongly motivated.

It is also worth mentioning that in this case we focused on a 2D planar surface, so you could also use the approach of treating the heat distribution as an image file, and convert that image to a set of curves, which can be used within any 2D workplane. That approach, however, is only applicable for 2D planar surfaces, while the approach presented here can also work on curved surfaces and even volumes.

Try It Yourself

Click the button below to access the files associated with the model example discussed here:

How to Model Polarization Rotation Along a Waveguide

$
0
0

The beam envelope method within the Wave Optics Module is a great feature for modeling photonic waveguiding structures. You can quickly set up models that compute the guided modes of a waveguide and how light propagating along the waveguide will be affected by, for example, anisotropies in the refractive indices of the materials. For devices with multiple supported waveguide modes and identical waveguide cross sections, there are some efficient modeling techniques to use. Let’s learn about such a situation.

Background on Optical Waveguides

In the field of photonics, many strategies exist for guiding light. The dielectric slab waveguide is always a good starting point, especially as a “textbook” example. More practically speaking, fiber optics, such as step-index fibers, dominate today’s communications infrastructure. For an overview of waveguiding and the field of photonics, see this previous blog post.

A schematic of an optical rib waveguide with the substrate shown in light orange, waveguide in orange, and air in blue.
Schematic of an optical rib waveguide (not to scale).

What we will consider here is a rib waveguide, as pictured in the cross section above. This waveguide supports multiple modes that have quite similar effective indices, but where the electric fields are pointing in different directions. Suppose now that a section of the substrate of this waveguide has an anisotropic refractive index. As we have already discussed, such a waveguide will support yet another set of different modes.

Here, we will show how to model such a waveguide in 3D and how the polarization of light guided along the waveguide will rotate.

Computing the Supported Modes

We will begin with a 3D geometry, as pictured below, of a straight waveguide, but subdivided into three sections. There will be an entrance region and an exit region. In these, we will assume that the refractive indices in all domains are isotropic. In the middle region, we will introduce an anisotropy in the refractive index of the substrate. This anisotropy might arise due to unwanted stresses in the substrate, or they may be purposefully introduced. We do want to introduce some kind of variation along the length of the structure, though, as otherwise, you could just model the case in 2D.

A schematic of a computational model of a waveguide structure, with the entrance/exit regions, port boundaries, and substrate region labeled.
Schematic of the computational model (not to scale).

First, we will compute all of the waveguide modes of interest. We will concern ourselves only with the first two modes of a 1550 nm wavelength light. We can use a combination of the Numeric Port boundary condition and the Boundary Mode Analysis study to do so; the results of which are shown below. Note from the plot how the electric field extends fairly far into the substrate. We will use these two modes in the next part of our analysis, the 3D modeling, to both excite the structure and monitor transmission through it. We will inject one of these modes with the electric field pointing upward, and as this mode propagates through the anisotropic region, we want to find out if and by how much this mode gets converted into the other mode at the exit. To do so, we will need to reuse and copy these solutions.

Side-by-side plots showing the electric fields of the first two waveguide modes, visualized in a red–white color gradient with black streamlines with arrows.
Visualization of the electric fields of the first two waveguide modes.

Modeling Polarization Rotation in the Full 3D Waveguide

Once all of the Numeric Port modes of interest have been computed and mapped to their respective User-Defined Port boundary conditions, we are ready to finish up the 3D model. The Electromagnetic Waves, Beam Envelopes interface takes the average wave vectors of the two modes of interest as the input, and here, we use the Unidirectional formulation. This is appropriate in our case because we will assume that light is solely propagating from the entrance to the exit, but that there is negligible reflection back toward the entrance.

Once solved, we can plot the absolute value of the electric field components along a line down the center of the waveguide. We can also evaluate the transmission into the two ports at the exit, which gives us a measure of how much the fields rotated through the device. In the entrance region, with isotropic properties, only the injected mode exists. Once this mode propagates into the region with the anisotropic substrate, which supports a different set of modes, there will be a gradual conversion into these modes that causes the fields to rotate. These modes also have slightly different propagation constants, which will lead to a beating phenomena along the length that will become more evident if we model an even longer section. At the exit region, though, all of the material properties are isotropic and only the original two previously computed modes can exist.

Simulation results in COMSOL Multiphysics showing the waveguide as a transparent cube with red arrows showing the polarization rotation of the electric field.
Results showing the rotation of the electric field along the length of the waveguide.

Closing Remarks

The model is available for download via the following article: “Copying and Reusing Boundary Mode Analysis Results“. This model is differentiated from other examples, such as the directional coupler, in that we are computing the boundary modes via a separate study and using operators to copy the numerically computed modes. For models with multiple ports, such as interferometers and resonators, this technique can be quite efficient.

Efficient Meshing Strategies for 3D Inductive Heating Models

$
0
0

One of the challenges when modeling inductive heating processes in 3D is that you often need to resolve the skin depth within the part being heated via a thin boundary layer mesh, but don’t want to include the remaining interior of the part within the electromagnetics model. Here, we will look at a meshing technique that efficiently addresses such cases.

Introduction to the 3D Inductive Heating Model

Consider the inductive heating setup shown in the image below, of a coil about an aluminum automotive piston head. For our purposes, we can assume symmetry and reduce the model to a quarter section, with Magnetic Insulation boundary conditions on the symmetry planes. We also approximate the boundary to free space via the Perfect Magnetic Conductor condition.

Side-by-side images of a model of an aluminum cylinder head visualized in gray in orange and the computational domain for the model when exploiting symmetry, visualized as a blue quarter circle.
Inductive heating setup of an aluminum cylinder head and a corresponding computational model exploiting symmetry.

The inductive copper coil, operating at 40 kHz, can be modeled via two homogenized multiturn coils, which do not need to be very finely meshed. However, within the aluminum piston head, the skin depth is comparable to the smaller feature sizes, thus we know that we need to use boundary layer meshing to accurately compute the losses.

Since we know that the electromagnetic fields will not penetrate very far into the material, we would ideally like to omit all of the central volume of the part from the electromagnetic field calculation. On the other hand, we do know that the central volume of the cylinder will affect the thermal solution, so we cannot just remove that volume entirely. We need to partition our part into two subdomains, based on the boundary layer meshing requirements. As it turns out, a combination of meshing tools can be used to quickly and easily set up exactly such a model. Let’s learn more!

Efficiently Setting Up the Model and Mesh

Starting with the geometry pictured above, we define the mesh. We start by generating a tetrahedral mesh within the part and the surrounding air, and we define a boundary layer mesh, composed of four elements each equal to half the skin depth, on the exposed boundaries of the piston, as visualized in the images below.

An image of the cylinder head model mesh, with an insert showing a closeup view of the boundary layer mesh on one of the piston faces.
Mesh, with a highlight of the boundary layer mesh on the piston faces.

Once this mesh is built, we would like to partition the geometry up, based on the boundary between the skin depth mesh and the remaining volume within the part. This requires a few extra steps. First, we need to introduce another 3D Component into our model. Into the Mesh branch of this new 3D component, we will import the mesh that was created earlier.

A screenshot of the model tree on the left and the Import Settings window on the right, with the Source option set to Meshing sequence.
The import mesh operation that copies the mesh from one Component to the other.

After the mesh is brought into this new Component, we need to introduce a Partition feature into the mesh and partition via the expression: isprism, as illustrated in the screenshot below. The isprism variable is a logical variable that is true for only the prismatic elements used within the boundary layer mesh. This operation thus divides the meshed volume of the cylinder into two volumes:

  1. The thin shell that is meshed with prism elements
  2. The remainder

These different domains are available for when we start to add physics to the model. If we ever want to go back and modify the mesh, we will want to go back to Component 1, modify the mesh, and then reimport the mesh into Component 2. It’s important to note that you can’t add an additional geometry into Component 2 — You always have to go back to the original Component, modify the source mesh, and then reimport.

A screenshot of the model tree on the left, Partition by Expression settings in the center, and Graphics window on the right, showing a newly partitioned mesh domain in gray and blue.
The Partition operation, operating on the mesh itself, along with a visualization of the newly created domain.

With this done, it’s possible to solve in the second Component for the electromagnetic fields in just the coil, air, and the boundary layer, while solving for the temperature field throughout the volume of the part. At the boundary between the boundary layer domain and the remaining volume of the part, it is reasonable to apply the Impedance boundary condition, as this will account for any small fraction of the losses that aren’t completely captured within the boundary layer mesh.

For this case, the electromagnetics model of just the coil, air, and skin depth region has ~20% less degrees of freedom than if we also solved for the fields deep within the part, which we already know are insignificant. These savings can be even more considerable for other parts.

Simulation results for the piston head model, with the temperature field visualized in red and yellow and a closeup insert showing the inductive heating for part of the boundary layer domain in blue and red.
The temperature field, computed throughout the volume, as well as the inductive heating, computed only within the boundary layer domain.

Further Resources and Closing Remarks

Find a comprehensive overview of modeling of induction heating and boundary layer meshing in this Learning Center course. The study type to use depends on the nonlinearities present, and if you want to study the temperature rise or the steady-state temperature field, as described in this previous blog post.

The technique shown here, of partitioning based upon the mesh, can be used in many other cases. It is even possible to reimport the resultant mesh as a geometry back into yet another component and remesh. Keep in mind, however, that the boundary layer meshing is an approximation of a uniform surface offset, and that the resultant geometry might not always be suitable for further geometric operations. As an alternative, if an exact offset is required and if robust subsequent geometry operations need to be performed, use the Thicken operation, which is available with the Design Module. However, in situations when an approximate thickness geometric layer is all that is needed, such as for 3D induction heating, the technique described here can be quite helpful.

Try It Yourself

Download the model file associated with this example by clicking the button below.

Viewing all 90 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>