diff --git a/frameworks/builder/src/main/java/org/intocps/maestro/framework/fmi2/api/Fmi2Builder.java b/frameworks/builder/src/main/java/org/intocps/maestro/framework/fmi2/api/Fmi2Builder.java index 3c15dcb2..f6d78fcd 100644 --- a/frameworks/builder/src/main/java/org/intocps/maestro/framework/fmi2/api/Fmi2Builder.java +++ b/frameworks/builder/src/main/java/org/intocps/maestro/framework/fmi2/api/Fmi2Builder.java @@ -755,6 +755,235 @@ interface PortExpressionValueMap extends Map { } } + /** + * Interface for an fmi instance. + *

+ * Note that all methods that do not take a scope uses the builders dynamic scope and adds the underlying instructions int he active scope. + */ + interface Fmi3InstanceVariable extends Variable> { + + void setDebugLogging(List categories, boolean enableLogging); + + void setupExperiment(DoubleVariable startTime, DoubleVariable endTime, BoolVariable endTimeDefined, Double tolerance); + + void setupExperiment(double startTime, Double endTime, Double tolerance); + + int enterInitializationMode(boolean toleranceDefined, double tolerance, double startTime, boolean stopTimeDefined, double stopTime); + + int exitInitializationMode(); + + void setupExperiment(Scope scope, DoubleVariable startTime, DoubleVariable endTime, BoolVariable endTimeDefined, + Double tolerance); + + void setupExperiment(Scope scope, double startTime, Double endTime, Double tolerance); + + int enterInitializationMode(Scope scope,boolean toleranceDefined, double tolerance, double startTime, boolean stopTimeDefined, + double stopTime); + + int exitInitializationMode(Scope scope); + + int terminate(Scope scope); + + int terminate(); + +// void freeInstance(); +// +// void freeInstance(Scope scope); + + /** + * @param scope + * @param currentCommunicationPoint + * @param communicationStepSize + * @param noSetFMUStatePriorToCurrentPoint a pair representing (full step completed, current time after step) + * @return + */ + Map.Entry, DoubleVariable> step(Scope scope, DoubleVariable currentCommunicationPoint, + DoubleVariable communicationStepSize, BoolVariable noSetFMUStatePriorToCurrentPoint); + + Map.Entry, DoubleVariable> step(Scope scope, DoubleVariable currentCommunicationPoint, + DoubleVariable communicationStepSize); + + Map.Entry, DoubleVariable> step(DoubleVariable currentCommunicationPoint, DoubleVariable communicationStepSize, + BoolVariable noSetFMUStatePriorToCurrentPoint); + + Map.Entry, DoubleVariable> step(DoubleVariable currentCommunicationPoint, DoubleVariable communicationStepSize); + + + List getPorts(); + + /** + * Get ports by name + * + * @param names + * @return + */ + List getPorts(String... names); + + /** + * Get ports by ref val + * + * @param valueReferences + * @return + */ + List getPorts(int... valueReferences); + + /** + * Get port by name + * + * @param name + * @return + */ + Port getPort(String name); + + /** + * Get port by ref val + * + * @param valueReference + * @return + */ + Port getPort(int valueReference); + + /** + * Get port values aka fmiGet + * + * @param ports + * @return + */ + Map> get(Port... ports); + + Map> get(Scope scope, Port... ports); + + /** + * Get all (linked) port values + * + * @return + */ + Map> get(); + + /** + * get filter by value reference + * + * @param valueReferences + * @return + */ + Map> get(int... valueReferences); + + /** + * Get filter by names + * + * @param names + * @return + */ + Map> get(String... names); + + Map> getAndShare(String... names); + + Map> getAndShare(Port... ports); + + Map> getAndShare(); + + Variable getShared(String name); + + Variable getShared(Port port); + + /** + * Get the value of a single port + * + * @param name + * @return + */ + Variable getSingle(String name); + + Variable getSingle(Port port); + + void set(Scope scope, PortValueMap value); + + + void set(Scope scope, PortVariableMap value); + + /** + * Set port values (if ports is not from this fmu then the links are used to remap) + * + * @param value + */ + void set(PortValueMap value); + + void set(Port port, Value value); + + void set(Port port, Variable value); + + void set(Scope scope, Port port, Variable value); + + void set(PortVariableMap value); + + /** + * Set this fmu port by name and link + */ + void setLinked(Scope scope, Port... filterPorts); + + void setLinked(); + + void setLinked(Port... filterPorts); + + void setLinked(String... filterNames); + + void setLinked(long... filterValueReferences); + + /** + * Set this fmu ports by val ref + * + * @param values + */ + void setInt(Map> values); + + /** + * Set this fmy ports by name + * + * @param value + */ + void setString(Map> value); + + /** + * Makes the values publicly available to all linked connections. On next set these ports will be resolved to the values given for + * other fmu + * + * @param values + */ + void share(Map> values); + + /** + * Makes the value publicly available to all linked connections. On next set these ports will be resolved to the values given for + * other fmu + * + * @param value + */ + void share(Port port, Variable value); + + /** + * Get the current state + * + * @return + */ + StateVariable getState() throws XPathExpressionException; + + /** + * Get the current state + * + * @return + */ + StateVariable getState(Scope scope) throws XPathExpressionException; + + + interface PortVariableMap extends Map> { + } + + interface PortValueMap extends Map> { + } + + interface PortExpressionValueMap extends Map { + } + } + interface Variable { String getName(); diff --git a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/MablApiBuilder.java b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/MablApiBuilder.java index d4c83d2e..344091a9 100644 --- a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/MablApiBuilder.java +++ b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/MablApiBuilder.java @@ -35,7 +35,7 @@ public class MablApiBuilder implements Fmi2Builder fmiStatusVariables; + private final Map fmiStatusVariables; private final Set externalLoadedModuleIdentifier = new HashSet<>(); int dynamicScopeInitialSize; List importedModules = new Vector<>(); @@ -140,76 +140,32 @@ public MablSettings getSettings() { return this.settings; } - public IntVariableFmi2Api getFmiStatusConstant(FmiStatus status) { - //if (!settings.fmiErrorHandlingEnabled) { - // throw new IllegalStateException("Fmi error handling feature not enabled"); - // } + interface FmiStatusInterface { + int getValue(); - if (!this.fmiStatusVariables.containsKey(status)) { - switch (status) { - case FMI_OK: { - IntVariableFmi2Api var = rootScope.store(status.name(), FmiStatus.FMI_OK.getValue()); - //relocate to top of scope - rootScope.addAfterOrTop(null, var.getDeclaringStm()); - fmiStatusVariables.put(FmiStatus.FMI_OK, var); - } - break; - case FMI_WARNING: { - IntVariableFmi2Api var = rootScope.store(status.name(), FmiStatus.FMI_WARNING.getValue()); - //relocate to top of scope - rootScope.addAfterOrTop(null, var.getDeclaringStm()); - fmiStatusVariables.put(FmiStatus.FMI_WARNING, var); - break; - } - case FMI_DISCARD: { - IntVariableFmi2Api var = rootScope.store(status.name(), FmiStatus.FMI_DISCARD.getValue()); - //relocate to top of scope - rootScope.addAfterOrTop(null, var.getDeclaringStm()); - fmiStatusVariables.put(FmiStatus.FMI_DISCARD, var); - } - break; - case FMI_ERROR: { - IntVariableFmi2Api var = storeStatusVariable(rootScope, status.name(), FmiStatus.FMI_ERROR.getValue()); - //IntVariableFmi2Api var = rootScope.store(status.name(), FmiStatus.FMI_ERROR.getValue()); - //relocate to top of scope - rootScope.addAfterOrTop(null, var.getDeclaringStm()); - fmiStatusVariables.put(FmiStatus.FMI_ERROR, var); - break; - } - case FMI_FATAL: { - IntVariableFmi2Api var = storeStatusVariable(rootScope, status.name(), FmiStatus.FMI_FATAL.getValue()); - //relocate to top of scope - rootScope.addAfterOrTop(null, var.getDeclaringStm()); - fmiStatusVariables.put(FmiStatus.FMI_FATAL, var); - break; - } - case FMI_PENDING: { - IntVariableFmi2Api var = rootScope.store(status.name(), FmiStatus.FMI_PENDING.getValue()); - //relocate to top of scope - rootScope.addAfterOrTop(null, var.getDeclaringStm()); - fmiStatusVariables.put(FmiStatus.FMI_PENDING, var); - break; - } - } + String getName(); + } + private IntVariableFmi2Api getFmiStatusConstant_aux(FmiStatusInterface status) { + if(!this.fmiStatusVariables.containsKey(status)) { + IntVariableFmi2Api var = rootScope.store(status.getName(), status.getValue()); + rootScope.addAfterOrTop(null, var.getDeclaringStm()); + fmiStatusVariables.put(status, var); } - return this.fmiStatusVariables.get(status); } + public IntVariableFmi2Api getFmiStatusConstant(FmiStatus status) {return getFmiStatusConstant_aux(status);} + public IntVariableFmi2Api getFmiStatusConstant(Fmi3Status status) {return getFmiStatusConstant_aux(status);} + public MablToMablAPI getMablToMablAPI() { return this.mablToMablAPI; } - public IntVariableFmi2Api getGlobalFmiStatus() { return globalFmiStatus; } - private IntVariableFmi2Api storeStatusVariable(ScopeFmi2Api rootScope, String name, int errorCode) { - return rootScope.store(() -> this.getNameGenerator().getNameIgnoreCase(name), errorCode); - } - @SuppressWarnings("rawtypes") private Variable createVariable(IMablScope scope, PType type, PExp initialValue, String... prefixes) { String name = nameGenerator.getName(prefixes); @@ -632,7 +588,7 @@ T load(String moduleType, Function, T> creat return m; } - public enum FmiStatus { + public enum FmiStatus implements FmiStatusInterface { FMI_OK(0), FMI_WARNING(1), FMI_DISCARD(2), @@ -645,11 +601,41 @@ public enum FmiStatus { private FmiStatus(final int value) { this.value = value; } + public int getValue() { return this.value; } + // Interface method, not sure how to best preserve enum name() method. + public String getName() { + for (FmiStatus status : FmiStatus.values()) { + if (status.value == this.value) { + return status.name(); + } + } + return null; + } + } + + public enum Fmi3Status implements FmiStatusInterface { + FMI_OK(0), + FMI_WARNING(1), + FMI_DISCARD(2), + FMI_ERROR(3), + FMI_FATAL(4); + private final int value; + private Fmi3Status(final int value) { + this.value = value; + } public int getValue() { return this.value; } + public String getName() { + for (FmiStatus status : FmiStatus.values()) { + if (status.value == this.value) { + return status.name(); + } + } + return null; + } } public static class MablSettings { diff --git a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/scoping/DynamicActiveBuilderScope.java b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/scoping/DynamicActiveBuilderScope.java index c0821a3e..342ffedf 100644 --- a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/scoping/DynamicActiveBuilderScope.java +++ b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/scoping/DynamicActiveBuilderScope.java @@ -255,7 +255,7 @@ public void registerComponentVariableFmi2Api(ComponentVariableFmi2Api componentV @Override public void registerInstanceVariableFmi3Api(InstanceVariableFmi3Api instanceVariableFmi3Api) { - // TODO stuff goes here. + activeScope.registerInstanceVariableFmi3Api((instanceVariableFmi3Api)); } @Override diff --git a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/scoping/ScopeFmi2Api.java b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/scoping/ScopeFmi2Api.java index 721c4847..4ddf63a8 100644 --- a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/scoping/ScopeFmi2Api.java +++ b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/scoping/ScopeFmi2Api.java @@ -222,12 +222,12 @@ public IntVariableFmi2Api store(String name, int value) { return store(() -> builder.getNameGenerator().getName(name), value); } - @Override public ArrayVariableFmi2Api store(String name, V[] value) { return store(() -> builder.getNameGenerator().getName(name), value); } + public DoubleVariableFmi2Api store(Supplier nameProvider, double value) { String name = nameProvider.get(); ARealLiteralExp initial = newARealLiteralExp(value); diff --git a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/FmuVariableFmi3Api.java b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/FmuVariableFmi3Api.java index 0b18e53f..ddb6d3c4 100644 --- a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/FmuVariableFmi3Api.java +++ b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/FmuVariableFmi3Api.java @@ -72,10 +72,6 @@ public InstanceVariableFmi3Api instantiate(String namePrefix, Fmi2Builder.TrySco //TODO: Extract bool visible and bool loggingOn from configuration var var = newVariable(name, newANameType("FMI3Instance"), newNullExp()); - - - - PStm instantiateAssign = newAAssignmentStm(newAIdentifierStateDesignator(name), call(getReferenceExp().clone(), "instantiateCoSimulation", newAStringLiteralExp(name), newABoolLiteralExp(true), newABoolLiteralExp(loggingOn), newABoolLiteralExp(true), newABoolLiteralExp(true), diff --git a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/InstanceVariableFmi3Api.java b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/InstanceVariableFmi3Api.java index ea1a2e20..8fe16bc1 100644 --- a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/InstanceVariableFmi3Api.java +++ b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/InstanceVariableFmi3Api.java @@ -1,5 +1,6 @@ package org.intocps.maestro.framework.fmi2.api.mabl.variables; +import org.intocps.fmi.jnifmuapi.fmi3.Fmi3Status; import org.intocps.maestro.ast.AVariableDeclaration; import org.intocps.maestro.ast.LexIdentifier; import org.intocps.maestro.ast.MableAstFactory; @@ -36,7 +37,7 @@ @SuppressWarnings("rawtypes") -public class InstanceVariableFmi3Api extends VariableFmi2Api> implements Fmi2Builder.Fmi2ComponentVariable { +public class InstanceVariableFmi3Api extends VariableFmi2Api> implements Fmi2Builder.Fmi3InstanceVariable { final static Logger logger = LoggerFactory.getLogger(InstanceVariableFmi3Api.class); private final static int FMI_OK = 0; private final static int FMI_WARNING = 1; @@ -255,8 +256,8 @@ public void setDebugLogging(List categories, boolean enableLogging) { scope.add(arrayContent, callStm); if (builder.getSettings().fmiErrorHandlingEnabled) { - FmiStatusErrorHandlingBuilder.generate(builder, "setDebugLogging", this, (IMablScope) scope, MablApiBuilder.FmiStatus.FMI_ERROR, - MablApiBuilder.FmiStatus.FMI_FATAL); + FmiStatusErrorHandlingBuilder.generate(builder, "setDebugLogging", this, (IMablScope) scope, MablApiBuilder.Fmi3Status.FMI_ERROR, + MablApiBuilder.Fmi3Status.FMI_FATAL); } } @@ -285,20 +286,19 @@ private void setupExperiment(Fmi2Builder.Scope scope, PExp startTime, PExp startTime.clone(), endTimeDefined, endTime != null ? endTime.clone() : newARealLiteralExp(0d))))); scope.add(stm); if (builder.getSettings().fmiErrorHandlingEnabled) { - FmiStatusErrorHandlingBuilder.generate(builder, "setupExperiment", this, (IMablScope) scope, MablApiBuilder.FmiStatus.FMI_ERROR, - MablApiBuilder.FmiStatus.FMI_FATAL); + FmiStatusErrorHandlingBuilder.generate(builder, "setupExperiment", this, (IMablScope) scope, MablApiBuilder.Fmi3Status.FMI_ERROR, + MablApiBuilder.Fmi3Status.FMI_FATAL); } } @Override - public void enterInitializationMode() { - this.enterInitializationMode(builder.getDynamicScope()); - + public int enterInitializationMode(boolean toleranceDefined, double tolerance, double startTime, boolean stopTimeDefined, double stopTime) { + return this.enterInitializationMode(builder.getDynamicScope(), toleranceDefined, tolerance, startTime, stopTimeDefined, stopTime); } @Override - public void exitInitializationMode() { - this.exitInitializationMode(builder.getDynamicScope()); + public int exitInitializationMode() { + return this.exitInitializationMode(builder.getDynamicScope()); } @Override @@ -313,24 +313,31 @@ public void setupExperiment(Fmi2Builder.Scope scope, double startTime, Dou this.setupExperiment(scope, newARealLiteralExp(startTime), newARealLiteralExp(endTime), newABoolLiteralExp(true), tolerance); } + // TODO: probably should return other things than ok also @Override - public void enterInitializationMode(Fmi2Builder.Scope scope) { - PStm stm = stateTransitionFunction(FmiFunctionType.ENTERINITIALIZATIONMODE); + public int enterInitializationMode(Fmi2Builder.Scope scope, boolean toleranceDefined, double tolerance, double startTime, + boolean stopTimeDefined, double stopTime) { + PStm stm = stateTransitionFunction(FmiFunctionType.ENTERINITIALIZATIONMODE, toleranceDefined, tolerance, startTime, stopTimeDefined, stopTime ); + + scope.add(stm); if (builder.getSettings().fmiErrorHandlingEnabled) { - FmiStatusErrorHandlingBuilder.generate(builder, "enterInitializationMode", this, (IMablScope) scope, MablApiBuilder.FmiStatus.FMI_ERROR, - MablApiBuilder.FmiStatus.FMI_FATAL); + FmiStatusErrorHandlingBuilder.generate(builder, "enterInitializationMode", this, (IMablScope) scope, MablApiBuilder.Fmi3Status.FMI_ERROR, + MablApiBuilder.Fmi3Status.FMI_FATAL); } + return Fmi3Status.OK.value; } + // TODO: Probably return other things than just ok. @Override - public void exitInitializationMode(Fmi2Builder.Scope scope) { + public int exitInitializationMode(Fmi2Builder.Scope scope) { PStm stm = stateTransitionFunction(FmiFunctionType.EXITINITIALIZATIONMODE); scope.add(stm); if (builder.getSettings().fmiErrorHandlingEnabled) { - FmiStatusErrorHandlingBuilder.generate(builder, "exitInitializationMode", this, (IMablScope) scope, MablApiBuilder.FmiStatus.FMI_ERROR, - MablApiBuilder.FmiStatus.FMI_FATAL); + FmiStatusErrorHandlingBuilder.generate(builder, "exitInitializationMode", this, (IMablScope) scope, MablApiBuilder.Fmi3Status.FMI_ERROR, + MablApiBuilder.Fmi3Status.FMI_FATAL); } + return Fmi3Status.OK.value; } @Override @@ -369,8 +376,8 @@ private Map.Entry, Fmi2Builder.DoubleVariable, Fmi2Builder.DoubleVariable Map> get(Fmi2Builder.Scope scop if (builder.getSettings().fmiErrorHandlingEnabled) { FmiStatusErrorHandlingBuilder.generate(builder, createFunctionName(FmiFunctionType.GET, e.getValue().get(0)), this, - (IMablScope) scope, MablApiBuilder.FmiStatus.FMI_ERROR, MablApiBuilder.FmiStatus.FMI_FATAL); + (IMablScope) scope, MablApiBuilder.Fmi3Status.FMI_ERROR, MablApiBuilder.Fmi3Status.FMI_FATAL); } if (builder.getSettings().setGetDerivatives && type.equals(new ARealNumericPrimitiveType())) { @@ -628,7 +655,7 @@ public Map>> getDerivatives(List scope, Fmi2Builder.Port p, Fmi2Builder.ExpressionValue v) { - this.set(scope, new PortValueMapImpl(Map.of(p, v))); + ; + // this.set(scope, new PortValueMapImpl(Map.of(p, v))); } public void set(PortExpressionValueMap value) { @@ -862,7 +890,7 @@ public void set(Fmi2Builder.Scope scope, List selectedPorts, if (builder.getSettings().fmiErrorHandlingEnabled) { FmiStatusErrorHandlingBuilder.generate(builder, createFunctionName(FmiFunctionType.SET, sortedPorts.get(0)), this, (IMablScope) scope, - MablApiBuilder.FmiStatus.FMI_ERROR, MablApiBuilder.FmiStatus.FMI_FATAL); + MablApiBuilder.Fmi3Status.FMI_ERROR, MablApiBuilder.Fmi3Status.FMI_FATAL); } // TODO: IntermediateUpdateMode instead of CanInterpolateInputs? @@ -968,7 +996,7 @@ public void setDerivatives(ArrayVariableFmi2Api derValInBuf, ArrayVariableFmi2Ap // If enabled handle potential errors from calling setRealInputDerivatives if (builder.getSettings().fmiErrorHandlingEnabled) { FmiStatusErrorHandlingBuilder.generate(builder, createFunctionName(FmiFunctionType.SETREALINPUTDERIVATIVES), this, (IMablScope) scope, - MablApiBuilder.FmiStatus.FMI_ERROR, MablApiBuilder.FmiStatus.FMI_FATAL); + MablApiBuilder.Fmi3Status.FMI_ERROR, MablApiBuilder.Fmi3Status.FMI_FATAL); } } @@ -979,20 +1007,22 @@ public void set(PortValueMap value) { @Override public void set(Fmi2Builder.Port port, Fmi2Builder.Variable value) { - this.set(new PortVariableMapImpl(Map.of(port, value))); + ; + // this.set(new PortVariableMapImpl(Map.of(port, value))); } @Override public void set(Fmi2Builder.Scope scope, Fmi2Builder.Port port, Fmi2Builder.Variable value) { - this.set(scope, new PortVariableMapImpl(Map.of(port, value))); + ; +// this.set(scope, new PortVariableMapImpl(Map.of(port, value))); } @Override public void set(Fmi2Builder.Port port, Fmi2Builder.Value value) { - PortValueMap map = new PortValueMapImpl(); - map.put(port, value); - set(map); - + ; + // PortValueMap map = new PortValueMapImpl(); + // map.put(port, value); + // set(map); } @@ -1077,20 +1107,35 @@ public void setString(Map> } @Override - public void terminate() { - this.terminate(builder.getDynamicScope()); + public int terminate() { + return this.terminate(builder.getDynamicScope()); } + // TODO: Return other values but ok? @Override - public void terminate(Fmi2Builder.Scope scope) { + public int terminate(Fmi2Builder.Scope scope) { PStm stm = stateTransitionFunction(FmiFunctionType.TERMINATE); scope.add(stm); if (builder.getSettings().fmiErrorHandlingEnabled) { - FmiStatusErrorHandlingBuilder.generate(builder, "terminate", this, (IMablScope) scope, MablApiBuilder.FmiStatus.FMI_ERROR, - MablApiBuilder.FmiStatus.FMI_FATAL); + FmiStatusErrorHandlingBuilder.generate(builder, "terminate", this, (IMablScope) scope, MablApiBuilder.Fmi3Status.FMI_ERROR, + MablApiBuilder.Fmi3Status.FMI_FATAL); } + return Fmi3Status.OK.value; } +// public void freeInstance() { +// this.terminate(builder.getDynamicScope()); +// } +// +// public void freeInstance(Fmi2Builder.Scope scope) { +// scope.add(newABlockStm(MableAstFactory.newExpressionStm(call(getReferenceExp().clone(), "fmi3FreeInstance")))) +// scope.add(newIf(newNotEqual(((InstanceVariableFmi3Api) inst).getReferenceExp().clone(), newNullExp()), newABlockStm( +// MableAstFactory.newExpressionStm( +// call(getReferenceExp().clone(), "freeInstance", ((InstanceVariableFmi3Api) inst).getReferenceExp().clone())), +// newAAssignmentStm(((InstanceVariableFmi3Api) inst).getDesignatorClone(), newNullExp())), null)); +// } + + // TODO: implement this from the other share function below. This for now to build. @Override public void share(Map> values) { @@ -1280,8 +1325,8 @@ public Fmi2Builder.StateVariable getState(Fmi2Builder.Scope scope) t call(this.getReferenceExp().clone(), "getState", Collections.singletonList(newARefExp(state.getReferenceExp().clone())))); scope.add(stm); if (builder.getSettings().fmiErrorHandlingEnabled) { - FmiStatusErrorHandlingBuilder.generate(builder, "getState", this, (IMablScope) scope, MablApiBuilder.FmiStatus.FMI_ERROR, - MablApiBuilder.FmiStatus.FMI_FATAL); + FmiStatusErrorHandlingBuilder.generate(builder, "getState", this, (IMablScope) scope, MablApiBuilder.Fmi3Status.FMI_ERROR, + MablApiBuilder.Fmi3Status.FMI_FATAL); } return state; @@ -1322,12 +1367,12 @@ public enum FmiFunctionType { */ static class FmiStatusErrorHandlingBuilder { static void generate(MablApiBuilder builder, String method, InstanceVariableFmi3Api instance, IMablScope scope, - MablApiBuilder.FmiStatus... statusesToFail) { + MablApiBuilder.Fmi3Status... statusesToFail) { if (statusesToFail == null || statusesToFail.length == 0) { return; } - Function checkStatusEq = + Function checkStatusEq = s -> newEqual(((IMablScope) scope).getFmiStatusVariable().getReferenceExp().clone(), builder.getFmiStatusConstant(s).getReferenceExp().clone()); @@ -1341,7 +1386,7 @@ static void generate(MablApiBuilder builder, String method, InstanceVariableFmi3 // thenScope.add(newAAssignmentStm(builder.getGlobalExecutionContinue().getDesignator().clone(), newABoolLiteralExp(false))); - for (MablApiBuilder.FmiStatus status : statusesToFail) { + for (MablApiBuilder.Fmi3Status status : statusesToFail) { ScopeFmi2Api s = thenScope.enterIf(new PredicateFmi2Api(checkStatusEq.apply(status))).enterThen(); builder.getLogger() .error(s, method.substring(0, 1).toUpperCase() + method.substring(1) + " failed on '%s' with status: " + status, instance); diff --git a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/StateMablVariableFmi3Api.java b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/StateMablVariableFmi3Api.java index 826610ad..f7c2188a 100644 --- a/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/StateMablVariableFmi3Api.java +++ b/frameworks/fmi2api/src/main/java/org/intocps/maestro/framework/fmi2/api/mabl/variables/StateMablVariableFmi3Api.java @@ -38,8 +38,8 @@ public void set(Fmi2Builder.Scope scope) throws IllegalStateException { scope.add(stm); if (builder.getSettings().fmiErrorHandlingEnabled) { InstanceVariableFmi3Api.FmiStatusErrorHandlingBuilder - .generate(builder, "setState", this.owner, (IMablScope) scope, MablApiBuilder.FmiStatus.FMI_ERROR, - MablApiBuilder.FmiStatus.FMI_FATAL); + .generate(builder, "setState", this.owner, (IMablScope) scope, MablApiBuilder.Fmi3Status.FMI_ERROR, + MablApiBuilder.Fmi3Status.FMI_FATAL); } } @@ -59,8 +59,8 @@ public void destroy(Fmi2Builder.Scope scope) throws IllegalStateException scope.add(stm); if (builder.getSettings().fmiErrorHandlingEnabled) { InstanceVariableFmi3Api.FmiStatusErrorHandlingBuilder - .generate(builder, "freeState", this.owner, (IMablScope) scope, MablApiBuilder.FmiStatus.FMI_ERROR, - MablApiBuilder.FmiStatus.FMI_FATAL); + .generate(builder, "freeState", this.owner, (IMablScope) scope, MablApiBuilder.Fmi3Status.FMI_ERROR, + MablApiBuilder.Fmi3Status.FMI_FATAL); } valid = false; diff --git a/maestro/src/test/java/org/intocps/maestro/BuilderFmi3Test.java b/maestro/src/test/java/org/intocps/maestro/BuilderFmi3Test.java index ff099d9c..66ea38c5 100644 --- a/maestro/src/test/java/org/intocps/maestro/BuilderFmi3Test.java +++ b/maestro/src/test/java/org/intocps/maestro/BuilderFmi3Test.java @@ -86,6 +86,14 @@ public void wt() throws Exception { InstanceVariableFmi3Api ballInstance = ballFmu.instantiate("ballInstance", varArray); + int res = ballInstance.enterInitializationMode(false, 0.0, 0.0, true,10.0); + res = ballInstance.exitInitializationMode(); + + res = ballInstance.terminate(); + + + + // Create the two FMUs FmuVariableFmi2Api controllerFMU = builder.getDynamicScope() @@ -94,7 +102,8 @@ public void wt() throws Exception { FmuVariableFmi2Api tankFMU = builder.getDynamicScope() .createFMU("tankFMU", (Fmi2ModelDescription) env.getModelDescription("{tankFMU}"), env.getUriFromFMUName("{tankFMU}")); - // Create the controller and tank instanes + + // Create the controller and tank instances ComponentVariableFmi2Api controller = controllerFMU.instantiate("controller"); ComponentVariableFmi2Api tank = tankFMU.instantiate("tank"); DynamicActiveBuilderScope dynamicScope = builder.getDynamicScope(); diff --git a/maestro/src/test/resources/fmi3/reference/bounchingball/fmi3_bb.mabl b/maestro/src/test/resources/fmi3/reference/bounchingball/fmi3_bb.mabl index 77ccf940..0a97e116 100644 --- a/maestro/src/test/resources/fmi3/reference/bounchingball/fmi3_bb.mabl +++ b/maestro/src/test/resources/fmi3/reference/bounchingball/fmi3_bb.mabl @@ -32,8 +32,6 @@ import Logger; uint sv_par_e=6; int res=0; - - uint svs[2]={sv_par_g, sv_par_e}; float values_r[2]={-9.81,0.7}; res=instance.setFloat32(svs,values_r);