MODSIM_TEMPLATE API#
rectangle_geometry.py#
Create a simple rectangle geometry.
- modsim_package.rectangle_geometry.get_parser()[source]
Return parser for CLI options.
All options should use the double-hyphen
--option VALUEsyntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag. Single hyphen-fflag 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
.caewill 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#
Partition the simple rectangle geometry created by rectangle_geometry.py.
- modsim_package.rectangle_partition.get_parser()[source]
Return parser for CLI options.
All options should use the double-hyphen
--option VALUEsyntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag. Single hyphen-fflag 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.caewill be used.output_file (str) – The output file for the Abaqus model. Will be stripped of the extension and
.caewill 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#
Mesh the simple rectangle geometry partitioned by rectangle_partition.py.
- modsim_package.rectangle_mesh.get_parser()[source]
Return parser for CLI options.
All options should use the double-hyphen
--option VALUEsyntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag. Single hyphen-fflag 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.caewill be used.output_file (str) – The output file for the Abaqus model. Will be stripped of the extension and
.caeand.inpwill 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: list[float] | tuple[float, ...] = (1.0,), height: list[float] | tuple[float, ...] = (1.0,), global_seed: list[float] | tuple[float, ...] = (1.0, 0.5, 0.25, 0.125), displacement: list[float] | tuple[float, ...] = (-0.01,)) dict[str, list[float]][source]
Return mesh convergence WAVES CartesianProduct schema dictionary.
- Parameters:
width – The rectangle width
height – The rectangle height
global_seed – The global mesh seed size
displacement – The rectangle top surface displacement
- Returns:
WAVES CartesianProduct schema
- modsim_package.rectangle_compression.nominal(width: float = 1.0, height: float = 1.0, global_seed: float = 1.0, displacement: float = -0.01) dict[str, float][source]
Return nominal simulation variables dictionary.
- Parameters:
width – The rectangle width
height – The rectangle height
global_seed – The global mesh seed size
displacement – The rectangle top surface displacement
- Returns:
nominal simulation variables
export_abaqus_image.py#
Save an assembly view image of an Abaqus model from an input or CAE file.
- modsim_package.export_abaqus_image.get_parser()[source]
Return parser for CLI options.
All options should use the double-hyphen
--option VALUEsyntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag. Single hyphen-fflag 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_nameto generate one. Theinput_fileis not modified to include this generated instance.- Parameters:
output_file (str) – Output image file. Supports
*.pngand*.svg.x_angle (float) – Rotation about X-axis in degrees for
abaqus.session.viewports[].view.rotateAbaqus Python methody_angle (float) – Rotation about Y-axis in degrees for
abaqus.session.viewports[].view.rotateAbaqus Python methodz_angle (float) – Rotation about Z-axis in degrees for
abaqus.session.viewports[].view.rotateAbaqus 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
*.caeor input*.inpfile 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
*.inpand*.cae.output_file (str) – Output image file. Supports
*.pngand*.svg.x_angle (float) – Rotation about X-axis in degrees for
abaqus.session.viewports[].view.rotateAbaqus Python methody_angle (float) – Rotation about Y-axis in degrees for
abaqus.session.viewports[].view.rotateAbaqus Python methodz_angle (float) – Rotation about Z-axis in degrees for
abaqus.session.viewports[].view.rotateAbaqus 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:
objectOpen an Abaqus CAE
input_fileas 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=Falseoption 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*.inpkeyword 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
.caewill 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: list[str | Path], group_path: str, concat_coord: str) Dataset[source]
Combine input data files into one dataset.
- Parameters:
input_files – list of path-like or file-like objects pointing to h5netcdf files containing Xarray Datasets
group_path – The h5netcdf group path locating the Xarray Dataset in the input files.
concat_coord – Name of dimension
- Returns:
Combined data
- modsim_package.utilities.csv_files_match(current_csv: DataFrame, expected_csv: DataFrame, index_column: str = 'time', sort_columns: list[str] | tuple[str, ...] = ('time', 'set_name')) bool[source]
Compare two pandas DataFrame objects and determine if they match.
- Parameters:
current_csv – Current CSV data of generated plot.
expected_csv – Expected CSV data.
index_column – name of the column to use an index
sort_columns – name of the column(s) to sort by. Defaults to
["time", "set_name"]
- Returns:
True if the CSV files match, False otherwise.
- modsim_package.utilities.merge_parameter_study(parameter_study_file: str | Path, combined_data: Dataset) Dataset[source]
Merge parameter study to existing dataset.
- Parameters:
parameter_study_file – 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 Dataset that will be merged.
- Returns:
Combined data
- modsim_package.utilities.save_plot(combined_data: Dataset, x_var: str, y_var: str, selection_dict: dict, concat_coord: str, output_file: str | Path) None[source]
Save scatter plot with given x and y labels.
- Parameters:
combined_data – XArray Dataset that will be plotted.
x_var – The independent (x-axis) variable key name for the Xarray Dataset “data variable”
y_var – The dependent (y-axis) variable key name for the Xarray Dataset “data variable”
selection_dict – Dictionary to define the down selection of data to be plotted. Dictionary
key: valuepairs must match the data variables and coordinates of the expected Xarray Dataset object.concat_coord – Name of dimension for which you want multiple lines plotted.
output_file – The plot file name. Relative or absolute path.
- modsim_package.utilities.save_table(combined_data: Dataset, selection_dict: dict, output_file: str | Path) None[source]
Save csv table.
- Parameters:
combined_data – XArray Dataset to be written as a CSV.
selection_dict – Dictionary to define the down selection of data to be plotted. Dictionary
key: valuepairs must match the data variables and coordinates of the expected Xarray Dataset object.output_file – The CSV file name. Relative or absolute path.
- modsim_package.utilities.sort_dataframe(dataframe: DataFrame, index_column: str = 'time', sort_columns: list[str] | tuple[str, ...] = ('time', 'set_name')) DataFrame[source]
Return a sorted dataframe and set an index.
sort columns by column name
sort rows by column values
sort_columnsset an index
- Parameters:
dataframe – dataframe to sort
index_column – name of the column to use an index
sort_columns – name of the column(s) to sort by
- Returns:
sorted and indexed 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#
Test the utilities module.
- 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_csv_files_match() None[source]
Test
utilities.csv_files_match().
- 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
- modsim_package.tests.test_utilities.test_sort_dataframe() None[source]
Test
utilities.sort_dataframe().
post_processing.py#
Post-process with data catenation and plotting.
- modsim_package.post_processing.get_parser() ArgumentParser[source]
Return parser for CLI options.
- modsim_package.post_processing.main(input_files: list[Path], output_file: Path, group_path: str, x_var: str, x_units: str, y_var: str, y_units: str, selection_dict: dict, parameter_study_file: Path | None = None, csv_regression_file: Path | None = None)[source]
Catenate
input_filesdatasets along theset_namedimension 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 of path-like or file-like objects pointing to h5netcdf files containing Xarray Datasets
output_file – The plot file name. Relative or absolute path.
group_path – The h5netcdf group path locating the Xarray Dataset in the input files.
x_var – The independent (x-axis) variable key name for the Xarray Dataset “data variable”
x_units – The independent (x-axis) units
y_var – The dependent (y-axis) variable key name for the Xarray Dataset “data variable”
y_units – The dependent (y-axis) units
selection_dict – Dictionary to define the down selection of data to be plotted. Dictionary
key: valuepairs must match the data variables and coordinates of the expected Xarray Dataset object.parameter_study_file – 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 – 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#
Compare CSV files and return an error code if they differ.
- modsim_package.regression.get_parser() ArgumentParser[source]
Return parser for CLI options.
All options should use the double-hyphen
--option VALUEsyntax to avoid clashes with the Abaqus option syntax, including flag style arguments--flag. Single hyphen-fflag 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