org.javafmi.wrapper.v1.Access Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fmu-wrapper Show documentation
Show all versions of fmu-wrapper Show documentation
javaFMI is a Java Library for the functional mock-up interface (or FMI). FMI defines a standardized interface to be used in computer simulations. The FMI Standard has beed developed by a large number of software companies and research centers that have worked in a cooperation project under the name of MODELISAR. This library addresses the connection of a java application with a FMU (functional mock-up unit).
/*
* Copyright 2013-2016 SIANI - ULPGC
*
* This File is part of JavaFMI Project
*
* JavaFMI Project is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* JavaFMI Project is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JavaFMI. If not, see .
*/
package org.javafmi.wrapper.v1;
import org.javafmi.modeldescription.v1.Capabilities;
import org.javafmi.modeldescription.v1.ModelDescription;
import org.javafmi.modeldescription.v1.ScalarVariable;
import org.javafmi.proxy.FmuFile;
import org.javafmi.proxy.Status;
import org.javafmi.proxy.v1.FmuProxy;
import org.javafmi.wrapper.Simulation;
public class Access implements FmuView {
private final ModelDescription modelDescription;
private final FmuFile fmuFile;
private final FmuProxy proxy;
public Access(Simulation simulation) {
this(new ProxyRetriever(simulation).proxy,
(ModelDescription) simulation.getModelDescription(),
simulation.getFmuFile());
}
Access(FmuProxy proxy, ModelDescription modelDescription, FmuFile fmuFile) {
this.proxy = proxy;
this.modelDescription = modelDescription;
this.fmuFile = fmuFile;
}
@Override
public ModelDescription getModelDescription() {
return modelDescription;
}
@Override
public boolean check(Capabilities.Capability capability) {
throw new UnsupportedOperationException();
}
@Override
public ScalarVariable[] getModelVariables() {
return modelDescription.getModelVariables();
}
@Override
public ScalarVariable getModelVariable(String varName) {
return modelDescription.getModelVariable(varName);
}
public String getVersion() {
return proxy.getVersion();
}
public void instantiate(double timeout) {
proxy.instantiate(fmuFile.getResourcesDirectoryPath());
}
public Status terminate() {
return proxy.terminate();
}
public Status reset() {
return proxy.reset();
}
public void freeInstance() {
proxy.freeInstance();
}
public Status doStep(double simulationTime, double stepSize) {
return proxy.doStep(simulationTime, stepSize);
}
public Status cancelStep() {
return proxy.cancelStep();
}
public Object getEnumeration(ScalarVariable modelVariable) {
return proxy.getEnumeration(modelVariable);
}
public double[] getReal(int... valueReference) {
return proxy.getReal(valueReference);
}
public int[] getInteger(int... valueReference) {
return proxy.getInteger(valueReference);
}
public boolean[] getBoolean(int... valueReference) {
return proxy.getBoolean(valueReference);
}
public String[] getString(int... valueReference) {
return proxy.getString(valueReference);
}
public Status setReal(int[] valueReference, double[] newValue) {
return proxy.setReal(valueReference, newValue);
}
public Status setInteger(int[] valueReference, int[] newValue) {
return proxy.setInteger(valueReference, newValue);
}
public Status setBoolean(int[] valueReference, boolean[] newValue) {
return proxy.setBoolean(valueReference, newValue);
}
public Status setString(int[] valueReference, String[] newValue) {
return proxy.setString(valueReference, newValue);
}
public Status setIsDoingLogging(boolean isDoingLogging) {
return proxy.setIsDoingLogging(isDoingLogging);
}
public boolean isTerminated() {
return proxy.isTerminated();
}
private static class ProxyRetriever extends Simulation {
private final FmuProxy proxy;
private ProxyRetriever(Simulation simulation) {
checkVersion(simulation);
this.proxy = (FmuProxy) getProxy(simulation);
}
private void checkVersion(Simulation simulation) {
if (getProxy(simulation) instanceof FmuProxy) return;
throw new RuntimeException("Access to FMU does not match with Simulation version");
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy