use of com.opensimulationplatform.core.model.modeldescription.Variable in project osp-validator by open-simulation-platform.
the class SystemStructureUtil method getVariableConnectionByPartNames.
public static Optional<VariableConnection> getVariableConnectionByPartNames(SystemStructure systemStructure, String simulatorAName, String variableAName, String simulatorBName, String variableBName) {
List<VariableConnection> variableConnections = systemStructure.getVariableConnections();
for (VariableConnection variableConnection : variableConnections) {
Simulator simulatorA = variableConnection.getSimulatorA();
Variable variableA = variableConnection.getVariableA();
Simulator simulatorB = variableConnection.getSimulatorB();
Variable variableB = variableConnection.getVariableB();
if (simulatorAName.equals(simulatorA.getName().get()) && variableAName.equals(variableA.getName().get()) && simulatorBName.equals(simulatorB.getName().get()) && variableBName.equals(variableB.getName().get())) {
return Optional.of(variableConnection);
}
}
return Optional.empty();
}
use of com.opensimulationplatform.core.model.modeldescription.Variable in project osp-validator by open-simulation-platform.
the class VE_VariableConnection_4 method getErrorMessage.
@Override
protected String getErrorMessage(VariableConnection variableConnection) {
Variable variableA = variableConnection.getVariableA();
String variableAName = variableA.getName().getId().get();
Variable variableB = variableConnection.getVariableB();
String variableBName = variableB.getName().getId().get();
return "VariableConnection [" + variableAName + ", " + variableBName + "] contains invalid variables";
}
use of com.opensimulationplatform.core.model.modeldescription.Variable in project osp-validator by open-simulation-platform.
the class VE_Name_1_Test method valid.
@Test
public void valid() {
Variable v1 = new Variable();
v1.setName("v1-unique-name");
Variable v2 = new Variable();
v2.setName("v2-unique-name");
builder.build(v1);
builder.build(v2);
builder.complete();
List<ValidationDiagnostic<Name>> diagnostics = validationError.validate();
assertTrue(diagnostics.isEmpty());
}
use of com.opensimulationplatform.core.model.modeldescription.Variable in project osp-validator by open-simulation-platform.
the class VE_Name_1_Test method invalid.
@Test
public void invalid() {
Variable v1 = new Variable();
v1.setName("not-a-unique-name");
Variable v2 = new Variable();
v2.setName("not-a-unique-name");
builder.build(v1);
builder.build(v2);
builder.complete();
List<ValidationDiagnostic<Name>> diagnostics = validationError.validate();
assertEquals(1, diagnostics.size());
Name invalidName = diagnostics.get(0).getValidatedObject();
assertEquals(invalidName.get(), v1.getName().get());
assertEquals(invalidName.get(), v2.getName().get());
}
use of com.opensimulationplatform.core.model.modeldescription.Variable 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());
}
Aggregations