September 2nd, 2016 by Mahdieh Mehrabi

**Written by: Maura Gallarotti – Project Engineer**

When building fluid networks in Dymola, it is of paramount importance to place the components in a specific order to achieve a staggered grid arrangement. This will reduce the number of non-linear equations, making the convergence faster and easier.

In this article, the staggered grid approach in the fluid networks will be explained and the importance of building networks following this rule will be demonstrated through a simple example.

Figure 1 shows a staggered grid, where mass-related fields such as pressure and temperature are defined on one set of grid points while velocity fields are defined on another set of grid points.

In Dymola, flow resistance models are components where the momentum balance is performed. Inside this models (that can be replaced with any model extended from BaseClasses.FlowModels.PartialStaggeredFlowModel), two different types of functions are used:

- dp_MFLOW: calculates the mass flow rate through the component out of the pressure drop dp. Generally, this function is numerically best used for the compressible case, where the pressure loss (dp) is known from the pressures defined as state variables in the medium model.
- dp_DP: calculates the pressure loss from the mass flow rate. It is numerically best used for the incompressible case, where the mass flow rate is known as state variable in the medium model.

On the other hand, volume models are the models where mass and energy balances are performed according to the finite volume approach. In the volumes, the pressure is defined as a state.

When two flow resistance models are connected in series, the pressure at the connection is unknown and the solver has to iterate at every step to calculate the pressure, leading to large nonlinear systems.

If two volumes are directly connected together, this means that (due to the stream concept of the connectors) the pressures of the two connected volumes are identical, the temperatures, however, are not equal. This corresponds to volumes that are connected together with a very short distance between them and the solver will need to iterate for some time until the different volume temperatures are equalised (leading to high-index DAE).

*Figure 1: Staggered grid.*

*Figure 2: Example of volume models vs flow resistance models.*

MSL pipes can have different structures which can be configured with the parameter ModelStructure on the Advanced tab:

*Figure 3: MSL Pipe Advanced tab showing all the possible model structure configurations.*

The model structures included in MSL pipes are:

**av_vb**: port_a – volume – flow model – volume – port_b (**nNodes-1**momentum balances between**nNodes**flow segments)**a_v_b**: port_a – flow model – volume – flow model – port_b (**nNodes+1**momentum balances across**nNodes**flow segments)**av_b**: port_a – volume – flow model – port_b**a_vb**: port_a – flow model – volume – port_b

The default is:

- nNodes=2
- modelStructure=Types.ModelStructure.av_vb

To practically demonstrate what has been discussed so far, we can build a simple fluid network to test the MSL pipe model.

The default settings for the MSL pipe are nNodes=2 and modelStructure av_vb (volume – flow model – volume). This means that to build the staggered grid correctly, we need two orifices (which are flow models), one before and one after the pipe.

Doing so, there will not be nonlinear systems, as shown in the translation tab – Statistics:

*Figure 4: Translation tab – Statistics for a staggered grid (nNodes=2).*

In case one wants to discretize the pipe with just one volume, the structure of the pipe could be either a_vb (flow model – volume) or av_b (volume – flow model). In this case, the fluid layout with the pipe between two orifices is not staggered anymore and leads to a nonlinear system of equations, as shown in the translation tab – Statistics.

*Figure 5: Translation tab – Statistics for a non staggered grid (nNodes=1).*

However, if a volume is introduced before the pipe (with structure a_vb), the nonlinear system of equations disappears:

*Figure 6: Translation tab – Statistics for a staggered grid (nNodes=1).*

This simple example has shown the effect of a non-staggered arrangement on the number of non-linear systems. When building more complex systems, it is essential to build fluid networks using the structure flow model – volume, to avoid models that are uselessly computationally expensive.

References:

Modelica Users Guide version 3.2.2

**Written by: Maura Gallarotti – Project Engineer**