Simulate your model¶
So far, you have collected measurement data and stored them in a Dataset object.
Next, you need to collect simulated data. How? You should feed your model with the input signals stored in the Dataset object that you prepared.
To extract the input signals from your Dataset object, you
can use the method dataset_values() and then
use these signals to feed your model:
# Assuming `ds` is a measurements Dataset object
(t, u_meas, y_meas) = ds.dataset_values()
# Assume you are using a simulation tool that has a Python API with
# a function called 'simulate_model()`
y_sim = simulate_model(time = t, input= u_meas)
Alternatively, you can export your Dataset object in the
format you need and import it into your modeling tool. To facilitate this
task, Dymoval allows you to dump Dataset objects into
Dymoval.Signal objects through the method
dump_to_signals().
# List containing Signal objects
signal_list = ds.dump_to_signals()
However, you will then need to manually export these signals in an appropriate
format depending on your modeling tool. Given the popularity of Matlab,
Dataset class has a
export_to_mat() method:
signal_list = ds.export_to_mat("./my_measurements.mat")
Once you have simulated your model, you should import the simulated data back into Python. At this point, you are ready to validate your model.
Note
Exporting/importing signals from/to Python to/from your modeling tool may be fairly annoying. For this reason, we recommend compiling your model into an FMU and using packages like pyfmu or fmpy to simulate your model directly from a Python environment, so you have everything in one place.
Regardless of your modeling tool (Simulink, Dymola, GT-Power, etc.), you most likely have an option for compiling models into FMUs. Check the documentation of your modeling tool for more details.