Search in sources :

Example 16 with VariableConnection

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

the class VariableGroupConnectionOwlBuilder method makeNestedVariableConnections.

private void makeNestedVariableConnections(VariableGroupConnection variableGroupConnection, OWLNamedIndividual individual) {
    VariableConnectionOwlBuilder variableConnectionOwlBuilder = new VariableConnectionOwlBuilder();
    variableConnectionOwlBuilder.setContext(context);
    List<Variable> variablesA = variableGroupConnection.getVariableGroupA().getVariables();
    List<Variable> variablesB = variableGroupConnection.getVariableGroupB().getVariables();
    for (int i = 0; i < min(variablesA.size(), variablesB.size()); i++) {
        VariableConnection connection = new VariableConnection();
        connection.setSimulatorA(variableGroupConnection.getSimulatorA());
        connection.setSimulatorB(variableGroupConnection.getSimulatorB());
        connection.setVariableA(variablesA.get(i));
        connection.setVariableB(variablesB.get(i));
        OWLNamedIndividual variableConnectionIndividual = variableConnectionOwlBuilder.build(connection);
        OWLObjectProperty hasConnection = context.owl.dataFactory.getOWLObjectProperty(op_has_connection, context.owl.prefixManager);
        OWLAxiom axiom = context.owl.dataFactory.getOWLObjectPropertyAssertionAxiom(hasConnection, individual, variableConnectionIndividual);
        context.axioms.add(axiom);
    }
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) OWLNamedIndividual(org.semanticweb.owlapi.model.OWLNamedIndividual) OWLAxiom(org.semanticweb.owlapi.model.OWLAxiom) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) OWLObjectProperty(org.semanticweb.owlapi.model.OWLObjectProperty)

Example 17 with VariableConnection

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

the class ValidateSystemStructureDataModel method main.

public static void main(String[] args) {
    SystemStructure systemStructure = new SystemStructure();
    Simulator s1 = new Simulator();
    s1.setName("s1");
    s1.setModelDescription(getModelDescription(Variable.Causality.INPUT, Variable.Causality.OUTPUT));
    Simulator s2 = new Simulator();
    s2.setName("s2");
    s2.setModelDescription(getModelDescription(Variable.Causality.OUTPUT, Variable.Causality.INPUT));
    VariableConnection vc = new VariableConnection();
    vc.setSimulatorA(s1);
    vc.setVariableA(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v5"));
    vc.setSimulatorB(s2);
    vc.setVariableB(ModelDescriptionUtil.getVariableByName(s2.getModelDescription(), "v5"));
    VariableGroupConnection vgc = new VariableGroupConnection();
    vgc.setSimulatorA(s1);
    vgc.setVariableGroupA(ModelDescriptionUtil.getVariableGroupByName(s1.getModelDescription(), "linearMechanicalPort"));
    vgc.setSimulatorB(s2);
    vgc.setVariableGroupB(ModelDescriptionUtil.getVariableGroupByName(s2.getModelDescription(), "linearMechanicalPort"));
    systemStructure.getSimulators().add(s1);
    systemStructure.getSimulators().add(s2);
    systemStructure.getVariableConnections().add(vc);
    systemStructure.getVariableGroupConnections().add(vgc);
    SystemStructureValidator validator = new SystemStructureValidator();
    List<ValidationDiagnostic<Object>> diagnostics = validator.validate(systemStructure);
    for (ValidationDiagnostic<Object> diagnostic : diagnostics) {
        System.out.println("Message: " + diagnostic.getErrorMessage());
        System.out.println("Object: " + diagnostic.getValidatedObject());
    }
}
Also used : SystemStructureValidator(com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) VariableGroupConnection(com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator)

Example 18 with VariableConnection

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

the class SystemStructureFactoryTest method canCreate.

@Test
public void canCreate() {
    SystemStructureFactory factory = new SystemStructureFactory();
    SystemStructure systemStructure = factory.create(TestResources.OSP_SYSTEM_STRUCTURE_CRANE);
    List<Simulator> simulators = systemStructure.getSimulators();
    List<VariableConnection> variableConnections = systemStructure.getVariableConnections();
    List<VariableGroupConnection> variableGroupConnections = systemStructure.getVariableGroupConnections();
    assertEquals(2, simulators.size());
    Simulator s1 = simulators.get(0);
    assertEquals("crane_controller", s1.getName().get());
    Simulator s2 = simulators.get(1);
    assertEquals("knuckle_boom_crane", s2.getName().get());
    assertEquals(1, variableConnections.size());
    VariableConnection variableConnection = variableConnections.get(0);
    Simulator simulatorA = variableConnection.getSimulatorA();
    Variable variableA = variableConnection.getVariableA();
    Simulator simulatorB = variableConnection.getSimulatorB();
    Variable variableB = variableConnection.getVariableB();
    assertEquals("crane_controller", simulatorA.getName().get());
    assertEquals("Act_Limits[1]", variableA.getName().get());
    assertEquals("knuckle_boom_crane", simulatorB.getName().get());
    assertEquals("Act_Limits[1]", variableB.getName().get());
    assertEquals(1, variableGroupConnections.size());
    VariableGroupConnection variableGroupConnection = variableGroupConnections.get(0);
    Simulator simulatorA1 = variableGroupConnection.getSimulatorA();
    VariableGroup variableGroupA = variableGroupConnection.getVariableGroupA();
    Simulator simulatorB1 = variableGroupConnection.getSimulatorB();
    VariableGroup variableGroupB = variableGroupConnection.getVariableGroupB();
    assertEquals("crane_controller", simulatorA1.getName().get());
    assertEquals("linear_mechanical_port", variableGroupA.getName().get());
    assertEquals("knuckle_boom_crane", simulatorB1.getName().get());
    assertEquals("linear_mechanical_port", variableGroupB.getName().get());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) VariableGroupConnection(com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection) VariableGroup(com.opensimulationplatform.core.model.modeldescription.variablegroup.VariableGroup) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Example 19 with VariableConnection

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

the class VariableConnectionConverter method convert.

@Override
public VariableConnection convert(Connections.VariableConnection variableConnectionElement) {
    VariableConnection variableConnection = new VariableConnection();
    List<VariableEndpoint> variableEndpoints = variableConnectionElement.getVariable();
    VariableEndpoint variableEndpointA = variableEndpoints.get(0);
    VariableEndpoint variableEndpointB = variableEndpoints.get(1);
    Simulator simulatorA = SystemStructureUtil.getSimulatorByName(context.systemStructure, variableEndpointA.getSimulator()).get();
    Variable variableA = ModelDescriptionUtil.getVariableByName(simulatorA.getModelDescription(), variableEndpointA.getName());
    variableConnection.setSimulatorA(simulatorA);
    variableConnection.setVariableA(variableA);
    Simulator simulatorB = SystemStructureUtil.getSimulatorByName(context.systemStructure, variableEndpointB.getSimulator()).get();
    Variable variableB = ModelDescriptionUtil.getVariableByName(simulatorB.getModelDescription(), variableEndpointB.getName());
    variableConnection.setSimulatorB(simulatorB);
    variableConnection.setVariableB(variableB);
    return variableConnection;
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) VariableEndpoint(com.opensimulationplatform.systemstructure.xml.model.VariableEndpoint)

Aggregations

VariableConnection (com.opensimulationplatform.core.model.systemstructure.VariableConnection)19 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)17 Variable (com.opensimulationplatform.core.model.modeldescription.Variable)15 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)13 Test (org.junit.Test)13 SystemStructure (com.opensimulationplatform.core.model.systemstructure.SystemStructure)7 VariableGroupConnection (com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection)5 Unit (com.opensimulationplatform.core.model.modeldescription.Unit)4 VariableGroup (com.opensimulationplatform.core.model.modeldescription.variablegroup.VariableGroup)1 SystemStructureValidator (com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator)1 Connections (com.opensimulationplatform.systemstructure.xml.model.Connections)1 OspSystemStructure (com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure)1 VariableEndpoint (com.opensimulationplatform.systemstructure.xml.model.VariableEndpoint)1 ArrayList (java.util.ArrayList)1 OWLAxiom (org.semanticweb.owlapi.model.OWLAxiom)1 OWLNamedIndividual (org.semanticweb.owlapi.model.OWLNamedIndividual)1 OWLObjectProperty (org.semanticweb.owlapi.model.OWLObjectProperty)1