Search in sources :

Example 1 with ModelDescription

use of com.opensimulationplatform.core.model.modeldescription.ModelDescription in project osp-validator by open-simulation-platform.

the class ValidateModelDescriptionDataModel method main.

public static void main(String[] args) {
    ModelDescription modelDescription = new ModelDescription();
    Unit unit = new Unit();
    unit.setExponent(Unit.Exponent.KILOGRAM, 1);
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.OUTPUT);
    v1.setType(Variable.Type.REAL);
    v1.setName("v1");
    v1.setUnit(unit);
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.OUTPUT);
    v2.setType(Variable.Type.REAL);
    v2.setName("v2");
    v2.setUnit(unit);
    Variable v3 = new Variable();
    v3.setCausality(Variable.Causality.INPUT);
    v3.setType(Variable.Type.REAL);
    v3.setName("v3");
    v3.setUnit(unit);
    Variable v4 = new Variable();
    v4.setCausality(Variable.Causality.INPUT);
    v4.setType(Variable.Type.REAL);
    v4.setName("v4");
    v4.setUnit(unit);
    Force force = new Force();
    force.setName("force");
    force.setVariables(Arrays.asList(v1, v2));
    LinearVelocity linearVelocity = new LinearVelocity();
    linearVelocity.setName("linearVelocity");
    linearVelocity.setVariables(Arrays.asList(v3, v4));
    LinearMechanicalPort linearMechanicalPort = new LinearMechanicalPort();
    linearMechanicalPort.setName("linearMechanicalPort");
    linearMechanicalPort.setForce(force);
    linearMechanicalPort.setLinearVelocity(linearVelocity);
    modelDescription.getUnits().add(unit);
    modelDescription.getVariables().addAll(Arrays.asList(v1, v2, v3, v4));
    modelDescription.getForces().add(force);
    modelDescription.getLinearVelocities().add(linearVelocity);
    modelDescription.getLinearMechanicalPorts().add(linearMechanicalPort);
    ModelDescriptionValidator validator = new ModelDescriptionValidator();
    List<ValidationDiagnostic<Object>> diagnostics = validator.validate(modelDescription);
    for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
        System.out.println("Message: " + diagnostic.getErrorMessage());
        System.out.println("Object: " + diagnostic.getValidatedObject());
    }
}
Also used : LinearVelocity(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Force(com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force) ModelDescriptionValidator(com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator) LinearMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Unit(com.opensimulationplatform.core.model.modeldescription.Unit)

Example 2 with ModelDescription

use of com.opensimulationplatform.core.model.modeldescription.ModelDescription in project osp-validator by open-simulation-platform.

the class ValidateSystemStructureDataModel method getModelDescription.

private static ModelDescription getModelDescription(Variable.Causality causalityA, Variable.Causality causalityB) {
    ModelDescription modelDescription = new ModelDescription();
    Unit unit = new Unit();
    unit.setExponent(Unit.Exponent.KILOGRAM, 1);
    Variable v1 = new Variable();
    v1.setCausality(causalityA);
    v1.setType(Variable.Type.REAL);
    v1.setName("v1");
    v1.setUnit(unit);
    Variable v2 = new Variable();
    v2.setCausality(causalityA);
    v2.setType(Variable.Type.REAL);
    v2.setName("v2");
    v2.setUnit(unit);
    Variable v3 = new Variable();
    v3.setCausality(causalityB);
    v3.setType(Variable.Type.REAL);
    v3.setName("v3");
    v3.setUnit(unit);
    Variable v4 = new Variable();
    v4.setCausality(causalityB);
    v4.setType(Variable.Type.REAL);
    v4.setName("v4");
    v4.setUnit(unit);
    Variable v5 = new Variable();
    v5.setCausality(causalityA);
    v5.setType(Variable.Type.REAL);
    v5.setName("v5");
    v5.setUnit(unit);
    Force force = new Force();
    force.setName("force");
    force.setVariables(Arrays.asList(v1, v2));
    LinearVelocity linearVelocity = new LinearVelocity();
    linearVelocity.setName("linearVelocity");
    linearVelocity.setVariables(Arrays.asList(v3, v4));
    LinearMechanicalPort linearMechanicalPort = new LinearMechanicalPort();
    linearMechanicalPort.setName("linearMechanicalPort");
    linearMechanicalPort.setForce(force);
    linearMechanicalPort.setLinearVelocity(linearVelocity);
    modelDescription.getUnits().add(unit);
    modelDescription.getVariables().addAll(Arrays.asList(v1, v2, v3, v4, v5));
    modelDescription.getForces().add(force);
    modelDescription.getLinearVelocities().add(linearVelocity);
    modelDescription.getLinearMechanicalPorts().add(linearMechanicalPort);
    return modelDescription;
}
Also used : LinearVelocity(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Force(com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force) LinearMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Unit(com.opensimulationplatform.core.model.modeldescription.Unit)

Example 3 with ModelDescription

use of com.opensimulationplatform.core.model.modeldescription.ModelDescription in project osp-validator by open-simulation-platform.

the class Validator method getModelDescriptionErrorMessages.

private List<String> getModelDescriptionErrorMessages(File ospSystemStructureFile, OspSystemStructure ospSystemStructureElement) {
    List<String> errorMessages = new ArrayList<>();
    for (Simulators.Simulator simulator : ospSystemStructureElement.getSimulators().getSimulator()) {
        FmuLocator fmuLocator = new DefaultFmuLocator(ospSystemStructureFile);
        URI fmu = fmuLocator.get(simulator);
        OspModelDescriptionLocator ospModelDescriptionLocator = new DefaultOspModelDescriptionLocator(ospSystemStructureFile, fmuLocator);
        Optional<File> ospModelDescriptionXml = ospModelDescriptionLocator.get(simulator);
        if (ospModelDescriptionXml.isPresent()) {
            OspModelDescriptionParser parser = new OspModelDescriptionParser();
            OspModelDescriptionType ospModelDescriptionElement = parser.parse(ospModelDescriptionXml.get());
            Map<Object, Location> locations = parser.getLocations();
            ModelDescriptionFactory factory = new ModelDescriptionFactory();
            ModelDescription modelDescription = factory.create(ospModelDescriptionXml.get(), fmu);
            Simulator s = new Simulator();
            s.setName(simulator.getName());
            s.setModelDescription(modelDescription);
            SystemStructure systemStructure = new SystemStructure();
            systemStructure.getSimulators().add(s);
            ModelDescriptionValidator validator = new ModelDescriptionValidator();
            List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
            Map<Object, Object> coreToJaxb = createModelDescriptionMap(ospModelDescriptionElement, modelDescription);
            errorMessages.addAll(getErrorMessages(ospModelDescriptionXml.get(), locations, diagnostics, coreToJaxb));
        }
    }
    return errorMessages;
}
Also used : ModelDescriptionFactory(com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory) OspSystemStructure(com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) URI(java.net.URI) OspModelDescriptionParser(com.opensimulationplatform.modeldescription.xml.parser.OspModelDescriptionParser) DefaultFmuLocator(com.opensimulationplatform.systemstructure.util.DefaultFmuLocator) FmuLocator(com.opensimulationplatform.systemstructure.util.FmuLocator) ModelDescriptionValidator(com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Simulators(com.opensimulationplatform.systemstructure.xml.model.Simulators) DefaultOspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator) OspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.OspModelDescriptionLocator) DefaultOspModelDescriptionLocator(com.opensimulationplatform.systemstructure.util.DefaultOspModelDescriptionLocator) DefaultFmuLocator(com.opensimulationplatform.systemstructure.util.DefaultFmuLocator) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) File(java.io.File) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Location(javax.xml.stream.Location)

Example 4 with ModelDescription

use of com.opensimulationplatform.core.model.modeldescription.ModelDescription in project osp-validator by open-simulation-platform.

the class SimulatorsValidatorTest method invalid.

@Test
public void invalid() {
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.UNDEFINED);
    v1.setType(Variable.Type.REAL);
    v1.setName("not-unique");
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.INPUT);
    v2.setType(Variable.Type.INTEGER);
    v2.setName("not-unique");
    modelDescription.getVariables().add(v1);
    modelDescription.getVariables().add(v2);
    Generic g = new Generic();
    g.setName("variable-container");
    g.setVariables(Arrays.asList(v1, v2));
    modelDescription.getGenerics().add(g);
    Force f1 = new Force();
    f1.setName("not-unique");
    Variable v3 = new Variable();
    v3.setName("v3");
    v3.setType(Variable.Type.REAL);
    v3.setCausality(Variable.Causality.OUTPUT);
    f1.setVariables(Arrays.asList(v3));
    Force f2 = new Force();
    f2.setName("not-unique");
    Variable v4 = new Variable();
    v4.setName("v4");
    v4.setType(Variable.Type.INTEGER);
    v4.setCausality(Variable.Causality.INPUT);
    f2.setVariables(Arrays.asList(v4));
    modelDescription.getForces().add(f1);
    modelDescription.getForces().add(f2);
    Variable v5 = new Variable();
    v5.setName("v5");
    v5.setCausality(Variable.Causality.OUTPUT);
    v5.setType(Variable.Type.REAL);
    Variable v6 = new Variable();
    v6.setName("v6");
    v6.setCausality(Variable.Causality.INPUT);
    v6.setType(Variable.Type.REAL);
    Force f3 = new Force();
    f3.setName("f3");
    f3.setVariables(Arrays.asList(v5, v6));
    modelDescription.getForces().add(f3);
    Variable v7 = new Variable();
    v7.setName("v7");
    v7.setCausality(Variable.Causality.OUTPUT);
    v7.setType(Variable.Type.REAL);
    Variable v8 = new Variable();
    v8.setName("v8");
    v8.setCausality(Variable.Causality.OUTPUT);
    v8.setType(Variable.Type.REAL);
    Force f4 = new Force();
    f4.setName("f4");
    f4.setVariables(Arrays.asList(v7, v8));
    Variable v9 = new Variable();
    v9.setName("v9");
    v9.setCausality(Variable.Causality.OUTPUT);
    v9.setType(Variable.Type.REAL);
    Variable v10 = new Variable();
    v10.setName("v10");
    v10.setCausality(Variable.Causality.OUTPUT);
    v10.setType(Variable.Type.REAL);
    LinearVelocity lv1 = new LinearVelocity();
    lv1.setName("lv1");
    lv1.setVariables(Arrays.asList(v9, v10));
    LinearMechanicalPort lmp1 = new LinearMechanicalPort();
    lmp1.setName("lmp1");
    lmp1.setForce(f4);
    lmp1.setLinearVelocity(lv1);
    modelDescription.getLinearMechanicalPorts().add(lmp1);
    Simulator s1 = new Simulator();
    s1.setName("not-unique");
    s1.setModelDescription(modelDescription);
    Simulator s2 = new Simulator();
    s2.setName("not-unique");
    s2.setModelDescription(modelDescription);
    SystemStructure systemStructure = new SystemStructure();
    systemStructure.getSimulators().add(s1);
    systemStructure.getSimulators().add(s2);
    SimulatorsValidator v = new SimulatorsValidator();
    List<ValidationDiagnostic<Object>> diagnostics = v.validate(systemStructure);
    assertEquals(13, diagnostics.size());
}
Also used : LinearVelocity(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Force(com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) Generic(com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic) LinearMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Example 5 with ModelDescription

use of com.opensimulationplatform.core.model.modeldescription.ModelDescription in project osp-validator by open-simulation-platform.

the class SimulatorsValidatorTest method valid.

@Test
public void valid() {
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.OUTPUT);
    v1.setType(Variable.Type.REAL);
    v1.setName("v1");
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.INPUT);
    v2.setType(Variable.Type.INTEGER);
    v2.setName("v2");
    modelDescription.getVariables().add(v1);
    modelDescription.getVariables().add(v2);
    Generic g = new Generic();
    g.setName("variable-container");
    g.setVariables(Arrays.asList(v1, v2));
    modelDescription.getGenerics().add(g);
    Force f1 = new Force();
    f1.setName("f1");
    Variable v3 = new Variable();
    v3.setName("v3");
    v3.setType(Variable.Type.REAL);
    v3.setCausality(Variable.Causality.OUTPUT);
    f1.setVariables(Arrays.asList(v3));
    Force f2 = new Force();
    f2.setName("f2");
    Variable v4 = new Variable();
    v4.setName("v4");
    v4.setType(Variable.Type.INTEGER);
    v4.setCausality(Variable.Causality.INPUT);
    f2.setVariables(Arrays.asList(v4));
    modelDescription.getForces().add(f1);
    modelDescription.getForces().add(f2);
    Variable v5 = new Variable();
    v5.setName("v5");
    v5.setCausality(Variable.Causality.OUTPUT);
    v5.setType(Variable.Type.REAL);
    Variable v6 = new Variable();
    v6.setName("v6");
    v6.setCausality(Variable.Causality.OUTPUT);
    v6.setType(Variable.Type.REAL);
    Force f3 = new Force();
    f3.setName("f3");
    f3.setVariables(Arrays.asList(v5, v6));
    modelDescription.getForces().add(f3);
    Variable v7 = new Variable();
    v7.setName("v7");
    v7.setCausality(Variable.Causality.OUTPUT);
    v7.setType(Variable.Type.REAL);
    Variable v8 = new Variable();
    v8.setName("v8");
    v8.setCausality(Variable.Causality.OUTPUT);
    v8.setType(Variable.Type.REAL);
    Force f4 = new Force();
    f4.setName("f4");
    f4.setVariables(Arrays.asList(v7, v8));
    Variable v9 = new Variable();
    v9.setName("v9");
    v9.setCausality(Variable.Causality.INPUT);
    v9.setType(Variable.Type.REAL);
    Variable v10 = new Variable();
    v10.setName("v10");
    v10.setCausality(Variable.Causality.INPUT);
    v10.setType(Variable.Type.REAL);
    LinearVelocity lv1 = new LinearVelocity();
    lv1.setName("lv1");
    lv1.setVariables(Arrays.asList(v9, v10));
    LinearMechanicalPort lmp1 = new LinearMechanicalPort();
    lmp1.setName("lmp1");
    lmp1.setForce(f4);
    lmp1.setLinearVelocity(lv1);
    modelDescription.getLinearMechanicalPorts().add(lmp1);
    Simulator s1 = new Simulator();
    s1.setName("s1");
    s1.setModelDescription(modelDescription);
    Simulator s2 = new Simulator();
    s2.setName("s2");
    s2.setModelDescription(modelDescription);
    SystemStructure systemStructure = new SystemStructure();
    systemStructure.getSimulators().add(s1);
    systemStructure.getSimulators().add(s2);
    SimulatorsValidator v = new SimulatorsValidator();
    List<ValidationDiagnostic<Object>> diagnostics = v.validate(systemStructure);
    assertTrue(diagnostics.isEmpty());
}
Also used : LinearVelocity(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Force(com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) Generic(com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic) LinearMechanicalPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Aggregations

ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)68 Variable (com.opensimulationplatform.core.model.modeldescription.Variable)61 Test (org.junit.Test)61 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)60 Unit (com.opensimulationplatform.core.model.modeldescription.Unit)35 Force (com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force)17 LinearVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity)13 LinearMechanicalPort (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort)12 Generic (com.opensimulationplatform.core.model.modeldescription.variablegroup.generic.Generic)9 Pressure (com.opensimulationplatform.core.model.modeldescription.variablegroup.pressure.Pressure)7 Torque (com.opensimulationplatform.core.model.modeldescription.variablegroup.torque.Torque)7 Voltage (com.opensimulationplatform.core.model.modeldescription.variablegroup.voltage.Voltage)7 AngularDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.angulardisplacement.AngularDisplacement)5 AngularVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.angularvelocity.AngularVelocity)5 Charge (com.opensimulationplatform.core.model.modeldescription.variablegroup.charge.Charge)5 Current (com.opensimulationplatform.core.model.modeldescription.variablegroup.current.Current)5 LinearDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.lineardisplacement.LinearDisplacement)5 Volume (com.opensimulationplatform.core.model.modeldescription.variablegroup.volume.Volume)5 VolumeFlowRate (com.opensimulationplatform.core.model.modeldescription.variablegroup.volumeflowrate.VolumeFlowRate)5 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)4