Main Content

Modeling and Simulating Fluid Networks

You can use Simscape™ Fluids™ blocks to build models that represent fluid systems. The Simscape Fluids component libraries represent elements such as pumps, valves, heat exchangers, or pipes in several physical modeling domains.

Network Connections

Like in other Simscape models, a series of connected fluid blocks create a network. Simscape Fluids blocks model one-dimensional flow and fluid flows in both directions along the network connection lines. Many Simscape Fluids blocks support reversed flows, which you can specify by using negative variables, such as negative mass flow rate.

Each Simscape Fluids domain has Across and Through variables. Through variables are conserved through a block while the net value of an Across variables can change across a block.

Fluid DomainAcross VariableThrough Variable
Isothermal liquidAbsolute pressureMass flow rate
Thermal liquidAbsolute pressure and temperatureMass flow rate and energy flow rate
Two-phase fluidAbsolute pressure and specific internal energyMass flow rate and energy flow rate
GasAbsolute pressure and temperatureMass flow rate and energy flow rate
Moist AirAbsolute pressure, temperature, specific humidity (water vapor mass fraction), and trace gas mass fractionMixture mass flow rate, mixture energy flow rate, water vapor mass flow rate, and trace gas mass flow rate
Hydraulic (isothermal)Gauge pressureVolumetric flow rate

You can ground a fluid network by including at least one block that models fluid volume. Blocks that model fluid volume have internal volumes, which means they have internally defined states. When you connect these blocks to a network, you can set the initial conditions of the model by specifying the block parameters for the component. The components use internal nodes, which represent the fluid states of their internal volumes, to calculate the mass, momentum, and energy balance over the block. You may observe different values if you choose to measure a variable at an internal node or at a port. For more information on grounding a network, see Networks and Network Connections.

For more information on block connections, ports, and variable types, see Basic Principles of Modeling Physical Networks.

Building Models

Enter ssc_new at the MATLAB® command line to open a Simscape model template with the recommended settings. You can view the Simscape Fluids block library by entering SimscapeFluids_lib on the MATLAB command line. Add blocks from the Simulink Library Browser or the Simscape Fluids block library to construct your model. The signals between the blocks represent the physical connections that exist between the components in a real system. Combine the model blocks like you combine the elements in a physical system.

Before simulating the model, you must define the initial conditions. You can view the initial conditions in the Variable Viewer. Initial conditions for Simscape Fluids models are domain dependent:

  • In the isothermal liquid domain, provide the initial pressure.

  • In the thermal liquid domain, provide the initial pressure and temperature.

  • In the gas domain, provide the initial pressure, and either the density or temperature.

  • In the moist air domain, provide the initial pressure, temperature, humidity, and trace gas amount.

  • In the two-phase fluid domain, provide the initial pressure and either the vapor quality, temperature, enthalpy, or internal energy.

To learn more about initializing models and setting variable priorities, see Block-Level Variable Initialization.

If you use ssc_new to create your model, the default solver is set to VariableStepAuto, which works for many models. The automatic solver will typically use daessc for Simscape Fluids models, which is a recommended and robust solver. You may need to adjust the solver to balance an accurate numerical solution and simulation time for your model. The variable-step solvers ode23t and ode15s are suitable for a range of dynamics and less computationally expensive. To learn more about selecting and configuring the right solver for your system, see Setting Up Solvers for Physical Models. For applications that require a fixed step solver, such as generating code, use the ode1be or ode14x solvers. If you use a fixed step solver, consider also turning on a local solver by selecting Use local solver in the Solver Configuration block. For more information about code generation, see Code Generation.

Parameterizing Blocks

Parameterize the blocks in your model to change and control the block behavior. Choose parameter values based on information from data sheets or measurements, or adjust the parameters to match your results. You can parameterize blocks by using:

  • Analytical formulations — Blocks that use analytical expressions calculate the block characteristics from your specified parameters. For example, if you use a Fixed-Displacement Pump (IL) block and set Leakage and friction parameterization to Analytical, the block calculates the leakage and friction from nominal values of shaft velocity, pressure gain, and friction torque.

  • Tabulated data — Blocks that use tabulated data use data defined across a range of values to define the block characteristics. The data tables may be 2-D or 3-D and are composed of independent vectors, such as from a test matrix. For example, if you use the Fixed-Displacement Pump (IL) block, and set Leakage and friction parameterization to Tabulated data - volumetric and mechanical loss, the block populates the Volumetric loss table, q_loss(dp,w) parameter with the volumetric losses at each test point for pressure gain and shaft speed over the range of each parameter.

    You can visualize and check the data in a lookup table before simulating a model by using the PS Lookup Table (1D) and PS Lookup Table (2D) blocks. See Plot Lookup Tables for more information.

  • Input signals — Blocks that use input signals use input ports to define the block characteristics. For example, if you use the Fixed-Displacement Pump (IL) block, and set Leakage and friction parameterization to Input signal - volumetric and mechanical loss, the block receives the leakage flow rate and friction through physical signal ports.

  • Block pre-parameterization — Blocks that include pre-paramerizations include predefined parameterizations that model specific manufacturer parts. To learn more, see List of Pre-Parameterized Components. For example, the Fixed-Displacement Pump (IL) block has pre-defined components available from several manufacturers.

You can modify parameter values during simulation if they are run-time configurable. To learn more about configurable parameters and settings, see About Simscape Run-Time Parameters.

Simulating and Verifying Your Model

When you are finished building and parametrizing your model, you can run the model. If the model returns any errors, see Troubleshooting Fluids Simulations for more information on addressing potential model errors. After simulating, you can verify your results to ensure that they are expected. There are multiple ways to simulate and analyze Simscape Fluids networks in the Simulink® environment:

  • To view and inspect your network variables at the start of the simulation, use the Variable Viewer.

  • Some blocks can display information on the block parametrization or attributes. For example, to visualize the compressor map for the Compressor (2P) and Compressor (G) blocks, right-click the block and select Fluids > Plot Compressor Map.

  • View the results of specific signals with a Scope block. Scope blocks plot Simulink signals. Convert a Simscape physical signal to a Simulink signal by using the PS-Simulink Converter block. You can also use a Probe block to select variables from blocks in the model and output them as Simulink signals. See Connecting Simscape Diagrams to Simulink Sources and Scopes for more information.

  • In the two-phase fluid domain, the P-H Diagram (2P) block plots a p-h diagram of the pressure with respect to the specific enthalpy and can replay the animation from the most recent simulation.

  • View the results from a block or the entire model by enabling data logging and viewing the results in the Simscape Results Explorer or the Simulation Data Inspector.

    • To turn on data logging for all blocks, from the Simulink Toolstrip, select Modeling > Model Settings > Model Settings. In the Configuration Parameters dialog box, select Simscape. In the right pane, under Data Logging, set Log simulation data to All and select Open viewer after simulation.

    • To turn on data logging for a specific block, click the block. In the Simscape Block tab, click Log Data and select Log Data, Log selected blocks only, and Open viewer after simulation.

    Use the Simscape Results Explorer to view the results of signals after simulating the model and the Simulation Data Inspector to compare results between simulations.

Balancing Accuracy, Speed, and Efficiency in Your Model

To change the accuracy, speed, and efficiency of your simulation, you can adjust one or more of these parameters in the Solver pane of the Configuration Parameters dialog box:

If you are using a fixed step solver, consider selecting Use local solver and adjusting the solver settings in the Solver Configuration block. See the Solver Configuration block to learn more.

In most cases, the default tolerance and step size values produce a good balance between the accuracy and speed of your model. You can balance the speed and accuracy by adjusting the Relative tolerance and Absolute tolerance parameters in the Solver pane of the Configuration Parameters dialog box. If the solver is missing significant behavior, you can choose smaller values for the tolerance parameters, but this will increase simulation time.

Related Topics