Search in sources :

Example 61 with Unit

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

the class VolumeFlowRateValidatorTest method valid.

@Test
public void valid() {
    ModelDescription modelDescription = new ModelDescription();
    VolumeFlowRate volumeFlowRate = new VolumeFlowRate();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.INPUT);
    v1.setType(Variable.Type.REAL);
    v1.setUnit(new Unit());
    Variable v2 = new Variable();
    v2.setCausality(v1.getCausality());
    v2.setType(v1.getType());
    v2.setUnit(v1.getUnit());
    volumeFlowRate.setVariables(Arrays.asList(v1, v2));
    modelDescription.getVolumeFlowRates().add(volumeFlowRate);
    VolumeFlowRateValidator v = new VolumeFlowRateValidator();
    List<ValidationDiagnostic<VolumeFlowRate>> diagnostics = v.validate(modelDescription);
    assertTrue(diagnostics.isEmpty());
}
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)

Example 62 with Unit

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

the class VE_VolumeFlowRate_3_Test method invalid.

@Test
public void invalid() {
    VolumeFlowRate volumeFlowRate = new VolumeFlowRate();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.INPUT);
    v1.setType(Variable.Type.REAL);
    v1.setUnit(new Unit());
    Variable v2 = new Variable();
    v2.setCausality(v1.getCausality());
    v2.setType(v1.getType());
    Unit u = new Unit();
    u.setExponent(Unit.Exponent.KILOGRAM, 1);
    v2.setUnit(u);
    volumeFlowRate.setVariables(Arrays.asList(v1, v2));
    builder.build(volumeFlowRate);
    builder.complete();
    List<ValidationDiagnostic<VolumeFlowRate>> diagnostics = validationError.validate();
    assertEquals(1, diagnostics.size());
    VolumeFlowRate invalidObject = diagnostics.get(0).getValidatedObject();
    List<Variable> variables = invalidObject.getVariables();
    assertTrue(variables.contains(v1));
    assertTrue(variables.contains(v2));
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) VolumeFlowRate(com.opensimulationplatform.core.model.modeldescription.variablegroup.volumeflowrate.VolumeFlowRate) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Test(org.junit.Test)

Example 63 with Unit

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

the class VariableTypeConverterTest method canConvert.

@Test
public void canConvert() {
    ConverterContext converterContext = new ConverterContext();
    Variable v = new Variable();
    v.setName("variableName");
    converterContext.modelDescription.getVariables().add(v);
    Unit u = new Unit();
    u.setName("unitName");
    converterContext.modelDescription.getUnits().add(u);
    VariableType variableType = new VariableType();
    variableType.setRef(v.getName().get());
    variableType.setUnit(u.getName().get());
    VariableTypeConverter variableTypeConverter = new VariableTypeConverter(converterContext);
    Variable variable = variableTypeConverter.convert(variableType);
    assertEquals(v, variable);
    assertEquals(u, variable.getUnit());
}
Also used : ConverterContext(com.opensimulationplatform.modeldescription.xml.converter.ConverterContext) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) VariableType(com.opensimulationplatform.modeldescription.xml.model.VariableType) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Test(org.junit.Test)

Example 64 with Unit

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

the class UnitTypeConverter method convert.

@Override
public Unit convert(UnitType unitType) {
    Unit unit = new Unit();
    unit.setName(unitType.getName());
    Fmi2Unit.BaseUnit baseUnit = unitType.getBaseUnit();
    unit.setFactor(baseUnit.getFactor());
    unit.setOffset(baseUnit.getOffset());
    unit.setExponent(KILOGRAM, baseUnit.getKg());
    unit.setExponent(METER, baseUnit.getM());
    unit.setExponent(SECOND, baseUnit.getS());
    unit.setExponent(AMPERE, baseUnit.getA());
    unit.setExponent(KELVIN, baseUnit.getK());
    unit.setExponent(MOL, baseUnit.getMol());
    unit.setExponent(CANDELA, baseUnit.getCd());
    unit.setExponent(RADIAN, baseUnit.getRad());
    unit.setExponent(PERCENT, baseUnit.getPercent());
    return unit;
}
Also used : Fmi2Unit(com.opensimulationplatform.modeldescription.xml.model.Fmi2Unit) Fmi2Unit(com.opensimulationplatform.modeldescription.xml.model.Fmi2Unit) Unit(com.opensimulationplatform.core.model.modeldescription.Unit)

Example 65 with Unit

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

the class VE_AngularDisplacement_3_Test method valid.

@Test
public void valid() {
    AngularDisplacement angularDisplacement = new AngularDisplacement();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.INPUT);
    v1.setType(Variable.Type.REAL);
    v1.setUnit(new Unit());
    Variable v2 = new Variable();
    v2.setCausality(v1.getCausality());
    v2.setType(v1.getType());
    v2.setUnit(v1.getUnit());
    angularDisplacement.setVariables(Arrays.asList(v1, v2));
    builder.build(angularDisplacement);
    builder.complete();
    List<ValidationDiagnostic<AngularDisplacement>> diagnostics = validationError.validate();
    assertTrue(diagnostics.isEmpty());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) AngularDisplacement(com.opensimulationplatform.core.model.modeldescription.variablegroup.angulardisplacement.AngularDisplacement) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Test(org.junit.Test)

Aggregations

Unit (com.opensimulationplatform.core.model.modeldescription.Unit)149 Variable (com.opensimulationplatform.core.model.modeldescription.Variable)145 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)137 Test (org.junit.Test)137 ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)35 Force (com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force)21 LinearVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity)16 Pressure (com.opensimulationplatform.core.model.modeldescription.variablegroup.pressure.Pressure)13 Torque (com.opensimulationplatform.core.model.modeldescription.variablegroup.torque.Torque)13 Voltage (com.opensimulationplatform.core.model.modeldescription.variablegroup.voltage.Voltage)13 AngularDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.angulardisplacement.AngularDisplacement)11 AngularVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.angularvelocity.AngularVelocity)11 Charge (com.opensimulationplatform.core.model.modeldescription.variablegroup.charge.Charge)11 Current (com.opensimulationplatform.core.model.modeldescription.variablegroup.current.Current)11 LinearDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.lineardisplacement.LinearDisplacement)11 Volume (com.opensimulationplatform.core.model.modeldescription.variablegroup.volume.Volume)11 VolumeFlowRate (com.opensimulationplatform.core.model.modeldescription.variablegroup.volumeflowrate.VolumeFlowRate)11 AngularAcceleration (com.opensimulationplatform.core.model.modeldescription.variablegroup.angularacceleration.AngularAcceleration)9 LinearAcceleration (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearacceleration.LinearAcceleration)9 LinearMechanicalPort (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort)7