Search in sources :

Example 1 with VariableGroupConnection

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

the class OspSystemStructureConverter method convert.

@Override
public SystemStructure convert(OspSystemStructure ospSystemStructureElement) {
    SystemStructure systemStructure = context.systemStructure;
    List<Simulators.Simulator> simulatorElements = ospSystemStructureElement.getSimulators().getSimulator();
    List<Simulator> simulators = context.simulatorConverter.convert(simulatorElements);
    systemStructure.getSimulators().addAll(simulators);
    List<Object> connectionElements = ospSystemStructureElement.getConnections().getVariableConnectionOrSignalConnectionOrVariableGroupConnection();
    List<Connections.VariableConnection> variableConnectionElements = new ArrayList<>();
    List<Connections.VariableGroupConnection> variableGroupConnectionElements = new ArrayList<>();
    for (Object connectionElement : connectionElements) {
        if (connectionElement instanceof Connections.VariableConnection) {
            variableConnectionElements.add((Connections.VariableConnection) connectionElement);
        } else if (connectionElement instanceof Connections.VariableGroupConnection) {
            variableGroupConnectionElements.add((Connections.VariableGroupConnection) connectionElement);
        }
    }
    List<VariableConnection> variableConnections = context.variableConnectionConverter.convert(variableConnectionElements);
    systemStructure.getVariableConnections().addAll(variableConnections);
    List<VariableGroupConnection> variableGroupConnections = context.variableGroupConnectionConverter.convert(variableGroupConnectionElements);
    systemStructure.getVariableGroupConnections().addAll(variableGroupConnections);
    return systemStructure;
}
Also used : Connections(com.opensimulationplatform.systemstructure.xml.model.Connections) OspSystemStructure(com.opensimulationplatform.systemstructure.xml.model.OspSystemStructure) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) ArrayList(java.util.ArrayList) VariableGroupConnection(com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection) VariableConnection(com.opensimulationplatform.core.model.systemstructure.VariableConnection) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator)

Example 2 with VariableGroupConnection

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

the class SystemStructureUtil method getParentVariableGroupConnection.

public static Optional<VariableGroupConnection> getParentVariableGroupConnection(SystemStructure systemStructure, VariableConnection variableConnection) {
    for (VariableGroupConnection variableGroupConnection : systemStructure.getVariableGroupConnections()) {
        List<Variable> variablesA = variableGroupConnection.getVariableGroupA().getVariables();
        List<Variable> variablesB = variableGroupConnection.getVariableGroupB().getVariables();
        Variable vcVarA = variableConnection.getVariableA();
        Variable vcVarB = variableConnection.getVariableB();
        for (int i = 0; i < variablesA.size(); i++) {
            Variable vgcVarA = variablesA.get(i);
            Variable vgcVarB = variablesB.get(i);
            if (vcVarA.equals(vgcVarA) && vcVarB.equals(vgcVarB)) {
                return Optional.of(variableGroupConnection);
            }
        }
    }
    return Optional.empty();
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) VariableGroupConnection(com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection)

Example 3 with VariableGroupConnection

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

the class SystemStructureUtil method getVariableGroupConnectionByPartNames.

public static Optional<VariableGroupConnection> getVariableGroupConnectionByPartNames(SystemStructure systemStructure, String simulatorAName, String variableGroupAName, String simulatorBName, String variableGroupBName) {
    List<VariableGroupConnection> variableGroupConnections = systemStructure.getVariableGroupConnections();
    for (VariableGroupConnection variableGroupConnection : variableGroupConnections) {
        Simulator simulatorA = variableGroupConnection.getSimulatorA();
        VariableGroup variableA = variableGroupConnection.getVariableGroupA();
        Simulator simulatorB = variableGroupConnection.getSimulatorB();
        VariableGroup variableB = variableGroupConnection.getVariableGroupB();
        if (simulatorAName.equals(simulatorA.getName().get()) && variableGroupAName.equals(variableA.getName().get()) && simulatorBName.equals(simulatorB.getName().get()) && variableGroupBName.equals(variableB.getName().get())) {
            return Optional.of(variableGroupConnection);
        }
    }
    return Optional.empty();
}
Also used : VariableGroupConnection(com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection) VariableGroup(com.opensimulationplatform.core.model.modeldescription.variablegroup.VariableGroup) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator)

Example 4 with VariableGroupConnection

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

the class SystemStructureValidatorTest method invalid.

@Test
public void invalid() {
    Simulator s1 = new Simulator();
    s1.setName("s1");
    s1.setModelDescription(createInvalidModelDescription());
    Simulator s2 = new Simulator();
    s2.setName("s2");
    s2.setModelDescription(createInvalidModelDescription());
    SystemStructure systemStructure = new SystemStructure();
    systemStructure.getSimulators().add(s1);
    systemStructure.getSimulators().add(s2);
    VariableConnection vc1 = new VariableConnection();
    vc1.setSimulatorA(s1);
    vc1.setSimulatorB(s2);
    vc1.setVariableA(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v3"));
    vc1.setVariableB(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v4"));
    VariableConnection vc2 = new VariableConnection();
    vc2.setSimulatorA(s1);
    vc2.setSimulatorB(s2);
    vc2.setVariableA(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v3"));
    vc2.setVariableB(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v5"));
    VariableConnection vc3 = new VariableConnection();
    vc3.setSimulatorA(s1);
    vc3.setSimulatorB(s2);
    vc3.setVariableA(ModelDescriptionUtil.getVariableByName(s1.getModelDescription(), "v3"));
    vc3.setVariableB(ModelDescriptionUtil.getVariableByName(s2.getModelDescription(), "v6"));
    systemStructure.getVariableConnections().add(vc1);
    systemStructure.getVariableConnections().add(vc2);
    systemStructure.getVariableConnections().add(vc3);
    VariableGroupConnection vgc1 = new VariableGroupConnection();
    vgc1.setSimulatorA(s1);
    vgc1.setSimulatorB(s2);
    vgc1.setVariableGroupA(ModelDescriptionUtil.getVariableGroupByName(s1.getModelDescription(), "f3"));
    vgc1.setVariableGroupB(ModelDescriptionUtil.getVariableGroupByName(s2.getModelDescription(), "lv1"));
    systemStructure.getVariableGroupConnections().add(vgc1);
    SystemStructureValidator v = new SystemStructureValidator();
    List<ValidationDiagnostic<Object>> diagnostics = v.validate(systemStructure);
    assertEquals(32, diagnostics.size());
}
Also used : 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) Test(org.junit.Test)

Example 5 with VariableGroupConnection

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

the class VariableGroupConnectionsValidatorTest method valid.

@Test
public void valid() {
    SystemStructure systemStructure = new SystemStructure();
    VariableGroupConnection variableGroupConnection = new VariableGroupConnection();
    Simulator simulatorA = new Simulator();
    Force forceA = new Force();
    forceA.setName("forceA");
    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);
    forceA.setVariables(Arrays.asList(variableA));
    simulatorA.getModelDescription().getVariables().add(variableA);
    simulatorA.getModelDescription().getForces().add(forceA);
    variableGroupConnection.setSimulatorA(simulatorA);
    variableGroupConnection.setVariableGroupA(forceA);
    Simulator simulatorB = new Simulator();
    Force forceB = new Force();
    forceB.setName("forceB");
    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);
    forceB.setVariables(Arrays.asList(variableB));
    simulatorB.getModelDescription().getVariables().add(variableB);
    simulatorB.getModelDescription().getForces().add(forceB);
    variableGroupConnection.setSimulatorB(simulatorB);
    variableGroupConnection.setVariableGroupB(forceB);
    systemStructure.getSimulators().add(simulatorA);
    systemStructure.getSimulators().add(simulatorB);
    systemStructure.getVariableGroupConnections().add(variableGroupConnection);
    VariableGroupConnectionsValidator validator = new VariableGroupConnectionsValidator();
    List<ValidationDiagnostic<VariableGroupConnection>> diagnostics = validator.validate(systemStructure);
    assertEquals(0, diagnostics.size());
}
Also used : Variable(com.opensimulationplatform.core.model.modeldescription.Variable) SystemStructure(com.opensimulationplatform.core.model.systemstructure.SystemStructure) VariableGroupConnection(com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection) Force(com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force) ValidationDiagnostic(com.opensimulationplatform.core.validation.ValidationDiagnostic) Unit(com.opensimulationplatform.core.model.modeldescription.Unit) Simulator(com.opensimulationplatform.core.model.systemstructure.Simulator) Test(org.junit.Test)

Aggregations

VariableGroupConnection (com.opensimulationplatform.core.model.systemstructure.VariableGroupConnection)17 Simulator (com.opensimulationplatform.core.model.systemstructure.Simulator)15 ValidationDiagnostic (com.opensimulationplatform.core.validation.ValidationDiagnostic)11 Test (org.junit.Test)11 Variable (com.opensimulationplatform.core.model.modeldescription.Variable)8 Force (com.opensimulationplatform.core.model.modeldescription.variablegroup.force.Force)8 SystemStructure (com.opensimulationplatform.core.model.systemstructure.SystemStructure)7 LinearVelocity (com.opensimulationplatform.core.model.modeldescription.variablegroup.linearvelocity.LinearVelocity)6 VariableGroup (com.opensimulationplatform.core.model.modeldescription.variablegroup.VariableGroup)5 VariableConnection (com.opensimulationplatform.core.model.systemstructure.VariableConnection)5 Unit (com.opensimulationplatform.core.model.modeldescription.Unit)2 SystemStructureValidator (com.opensimulationplatform.core.validation.systemstructure.SystemStructureValidator)1 VariableGroupConnection (com.opensimulationplatform.gen.owl.model.OntologyClasses.VariableGroupConnection)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