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