Search in sources :

Example 31 with Variable

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

the class VariableConnectionsValidatorTest method valid.

@Test
public void valid() {
    SystemStructure systemStructure = new SystemStructure();
    VariableConnection variableConnection = new VariableConnection();
    Simulator simulatorA = new Simulator();
    Variable variableA = new Variable();
    Unit unitA = new Unit();
    unitA.setExponent(Unit.Exponent.KILOGRAM, 1);
    variableA.setName("variableA");
    variableA.setUnit(unitA);
    variableA.setType(Variable.Type.REAL);
    variableA.setCausality(Variable.Causality.OUTPUT);
    simulatorA.getModelDescription().getVariables().add(variableA);
    variableConnection.setSimulatorA(simulatorA);
    variableConnection.setVariableA(variableA);
    Simulator simulatorB = new Simulator();
    Variable variableB = new Variable();
    Unit unitB = new Unit();
    unitB.setExponent(Unit.Exponent.KILOGRAM, 1);
    variableB.setName("variableB");
    variableB.setUnit(unitB);
    variableB.setType(Variable.Type.REAL);
    variableB.setCausality(Variable.Causality.INPUT);
    simulatorB.getModelDescription().getVariables().add(variableB);
    variableConnection.setSimulatorB(simulatorB);
    variableConnection.setVariableB(variableB);
    systemStructure.getSimulators().add(simulatorA);
    systemStructure.getSimulators().add(simulatorB);
    systemStructure.getVariableConnections().add(variableConnection);
    VariableConnectionsValidator validator = new VariableConnectionsValidator();
    List<ValidationDiagnostic<VariableConnection>> diagnostics = validator.validate(systemStructure);
    assertEquals(0, diagnostics.size());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Example 32 with Variable

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

the class VariableGroupsValidatorTest method invalid.

@Test
public void invalid() {
    ModelDescription modelDescription = new ModelDescription();
    Force f1 = new Force();
    Variable v1 = new Variable();
    Unit u1 = new Unit();
    u1.setExponent(Unit.Exponent.KILOGRAM, 1);
    v1.setUnit(u1);
    v1.setName("v1");
    v1.setType(Variable.Type.REAL);
    v1.setCausality(Variable.Causality.OUTPUT);
    Variable v2 = new Variable();
    Unit u2 = new Unit();
    u2.setExponent(Unit.Exponent.KILOGRAM, 2);
    v2.setUnit(u2);
    v2.setName("v2");
    v2.setType(Variable.Type.REAL);
    v2.setCausality(Variable.Causality.OUTPUT);
    f1.setVariables(Arrays.asList(v1, v2));
    f1.setName("f1");
    Force f2 = new Force();
    Variable v3 = new Variable();
    v3.setUnit(u1);
    v3.setName("v3");
    v3.setType(Variable.Type.REAL);
    v3.setCausality(Variable.Causality.OUTPUT);
    Variable v4 = new Variable();
    v4.setUnit(u1);
    v4.setName("v4");
    v4.setType(Variable.Type.INTEGER);
    v4.setCausality(Variable.Causality.OUTPUT);
    f2.setVariables(Arrays.asList(v3, v4));
    f2.setName("f2");
    Force f3 = new Force();
    Variable v5 = new Variable();
    v5.setUnit(u1);
    v5.setName("v5");
    v5.setType(Variable.Type.REAL);
    v5.setCausality(Variable.Causality.OUTPUT);
    Variable v6 = new Variable();
    v6.setUnit(u1);
    v6.setName("v6");
    v6.setType(Variable.Type.REAL);
    v6.setCausality(Variable.Causality.INPUT);
    f3.setVariables(Arrays.asList(v5, v6));
    f3.setName("f3");
    modelDescription.getVariables().add(v1);
    modelDescription.getVariables().add(v2);
    modelDescription.getVariables().add(v3);
    modelDescription.getVariables().add(v4);
    modelDescription.getVariables().add(v5);
    modelDescription.getVariables().add(v6);
    modelDescription.getUnits().add(u1);
    modelDescription.getUnits().add(u2);
    modelDescription.getForces().add(f1);
    modelDescription.getForces().add(f2);
    modelDescription.getForces().add(f3);
    VariableGroupsValidator v = new VariableGroupsValidator();
    List<ValidationDiagnostic<VariableGroup>> diagnostics = v.validate(modelDescription);
    assertEquals(3, diagnostics.size());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Force(com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force) 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 33 with Variable

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

the class ElectromagneticPortValidatorTest method valid.

@Test
public void valid() {
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.OUTPUT);
    Voltage voltage = new Voltage();
    voltage.setVariables(Arrays.asList(v1));
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.INPUT);
    Current current = new Current();
    current.setVariables(Arrays.asList(v2));
    ElectromagneticPort electromagneticPort = new ElectromagneticPort();
    electromagneticPort.setVoltage(voltage);
    electromagneticPort.setCurrent(current);
    modelDescription.getElectromagneticPorts().add(electromagneticPort);
    ElectromagneticPortValidator electromagneticPortValidator = new ElectromagneticPortValidator();
    List<ValidationDiagnostic<ElectromagneticPort>> diagnostics = electromagneticPortValidator.validate(modelDescription);
    assertTrue(diagnostics.isEmpty());
}
Also used : ElectromagneticPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.electromagneticport.ElectromagneticPort) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Voltage(com.opensimulationplatform.core.model.modeldescription.variablegroup.voltage.Voltage) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Current(com.opensimulationplatform.core.model.modeldescription.variablegroup.current.Current) Test(org.junit.Test)

Example 34 with Variable

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

the class ElectromagneticPortValidatorTest method invalid.

@Test
public void invalid() {
    ModelDescription modelDescription = new ModelDescription();
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.OUTPUT);
    Voltage voltage = new Voltage();
    voltage.setVariables(Arrays.asList(v1));
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.OUTPUT);
    Current current = new Current();
    current.setVariables(Arrays.asList(v2));
    ElectromagneticPort electromagneticPort = new ElectromagneticPort();
    electromagneticPort.setVoltage(voltage);
    electromagneticPort.setCurrent(current);
    modelDescription.getElectromagneticPorts().add(electromagneticPort);
    ElectromagneticPortValidator electromagneticPortValidator = new ElectromagneticPortValidator();
    List<ValidationDiagnostic<ElectromagneticPort>> diagnostics = electromagneticPortValidator.validate(modelDescription);
    assertEquals(1, diagnostics.size());
    assertEquals(electromagneticPort, diagnostics.get(0).getValidatedObject());
}
Also used : ElectromagneticPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.electromagneticport.ElectromagneticPort) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Voltage(com.opensimulationplatform.core.model.modeldescription.variablegroup.voltage.Voltage) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) ModelDescription(com.opensimulationplatform.core.model.modeldescription.ModelDescription) Current(com.opensimulationplatform.core.model.modeldescription.variablegroup.current.Current) Test(org.junit.Test)

Example 35 with Variable

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

the class VE_ElectromagneticPort_1_Test method invalid.

@Test
public void invalid() {
    Variable v1 = new Variable();
    v1.setCausality(Variable.Causality.OUTPUT);
    v1.setUnit(new Unit());
    v1.setType(Variable.Type.REAL);
    Variable v2 = new Variable();
    v2.setCausality(Variable.Causality.OUTPUT);
    v2.setUnit(new Unit());
    v2.setType(Variable.Type.REAL);
    Variable v3 = new Variable();
    v3.setCausality(Variable.Causality.OUTPUT);
    v3.setUnit(new Unit());
    v3.setType(Variable.Type.REAL);
    Variable v4 = new Variable();
    v4.setCausality(Variable.Causality.OUTPUT);
    v4.setUnit(new Unit());
    v4.setType(Variable.Type.REAL);
    Voltage voltage = new Voltage();
    voltage.setVariables(Arrays.asList(v1, v2));
    Current current = new Current();
    current.setVariables(Arrays.asList(v3, v4));
    ElectromagneticPort electromagneticPort = new ElectromagneticPort();
    electromagneticPort.setVoltage(voltage);
    electromagneticPort.setCurrent(current);
    builder.build(electromagneticPort);
    builder.complete();
    List<ValidationDiagnostic<ElectromagneticPort>> diagnostics = validationError.validate();
    assertEquals(1, diagnostics.size());
    ElectromagneticPort invalidElectromagneticPort = diagnostics.get(0).getValidatedObject();
    assertEquals(electromagneticPort, invalidElectromagneticPort);
}
Also used : ElectromagneticPort(com.opensimulationplatform.core.model.modeldescription.variablegroup.electromagneticport.ElectromagneticPort) Variable(com.opensimulationplatform.core.model.modeldescription.Variable) Voltage(com.opensimulationplatform.core.model.modeldescription.variablegroup.voltage.Voltage) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Current(com.opensimulationplatform.core.model.modeldescription.variablegroup.current.Current) Test(org.junit.Test)

Aggregations

Variable (com.opensimulationplatform.core.model.modeldescription.Variable)237 Test (org.junit.Test)185 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)183 Unit (com.opensimulationplatform.core.model.modeldescription.Unit)145 ModelDescription (com.opensimulationplatform.core.model.modeldescription.ModelDescription)61 Force (com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force)34 LinearVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity)27 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)23 Pressure (com.opensimulationplatform.core.model.modeldescription.variablegroup.pressure.Pressure)18 Torque (com.opensimulationplatform.core.model.modeldescription.variablegroup.torque.Torque)18 Voltage (com.opensimulationplatform.core.model.modeldescription.variablegroup.voltage.Voltage)18 VariableType (com.opensimulationplatform.modeldescription.xml.model.VariableType)17 VariableConnection (com.opensimulationplatform.core.model.systemstructure.VariableConnection)16 AngularDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.angulardisplacement.AngularDisplacement)14 AngularVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.angularvelocity.AngularVelocity)14 Charge (com.opensimulationplatform.core.model.modeldescription.variablegroup.charge.Charge)14 Current (com.opensimulationplatform.core.model.modeldescription.variablegroup.current.Current)14 LinearDisplacement (com.opensimulationplatform.core.model.modeldescription.variablegroup.lineardisplacement.LinearDisplacement)14 LinearMechanicalPort (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearmechanicalport.LinearMechanicalPort)14 Volume (com.opensimulationplatform.core.model.modeldescription.variablegroup.volume.Volume)14