MODSIM_TEMPLATE API#
rectangle_geometry.py#
- modsim_package.rectangle_geometry.get_parser()[source]
Return parser for CLI options
All options should use the double-hyphen
--option VALUE
syntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag
. Single hyphen-f
flag syntax often clashes with the Abaqus command line options and should be avoided.- Returns:
parser
- Return type:
argparse.ArgumentParser
- modsim_package.rectangle_geometry.main(output_file, model_name, part_name, width, height)[source]
Create a simple rectangle geometry.
This script creates a simple Abaqus model with a single rectangle part.
- Parameters:
output_file (str) – The output file for the Abaqus model. Will be stripped of the extension and
.cae
will be used.model_name (str) – The name of the Abaqus model
part_name (str) – The name of the Abaqus part
width (float) – The rectangle width
height (float) – The rectangle height
- Returns:
writes
output_file
.cae andoutput_file
.jnl
rectangle_partition.py#
- modsim_package.rectangle_partition.get_parser()[source]
Return parser for CLI options
All options should use the double-hyphen
--option VALUE
syntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag
. Single hyphen-f
flag syntax often clashes with the Abaqus command line options and should be avoided.- Returns:
parser
- Return type:
argparse.ArgumentParser
- modsim_package.rectangle_partition.main(input_file, output_file, model_name, part_name, width, height)[source]
Partition the simple rectangle geometry created by
rectangle_geometry.py
This script partitions a simple Abaqus model with a single rectangle part.
Feature labels:
bottom_left
- bottom left vertexbottom_right
- bottom right vertextop_right
- top right vertextop_left
- top left vertexleft
- left edgetop
- top edgeright
- right edgebottom
- bottom edge
- Parameters:
input_file (str) – The Abaqus model file created by
rectangle_geometry.py
. Will be stripped of the extension and.cae
will be used.output_file (str) – The output file for the Abaqus model. Will be stripped of the extension and
.cae
will be used.model_name (str) – The name of the Abaqus model
part_name (str) – The name of the Abaqus part
width (float) – The rectangle width
height (float) – The rectangle height
- Returns:
writes
output_file
.cae andoutput_file
.jnl
rectangle_mesh.py#
- modsim_package.rectangle_mesh.get_parser()[source]
Return parser for CLI options
All options should use the double-hyphen
--option VALUE
syntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag
. Single hyphen-f
flag syntax often clashes with the Abaqus command line options and should be avoided.- Returns:
parser
- Return type:
argparse.ArgumentParser
- modsim_package.rectangle_mesh.main(input_file, output_file, model_name, part_name, global_seed)[source]
Mesh the simple rectangle geometry partitioned by
rectangle_partition.py
This script meshes a simple Abaqus model with a single rectangle part.
Feature labels:
NODES
- all part nodesELEMENTS
- all part elements
- Parameters:
input_file (str) – The Abaqus model file created by
rectangle_partition.py
. Will be stripped of the extension and.cae
will be used.output_file (str) – The output file for the Abaqus model. Will be stripped of the extension and
.cae
and.inp
will be used for the model and orphan mesh output files, respectively.model_name (str) – The name of the Abaqus model
part_name (str) – The name of the Abaqus part
global_seed (float) – The global mesh seed size
- Returns:
output_file
.cae,output_file
.jnl,output_file
.inp
rectangle_compression.py#
Parameter sets and schemas for the rectangle compression simulation
- modsim_package.rectangle_compression.mesh_convergence(width=[1.0], height=[1.0], global_seed=[1.0, 0.5, 0.25, 0.125], displacement=[-0.01])[source]
Return mesh convergence WAVES CartesianProduct schema dictionary
- Parameters:
global_seed (float) – The global mesh seed size
- Returns:
WAVES CartesianProduct schema
- Return type:
dict
- modsim_package.rectangle_compression.nominal(width=1.0, height=1.0, global_seed=1.0, displacement=-0.01)[source]
Return nominal simulation variables dictionary
- Parameters:
width (float) – The rectangle width
height (float) – The rectangle height
global_seed (float) – The global mesh seed size
displacement (float) – The rectangle top surface displacement
- Returns:
nominal simulation variables
- Return type:
dict
export_abaqus_image.py#
- modsim_package.export_abaqus_image.get_parser()[source]
Return parser for CLI options
All options should use the double-hyphen
--option VALUE
syntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag
. Single hyphen-f
flag syntax often clashes with the Abaqus command line options and should be avoided.- Returns:
parser
- Return type:
argparse.ArgumentParser
- modsim_package.export_abaqus_image.image(output_file, x_angle=0.0, y_angle=0.0, z_angle=0.0, image_size=(1920, 1080), model_name='Model-1', part_name='Part-1', color_map='Material')[source]
Save an assembly view image of an Abaqus model from an input or CAE file.
The viewer window is adjusted by the provided x, y, and z angles and the viewport is set to fit the assembly prior to saving an image of the viewport screen.
If the model assembly has no instances, use
part_name
to generate one. Theinput_file
is not modified to include this generated instance.- Parameters:
output_file (str) – Output image file. Supports
*.png
and*.svg
.x_angle (float) – Rotation about X-axis in degrees for
abaqus.session.viewports[].view.rotate
Abaqus Python methody_angle (float) – Rotation about Y-axis in degrees for
abaqus.session.viewports[].view.rotate
Abaqus Python methodz_angle (float) – Rotation about Z-axis in degrees for
abaqus.session.viewports[].view.rotate
Abaqus Python methodimage_size (tuple) – Tuple containing height and width of the output image in pixels
model_name (str) – model to query in the Abaqus model database
part_name (str) – part to query in the specified Abaqus model
color_map (str) – color map key
- Returns:
writes image to
{output_file}
- modsim_package.export_abaqus_image.main(input_file, output_file, x_angle=0.0, y_angle=0.0, z_angle=0.0, image_size=(1920, 1080), model_name='Model-1', part_name='Part-1', color_map='Material')[source]
Save an assembly view image of an Abaqus model from an input or CAE file.
Open an Abaqus CAE
*.cae
or input*.inp
file and save an assembly view image. Abaqus CAE files are copied to a temporary file before opening to avoid file modification, which is necessary for compatibility with build systems such as SCons.- Parameters:
input_file (str) – Abaqus input file. Supports
*.inp
and*.cae
.output_file (str) – Output image file. Supports
*.png
and*.svg
.x_angle (float) – Rotation about X-axis in degrees for
abaqus.session.viewports[].view.rotate
Abaqus Python methody_angle (float) – Rotation about Y-axis in degrees for
abaqus.session.viewports[].view.rotate
Abaqus Python methodz_angle (float) – Rotation about Z-axis in degrees for
abaqus.session.viewports[].view.rotate
Abaqus Python methodimage_size (tuple) – Tuple containing height and width of the output image in pixels
model_name (str) – model to query in the Abaqus model database
part_name (str) – part to query in the specified Abaqus model
color_map (str) – color map key
- Returns:
writes image to
{output_file}
abaqus_utilities.py#
Abaqus utilities to be re-used in multiple places
- class modsim_package.abaqus_utilities.AbaqusNamedTemporaryFile(input_file, *args, **kwargs)[source]
Bases:
object
Open an Abaqus CAE
input_file
as a temporary file. Close and delete on exit of context manager.Provides Windows compatible temporary file handling. Required until Python 3.12
delete_on_close=False
option is available in Abaqus Python.- Parameters:
input_file (str) – The input file to copy before open
- modsim_package.abaqus_utilities.export_mesh(model_object, part_name, orphan_mesh_file)[source]
Export an orphan mesh for the specified part instance in an Abaqus model
Using an abaqus model object (
model_object = abaqus.mdb.models[model_name]
) with part(s) that are meshed and instanced in an assembly, get the*.inp
keyword blocks and save an orphan mesh file,orphan_mesh_file
.inp, for the specificpart_name
.- Parameters:
model_object (abaqus.mdb.models[model_name]) – Abaqus model object
part_name (str) – Part name to export as an orphan mesh
orphan_mesh_file (str) – File name to write for the orphan mesh. Will be stripped of the extension and
.cae
will be used, e.g.orphan_mesh_file
.inp
- Returns:
writes
orphan_mesh_file
.inp
- modsim_package.abaqus_utilities.return_abaqus_constant(search)[source]
If search is found in the abaqusConstants module, return the abaqusConstants object.
- Parameters:
search (str) – string to search in the abaqusConstants module attributes
- Return value:
abaqusConstants attribute
- Return type:
abaqusConstants.<search>
- Raises:
ValueError – If the search string is not found.
argparse_types.py#
Python 2/3 compatible argparse types for input verification
- modsim_package.argparse_types.positive_float(argument)[source]
Type function for argparse - positive floats
Abaqus Python 2 and Python 3 compatible argparse type method: https://docs.python.org/3.12/library/argparse.html#type.
- Parameters:
argument (str) – string argument from argparse
- Returns:
argument
- Return type:
float
- Raises:
ValueError –
The argument can’t be cast to float
The argument is less than 0.0 in a float comparison
utilities.py#
Python 3 utilities not compatible with Abaqus Python 2
- modsim_package.utilities.combine_data(input_files, group_path, concat_coord)[source]
Combine input data files into one dataset
- Parameters:
input_files (list) – list of path-like or file-like objects pointing to h5netcdf files containing Xarray Datasets
group_path (str) – The h5netcdf group path locating the Xarray Dataset in the input files.
concat_coord (str) – Name of dimension
- Returns:
Combined data
- Return type:
xarray.DataArray
- modsim_package.utilities.csv_files_match(current_csv, expected_csv, index_column='time', sort_columns=['time', 'set_name'])[source]
Compare two pandas DataFrame objects and determine if they match.
- Parameters:
current_csv (pandas.DataFrame) – Current CSV data of generated plot.
expected_csv (pandas.DataFrame) – Expected CSV data.
- Returns:
True if the CSV files match, False otherwise.
- Return type:
bool
- modsim_package.utilities.merge_parameter_study(parameter_study_file, combined_data)[source]
Merge parameter study to existing dataset
- Parameters:
parameter_study_file (str) – path-like or file-like object containing the parameter study dataset. Assumes the h5netcdf file contains only a single dataset at the root group path, .e.g.
/
.combined_data (xarray.DataArray) – XArray Dataset that will be merged.
- Returns:
Combined data
- Return type:
xarray.DataArray
- modsim_package.utilities.save_plot(combined_data, x_var, y_var, selection_dict, concat_coord, output_file)[source]
Save scatter plot with given x and y labels
- Parameters:
combined_data (xarray.DataArray) – XArray Dataset that will be plotted.
x_var (str) – The independent (x-axis) variable key name for the Xarray Dataset “data variable”
y_var (str) – The dependent (y-axis) variable key name for the Xarray Dataset “data variable”
selection_dict (dict) – Dictionary to define the down selection of data to be plotted. Dictionary
key: value
pairs must match the data variables and coordinates of the expected Xarray Dataset object.concat_coord (str) – Name of dimension for which you want multiple lines plotted.
output_file (str) – The plot file name. Relative or absolute path.
- modsim_package.utilities.save_table(combined_data, selection_dict, output_file)[source]
Save csv table
- Parameters:
combined_data (xarray.DataArray) – XArray Dataset to be written as a CSV.
selection_dict (dict) – Dictionary to define the down selection of data to be plotted. Dictionary
key: value
pairs must match the data variables and coordinates of the expected Xarray Dataset object.output_file (str) – The CSV file name. Relative or absolute path.
- modsim_package.utilities.sort_dataframe(dataframe, index_column='time', sort_columns=['time', 'set_name'])[source]
Return a sorted dataframe and set an index
sort columns by column name
sort rows by column values
sort_columns
set an index
- Returns:
sorted and indexed dataframe
- Return type:
pandas.DataFrame
- modsim_package.utilities.write_study_definition(study_definition: ParameterGenerator | dict, path: Path, alias: str) None [source]
Write parameter study definition files to path
Calls parameter generator write function or writes a YAML dictionary
- Parameters:
study_definition – Parameter study definition. WAVES parameter generator or dictionary.
path – Output directory
alias – Parameter study dictionary file name
test_utilities.py#
- modsim_package.tests.test_utilities.test_combine_data()[source]
Test the Python 3 Xarray Dataset concatenation utility
Concatenate real datasets with coordinates representative of a WAVES parameter study workflow
- modsim_package.tests.test_utilities.test_merge_parameter_study()[source]
Test the Python 3 Xarray Dataset and WAVES parameter study merge utility
Sign-of-life test that a real parameter study object merges correctly with a representative Dataset
- modsim_package.tests.test_utilities.test_save_plot()[source]
Test the Python 3 Xarray Dataset plotting utility
Test that the function arguments are unpacked into the correct I/O calls
- modsim_package.tests.test_utilities.test_save_table()[source]
Test the Python 3 Xarray Dataset CSV file saving utility
Test that the function arguments are unpacked into the correct I/O calls
post_processing.py#
Post-process with data catenation and plotting
- modsim_package.post_processing.get_parser()[source]
Return parser for CLI options
All options should use the double-hyphen
--option VALUE
syntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag
. Single hyphen-f
flag syntax often clashes with the Abaqus command line options and should be avoided.- Returns:
parser
- Return type:
argparse.ArgumentParser
- modsim_package.post_processing.main(input_files, output_file, group_path, x_var, x_units, y_var, y_units, selection_dict, parameter_study_file=None, csv_regression_file=None)[source]
Catenate
input_files
datasets along theset_name
dimension and plot selected data.Optionally merges the parameter study results datasets with the parameter study definition dataset, where the parameter study dataset file is assumed to be written by a WAVES parameter generator.
- Parameters:
input_files (list) – list of path-like or file-like objects pointing to h5netcdf files containing Xarray Datasets
output_file (str) – The plot file name. Relative or absolute path.
group_path (str) – The h5netcdf group path locating the Xarray Dataset in the input files.
x_var (str) – The independent (x-axis) variable key name for the Xarray Dataset “data variable”
x_units (str) – The independent (x-axis) units
y_var (str) – The dependent (y-axis) variable key name for the Xarray Dataset “data variable”
y_units (str) – The dependent (y-axis) units
selection_dict (dict) – Dictionary to define the down selection of data to be plotted. Dictionary
key: value
pairs must match the data variables and coordinates of the expected Xarray Dataset object.parameter_study_file (str) – path-like or file-like object containing the parameter study dataset. Assumes the h5netcdf file contains only a single dataset at the root group path, .e.g.
/
.csv_regression_file (str) – path-like or file-like object containing the CSV dataset to compare with the current plot data. If the data sets do not match a non-zero exit code is returned.
regression.py#
- modsim_package.regression.get_parser() ArgumentParser [source]
Return parser for CLI options
All options should use the double-hyphen
--option VALUE
syntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag
. Single hyphen-f
flag syntax often clashes with the Abaqus command line options and should be avoided.- Returns:
parser
- Return type:
- modsim_package.regression.main(first_file: Path, second_file: Path, output_file: Path) None [source]
Compare CSV files and return an error code if they differ
- Parameters:
first_file – path-like or file-like object containing the first CSV dataset
second_file – path-like or file-like object containing the second CSV dataset