12 #include <axom/slic.hpp>
21 Mesh::Mesh(
const std::string& meshfile,
const std::string& meshtag,
int refine_serial,
int refine_parallel,
27 notifyIfRankHasNoElements();
31 Mesh::Mesh(mfem::Mesh&& mesh,
const std::string& meshtag,
int refine_serial,
int refine_parallel, MPI_Comm comm)
36 notifyIfRankHasNoElements();
40 Mesh::Mesh(mfem::ParMesh&& mesh,
const std::string& meshtag) : mesh_tag_(meshtag)
42 auto meshtmp = std::make_unique<mfem::ParMesh>(std::move(mesh));
43 meshtmp->EnsureNodes();
44 meshtmp->ExchangeFaceNbrData();
46 notifyIfRankHasNoElements();
50 void Mesh::notifyIfRankHasNoElements()
const
53 MPI_Comm_rank(
getComm(), &myRank);
54 MPI_Comm_size(
getComm(), &numRanks);
55 int rankHasNoElements = (0 == mfem_mesh_->GetNE()) ? 1 : 0;
56 ::std::vector<int> gatheredRankData((0 == myRank) ?
static_cast<::std::size_t
>(numRanks) : 0);
57 MPI_Gather(&rankHasNoElements, 1, MPI_INT, gatheredRankData.data(), 1, MPI_INT, 0,
getComm());
59 ::std::vector<::std::size_t> ranksWithNoElements;
60 for (::std::size_t i = 0; i < static_cast<::std::size_t>(numRanks); ++i) {
61 if (1 == gatheredRankData[i]) {
62 ranksWithNoElements.push_back(i);
65 if (0 < ranksWithNoElements.size()) {
66 ::std::ostringstream msg;
67 msg <<
"\nAfter refining and distributing mesh, the following " << ranksWithNoElements.size()
68 <<
" ranks own zero elements:\n[";
69 for (const ::std::size_t& rank : ranksWithNoElements) {
76 ::axom::slic::flushStreams();
81 void Mesh::createDomains()
88 void Mesh::errorIfDomainExists(
const std::string& domain_name)
const
90 SLIC_ERROR_IF(domains_.find(domain_name) != domains_.end(),
91 std::format(
"A domain named {0} already exists in mesh with tag {1}", domain_name, mesh_tag_));
102 SLIC_ERROR_IF(&this->
mfemParMesh() != &domain.
mesh_,
"A domain inserted onto a mesh must be defined on that mesh");
103 errorIfDomainExists(domain_name);
104 domains_.insert({domain_name,
domain});
109 SLIC_ERROR_IF(domains_.find(domain_name) == domains_.end(),
110 std::format(
"Could not find domain named {0} in mesh with tag {1}", domain_name, mesh_tag_));
111 return domains_.at(domain_name);
115 std::function<
bool(std::vector<vec2>,
int)> func)
117 errorIfDomainExists(domain_name);
119 return domain(domain_name);
123 std::function<
bool(std::vector<vec3>,
int)> func)
125 errorIfDomainExists(domain_name);
127 return domain(domain_name);
131 std::function<
bool(std::vector<vec2>,
int)> func)
133 errorIfDomainExists(domain_name);
135 return domain(domain_name);
139 std::function<
bool(std::vector<vec3>,
int)> func)
141 errorIfDomainExists(domain_name);
143 return domain(domain_name);
147 std::function<
bool(std::vector<vec2>,
int)> func)
149 errorIfDomainExists(domain_name);
151 return domain(domain_name);
155 std::function<
bool(std::vector<vec3>,
int)> func)
157 errorIfDomainExists(domain_name);
159 return domain(domain_name);
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.
mfem::ParFiniteElementSpace & space()
Returns a non-owning reference to the internal FESpace.
void insertDomain(const std::string &domain_name, const Domain &domain)
Insert a domain onto mesh.
smith::Domain & entireBody() const
Returns domain corresponding to the entire mesh.
smith::FiniteElementDual newShapeDisplacementDual()
create new shape displacement sensitivity
smith::Domain & domain(const std::string &domain_name) const
Returns registered domain with specified name.
const mfem::ParFiniteElementSpace & shapeDisplacementSpace()
get space associated with shape displacement
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...
static std::string entireBodyName()
Returns string, name used to access the entire domain body.
smith::Domain & internalBoundary() const
Returns domain boundary corresponding to the internal boundary elements.
static std::string internalBoundaryName()
Returns string, name used to access the internal boundary elements.
smith::FiniteElementState newShapeDisplacement()
create new shape displacement
MPI_Comm getComm() const
Returns parallel communicator.
smith::Domain & entireBoundary() const
Returns domain boundary corresponding to the entire mesh.
const std::string & tag() const
Returns string tag for mesh.
const mfem::ParMesh & mfemParMesh() const
Returns const parallel mfem mesh.
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 ...
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.
static std::string entireBoundaryName()
Returns string, name used to access the entire boundary.
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 ...
static FiniteElementState & shapeDisplacement(const std::string &mesh_tag)
Get the shape displacement finite element state.
static mfem::ParMesh & setMesh(std::unique_ptr< mfem::ParMesh > pmesh, const std::string &mesh_tag)
Gives ownership of mesh to StateManager.
static FiniteElementDual & shapeDisplacementDual(const std::string &mesh_tag)
Get the shape displacement finite element dual.
This file contains helper traits and enumerations for classifying finite elements.
This contains a class that represents the dual of a finite element vector space, i....
Smith mesh class which assists in constructing the appropriate parallel mfem meshes and registering a...
This file contains helper functions for importing and managing various mesh objects.
std::unique_ptr< mfem::ParMesh > refineAndDistribute(mfem::Mesh &&serial_mesh, const int refine_serial, const int refine_parallel, const MPI_Comm comm)
Finalizes a serial mesh into a refined parallel mesh.
Accelerator functionality.
Domain EntireInteriorBoundary(const mesh_t &mesh)
constructs a domain from all the interior boundary elements in a mesh
Domain EntireBoundary(const mesh_t &mesh)
constructs a domain from all the boundary elements in a mesh
Domain EntireDomain(const mesh_t &mesh)
constructs a domain from all the elements in a mesh
mfem::Mesh buildMeshFromFile(const std::string &mesh_file)
Constructs an MFEM mesh from a file.
This file contains the declaration of the StateManager class.
a class for representing a geometric region that can be used for integration
static Domain ofElements(const mesh_t &mesh, std::function< bool(std::vector< vec2 >, int)> func)
create a domain from some subset of the elements (spatial dim == geometry dim) in an mfem::Mesh
static Domain ofBoundaryElements(const mesh_t &mesh, std::function< bool(std::vector< vec2 >, int)> func)
create a domain from some subset of the boundary elements (spatial dim == geometry dim + 1) in an mfe...
static Domain ofInteriorBoundaryElements(const mesh_t &mesh, std::function< bool(std::vector< vec2 >, int)> func)
create a domain from some subset of the interior boundary elements in an a mesh
const mesh_t & mesh_
the underyling mesh for this domain