evaluate_step_by_step#

TwinModel.evaluate_step_by_step(step_size, inputs=None, field_inputs=None)#

Evaluate the twin model at time instant t plus a step size given inputs at time instant t.

Twin model evaluation must have been initialized before calling this evaluation method. For more information, see the pytwin.TwinModel.initialize_evaluation() method.

Note

if field_inputs are supplied for a TBROM, they will override any input mode coefficient inputs for that ROM that are included in inputs.

Parameters:
step_sizefloat

Step size in seconds to reach the next time step. The value must be positive.

inputsdict (optional)

Dictionary of scalar input values ({“name”: value}) at time instant t. An input is not updated if the associated key is not found in the twin model’s input_names property. If values for inputs are not provided in the dictionary, their current values are kept.

field_inputsdict (optional)

Dictionary of input fields snapshots ({“tbromname”: {“inputfieldname”: snapshot}}) to use for twin model evaluation. snapshot may be a Numpy array, or string for path of snapshot file.

Examples

>>> from pytwin import TwinModel
>>>
>>> # Example 1 - Evaluate step by step with scalar inputs and scalar outputs
>>> twin_model = TwinModel(model_filepath='path_to_your_twin_model.twin')
>>> twin_model.initialize_evaluation()
>>> twin_model.evaluate_step_by_step(step_size=0.1, inputs={'input1': 1., 'input2': 2.})
>>> scalar_results = {'Time': twin_model.evaluation_time, 'Outputs': twin_model.outputs}
>>>
>>> # Example 2 - Evaluate step by step with field input from disk and field output to disk
>>> twin_model = TwinModel(model_filepath='path_to_your_twin_model.twin')
>>> twin_model.initialize_evaluation()
>>> romname = twin_model.tbrom_names[0]
>>> fieldname = twin_model.get_field_input_names(romname)[0]
>>> twin_model.evaluate_step_by_step(step_size=0.1, inputs={'input1': 1., 'input2': 2.},
>>>                                  field_inputs={romname: {fieldname:'path_to_the_snapshot.bin'}})
>>> field_output = twin_model.generate_snapshot(rom_name=romname, on_disk=True)
>>> field_results = {'Time': twin_model.evaluation_time, 'Field': field_output}
>>>
>>> # Example 3 - Evaluate step by step with field input from memory and field output in memory
>>> twin_model = TwinModel(model_filepath='path_to_your_twin_model.twin')
>>> twin_model.initialize_evaluation()
>>> romname = twin_model.tbrom_names[0]
>>> fieldname = twin_model.get_field_input_names(romname)[0]
>>> snapshot = np.array([3.14, 2.71, 9.81, 6.02])
>>> twin_model.evaluate_step_by_step(step_size=0.1, inputs={'input1': 1., 'input2': 2.},
>>>                                  field_inputs={romname: {fieldname:snapshot}})
>>> field_output = twin_model.generate_snapshot(rom_name=romname, on_disk=False)
>>> field_results = {'Time': twin_model.evaluation_time, 'Field': field_output}