TwinModel#

class pytwin.TwinModel(model_filepath)#

Evaluates a twin model in a TWIN file created by Ansys Twin Builder.

After a twin model is initialized, it can be evaluated with two modes (step-by-step or batch). to make predictions. Parametric workflows are also supported.

Parameters:
model_filepathstr

File path to the TWIN file for the twin model.

Examples

Create the twin model given the file path to the TWIN file. Initialize two parameters and two inputs of the twin model. Then, evaluate the two steps and retrieve the 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.close()

Cleanup object when user asks to close it.

TwinModel.evaluate_batch(inputs_df[, ...])

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

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

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

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

Generate a points file either in memory or on disk, for the full domain or a specific part.

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

Generate a field snapshot based on current states of the Twin, either in memory or on disk, for the full field or a specific part.

TwinModel.generate_snapshot_batch(...[, ...])

Generate several field snapshots based on historical batch results of the Twin, either in memory or on disk, for the full field or a specific named selection.

TwinModel.get_available_view_names(rom_name)

Get a list of view names for a ROM (reduced order model) in the twin model.

TwinModel.get_field_input_names(rom_name)

Get the list of input fields names associated to the TBROM named rom_name

TwinModel.get_field_output_name(rom_name)

Get the output field name associated to the TBROM named rom_name

TwinModel.get_geometry_filepath(rom_name)

Get the geometry file associated with a ROM available in the twin model.

TwinModel.get_image_filepath(rom_name, view_name)

Get the image file that was created by the given ROM at the given time instant.

TwinModel.get_named_selections(rom_name)

Get the list of named selections associated to the TBROM named rom_name

TwinModel.get_rom_directory(rom_name)

Get the working directory path for a ROM in the twin model.

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

Get the snapshot file that was created by the given ROM at the given time instant.

TwinModel.get_tbrom_output_field(rom_name)

Return the TBROM output field as a PyVista DataSet object, in the form of point cloud data.

TwinModel.initialize_evaluation([...])

Initialize evaluation of a twin model.

TwinModel.load_state(model_id, evaluation_time)

Load a state that has been saved by a twin model instantiated with the same TWIN file.

TwinModel.project_tbrom_on_mesh(rom_name, ...)

Project the field ROM data onto a targeted mesh, using the current states of the TwinModel.

TwinModel.save_state()

Save the state of the twin model after its initialization and after step-by-step evaluation.

Attributes

TwinModel.TBROM_FILENAME_TIME_FORMAT

TwinModel.TBROM_FOLDER_NAME

TwinModel.TBROM_IMAGE_EXT

TwinModel.TBROM_SNAPSHOT_EXT

TwinModel.TBROM_SNAPSHOT_FILE_PREFIX

TwinModel.TBROM_VIEWS_KEY

TwinModel.evaluation_is_initialized

Indicator for if the evaluation has been initialized.

TwinModel.evaluation_time

Floating point number that is the current twin model evaluation time in seconds.

TwinModel.id

Model unique ID.

TwinModel.initialization_time

Floating point number that is the time at which the twin model has been initialized.

TwinModel.inputs

Dictionary with input values at the current evaluation time.

TwinModel.instantiation_time

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

Filepath for the twin model that has been verified and loaded.

TwinModel.model_log

Path to the model log file that is used at twin runtime instantiation.

TwinModel.model_log_link

Path to the symbolic link to the model log file.

TwinModel.model_temp

Model temporary directory (within the global working directory).

TwinModel.name

Model name.

TwinModel.outputs

Dictionary with output values at the current evaluation time.

TwinModel.parameters

Dictionary with parameter values at the current evaluation time.

TwinModel.tbrom_count

Return number of TBROM contained in the Twin.

TwinModel.tbrom_directory_path

TBROM directory path.

TwinModel.tbrom_info

Dictionary with TBROM model names included in the twin model and their corresponding 3D visualization capabilities.

TwinModel.tbrom_names

List of available TBROM names.