Hopsan
Model and Component Regression Testing

When you have finished a component and/or model and you are satisfied with the simulation results you can save you model and some of the simulation results as a test model. You can later run this model again and automatically compare the simulation results. This is very important if you want to make sure that your component and models do not change their behaviour when new versions of Hopsan are released. Remember that if you want to make new changes (that affect simulation results) in the modeled component, your validation data must be recreated.

How to Create a Validation Model in Hopsan CLI

The HopsanCLI can automatically create a validation data set based on all scopes in your model. If no scopes are available, no data set will be created.

  1. Use the HopsanCLI (Hopsan CommandLineInterface) with the -m and –createValidationData switches according to the following examples:
    The -d (destination directory) switch is optional
    1. Windows: hopsancli.exe -m pathto\ExampleModel.hmf –createValidationData -d outputDirectoryPath
    2. Ubuntu: ./hopsancli -m pathto/ExampleModel.hmf –createValidationData -d outputDirectoryPath
  2. Store the model, dataset and hvc file in a safe place.

How to Create a Validation Model in Hopsan GUI

  1. Open your model in HopsanGUI and simulate it.
    1. Add the variables (from ports) that you want to use as validation data to a plot window.
    2. Export the data as hvc, hvd (Hopsan Validation Configuration and Data) files.
  2. The generated hvc file contains default entries. You may want to manually edit it, see format description below.
  3. Store the model, dataset and hvc file in a safe place.

How to Test a Validation Model in Hopsan CLI

  1. Use the HopsanCLI (Hopsan CommandLineInterface) with the -t (for test) switch according to:
    1. Windows: hopsancli.exe -t "MyHVCFile.hvc"
    2. Ubuntu: ./hopsancli -t "MyHVCFile.hvc"
  2. If you want to automatically test multiple models, then you should write a script that goes through all of your hvc files.

How to Test a Validation Model in Hopsan GUI

  1. Open the Model Validation Widget in the Tools menu.
    1. Load your Hopsan Validation Configuration .hvc file. The widget will show you what variables will be tested.
    2. Note! The widget is not yet fully implemented but you can compare data
    3. Click the compare button to simulate the model and generate plots comparing the data. You must manually check the data to make sure that the simulated result is the same as the validation data.

The HVC (Hopsan Validation Configuration) Format

This is an example HVC File. Note that you can have multiple <validation> and <variable> tags to perform multiple tests from the same configuration file.

<?xml version="1.0" encoding="UTF-8"?>
<hopsanvalidationconfiguration hvcversion="0.2">
    <validation hopsancliversion="0.6.x_r6964" time="141140" date="20140430" hopsancoreversion="0.6.x_r6964">
        <!--Optional path to model file, if not specified the same name (excluding suffix) and path as this file will be used-->
        <modelfile>../Example Models/Position Servo.hmf</modelfile>
        <!--<parameterset>Not yet supported!</parameterset>-->
        <!--Optional path to Hopsan validation data file, if not specified the same name (excluding suffix) and path as this file will be used-->
        <hvdfile>Position Servo.hvd</hvdfile>
        <!-- The name attribute contains the full name including subsystem hierarchy. Ex: System$Subsystem$Component#Port#Variable -->
        <variable name="Position_Servo$Position_Sensor#out#Value">
            <!--The time column in the hvd file for this variable. Column indexing begins at 0-->
            <timecolumn>0</timecolumn>
            <!--The data column in the hvd file for this variable. Column indexing begins at 0-->
            <column>1</column>
            <!--Tolerance, allowed deviation 0.01==1%-->
            <tolerance>0.01</tolerance>
        </variable>
        <variable name="Position_Servo$Step#out#Value">
            <timecolumn>0</timecolumn>
            <column>2</column>
            <tolerance>0.01</tolerance>
        </variable>
        <variable name="Position_Servo$4_3_Servo_Valve#xv#Value">
            <timecolumn>0</timecolumn>
            <column>3</column>
            <tolerance>0.01</tolerance>
        </variable>
        <variable name="Position_Servo$Pressure_Relief_Valve#xv#Value">
            <timecolumn>0</timecolumn>
            <column>4</column>
            <tolerance>0.01</tolerance>
        </variable>
    </validation>
</hopsanvalidationconfiguration>