|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: "OSP validator" |
| 4 | +permalink: /osp-validator |
| 5 | +has_toc: false |
| 6 | +nav_order: 6 |
| 7 | +--- |
| 8 | +<div style="text-align: right"> |
| 9 | + <b> |
| 10 | + <a href="https://github.com/open-simulation-platform/osp-validator">osp-validator</a> |
| 11 | + on GitHub |
| 12 | + </b> |
| 13 | +</div> |
| 14 | + |
| 15 | +# OSP validator |
| 16 | + |
| 17 | +The [osp-validator](https://github.com/open-simulation-platform/osp-validator) repository implements a java library and |
| 18 | +command line interface which validates an FMU with accompanying `OspModelDescription.xml` file, according to the |
| 19 | +[OSP-IS](/url/to/osp-is/document) standard. It also validates a simulation configuration as specified by a |
| 20 | +`OspSystemStructure.xml` file. |
| 21 | + |
| 22 | +## Java library |
| 23 | +The java library is accessed through the jar file `osp-validator-api-<version>.jar`, which is found in specific releases |
| 24 | +of the `osp-validator` repository, or produced when building the project. |
| 25 | + |
| 26 | +The java library can be used by simulation configuration tools which needs to validate that the models and configuration |
| 27 | +is according to OSP-IS. The [kopl](/url/to/kopl/documentation) configuration tool uses this library for validation. |
| 28 | + |
| 29 | +Examples showing how it can be used in a java application can be found [here](/url/to/examples/in/osp-validator/repo) |
| 30 | + |
| 31 | +## Command line interface |
| 32 | +A command line tool to interface the validator called `osp-cli.jar` is produced when building the `osp-validator` |
| 33 | +project, and it is available in every release. The command line inteface tool can be used to verify that a given |
| 34 | +`OspModelDescription.xml` and FMU is according to the OSP-IS, and it can also validate simulation configurations |
| 35 | +defined by a `OspSystemStructure.xml` file. If there are no validation errors the output is empty. In case there are |
| 36 | +validation errors, it will print error messages for all the violated rules. |
| 37 | + |
| 38 | +Calling the `osp-cli.jar` without any input arguments prints out usage help: |
| 39 | +``` |
| 40 | +$ java -jar osp-cli.jar |
| 41 | +Usage: msmi-cli.jar [options] [command] [command options] |
| 42 | + Options: |
| 43 | + --help, -h |
| 44 | + Print help |
| 45 | + --version, -v |
| 46 | + Print version |
| 47 | + Commands: |
| 48 | + osp-system-structure Validate OspSystemStructure.xml |
| 49 | + Usage: osp-system-structure [options] |
| 50 | + Options: |
| 51 | + -file |
| 52 | + Path to OspSystemStructure.xml |
| 53 | +
|
| 54 | + osp-model-description Validate OspModelDescription.xml |
| 55 | + Usage: osp-model-description [options] |
| 56 | + Options: |
| 57 | + -file |
| 58 | + Path to OspModelDescription.xml |
| 59 | + -fmu |
| 60 | + Path to fmu |
| 61 | +``` |
| 62 | + |
| 63 | +### Usage example |
| 64 | +The .xml files shown below, which represents a valid configuration, can be validated with `osp-cli.jar` as follows: |
| 65 | + |
| 66 | +``` |
| 67 | +$ java -jar osp-cli.jar osp-system-structure -file OspSystemStructure.xml |
| 68 | +``` |
| 69 | + |
| 70 | +This produces no output, meaning all models, and the configuration itself is valid according to |
| 71 | +OSP-IS. If we change the line `<VariableGroup simulator="crane_controller" name="linear_mechanical_port"/>` in |
| 72 | +`OspSystemStructure.xml` to `<VariableGroup simulator="crane_controller" name="force"/>` and run the validation again, |
| 73 | +we see that the validator prints out an error message associated with the violated rules, and accompanying line |
| 74 | +number for where the error is: |
| 75 | + |
| 76 | +``` |
| 77 | +$ java -jar osp-cli.jar osp-system-structure -file OspSystemStructure.xml |
| 78 | +Validation error in OspSystemStructure.xml on line 11: |
| 79 | +VariableGroupConnection [crane_controller.force, knuckle_boom_crane.linear_mechanical_port] is invalid |
| 80 | +because they have different types [Force, LinearMechanicalPort] |
| 81 | +``` |
| 82 | + |
| 83 | +### Example XML files |
| 84 | +`CraneController_OspModelDescription.xml` |
| 85 | +```xml |
| 86 | +<?xml version="1.0" encoding="utf-8" ?> |
| 87 | +<OspModelDescription xmlns="http://opensimulationplatform.com/osp-is/OSPModelDescription" version="1.0"> |
| 88 | + <VariableGroups> |
| 89 | + <Generic name="actuator_limits"> |
| 90 | + <Variable ref="Act_Limits[1]"/> |
| 91 | + <Variable ref="Act_Limits[2]"/> |
| 92 | + <Variable ref="Act_Limits[3]"/> |
| 93 | + </Generic> |
| 94 | + <LinearMechanicalPort name="linear_mechanical_port"> |
| 95 | + <Force name="force"> |
| 96 | + <Variable ref="p_Crane.e[1]"/> |
| 97 | + <Variable ref="p_Crane.e[2]"/> |
| 98 | + <Variable ref="p_Crane.e[3]"/> |
| 99 | + </Force> |
| 100 | + <LinearVelocity name="linear_velocity"> |
| 101 | + <Variable ref="p_Crane.f[1]"/> |
| 102 | + <Variable ref="p_Crane.f[2]"/> |
| 103 | + <Variable ref="p_Crane.f[3]"/> |
| 104 | + </LinearVelocity> |
| 105 | + </LinearMechanicalPort> |
| 106 | + </VariableGroups> |
| 107 | +</OspModelDescription> |
| 108 | +``` |
| 109 | + |
| 110 | +`KnuckleBoomCrane_OspModelDescription.xml` |
| 111 | +```xml |
| 112 | +<?xml version="1.0" encoding="utf-8" ?> |
| 113 | +<OspModelDescription xmlns="http://opensimulationplatform.com/osp-is/OSPModelDescription" version="1.0"> |
| 114 | + <VariableGroups> |
| 115 | + <Generic name="actuator_limits"> |
| 116 | + <Variable ref="Act_Limits[1]"/> |
| 117 | + <Variable ref="Act_Limits[2]"/> |
| 118 | + <Variable ref="Act_Limits[3]"/> |
| 119 | + </Generic> |
| 120 | + <LinearMechanicalPort name="linear_mechanical_port"> |
| 121 | + <Force name="force"> |
| 122 | + <Variable ref="p_Crane.e[1]"/> |
| 123 | + <Variable ref="p_Crane.e[2]"/> |
| 124 | + <Variable ref="p_Crane.e[3]"/> |
| 125 | + </Force> |
| 126 | + <LinearVelocity name="linear_velocity"> |
| 127 | + <Variable ref="p_Crane.f[1]"/> |
| 128 | + <Variable ref="p_Crane.f[2]"/> |
| 129 | + <Variable ref="p_Crane.f[3]"/> |
| 130 | + </LinearVelocity> |
| 131 | + </LinearMechanicalPort> |
| 132 | + </VariableGroups> |
| 133 | +</OspModelDescription> |
| 134 | +``` |
| 135 | + |
| 136 | +`OspSystemStructure.xml` |
| 137 | +```xml |
| 138 | +<OspSystemStructure version="0.1" xmlns="http://opensimulationplatform.com/MSMI/OSPSystemStructure"> |
| 139 | + <Simulators> |
| 140 | + <Simulator name="crane_controller" source="CraneController.fmu" stepSize="1.051732E7"/> |
| 141 | + <Simulator name="knuckle_boom_crane" source="KnuckleBoomCrane.fmu" stepSize="1.051732E7"/> |
| 142 | + </Simulators> |
| 143 | + <Connections> |
| 144 | + <VariableConnection> |
| 145 | + <Variable simulator="crane_controller" name="Act_Limits[1]"/> |
| 146 | + <Variable simulator="knuckle_boom_crane" name="Act_Limits[1]"/> |
| 147 | + </VariableConnection> |
| 148 | + <VariableGroupConnection> |
| 149 | + <VariableGroup simulator="crane_controller" name="linear_mechanical_port"/> |
| 150 | + <VariableGroup simulator="knuckle_boom_crane" name="linear_mechanical_port"/> |
| 151 | + </VariableGroupConnection> |
| 152 | + </Connections> |
| 153 | +</OspSystemStructure> |
| 154 | +``` |
0 commit comments