How to Use State Variables in COMSOL Multiphysics®
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.
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:
The settings for this feature are shown in the screenshot below.
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:
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.
The definition of the state variable
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.
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:
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.
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:
This nested if statement will switch the value of
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:
LiquidToSolid(T) are two different functions of temperature associated with the two different branches.
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.
- COMSOL Now
- Fluid & Heat
- Structural & Acoustics
- Today in Science