pytwin.TwinModel#

class pytwin.TwinModel(model_filepath)#

The public class to evaluate a twin model given a twin model file (with .twin extension) created with Ansys Twin Builder. After being initialized, a twin model object can be evaluated with two modes (step-by-step or batch mode) to make predictions. Parametric workflows are also supported.

Parameters:
model_filepathstr

File path to the twin model (with .twin) extension.

Examples

Create a twin model object given the file path to the twin model file. Initialize two parameters and two inputs of the twin model. Then evaluate two steps and retrieve results in a dictionary.

>>> from pytwin import TwinModel
>>>
>>> twin_model = TwinModel(model_filepath='path_to_your_twin_model.twin')
>>>
>>> twin_model.initialize_evaluation(parameters={'param1': 1., 'param2': 2.}, inputs={'input1': 1., 'input2': 2.})
>>> outputs = dict()
>>> outputs['Time'] = [twin_model.evaluation_time]
>>> outputs['output1'] = [twin_model.outputs['output1']]
>>> outputs['output2'] = [twin_model.outputs['output2']]
>>>
>>> twin_model.evaluate_step_by_step(step_size=0.1, inputs={'input1': 10., 'input2': 20.})
>>> outputs['Time'].append(twin_model.evaluation_time)
>>> outputs['output1'].append(twin_model.outputs['output1'])
>>> outputs['output2'].append(twin_model.outputs['output2'])
>>>
>>> twin_model.evaluate_step_by_step(step_size=0.1, inputs={'input1': 20., 'input2': 30.})
>>> outputs['Time'].append(twin_model.evaluation_time)
>>> outputs['output1'].append(twin_model.outputs['output1'])
>>> outputs['output2'].append(twin_model.outputs['output2'])

Methods

TwinModel.evaluate_batch(inputs_df)

Evaluate the twin model with historical input values given with a data frame.

TwinModel.evaluate_step_by_step(step_size[, ...])

Evaluate the twin model at time instant t + step_size given inputs at time instant t.

TwinModel.get_available_view_names(rom_name)

Get a list of available view names for a given Reduced Order Model (ROM) available in the TwinModel.

TwinModel.get_geometry_filepath(rom_name)

Get the geometry file associated to a Reduced Order Model (ROM) available in the TwinModel.

TwinModel.get_image_filepath(rom_name, view_name)

Get the image file associated to a Reduced Order Model (ROM) available in the TwinModel and evaluated at the given time instant.

TwinModel.get_rom_directory(rom_name)

Get working directory path for a given Reduced Order Model (ROM) available in the TwinModel.

TwinModel.get_snapshot_filepath(rom_name[, ...])

Get the snapshot file associated to a Reduced Order Model (ROM) available in the TwinModel and evaluated at the given time instant.

TwinModel.initialize_evaluation([...])

Initialize the twin model evaluation with: (1) a dictionary of parameters values and/or inputs (start) values OR (2) a json configuration file (see example below).

TwinModel.load_state(model_id, evaluation_time)

Load a state that has been saved by a TwinModel instantiated with same .twin file.

TwinModel.save_state()

Save the state of a TwinModel.

Attributes

TwinModel.evaluation_is_initialized

Return true if evaluation has been initialized.

TwinModel.evaluation_time

Return a floating point number that is the current twin model evaluation time (in second).

TwinModel.id

Model unique id

TwinModel.initialization_time

Return a floating point number that is the time at which the twin model has been initialized.

TwinModel.inputs

Return a dictionary with input values at current evaluation time.

TwinModel.instantiation_time

Return a floating point number that is the time at which the twin model has been instantiated.

TwinModel.model_dir

Model directory (within the global working directory)

TwinModel.model_filepath

Return a string that is the twin model filepath that has been verified and loaded.

TwinModel.model_log

Path to model log file that is used at TwinRuntime instantiation (because we don't know the model name before having instantiated it and this can't use the model_dir in the log file path that is given at instantiation).

TwinModel.model_log_link

Path to symbolic link to the log file in the temporary folder and that is stored in the model_dir.

TwinModel.model_temp

Model temporary directory (within the global working directory).

TwinModel.name

Model name.

TwinModel.outputs

Return a dictionary with output values at current evaluation time.

TwinModel.parameters

Return a dictionary with parameter values at current evaluation time.

TwinModel.tbrom_directory_path

Return TBROM directory path.

TwinModel.tbrom_info

Return a dictionary with TBROM model names included in the Twin and their corresponding 3D visualization capabilities available (e.g.

TwinModel.tbrom_names

Return available TBROM model names.