I have a FMU which I am attempting to simulate in JModelica. The input
parameter needs to refer to the current state of some of the variables in the JModelica FMU simulation. However, I'm having trouble accessing these.
Reading the documentation, I would be given to believe that the functions .get_variable_nominal()
or .get()
would provide access to these, but this is not the case.
The basic structure of the code is as follows:
from pyfmi import load_fmu
model = none
def inputFunction(t):
global model
# Get current state of desired variable(s)
variable = model.some_function("object.variable_name")
# Do some mathematical process to get input value
input_value = foo(variable)
return input_value
def main():
global model
# FMU's input variables
inputs = ["list", "of", "input", "variables"]
# Get model from FMU file
model = load_fmu("model_name.fmu")
# Create input object for simulation method
inputObj = (inputs, inputFunction)
# Do some simulation
opts = model.simulate_options()
results = model.simulate(start_time=0, final_time=100.0, input=inputObj, options=opts)
if __name__ == "__main__":
main()
If in the place of .some_function("object.variable_name")
, I use .get_variable_nominal("object.variable_name")
, the function returns a float value of 1.0
(I seem to get different arbitrary values if I specify a different FMU variable). Whereas with .get("object.variable_name")
, the error FMUException: Failed to get the Real values.
is returned. The value I am expecting at the beginning of the simulation is a float
value of approximately 303
.
Note that the FMU simulation behaves correctly if run with fixed input values, so the correct values are indeed stored in the model.
Thank-you to anyone who can help me understand what is going on here.