The short answer is yes the tools you mention are set up to do what you are asking.
A long answer can be found for FMPy:
But the gist is to perform changes during simulation like you are asking the
approach you want you need to go a layer deeper than simulate_fmu
and use doStep
and associated setup. The functions/approach needed for these are defined by the FMI standard while highler level implmentations like simulate_fmu
are not and are therefore tool dependent implementations of the standard.
The cliff notes are:
- Prep the Simulation Inputs
- e.g., unzip the FMU, define simulation setup, and instantiate the FMU
from fmpy import read_model_description, extract
from fmpy.fmi2 import FMU2Slave
# extract the FMU
unzipdir = extract(fmu_filename)
fmu = FMU2Slave(guid=model_description.guid,
unzipDirectory=unzipdir,
modelIdentifier=model_description.coSimulation.modelIdentifier,
instanceName='instance1')
# initialize
fmu.instantiate()
fmu.setupExperiment(startTime=start_time)
fmu.enterInitializationMode()
fmu.exitInitializationMode()
- Simulation Loop
- Set/Get values (can do this before and/or after timestep):
fmu.setReal
and fmu.getReal
- Solve the time step (
fmu.doStep
)
- Store values
- Loop until complete
- Terminate Simulation:
fmu.terminate()
and fmu.freeInstance
- Plot results
- Celebrate!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…