hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
hummingbird::Mesh Class Reference

Class defing a mesh. More...

#include <mesh.h>

Classes

struct  GmshReadState
 Intermediate state accumulated while reading a gmsh file, shared across the section subroutines below. More...

Public Member Functions

 Mesh ()=default
 Construct a new Mesh object.
 Mesh (const std::string &msh_file)
 Construct a new Mesh object from a gmsh .msh file.
void AddNode (const Node &node)
 Add node to Mesh.
void AddNodes (const std::vector< Node > &nodes)
 Add nodes in a vector to Mesh.
void AddElement (std::unique_ptr< Element > element)
 Add element to Mesh.
void CreateInteriorElementNodes (const GaussLobattoLegendre &gll_quadrature)
 Create interior nodes on elements using Gauss-Lobatto-Legendre quadrature set and add to Mesh.
const std::vector< Node > & nodes () const
 Get the Nodes in the mesh.
const std::vector< std::unique_ptr< Element > > & elements () const
 Get the elements in the mesh.
const Node & GetNode (const size_t id) const
 Get Node by ID.
size_t n_elements () const
 Get the number of Elements in the mesh.
size_t n_nodes () const
 Get the number of nodes in the mesh.
unsigned int dimension () const
 Get the spatial dimension of the mesh, derived from the elements it contains (e.g. 1 for a mesh of Segments). 0 if no elements have been added yet.
const std::vector< size_t > & boundary_node_ids () const
 Get the boundary node IDs.
const Element & GetElement (const size_t index) const
 Get an Element by index.
void InitializeNodeSolutions (const size_t n_ordinates, const QuadratureBase< Ordinate > &angular_quad_set, const SourceBank &source_bank)
 Initialize node solution vectors to the correct lengths. Scalar and angular fluxes are set to 0 and source fluxes are set to the element's external source.
void Prepare (const GaussLobattoLegendre &gll_quadrature)
 Prepare the mesh for running a simulation by generating interior nodes using the GLL quadrature set, renumbering nodes, then checking these nodes.
void ResolveIDs (const MaterialBank &material_bank, const SourceBank &source_bank, const BCBank &bc_bank)
 Resolve the raw gmsh Physical Group tags currently stored in material_id()/source_id()/bc_id (set from the .msh file alone, with no bank access) into the real IDs assigned by the given banks, by looking up the name each tag's Physical Group carries (e.g. "mms_material" from "material:mms_material") via BankBase::GetIDByName. Nodes with bc_id == 0 (never tagged by a point element) are left alone.
void FindBoundaryNodes ()
 Populates the boundary_node_ids_ member. Must be called after ResolveIDs!
void SetOutwardNormals ()
 Set the outward-pointing unit normal vector on each boundary node (Node::outward_normal), normalized via arma::normalise. Must be called after FindBoundaryNodes (needs boundary_node_ids_ populated) and after Prepare (needs final, renumbered node ids).
void UpdateNodeScalarFluxes (const QuadratureBase< Ordinate > &angular_quad_set)
 Update the nodes' scalar flux values.
void UpdateNodeAngularFluxes (const SEMProblem &sem_problem, const size_t n_ordinates)
 Update the nodes' angular flux values.
void SetNodeSourceFluxes (const size_t node_id, const std::vector< double > &source_fluxes)
 Set the Node's source flux values.

Private Member Functions

void RenumberNodes ()
 Renumber nodes in mesh to keep node IDs near each other in a single element.
void CheckNodeIDs ()
 Check that all Node IDs are unique and continuous from 0 to N-1 for N total nodes.
void ReadGMSH (const std::string &msh_file)
 Construct a Mesh from a gmsh ASCII (format 4.1) .msh file. Reading routes to a section-specific subroutine using an unordered_map keyed by the gmsh section header (e.g. "$Nodes"). Only the sections needed to build 1D meshes (Segment elements, from 2-node line elements and Physical Point/Curve groups) are currently handled; support for 2D quad elements can be added later by extending ReadElements without needing to restructure this dispatch.
void ReadPhysicalNames (std::ifstream &file, GmshReadState &state)
 Read the $PhysicalNames section into state.physical_names.
void ReadEntities (std::ifstream &file, GmshReadState &state)
 Read the $Entities section into state.point_physical_tags and state.curve_physical_tags.
void ReadNodes (std::ifstream &file, GmshReadState &state)
 Read the $Nodes section, adding Node objects to the mesh and recording the gmsh tag to Node ID mapping in state.node_tag_to_id.
void ReadElements (std::ifstream &file, GmshReadState &state)
 Read the $Elements section, adding Segment elements to the mesh for 2-node line elements. Point elements are consumed and used to tag the boundary/bc_id of the Node they reference, since they mark boundary entities in gmsh.
int GetMaterialID (const std::vector< int > &curve_physical_tags, const std::unordered_map< int, std::string > &physical_names) const
 Find the material ID for a curve entity, defined as the tag of the Physical Group on that curve whose name is prefixed with "material:" (see cases/README.md).
int GetSourceID (const std::vector< int > &curve_physical_tags, const std::unordered_map< int, std::string > &physical_names) const
 Find the source ID for a curve entity, defined as the tag of the Physical Group on the curve whose name is prefixed with "source:" (see cases/README.md).
int GetBCID (const std::vector< int > &point_physical_tags, const std::unordered_map< int, std::string > &physical_names) const
 Find the BC ID for a point entity, defined as the tag of the Physical Group on that point whose name is prefixed with "bc:" (see cases/README.md).
std::string ExtractName (const std::string &physical_name) const
 Extract the name after the ":" in a Physical Group name (e.g. "mms_material" from "material:mms_material").
void CheckMaterialIDsOnElements ()
 Check that the material IDs on the elements are set on construction.

Private Attributes

std::vector< Node > nodes_
 Nodes in the mesh.
std::vector< size_t > boundary_node_ids_
 Nodes in the mesh that exist on the mesh boundaries (that is, they have a boundary condition assigned).
std::vector< std::unique_ptr< Element > > elements_
 Elements in the mesh.
unsigned int dimension_ = 0
 Spatial dimension of the mesh's elements, set by the first call to AddElement. 0 if no elements have been added yet.
std::unordered_map< int, std::string > physical_names_
 Map from Physical Group tag to its name (e.g. "material:foo"), persisted from GmshReadState::physical_names for use by ResolveIDs after reading is done.

Detailed Description

Class defing a mesh.

Definition at line 27 of file mesh.h.

Constructor & Destructor Documentation

◆ Mesh() [1/2]

hummingbird::Mesh::Mesh ( )
default

Construct a new Mesh object.

◆ Mesh() [2/2]

hummingbird::Mesh::Mesh ( const std::string & msh_file)

Construct a new Mesh object from a gmsh .msh file.

Parameters
msh_filegmsh .msh file

Definition at line 21 of file mesh.cc.

Member Function Documentation

◆ AddElement()

void hummingbird::Mesh::AddElement ( std::unique_ptr< Element > element)

Add element to Mesh.

Parameters
elementElement

Definition at line 41 of file mesh.cc.

◆ AddNode()

void hummingbird::Mesh::AddNode ( const Node & node)

Add node to Mesh.

Parameters
nodeNode

Definition at line 35 of file mesh.cc.

◆ AddNodes()

void hummingbird::Mesh::AddNodes ( const std::vector< Node > & nodes)

Add nodes in a vector to Mesh.

Parameters
nodesNodes

Definition at line 37 of file mesh.cc.

◆ boundary_node_ids()

const std::vector< size_t > & hummingbird::Mesh::boundary_node_ids ( ) const
inline

Get the boundary node IDs.

Returns
const std::vector<size_t>&

Definition at line 123 of file mesh.h.

◆ CheckMaterialIDsOnElements()

void hummingbird::Mesh::CheckMaterialIDsOnElements ( )
private

Check that the material IDs on the elements are set on construction.

Definition at line 26 of file mesh.cc.

◆ CheckNodeIDs()

void hummingbird::Mesh::CheckNodeIDs ( )
private

Check that all Node IDs are unique and continuous from 0 to N-1 for N total nodes.

Exceptions
std::runtime_errorPrints expected ID, found ID, and previous ID.

Definition at line 102 of file mesh.cc.

◆ CreateInteriorElementNodes()

void hummingbird::Mesh::CreateInteriorElementNodes ( const GaussLobattoLegendre & gll_quadrature)

Create interior nodes on elements using Gauss-Lobatto-Legendre quadrature set and add to Mesh.

Parameters
gll_quadratureGauss-Lobatto-Legendre quadrature set

Definition at line 60 of file mesh.cc.

◆ dimension()

unsigned int hummingbird::Mesh::dimension ( ) const
inline

Get the spatial dimension of the mesh, derived from the elements it contains (e.g. 1 for a mesh of Segments). 0 if no elements have been added yet.

Returns
unsigned int

Definition at line 116 of file mesh.h.

◆ elements()

const std::vector< std::unique_ptr< Element > > & hummingbird::Mesh::elements ( ) const
inline

Get the elements in the mesh.

Returns
const std::vector<std::unique_ptr<Element>>&

Definition at line 83 of file mesh.h.

◆ ExtractName()

std::string hummingbird::Mesh::ExtractName ( const std::string & physical_name) const
private

Extract the name after the ":" in a Physical Group name (e.g. "mms_material" from "material:mms_material").

Parameters
physical_namePhysical Group name
Returns
std::string

Definition at line 363 of file mesh.cc.

◆ FindBoundaryNodes()

void hummingbird::Mesh::FindBoundaryNodes ( )

Populates the boundary_node_ids_ member. Must be called after ResolveIDs!

Definition at line 367 of file mesh.cc.

◆ GetBCID()

int hummingbird::Mesh::GetBCID ( const std::vector< int > & point_physical_tags,
const std::unordered_map< int, std::string > & physical_names ) const
private

Find the BC ID for a point entity, defined as the tag of the Physical Group on that point whose name is prefixed with "bc:" (see cases/README.md).

Exceptions
std::runtime_errorif no such Physical Group is found
Parameters
point_physical_tagsPhysical Group tags assigned to the point
physical_namesMap from Physical Group tag to name
Returns
int

Definition at line 310 of file mesh.cc.

◆ GetElement()

const Element & hummingbird::Mesh::GetElement ( const size_t index) const
inline

Get an Element by index.

Parameters
indexIndex of the element
Returns
const Element&

Definition at line 133 of file mesh.h.

◆ GetMaterialID()

int hummingbird::Mesh::GetMaterialID ( const std::vector< int > & curve_physical_tags,
const std::unordered_map< int, std::string > & physical_names ) const
private

Find the material ID for a curve entity, defined as the tag of the Physical Group on that curve whose name is prefixed with "material:" (see cases/README.md).

Exceptions
std::runtime_errorif no such Physical Group is found
Parameters
curve_physical_tagsPhysical Group tags assigned to the curve
physical_namesMap from Physical Group tag to name
Returns
int

Definition at line 289 of file mesh.cc.

◆ GetNode()

const Node & hummingbird::Mesh::GetNode ( const size_t id) const
inline

Get Node by ID.

Parameters
idNodeID
Returns
const Node&

Definition at line 93 of file mesh.h.

◆ GetSourceID()

int hummingbird::Mesh::GetSourceID ( const std::vector< int > & curve_physical_tags,
const std::unordered_map< int, std::string > & physical_names ) const
private

Find the source ID for a curve entity, defined as the tag of the Physical Group on the curve whose name is prefixed with "source:" (see cases/README.md).

Exceptions
std::runtime_errorif no such Physical Group is found
Parameters
curve_physical_tagsPhysical Group tags assigned to the curve
physical_namesMap from Physical Group tag to name
Returns
int

Definition at line 300 of file mesh.cc.

◆ InitializeNodeSolutions()

void hummingbird::Mesh::InitializeNodeSolutions ( const size_t n_ordinates,
const QuadratureBase< Ordinate > & angular_quad_set,
const SourceBank & source_bank )

Initialize node solution vectors to the correct lengths. Scalar and angular fluxes are set to 0 and source fluxes are set to the element's external source.

Parameters
n_ordinatesNumber of ordinates
angular_quad_setAngular quadrature set
source_bankSource bank

Definition at line 320 of file mesh.cc.

◆ n_elements()

size_t hummingbird::Mesh::n_elements ( ) const
inline

Get the number of Elements in the mesh.

Returns
size_t

Definition at line 100 of file mesh.h.

◆ n_nodes()

size_t hummingbird::Mesh::n_nodes ( ) const
inline

Get the number of nodes in the mesh.

Returns
size_t

Definition at line 107 of file mesh.h.

◆ nodes()

const std::vector< Node > & hummingbird::Mesh::nodes ( ) const
inline

Get the Nodes in the mesh.

Returns
const std::vector<Node>&

Definition at line 76 of file mesh.h.

◆ Prepare()

void hummingbird::Mesh::Prepare ( const GaussLobattoLegendre & gll_quadrature)

Prepare the mesh for running a simulation by generating interior nodes using the GLL quadrature set, renumbering nodes, then checking these nodes.

Parameters
gll_quadratureGaussLegendreLobatto quadrature set

Definition at line 54 of file mesh.cc.

◆ ReadElements()

void hummingbird::Mesh::ReadElements ( std::ifstream & file,
GmshReadState & state )
private

Read the $Elements section, adding Segment elements to the mesh for 2-node line elements. Point elements are consumed and used to tag the boundary/bc_id of the Node they reference, since they mark boundary entities in gmsh.

Exceptions
std::runtime_errorfor any element type other than a point or a 2-node line, since only 1D meshes are currently supported
Parameters
filegmsh file stream, positioned just after the section header
stateShared gmsh read state

Definition at line 228 of file mesh.cc.

◆ ReadEntities()

void hummingbird::Mesh::ReadEntities ( std::ifstream & file,
GmshReadState & state )
private

Read the $Entities section into state.point_physical_tags and state.curve_physical_tags.

Exceptions
std::runtime_errorif the mesh contains surface or volume entities, since only 1D (point/curve) meshes are currently supported
Parameters
filegmsh file stream, positioned just after the section header
stateShared gmsh read state

Definition at line 155 of file mesh.cc.

◆ ReadGMSH()

void hummingbird::Mesh::ReadGMSH ( const std::string & msh_file)
private

Construct a Mesh from a gmsh ASCII (format 4.1) .msh file. Reading routes to a section-specific subroutine using an unordered_map keyed by the gmsh section header (e.g. "$Nodes"). Only the sections needed to build 1D meshes (Segment elements, from 2-node line elements and Physical Point/Curve groups) are currently handled; support for 2D quad elements can be added later by extending ReadElements without needing to restructure this dispatch.

Parameters
msh_filePath to the gmsh .msh file

Definition at line 114 of file mesh.cc.

◆ ReadNodes()

void hummingbird::Mesh::ReadNodes ( std::ifstream & file,
GmshReadState & state )
private

Read the $Nodes section, adding Node objects to the mesh and recording the gmsh tag to Node ID mapping in state.node_tag_to_id.

Parameters
filegmsh file stream, positioned just after the section header
stateShared gmsh read state

Definition at line 198 of file mesh.cc.

◆ ReadPhysicalNames()

void hummingbird::Mesh::ReadPhysicalNames ( std::ifstream & file,
GmshReadState & state )
private

Read the $PhysicalNames section into state.physical_names.

Parameters
filegmsh file stream, positioned just after the section header
stateShared gmsh read state

Definition at line 143 of file mesh.cc.

◆ RenumberNodes()

void hummingbird::Mesh::RenumberNodes ( )
private

Renumber nodes in mesh to keep node IDs near each other in a single element.

Definition at line 68 of file mesh.cc.

◆ ResolveIDs()

void hummingbird::Mesh::ResolveIDs ( const MaterialBank & material_bank,
const SourceBank & source_bank,
const BCBank & bc_bank )

Resolve the raw gmsh Physical Group tags currently stored in material_id()/source_id()/bc_id (set from the .msh file alone, with no bank access) into the real IDs assigned by the given banks, by looking up the name each tag's Physical Group carries (e.g. "mms_material" from "material:mms_material") via BankBase::GetIDByName. Nodes with bc_id == 0 (never tagged by a point element) are left alone.

Exceptions
std::runtime_errorif a material name from the mesh has no match in material_bank
Parameters
material_bankMaterial bank
source_bankSource bank
bc_bankBC bank

Definition at line 337 of file mesh.cc.

◆ SetNodeSourceFluxes()

void hummingbird::Mesh::SetNodeSourceFluxes ( const size_t node_id,
const std::vector< double > & source_fluxes )
inline

Set the Node's source flux values.

Parameters
node_idNode ID
source_fluxesSource fluxes

Definition at line 217 of file mesh.h.

◆ SetOutwardNormals()

void hummingbird::Mesh::SetOutwardNormals ( )

Set the outward-pointing unit normal vector on each boundary node (Node::outward_normal), normalized via arma::normalise. Must be called after FindBoundaryNodes (needs boundary_node_ids_ populated) and after Prepare (needs final, renumbered node ids).

Exceptions
std::runtime_errorif the mesh is not 1D (not yet implemented for other dimensions)

Definition at line 373 of file mesh.cc.

◆ UpdateNodeAngularFluxes()

void hummingbird::Mesh::UpdateNodeAngularFluxes ( const SEMProblem & sem_problem,
const size_t n_ordinates )

Update the nodes' angular flux values.

Parameters
sem_problemSEMProblem object containing updated flux values
n_ordinatesNumber of ordinates

Definition at line 391 of file mesh.cc.

◆ UpdateNodeScalarFluxes()

void hummingbird::Mesh::UpdateNodeScalarFluxes ( const QuadratureBase< Ordinate > & angular_quad_set)

Update the nodes' scalar flux values.

Parameters
angular_quad_setAngular quadrature set

Definition at line 386 of file mesh.cc.

Member Data Documentation

◆ boundary_node_ids_

std::vector<size_t> hummingbird::Mesh::boundary_node_ids_
private

Nodes in the mesh that exist on the mesh boundaries (that is, they have a boundary condition assigned).

Definition at line 228 of file mesh.h.

◆ dimension_

unsigned int hummingbird::Mesh::dimension_ = 0
private

Spatial dimension of the mesh's elements, set by the first call to AddElement. 0 if no elements have been added yet.

Definition at line 235 of file mesh.h.

◆ elements_

std::vector<std::unique_ptr<Element> > hummingbird::Mesh::elements_
private

Elements in the mesh.

Definition at line 231 of file mesh.h.

◆ nodes_

std::vector<Node> hummingbird::Mesh::nodes_
private

Nodes in the mesh.

Definition at line 224 of file mesh.h.

◆ physical_names_

std::unordered_map<int, std::string> hummingbird::Mesh::physical_names_
private

Map from Physical Group tag to its name (e.g. "material:foo"), persisted from GmshReadState::physical_names for use by ResolveIDs after reading is done.

Definition at line 240 of file mesh.h.


The documentation for this class was generated from the following files:
  • /home/runner/work/hummingbird/hummingbird/include/mesh/mesh.h
  • /home/runner/work/hummingbird/hummingbird/src/mesh/mesh.cc