Search in sources :

Example 66 with ModelDescription

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

the class ValidateOspModelDescriptionFile method main.

public static void main(String[] args) throws URISyntaxException {
    File ospModelDescriptionFile = new File("/path/to/OspModelDescription.xml");
    URI fmu = new URI("file:///path/to/model.fmu");
    ModelDescriptionFactory factory = new ModelDescriptionFactory();
    ModelDescription modelDescription = factory.create(ospModelDescriptionFile, fmu);
    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 : ModelDescriptionFactory(com.opensimulationplatform.modeldescription.xml.factory.ModelDescriptionFactory) ModelDescriptionValidator(com.opensimulationplatform.core.validation.modeldescription.ModelDescriptionValidator) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) File(java.io.File) URI(java.net.URI)

Example 67 with ModelDescription

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

the class OspModelDescriptionTypeConverterTest method canConvert.

@Test
public void canConvert() {
    ConverterContext converterContext = getConverterContext();
    OspModelDescriptionType ospModelDescriptionType = getOspModelDescriptionType();
    OspModelDescriptionTypeConverter ospModelDescriptionTypeConverter = new OspModelDescriptionTypeConverter(converterContext);
    ModelDescription modelDescription = ospModelDescriptionTypeConverter.convert(ospModelDescriptionType);
    assertEquals(1, modelDescription.getVariables().size());
    assertEquals(2, modelDescription.getUnits().size());
    assertEquals(1, modelDescription.getGenerics().size());
    assertEquals(3, modelDescription.getForces().size());
    assertEquals(3, modelDescription.getTorques().size());
    assertEquals(3, modelDescription.getVoltages().size());
    assertEquals(3, modelDescription.getPressures().size());
    assertEquals(2, modelDescription.getLinearVelocities().size());
    assertEquals(2, modelDescription.getAngularVelocities().size());
    assertEquals(2, modelDescription.getCurrents().size());
    assertEquals(2, modelDescription.getVolumeFlowRates().size());
    assertEquals(2, modelDescription.getLinearDisplacements().size());
    assertEquals(2, modelDescription.getAngularDisplacements().size());
    assertEquals(2, modelDescription.getCharges().size());
    assertEquals(2, modelDescription.getVolumes().size());
    assertEquals(1, modelDescription.getLinearMechanicalPorts().size());
    assertEquals(1, modelDescription.getAngularMechanicalPorts().size());
    assertEquals(1, modelDescription.getElectromagneticPorts().size());
    assertEquals(1, modelDescription.getHydraulicPorts().size());
    assertEquals(1, modelDescription.getLinearMechanicalQuasiPorts().size());
    assertEquals(1, modelDescription.getAngularMechanicalQuasiPorts().size());
    assertEquals(1, modelDescription.getElectromagneticQuasiPorts().size());
    assertEquals(1, modelDescription.getHydraulicQuasiPorts().size());
}
Also used : ConverterContext(com.opensimulationplatform.modeldescription.xml.converter.ConverterContext) FmiModelDescription(com.opensimulationplatform.modeldescription.util.FmiModelDescription) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Test(org.junit.Test)

Example 68 with ModelDescription

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

the class VolumeFlowRateValidatorTest method invalid.

@Test
public void invalid() {
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.INPUT);
    v1.setType(Variable.Type.REAL);
    v1.setUnit(new Unit());
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.OUTPUT);
    v2.setType(Variable.Type.INTEGER);
    Unit unit = new Unit();
    unit.setExponent(Unit.Exponent.KILOGRAM, 1);
    v2.setUnit(unit);
    VolumeFlowRate volumeFlowRate = new VolumeFlowRate();
    volumeFlowRate.setVariables(Arrays.asList(v1, v2));
    modelDescription.getVolumeFlowRates().add(volumeFlowRate);
    VolumeFlowRateValidator v = new VolumeFlowRateValidator();
    List<ValidationDiagnostic<VolumeFlowRate>> diagnostics = v.validate(modelDescription);
    assertEquals(3, diagnostics.size());
    for (ValidationDiagnostic<VolumeFlowRate> diagnostic : diagnostics) {
        assertEquals(volumeFlowRate, diagnostic.getValidatedObject());
    }
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) VolumeFlowRate(com.opensimulationplatform.core.model.modeldescription.variablegroup.volumeflowrate.VolumeFlowRate) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) 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