Main Content

Validating Flow Response With the Simulation Data Inspector

This example shows the workflow for a unit test assessment of model suitability based on the mass flow rate through a valve by using the Simulation Data Inspector (Data Inspector). Performing a successful validation ensures that you are using the most appropriate equations to model a specific application or phenomena. Testing a model's response in a test harness helps to assess the response of a model to a controlled range of inputs. You can find other test harness examples in Test Harnesses.

This tutorial uses the example sscfluids_4_way_3_position_valve, which is composed of a Simulink model and a live script that runs the harness for multiple spool positions:

Model of a valve in a test harness

The sscfluids_4_way_3_position_valve example uses a script to run and process the model and plot the simulation data. This tutorial shows an alternative way to validate the model by using the Simulation Data Inspector. Open the model by entering sscfluids_4_way_3_position_valve at the command line. Open the live script by clicking the Open live script link at the bottom of the model.

Build a Test Harness

To collect simulation data to validate the four-way valve, construct a unit test that interrogates the valve at a range of pressures. The sscfluids_4_way_3_position_valve is an example of a four-way valve in a test harness:

  • Use a Ramp block and a PS-Lookup Table (1D) block to set the testing range of the valve. The ramp block specifies the simulation time and the look-up table specifies the validating data range. In sscfluids_4_way_3_position_valve:

    • Mass flow rate is the chosen variable to validate against specification sheet data. The test harness is configured to steadily increase pressure from 0 to 5.8 bar.

    • The specification sheet data is for maximum open area, which is when the spool positions are fully extended in the positive and negative positions. The simulation runs two tests: one for the flow paths open at the maximum positive position, and one for the flow paths open at the maximum negative spool position.

  • Store your validating data in a Simulation Data Inspector-friendly format. The validating data is specified as volumetric flow rate for pressure differential over the four valve flow paths. However, the data need to be converted to a timeseries in order to compare it in the Data Inspector with the simulation results:

    %For 11 data points in the look-up table during a ramp from 0 to 100s:
    flowRateData_PB = timeseries(0.0166*[0.58 9.45 20.6 29.9 41.7 55.9 69.3 82.2 94 107 120], linspace(0,100,11));
    flowRateData_PB.Name = 'Mass Flow Rate PB';
    save validating_data.mat flowRateData_PB
    The specification sheet data is in lpm. To match the simulation default units, the data set is multiplied by 0.0166 to convert the data to kg/s.

    You can also import timeseries data from an Excel sheet. For more information on formatting data for the Simulation Data Inspector, see Simulink.sdi.createRun and Microsoft Excel Import, Export, and Logging Format.

  • In sscfluids_4_way_3_position_valve, the valve performance is modeled by default with tabulated data. Change this to a linear model in the live script at line 26 with the following command:

    % Setting parameters from Orifice parameterization dropdown

    This is equivalent to setting the valve Orifice parameterization to Linear - Area vs. spool travel.

  • The test harness is constructed as a unit within a system. To maintain flow through the valve, pumps are connected between the look-up tables and ports.

Collect Simulation Data

The interrogation range is set by the limits of the validating data.

Once the ramp, valve, and 1-D look-up table data and parameters have been set, log the valve data so it can be used in the Simulation Data Inspector. To log the data:

  1. In Modeling, select Model Settings > Model Settings, select Simscape.

  2. In the Simscape pane, check Record data in Simulation Data Inspector.

  3. Check Open viewer after simulation.

  4. Un-check Limit data points.

When the data are recorded in the Simulation Data Inspector, they are saved there under the block name and port. For example, in a test harness saved as sscfluids_4_way_3_position_valve.slx, the mass flow rate in the valve block between ports P and B is saved as a signal as simlog_sscfluids_4_way_3_position_valve.valve.orifice_PB.mdot_A.

When Record data in Simulation Data Inspector is left unchecked, the results are saved as a Series object under the simlog variable. For example, the time series for the mass flow rate through the P-B orifice of the valve block is saved as a series as simlog_sscfluids_4_way_3_position_valve.valve.orifice_PB.mdot_A.series.values. For more information, see simscape.logging.Series.

After you enable logging, run the live script.

Assess Model Results

  1. Import your validating data.

    • Click Import. Select Import From and navigate to the pressure timeseries data Mass Flow Rate PB. The import pane displays timeseries data currently in your workspace.

    • In the To section, ensure that New run is selected and that the time series data Mass Flow Rate PB is checked. Click Import.

  2. In the left-hand pane, click Compare.

  3. Set Baseline to Signals > Mass Flow Rate PB.

  4. Set Compare to to Signals > simlog_sscfluids_4_way_3_position_valve.valve.orifice_PB.mdot_A (Run 1: 4_way_3_position_valve). This run contains the signal data from when the P-B orifice is in open in the positive and neutral positions.

  5. The tolerance of your comparison is the precision to which you can validate your model. Depending on the size of a signal, the Simulation Data Inspector uses either the relative or the absolute tolerance for validation:

    • Global absolute tolerance signifies the overall absolute range of acceptable variation between data and a simulation point. This tolerance is applied when the signal is small.

    • Global relative tolerance signifies the maximum acceptable difference between data and a simulation point. This tolerance is applied when the signal is large.

    • Global time tolerance signifies the range in time one value can be compared to another.

    The absolute and relative tolerances should be equal to or larger than the solver tolerance. In this example, set the absolute and relative tolerances to 0.03 and set the time tolerance to 0. A nonzero time tolerance value is useful when you expect an impulse response during simulation.

  6. Click Compare. The simulation and data appear with the tolerance bounding lines:

Plot of out-of-tolerance simulation results in the SDI

With global and absolute tolerances of 0.03, the linear model is out of tolerance with the data. When the simulation results are fully within the green band limits, the valve is validated for the tested range of the simulation. The shape of the error suggests that it isn't the most suitable model for the application.

The default parameterization of sscfluids_4_way_3_position_valve is the same tabulated data as the specification sheet. To see a model in the Simulation Data Inspector that is fully in tolerance, change the parameterization at line 26 in the live script back to:

% Setting parameters from Orifice parameterization dropdown
Run the script again and set Compare to to the new run. The error trends shows that this is the correct model for the application, and the results are within tolerance:

Plot of in-tolerance simulation results in the SDI

However, the slight error offset suggests that some tuning would improve the model accuracy.

Related Topics