I recently wrote a blog post about exploiting periodicity to reuse the flow solution in the modeling of a microfluidic device. To quickly refresh our memories, a microfluidic device may feature small serpentine channels, as shown in the image below. Two inlets introduce different solutes in the same solvent, and good mixing at the outlet is desired.
A typical microfluidic device. Image by IXfactory STK — Own work. Licensed under CC BYSA 3.0, via Wikimedia Commons.
We know that it is possible to compute the fluid flow field in only one of the repeating unit cells, and to pattern this flow solution along the repeating structure to define the flow field along the entire device. The Transport of Diluted Species problem can then be solved in the repeated section, as shown in the figure below.
One approach is to compute the flow field on one unit subcell. This flow solution can be used by the chemical species transport problem, solved over the entire domain.
Shortly after finishing my earlier blog post on this topic, one of my colleagues challenged me to come up with an even simpler way of modeling the same situation, which made me think of the following problem.
It may not be immediately obvious from the above image that this case has a very high Péclet number, meaning that the transport of the species due to the motion of the fluid is far greater than the transport via species, via diffusion. Stated another way, the solution downstream does not affect the solution upstream.
Now, if the Péclet number is high, then we do not necessarily need to solve the Transport of Diluted Species problem on the entire domain. We can solve it on the same unit cell used to compute the fluid flow field, but we need to come up with a way to map the species distribution at the output boundary back to the input boundary and rerun the simulation. Let’s find out how to do this.
The modeling procedure we should follow is sketched out in the figure below. We can reduce our entire modeling domain down to one unit cell. We will compute the flow field in this unit cell using laminar inflow and outflow conditions. This computed flow field will be used as the transport term in the Transport of Diluted Species interface, which additionally requires a concentration profile at the inlet.
We can start by assuming a particular species concentration at the inlet and solve for the concentration field throughout the modeling domain. Then, we evaluate the concentration profile at the outlet; map that profile back to the inlet boundary, where it can be applied as a new inlet condition; and solve the model again. Each time we repeat this process, we are essentially solving for the concentration profile in the next (downstream) unit cell of our microfluidic device.
The solution procedure for modeling a repeated microfluidic device with a single unit cell.
The modeling implementation begins with a General Extrusion component coupling, named genext1, defined at the outlet boundary. This coupling simply maps the fields at the outlet boundary back to the inlet boundary by specifying a displacement along the xaxis, similar to the method shown in an earlier blog post.
The General Extrusion component coupling maps the solution on one boundary to another boundary by the specified offset of 3 mm.
Next, a Boundary ODEs and DAEs interface is added to the inlet boundary. The settings for this interface are shown below. The variable is named c_b and the discretization is set to Lagrange — Linear to match the discretization of the Transport of Diluted Species interface. The Source Term for the Distributed ODE is (c_bgenext1(c))[m^3/mol], which sets the value of c_b at the inlet equal to c. The species concentration is computed at the outlet, which is mapped back to the inlet via the General Extrusion operator.
The Boundary ODEs and DAEs interface. Relevant settings are highlighted.
Next, let’s look at where the variable c_b is used. The screenshot below shows the Inflow boundary condition for the Transport of Diluted Species interface.
The inlet condition for the Transport of Diluted Species interface.
The expression entered into this field is if(Index,c_b,(1+tanh(x/0.1[mm]))/2), which uses the if() statement to set up a different inlet concentration based upon a Global Parameter, Index. The expression (1+tanh(x/0.1[mm]))/2 is the assumed species concentration at the inlet of the device (this concentration is arbitrarily set to range from zero to one) and is only applied if Index is equal to zero. For any other values of Index, the species concentration at the inlet is actually taken from the computed species concentration at the outlet.
But how do we specify that we want the previously computed outlet concentration to be used as the inlet concentration? For that, we need to modify our Study settings. The Study is composed of two sequential Stationary Steps. The first step solves the Laminar Flow interface alone. The resulting steadystate fluid velocity field is automatically passed along to the second step, which solves for both the Transport of Diluted Species and Boundary ODEs and DAEs interfaces.
The second Stationary Step includes an Auxiliary Sweep, as shown in the screenshot below. Note that the Index parameter is swept over the values 0, 1, and 2, which represent the threeunit cells of the system that we want to model. Also note that Run continuation for is set to No parameter (since there is no benefit of using load ramping or nonlinearity ramping in this case) and that Reuse solution for previous step is set to Yes.
The Stationary study step with the Auxiliary sweep enabled.
There is one more modification that needs to be made to the Solver Configurations. We need to manually add a Previous Solution node to the Parametric node and specify that the variable c_b should be accessed at the previous step in the parameter sweep. The settings are shown below.
The Previous Solution node settings.
With these study settings, we repeat the simulation for each one of the three unit cells, passing the concentration field from the outlet back to the inlet before computing the concentration field. The results can be combined into a single plot showing the concentration profile throughout the entire domain of interest.
The concentration solution plotted for three unit cells, solved sequentially.
The approach shown in this blog post is valid for models of chemical species transport in periodic structures where the Péclet number is high. The process is certainly valid for solving other transportdominant problems in COMSOL Multiphysics as well. Even though we assume here that the flow is periodic and the properties of the fluid are invariant, this approach can be extended to mapping the flow field from the outlet back to the inlet.
The problem shown here could also be addressed via LiveLink™ for MATLAB®, which provides us with a scripting interface that allows us to extract data, remap it, and rerun solutions with different inputs. Still, it is nice to see that we can build such models in the graphical user interface (GUI) as well.
The computational advantage here will grow with the number of unit cells that we have to analyze. If there are N unit cells, the memory requirements and the solution times for using this approach will be approximately N times smaller than building an entire model.
If you have questions about this, and are interested in using COMSOL Multiphysics for your modeling needs, please contact us.
]]>
Imagine letting a marble roll down a curved ramp, such as those seen in roller skate parks, and measuring the time for the marble to roll from point A to point B. Our goal is to redesign the shape of the ramp between the two points, such that it takes the shortest possible time for the marble to travel between them. For simplicity, we consider the ideal situation where friction is neglected and the marble is infinitely small (a point mass).
The brachistochrone curve is an idealized curve that provides the fastest descent possible. There is actually an analytical solution to this case or, with some derivation work, we can use the PDE functionality of COMSOL Multiphysics to solve the problem. However, since I am a “firm believer of the principle of least action”, a fancy way of saying “a lazy physicist”, we will use the Optimization Module instead.
Assuming point A of our problem is located at the origin (x, y) = (0, 0), the analytical solution for the brachistochrone is a parametric curve of this form:
(1)
where the parameter r is a constant and the parameter t is the running parameter for the parametric curve and varies linearly from tA to tB along the curve. Typically, when we solve this problem, we are given the location of point B and solve for r and t.
Here, we will start with the analytic solution for the brachistochrone and a known set of r and t that give us the location of point B. We will show how to approximate this analytic solution using the optimization functionality within COMSOL Multiphysics and the Optimization Module.
We will start with a blank model. In fact, we will not add any “component” in the Model Builder; no geometry, physics, or mesh will be needed. This is an interesting example of “a model without a model”.
First, we define a set of global parameters. We set the constant parameter r to 1 and the value of tB for point B to 1.2 \pi. (Keep in mind that A is the origin, so implicitly tA=0.) The location of point B (xB, yB
) can then be calculated using Eq. (1), as shown in the screenshot below.
Next, we use an interpolation function to approximate the brachistochrone curve. We define the xpositions of a few interpolation points as x1 ~ x4
and give the ypositions (y1 ~ y4
) an initial guess, such that the interpolation points start out on a straight line between point A and point B.
This interpolation function can be set up as shown in following screenshot.
You can click the Create Plot button to generate a plot of the interpolation function. For clarity, remove the two extrapolation plots. Next, add a line graph of the analytical solution to the same plot group to compare with the numerical solution later.
To create a plot of the parametric curve, first create a dummy analytic function under the Global Definitions node, setting the upper limit of the argument to tB
(under the Plot Parameters section). The sole purpose of this analytic function is to provide a list of t values between 0 and tB
for us to draw the parametric curve. Click Create Plot and drag the resulting Line Graph 1 out of 1D Plot Group 2 and into 1D Plot Group 1 (its name will change to Line Graph 2 automatically). For the yaxis data, enter the expression corresponding to Eq. (1): r*(1+cos(root.x))
. Similarly, for the xaxis data, enter r*(root.xsin(root.x))
.
Note that the COMSOL Multiphysics variable
root.x
here corresponds to the t parameter in Eq. (1).
Click the Plot button. We now have a graph of the analytic solution (green curve) and the initial guess (blue curve and black dots) as shown below.
To calculate the travel time for the marble to roll from point A to point B, we use the assumption that the motion is frictionless, so that all loss in potential energy turns into kinetic energy, which is proportional to the square of the speed. Thus, if the curve is represented by the formula y = f(x), then the instantaneous speed is proportional to the square root of the loss in height: v \propto \sqrt{0f(x)} (recall that we assume the original height at point A is 0). For an infinitesimal movement of dx in the xdirection, the path length that the marble travels along the curve is ds = dx \sqrt{1+f'(x)^2}. The time it takes to travel this length is simply the length divided by the speed d\tau = ds/v. Therefore, we arrive at an expression for the total travel time for any given curve y = f(x):
All we have to do now is let the COMSOL software find the curve that minimizes this expression for the travel time.
You may have noticed that we use the “proportional to” symbol (\propto) in the expression for the travel time, since we have neglected to include the mass of the marble and the gravitational acceleration constant in the formula. Since these numbers combine to merely scale the travel time by a constant factor, they do not affect what the curve looks like for the minimization problem. In other words, the brachistochrone curve is independent of the weight of the marble.
Since we use the interpolation function int1
to approximate the curve f(x), we can define a global variable T
for the travel time using the formula given above: integrate(sqrt((1+(d(int1(x),x))^2)/max(0int1(x),eps)),x,0,xB)
. The extra expression max(... ,eps)
in the denominator prevents dividebyzero situations, as shown below.
Now we are ready to ask the software to minimize the travel time for us. Create an empty study and then rightclick to add an Optimization node under it. We can use either the Coordinate Search, NelderMead, BOBYQA, or COBYLA optimization solvers for this “modelfree” optimization problem. COBYLA turns out to be the fastest.
In the settings window, under the section Objective Function, enter T
for the expression, which by default is minimized. Then, under the section Control Variables and Parameters, use the Add button (a “plus” sign icon) to add the parameters y1  y4
. The initial value fields are automatically filled with the corresponding values in the global parameters table. Under the Output While Solving section, check the Plot check box. These settings are shown in the screenshot below.
Click Compute to watch as the optimization solver moves the interpolation curve up and down until the minimal travel time is reached. Even with the very crude linear interpolation curve using only four interpolation points, the results in the graph below show remarkable agreement with the analytical solution. Higherorder interpolation and more interpolation points will further improve the solution.
A few years ago, my mentor William Vetterling from ZINK Imaging chatted with a few of us at lunch about how we can use COMSOL Multiphysics to solve anything, since it provides the mathematical tools to handle all kinds of equations encountered in science and technology. This idea eventually evolved into his keynote presentation on the “Library of Babel” at the COMSOL Conference 2012 Boston. We have used an example of a “model without a model” to solve the brachistochrone curve problem by taking advantage of the software’s versatile builtin mathematical expressions and optimization functionality. I hope this demonstration will stimulate more creative usage of COMSOL Multiphysics to tackle more technical challenges.
]]>
At a point P_d in the destination entity, we want to compute a quantity that is a function of another quantity defined at the source entity. Thus, the latter quantity from a source point P_s needs to be copied to the destination entity. Extrusion operators are used to identify which point in the source entity corresponds to a point in the destination entity. In other words, the operators define the pointtopoint map.
If the mapping is affine, it is sufficient to know how some points in the source correspond to points in the destination entity. From such sourcedestination pairs, one can infer the general mapping from superposition. However, in general, we need to write the mathematical expression for the mapping. This can be either an explicit definition of the source point P_s as a function of P_d or an implicit relation between P_d and P_s.
When using Linear Extrusion operators, we visually indicate the mappings for enough points (bases) and COMSOL Multiphysics figures out how to transform the remaining points. In the case of General Extrusion operators, we write out the mathematical description of the mapping for an arbitrary point in the destination.
To begin, let’s focus on how to replicate a Linear Extrusion operator with a General Extrusion operator. We can then consider examples in which the General Extrusion operator must be used.
For affine relations, General Extrusion operators can be used as an alternative to Linear Extrusion operators. When it comes to general nonlinear mappings, General Extrusion operators are necessary. To add a General Extrusion operator, we go to Definitions > Component Couplings > General Extrusion.
In our earlier blog post on Linear Extrusion operators, we considered an affine mapping that pairs up points 1, 4, and 2 in the source domain to points 1, 5, and 2 in the destination domain. Take a look at the figure below. The two circles in the geometry have centers at the origin and radii of 1.0 and 1.5.
Any affine transformation can be expressed as the sum of a linear transformation and a translation operation. Therefore, we have
Now we need to find the constants a,b,c,d,e, and f. Since source points (0, 0); (1.0, 0); and (0, 1.0) correspond respectively to destination points at (0, 0); (1.5, 0); and (0, 1.5), we get
Now that we know how to find the corresponding coordinates of the source point, given any point (x,y) in the destination, we enter the righthand side of the above equation (without the subscripts) in the destination map of the General Extrusion settings window.
A linear mapping built using a General Extrusion operator.
Let’s now explore how to use a General Extrusion operator to copy data from a 2D axisymmetric component to a 3D component, such that the source and destination points correspond to the same point in space. Consider thermal expansion with axisymmetric thermal boundary conditions and material properties. If the structural boundary conditions are not axisymmetric, we can save time by performing an axisymmetric thermal analysis in one component, and then mapping the temperature from the 2D axisymmetric domain to the 3D domain for structural analysis in another component.
When building the mapping, it is important to ask the following question: Given the coordinates of the destination point, how do we go to the source point? In this instance, that relationship is given by
As in Example 1, we enter the expression on the righthand side in the destination map.
Using a General Extrusion operator to copy data from the 2D axisymmetric domain to the corresponding 3D domain. Note that for axisymmetric components, variables can be viewed in 3D with a Revolution 2D data set in the Results node. However, if we want to use variables from a 2D axisymmetric component in the physics node of a 3D component (i.e., thermal expansion), we need to utilize General Extrusion operators.
The operator genext1 is not known inside the 3D component comp2; neither is T. If we want to use the temperature from the 2D axisymmetric component as an input in the 3D component, we have to use comp1.genext1(comp1.T). This approach helps avoid confusion if there is an extrusion or another operator also called genext1 or another variable called T in the second component.
Note that a Linear Extrusion operator cannot be used here. Because the source and destination objects have different dimensions, affine transformations are impossible.
In these first two examples, the Use source map check box in the Source section of the settings window has been left unchecked. COMSOL Multiphysics filled in x and y in the first case and r and z in the second case. When this check box is left unchecked, COMSOL Multiphysics assumes that we have explicit expressions for each coordinate of the source as functions of coordinates of the destination. Oftentimes, however, we may not have explicit expressions.
Next, we’ll look at how to use a General Extrusion operator to specify implicit relations.
A 2D parabolic curve given by \frac{y}{d} =(\frac{ x}{d})^2 is in a square domain of side d. Our task is to build an operator that maps data from this curve (represented in blue in the figure below) to different parts of the square. The parabola is the source. We want an operator that will copy from a point on the parabola to a point in the square, such that the distance of the destination point from the origin is equal to the length of the segment of the parabola between the origin and the source point.
A little calculus gives us the arc length of the parabola between the origin and the source point (x,y).
The relationship between the source and destination points is therefore
If we want an explicit sourcedestination mapping of the form
we first need to invert the expression L=\frac{x_s}{2}\sqrt{1+4(\frac{x_s}{d})^2}+\frac{d}{4}\ln(2\frac{x_s}{d}+\sqrt{1+4(\frac{x_s}{d})^2}) and write x_s in terms of L. That’s no fun at all!
This is exactly why COMSOL Multiphysics allows us to specify implicit relations between source and destination coordinates by using two mappings: the destination map and the source map. We need to provide T_d and T_s, such that
Using source and destination maps to define implicit relations between source and destination coordinates in a General Extrusion operator.
COMSOL Multiphysics will take care of T_s^{1}(T_d(x_d,y_d)), a necessary step in identifying the source coordinates. Note that the source map needs to be onetoone for the inverse to exist. In practice, COMSOL Multiphysics does not construct an analytic expression for the inverse of the source map. Instead, at every destination point, it first evaluates T_d(x_d,y_d) and carries out a mesh search operation to find the point on the source where this evaluation matches T_s(x_s,y_s). A onetoone source map makes the search return, at most, one source point for a given destination point.
In the General Extrusion settings window shown above, the labels under Destination Map and Source read x^iexpression and y^iexpression rather than xexpression and yexpression. The reason is that x^i and y^i are indices for the first and second pairs of expressions used to define the sourcedestination relationship implicitly. They are not necessarily pertaining to the x or y coordinates in the source or destination. These indices are, in a sense, coordinates of an intermediate mesh, and a General Extrusion operator matches source and destination points that have the same intermediate coordinates. In this example, one expression is sufficient enough to uniquely relate any destination point in the square domain to a source point on the parabolic curve. Thus, the second line y^iexpression is left blank.
To see how this General Extrusion operator maps variables, consider a plane stationary heat conduction problem with the left and right edges at temperatures of 300 K and 400 K, respectively. The top and bottom surfaces are thermally insulated, and there are no heat sources. The temperature will vary linearly with x. From the graph below, can you see why the plot of arcext(T) on the right shows a radial variation?
Left: Temperature varies linearly from left to right. Center: Temperature along the parabola. Right: Temperature mapped from the parabola to the domain. All points in the domain with the same distance from the origin copy temperature from the same point on the parabola.
To apply what we have learned thus far, let’s now build a diode model using the Electric Currents physics interface in COMSOL Multiphysics. Extrusion operators help us construct normal current density boundary conditions on each side of the ideal pn junction. We can tag the different sides as 1 and 2, as illustrated in the figure below. The Shockley diode equation for the currentvoltage (IV) relation is used at the junction. The parameters J_s, q, k, \textrm{and } T represent the following, respectively: the saturation current density, the electronic charge, Boltzmann’s constant, and temperature.
Extrusion operators can be used to access the electric potential on the other side of a junction.
To implement the normal current boundary condition on side 1, we need access to the electric potential V_2 on side 2. Similarly, on side 2, we need access to the electric potential V_1 on the other side of the junction. Thus, two extrusion operators are required. Each side of the junction becomes a source entity in one of the extrusion operators, as depicted below.
Both cases involve mapping between points that share the same xcoordinate. Because the source entities are different, two operators are needed.
Now we will use the operators in the physics nodes to implement the boundary conditions. The boundary condition at the top side is illustrated below. Note that V refers to the electric potential at a point on the top side while genext2(V) refers to the electric potential vertically on the bottom side.
Using a General Extrusion operator to refer to the electric potential at a point on the other side of the junction.
A similar boundary condition is used on the bottom side of the junction. The corresponding normal current density for the Normal Current Density 2 node applied to edge 3 is Js*(exp((Vgenext1(V))/kTbyq)1). Here, V refers to the electric potential at a point on the bottom side, while genext1(V) refers to the electric potential vertically on the top side.
In fact, a shortcut can be made by using the expression genext2(V)genext1(V) for the voltage difference, regardless of which side it is being applied. For clarity, we did not use this trick here.
With a voltage terminal at the bottom of the device and ground at the top of the device, the following results are obtained.
Extrusion operators can be used to make couplings between points in the same component or different components. Here, the pn junction in a diode is represented by a thin gap in the geometry. The electric potential on one side of the gap is accessed from the other side by using an extrusion operator in order to compute the current density flowing across the gap.
Extrusion operators are used to construct pointwise relations between source and destination points. Sometimes, we may want to access an integral, average, maximum, or minimum over a source line, surface, or volume. In such cases, we can use projection, integration, average, maximum, or minimum component couplings. You can learn more about the use of projection operators in this previous blog post.
Today, we have discussed how to use General Extrusion operators to create mappings for copying variables from one part of a simulation domain to another. In addition to simply copying known quantities, these operators can be used to create nonlocal couplings between unknown variables, as illustrated in our pn junction example. This approach is also useful in other analyses including structural contact or surfacetosurface radiation in heat transfer. COMSOL Multiphysics includes builtin features pertaining to such physical effects.
If the nonlocal couplings you want to simulate are not included in the builtin features of COMSOL Multiphysics, you can use the strategies you’ve learned today to implement them. Please feel free to contact us if you have any questions!
To explore the use of General Extrusion operators in other types of situations, consult the following blog posts:
]]>
There are many practical situations in which mapping variables from one component, or part of a component, to another is needed. One instance is the linking of two submodels, for example, the generation of inlet boundary conditions for turbulent flow models. The boundary conditions at the inlets significantly affect the flow in the domain. However, the flow profiles at the inlets are not as easily defined as with laminar flow. To generate turbulent inlet boundary conditions, an auxiliary model with normal inflow can be used. The resulting velocity profile at the outlet then needs to be copied to the inlet of the main model.
Efficiency can be another reason to map variables between regions. Consider thermal expansion with axisymmetric thermal boundary conditions and material properties. If the structural boundary conditions are not axisymmetric, we can save time by performing an axisymmetric thermal analysis first, and then mapping the temperature from the 2D axisymmetric domain to the 3D domain for structural analysis.
Another common scenario is the implementation of periodic or other boundary conditions where a quantity at a point on a boundary is related to a quantity at a point on another boundary. For example, in a diode, the normal current density on one side of the pn junction depends on the electric potential at the same point and the electric potential on the other side of the junction. While a variety of such boundary conditions are built into the appropriate physics interfaces in COMSOL Multiphysics, from time to time users may need to construct their own.
Such instances require pointwise mapping of variables from one domain or boundary to another. Today, we will show how these mappings can be constructed.
The idea of a mapping involves two geometric entities: the source where a quantity is known and the destination where the quantity will be used. We know a quantity, q_s, at the source and want to calculate another quantity, q_d, at the destination. The new quantity, q_d, can be a copy of q_s or a function of it.
We can break this problem down into these steps:
We end up with
The focus of this blog post is on the transformation T : x_d \rightarrow x_s.
COMSOL Multiphysics offers two coupling operators to specify this mapping: Linear Extrusion operators and General Extrusion operators. Linear Extrusion operators are easier to build, but their utility is limited to affine transformations. General Extrusion operators are more general but take more work to define.
Here, we will discuss Linear Extrusion operators. In a later blog post, we will deal with General Extrusion operators.
When the source and destination points are related to each other by affine transformations such as translation, scaling, reflection, rotation, or shear, COMSOL Multiphysics provides a simple way of specifying the extrusion operator: the Linear Extrusion operator. To add a Linear Extrusion operator, we go to Definitions>Component Couplings>Linear Extrusion.
The basic idea of a Linear Extrusion operator is that an affine transformation between two lines can be defined if we know two corresponding pairs of points on the lines. Similarly, three pairs of noncollinear points and four pairs of nonplanar (with no more than two collinear) points are enough to describe affine mappings of 2D and 3D domains, respectively.
This is similar to linear system analysis in general. If we know the transformation of a sufficient number of base points/vectors, we can transform every point/vector using linear superposition. Think of the Linear Extrusion operator as a visual way of picking the basis and their transformations. From that information, COMSOL Multiphysics automatically derives the mapping that needs to be applied on an arbitrary point/vector.
We will illustrate this with a few examples.
The first operator is used for mapping data from the line segment with ends 1 and 4 to the line segment with ends 4 and 5, with the orientation preserved. All we need to do is indicate to COMSOL Multiphysics which point goes where, as shown in the image below.
A Linear Extrusion operator matching points 1 and 4 in the source to points 4 and 5 in the destination, respectively.
Note that even though we are in a 2D space, we are working with 1D objects (lines). Thus, it suffices to indicate the correspondence between two sets of vertices. What if we choose 5 for Destination vertex 1 and 4 for Destination vertex 2? In that case, in addition to the translation and stretching needed to take segment 14 to segment 45, there will be a flipping. See the plot below.
The order of vertices under Source Vertices and Destination Vertices of a Linear Extrusion operator determines the orientation of the mapping.
Now, let’s increase the dimension of our objects and build the Linear Extrusion operator to copy data from the interior circle to the outer domain by radially stretching. All we need to do is to add one more pair of vertices to the above vertex pairing. See the Linear Extrusion settings window below.
The higher the dimension of objects in the mapping, the more vertices in the geometry need to be paired up to define a Linear Extrusion operator.
The mapping matches points 1, 4, and 2 in the source domain to points 1, 5, and 3 in the destination domain, respectively. If we want to look at this in terms of basis vectors, segment 14 in the source corresponds to segment 15 in the destination. Similarly, segment 12 in the source corresponds to segment 13 in the destination. From these two linearly independent bases, COMSOL Multiphysics gets enough information to construct the mapping that takes any destination point in the 2D domain to a source point. The figure below shows how a variable \phi defined on the interior circle is mapped by the Linear Extrusion operator linext2 that we just defined.
A variable defined over interior circle (left) and mapped to all points using the Linear Extrusion operator (right).
What we have done up to now is build the infrastructure that will help us access variables. Now, let’s see how to use the tool we built.
If we look at any of the Linear Extrusion settings windows shown in the images above, we see Operator name at the top. That name is what we will use to access the mapping. If linext2 was the name of the extrusion operator, any time we are at a destination point and want to refer to a quantity, say u, from the corresponding source point, we use the expression linext2(u). If we want the variable w from the same source point, we use linext2(w). This explains why we call them operators. Once we build them, we can use them with any legitimate argument.
Instead of just using a variable, if we want a function of the variable, we can put the function either inside the operator or apply the function to the output of the operator. For example, linext2(w^2) is equivalent to linext2(w)^2. Does linext2(w)+u return the same value as linext2(w+u)? Generally, no. In the first case, u at a destination point is added to w evaluated at the corresponding source point. In the second case, both u and w are evaluated at the source point. The image below illustrates this point using the Linear Extrusion operator from Example 2.
The variable \phi is evaluated at the destination in the inner circle and at the source in the outer arc (left). All evaluations are at the source (right). Note that in general, the argument, such as \phi, can be a valid quantity at a destination point. In such cases, its value is generally different from the value returned by the extrusion operator.
Finally, when using an extrusion operator to map variables between different components, the operator should be added to the Definitions node of the component containing the source object. That component’s tag should be used when we use the operator in another component. To access a variable u defined in component 1 from component 2 using the Linear Extrusion operator linext2, the correct syntax is comp1.linext2(comp1.u). This avoids confusion if there is an extrusion or another operator also called linext2 or another variable called u in the second component.
The focus of this blog post is the construction of Linear Extrusion operators. For their use in a full modeling problem, please see the simulation of the backward facing step. In this example, a Linear Extrusion operator was used to transfer accurate inlet velocity from an auxiliary analysis in a turbulent flow simulation.
Stay tuned for our upcoming blog post on how to build General Extrusion operators, where we will illustrate their use in a full modeling example. In the meantime, please feel free to contact us if you have any questions.
]]>
Canoeing is one of my favorite hobbies. In fact, I used to paddle dragon boats competitively on the beautiful Charles River here in Boston. If you’re ever in the city on a nice summer day, I strongly encourage you to rent a canoe and paddle down the river.
Dragon boats on the Charles River.
Boston’s weather, however, can change rather quickly. While it may be calm when you begin moving down the river, high winds can pick up and start blowing your canoe all over the place. Every time you raise your oar out of the water, it will catch the wind. As you swing your oar forward, you will hit the crests of the small waves that are being kicked up. Such movement leaves you wet and, even worse, throws off the balance of the boat. How might you change your paddle stroke to regain control of the situation?
An experienced paddler would start to use the Indian stroke, also called the Canadian Jstroke — just one of the many kinds of canoe paddle strokes. This stroke moves the paddle backward in the typical power stroke. Without lifting the paddle out of the water, the paddler rotates their grip, such that the paddle’s blade is parallel to the direction of travel on the return stroke.
The advantage of the Indian stroke, nicely demonstrated here, is that the paddle blade is never exposed to the wind and does not strike any of the wave crests. While easy to perform at slow speeds, this stroke is rarely used in races. It requires exceptionally strong control of the paddle as well as a solid understanding of how to move the paddle through the water.
With COMSOL Multiphysics, you can analyze and improve upon your paddle stroke. We’ll show you how.
Let’s simplify things a bit. We will consider a simplified paddle stroke and model it in the 2D plane. Although it is assumed that there is no variation in the zdirection (the water depth), we can begin here to gain some insight. The model under consideration is comprised of a rectangular fluid domain that is filled with water. The example includes a canoeshaped cutout as well as a rectangular cutout that represents the paddle.
We want to model the paddle moving back and forth along a known path and rotating about its center. We can specify the fluid velocity at the paddle blade based on the known translational and rotational movement. The fluid velocity at the canoe wall is zero and open boundary conditions surround our model space.
The modeling domain considers the paddle translating and rotating next to the canoe. The boat moves from left to right.
Previously on the blog, we highlighted approaches for modeling general translations of domains as well as rotations and linear translations. A combination of these techniques can be used to model the deformation and rotation of the paddle. The animation below illustrates such techniques, showing the mesh through one full stroke. The mesh faces can slide relative to one another, yet still maintain continuity of the solution across these disjoint mesh interfaces.
An animation depicting moving mesh. A very coarse mesh is shown for illustrative purposes.
Since the translation and rotation of the paddle blade are now completely defined, there is only one thing left to solve: the NavierStokes equations on the moving domains. In this analysis, we will assume laminar flow. We will also assume that the canoe is quite heavy and is not yet moving. The animation below allows you to visualize the results for the first few strokes.
Flow during the paddle stroke.
Now that you can visualize the flow patterns around the paddle blade, albeit in this somewhat simplified case, how might you improve your own stroke? Once you determine your optimal stroke, you might even want to consider joining a competitive dragon boat team here in Boston, or elsewhere — a healthy and fun way to put your COMSOL Multiphysics modeling skills to use!
Can you think of other situations in which this approach could be applicable? We are happy to hear your feedback. If you are interested in using COMSOL Multiphysics to model your paddle, or perhaps another form of fluidstructure interaction, please contact us.
]]>
In a previous blog post, we discussed the modeling of objects translating inside of domains that are filled with a fluid, or just a vacuum. This initial approach introduced the use of the deformed mesh interfaces and the concept of quadrilateral (or triangular) deforming domains, where the deformation is defined via bilinear interpolation. Such a technique works well even for large deformations, as long as the regions around the moving object can be appropriately subdivided. This, however, is not always possible.
A solid object moving along a linear path inside of a complicated domain.
Consider the case shown above, where an object moves along a straight line path, defined by \mathbf x(t), through a domain with protrusions from the sides. In this situation, it would be quite difficult to implement the original approach. So what else can we do?
The solution involves four steps. They are:
We can begin by dividing our original model space into two different geometry objects, as depicted in the figure below. Here, the red domains represent the stationary domains and the blue domains represent the regions in which our object is linearly translating. The subdivision process takes place in the geometry sequence, which is then finalized with the Form Assembly operation.
For a description of this functionality and steps on how to use it, watch this video.
Subdividing the modeling space into different geometry objects.
The Form Assembly step will allow the finite element meshes in the blue domains to slide relative to the meshes in the red domains. This step will also automatically introduce identity pairs that can be used to maintain continuity of the fields for which we will be solving. Let’s take a look at a representative mesh that may be appropriate in this case.
The subdivided domains with a representative mesh.
In the figure above, note that the dark red domains contain meshes that will not move at all. The dark blue domains, meanwhile, have translations completely defined by our known function, \mathbf x(t). The light blue domains are the regions in which the mesh will deform. We can simply use the previously introduced method of bilinear interpolation in these domains. You should also note that a Mapped mesh is used for these two rectangular domains and that the distribution of the elements is adjusted, such that they are reasonably similar in size or smaller than the adjacent nondeforming elements.
After the object has been linearly translated, the mesh in the light blue domains deforms.
From the previous images, you can clearly see that the meshes no longer line up between the moving and stationary domains. While COMSOL Multiphysics version 5.0 has introduced greater accuracy in the handling of noncongruent meshes between domains, there are some things that you should be aware of when using this functionality.
As a result of the Form Assembly geometric finalization step, COMSOL Multiphysics will automatically determine the identity pairs — the mating faces at which the mesh can be misaligned. We simply need to tell each physics interface within our model to maintain continuity at these boundaries. This can be accomplished via the Pairs > Continuity boundary condition, which is available within the boundary conditions for all of the physics interfaces.
Once this feature is added and applied to all of the identity pairs, the software will apply additional conditions at these interfaces to ensure that the solution is as smooth as possible over the mesh discontinuity. Each identity pair has a socalled source side and a destination side. The mesh on the destination side should be finer in all configurations of the mesh.
Assembly meshes with noncongruent meshes at the boundaries can be used in combination with most physics interfaces. There are, however, a few important exceptions. Whenever you are solving an electromagnetics problem involving a curl operator on a vector field, such a technique cannot be used. Common physics interfaces that fall into this category include the 3D Electromagnetic Waves interfaces, the 3D Magnetic Fields interfaces, and the 3D Magnetic and Electric Fields interfaces. This still, of course, leaves us with a wide range of physics.
Let’s look at one case of computing the temperature fields around our object, with differing temperatures for the object and the surrounding domain’s outer walls. The contour plots of the temperature fields shown below verify that the solution is quite smooth over the boundary where the mesh is not continuous.
The temperature fields over time are smooth across the Continuity boundary condition applied to the identity pair.
At this point, you can probably already see how this same technique can be applied to a rotating object. We simply create a circular domain around our rotating object and use all of the same techniques we have discussed here. Of course, if the object is only rotating, we no longer need the deforming mesh — making things even a bit simpler for us.
The figures below show the same object from before, except now the object is rotating.
An object rotating about a point.
An assembly composed of stationary and rotating objects as well as the mesh.
The expressions for the prescribed deformation of the rotating domain, (X_{r}, Y_{r}), can be expressed in terms of the angular frequency, \omega; the undeformed geometry coordinates, (X_{g}, Y_{g}); the point about which the object is rotating, (X_{0}, Y_{0}); and time, t. This gives us the following expressions:
where the prescribed deformation in the Deformed Geometry interface is quite simply:
Seems easy, right? In fact, the technique outlined in this section is actually applied automatically in COMSOL Multiphysics when using the Rotating Machinery, Fluid Flow and the Rotating Machinery, Magnetic physics interfaces. This provides you with a behindthescenes look at what is going on within these interfaces!
We have now introduced methods for modeling the motion of solid objects inside fluid or vacuumfilled domains. Although we have simply prescribed a displacement in all of these cases, the displacement of our solid objects could be computed and coupled to the field solutions in the surrounding regions. That is, however, a topic for another day.
Interested in learning more about using the deformed mesh interfaces for your modeling? Download the tutorial from our Application Gallery.
]]>
Suppose we want to set up a COMSOL Multiphysics model of a solid object moving around inside of a larger domain filled with fluid such as air, or even just a vacuum. To start, let’s assume that we know what path the object will take over time. We won’t worry about which physics we need to solve the model, but we’ll assume that we want to solve for some fields in both the moving domain and the surrounding domain. Of course, we will need a finite element mesh in both of these regions, but this finite element mesh will need to change.
A solid object moves freely around inside of a larger domain along a known path.
For situations like this, there are two options: The Deformed Geometry interface and the Moving Mesh interface. These two interfaces actually work identically, but are meant to be used in different situations.
The actual use of these two interfaces is identical, but choosing between them depends on which other physics you want to solve, as the interfaces handle each type of physics differently. Although we won’t cover how to choose between these two interfaces in this blog post, it is worth reading the sections “Deformed Mesh Fundamentals” and “Handling Frames in Heat Transfer” in the COMSOL Multiphysics Reference Manual as a starting point.
It is also worth mentioning that the Solid Mechanics interface cannot be combined with the Moving Mesh interface. The Solid Mechanics interface already computes the domain deformation via the balance of momentum. Other physics, such as heat transfer in solids, are solved on this deformed shape. On the other hand, it is reasonable to combine the Deformed Geometry interface with the Solid Mechanics interface if you want to study the change in stresses due to material removal, or if you want to perform a parametric sweep over a dimension without parameterizing the geometry, as described in this previous blog post.
Here, we look at the conceptual case of an object moving around inside of a larger domain with stationary boundaries, as shown in the figure above. The path of the object over time is known. We will look at how to set up the Deformed Geometry interface for this problem. But first, we need to take a quick look at which equations will be solved in COMSOL Multiphysics.
Our case of an object moving around inside of a domain is actually a boundary value problem. All boundaries have known displacements, and these boundary displacements can be used to define the deformation of the mesh within the interior of both domains.
There are four types of approaches for computing the deformation of the mesh within each domain: Laplace, Winslow, Hyperelastic, and Yeoh smoothing types. Here, we will address only the simplest case, referred to as a Laplace smoothing, and demonstrate how this approach is sufficient for most cases. The Laplace smoothing approach solves the following partial differential equation within the domain:
where lowercase (x,y,z) are the deformed positions of the mesh and uppercase (X,Y,Z) are the original, undeformed positions.
Since the displacements at all boundaries are known, this is a wellposed problem, and theoretically, the solution to this equation will give us the deformation of the mesh. However, in practice, we may run into cases where the computed deformation field is not very useful. This is illustrated in the figure below, which shows the original mesh on the original domain and the deformed mesh as the part is moved along the diagonal. Observe the highlighted region and note that the mesh gets highly distorted around the moving part edges, especially at sharp corners. This high distortion prevents the model from solving the above equation past a certain amount of deformation.
Original and deformed mesh. The region where the mesh gets highly distorted is highlighted.
In the above image, the deformation of the blue domain is completely described by its boundaries and can be prescribed. On the other hand, the deformation within the red region requires solving the above partial differential equation, and this leads to difficulties. What we want is an approach that allows us to model greater deformations while minimizing the mesh deformation.
If you have a mathematical background, you will recognize the above governing equation as Laplace’s equation and you might even know the solutions to it for a few simple cases. One of the simpler cases is the solution to Laplace’s equation on a Cartesian domain with Dirichlet boundary conditions that vary linearly along each boundary and continuously around the perimeter. For this case, the solution within the domain is equal to bilinear interpolation between the boundary conditions given at the four corners. As it turns out, you can use bilinear interpolation to find the solution to Laplace’s equation for any convex foursided domain with straight boundaries.
The first thing that we have to do is subdivide our complicated deforming domain into convex foursided domains with straight boundaries. One such possible subdivision is shown below.
Subdividing the domain so that the deforming region (red) is composed of foursided convex domains.
The deforming domain is divided into convex quadrilateral domains. In fact, we could have also divided it into triangular domains since that would simply be a special case of a quadrilateral with two vertices at the same location — a socalled degenerate domain. We would only need to decompose the domain into triangles if it were not possible to split the domains into quadrilaterals.
Now that we have these additional boundaries, we need to completely define all of the boundary conditions for the deformation within the domain. The boundaries adjacent to the deforming domain are known and there is no deformation at the outside boundaries. But what about the boundaries connecting these? We have a straight line connecting two points where the deformation is known, so we could just apply linear interpolation along these lines to specify the deformation there as well.
And how can we easily compute this linear interpolation? As you might have already guessed, we can simply solve Laplace’s equation along these connecting lines!
A very general way of doing this is by adding a Coefficient Form Boundary PDE interface to our model to solve for two variables that describe the displacement along each of these four boundaries. This interface allows you to specify the coefficients of a partial differential equation to set up Laplace’s equation along a boundary. We know the displacements at the points on either end of the boundary, which gives us a fully defined and solvable boundary value problem for the displacements along the boundaries.
These new help variables completely define the deforming domains. The results are shown below and demonstrate that larger deformations of the mesh are possible. Of course, we still cannot move the object such that it collides with the boundary. That would imply that the topology of the domain would change; also, the elements cannot have zero area. We can, however, make the deformed domain very small and thin.
The undeformed and deformed mesh after adding the help variables for the Deformed Geometry along the interior boundaries.
You are probably thinking that the mesh shown above appears rather distorted, but keep in mind that all of these distorted elements still have straightsided edges, which is good. In practice, you will often find that you can get good results even from what appear to be highly distorted elements.
However, we can observe that there are now very many small, distorted elements in one region and larger, stretched elements in other parts of our moving domain. The last piece of the puzzle is to use Automatic Remeshing, which will stop a transient simulation based on a mesh quality metric and remesh the current deformed shape.
The deformed geometry immediately before and after the Automatic Remeshing step.
We can see from the above images that Automatic Remeshing leads to a lower element count in the compressed region and adds elements in the stretched region, such that the elements are reasonably uniform. This total number of elements in the mesh stays about the same. There is also an added computational burden due to the remeshing, so this step is only warranted if the element distortion adversely affects the accuracy of the results.
We have looked at a case where we know exactly how our solid object will move around in our fluid domain. But what if there is an unknown deformation of the solid, such as due to some applied loads that are computed during the solution? A classic example of such a situation is a fluidstructure interaction analysis, where the deformation of the solid is due to the surrounding fluid flow.
In such situations, we can use the Integration Component Coupling operator, which makes the deformation at one point of a deforming solid structure available everywhere within the model space. The deformation of one or more points can then be used to control the deformation of the mesh. A good example of this technique is available in the Micropump Mechanism tutorial. The technique is visualized below.
When the actual deformation is unknown, an integration component coupling at a helper point can be used to control a helper line that defines the mesh deformation.
We can see in the image above that the modeling domain is actually not divided into convex quadrilaterals, and that the helper line is allowed to slide along the top boundary of the modeling domain. So this modeling approach is a little bit less strict, yet still allows the mesh to deform significantly. Hopefully it is clear that there is no single best approach to every situation. You may want to investigate a combination of techniques for your particular case.
We have described how to use the deformed mesh interfaces efficiently by decomposing the deforming domain into quadrilateral domains and introducing help variables along the boundaries. This approach makes the problem easier for the COMSOL Multiphysics software to solve. The addition of Automatic Remeshing is helpful if there is significant deformation. The approach outlined here can also be applied to 3D geometries. An example that uses both 2D and 3D cases is available here.
So far, we have only looked at translations of objects inside of relatively simple domains where it is easy to set up deforming domains. When we need to consider geometries that cannot easily be subdivided and cases with rotations of objects, we need to use a different approach. We will cover that topic in an upcoming blog post on this subject, so stay tuned!
]]>
Suppose you are tasked with computing the fluid flow through a network of pipes, as depicted below. You can see that there are many bends with long straight sections in between.
A piping network. Image by Hervé Cozanet, via Wikimedia Commons.
The geometry for a fluid flow model of just one pipe in this network might look like the image below.
A CAD model of a pipe volume for fluid flow analysis.
If you go ahead and mesh this geometry with just the default PhysicsControlled Mesh capability, you will obtain a mesh like that pictured below. Note that the boundary layer mesh is applied to the pipe walls and that the mesh is otherwise quite uniform in size within the long, straight sections of the pipe.
The default finite element mesh for this fluid flow problem includes a boundary layer mesh on all noslip boundaries.
An experienced fluid flow analyst would immediately recognize that the flow field in the long, straight sections will be primarily parallel to the pipe and vary quite gradually along the axis. Meanwhile, the variation of the velocity along the cross section and around the bends will be significant. We can exploit this foreknowledge of the solution to partition the geometry into various domains.
The pipe domain is partitioned into several subdomains, which are shown in different colors.
Once the geometry is partitioned, we can apply a Free Tetrahedral mesh feature. This mesh should only be applied to one of the domains along the length of the pipe; a domain that represents a bend (depicted below). Note that the Boundary Layers mesh feature is not yet applied.
A tetrahedral mesh is applied to only one of the domains.
From this one meshed domain, we can now use the Swept mesh functionality in the straight sections, as illustrated below. It is also possible to specify a Distribution subfeature to the Swept feature to explicitly control the element distribution and set up a nonuniform element size along the length. Since we anticipate that the flow will vary gradually along the length, the elements can be quite stretched in the axial direction.
The swept mesh along the straight sections also has a nonuniform element distribution.
We can now apply a tetrahedral mesh to nest the two bent sections and sweep the remaining straight sections. The last step of the meshing sequence is to apply the Boundary Layers mesh feature.
The combination of a tetrahedral and swept mesh with the boundary layers applied at the walls.
From the above images, we can observe that the swept mesh can significantly reduce the size of the model for this fluid flow problem. Our Flow Through a Pipe Elbow tutorial is one example in which this swept meshing technique is used.
Shifting gears, let’s now consider an inductive coil similar to the one pictured below.
An inductive coil. Image by Spinningspark, via Wikimedia Commons.
This coil consists of a long wire with quite gradual bends. If tasked with computing the inductance, we would also need to consider the surrounding air and the magnetic core materials. The geometry for such a model and the default mesh might look like the image below.
A coil surrounding a magnetic core in an air domain.
The default Free Tetrahedral mesh feature is applied to the entire model.
You’ve probably already recognized that the coil itself is an excellent candidate for swept meshing. The coil is long and uniform in cross section. As such, we can begin with a triangular surface mesh at one end and then sweep it along the entire length of the coil to create triangular prismatic elements.
A triangular mesh (represented in blue) is applied to the crosssectional surface at one end of the coil and then swept along the entire length.
We do, however, still need a volumetric mesh of the surroundings. This surrounding volume is amenable to only tetrahedral meshing, not swept meshing. A volume that is to be meshed with tetrahedral elements can only have triangular surface elements on all of its boundaries. Thus, we must first add a Convert feature to the mesh sequence and apply it to the surfaces between the coil and its surroundings. The operation is designed to split the elements touching the boundaries such that triangular face elements are created.
The convert operation introduces triangular elements on the boundaries of the coil.
The remaining domains are meshed with tetrahedra.
From the above image, we can see that fewer elements are used to describe the coil than in the default mesh settings. A similar example is the Anisotropic Heat Transfer Through Woven Carbon Fibers tutorial, which considers a combination of swept meshing and tetrahedral meshing of the surroundings (albeit with different physics involved).
Finally, let us consider a microelectromechanical system (MEMS) structure that is composed of microscale structural features that deflect. If different electrical potentials are applied to different objects, a perturbation of the structure will be measurable through a change in capacitance. A change in applied potentials can deform the system. Such an effect is exploited in devices like comb drives, accelerometers, and gyroscopes.
A MEMS cantilever beam at resonance. Image by Pcflet01, via Wikimedia Commons.
A common characteristic of such MEMS structures is that they are composed of various thin planar layers that need to be meshed along with the surrounding air domain. The gaps between structures may also be quite slender. A simplified model for part of such a MEMS structure might appear similar to the model shown below, with interleaved fingers.
A simplified model representing part of a typical MEMS structure.
When using the default mesh settings, small elements will be inserted in the narrow air gaps between the parts (illustrated below). However, we do know that the fingers on either side will be at different potentials and that the gap between the straight sections of the fingers and the ground plane will have a uniform electric field.
The default mesh settings show smaller elements than those that are needed in regions where we know the electric field will be nearly uniform.
This present structure is actually not amenable to swept meshing, as there are no domains in this model that have a uniform cross section. But, if we introduce some partitioning planes, we can break this domain up into prismatic domains that are amenable to swept meshing. We will first introduce two partitioning planes — one at the top and one at the bottom surface of the fingers — that will partition both the air domain and the two solid domains. We add these planes as Work Plane features to the geometry sequence and they are used as input by the two Partition Object features that divide the solids.
Two planes are introduced that partition both the air and the solid domains.
It is then possible to introduce additional partitioning planes, as shown below, to delineate the long, straight sections of the fingers. This is important because we know the electric fields and displacements will vary quite gradually in these regions.
Two additional planes divide the fingers into prismatic domains.
Now we can begin the meshing process using the Mapped mesh feature on the new rectangular surfaces introduced by the partitioning. The nonrectangular faces on the same plane can be meshed with triangular elements, as illustrated below.
A surface mesh applied to one of the partitioning planes.
The surface mesh can be used as the starting point for the swept mesh, which can be applied to the two layers of the thin domains — the fingers and the air gaps between the fingers and the ground. The air domain can be meshed with tetrahedral elements after a convert operation is applied to the adjacent rectangular element faces.
The final mesh consists of a combination of free and swept meshes.
We can observe that the number of total elements in the finite element model has been reduced. For an example demonstrating this technique of partitioning planes and swept meshing, please see our Surface Micromachined Accelerometer tutorial.
Swept meshing is a powerful technique for minimizing the computational complexity of many classes of COMSOL Multiphysics models. By using your engineering judgment and knowledge to address each problem, you can obtain highaccuracy results quickly and at relatively lower computational costs than with default mesh settings.
While you, of course, do not always need to use this approach, you should consider applying it to cases where your geometry has high aspect ratios, there are relatively thin or thick regions, and you are reasonably certain that the solution will be represented well by the swept mesh.
In conjunction with this topic, here are some additional blog posts to read:
Consider a onedimensional domain on the xaxis with a source localized around x = 0. We can plot the strength of the source as a function of x and it may look like this:
Here, we have assumed that the strength has a constant value of 1/w within the interval [w/2, w/2] and is zero everywhere else. This gives a rectangular shape of width w and height 1/w, as shown in the figure above. The function is often called a rectangular, tophat, or sometimes, a disc function. The total strength of the source is given by the area of the rectangle, which is unity.
For linear systems, if we only care about what happens far away from the source where \left x \right \gg w, then the actual shape of the source strength does not matter much, as long as the area beneath that shape is the same. Furthermore, we are free to make w progressively smaller and smaller: the width of the rectangle decreases while its height increases in such a way that the total area remains the same, as shown in the graph below.
The localized source represented by the blue curve is progressively made thinner and taller (the orange and green curves), while maintaining the integrated strength of unity.
Eventually, we arrive at a rectangle that is infinitesimally thin and infinitely tall, but still has a well defined area of unity. This leads us to the socalled delta function \delta(x) and, correspondingly, the localized source now becomes an idealized point source of unit strength.
The delta function has some convenient properties. Its value is zero everywhere except at the origin:
Integrating the product of a delta function and another function just extracts the value of the latter function at the origin:
A point source at a general position x=a can be obtained by a simple coordinate shift of the delta function \delta(xa). We have
and
It is also easy to generalize the delta function and the corresponding point source to higher dimensions. For example, in 2D, we have
and
(1)
This tutorial solves the Poisson equation on a unit disc with a point source at the origin. The equation reads
(2)
where u is the dependent field variable to be solved.
At first sight it may not be obvious how to discretize this equation to be solved numerically. What value do we put at the origin for the source term on the righthand side? The value of the delta function is infinite there, but computers don’t like infinities!
Here, we will see that the weak formulation comes in handy. Recall that in this introductory blog post on the weak form, we multiply the differential equation to be solved by a test function and integrate over the entire domain (See Eq.(4) in that post). We can follow the same procedure here to solve Eq. (2). After multiplying by a test function \tilde{u}(x,y) and integrating over the unit disc domain, the righthand side of Eq. (2) simply becomes
(3)
by using the integration property of the delta function given in Eq. (1). This gives us something very easy to implement in COMSOL Multiphysics.
Start with a new 2D model with the Weak Form PDE physics interface and a Stationary study. Draw a unit circle centered at (0,0) and draw a point there as well. Set the Weak Expressions field under the default Weak Form PDE 1 feature to test(ux)*uxtest(uy)*uy
. This takes care of the lefthand side of Eq. (2) in exactly the same fashion as for the 1D case discussed in this previous post.
Now, for the point source on the righthand side, \tilde{u}(0,0), we simply add a point Weak Contribution node and select the point at the origin. For the Weak expression, we enter test(u)
. It’s that simple for the point source!
It may be worth noting that by entering test(u)
, we set the strength of the point source to unity. For any other source magnitude, simply multiply by a factor. For example, the expression 2*test(u)
gives a point source of strength 2.
After finishing the setup with a Dirichlet boundary condition at the perimeter of the circle, we can solve the model and observe the same solution as seen in the point source tutorial mentioned above:
Also as seen in the tutorial, the numerical solution (blue curve) matches the analytical solution (green curve) very well, except near the original where a singularity occurs:
As mentioned earlier, the point source provides a convenient idealization of a localized source in situations where we only care about the solution far away from the source. We illustrate this point with the following graph, where we have added three more curves to the graph above. These three curves are numerical solutions to the same Poisson equation in the same unit disc domain, but with various sizes of tophat, or disc, shaped sources replacing the point source. The integrated strength of each tophat source is calibrated to unity by setting its height to one over its area, in the same fashion as in the 1D case shown in the image above. As we see clearly from the figure below, all solutions are indistinguishable from one another far away from the sources. (In this example for x \gg 10 \, mm.)
Here, we have demonstrated the ease of creating point sources using the weak form. The numerical difficulty in the representation of the delta function is circumvented with a simple integration. In upcoming posts we will look at discontinuities and boundary conditions. Stay tuned!
]]>
Let’s begin by looking at a microfluidic device, as shown below. Such devices feature small channels that are filled with fluids carrying different chemical species. Within their design, a common goal is to achieve optimal mixing within a small surface area, hence the serpentine channel.
A typical microfluidic device. Image by IXfactory STK — Own work, via Wikimedia Commons.
The schematic below illustrates that there are two fluid inlets, both of which carry the same solvent (water) but a different solute. At the outlet, we want the species to be well mixed. To model such a situation, we want to solve the NavierStokes equations for the flow. This computed flow field can then be used as input for the convectiondiffusion equation governing the species concentration. The Micromixer tutorial, available in our Application Gallery, is an example of such a model.
Now, if desired, it is possible to model the entire device shown above. However, if we neglect the structure near the inlet and the outlet, we can reasonably assume that the flow within the channel bends will be identical between the unit cells. Therefore, we can greatly reduce our model by solving only for the fluid flow within one unit cell and patterning this flow solution throughout the modeling domain for the convectiondiffusion problem.
Schematic of a microfluidic mixer that depicts the repeated unit cell and the inlet and outlet zones.
For such a unit cell model, the walls of the channels are set to the Wall, No Slip condition. The Periodic Flow condition is used to set the velocity so it is identical at the inlet and outlet boundaries, allowing us to specify a pressure drop over a single unit cell. A pressure constraint at a single point is used to gauge fix the pressure field. The working fluid is water with properties defined at room temperature and pressure. The flow solution on this unit cell is also plotted, as shown below.
The periodic modeling domain and the fluid flow solution.
Now that we have the solution on one unit cell, we can use the General Extrusion component coupling to map the solution from this one unit cell onto the repeated domains. This will enable us to define the flow field in the entire serpentine section.
The General Extrusion feature is available in the model tree under Component > Definitions > Component Coupling. The settings for this feature are illustrated below. To map the solution from one domain into the other domains that are offset by a known displacement along the xaxis, the destination map uses the expression “xDisp” for the xexpression. Thus, every point in the original domain is mapped along the positive xdirection by the specified displacement. Since there is no displacement in the ydirection, the yexpression is set at its default “y”.
The variable Disp is individually defined within each of the three domains, as shown in the figure below. Therefore, only a single operator is needed to map the velocity field into all of the domains. Within the original domain, a displacement of zero is used.
The settings for the General Extrusion operator and the definitions of the variable in the three domains.
With the General Extrusion operator defined, we can now use it throughout the model. In this example, the operator is used by the Transport of Diluted Species interface to define the velocity field (illustrated below). The velocity field is given by u and v, the fluid velocity in the x and ydirections, respectively. The components of this velocity field are now defined in all of the repeated domains via the General Extrusion operator: genext1(u) and genext1(v), respectively.
The General Extrusion operator is used to define the velocity field in all three periodic domains.
Now that the velocity field is defined throughout the modeling domain, the species concentration at the inlet is defined via the Inflow boundary condition. This applies a varying species concentration over the inlet boundary. An Outlet boundary condition is applied at the other end.
Although it is not strictly necessary to do so, the mesh is copied from the one domain used to solve for the fluid flow to all of the other domains. The Copy Domain mesh feature can copy the mesh exactly, thereby avoiding any interpolation of the flow solution between meshes.
The model is solved in two steps — first, the Laminar Flow physics interface is solved, and then the Transport of Diluted Species interface is solved. This is reasonable to do since it is assumed that the flow field is independent of the species concentration. The results of the analysis, including the concentration and the mapped velocity field, are depicted below.
The species concentration (shown in color) is solved in all three repeating domains. The periodic velocity field, indicated by the arrows, is solved in one domain and mapped into the others.
We have discussed how the General Extrusion component coupling can be used to set up a linear pattern of a periodic solution as part of a multiphysics analysis. For circular periodicity, a rotation matrix, not a linear shift, must be used in the destination map. An example of defining such a rotation matrix is detailed in this previous blog post.
The approach we have applied here is appropriate for any instance in which a spatially repeating solution needs to be utilized by other physics. Where might you use it in your multiphysics modeling?
]]>
Let’s start this conversation with a very simple problem — computing the capacitance of two parallel flat square metal plates, of side length L=1\:m, separated by a distance D=0.1\:m, and with a dielectric material of relative permittivity \epsilon_r= 2 sandwiched in between. Under the assumption that the fringing fields are insignificant (a rather severe assumption, but we will use it here to get started), we can write an analytic expression for the capacitance:
where \epsilon_0 is the permittivity of free space.
We can easily differentiate this expression with respect to our three inputs to find the design sensitivities:
Now let’s look at computing these same sensitivities using the functionality of COMSOL Multiphysics.
Schematic of a parallel plate capacitor model, neglecting the fringing fields.
We can start by building a model using the Electrostatics physics interface. Our domain will be a block of length L and height D with a relative permittivity of \epsilon_r. The boundary condition at the bottom is a Ground condition, and at the top, an Electric Potential condition sets the voltage to V_0=1\:V. The sides of the block have the default Zero Charge boundary condition, which is equivalent to neglecting the fringing fields. We can solve this model and find the voltage field between the two plates. Based on this solution, we can also calculate the system capacitance based on the integral of the electric energy density, W_e, throughout the entire model:
This equation does assume that one plate (or terminal) is held at a voltage V_0, while all other terminals in the model are grounded. The integral of the electric energy density over all domains is already computed via the builtin variable comp1.es.intWe
, and we can use it to define an expression for the computed capacitance. Of course, we will want to compare this value and our computed sensitivities to the analytic values so we can define some variables for these quantities. We can use the builtin differentiation operator, d(f(x),x), to evaluate the exact sensitivities, as shown in the screenshot below.
Variables are used to compute the model capacitance, as well as to compute the exact capacitance and its sensitivities. The builtin differentiation operator, for example d(C_exact,L), can be used to evaluate the exact sensitivities.
After solving our model, we can evaluate the computed system capacitance, compare it to the analytic value, and evaluate the design sensitivities analytically. Now let’s look at how to compute these sensitivities with COMSOL Multiphysics.
The parameters that we are considering affect both the material properties as well as the geometric dimensions of the model. When the design parameters affect the geometry, we need to use the Deformed Geometry interface, which lets us evaluate the sensitivities with respect to a geometric deformation.
The design parameters will affect a change in the geometry as shown. The hidden faces experience no displacement normal to the boundaries.
We introduce two new Global Parameters, dL and dD, which represent a change in L and D. These will be used in the Deformed Geometry interface, which has four relevant features. First, a Free Deformation feature is applied to the domain, which means that the computational domain can deform based on the applied boundary conditions. Next, Prescribed Mesh Displacement features are applied to the six faces of the domain. In the screenshot below, the deformation (dL) normal to the faces is prescribed as shown in the sketch above.
The Prescribed Mesh Displacement features are used to control the displacement normal to all domain boundaries.
Finally, to actually compute the sensitivities, we must add a Sensitivity node to the Study Sequence. This is shown in the screenshot below. You will want to enter the objective function expression, in this case C_computed
, as well as all of the design parameters that you are interested in studying. Also, choose the value for the design parameters around which you want to evaluate the sensitivities. Since dL and dD represent an incremental change in the dimensions, we can leave these both at zero to compute the sensitivities for L=1\:m and D=0.1\:m. The parameter controlling the material permittivity needs no special handling, other than to choose it as one of the parameters in the Sensitivity study.
There are two options in the form shown below for the gradient method:
A Sensitivity feature using the adjoint method is added to the study sequence, and the settings show the objective function and the parameters that are considered.
After solving, you will now be able to go to Results > Derived Values > Global Evaluation and enter the expressions fsens(dL)
, fsens(dD)
, and fsens(epsilon_r)
to evaluate the sensitivity of the capacitance with respect to the design parameters. Of course, you can also compare these to the previously computed analytic sensitivities and observe agreement.
Analytic  Computed  

\frac{\partial C}{\partial \epsilon_r}

88.542 nF  88.542 nF 
\frac{\partial C}{\partial L}

354.17 nF/m  354.17 nF/m 
\frac{\partial C}{\partial D}

1770.8 nF/m  1770.8 nF/m 
Now that we have the basic idea down in terms of computing the sensitivity of the capacitance of this system, what else can we do? Certainly, we can move on to some more complicated geometries, but there are a few points that we need to keep in mind as we move beyond this example.
There are two conditions that must be fulfilled for sensitivity analysis to work. First, the objective function itself must be differentiable with respect to the solution field. This means that objective functions such as the maximum and minimum of a field are not possible. Second, the parameters must be continuous in the realnumber space. Thus, integer parameters (e.g., the number of spokes on a wheel) are not possible.
Sensitivity calculations are not currently available for eigenvalue problems, nor ray tracing or particle tracing.
The design parameters themselves are typically Global Parameters, but you can also use the Sensitivity interface to add a Control Variable Field defined over domains, boundaries, edges, and points as desired.
Objective functions are typically defined in terms of integrals of the solution over domains or boundaries. It is also possible to set up an objective function as a Probe at a particular location in the model space. Any derived quantity based on the solution field, such as the spatial gradients of the solution, can be used as part of the objective function.
Computing design sensitivities is helpful for determining which parameters affect our objective function the most and gives us an idea about which parameters we might want to focus on as we start to consider design changes. Some other examples that use this functionality include our tutorial model of an axial magnetic bearing and our sensitivity analysis of a communication mast detail. Of course, this method can be used in far more cases than we can describe at once.
This story continues when we start to use these sensitivities to improve our objective function — where we optimize the design. This can be done with the Optimization Module, which we will cover in an upcoming blog post.
]]>