Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
mesh.hpp
Go to the documentation of this file.
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
13 #pragma once
14 
15 #include <memory>
16 #include <string>
17 #include <functional>
18 #include <map>
19 #include <vector>
20 
21 #include "mpi.h"
22 
23 #include "mfem.hpp"
26 
27 namespace smith {
28 
29 // Forward declare
30 struct Domain;
31 class FiniteElementState;
32 class FiniteElementDual;
33 
37 class Mesh {
38  public:
45  Mesh(mfem::Mesh&& mesh, const std::string& meshtag, int serial_refine = 0, int parallel_refine = 0,
46  MPI_Comm comm = MPI_COMM_WORLD);
47 
51  Mesh(mfem::ParMesh&& mesh, const std::string& meshtag);
52 
59  Mesh(const std::string& meshfile, const std::string& meshtag, int serial_refine = 0, int parallel_refine = 0,
60  MPI_Comm comm = MPI_COMM_WORLD);
61 
63  const std::string& tag() const { return mesh_tag_; }
64 
66  const mfem::ParMesh& mfemParMesh() const { return *mfem_mesh_; }
67 
69  mfem::ParMesh& mfemParMesh() { return *mfem_mesh_; }
70 
72  MPI_Comm getComm() const;
73 
75  static std::string entireBodyName() { return "entire_body"; }
76 
78  smith::Domain& entireBody() const;
79 
81  static std::string entireBoundaryName() { return "entire_boundary"; }
82 
85 
87  static std::string internalBoundaryName() { return "internal_boundary"; }
88 
91 
93  void insertDomain(const std::string& domain_name, const Domain& domain);
94 
96  smith::Domain& domain(const std::string& domain_name) const;
97 
101  smith::Domain& addDomainOfBoundaryElements(const std::string& domain_name,
102  std::function<bool(std::vector<vec3>, int)> func);
103 
107  smith::Domain& addDomainOfBoundaryElements(const std::string& domain_name,
108  std::function<bool(std::vector<vec2>, int)> func);
109 
113  smith::Domain& addDomainOfInternalBoundaryElements(const std::string& domain_name,
114  std::function<bool(std::vector<vec3>, int)> func);
115 
119  smith::Domain& addDomainOfInternalBoundaryElements(const std::string& domain_name,
120  std::function<bool(std::vector<vec2>, int)> func);
121 
125  smith::Domain& addDomainOfBodyElements(const std::string& domain_name,
126  std::function<bool(std::vector<vec3>, int)> func);
127 
131  smith::Domain& addDomainOfBodyElements(const std::string& domain_name,
132  std::function<bool(std::vector<vec2>, int)> func);
133 
135  const mfem::ParFiniteElementSpace& shapeDisplacementSpace();
136 
139 
142 
143  private:
146  void notifyIfRankHasNoElements() const;
147 
150  void createDomains();
151 
153  void errorIfDomainExists(const std::string& domain_name) const;
154 
156  std::string mesh_tag_;
157 
159  mfem::ParMesh* mfem_mesh_;
160 
162  mutable std::map<std::string, smith::Domain> domains_;
163 };
164 
165 } // namespace smith
Class for encapsulating the dual vector space of a finite element space (i.e. the space of linear for...
Class for encapsulating the critical MFEM components of a primal finite element field.
Helper class for constructing a mesh consistent with Smith.
Definition: mesh.hpp:37
void insertDomain(const std::string &domain_name, const Domain &domain)
Insert a domain onto mesh.
Definition: mesh.cpp:100
smith::Domain & entireBody() const
Returns domain corresponding to the entire mesh.
Definition: mesh.cpp:94
smith::FiniteElementDual newShapeDisplacementDual()
create new shape displacement sensitivity
Definition: mesh.cpp:169
mfem::ParMesh & mfemParMesh()
Returns parallel mfem mesh.
Definition: mesh.hpp:69
smith::Domain & domain(const std::string &domain_name) const
Returns registered domain with specified name.
Definition: mesh.cpp:107
const mfem::ParFiniteElementSpace & shapeDisplacementSpace()
get space associated with shape displacement
Definition: mesh.cpp:162
smith::Domain & addDomainOfBodyElements(const std::string &domain_name, std::function< bool(std::vector< vec3 >, int)> func)
create domain of 3D elements with specified name The second argument is a function taking a std::vect...
Definition: mesh.cpp:154
static std::string entireBodyName()
Returns string, name used to access the entire domain body.
Definition: mesh.hpp:75
smith::Domain & internalBoundary() const
Returns domain boundary corresponding to the internal boundary elements.
Definition: mesh.cpp:98
static std::string internalBoundaryName()
Returns string, name used to access the internal boundary elements.
Definition: mesh.hpp:87
smith::FiniteElementState newShapeDisplacement()
create new shape displacement
Definition: mesh.cpp:167
MPI_Comm getComm() const
Returns parallel communicator.
Definition: mesh.cpp:79
smith::Domain & entireBoundary() const
Returns domain boundary corresponding to the entire mesh.
Definition: mesh.cpp:96
const std::string & tag() const
Returns string tag for mesh.
Definition: mesh.hpp:63
const mfem::ParMesh & mfemParMesh() const
Returns const parallel mfem mesh.
Definition: mesh.hpp:66
smith::Domain & addDomainOfInternalBoundaryElements(const std::string &domain_name, std::function< bool(std::vector< vec3 >, int)> func)
create domain of 3D internal boundary elements with specified name The second argument is a function ...
Definition: mesh.cpp:138
Mesh(mfem::Mesh &&mesh, const std::string &meshtag, int serial_refine=0, int parallel_refine=0, MPI_Comm comm=MPI_COMM_WORLD)
Construct from existing serial mfem mesh.
Definition: mesh.cpp:31
static std::string entireBoundaryName()
Returns string, name used to access the entire boundary.
Definition: mesh.hpp:81
smith::Domain & addDomainOfBoundaryElements(const std::string &domain_name, std::function< bool(std::vector< vec3 >, int)> func)
create domain of 3D boundary elements with specified name The second argument is a function taking a ...
Definition: mesh.cpp:122
many of the functions in this file amount to extracting element indices from an mesh_t like
Accelerator functionality.
Definition: smith.cpp:36
a class for representing a geometric region that can be used for integration
Definition: domain.hpp:33
Implementation of the tensor class used by Functional.