amfe.mesh module

Mesh module of amfe. It handles the mesh from import, defining the dofs for the boundary conditions and the export.

class amfe.mesh.Mesh[source]

Bases: object

Class for handling the mesh operations.

nodes

ndarray – Array of x-y-z coordinates of the nodes. Dimension is (no_of_nodes, no_of_dofs_per_node). If no_of_dofs_per_node: z-direction is dropped!

connectivity

list – List of nodes indices belonging to one element.

constraint_list

ndarray – Experimental: contains constraints imported from nastran-files via import_bdf()

el_df

pandas.DataFrame – Pandas Dataframe containing Element-Definitions of the Original file (e.g. *.msh or *.bdf-File)

ele_obj

list – List of element objects. The list contains actually only the pointers pointing to the element object. For each combination of element-type and material only one Element object is instanciated. ele_obj contains for each element a pointer to one of these Element objects.

neumann_connectivity

list – list of nodes indices belonging to one element for neumann BCs.

neumann_obj

list – List of element objects for the neumann boundary conditions.

nodes_dirichlet

ndarray – Array containing the nodes involved in Dirichlet Boundary Conditions.

dofs_dirichlet

ndarray – Array containing the dofs which are to be blocked by Dirichlet Boundary Conditions.

no_of_dofs_per_node

int – Number of dofs per node. Is 3 for 3D-problems, 2 for 2D-problems. If rotations are considered, this nubmer can be >3.

no_of_elements

int – Number of elements in the whole mesh associated with an element object.

no_of_nodes

int – Number of nodes of the whole system.

no_of_dofs

int – Number of dofs of the whole system (including constrained dofs).

element_class_dict

dict – Dictionary containing objects of elements.

element_boundary_class_dict

dict – Dictionary containing objects of skin elements.

node_idx

int – index describing, at which position in the Pandas Dataframe el_df the nodes of the element start.

deflate_mesh()[source]

Deflate the mesh, i.e. delete nodes which are not connected to an element.

Parameters:None
Returns:
Return type:None
import_bdf(filename, scale_factor=1.0)[source]

Import a NASTRAN mesh.

Parameters:
  • filename (string) – filename of the .bdf-file
  • scale_factor (float, optional) – scale factor for the mesh to adjust the units. The default value is 1, i.e. no scaling is done.
Returns:

Return type:

None

Notes

This function is heavily experimental. It is just working for a subset of NASTRAN input files and the goal is to capture the mesh and the constraints of the model. The constraints are captured in the constraint_list-object of the class.

The internal representation of the elements is done via a Pandas Dataframe object.

import_csv(filename_nodes, filename_elements, explicit_node_numbering=False, ele_type=False)[source]

Imports the nodes list and elements list from 2 different csv files.

Parameters:
  • filename_nodes (str) – name of the file containing the nodes in csv-format
  • filename_elements (str) – name of the file containing the elements in csv-format
  • explicit_node_numbering (bool, optional) – Flag stating, if the nodes are explicitly numbered in the csv-file. When set to true, the first column is assumed to have the node numbers and is thus ignored.
  • ele_type (str) – Spezifiy elements type of the mesh (e.g. for a Tri-Mesh different elements types as Tri3, Tri4, Tri6 can be used) If not spezified value is set to ‘False’
Returns:

Return type:

None

Examples

TODO

import_inp(filename, scale_factor=1.0)[source]

Import Abaqus input file.

Parameters:
  • filename (string) – filename of the .msh-file
  • scale_factor (float, optional) – scale factor for the mesh to adjust the units. The default value is 1, i.e. no scaling is done.
Returns:

Return type:

None

Notes

This function is heavily experimental. It is just working for a subset of Abaqus input files and the goal is to capture the mesh of the model.

The internal representation of the elements is done via a Pandas Dataframe object.

import_msh(filename, scale_factor=1.0)[source]

Import a gmsh-mesh.

This method sets the following properties:
  • el_df: Element Definitions as pandas Dataframe
    (Attention! This property is not the property that defines the elements for later calculation. This is located in the connectivity property)
  • node_idx: First Column in el_df pandas dataframe where the first
    node-id of each element is stored
  • no_of_dofs_per_node: important to recognize 2D vs. 3D problem
  • nodes: Node Definitions (Locations)
Parameters:
  • filename (string) – filename of the .msh-file
  • scale_factor (float, optional) – scale factor for the mesh to adjust the units. The default value is 1, i.e. no scaling is done.
Returns:

Return type:

None

Notes

The internal representation of the elements is done via a Pandas Dataframe object. This gives the possibility to dynamically choose a part of the mesh for boundary conditons etc.

load_group_to_mesh(key, material, mesh_prop='phys_group')[source]

Add a physical group to the main mesh with given material.

It generates the connectivity list (mesh-class-property connectivity) which contains the element configuration as array and provides a map with pointers to Element-Objects (Tet, Hex etc.) which already contain information about material that is passed. Each element gets a pointer to such an element object.

Parameters:
  • key (int) – Key for mesh property which is to be chosen. Matches the group given in the gmsh file. For help, the function mesh_information or boundary_information gives the groups
  • material (Material class) – Material class which will be assigned to the elements
  • mesh_prop ({'phys_group', 'geom_entity', 'el_type'}, optional) – label of which the element should be chosen from. Standard is physical group.
Returns:

Return type:

None

mesh_information(mesh_prop='phys_group')[source]

Print some information about the mesh that is being imported Attention: This information is not about the mesh that is already loaded for further calculation. Instead it is about the mesh that is found in an import-file!

Parameters:mesh_prop (str, optional) – mesh property of the loaded mesh. This mesh property is the basis for selection of parts of the mesh for materials and boundary conditions. The default value is ‘phys_group’ which is the physical group, if the mesh comes from gmsh.
Returns:
Return type:None
save_mesh_xdmf(filename, field_list=None, bmat=None, u=None, timesteps=None)[source]

Save the mesh in hdf5 and xdmf file format.

Parameters:
  • filename (str) – String consisting the path and the filename
  • field_list (list) –

    list containing the fields to be exported. The list is a list of tupels containing the array with the values in the columns and a dictionary with the attribute information:

    >>> # example field list with reduced displacement not to export
    >>> # ParaView and strain epsilon to be exported to ParaView
    >>> field_list = [(q_red, {'ParaView':False, 'Name':'q_red'}),
                      (eps, {'ParaView':True,
                             'Name':'epsilon',
                             'AttributeType':'Tensor6',
                             'Center':'Node',
                             'NoOfComponents':6})]
    
  • bmat (csrMatrix) – CSR-Matrix describing the way, how the Dirichlet-BCs are applied: u_unconstr = bmat @ u_constr
  • u (nparray) – matrix with displacement vectors as columns for different timesteps
  • timesteps (nparray) – vector with timesteps a displacement vector is stored in u
Returns:

Return type:

None

Notes

Only one homogeneous mesh is exported. Thus only the mesh made of the elements which occur most often is exported. The other meshes are discarded.

set_dirichlet_bc(key, coord, mesh_prop='phys_group', output='internal')[source]

Add a group of the mesh to the dirichlet nodes to be fixed. It sets the mesh-properties ‘nodes_dirichlet’ and ‘dofs_dirichlet’

Parameters:
  • key (int) – Key for mesh property which is to be chosen. Matches the group given in the gmsh file. For help, the function mesh_information or boundary_information gives the groups
  • coord (str {'x', 'y', 'z', 'xy', 'xz', 'yz', 'xyz'}) – coordinates which should be fixed
  • mesh_prop (str {'phys_group', 'geom_entity', 'el_type'}, optional) – label of which the element should be chosen from. Default is phys_group.
  • output (str {'internal', 'external'}) – key stating, boundary information is stored internally or externally
Returns:

  • nodes (ndarray, if output == ‘external’) – Array of nodes belonging to the selected group
  • dofs (ndarray, if output == ‘external’) – Array of dofs respecting the coordinates belonging to the selected groups

set_neumann_bc(key, val, direct, time_func=None, shadow_area=False, mesh_prop='phys_group')[source]

Add group of mesh to neumann boundary conditions.

Parameters:
  • key (int) – Key of the physical domain to be chosen for the neumann bc
  • val (float) – value for the pressure/traction onto the element
  • direct (str 'normal' or ndarray) – array giving the direction, in which the traction force should act. alternatively, the keyword ‘normal’ may be given. Default value: ‘normal’.
  • time_func (function object) –

    Function object returning a value between -1 and 1 given the input t:

    >>> val = time_func(t)
    
  • shadow_area (bool, optional) – Flat setting, if force should be proportional to the shadow area, i.e. the area of the surface projected on the direction. Default value: ‘False’.
  • mesh_prop (str {'phys_group', 'geom_entity', 'el_type'}, optional) – label of which the element should be chosen from. Default is phys_group.
Returns:

Return type:

None

tie_mesh(master_key, slave_key, master_prop='phys_group', slave_prop='phys_group', tying_type='fixed', robustness=4, verbose=False, conform_slave_mesh=True, fix_mesh_dist=0.001)[source]

Tie nonconforming meshes for a given master and slave side.

Parameters:
  • master_key (int or string) – mesh key of the master face mesh. The master face mesh has to be at least the size of the slave mesh. It is better, when the master mesh is larger than the slave mesh.
  • slave_key (int or string) – mesh key of the slave face mesh or point cloud
  • master_prop (string, optional) – mesh property for which master_key is specified. Default value: ‘phys_group’
  • slave_prop (string, optional) – mesh property for which slave_key is specified. Default value: ‘phys_group’
  • tying_type (string {'fixed', 'slide'}) – Mesh tying type. ‘fixed’ glues the meshes together while ‘slide’ allows for a sliding motion between the meshes.
  • robustness (int, optional) – Integer value indicating, how many master elements should be considered for one slave node.
Returns:

  • slave_dofs (ndarray, type: int) – slave dofs of the tied mesh
  • row (ndarray, type: int) – row indices of the triplet description of the master slave conversion
  • col (ndarray, type: int) – col indices of the triplet description of the master slave conversion
  • val (ndarray, type: float) – values of the triplet description of the master slave conversion

Notes

The master mesh has to embrace the full slave mesh. If this is not the case, the routine will fail, a slave point outside the master mesh cannot be addressed to a specific element.

amfe.mesh.create_xdmf_from_hdf5(filename)[source]

Create an accompanying xdmf file for a given hdmf file.

Parameters:filename (str) – filename of the hdf5-file. Produces an XDMF-file of same name with .xdmf ending.
Returns:
Return type:None