Writing a VMAP file#
The VMAPExport Class#
- class pylife.vmap.VMAPExport(file_name)[source]#
Write pyLife mesh data and variables to a VMAP file.
Use this class to export a pandas mesh from pyLife to the HDF5-based VMAP format. A geometry stores node coordinates and element connectivity, optional node and element sets describe named subsets, and variables store result fields inside VMAP states for later post-processing in CAE tools.
The input mesh is a
DataFrameindexed byelement_idandnode_id. Coordinate columnsxandyare required for two-dimensional meshes;zis used when present for three-dimensional meshes. Variables are read from mesh columns such asdx,dy,dzforDISPLACEMENTorS11throughS23forSTRESS_CAUCHY. Numeric values are written as provided, so units follow the pyLife data and the originating finite-element model.- Parameters:
file_name (str) – Path to the VMAP file to create. Existing files are overwritten by
h5pyin write mode.- Raises:
OSError – Raised when the VMAP file cannot be created. A partially created file is removed before the exception is re-raised.
See also
pylife.vmap.VMAPImportRead VMAP geometry and variables into pandas.
Examples
exporter = VMAPExport("results.vmap") ( exporter .add_geometry("1", mesh) .add_variable("STATE-1", "1", "DISPLACEMENT", mesh) .add_variable("STATE-1", "1", "STRESS_CAUCHY", mesh) )
- add_element_set(geometry_name, indices, mesh, name=None)[source]#
Add a named element set to an existing geometry.
- Parameters:
geometry_name (str) – Name of the VMAP geometry that receives the set.
indices (pandas.Index) – Element ids to include in the set. Every id must be present in
mesh.mesh (pandas.DataFrame) – Mesh whose
element_idindex level defines the valid element ids.name (str, optional) – User-visible value of the VMAP
MYSETNAMEattribute. If omitted, an empty string is written. Default isNone.
- Returns:
The exporter itself to allow fluent method chaining.
- Return type:
- Raises:
- add_geometry(geometry_name, mesh)[source]#
Add a geometry from a pyLife mesh to the VMAP file.
The geometry contains node coordinates and element connectivity. The mesh must be indexed by
element_idandnode_idand must contain coordinate columnsxandy; columnzis written when present.- Parameters:
geometry_name (str) – Name of the VMAP geometry to create.
mesh (pandas.DataFrame) – Mesh to export. The frame must contain one row per element-node pair and coordinate columns in the length unit used by the model.
- Returns:
The exporter itself to allow fluent method chaining.
- Return type:
- Raises:
KeyError – Raised when
geometry_namealready exists.VMAPExportError – Raised when geometry creation fails. The partially created geometry is removed before the exception is re-raised.
- add_integration_types(content)[source]#
Add VMAP integration type definitions to the system group.
- Parameters:
content (dict) – Mapping of integration type keys to constructor arguments for
VMAPIntegrationType.- Returns:
The exporter itself to allow fluent method chaining.
- Return type:
- Raises:
KeyError – Raised when the VMAP integration type dataset already exists.
VMAPExportError – Raised when writing the system dataset fails.
- add_node_set(geometry_name, indices, mesh, name=None)[source]#
Add a named node set to an existing geometry.
- Parameters:
geometry_name (str) – Name of the VMAP geometry that receives the set.
indices (pandas.Index) – Node ids to include in the set. Every id must be present in
mesh.mesh (pandas.DataFrame) – Mesh whose
node_idindex level defines the valid node ids.name (str, optional) – User-visible value of the VMAP
MYSETNAMEattribute. If omitted, an empty string is written. Default isNone.
- Returns:
The exporter itself to allow fluent method chaining.
- Return type:
- Raises:
- add_variable(state_name, geometry_name, variable_name, mesh, column_names=None, location=None)[source]#
Add a result variable to a state and geometry.
The variable values are taken from columns in
meshand written below the VMAPVARIABLESgroup. When the state or state-specific geometry group does not yet exist, it is created automatically. Known pyLife variables use predefined column names and VMAP locations; custom variables require explicitcolumn_namesand may require an explicitlocation.- Parameters:
state_name (str) – Name of the VMAP state, usually a load step or increment such as
STATE-1.geometry_name (str) – Name of the VMAP geometry that owns the variable.
variable_name (str) – Name of the VMAP variable to create, for example
DISPLACEMENTorSTRESS_CAUCHY.mesh (pandas.DataFrame) – Mesh containing the columns to export. For nodal variables one value per
node_idis written; for element-nodal variables the values are written for the mesh rows.column_names (list of str, optional) – Mesh columns to export for
variable_name. If omitted, predefined pyLife column names are used for known variables. Default isNone.location (enum.Enum, optional) – VMAP variable location. Use
VariableLocations.NODEfor nodal data orVariableLocations.ELEMENT_NODALfor element-nodal data. If omitted, the predefined location for a known variable is used. Default isNone.
- Returns:
The exporter itself to allow fluent method chaining.
- Return type:
- Raises:
KeyError – Raised when
geometry_namedoes not exist, the variable already exists, or no predefined column names are available.APIUseError – Raised when
locationis missing for an unknown variable or is not aVariableLocationsvalue.VMAPExportError – Raised when writing the variable fails. The partially created variable is removed before the exception is re-raised.
Notes
Only nodal and element-nodal variables are supported by the current export implementation. Values are written without unit conversion.
- property file_name#
Return the path of the VMAP file being written.
- Returns:
Path passed to
VMAPExportduring construction.- Return type:
- set_group_attribute(object_path, key, value)[source]#
Set an attribute on an existing VMAP HDF5 object.
- Parameters:
object_path (str) – Absolute path of the VMAP group or dataset whose attribute is written.
key (str) – Name of the attribute to create.
value (numpy.dtype) – Attribute value to store. The value must be accepted by
h5py.AttributeManager.create().
- Raises:
KeyError – Raised when
object_pathdoes not exist in the VMAP file.
- variable_column_names(parameter_name)[source]#
Return pyLife column names for a VMAP variable.
- Parameters:
parameter_name (str) – VMAP variable name, for example
DISPLACEMENTorSTRESS_CAUCHY.- Returns:
Column names expected in the mesh for
parameter_name.- Return type:
- Raises:
KeyError – Raised when
parameter_nameis not a predefined VMAP variable in pyLife.
Examples
>>> from pylife.vmap import VMAPExport >>> VMAPExport.variable_column_names(None, "DISPLACEMENT") ['dx', 'dy', 'dz']
In practice the method is called on an export object, e.g.
export.variable_column_names("STRESS_CAUCHY").
- variable_location(parameter_name)[source]#
Return the predefined VMAP location for a variable.