In a recent blog post, Lexi explained how to best use line, surface, and volume plots. We will now look into arrow plots and how you can use these to your advantage. After a beginner’s guide, you’ll get a “look in the kitchen” via a very interesting industrial application where arrow plots played a crucial design role in winning a consulting assignment.
The arrow plot is a very powerful tool for visualizing field distributions. In COMSOL Multiphysics, we typically compute fields — whether this pertains to turbulent flow velocities, magnetic fields, chemical species transport, or thermal gradients. All of these benefit greatly from being visualized properly.
Generator: Using arrow plots for magnetic fields.
Ozone reactor: Using arrow plots for fluid flow vectors.
Let’s go over the options step-by-step, continuing to use the Heat Sink model that Lexi used in our previous postprocessing blog post as an example.
Starting out, our model only has one 3D Plot Group with a surface plot of the temperature. By clicking on “3D Plot Group 1” in the ribbon or right-clicking “3D Plot Group 1” in the model tree, we can add an Arrow Volume plot.
You will notice that arrow plots exist in three dimensions:
We’ll go for the arrow volume plot in this example, which gives us the following result:
Although useful, it’s hard to gain significant insight with the default settings here. The problem here is two-fold: the arrow color doesn’t stand out enough and the volume is stacked with too many layers of arrows.
Let’s start by tackling the first issue. It seems more convenient to choose a more contrasting color — we’ll go with magenta for now. The arrow color can be modified in the settings window, as displayed here:
Furthermore, we’re better off plotting only one layer of arrows. This can be changed in the same settings window, where the grid points can be chosen:
That gives the following result:
Hmm… Still not so great. What we need are more arrows in the in-plane directions, which are the x- and y-directions here. We’ll change them to 35 to get:
A more insightful perspective can be obtained by clicking the “XY View” button, located above the Graphics Window.
We can easily see how the air finds its way around the heat sink rods, as well as the reduced velocity behind them. This is where the arrow plot provides unique insight into what is going on; if we were instead using experiments, obtaining this information would be very difficult, if possible at all.
My roots are in experimental physics, and over the years, I’ve seen and felt the obstacles within performing such measurements. Think: Expensive downtime, challenging device scale (from microfluidics to enormous water filtration plants), equipment cost, having to interpolate — sometimes guess — between a limited amount of data points, probes influencing the measurement itself, and so on.
As you will notice in the plot, the arrow length is proportional to the velocity by default. This can also be set to Normalized and Logarithmic. The two latter options are great, for instance, to visualize local vortices, which generally have low velocity amplitudes compared to mid-stream values.
Until now, we’ve chosen just one color for the arrows, but they can also be given a color proportional to any expression. This can be done by right-clicking “Arrow Volume 1″ and choosing “Color expression”. By default, this will be given the Rainbow color table.
Changing the color table of the surface plot, we end up with the following image:
Now that you have an idea of how to use arrow plots, let’s have a look at why this is good to know.
I am from The Netherlands, and as you might know, about one third of The Netherlands is below sea level. For this reason, we’ve been very active in the field of water management, starting as early as the 10^{th} century. It’s still a big engineering field today, and the following case falls under the umbrella of this application area.
Pumping stations are used to move water to a higher elevation level, such as to bring water to canals, drain flooded land, and for other water infrastructure applications. These pumps are very large in size — 50 m^{3}/min and up. Below is an example of a water pump station:
Pumping station. “Gemaal van sasse” by Vincent de Groot — http://www.videgro.net — Own work. Licensed under CC BY 2.5 via Wikimedia Commons.
In our specific industry example (not pictured above), a new type of pump was designed to handle a dynamic range of water levels on the inlet side. For various reasons, the designers decided to build an elbow-shaped pipe on the inlet side (imagine the shape of a classic faucet, but with the flow direction reversed). The specs of the pump — power and discharge — were more than sufficient for the job, but when connected to the system, the pump efficiency was measured as being much too low. The target specification could not be met, and, with deadlines fast approaching, the engineers were under pressure to quickly come up with a diagnosis and solution.
Confidentiality of the case prevents me from going into details, but it turns out that their chosen pipe geometry, at certain water levels, creates a swirling flow going into the pump entrance, which severely limits its efficiency. Testing numerous design variations in the field isn’t easy or cheap. Moreover, while you can measure pump efficiency, you would still be in the dark as to the details of the specific flow behavior. This would mean one has to measure a very expensive “black box”, with little idea whether the next design iteration will improve things or why.
For these reasons, the company hired an engineering firm that uses COMSOL Multiphysics with the CFD Module to resolve the issue.
While I cannot provide specific details, I can show conceptually what was going on and why arrow plots were useful in convincing management to go for a specific design modification. For demonstration purposes, I’m using the Flow in a Pipe Elbow model, which is available in our Model Gallery:
As the water flow is highly turbulent, going through a 90-degree bend will strongly distort the field. This can be seen in the velocity plot above, but we can perhaps make it more clear with an arrow plot. With our previous settings, the plot looks as follows:
Because the water speed is still predominantly in the pipe direction, the in-plane speed is somewhat disguised. Let’s do something about that.
As always, you can modify any expression in COMSOL Multiphysics. In this case, we could multiply the in-plane directions of the flow field by a large factor, but it’s even easier to simply set the y-component of the arrow plot to zero:
And the result:
We can now very clearly see how the swirling flow components fade away over distance. Notice that these are not your typical plumbing-sized pipes, but sewage pipe size — the distance of flow settlement is significant and the water moves at violent speeds.
We can also export the results as an animation:
Here’s a closer look:
In the situation of the pump designers mentioned above, the geometry of the entrance in combination with certain water levels created much worse flow distortion effects than those from the elbow bend. Now, to be clear, there are other postprocessing methods to put hard numbers on how quickly (or slowly) the anisotropy dissipates. However, in this specific case, the above images were of decisive importance to convince the higher-ups what the problem was and how it could be solved. The consulting firm in question managed to win the assignment over competitors by providing a quick and cost-effective solution guided by simulations.
If you have any interesting tips or applications related to the topic presented here, make sure to share them via the comments section below. Stay tuned for our next postprocessing topic: slice plots.
]]>
To demonstrate these three plot types, I’ll use the example of an aluminum heat sink, often used for cooling electrical circuitry components. This model is available from the COMSOL Multiphysics Model Libraries if you have the Heat Transfer Module or CFD Module.
The heat sink is made of aluminum, shaped with a cluster of pillars for cooling, and mounted on a silica glass plate. In the model set-up, it sits inside a rectangular channel with an inlet and outlet for air flow. The base of the heat sink initially experiences 1 watt of heat flux, which is generated by an external heat source.
This model includes coupled thermal and fluid flow effects to analyze temperature gradients and cooling power, resulting from thermal conduction and convection.
In some ways, it is easiest (visually) to use surfaces to demonstrate the plot settings in COMSOL Multiphysics. Surface plots are used to show results quantities on the boundaries of a model’s geometry. They can be added either by right-clicking the Results node of the Model Builder or by using the Results tab in the ribbon.
First, I’ll add a 3D plot group, and then I’ll add a surface plot to it. (When you add a 3D plot group from the ribbon, a new tab called 3D Plot Group 1 will appear and you can add surface, line, and volume plots from there, in addition to using the Model Builder.)
Adding a surface plot automatically creates a plot showing the temperature on every boundary in the geometry. However, if I simply create a surface plot, it will look something like this:
This is because the air domain is blocking our view. In order to actually see the heat sink inside, I’ll need to hide some entities. In the Model Builder, expand Component 1 > Definitions > View. The View node is where you can hide boundaries, edges, or entire domains and control the scene lighting of your model. (Take a look at my blog post about the graphics window to learn more about using the View node.)
Now, I’ll right-click the View node and choose Hide Geometric Entities. I’ll set the geometric entity level to Boundary. Then, I’ll select the faces of the channel that are blocking our view of the heat sink (boundaries 1, 2, and 4). If you’re following along in the model, you might also select boundary 121, which is the channel inlet.
The boundaries will turn purple when clicked, indicating that they are selected.
Now, if I return to the plot group, we can see the whole heat sink:
Note that choosing a selection of boundaries in a plot — similar in some ways to hiding geometric entities — allows you to show results on only the boundaries you’ve chosen. This is done by creating a solution under the Data Sets node: Right-click Data Sets and choose “Solution”, then right-click the Solution node and choose “Add Selection”. This selection works the same way as for hiding entities; set the geometric entity level to the correct type and choose the boundaries (or edges, or domains) that you want. When you create a new plot, make sure to choose this solution as the data set.
The settings for color and style make it easy to control the look of the results plots. For instance, here I’ve changed the color table to ThermalLight:
You can also control the color and data range by dragging the sliders under the Range tab. These two options allow you to visualize results on only a specific interval.
Adjusting the color range will align the colors representing the maximum and minimum temperature (white and dark red, respectively) with the chosen maximum and minimum temperatures. For instance, in the plot below, I have set the color range minimum to 320 (temperature is in Kelvin). This is helpful for cases where you’re only concerned with results inside a certain interval — so in this case, I only want to see a gradient in areas of the heat sink that are hotter than 320 K:
The manual data range controls something a little different. Rather than changing the color shown for a specific data range, this only plots the data interval specified by the maximum and minimum. Raising the minimum or lowering the maximum will actually remove data points from the plot:
Another interesting feature of the Coloring and Style tab is a check-box under the main node (3D Plot Group 1) labeled Plot data set edges. Unchecking it will cause the plot to remove the black lines on the edges of the geometry. This is easiest to see on the plot with the altered color range, below:
Line and volume plots can be added the same way I added a surface plot in the previous example, by right-clicking the Results node or using the ribbon. Next, I’ll add a new 3D plot group with a line plot. Using the View node again, this time to hide the edges of the channel. I have plotted only the edges of the heat sink. This plot will show the change in temperature on the individual edges, allowing us to see clearly how the temperature is changing along the height of the pillars:
Note: All of the examples shown will use 3D plot groups, but they have an equivalent in 2D as well. For instance, in a 2D plot group, this type of plot would be used to show temperature on the edges that lie in a certain plane.
Likewise, a volume plot shows the change in a variable through an entire 3D domain. Volume plots can often save you the trouble of selecting many individual boundaries, the way you might need to for a surface plot. For instance, if I wanted to see the heat sink only, I could create a surface plot using a data set that contains all the boundaries of the heat sink. But in the figure below, I have plotted the temperature on the volume of the heat sink domain (excluding the channel domain), and we can see the temperature gradient:
That’s it for a run-down of these plot types and how to control their coloring and style! Hopefully this demonstration will help you get started in some effective postprocessing. These are just a few of the plot types available in COMSOL Multiphysics — stay tuned for future posts demonstrating other plot techniques, such as arrows, streamlines, contours, and some application-specific types. We will also demonstrate using cut line plots, which allow you to plot any quantity along an arbitrary line through the model.
]]>
In a 3D model, we are often interested in understanding how a solution evolves along a particular direction. Let’s consider the 3D Laminar Static Mixer model, where the fluid velocity and concentration distribution are primarily varying along the axial direction. This model shows how the static geometric obstacles induce secondary flows in the device, which, in turn, improve the mixing characteristics. The plot below shows the steady-state concentration distribution on parallel sections (or slices).
Concentration slice plot in a laminar static mixer.
The plot shows how the concentration changes from a perfectly unmixed state to a mixed state. Let’s look at how we can present this information using an animation. Our objective is to stitch the static slices together to create the frames of a movie.
The first step is to add a parameter corresponding to the axial coordinate. For this example model, we add a parameter zp as shown in the screenshot below.
Adding a parameter in the Parameters table.
Second, we need to change the slice plot settings. In the Plane Data section, let’s change the Entry Method to “Coordinates” with zp as the input to the z-coordinates field. These changes enable us to plot the solution in the plane z = zp.
Plane data settings for concentration slice plot.
Last, we need to add an Animation or Player node to the model (right-click on Export under the Results node and choose “Animation”). We would like to generate an animation that plots the solution as the slice location zp moves from one end of the mixer to the other.
In the Animation settings, choose the Subject as “Concentration (chds)”, which is the concentration slice plot.
Now, let’s change the Sequence type to “Result parameter” with zp as the Parameter ranging from -6 to 36, as shown below. One could also use similar animation settings in the Player node (right-click on Export and choose “Player”) to visualize animations within the COMSOL Desktop.
Animation settings for changing the slice location.
Now, click on the Export button to create the desired animation. The resulting animation for our Laminar Static Mixer model appears below.
Animation showing concentration evolution along the axial direction.
It is simple to further customize your animations in terms of frame rate, orientation, animation format, etc. This is done through various options in the Animation and Plot settings. For example, the following animation shows the same animation with an xy view without the data set (geometric) edges.
Animation showing concentration evolution (xy view) along the axial direction without the data set edges.
We have used a very simple three-step procedure to combine cross-sectional data (parallel slices) to create an animation for a 3D steady-state model. Now, suppose we are interested in finding the maximum (or minimum) value of any variable in each of these parallel slices.
Do you think we can create a plot of cross-sectional maximum (or minimum) values along the axial direction? I will address this post-processing question in a follow up blog entry. Stay tuned!
]]>We have all experienced the boredom and frustration of being stuck in a traffic jam. Very often, traffic congestion comes and goes for no obvious reason. Employing the analogy to gas dynamics, we can now simulate traffic flow using the equation-based modeling capabilities of COMSOL Multiphysics and gain a better understanding of why congestion happens.
The Texas Transportation Institute estimates that in 2000, the 75 largest metropolitan areas experienced 3.6 billion vehicle hours of delay, resulting in 5.7 billion gallons in wasted fuel and $67.5 billion in lost productivity. We are inclined to blame bad weather, poorly timed traffic lights, and other drivers for not merging into the exit lane in advance. It must be someone’s fault.
According to a 2005 report by the Federal Highway Administration (FHA), about 40% of traffic congestion in the U.S. occurs as a result of sheer volume of traffic. Between 1980 and 1999, vehicle miles of travel grew by 76% while the amount of new roads or lanes increased only by 1.5%. There simply aren’t enough or large enough roads. However, can a large volume of vehicles alone cause congestion? If everyone drives at a constant speed of 55 mph, a congestion is unlikely to happen, isn’t it?
A group of Japanese scientists, Sugiyama et al., conducted an experiment in March 2008 to prove us wrong. As shown in this video, 22 homogeneously distributed cars are initially traveling at the same speed on a circuit. A traffic jam then appears out of nowhere and propagates backward like a solitary wave.
MIT professor Rodolfo Rosales calls this phenomenon phantom traffic jam, which arises without any bottleneck or obstacle. When the traffic density passes a critical threshold, even a small perturbation in the traffic flow can amplify into traveling waves of high traffic density. This means that in rush hour traffic, when we reach for a cup of coffee or fiddle with the radio, the perturbation in vehicle speed might just be enough to leave the road haunted by phantom traffic jams.
Besides experiments, phantom traffic jams can be observed in a numerical simulation study. Since traffic flow resembles inviscid fluid flow, the phantom traffic jams can be modeled as detonation waves produced by explosions. A widely known model depicting this phenomenon is the Payne-Whitham model. The corresponding partial differential equations (PDEs) are implemented as an equation-based model in COMSOL Multiphysics.
The equations for the density and velocity of the cars are implemented directly in the COMSOL Multiphysics user interface (UI). Because it does not require any coding, such a model can be implemented in a few minutes.
The COMSOL Multiphysics model consists of a one-dimensional line 500 meters in length with periodic boundaries. In the following animation, the two ends of the line are connected to form a circuit, where 27 cars are traveling clockwise. Traffic density is represented by the radius of the red curve on the outside as well as the colors on the inner ring. A small initial perturbation is introduced to the traffic flow, which later grows into a traveling peak on the traffic density curve. Correspondingly, the congestion locations change from green to yellow and red in the color ring. We can clearly see how small sections of congestion emerge, form a single traffic jam, and propagate backwards in traffic, i.e. counter-clockwise, just like in the video of the experiment we linked to above.
Traffic density evolution normalized against maximum density.
Reducing the number of cars on the circuit can obviously alleviate the congestion. Another interesting aspect of the model is that we assume each driver has a reaction time of 3.3 seconds. That means a driver needs 3.3 seconds to fully adjust their speed to match the speed of traffic. This delay in reaction is partially responsible for amplifying the initial perturbation. Supposing all the cars are equipped with radar-guided cruise control and the reaction time is reduced to 0.4 seconds, the congestion can be eliminated altogether — something to factor in next time you buy a car!
Although the Payne-Whitham model only simulates a simplified version of our daily commute, more complexity can be added using the COMSOL Multiphysics equation-based modeling capabilities. The COMSOL software can not only handle different types of PDEs, but also ordinary differential equations (ODEs), algebraic equations, and transcendental equations. These capabilities are all included in the core functionality of COMSOL Multiphysics.
Consider a situation where you have solved a problem for a range of parameters using the Parametric Sweep feature in COMSOL Multiphysics and want to compare the results for the different values of the parameter against each other or a benchmark value of the parameter. An important example of this is a mesh convergence study, where the element size is the sweep parameter and the solution for each mesh size is compared with the solution on the finest mesh.
To evaluate the difference in some norm, you first need to make a join data set. As discussed earlier, when “joining”, or comparing, solutions, you will be asked to choose which two base data sets you intend to join: data1 and data2. For a parametric study, each base data set contains more than one solution. Thus, you have to decide whether you want to compare just one or all of your parameter values to the benchmark solution. In a mesh refinement study, for example, you can choose “All” for data1 and “One” for data2. When you choose “One”, COMSOL Multiphysics will present you with a drop-down menu, where you can pick the benchmark value.
In the figure below, the value of the element size parameter, hn, for the finest mesh is 16.
Joining a parametric solution comparing all of the parameter solutions to the benchmark solution from the finest mesh.
Once you have built the join data set, the next step is to use it in postprocessing. For the above 2D steady state heat transfer problem, consider the integral of the square of the difference in temperature, i.e., the L2-norm of the difference. To perform a spatial integration, go to Results in the Model Tree, right-click “Derived Values” and choose “Surface Integration” to get the following settings window:
Settings window for calculating the the L2-norm of the difference in temperature .
Above, you can see that you have a choice of using one, some, or all of the parametric values for the postprocessing step. Note that this is possible because the “All” option was used for the first data set when you built the join data set. By choosing “All” in the Surface Integration settings window, when you then click “Evaluate”, the L2 difference between the solution on the finest mesh and all other meshes will be evaluated and tabulated. To this end, the COMSOL software takes the solution for each value of the sweep parameter and uses it for data1, whereas the solution for hn = 16 is used for data2. Using the Table Graph feature, you can obtain a plot of the difference versus the mesh size.
Plot using the specified join data set that compares the L2-norm of the difference in temperature versus the mesh size. The plot can be instantly made by using the Table Graph button.
COMSOL Multiphysics allows you to perform parametric sweeps using more than one parameter. In a multiparameter sweep, you have two options for Sweep type: “All combinations” and “Specified combinations”. In the first case, the COMSOL software carries out a nested parametric sweep, where every combination of parameters is utilized. In the second case, a combination of parameter values with the same indices is constructed, where the parameter value lists for all parameters need to have the same lengths. As far as solution joining is concerned, this case is the same as a single parameter sweep. Thus, in the investigated case here, we will assume that the Sweep type is set to “All combinations”, where the parameter lists do not need to be of the same length.
In the mesh convergence study above, a convective heat flux boundary condition with heat transfer coefficient of 5 W/(m^{2}K) was used as a boundary condition. Let us parameterize this coefficient, using the parameter name hflux, so as to compute the solution for all combinations of the heat transfer coefficient and mesh size. Here’s what that looks like:
Setting up a multiparameter sweep. The heat transfer coefficient is parameterized from 5 W/(m^{2}K) to 20 W/(m^{2}K) with steps of 3 W/(m^{2}K), while the mesh is parameterized in the same way as the previous case.
When you create the join data set, COMSOL Multiphysics gives you a vectorized list of the parameters in order to identify the base or benchmark solution. In this example, we should choose one of the combinations with hn = 16, which in our case will be hflux = 8 W/(m^{2}K):
Join data set with a multiparameter sweep. The case for the finest mesh (hn = 16) and a heat transfer coefficient of 8 W/(m^{2}K) is used as the benchmarking solution.
Finally, to evaluate the L2 norm difference, we use the Surface Integration like in the case of a single parameter sweep. The difference here is that instead of using all solutions, we only use the case with hflux = 8 W/(m^{2}K) and all values of the mesh size. There can be reasons where all combinations have to be considered, but for a mesh refinement study, solutions with the same problem parameters (material properties, boundary conditions, etc.) require that only different mesh sizes are compared.
Specifying the L2 norm of the temperature difference for all mesh refinement parameters at a heat transfer coefficient value of 8 W/(m^{2}K).
To repeat the convergence study for the next value of the heat transfer coefficient (11 W/(m^{2}K)), you can go back to the Join settings window and choose the parameter combination for that value of hflux and hn = 16 as the second base solution.
Sometimes, you may have base solutions defined on different domains. This can, for example, arise if a parameter used during geometry creation is applied in a parametric sweep. In such cases, the software implements the join data set only over the intersection of the domains used for the base solutions.
The methods for stationary parametric studies as described above work similarly for other study types. For eigenfrequency, frequency domain, and time-dependent studies, the parameter sets will be formed by the eigenfrequencies, frequencies, and time steps, respectively.
For eigenfrequency, frequency domain, and time-dependent studies, COMSOL Multiphysics has default operators that can be used to work with multiple data sets: the with operator for all three and the at operator for just time-dependent studies.
The with operator can be used to access solutions during results evaluation. The operator takes two input arguments. The first one is a positive integer, which is an index to identify the solution. A value of 1 identifies the solution with the lowest eigenvalue, frequency, or time value. A value of 2 is used for the second lowest value, and so on. The second input argument is the expression that you want to evaluate using this solution.
Now, we will show how you can emulate what you can do with a join data set while using the with operator. The main idea is that while non-indexed quantities are evaluated at the solution picked in the Data set option in that operation’s settings window, you can override that choice by indexing using the with operator. We will use this to illustrate how to verify orthogonality of mode shapes in an eigenfrequency study.
Verifying orthogonality of mode shapes using the with operator.
The above figure is from an eigenfrequency study of a 3D solid mechanics problem, where we evaluated the six lowest eigenvalues. Since we chose “All” in the Eigenfrequency selection in the Volume Integration settings window, COMSOL Multiphysics evaluates the integrand shown under “Expression” for all six values.
In each case, while the displacements u, v, and w in the x-, y-, and z-directions, respectively, are evaluated at the current eigenfrequency value that is considered, the value indexed using the with operator is evaluated at the first eigenfrequency. Thus, we expect all but the first value of this evaluation to be negligible. This is shown in the table below:
Dot product of mode shapes evaluated using the with operator.
The same idea holds true if you want to plot the difference in the solution, for example. In a solid mechanics problem, you can type with(1,v)-with(2,v) under Expression in the plot settings window to plot the difference in the y displacement of the two lowest eigenvalues. In a model with a solid mechanics problem, the COMSOL software allows you to plot a solution on a deformed configuration if you add a Deformation node to the plot. You may be wondering which values of displacement are used to obtain the deformed shape. By default, the solution corresponding to the plot’s data set is used. For eigenfrequency, frequency domain, and time-dependent studies, you can override that choice using the with operator in the Deformation settings window.
In the case of time-dependent problems, the at operator offers additional functionality during the results evaluation. Like the with operator, the at operator takes two arguments with the second argument similarly being the expression to be evaluated. The first argument is a positive real number for the actual time. For example, if 1 is used in the first argument, it means t = 1 (in the relevant unit of time) and not the lowest time the problem is solved for. If a solution has already been computed for the specified value of time, COMSOL Multiphysics uses the computed solution. Otherwise, it provides a solution at that time using interpolation.
Can the with and at operators substitute a join data set for eigenfrequency and transient analyses? The answer is that while you can reproduce certain operations on joint data sets using these two operators, solution joining has additional advantages. The with and at operators have access to solutions in the same data set only. Consider a situation where you have solved a time-dependent problem for two different initial conditions. You will have two data sets, say Solution 1 and Solution 2, each containing solutions for all time steps of the corresponding initial condition. If you want to compare the solution based on the first initial condition to the solution based on the second initial condition, you can only do this using join data sets. Moreover, solution joining gives you a new data set that you can now use as a base solution in another join operation.
In some situations, using the with or at operators can be easier than making a join data set. For instance, if you want to simultaneously work with solutions from more than two time steps from a time-dependent study, you would have to form more than one join data sets. Yet, by using the with operator you can just type, for example, with(1,u) + with(2,u) – with(3,u), where u is the quantity you are interested in, without the overhead of having to create multiple join data sets.
In this blog entry, we have extended our discussion of solution joining for single stationary solutions to parametric, eigenfrequency, frequency domain, and time-dependent solutions. For the last three types of studies, we have also shown how the with and at operators can be used to carry out operations akin to what solution joining offers.
In particular, we have demonstrated how solution joining can be used to carry out a mesh convergence study. The norm used to evaluate convergence was the square of the difference in the dependent variable.
]]>To join solutions, right-click on Data Sets under “Results” and choose Join. When using the ribbon (or menu if you’re running Mac® OS or Linux®), the command is Results > More Data Sets > Base Data Sets > Join. In the Join settings window, you need to make two choices: which solutions to combine and how to combine them.
You determine the base data sets under the Data 1 and Data 2 sections. Right beneath Data 2, you can configure the combination method.
The Join settings window.
There are seven choices for the combination method. However, five of those can be taken as special cases of the other two options. We will start by discussing the General and Explicit methods.
When Method is set to General, a field appears where you can enter an expression. For instance, data1-data2
makes a difference expression and (data1-data2)^2
the square of a difference. The latter can be used, for example, as an integrand for evaluating difference in the L2 norm.
At this stage, the variable that is going to be compared is not specified. In essence, we are constructing an operator that can later be used with any quantity defined in both of the original base solutions. Consider a problem where T
is the dependent variable, such as in a heat transfer problem.
Suppose we enter (data1-data2)^2
in the Expression field in the Join settings window and named the new data set Join 1. Then, to plot the square of the difference in the temperature, we choose Join 1 for Data set and T
for Expression in the plot settings window.
To demonstrate the use of solution joining using the General method, we will consider two modeling examples.
In this example, a 2D plane stress model of a membrane with a thickness of 0.1 meters is alternately loaded by a uniformly distributed load of 10 MN/m along the right end and a triangular load at the same edge with a maximum intensity of 20 MN/m at the center and vanishing at the ends. These two loads are statically equivalent. According to Saint-Venant’s Principle, the difference in the solution should diminish as you go further from the loaded edge.
We compute two stationary solutions using first the uniform load and then the triangular load. Then, we create a joint solution Join 1 using the General combination with abs(data1-data2)
in the Expression field as shown in the above figure. To plot the absolute difference in the von Mises stress, we now make a surface plot using the Join 1 data set and solid.mises
in the Expression field of the Surface settings window. In the figure below, the difference is large near the loaded edge and much smaller far from the edge, as predicted by Saint-Venant’s Principle.
Von Mises stress with uniform and triangular edge loading, and absolute difference in von Mises Stress.
Engineers run analyses for different conditions and want to know the best or worst case situation at all points in the domain. For example, in a thermal analysis, the maximum temperature is of interest. At some points in the domain, the maximum temperature is encountered for one set of boundary or domain conditions and at other points for other sets of conditions. The temperature envelop shows the extreme temperature values at each point under any circumstance.
In this example, we consider a simple stationary 1D heat conduction problem. In the first case, the temperature goes from 300 K at the left end to 400 K at the right end. In the second case, the temperature is flipped, going from 400 K at the left end to 300 K at the right end.
To construct the maximum temperature envelop, we make a joint data set Join 1 from the two solutions using the General method and max(data1,data2)
for the expression. Then, in a line plot, we choose Join 1 for the data set and T
for the expression to get the maximum temperature envelop (depicted below).
Result enveloping settings.
In the plot below, you can see the joining operation and the result envelop together with the results from the two base cases:
If we want to plot the minimum temperature envelop, we have to add a new joint data set using min(data1,data2)
in the Join settings window.
There is one restriction when using the General method for joining: you have to use the same variable from both base solutions in subsequent operations, such as plotting or integration. For example, to plot the sum of the variable u
from the first data set and the variable v
from the second data set, you cannot use the General method. If we have data1 + data2
under Expression in the Join settings window, we can use it either with u
, which returns data1(u) + data2(u)
, or with v
, which returns data1(v) + data2(v)
.
This is where the Explicit method comes in handy. When you opt for this method, COMSOL Multiphysics makes two new operators, data1
and data2
, which can be used to access quantities from the first and second data set, respectively. A difference with the General method is that there is no field for typing an expression at the solution joining stage. The two operators can be used directly later in the plot, integration, average, or other settings. For instance, data1(u) + data2(v)
can be typed in a plot settings window, provided that u
is a legitimate variable in the first solution and v
is available in the second solution.
Another advantage of the Explicit method is that since an expression is not fixed at the solution joining stage, you do not need to create a new joint data set to use a different expression. In a 1D heat transfer problem, for example, we can make an Explicit joining and use it in two different line integrations for both the L2 and H1 norms. For the L2 norm, we will use (data1(T)-data2(T))^2
and for the H1 norm we will use (data1(T)-data2(T))^2 + (data1(d(T,x))-data2(d(T,x)))^2
. Here, d(T,x) is the derivative of T
with respect to x
, which is a predefined operator in COMSOL Multiphysics.
Going back to the temperature envelop example, we needed two joint data sets to make the maximum and minimum temperature envelops using the General method. If we instead went with the Explicit method, we would only need one joint data set and use max(data1(T),data2(T))
and min(data1(T),data2(T))
in line graphs to plot the maximum and minimum envelop, respectively.
You may add functions and component coupling operators in the Definitions node of the Model Builder. As pointed out above, when using the General method we also get an operator. Thus, we end up with a composition operator when we employ a user-defined coupling operator or function with a data set joined using the General method. The question is: Which operator is the inner operator and which is the outer operator in the composition? The answer is that the operator made by the solution joining is the outer one and any operator added in the Definitions node becomes the inner operator. Let us look at an example to illustrate the idea.
Consider a coupling operator intop1
added in the Definitions node of the above 1D heat conduction example. A data set Join 2 is made from two solutions using the General method and the expression (data1 - data2)^2
. If we choose Join 2 for Data set and intop1(T)
for Expression in Results > Derived Values > Global Evaluation, will we get the L2-norm of the difference between the two base solutions? The answer is no. The global evaluation returns a value of zero.
Since intop1
is the inner operator, what gets evaluated is (intop1(T)-intop2(T))^2
, which clearly is not the L2 norm of the difference. To get the L2 norm of the difference, we have to use the predefined integration operator available in Results > Derived Values, then choose Join 2 for Data set and select our domain. Finally, use T
for Expression. The figures below show the COMSOL Multiphysics implementations of these operations and their mathematical representations.
Using operators on joined solutions with the General method.
In summary, the order of operators in a composition operation is as follows: functions or coupling operators added in the Definitions node; the operator created by Join; and predefined average, maximum, minimum, and integration operators available in Results > Derived Values, from inside to outside.
When using the Explicit combination, the situation is clearer. The figures below show how the difference of the integrals and the integral of the difference are evaluated on an explicitly joined data set Join 3.
Using operators on joined solutions with the Explicit method.
The other five combination methods are Difference, Norm of Difference, Product, Quotient, and Sum. They are equivalent to using the General method with data1-data2
, abs(data1-data2)
, data1*data2
, data1/data2
and data1 + data2
for Expression
. Of course, whatever can be done with the General method can also be done with the Explicit method by building the expression later at the point of use.
In this blog post we have focused on joining stationary solutions with no parametric sweeps. In the case of parametric sweeps or in time dependent solutions, each base solution contains more than one data set. The same is true for eigenfrequency and frequency domain studies. For these study types, solution joining can be used to evaluate some useful and interesting quantities. We will discuss that in a follow-up blog entry.
Flux refers to the area density of any quantity that flows through a well-defined boundary of a domain. The domain could be a volume (in 3D), surface (in 2D), or edge (in 1D). Correspondingly, the boundary through which we compute the flux would be surface (in 3D), edge (in 2D), and point (in 1D), respectively. The total flux through the cross section is then the sum total of flux coming out of that boundary. Although this idea has its origin in the field of transport processes, the concept of flux and total flux can be related to many physics. This is because most physics are mathematically formulated based on some form of conservation equation. The following table provides a summary of flux-type physical quantities from different physics areas.
Physics | Flux | Total Flux | ||
---|---|---|---|---|
Electrostatics | Electric displacement or Surface charge density (Unit: C/m^{2}) | Surface charge (Unit: C) | ||
Electric Currents | Current density (Unit: A/m^{2}) | Current (Unit: A) | ||
Magnetic Fields | Magnetic flux density (Unit: T) | Magnetic flux (Unit: Wb) | ||
Mass Transport | Rate of Material flux (Unit: mol/m^{2}s) | Material flow rate (Unit: mol/s) | ||
Fluid Dynamics | Mass flux or Mass flow rate per unit area (Unit: kg/m^{2}s) | Mass flow rate (Unit: kg/s) | ||
Heat Transfer | Heat flux or Power per unit area (Unit: W/m^{2}) | Power (Unit: W) | ||
Structural Mechanics | Stress (Unit: Pa) | Force (Unit: N) |
Now, let’s look at an example to find out the simple math behind computing flux.
A simple example of computing current through a conductor.
Imagine a cylindrical conductor (shown above) through which electric current flows as a result of a potential difference across its two ends. Now, let’s focus on a small section of the conductor along its length (shown above as the red-dashed disk). The left and right ends of the disk are at position x_{1} and x_{2}, respectively, and have a constant cross-section area of A. The electric potential on the left and right ends of the disk are V_{1} and V_{2}, respectively. The electrical conductivity is denoted by σ. For electric current conduction, the flux physically signifies the total number of electrons flowing through the cross section per unit time (referred to as current density). Using Ohm’s Law, the current density (J) through this cross section can be computed from the following expression:
Now, in order to compute the current density through a cross-section boundary, let’s imagine that we squeeze the thickness of this disk, so that Δx ≈ 0. This helps us make the jump from algebra to differential calculus and express the flux through a boundary as:
Now, let’s make another jump from one-dimensional current conduction to a three-dimensional scenario where the electric potential as well as the conductivity could, in general, vary as a function of x-, y-, and z-coordinates. This would give us a current density vector:
Using notations from vector calculus, the above expression could be written in a more compact form:
Going back to our simple example, let’s say we are interested in finding out the total current passing through any arbitrary cross section of the conductor. For a straight cylinder with a constant cross-section area, we can easily find the total current passing through any section, by multiplying the cross-section area with the current density (flux).
What would you do for the three-dimensional case with the flux vector?
Here, we will follow the principles of integral calculus to find that out.
An arbitrary boundary (∂Ω) in 3D space whose normal vector is \hat{\bf n}=\begin{bmatrix} n_x & n_y & n_z\end{bmatrix}. The flux through this boundary is specified by the vector, \overrightarrow{\bf J}=\begin{bmatrix} J_x & J_y & J_z\end{bmatrix}.
To find the total normal flux through an arbitrary boundary, denoted by ∂Ω, we first need to find the normal flux through that boundary. This can be obtained from the dot product of the normal vector (\hat{\bf n}) of the boundary and the flux vector (\overrightarrow{\bf J}). The total normal flux can then be obtained by integrating this quantity over the boundary. The final expression used for computing the total normal flux would then be:
Now let’s find out how you can compute the total normal flux on a planar surface in the COMSOL software. We will look into two possibilities.
Let’s solve a DC electric current conduction problem on a bent copper wire whose two ends are at a potential difference of 1 mV.
Overview of the electric current conduction model set-up. All geometric units are in millimeters (mm).
Here, we use the Electric Currents interface and a stationary study to solve a DC current conduction problem. A swept mesh is used on the geometry.
Representation of the problem in the COMSOL software.
Before we proceed to compute the total current in the conductor, let’s take a look at the current density variation inside the conductor.
Spatial variation in the magnitude of current density and direction of current flow.
As moving charges try to take the shortest path (least resistance), we see that, in the curved section of the conductor, the current density varies through the volume significantly. It is largest near the inner radius and smallest near the outer radius.
Now, let’s turn our attention to one of the internal boundaries that connects the straight and curved regions.
Spatial variation in the magnitude of current density on one of the internal geometric boundaries. The arrows show the direction of the normal vector of this boundary. Note that this direction coincides with that of the direction of the current flow.
In order to compute the total current flowing through this cross section, we will use the Surface Integration feature, which is available under Results > Derived Values.
Snapshot of performing a surface integration to compute the area integral of the dot product of current density vector and surface normal vector.
Remember the integrand to obtain the normal flux: ( n_xJ_x+n_yJ_y+n_zJ_z ). For arbitrary geometrical shapes, this expression can be very complicated. The good news is that the COMSOL software contains automatic, built-in expressions for this, which can be used in both pre- and postprocessing. Here is how the expression looks in COMSOL Multiphysics:
nx*ec.Jx+ny*ec.Jy+nz*ec.Jz
Here, the components of the current density vector are available as built-in variables, namely, ec.Jx, ec.Jy, and ec.Jz. You can also find similar variables for the the flux quantity in other physics interfaces. The COMSOL software automatically computes the normal vector for all of the boundaries on the geometry. This information can be accessed by using the variables nx, ny, and nz.
Using this approach, we find the resulting current to be 62.9 A.
Now, let’s find out how you can implement the same idea on an arbitrary planar surface that cuts through the modeling geometry.
You can use the Cut Plane feature under Results > Data Sets to create such a planar surface. There is no need to go back and change the actual modeling geometry to insert this surface and solve the model again. This is a big advantage when you decide to visualize or compute some quantity on an arbitrary planar surface. The cut plane can be created using two alternate approaches.
Screenshot showing the options to create a cut plane. The green line in the Graphics window represents the boundary of the cut plane intersecting the modeling geometry. The red line is the normal of the cut plane. (Click to enlarge)
Screenshot of the Settings window for the Cut Plane branch, which is found under Results > Data Sets. Variable names for the surface normal vector can be invoked from the Advanced settings, by checking the “Define normal variables” checkbox.
In order to access the variables corresponding to the normal vector of the cut plane, you would need to look under the Advanced section in the settings window of the Cut Plane data set branch and check the box to “Define normal variables“. This will invoke the variables cpl1nx, cpl1ny, and cpl1nz. The default naming convention for these variables uses the tag name (cpl1) attached to the Cut Plane 1 data set. So, if you create another cut plane, its normal variables will automatically be given a different name. You can also replace these default variables names with other names of your choice.
The COMSOL software computes the cut plane normal vector from the cross product of the two base vectors that define the plane. These base vectors are computed from the coordinates of the three points that are used to define the cut plane.
Surface plot of the magnitude of current density on the cut plane and an arrow surface plot showing the cut plane normal vector with red arrows.
Finally, let’s find out how we can compute the total normal flux (current) passing through the cut plane.
Once again, we use the Surface Integration feature. This time, we need to ensure that the data set for the Surface Integration branch is set to Cut Plane 1 (or the desired cut plane data set, if you have multiple cut planes).
Snapshot of performing a surface integration to compute the area integral of the dot product of current density vector and surface normal vector of the cut plane.
The expression that we integrate over the surface of the cut plane is the following.
-(cpl1nx*ec.Jx+cpl1ny*ec.Jy+cpl1nz*ec.Jz)[1/mm]
Here, the negative sign that precedes the expression is used, because the direction of the cut plane normal is opposite to that of the direction of current flow. Also, note the normalization of the unit by using the [1/mm] factor. This is done to take into account the fact that the modeling geometry uses the millimeter as the length unit of choice. Using this approach, once again, we confirm the resulting current to be 62.9 A.
Now you just need to open your favorite COMSOL Multiphysics model and try out what you learned here on any other physics of your choice.
You can learn more about postprocessing in COMSOL Multiphysics from the videos and blogs available on our website.
]]>
Substrate integrated waveguide (SIW) antennas are small devices that are showing promise for use in applications such as military and satellite communications. Very simple to implement, they make it easy to direct radiative waves. Visualizing results on these devices can give an integrated picture of the geometry, materials, and physical phenomena that are present. I asked my colleague, Jiyoun Munn, to teach me how to show RF radiation in an SIW antenna using the postprocessing tools available in COMSOL Multiphysics. Here’s what he told me.
Below is the geometry of a model that we’ll use to explore some postprocessing techniques. We’ll include different surfaces for different geometric components in a solution plot. This kind of visualization is particularly helpful for guiding knowledge of the physics occurring in a device. It is also helpful for verifying that the hardware is operating correctly.
This antenna contains a copper microstrip overlaid on a dielectric surface (usually a mix of PTFE or Teflon and fiberglass) and a series of slots that are open to the environment. These each function as a radiation source, facilitating what are called “leaky waves”, or waves that escape from the waveguide through the slots. The slots are spaced so that waves exiting each slot will have a different magnitude, phase, and radiating energy. The lumped ports are the input (Lumped port 1) and output (Lumped port 2) where waves enter and leave the waveguide.
This model is named siw_leaky_wave_antenna.mph. The fully solved model is accessible from the COMSOL Model Libraries Update (under File > Help > Update COMSOL Model Library > Full Models > RF Module > Antennas). Upon opening the model, one of the first things you might notice is that the geometry contains several domains outside of the antenna itself. These are the air domain and perfectly matched layers (PML) that surround the model, but for visualizing purposes, we don’t want to see them. So the first thing we’ll do is hide these geometric entities.
Right-click the View node under Component > Definitions and select Hide Geometric Entities. Make sure that the Geometric entity level is set to “Domain”. You can select a section of a domain by clicking on it (it will turn red when you move the mouse over it):
Once you’ve hidden each section, right-click the View node and choose Hide Geometric Entities again. This time, select all of the circular domains that surround the antenna. This leaves us free to see the hardware clearly.
Note: This same feature also enables visualization of the interior of the modeling domain. While we don’t need to see the inside of the hardware for this model, this capability can give a good look into the physics happening inside a device. We’ll demonstrate this feature in Part 2. Stay tuned!
Now, expand the Data Sets node under Results. Duplicate Solution 1 four times by right-clicking its node and choosing Duplicate. We’ll set each of the new solutions to correspond to one part of the geometry, so that we can plot different results on different areas of the hardware. Rename each new solution (preserve Solution 1 as it is) according to the part of the geometry it will correspond to — Copper, Dielectric, Vias, and Slots.
For each of these solutions, we’ll need to select the appropriate geometric entities. Right-click the Copper solution and choose Add Selection. From the Geometric entity level, choose Boundary. Then click on the microstrip. Since we will only be looking at the top of the antenna, there is no need to select the copper areas on the bottom.
Do the same for the dielectric, vias, and slots (see the images below to check your selections).
To select the vias, there are a couple of methods that are easier than selecting each section of each cylindrical boundary one by one. If the vias have been previously organized into a group, you can choose that group as the data set. If they haven’t, the simplest way to select all of the boundaries is to arrange the graphics view so that all the vias are in vertical columns and you can draw a selection box around each set. Click and drag the mouse until you’re happy with the model orientation.
The Select Box tool is located in the toolbar at the top of the graphics window (). Click and drag the box carefully around the elements you want to highlight (each column of vias, in this case):
You may end up with a few more boundaries selected than you want (as in the figure above, where several boundaries on the slots are highlighted in purple). To deselect these, click on each one.
Click on the circular boundary at the top of each via hole in order to deselect it. This is easier if you zoom in. Since the vias are open to the environment on top and in the center, we don’t want the top boundary to look like metal. (This might seem like a long process, but it’s faster than selecting each boundary of each cylinder one by one!)
Now that we have each data set, we can begin adding results plots. Right-click the Results node and add a 3D plot group. I prefer to not see data set edges in this surface, so I have unchecked the Plot data set edges box in the plot settings window.
Right-click the new plot group (3D Plot Group 4) and choose Surface. Since we’re plotting on several different components — copper, dielectric, metal vias, slots — we’ll need several surfaces. Duplicate the surface you just created three times. Your results node should now look like the one below.
First, let’s make the microstrip a nice copper color. Go to Surface 1. In the settings window, change the data set to “Copper”.
To save some computational resources, we’ll set the expression to a dummy variable. Since we’re not plotting results on this part of the geometry, there’s no need for a physics expression. Instead, set the expression to 1.
Go to the Coloring and Style tab and change your settings to match roughly what’s shown below. Make sure to set the Coloring selection to “Uniform” and then choose a custom color that’s close to copper.
Initially, it’s going to look a little weird. But that’s okay; once we add colors for the other materials, the geometry will start to become clearer.
Next, let’s add color for the dielectric and the vias. We’ll do this exactly the way we did for the copper microstrip (choosing colors that match the materials). For the dielectric (if you recall, this is usually made of a PTFE laminate), choose an off-white color. For the vias, choose a metallic silver.
Our geometry is starting to look a little more realistic. For the slots, though, we’ll plot results from the simulation data. The slots are where the leaky waves are generated, so we’ll want to show how strong the electric field is in each one, and how it changes from one end of the waveguide to the other.
For Surface 4, set the Data set to Slots. This time, choose Replace Expression in the Expression tab. Navigate to Electromagnetic Waves, Frequency Domain > Electric and double-click Electric field norm (emw.normE). Click Plot:
We can see from the results we just plotted that the electric field is highest near the input port and weakens toward the output port. But we can’t tell much else, since the plot is so small. Let’s see if we can get a better view of the radiation pattern.
Right-click 3D Plot Group 4 and choose More Plots > Far Field. A far-field calculation behaves as if the antenna is very far away and so gives a wide view that shows both the direction and the intensity of the radiating energy. As with the surface plot we created in the slots, we want to know how strong the electric field is and how it changes.
Go to Replace Expression > Far field and double-click Far-field norm (emw.normEfar). Click Plot.
We can see the 3D radiation pattern in the center of the microstrip, but it’s very small. Since we are treating the waveguide as though it is very far away, we can’t really tell what’s going on from here. In order to see it more clearly, we’ll magnify it.
This is easy to do; multiply the expression by a factor of 10. You can do this by adding 10* in the expression in the field, so that the whole expression becomes 10*emw.normEfar. Click Plot again.
It’s now obvious that we need to refine the resolution a bit, but we’ll save this for last. We can see the 3D pattern of the radiating energy now.
Tilt the antenna by clicking on the model and dragging the mouse. With a certain orientation, you’ll be able to see the far-field radiation pattern extending below the substrate:
For visualization purposes, we may want to see the entire pattern more easily from the top, rather than needing to look at the waveguide from the side, where we can’t see the slots. Let’s shift the antenna geometry down a little bit, so that the entire far-field plot is visible on top of it.
To do this, right-click Surface 1 and choose Deformation. We’re adding a very simple deformation, a translation in the z-direction only. In the Expression section, set the x-component to 0, the y-component to 0, and the z-component to -5. Check the Scale factor box, and set it equal to 1.
Click Plot. Our geometry now looks pretty funny, because we’ve shifted one part of it down by 5 millimeters, but the rest has stayed put:
We don’t have to redo this step for each surface, though. We can copy the deformation and paste it into the other surface plots. Right-click Deformation 1 and choose Copy. Then right-click each of the other surfaces (2-4) and choose Paste Deformation. Now, the far-field pattern should be sitting right on top of the antenna.
Almost perfect! Finally, let’s refine the far-field visualization. Click on the Far Field 1 node and expand the Evaluation tab. Here, you’ll see options for two different angle resolutions: \theta and \varphi. By default, they are set to \theta = 10 and \varphi = 20. These angles represent the number of rotational samples that the simulation will check for, elevation and azimuth; the higher the angle number, the smoother and more accurate the pattern visualization will be.
Try setting them both to a higher sample number, for example, 45. This will give a higher resolution, but still not as smooth as we might like. For a very smooth visualization of the 3D radiation pattern (though also somewhat heavy computationally), set them both to 180. Click Plot again. Now we have a clear picture of the electric field strength and direction:
Congratulations! You’ve completed a complex visualization of the antenna and the electric field caused by the wave radiation, complete with surfaces on individual geometry selections, realistic material colors, and deformations. Try tilting the model in the Graphics window to see which view you like best.
Visualizing tools like the ones we used in this model are often very helpful for understanding the physics phenomena in a device, sharing your simulation results with others, and generating clean and beautiful results plots. I hope you’ve enjoyed learning how to plot these solutions and that you’ll be able to apply these techniques to other models in the future.
Consider the problem of taking the integral of a quadratic function:
The integral is the area of the shaded region.
We can evaluate this integral within COMSOL Multiphysics by using the integrate function, which has the syntax: integrate(u^2,u,0,2,1e-3). Here, the first argument is the expression, the second is the variable to integrate over, the third and fourth arguments are the limits of the integration, and the optional fifth argument is the relative tolerance of the integral, which must be between 0 and 1. If the fifth argument is omitted, the default value of 1e-3 is used. We can call this function anywhere within the set-up of the model.
Here, we’ll use it within the Global Equations interface:
The Global Equation for Integral computes the integral between the specified limits.
There aren’t any big surprises here, so far. We can solve this problem in COMSOL Multiphysics or by hand. But suppose we turn the problem around a bit. What if we know what the integral should evaluate to, but don’t know the upper limit of the integral?
Let’s look at how to solve the following problem for the upper limit, u_b:
We can solve this by changing the Global Equation such that it solves for the upper limit of the integral:
The Global Equation for u_b solves for the upper limit of the interval for which the integral evaluates to 6.
There are a few changes in the above Global Equation. The variable is changed to u_b and the expression that must equal zero becomes: 6-integrate(u^2,u,0,u_b). So, the software will find a value for u_b such that the integral equals the specified value.
Note that the initial value of u_b is non-zero.
Since we use the Newton-Raphson method to solve this, we should not start from a point where the slope of the function is zero. After solving the problem, we find that u_b = 2.621.
Now, let’s complicate things a bit more and solve the following problem for both limits of the interval, u_a and u_b:
Since we have two unknowns, we clearly need to have one more equation here, so let’s additionally say that (u_b-u_a)-1=0
An additional equation is added to specify the difference between the upper and lower limits of the interval.
Solving the model, shown above, will give us values of u_a = 1.932 and u_b = 2.932. It would actually also be possible to solve this with a single Global Equation, by writing 6-integrate(u^2,u,u_b-1,u_b) as the equation to solve for u_b, but it is interesting to see that we can solve for multiple equations simultaneously.
Next, let’s put the above technique into practice to determine the operating conditions of a heat exchanger. Consider the Model Library example of the geothermal heating of water circulating through a network of pipes submerged in a pond.
Water pumped through a submerged network of pipes is heated up.
In this example, the Pipe Flow Module is used to model water at 5°C (278.15 K) pumped into a network of pipes and heated up by the relatively warmer water in a pond. The temperature of the water in the pond varies between 10°C and 20°C with depth. The computed temperature at the output is 11.1°C (284.25 K). If the mass flow rate of water is specified to be 4 kg/s, then the total absorbed heat is:
where \dot m is the mass flow rate and C_p(T) is the specific heat, which is temperature dependent.
Now, in fact, the network of pipes we have here is a closed-loop system, but we simply aren’t modeling the part of the system between the pipe outlet and inlet. This model contains an implicit assumption that as the water gets pumped from the outlet back to the inlet, it is cooled back down to exactly 5°C.
So, instead of assuming that the temperature of the water coming into the pipe is a constant temperature, let’s consider this closed-loop system connected to another heat exchanger that removes a specified amount of heat. Suppose that this heat exchanger can only extract 10 kW. What will the temperature of the water in the pipes be?
Clearly, the first step here would be to write the integral for the extracted heat, in terms of the unknown limits, T_{in} and T_{out}:
The second condition that we need to include is the relationship between the input and output temperatures. This is computed by our existing finite element model. The model uses a fixed temperature boundary condition at the pipe inlet and computes the temperature along the entire length of the pipe. Therefore, all we need to do is add a Global Equation to our existing model to compute the (initially unknown) inlet temperature, T_in, in terms of the extracted heat, and the temperature difference between the inlet and outlet.
The Global Equation that specifies the total heat extracted from the pond loop.
Let’s look at the equation for T_in, the inlet temperature to the pipe flow model, in detail:
10[kW]-integrate(4[kg/s]*mat1.def.Cp,T,T_in,T_out)
Starting from the right, T_out is the computed outlet temperature. It is available within the Global Equation via the usage of the Integration Coupling Operator, defined at the outlet point of the flow network. That is, T_out=intop1(T), which is defined as a global variable within the Component Definitions.
T_in is the temperature at the inlet to the pipe network, which is the quantity that we want to compute; T is the temperature variable, which is used within the material definitions; and mat1.def.Cp is the expression for the temperature dependent specific heat defined within the Materials branch.
The closed-loop solution. 10 kW is extracted at this operating point. Note how the water heats up and cools down within the pond under these operation conditions.
You can see from the techniques we’ve outlined here that you can not only take an integral, but even solve for the limits of that integration, and make this equation a part of the rest of your model. The example presented here considers a heat exchanger. Where else do you think you could use this powerful technique?
]]>
Multiphysics simulations are based on partial differential equations (PDEs). These PDEs are typically derived from conservation laws of physical principles, such as conservation of mass, energy, and momentum. These well-known conservation laws can, without any further assumptions, be formulated as integral equations over arbitrary domains.
Volume integral terms describe what is stored inside the domains or added by sources, while surface integrals describe the interaction with neighboring domains or an external environment. Provided that all involved functions are smooth enough, the divergence theorem by Gauss can transform the surface integrals into volume integrals. Since the domain used in the derivation is arbitrary, the resulting equation must be valid at every point individually, turning the integral equation into a PDE.
There is, however, a slight flaw in this standard PDE derivation procedure: the functions involved (material properties, in particular) are not always smooth enough to justify the application of Gauss’s law everywhere. The resulting PDE is, therefore, too strict in the sense that it does not allow all physically sensible solutions (this is where the weak form comes into play). The weak equation partially reverses the derivation procedure to return an integral formulation, which is less strict than the PDE. This means that weak equations are actually closer to the underlying physics than classic equations.
We will begin with the PDE and outline the typical procedure for deriving its weak counterpart. To this end, let’s consider the diffusion equation:
Most of the equations in the COMSOL software involve similar terms. For heat transfer applications, the diffusion coefficient, c, and the source term, f, refer to the thermal conductivity and a heat source, respectively. If the unknown function, u, is a solution of the original PDE, it is also a solution of the following integral equation:
This results from multiplying the PDE with an arbitrary function, v, followed by applying the integral over \Omega on both sides of the equation.
Conversely, a function, u, that solves the integral equation for a sufficient number of different functions, v, is a likely candidate for solving the original PDE. That is why the functions, v, are called test functions and play a key role in the finite element method. We will discuss the choice of test functions in the section below.
The transformation of the PDE into this integral equation already reflects the nature of the weak form, but is usually followed by a second step. This step applies the divergence theorem by Gauss or Green’s formula (also known as integration by parts) on second order derivatives. In our example, we can rewrite the left-hand side of the previous integral equation as:
with \partial \Omega being the boundary of the domain, \Omega, and n the normal vector oriented away from the domain. Using this formula, the final weak form of the diffusion equation reads:
The boundary integral is responsible for the interaction with the surrounding of \Omega. Here, boundary conditions come into play, which describe this interaction and, thereby, make the whole problem unique. When we simulate heat transfer, the term -c\nabla u\cdot n describes the heat flux over the boundary, for example. If there is no heat flux, the boundary is thermally insulated.
A function, u, is called a weak solution of the PDE if it solves the weak equation for many different test functions, v. More precisely, we not only consider one test function, but v represents a whole class of test functions where each one corresponds to an equation. Of course, we could never consider all possible test functions as this would result in an infinite amount of equations. In practice, we need a finite number of well-chosen test functions. This is where finite elements come into play.
You all know that the computational domain needs to be meshed before running your study. Meshing divides the geometry into a set of smaller volumes — elements. Test functions can then be defined using polynomials on each element such that they are non-zero only on a small group of neighboring elements, and zero outside the group. The most common type of polynomials, constructed in this way, are known as Lagrange shape functions and are used by the COMSOL software for many physics interfaces.
Selecting discretization.
In the Discretization settings, Lagrange elements are used by default.
There are also other possible test functions exist, but we won’t discuss those details here. The important thing to note is that since test functions associated with different mesh elements are independent, the mesh effectively decides the number of test functions, as well as their spatial resolution.
What does all this have to do with your solution? The resulting solution of your computation is actually a superposition of all involved test functions. The message here is that although your true solution might be a rather complex function, it can be approximated as a combination of very simple functions. The finer the mesh, the more shape functions are involved and the better the solution will be (especially in regions with steep gradients, as more mesh elements are needed). If you keep refining the mesh until your solution does not change anymore, you have successfully performed a mesh convergence study and your solution is likely to be a good approximation of the original PDE’s solution.
This method of using the test functions to approximate the solution is called the Ritz-Galerkin approach and is, in some sense, the best finite element approach as it minimizes the error of the calculated and exact solution. There is a lot more to cover on the topic of discretization, such as meshing and convergence. For now we’ll add the following plot, which could represent a bending membrane under a given load. It shows piecewise linear approximations of the solution with an increasing mesh resolution.
Example of how a solution improves for an increasing number of linear shape functions.
Theoretically, the mesh resolution can be increased further, meaning that the set of test functions becomes larger. You can imagine that the mathematical limit of this procedure results in a set of test functions, which is, in some sense, complete and continuous. This is not relevant from a practical point of view, but the argument leads towards a sound mathematical theory of solvability and uniqueness of solutions. Although you, as a COMSOL Multiphysics user, do not need to deal with these issues, it will be comforting to know that there is a sound theoretical basis of your calculations.
At this point, you may be wondering how the weak form is expressed in COMSOL syntax. To this end, the software provides the test operator, which is used to express the test functions, v. The test operator operates on the solution variable, u, and its derivatives, i.e., v=\mathrm{test}(u). There is a logical reason for associating test functions with the solution in this way. If the solution is represented using a polynomial basis on the mesh, as described above, using the same basis for the test functions ensures that the discrete system contains the same number of unknowns and equations.
In order to translate the first term of the weak equation of our example into COMSOL syntax, we first need to rewrite the gradients by means of the partial derivatives with respect to x, y, and z. Here, the notation for the first partial derivative is \frac{\partial u}{\partial x}=ux.
Similarly, partial derivatives of the test function are expressed as \frac{\partial v}{\partial x}=\mathrm{test}(ux).
Altogether, the domain integral terms of the weak form read in COMSOL syntax as:
The boundary terms require special treatment, which is beyond the scope of this blog post. No equals sign needs to be included, since the weak form PDE is automatically set to zero. It is important to note that this translation is normally done automatically because COMSOL Multiphysics needs the weak form to proceed with the calculation. However, it is also possible to enter a weak form as a user. The default domain Weak Form PDE interface suggests the above equation with c=f=1 and a change of sign, as shown in the following screenshots:
Weak form interfaces available in COMSOL Multiphysics.
Example how to enter the weak form in COMSOL syntax.
What does all of this mean in practice? The real world is not always nice and smooth. It can show kinks in material data, rough surfaces, point sources, or rapid changes in the solution or its gradient. While classic PDEs reach their limits for non-smooth physical effects, weak equations are most often very suitable. They are less strict because all involved terms are integrals over mesh elements and don’t need to be well-defined at every single point in the domain. This is the key benefit of the finite element approach, which enables the COMSOL software, and you, as a user, to get solutions for your real-world applications.
To sum up, weak equations:
Creating or importing a geometry is usually the first step in the COMSOL Multiphysics modeling process. Depending on the goal of our simulation, the geometry can be either a realistic or an idealized representation of a device.
There are various ways to build a geometry. For example, we can draw shapes on a work plane and extrude them, or we can create a solid object and combine it with other solid objects to obtain a final shape. On some occasions, the device we are drawing consists of several parts. To be able to apply different material settings, we would need to draw these parts as separate solid objects.
Imported geometry from a CAD file, for example, often needs repair or simplification by removing small, or otherwise unnecessary, details. In the COMSOL® software, we can draw new shapes to complement imported objects. Regardless of how we create the geometry, we can always go back and edit the various operations (which are collected in the geometry sequence under the Geometry node in the Model Builder).
After we create the geometry, we can proceed to define the physics, include material and boundary settings, and then mesh the geometry. If necessary, we can go back to modify the design, in which case the physics settings are retained on the domains and boundaries we have originally selected. Before solving, we create the finite element mesh that should provide an adequate approximation of the geometry. Finally, we evaluate the results of the simulation by plotting them on the geometry.
Geometry of a wheel rim during the various stages of a fatigue analysis.
In COMSOL Multiphysics, the geometric kernel is the software component that ensures that all of the above functions work smoothly. The kernel keeps track of the mathematical representations of the geometrical objects we draw or import. It has functions and algorithms for constructing these objects and the interactions between them, such as joining or intersecting. Additionally, there is a part of the geometric kernel that ensures that the geometry is associative, i.e., we can modify it without a need to reapply physics settings. Furthermore, the kernel can also provide information about the geometry for other software components, such as calculating projections or surface curvature for the mesher.
Geometric kernels can be configured to do different tasks. To ensure the best possible performance, the COMSOL software provides not one, but two kernels. It includes the COMSOL kernel, which works best with geometry created in the software. To handle imported CAD geometry, the CAD Import Module and LiveLink™ for CAD products package a dedicated geometric kernel, the Parasolid® kernel (called the CAD Import Module kernel in the UI).
The Parasolid® kernel provides repair functionality for imported CAD designs. It also includes functionality that enables simplification of the geometry — to delete fillets or holes, for example. There is more to it than the repair and defeaturing of imported objects, however. The usual geometry operations are also implemented by the Parasolid® kernel. This means that even when using this kernel, we can create and modify geometry, including imported CAD objects.
Removing holes and other details from a geometry during defeaturing.
When we install COMSOL Multiphysics with a license that includes the CAD Import Module or one of the LiveLink™ products for CAD, the Parasolid® kernel is set to default when starting a new model. However, we can easily change this setting in the Preferences window.
To check and change the geometric kernel in a model component after we have started modeling, we can click the Geometry node in the Model Builder to navigate to the Geometry settings window.
By changing the Geometry representation in the settings, we can control which kernel handles the geometry in the current model component. Changing the kernel requires a rebuild of the geometry sequence by using the kernel we have switched to. The geometry sequence cannot be rebuilt using the COMSOL kernel if it includes any operations that are only available with the CAD Import Module kernel. These operations include those that appear under Defeaturing and Repair in the Geometry toolbar and the Import feature (if the imported file is of a format supported by the CAD Import Module). In these situations, we can convert the geometry objects to be used with the COMSOL kernel, as shown below.
When we import geometry from a CAD file, we often prepare it for analysis by using the repair and defeaturing operations available with the CAD Import Module kernel. Even though the CAD Import Module is needed to open a model containing such a geometry sequence, there is a simple two-step process to share the geometry in COMSOL format. First, we convert the defeatured geometry objects to the COMSOL format. You can find the Convert to COMSOL operation under Conversions in the Geometry toolbar, as shown below.
Second, we export the converted geometry objects to the COMSOL Multiphysics format (.mphbin or .mphtxt).
Parasolid is a registered trademark of Siemens Product Lifecycle Management Software Inc. or its subsidiaries in the United States and in other countries. All other trademarks are the property of their respective owners, and COMSOL AB and its subsidiaries and products are not affiliated with, endorsed by, sponsored by, or supported by those, or the above, non-COMSOL trademark owners. For a list of such trademark owners, see www.comsol.com/trademarks.
]]>