diff --git a/build.gradle b/build.gradle index 51af8611124bb7ce4ccfc868da0df4112c3684e8..c479d4542c8df7c11a2fb23d2215a7c00666d1b0 100644 --- a/build.gradle +++ b/build.gradle @@ -44,8 +44,6 @@ project(':de.prob.core') { // hardcode a specific MXParser version here. // It *should* be safe to update this when a new version is released. implementation group: 'io.github.x-stream', name: 'mxparser', version: '1.2.2' - implementation group: 'net.java.dev.jna', name: 'jna', version: '3.4.0' - implementation group: 'de.hhu.stups', name: 'ptolemy-jfmi', version: '1.1.0' } } diff --git a/de.prob.core/.classpath b/de.prob.core/.classpath index 91af8803d370f7eadea6a1b56eb4aae451b92dd3..17e8abd7b307e8d729d012134148b630608a3d38 100644 --- a/de.prob.core/.classpath +++ b/de.prob.core/.classpath @@ -10,12 +10,10 @@ --> <classpathentry exported="true" kind="lib" path="lib/dependencies/answerparser-2.12.4.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/bparser-2.12.4.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/jna-3.4.0.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/ltlparser-2.12.4.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/mxparser-1.2.2.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/parserbase-2.12.4.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/prologlib-2.12.4.jar"/> - <classpathentry exported="true" kind="lib" path="lib/dependencies/ptolemy-jfmi-1.1.0.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/sablecc-runtime-3.4.1.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/theorymapping-2.12.4.jar"/> <classpathentry exported="true" kind="lib" path="lib/dependencies/unicode-2.12.4.jar"/> diff --git a/de.prob.core/META-INF/MANIFEST.MF b/de.prob.core/META-INF/MANIFEST.MF index e5f3cf4f8774b8777e71fb1389f22f992d3ca2a5..55cb5bf575618edcb520117f55f6d1720014c40b 100644 --- a/de.prob.core/META-INF/MANIFEST.MF +++ b/de.prob.core/META-INF/MANIFEST.MF @@ -76,7 +76,6 @@ Export-Package: com.thoughtworks.xstream, de.prob.core.sablecc.parser, de.prob.core.translator, de.prob.core.types, - de.prob.cosimulation, de.prob.eventb.translator, de.prob.eventb.translator.flow, de.prob.eventb.translator.internal, @@ -93,10 +92,7 @@ Export-Package: com.thoughtworks.xstream, de.prob.unicode, de.prob.unicode.analysis, de.prob.unicode.lexer, - de.prob.unicode.node, - org.ptolemy.fmi, - org.ptolemy.fmi.driver, - org.ptolemy.fmi.type + de.prob.unicode.node Bundle-Activator: de.prob.core.internal.Activator Eclipse-BuddyPolicy: registered Bundle-RequiredExecutionEnvironment: JavaSE-1.8 @@ -109,8 +105,6 @@ Bundle-ClassPath: ., lib/dependencies/ltlparser-2.12.4.jar, lib/dependencies/bparser-2.12.4.jar, lib/dependencies/answerparser-2.12.4.jar, - lib/dependencies/ptolemy-jfmi-1.1.0.jar, lib/dependencies/xstream-1.4.19.jar, lib/dependencies/mxparser-1.2.2.jar, - lib/dependencies/xmlpull-1.1.3.1.jar, - lib/dependencies/jna-3.4.0.jar + lib/dependencies/xmlpull-1.1.3.1.jar diff --git a/de.prob.core/build.properties b/de.prob.core/build.properties index e7303ec97ecb2367e158854a029a505bb0246cca..e6e9ffdc8bb3c72a78b9b43a614840acb75856bb 100644 --- a/de.prob.core/build.properties +++ b/de.prob.core/build.properties @@ -5,8 +5,4 @@ bin.includes = META-INF/,\ .,\ prob/,\ lib/,\ - lib/dependencies/xmlpull-1.1.3.1.jar,\ - lib/dependencies/ptolemy-jfmi-1.1.0.jar,\ - lib/dependencies/jna-3.4.0.jar - - + lib/dependencies/xmlpull-1.1.3.1.jar diff --git a/de.prob.core/src/de/prob/cosimulation/FMU.java b/de.prob.core/src/de/prob/cosimulation/FMU.java deleted file mode 100644 index d726cdea926eb06c21100d0c7da0774fb18d216a..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/cosimulation/FMU.java +++ /dev/null @@ -1,240 +0,0 @@ -package de.prob.cosimulation; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.ptolemy.fmi.FMICallbackFunctions; -import org.ptolemy.fmi.FMILibrary; -import org.ptolemy.fmi.FMIModelDescription; -import org.ptolemy.fmi.FMIScalarVariable; -import org.ptolemy.fmi.FMUFile; -import org.ptolemy.fmi.FMULibrary; - -import com.sun.jna.Function; -import com.sun.jna.NativeLibrary; -import com.sun.jna.Pointer; - -public class FMU { - - private static final double TIMEOUT = 1000; - - /** The modelIdentifier from modelDescription.xml. */ - String _modelIdentifier; - - /** The NativeLibrary that contains the functions. */ - NativeLibrary _nativeLibrary; - private Pointer component; - - private final FMIModelDescription modelDescription; - - private final Map<String, FMIScalarVariable> variables = new HashMap<String, FMIScalarVariable>(); - - private final Set<IFMUListener> listeners = new HashSet<IFMUListener>(); - - public void registerListener(final IFMUListener listener) { - listeners.add(listener); - } - - public void unregisterListener(final IFMUListener listener) { - listeners.remove(listener); - } - - public FMU(final String fmuFileName) throws IOException { - modelDescription = FMUFile.parseFMUFile(fmuFileName); - String sharedLibrary = FMUFile.fmuSharedLibrary(modelDescription); - - for (FMIScalarVariable fmiScalarVariable : modelDescription.modelVariables) { - variables.put(fmiScalarVariable.name, fmiScalarVariable); - } - - _nativeLibrary = NativeLibrary.getInstance(sharedLibrary); - - // The modelName may have spaces in it. - _modelIdentifier = modelDescription.modelIdentifier; - - // The URL of the fmu file. - String fmuLocation = new File(fmuFileName).toURI().toURL().toString(); - - // The tool to use if we have tool coupling. - String mimeType = "application/x-fmu-sharedlibrary"; - - // Timeout in ms., 0 means wait forever. - double timeout = TIMEOUT; - - // There is no simulator UI. - byte visible = 0; - // Run the simulator without user interaction. - byte interactive = 0; - // Callbacks - FMICallbackFunctions.ByValue callbacks = new FMICallbackFunctions.ByValue( - new FMULibrary.FMULogger(), new FMULibrary.FMUAllocateMemory(), - new FMULibrary.FMUFreeMemory(), - new FMULibrary.FMUStepFinished()); - // Logging tends to cause segfaults because of vararg callbacks. - byte loggingOn = (byte) 0; - - component = instantiateFMU(fmuLocation, mimeType, timeout, visible, - interactive, callbacks, loggingOn); - - if (component.equals(Pointer.NULL)) { - throw new RuntimeException("Could not instantiate model."); - } - } - - public String getFmiVersion() { - assert _nativeLibrary != null; - Function function = getFunction("_fmiGetVersion"); - return (String) function.invoke(String.class, new Object[0]); - } - - public void initialize(final double startTime, final double endTime) { - invoke("_fmiInitializeSlave", new Object[] { component, startTime, - (byte) 1, endTime }, "Could not initialize slave: "); - } - - public boolean getBoolean(final String name) { - FMIScalarVariable fmiScalarVariable = variables.get(name); - return fmiScalarVariable.getBoolean(component); - } - - public double getDouble(final String name) { - FMIScalarVariable fmiScalarVariable = variables.get(name); - return fmiScalarVariable.getDouble(component); - } - - public int getInt(final String name) { - FMIScalarVariable fmiScalarVariable = variables.get(name); - return fmiScalarVariable.getInt(component); - } - - public String getString(final String name) { - FMIScalarVariable fmiScalarVariable = variables.get(name); - return fmiScalarVariable.getString(component); - } - - public void set(final String name, final boolean b) { - FMIScalarVariable fmiScalarVariable = variables.get(name); - fmiScalarVariable.setBoolean(component, b); - } - - public void set(final String name, final int i) { - FMIScalarVariable fmiScalarVariable = variables.get(name); - fmiScalarVariable.setInt(component, i); - } - - public void set(final String name, final double d) { - FMIScalarVariable fmiScalarVariable = variables.get(name); - fmiScalarVariable.setDouble(component, d); - } - - public void set(final String name, final String s) { - FMIScalarVariable fmiScalarVariable = variables.get(name); - fmiScalarVariable.setString(component, s); - } - - public double doStep(final double time, final double delta_t) { - Function doStep = getFunction("_fmiDoStep"); - invoke(doStep, new Object[] { component, time, delta_t, (byte) 1 }, - "Could not simulate, time was " + time + ": "); - - for (IFMUListener l : listeners) { - l.trigger(variables); - } - return time + delta_t; - } - - public void terminate() { - invoke("_fmiTerminateSlave", new Object[] { component }, - "Could not terminate slave: "); - invoke("_fmiFreeSlaveInstance", new Object[] { component }, - "Could not dispose resources of slave: "); - component = null; - } - - @Override - protected void finalize() throws Throwable { - this.terminate(); - super.finalize(); - } - - public void reset() { - invoke("_fmiResetSlave", new Object[] { component }, - "Could not reset slave: "); - } - - public FMIModelDescription getModelDescription() { - return modelDescription; - } - - private Pointer instantiateFMU(final String fmuLocation, - final String mimeType, final double timeout, final byte visible, - final byte interactive, - final FMICallbackFunctions.ByValue callbacks, final byte loggingOn) { - Function instantiateSlave = getFunction("_fmiInstantiateSlave"); - Pointer fmiComponent = (Pointer) instantiateSlave.invoke(Pointer.class, - new Object[] { _modelIdentifier, modelDescription.guid, - fmuLocation, mimeType, timeout, visible, interactive, - callbacks, loggingOn }); - return fmiComponent; - } - - /** - * Return a function by name. - * - * @param name - * The name of the function. The value of the modelIdentifier is - * prepended to the value of this parameter to yield the function - * name. - * @return the function. - */ - public Function getFunction(final String name) { - // This is syntactic sugar. - return _nativeLibrary.getFunction(_modelIdentifier + name); - } - - /** - * Invoke a function that returns an integer representing the FMIStatus - * return value. - * - * @param name - * The name of the function. - * @param arguments - * The arguments to be passed to the function. - * @param message - * The error message to be used if there is a problem. The - * message should end with ": " because the return value of the - * function will be printed after the error message. - */ - public void invoke(final String name, final Object[] arguments, - final String message) { - Function function = getFunction(name); - invoke(function, arguments, message); - } - - /** - * Invoke a function that returns an integer representing the FMIStatus - * return value. - * - * @param function - * The function to be invoked. - * @param arguments - * The arguments to be passed to the function. - * @param message - * The error message to be used if there is a problem. The - * message should end with ": " because the return value of the - * function will be printed after the error message. - */ - public void invoke(final Function function, final Object[] arguments, - final String message) { - int fmiFlag = ((Integer) function.invoke(Integer.class, arguments)) - .intValue(); - if (fmiFlag > FMILibrary.FMIStatus.fmiWarning) { - throw new RuntimeException(message + fmiFlag); - } - } - -} diff --git a/de.prob.core/src/de/prob/cosimulation/IFMUListener.java b/de.prob.core/src/de/prob/cosimulation/IFMUListener.java deleted file mode 100644 index 2001ffddf65a1e1aa8941b133b3d81cf65cb5b6b..0000000000000000000000000000000000000000 --- a/de.prob.core/src/de/prob/cosimulation/IFMUListener.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.prob.cosimulation; - -import java.util.Map; - -import org.ptolemy.fmi.FMIScalarVariable; - -public interface IFMUListener { - - void trigger(Map<String, FMIScalarVariable> variables); - -}