Set FMU simulation parameters#

FMUPointToFieldFunction is an OpenTURNS-friendly overlay of the class otfmi.OpenTURNSFMUPointToFieldFunction, closer to the underlying FMI backend implementation. Some FMU simulation parameters can be given to FMUPointToFieldFunction, yet most of them can only be passed to an OpenTURNSFMUPointToFieldFunction.

First, retrieve the path to epid.fmu.

import otfmi.example.utility
import openturns as ot

path_fmu = otfmi.example.utility.get_path_fmu("epid")

The FMU simulation start and final times are the only simulation-related parameter that can be passed to FMUPointToFieldFunction.

function = otfmi.FMUPointToFieldFunction(
    path_fmu,
    inputs_fmu=["infection_rate", "healing_rate"],
    outputs_fmu=["infected"],
    start_time=0.0,
    final_time=15.0,
)

inputPoint = ot.Point([2.0, 0.5])
outputSample = function(inputPoint)
print(outputSample)
      [ infected  ]
  0 : [   1       ]
  1 : [   1.15797 ]
  2 : [   1.34053 ]
  3 : [   1.55145 ]
  4 : [   1.79618 ]
  5 : [   2.07889 ]
  6 : [   2.40535 ]
  7 : [   2.78394 ]
  8 : [   3.22099 ]
  9 : [   3.72531 ]
 10 : [   4.30964 ]
 11 : [   4.98352 ]
 12 : [   5.76024 ]
 13 : [   6.65894 ]
 14 : [   7.6938  ]
 15 : [   8.88445 ]
 16 : [  10.2592  ]
 17 : [  11.8385  ]
 18 : [  13.6506  ]
 19 : [  15.7361  ]
 20 : [  18.1233  ]
 21 : [  20.851   ]
 22 : [  23.9749  ]
 23 : [  27.5311  ]
 24 : [  31.5692  ]
 25 : [  36.1597  ]
 26 : [  41.3426  ]
 27 : [  47.1733  ]
 28 : [  53.7293  ]
 29 : [  61.0422  ]
 30 : [  69.1578  ]
 31 : [  78.1392  ]
 32 : [  87.9855  ]
 33 : [  98.7031  ]
 34 : [ 110.303   ]
 35 : [ 122.718   ]
 36 : [ 135.879   ]
 37 : [ 149.702   ]
 38 : [ 164.032   ]
 39 : [ 178.704   ]
 40 : [ 193.528   ]
 41 : [ 208.281   ]
 42 : [ 222.739   ]
 43 : [ 236.65    ]
 44 : [ 249.803   ]
 45 : [ 261.995   ]
 46 : [ 273.007   ]
 47 : [ 282.727   ]
 48 : [ 291.048   ]
 49 : [ 297.856   ]
 50 : [ 303.17    ]
 51 : [ 306.998   ]
 52 : [ 309.338   ]
 53 : [ 310.303   ]
 54 : [ 309.981   ]
 55 : [ 308.439   ]
 56 : [ 305.829   ]
 57 : [ 302.263   ]
 58 : [ 297.837   ]
 59 : [ 292.69    ]
 60 : [ 286.93    ]
 61 : [ 280.645   ]
 62 : [ 273.945   ]
 63 : [ 266.916   ]
 64 : [ 259.628   ]
 65 : [ 252.159   ]
 66 : [ 244.568   ]
 67 : [ 236.908   ]
 68 : [ 229.228   ]
 69 : [ 221.568   ]
 70 : [ 213.963   ]
 71 : [ 206.442   ]
 72 : [ 199.029   ]
 73 : [ 191.747   ]
 74 : [ 184.61    ]
 75 : [ 177.63    ]
 76 : [ 170.824   ]
 77 : [ 164.195   ]
 78 : [ 157.748   ]
 79 : [ 151.493   ]
 80 : [ 145.427   ]
 81 : [ 139.552   ]
 82 : [ 133.873   ]
 83 : [ 128.384   ]
 84 : [ 123.083   ]
 85 : [ 117.972   ]
 86 : [ 113.045   ]
 87 : [ 108.297   ]
 88 : [ 103.729   ]
 89 : [  99.3328  ]
 90 : [  95.1037  ]
 91 : [  91.0421  ]
 92 : [  87.1385  ]
 93 : [  83.3882  ]
 94 : [  79.7909  ]
 95 : [  76.3374  ]
 96 : [  73.023   ]
 97 : [  69.847   ]
 98 : [  66.8007  ]
 99 : [  63.8794  ]
100 : [  61.0825  ]
101 : [  58.4016  ]
102 : [  55.8325  ]
103 : [  53.3743  ]
104 : [  51.0195  ]
105 : [  48.7641  ]
106 : [  46.6072  ]
107 : [  44.542   ]
108 : [  42.5649  ]
109 : [  40.6749  ]
110 : [  38.866   ]
111 : [  37.1349  ]
112 : [  35.4807  ]
113 : [  33.8979  ]
114 : [  32.3837  ]
115 : [  30.9372  ]
116 : [  29.5535  ]
117 : [  28.2301  ]
118 : [  26.9662  ]
119 : [  25.7575  ]
120 : [  24.6017  ]
121 : [  23.4981  ]
122 : [  22.4428  ]
123 : [  21.434   ]
124 : [  20.4708  ]
125 : [  19.5501  ]
126 : [  18.6699  ]
127 : [  17.8298  ]
128 : [  17.0267  ]
129 : [  16.2592  ]
130 : [  15.5266  ]
131 : [  14.8264  ]
132 : [  14.1573  ]
133 : [  13.5188  ]
134 : [  12.9086  ]
135 : [  12.3254  ]
136 : [  11.769   ]
137 : [  11.2373  ]
138 : [  10.7293  ]
139 : [  10.2445  ]
140 : [   9.78135 ]
141 : [   9.33882 ]
142 : [   8.9166  ]
143 : [   8.51321 ]
144 : [   8.12781 ]
145 : [   7.76013 ]
146 : [   7.40886 ]
147 : [   7.07328 ]
148 : [   6.75314 ]
149 : [   6.44731 ]
150 : [   6.15515 ]

To set more parameters for the FMU simulation, OpenTURNSFMUPointToFieldFunction can be employed. Backend-specific options use the pyfmi_options/fmpy_options keywords: only the ones matching the model’s backend are taken into account. Below, silent mode is requested from the PyFMI backend.

midlevel_function = otfmi.OpenTURNSFMUPointToFieldFunction(
    path_fmu,
    inputs_fmu=["infection_rate", "healing_rate"],
    outputs_fmu=["infected"],
    start_time=0.0,
    final_time=15.0,
)

outputPoint = midlevel_function.base.simulate(
    inputPoint, algorithm="FMICSAlg", pyfmi_options={"silent_mode": True}
)

For advanced users, the middle-level class otfmi.OpenTURNSFMUPointToFieldFunction also gives access to the underlying backend model. We can hence access all its object methods:

fmu_model = midlevel_function.base.get_model()
print(dir(fmu_model))
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__pyx_vtable__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '_additional_logger', '_close_log_file', '_convert_filter', '_current_log_size', '_deactivate_logging', '_default_options', '_enable_logging', '_exec_algorithm', '_exec_estimate_algorithm', '_exec_simulate_algorithm', '_get', '_get_A', '_get_B', '_get_C', '_get_D', '_get_default_log_file_name', '_get_directional_proxy', '_get_module_name', '_get_time', '_group_A', '_group_B', '_group_C', '_group_D', '_has_entered_init_mode', '_init_log_state', '_invoked_dealloc', '_last_accepted_time', '_loaded_with_log_level', '_log_handler', '_log_is_stream', '_log_open', '_log_stream', '_log_stream_is_open', '_max_log_size', '_max_log_size_msg_sent', '_open_log_file', '_provides_directional_derivatives', '_pyEventInfo', '_relative_tolerance', '_result_file', '_save_bool_variables_val', '_save_int_variables_val', '_save_real_variables_val', '_set', '_set_log_stream', '_set_time', '_setup_log_state', '_supports_get_set_FMU_state', 'append_log_message', 'cache', 'cancel_step', 'deserialize_fmu_state', 'do_step', 'enter_initialization_mode', 'estimate', 'estimate_options', 'exit_initialization_mode', 'extract_xml_log', 'file_object', 'free_fmu_state', 'free_instance', 'get', 'get_author', 'get_boolean', 'get_boolean_status', 'get_capability_flags', 'get_categories', 'get_copyright', 'get_default_experiment_start_time', 'get_default_experiment_step', 'get_default_experiment_stop_time', 'get_default_experiment_tolerance', 'get_derivatives_dependencies', 'get_derivatives_dependencies_kind', 'get_derivatives_list', 'get_description', 'get_directional_derivative', 'get_fmil_log_level', 'get_fmu_kind', 'get_fmu_state', 'get_generation_date_and_time', 'get_generation_tool', 'get_guid', 'get_identifier', 'get_input_list', 'get_integer', 'get_integer_status', 'get_last_result_file', 'get_license', 'get_log', 'get_log_categories', 'get_log_filename', 'get_log_level', 'get_max_log_size', 'get_model_time_varying_value_references', 'get_model_types_platform', 'get_model_variables', 'get_model_version', 'get_name', 'get_number_of_lines_log', 'get_ode_sizes', 'get_output_dependencies', 'get_output_dependencies_kind', 'get_output_derivatives', 'get_output_list', 'get_real', 'get_real_status', 'get_scalar_variable', 'get_state_space_representation', 'get_states_list', 'get_status', 'get_string', 'get_string_status', 'get_unpacked_fmu_path', 'get_variable_alias', 'get_variable_alias_base', 'get_variable_by_valueref', 'get_variable_causality', 'get_variable_data_type', 'get_variable_declared_type', 'get_variable_description', 'get_variable_display_unit', 'get_variable_display_value', 'get_variable_initial', 'get_variable_max', 'get_variable_min', 'get_variable_naming_convention', 'get_variable_nominal', 'get_variable_references', 'get_variable_relative_quantity', 'get_variable_start', 'get_variable_unbounded', 'get_variable_unit', 'get_variable_valueref', 'get_variable_variability', 'get_version', 'has_reached_max_log_size', 'initialize', 'instantiate', 'print_log', 'reset', 'serialize_fmu_state', 'serialized_fmu_state_size', 'set', 'set_additional_logger', 'set_boolean', 'set_debug_logging', 'set_fmu_state', 'set_input_derivatives', 'set_integer', 'set_log_level', 'set_max_log_size', 'set_real', 'set_string', 'setup_experiment', 'simulate', 'simulate_options', 'terminate', 'time']

Note

otfmi’ classes FMUPointToFieldFunction and otfmi.OpenTURNSFMUPointToFieldFunction are designed to highlight the most useful backend methods and simplify their use!

Total running time of the script: (0 minutes 0.107 seconds)