NLMech  0.1.0
fe::Mesh Class Reference

A class for mesh data. More...

#include <mesh.h>

Collaboration diagram for fe::Mesh:
Collaboration graph

Public Member Functions

 Mesh ()
 Constructor.
 
 Mesh (inp::MeshDeck *deck)
 Constructor. More...
 
 Mesh (size_t dim=0)
 Constructor. More...
 
void print (int nt=0, int lvl=0) const
 Prints the information about the instance of the object. More...
 
std::string printStr (int nt=0, int lvl=0) const
 Returns the string containing information about the instance of the object. More...
 
Accessor methods
size_t getDimension () const
 Get the dimension of the domain. More...
 
size_t getNumNodes () const
 Get the number of nodes. More...
 
size_t getNumElements () const
 Get the number of elements. More...
 
size_t getNumDofs () const
 Get the number of dofs. More...
 
size_t getElementType () const
 Get the type of element in mesh. More...
 
double getMeshSize () const
 Get the mesh size. More...
 
util::Point3 getNode (const size_t &i) const
 Get coordinates of node i. More...
 
double getNodalVolume (const size_t &i) const
 Get nodal volume of node i. More...
 
const std::vector< util::Point3 > & getNodes () const
 Get the nodes data. More...
 
std::vector< util::Point3 > & getNodes ()
 
const std::vector< util::Point3 > * getNodesP () const
 Get the pointer to nodes data. More...
 
std::vector< util::Point3 > * getNodesP ()
 
const std::vector< uint8_t > * getFixityP () const
 Get the pointer to fixity data. More...
 
std::vector< uint8_t > * getFixityP ()
 
const std::vector< uint8_t > & getFixity () const
 Get the reference to fixity data. More...
 
std::vector< uint8_t > & getFixity ()
 
const std::vector< double > & getNodalVolumes () const
 Get the nodal volume data. More...
 
std::vector< double > & getNodalVolumes ()
 
const std::vector< double > * getNodalVolumesP () const
 Get the pointer to nodal volume data. More...
 
std::vector< double > * getNodalVolumesP ()
 
const std::vector< size_t > getPrescribedNodes () const
 Get the vector of indicies with prescribed values from the couplign method. More...
 
std::vector< size_t > getPrescribedNodes ()
 
const std::vector< util::Point3getPrescribedValues () const
 Get the vector of values of the prescribed nodes from the couplign method. More...
 
std::vector< util::Point3getPrescribedValues ()
 
bool isNodeFree (const size_t &i, const unsigned int &dof) const
 Return true if node is free. More...
 
std::vector< size_t > getElementConnectivity (const size_t &i) const
 Get the connectivity of element. More...
 
std::vector< util::Point3getElementConnectivityNodes (const size_t &i) const
 Get the vertices of element. More...
 
const std::vector< size_t > & getElementConnectivities () const
 Get the reference to element-node connectivity data. More...
 
std::vector< size_t > & getElementConnectivities ()
 
const std::vector< size_t > * getElementConnectivitiesP () const
 Get the pointer to element-node connectivity data. More...
 
std::vector< size_t > * getElementConnectivitiesP ()
 
const std::pair< std::vector< double >, std::vector< double > > & getBoundingBox () const
 Get the bounding box of the mesh. More...
 
Setter methods
void setMeshData (const size_t &dim, std::vector< util::Point3 > &nodes, std::vector< double > &volumes)
 Set the mesh data for finite difference simulations. More...
 
void setNodes (std::vector< util::Point3 > &nodes)
 Set the nodal data of the mesh. More...
 
void setNodalVolumes (std::vector< double > &volumes)
 Set the nodal volume data of the mesh. More...
 
void setFixity (std::vector< uint8_t > &fixity)
 Set nodal fixity masks. More...
 
void setFixity (const size_t &i, const unsigned int &dof, const bool &flag)
 Set the fixity to free (0) or fixed (1) More...
 
void setMeshSize (const double &h)
 Set the mesh size. More...
 
void readFromFile (inp::MeshDeck *deck, const std::string &filename)
 Reads mesh data from the file and populates other data. More...
 
void clearElementData ()
 Clear element-node connectivity data.
 

Private Member Functions

Utility methods
void createData (const std::string &filename, bool ref_config, bool is_centroid_based, bool has_coupling_data)
 Reads mesh data from the file and populates other data. More...
 
void nodesAtCentroid ()
 Converts standard fem mesh to particle mesh with nodes at the center of element.
 
void computeVol ()
 Compute the nodal volume. More...
 
void computeBBox ()
 Compute the bounding box

 
void computeMeshSize ()
 Compute the mesh size. More...
 

Private Attributes

std::pair< std::vector< double >, std::vector< double > > d_bbox
 Bounding box. More...
 
size_t d_dim
 Dimension of the mesh.
 
std::string d_filename
 Filename to read mesh data.
 
std::vector< int > d_gInvMap
 Map from global id to reduced global id. More...
 
std::vector< size_t > d_gMap
 Map from global reduced id to default global id. More...
 
double d_h
 Mesh size.
 
bool d_keepElementConn
 Specify if we keep the element connectivity data.
 
size_t d_numDofs
 Number of dofs = (dimension) times (number of nodes)
 
std::string d_spatialDiscretization
 Tag for spatial discretization type. More...
 
Mesh data
size_t d_numNodes
 Number of nodes.
 
size_t d_numElems
 Number of elements.
 
size_t d_eType
 Element type. More...
 
size_t d_eNumVertex
 Number of vertex per element. More...
 
std::vector< util::Point3d_nodes
 Vector of initial (reference) coordinates of nodes.
 
std::vector< size_t > d_enc
 Element-node connectivity data. More...
 
std::vector< std::vector< size_t > > d_nec
 Node-element connectivity data. More...
 
std::vector< uint8_t > d_fix
 Vector of fixity mask of each node. More...
 
std::vector< double > d_vol
 Vector of volume of each node. More...
 
std::vector< size_t > d_prescribed_nodes
 Vector with the indicies of all nodes with prescribed boundary data. More...
 
std::vector< util::Point3d_prescribed_values
 Vector with the values of all nodes with prescribed boundary data. More...
 

Detailed Description

A class for mesh data.

In this class the mesh data such as nodes, element-node connectivity, node-element connectivity are stored. The class also stores fixity mask of nodes which indicates if x-, y-, or z-dof of the node is fixed or free.

We currently only support mesh with only one type of elements, i.e. mesh can not have mix of two types of elements. For example, we can not have mesh with triangle and quadrangle elements together.

This class is used in both finite difference implementation and finite element implementation. For finite difference, we only require nodal volume. If the mesh file contains nodal volume, we skip reading element-node and node-element connectivity, however if mesh file does not have nodal volume data, we read connectivity data and compute the nodal volume.

Constructor & Destructor Documentation

◆ Mesh() [1/2]

fe::Mesh::Mesh ( size_t  dim = 0)
explicit

Constructor.

Parameters
dimDimension of the problem

◆ Mesh() [2/2]

fe::Mesh::Mesh ( inp::MeshDeck deck)
explicit

Constructor.

The constructor initializes the data using input deck, performs checks on input data, and reads mesh file and populates the mesh related data. The mesh file of **.csv**, **.vtu (VTK)** and **.msh (Gmsh)** are supported.

Parameters
deckInput deck which contains user-specified information
Here is the call graph for this function:

Member Function Documentation

◆ computeMeshSize()

void fe::Mesh::computeMeshSize ( )
private

Compute the mesh size.

This method searches for minimum distance between any two mesh nodes and stores it as a mesh size.

Referenced by Mesh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ computeVol()

void fe::Mesh::computeVol ( )
private

Compute the nodal volume.

This method requires element-node connectivity data to compute the nodal volumes. Formula for volume of a node $ i$ is given by

\[ V_i = \sum_{e \in \mathbf{N}_i} \int_{T_e} N_i(x) dx, \]

where $\mathbf{N}_i$ is a list of elements which have node $ i$ as its vertex, $ T_e$ is the element domain, $ N_i$ is the shape function of the node $ i$ in element e.

Here is the call graph for this function:

◆ createData()

void fe::Mesh::createData ( const std::string &  filename,
bool  ref_config,
bool  is_centroid_based,
bool  has_coupling_data 
)
private

Reads mesh data from the file and populates other data.

This function calls reader methods in namespace rw::reader to read the mesh file. For finite difference implementation, we support **.csv** mesh file which has nodal coordinates and nodal volumes data.

However, for finite element implementation, we require either **.vtu** or **.msh** file with element-node connectivity data.

Parameters
filenameName of the mesh file
ref_configBase the mesh on reference configuration (obtain reference configuration using point data and displacement data)
is_centroid_basedSpecify if we create node at the center of element
has_coupling_dataSpecify if we read the additional data needed for coupling

Referenced by Mesh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBoundingBox()

const std::pair<std::vector<double>, std::vector<double> >& fe::Mesh::getBoundingBox ( ) const
inline

Get the bounding box of the mesh.

Returns
box Bounding box

Referenced by model::Output::Output().

Here is the caller graph for this function:

◆ getDimension()

size_t fe::Mesh::getDimension ( ) const
inline

Get the dimension of the domain.

Returns
N Dimension

Referenced by loading::InitialCondition::apply().

Here is the caller graph for this function:

◆ getElementConnectivities()

const std::vector<size_t>& fe::Mesh::getElementConnectivities ( ) const
inline

Get the reference to element-node connectivity data.

Returns
reference Reference

◆ getElementConnectivitiesP()

const std::vector<size_t>* fe::Mesh::getElementConnectivitiesP ( ) const
inline

Get the pointer to element-node connectivity data.

Returns
pointer Pointer

Referenced by model::Output::Output().

Here is the caller graph for this function:

◆ getElementConnectivity()

std::vector<size_t> fe::Mesh::getElementConnectivity ( const size_t &  i) const
inline

Get the connectivity of element.

Since we store connectivity in a single vector, we use fe::Mesh::d_eNumVertex to get the connectivity of element. Given element e, the connectivity of e begins from location $ i_0 = e*d\_eNumVertex + 0 $ upto $i_{n-1} = e*d\_eNumVertex + d\_eNumVertex - 1$.

So the connectivity of e is d_enc[ $i_0$], d_enc[ $ i_1 $], ..., d_end[ $i_{n-1}$]

Parameters
iId of an element
Returns
vector Vector of nodal ids

◆ getElementConnectivityNodes()

std::vector<util::Point3> fe::Mesh::getElementConnectivityNodes ( const size_t &  i) const
inline

Get the vertices of element.

Parameters
iId of an element
Returns
vector Vector of vertices

◆ getElementType()

size_t fe::Mesh::getElementType ( ) const
inline

Get the type of element in mesh.

Returns
type Element type (using VTK convention)

Referenced by model::Output::Output().

Here is the caller graph for this function:

◆ getFixity()

const std::vector<uint8_t>& fe::Mesh::getFixity ( ) const
inline

Get the reference to fixity data.

Returns
reference Reference to fixity data

◆ getFixityP()

const std::vector<uint8_t>* fe::Mesh::getFixityP ( ) const
inline

Get the pointer to fixity data.

Returns
pointer Pointer to fixity data

Referenced by model::Output::Output().

Here is the caller graph for this function:

◆ getMeshSize()

double fe::Mesh::getMeshSize ( ) const
inline

Get the mesh size.

Returns
h Mesh size

Referenced by loading::FLoading::apply(), material::pd::RNPBond::RNPBond(), and geometry::VolumeCorrection::VolumeCorrection().

Here is the caller graph for this function:

◆ getNodalVolume()

double fe::Mesh::getNodalVolume ( const size_t &  i) const
inline

Get nodal volume of node i.

Parameters
iId of the node
Returns
vol Volume

Referenced by model::Output::Output().

Here is the caller graph for this function:

◆ getNodalVolumes()

const std::vector<double>& fe::Mesh::getNodalVolumes ( ) const
inline

Get the nodal volume data.

Returns
Vector Vector of nodal volume

◆ getNodalVolumesP()

const std::vector<double>* fe::Mesh::getNodalVolumesP ( ) const
inline

Get the pointer to nodal volume data.

Returns
Pointer to nodal volume data

Referenced by model::Output::Output().

Here is the caller graph for this function:

◆ getNode()

util::Point3 fe::Mesh::getNode ( const size_t &  i) const
inline

Get coordinates of node i.

Parameters
iId of the node
Returns
coords Coordinates

Referenced by loading::FLoading::apply(), loading::ULoading::apply(), loading::InitialCondition::apply(), geometry::DampingGeom::computeDampingCoefficient(), loading::FLoading::FLoading(), and loading::ULoading::ULoading().

Here is the caller graph for this function:

◆ getNodes()

const std::vector<util::Point3>& fe::Mesh::getNodes ( ) const
inline

Get the nodes data.

Returns
nodes Nodes data

◆ getNodesP()

const std::vector<util::Point3>* fe::Mesh::getNodesP ( ) const
inline

Get the pointer to nodes data.

Returns
pointer Pointer to nodes data

Referenced by tools::pp::Compute::Compute(), util::StateBasedHelperFunctions::dilatation(), model::Output::Output(), util::StateBasedHelperFunctions::StateBasedHelperFunctions(), and geometry::VolumeCorrection::VolumeCorrection().

Here is the caller graph for this function:

◆ getNumDofs()

size_t fe::Mesh::getNumDofs ( ) const
inline

Get the number of dofs.

Returns
N Number of dofs

◆ getNumElements()

size_t fe::Mesh::getNumElements ( ) const
inline

Get the number of elements.

Returns
N Number of elements

Referenced by model::Output::Output().

Here is the caller graph for this function:

◆ getNumNodes()

size_t fe::Mesh::getNumNodes ( ) const
inline

◆ getPrescribedNodes()

const std::vector<size_t> fe::Mesh::getPrescribedNodes ( ) const
inline

Get the vector of indicies with prescribed values from the couplign method.

Returns
Vector with the indicies

Referenced by loading::ULoading::ULoading().

Here is the caller graph for this function:

◆ getPrescribedValues()

const std::vector<util::Point3> fe::Mesh::getPrescribedValues ( ) const
inline

Get the vector of values of the prescribed nodes from the couplign method.

Returns
Vector with the prescribed values

Referenced by loading::ULoading::apply().

Here is the caller graph for this function:

◆ isNodeFree()

bool fe::Mesh::isNodeFree ( const size_t &  i,
const unsigned int &  dof 
) const
inline

Return true if node is free.

Parameters
iId of node
dofDof to check for
Returns
bool True if dof is free else false

Referenced by loading::InitialCondition::apply().

Here is the caller graph for this function:

◆ print()

void fe::Mesh::print ( int  nt = 0,
int  lvl = 0 
) const
inline

Prints the information about the instance of the object.

Parameters
ntNumber of tabs to append before each line of string
lvlLevel of information sought (higher level means more information)
Here is the call graph for this function:

◆ printStr()

std::string fe::Mesh::printStr ( int  nt = 0,
int  lvl = 0 
) const

Returns the string containing information about the instance of the object.

Parameters
ntNumber of tabs to append before each line of string
lvlLevel of information sought (higher level means more information)
Returns
string String containing information about this object

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readFromFile()

void fe::Mesh::readFromFile ( inp::MeshDeck deck,
const std::string &  filename 
)

Reads mesh data from the file and populates other data.

Parameters
deckMesh deck
filenameName of the mesh file

◆ setFixity() [1/2]

void fe::Mesh::setFixity ( const size_t &  i,
const unsigned int &  dof,
const bool &  flag 
)

Set the fixity to free (0) or fixed (1)

Parameters
iId of node
dofDof which is affected
flagSet fixity to fixed if true or free

◆ setFixity() [2/2]

void fe::Mesh::setFixity ( std::vector< uint8_t > &  fixity)

Set nodal fixity masks.

Parameters
fixityReference to fixity of all nodes

Referenced by loading::ULoading::ULoading().

Here is the caller graph for this function:

◆ setMeshData()

void fe::Mesh::setMeshData ( const size_t &  dim,
std::vector< util::Point3 > &  nodes,
std::vector< double > &  volumes 
)

Set the mesh data for finite difference simulations.

Parameters
dimDimension
nodesReference to nodes reference configuration
volumesReference to nodal volumes

◆ setMeshSize()

void fe::Mesh::setMeshSize ( const double &  h)

Set the mesh size.

Parameters
hMesh size

◆ setNodalVolumes()

void fe::Mesh::setNodalVolumes ( std::vector< double > &  volumes)

Set the nodal volume data of the mesh.

Parameters
volumesReference to nodal volumes

◆ setNodes()

void fe::Mesh::setNodes ( std::vector< util::Point3 > &  nodes)

Set the nodal data of the mesh.

Parameters
nodesReference to nodes reference configuration

Field Documentation

◆ d_bbox

std::pair<std::vector<double>, std::vector<double> > fe::Mesh::d_bbox
private

Bounding box.

Returns
(xmin,ymin,zmin) and (xmax,ymax,zmax)

Referenced by getBoundingBox().

◆ d_enc

std::vector<size_t> fe::Mesh::d_enc
private

Element-node connectivity data.

Structure: First d_eNumVertex data gives the connectivity of first element, and next d_eNumVertex data gives the connectivity of second element and so on and so fourth.

Referenced by getElementConnectivities(), getElementConnectivitiesP(), getElementConnectivity(), getElementConnectivityNodes(), and getNumElements().

◆ d_eNumVertex

size_t fe::Mesh::d_eNumVertex
private

Number of vertex per element.

This information is useful in getting the connectivity for a given element. We assume that the mesh has only one type of elements and based on that assumption we store the element-node connectivity in a single vector.

The value for different elements are

  • Line element: 2,
  • Triangle element: 3,
  • Quadrilateral element: 4,
  • Tetrahedral element: 4

Referenced by getElementConnectivity(), getElementConnectivityNodes(), and getNumElements().

◆ d_eType

size_t fe::Mesh::d_eType
private

Element type.

We follow VTK convention to identify the elements:

  • Line element = 3,
  • Triangle element = 5,
  • Pixel element = 8,
  • Quadrilateral element = 9,
  • Tetrahedral element = 10

Referenced by getElementType().

◆ d_fix

std::vector<uint8_t> fe::Mesh::d_fix
private

Vector of fixity mask of each node.

First bit represents x-dof, second represents y-dof, and third represents z-dof. 0 represents free dof and 1 represents fixed dof.

We store data in uint8_t type which can hold 8 bit. At present we only use first 3 bits.

Referenced by getFixity(), getFixityP(), and isNodeFree().

◆ d_gInvMap

std::vector<int> fe::Mesh::d_gInvMap
private

Map from global id to reduced global id.

This is a inverse of d_gMap

◆ d_gMap

std::vector<size_t> fe::Mesh::d_gMap
private

Map from global reduced id to default global id.

We assign number to each free dof where number ranges from 0 to total number of free dofs. This is referred to set of global reduced id. This new set of ids are subset of set of global ids of all dofs, and therefore, "reduced" word is used.

d_gMap provides a map from global reduced id to global id.

Note
Needed only when the discretization is "weak_finite_element" for the assembly of the mass matrix.

◆ d_nec

std::vector<std::vector<size_t> > fe::Mesh::d_nec
private

Node-element connectivity data.

At present, this data is never populated.

◆ d_prescribed_nodes

std::vector<size_t> fe::Mesh::d_prescribed_nodes
private

Vector with the indicies of all nodes with prescribed boundary data.

For coupling with other codes, e.g. FEM or PUM, prescribed values for displacement or force are given by the local method and applied to these PD nodes.

Referenced by getPrescribedNodes().

◆ d_prescribed_values

std::vector<util::Point3> fe::Mesh::d_prescribed_values
private

Vector with the values of all nodes with prescribed boundary data.

For coupling with other codes, e.g. FEM or PUM, prescribed values for displacement or force are given by the local method and applied to these PD nodes.

Referenced by getPrescribedValues().

◆ d_spatialDiscretization

std::string fe::Mesh::d_spatialDiscretization
private

Tag for spatial discretization type.

List of valid values are:

  • finite_difference
  • weak_finite_element
  • nodal_finite_element
  • truss_finite_element

Referenced by Mesh().

◆ d_vol

std::vector<double> fe::Mesh::d_vol
private

Vector of volume of each node.

For uniform square mesh, the volume is simply $ h^2 $ in 2-d and $ h^3$ in 3-d, where $ h$ is the mesh size. For general mesh, the volume is computed using the element-node connectivity of the mesh.

Referenced by getNodalVolume(), getNodalVolumes(), getNodalVolumesP(), and Mesh().


The documentation for this class was generated from the following files: