主要内容

Develop Simscape Fluids Models for Efficient Simulations and Real-Time Applications

To use a Simscape™ Fluids™ model in real-time, hardware-in-the-loop simulation, the model must run with a fixed-step solver and at a fixed cost. Fluid domains model complex dynamics and require specific considerations. For more information on configuring a Simscape model for real-time simulation, see Real-Time Model Preparation.

To see an example that converts a Simscape Fluids model for real-time execution, see Configure a Hydraulic Lift Model for Real-Time Simulation.

Choose the Domain

The computational complexity of a Simscape Fluids model depends on its fluid domain. To develop a model for real-time simulation, choose the simplest domain for your modeling needs. This table lists the domains in increasing order of computational complexity. For more information on fluid domains, see Select the Working Fluid.

DomainNotes
Isothermal liquid The isothermal liquid domain has the lowest computational requirements.
Thermal liquidModeling thermal effects introduces computational complexity. If thermal effects are not crucial, consider using the isothermal liquid domain.
GasModeling compressible flow effects or choked flow adds computational complexity. Fast dynamics, such as valves that open and close quickly, are also more common in the gas domain.
Moist airModeling water condensation and multiple species adds equations and complexity. Similar to the gas domain, blocks in the moist air domain can model compressible flow effects, which can have choked flow and fast dynamics, which add computational complexity.
Two-phase fluid

The range of fluid attributes across the fluid states adds computational complexity. Liquid and vapor density and energy can differ by orders of magnitude, which makes pressure and flow rate sensitive to changing conditions.

To model refrigeration systems in the two-phase fluid domain in real-time, you must specify the correct charge mass. Use the refrigerantChargeProperties function to help determine the correct initial conditions based on charge mass.

Build a Model That Follows Modeling Best Practices

To create a model to convert to real-time, develop the initial model by following modeling best practices.

Build the Model Incrementally

Ensure that small sections of the model run in fixed-cost and fixed-step before combining them. Repeatedly test the model as you add more pieces. Building the overall model incrementally can identify if certain blocks or pieces of the model introduce performance issues.

Prevent Model Complexity

As you build your model, keep the number of blocks low and use simple blocks where possible. Consider the following:

  • Use Flow Resistance or Orifice blocks, which have more robust equations, rather than Local Restriction blocks.

  • Place blocks that model fluid volume, such as chambers or pipes, between valves. You can also increase the leakage in valves that close quickly to prevent dry nodes. Dry nodes occur when the solver calculates a block node that has no fluid present.

  • Add expansion tanks, such as the Tank (G-TL) block or an accumulator block, to liquid closed loops. These blocks provide liquid expansion space.

  • Start models from equilibrium. Check that the initial conditions are consistent across blocks. Start the model with pumps off, valves between large pressure gradients closed, valves between no pressure gradients open, and at environmental temperature. After the simulation starts, you can slowly introduce dynamics to the model.

  • When modeling two-phase fluid condenser-evaporators, use system-level blocks, which are less computationally expensive than geometry-based condenser-evaporator blocks.

Add Fluid Power Sources

Two types of blocks can introduce flow in a fluid model: ideal Flow Rate Source blocks and fluid machine blocks, such as compressor or pump blocks. Avoid using Flow Rate Source blocks with constant or simple inputs in a closed loop, because the underlying equations can be too numerically stiff or can cause problems with fluid capacitance. Use fluid machine blocks, such as a compressor or pump. You can also use a Flow Rate Source and a PS Lookup Table block controlled by a Pressure Sensor block. This combination of blocks can represent a fluid machine.

If you are using a Flow Rate Source block, set Flow rate type to Mass flow rate rather than Volumetric flow rate. The block calculations when modeling volumetric flow rate depend on the density at the block outlet, which can be impacted by changes downstream.

Prevent Fast Dynamics

If a model has rapidly oscillating or changing dynamics, the solver requires very small steps to solve it, which makes it difficult to run in real-time. In Simscape Fluids models, you can prevent fast dynamics by:

  • Replacing high frequency oscillating components with a representative component. For example, use a flow source or a simple pump to model a piston pump.

  • Avoiding sharp changes between operation modes, flow turning on or off, or flow changing directions.

  • Adding a transfer function to the input signal to slow the effects on blocks controlled by input signals, such as valves or compressors. If the model uses a Simulink-PS Converter block, set Filtering and derivatives to Filter input, derivatives calculated and Input filtering order to First-order filtering.

Convert to Fixed-Cost and Fixed-Step

After you assemble the model, ensure that it runs smoothly and accurately with a variable-step solver before configuring the solver to run in real-time. To run a model in fixed-step and fixed-cost, in the Solver Configuration block, select Use local solver and Use fixed-cost runtime consistency iterations, and run the model. If the model runs without error and the results match what is expected, the model is real-time capable. If you do not have expected results to compare to, you can compare the results from the variable and fixed-step versions of the model. For more information on solver settings for real-time models, see Define Step Size and Number of Nonlinear Iterations for Simscape Real-Time Simulation.

For an example that illustrates possible fixed-cost errors and demonstrates how to compare the simulation results, see Configure a Hydraulic Lift Model for Real-Time Simulation.

See Also

|