Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
mesh.cpp
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Serac Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
7 #include "serac/physics/mesh.hpp"
8 
9 #include <utility>
10 
11 #include <axom/fmt.hpp>
12 #include <axom/slic.hpp>
13 
18 
19 namespace serac {
20 
21 Mesh::Mesh(const std::string& meshfile, const std::string& meshtag, int refine_serial, int refine_parallel,
22  MPI_Comm comm)
23  : mesh_tag_(meshtag)
24 {
25  auto meshtmp = mesh::refineAndDistribute(buildMeshFromFile(meshfile), refine_serial, refine_parallel, comm);
26  mfem_mesh_ = &serac::StateManager::setMesh(std::move(meshtmp), mesh_tag_);
27  createDomains();
28 }
29 
30 Mesh::Mesh(mfem::Mesh&& mesh, const std::string& meshtag, int refine_serial, int refine_parallel, MPI_Comm comm)
31  : mesh_tag_(meshtag)
32 {
33  auto meshtmp = serac::mesh::refineAndDistribute(std::move(mesh), refine_serial, refine_parallel, comm);
34  mfem_mesh_ = &serac::StateManager::setMesh(std::move(meshtmp), mesh_tag_);
35  createDomains();
36 }
37 
38 Mesh::Mesh(mfem::ParMesh&& mesh, const std::string& meshtag) : mesh_tag_(meshtag)
39 {
40  auto meshtmp = std::make_unique<mfem::ParMesh>(std::move(mesh));
41  meshtmp->EnsureNodes();
42  meshtmp->ExchangeFaceNbrData();
43  mfem_mesh_ = &serac::StateManager::setMesh(std::move(meshtmp), mesh_tag_);
44  createDomains();
45 }
46 
47 MPI_Comm Mesh::getComm() const { return mfem_mesh_->GetComm(); }
48 
49 void Mesh::createDomains()
50 {
51  domains_.insert({entireBodyName(), serac::EntireDomain(*mfem_mesh_)});
52  domains_.insert({entireBoundaryName(), serac::EntireBoundary(*mfem_mesh_)});
53  domains_.insert({internalBoundaryName(), serac::InteriorFaces(*mfem_mesh_)});
54 }
55 
57 
59 
61 
62 serac::Domain& Mesh::domain(const std::string& domain_name) const
63 {
64  SLIC_ERROR_IF(domains_.find(domain_name) == domains_.end(),
65  axom::fmt::format("Could not find domain named {0} in mesh with tag {1}", domain_name, mesh_tag_));
66  return domains_.at(domain_name);
67 }
68 
69 serac::Domain& Mesh::addDomainOfBoundaryElements(const std::string& domain_name,
70  std::function<bool(std::vector<vec2>, int)> func)
71 {
72  SLIC_ERROR_IF(domains_.find(domain_name) != domains_.end(),
73  axom::fmt::format("A domain named {0} already exists in mesh with tag {1}", domain_name, mesh_tag_));
74  domains_.emplace(domain_name, Domain::ofBoundaryElements(*mfem_mesh_, func));
75  return domain(domain_name);
76 }
77 
78 serac::Domain& Mesh::addDomainOfBoundaryElements(const std::string& domain_name,
79  std::function<bool(std::vector<vec3>, int)> func)
80 {
81  SLIC_ERROR_IF(domains_.find(domain_name) != domains_.end(),
82  axom::fmt::format("A domain named {0} already exists in mesh with tag {1}", domain_name, mesh_tag_));
83  domains_.emplace(domain_name, Domain::ofBoundaryElements(*mfem_mesh_, func));
84  return domain(domain_name);
85 }
86 
87 serac::Domain& Mesh::addDomainOfBodyElements(const std::string& domain_name,
88  std::function<bool(std::vector<vec2>, int)> func)
89 {
90  SLIC_ERROR_IF(domains_.find(domain_name) != domains_.end(),
91  axom::fmt::format("A domain named {0} already exists in mesh with tag {1}", domain_name, mesh_tag_));
92  domains_.emplace(domain_name, Domain::ofElements(*mfem_mesh_, func));
93  return domain(domain_name);
94 }
95 
96 serac::Domain& Mesh::addDomainOfBodyElements(const std::string& domain_name,
97  std::function<bool(std::vector<vec3>, int)> func)
98 {
99  SLIC_ERROR_IF(domains_.find(domain_name) != domains_.end(),
100  axom::fmt::format("A domain named {0} already exists in mesh with tag {1}", domain_name, mesh_tag_));
101  domains_.emplace(domain_name, Domain::ofElements(*mfem_mesh_, func));
102  return domain(domain_name);
103 }
104 
105 const mfem::ParFiniteElementSpace& Mesh::shapeDisplacementSpace()
106 {
108 }
109 
111 
113 
114 } // namespace serac
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.
serac::Domain & entireBody() const
Returns domain corresponding to the entire mesh.
Definition: mesh.cpp:56
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:30
serac::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:96
static std::string internalBoundaryName()
Returns string, name used to access the internal boundary elements.
Definition: mesh.hpp:87
const mfem::ParFiniteElementSpace & shapeDisplacementSpace()
get space associated with shape displacement
Definition: mesh.cpp:105
serac::Domain & internalBoundary() const
Returns domain boundary corresponding to the internal boundary elements.
Definition: mesh.cpp:60
serac::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:78
serac::FiniteElementState newShapeDisplacement()
create new shape displacement
Definition: mesh.cpp:110
static std::string entireBoundaryName()
Returns string, name used to access the entire boundary.
Definition: mesh.hpp:81
serac::Domain & entireBoundary() const
Returns domain boundary corresponding to the entire mesh.
Definition: mesh.cpp:58
serac::FiniteElementDual newShapeDisplacementDual()
create new shape displacement sensitivity
Definition: mesh.cpp:112
static std::string entireBodyName()
Returns string, name used to access the entire domain body.
Definition: mesh.hpp:75
const std::string & tag() const
Returns string tag for mesh.
Definition: mesh.hpp:63
MPI_Comm getComm() const
Returns parallel communicator.
Definition: mesh.cpp:47
serac::Domain & domain(const std::string &domain_name) const
Returns registered domain with specified name.
Definition: mesh.cpp:62
static FiniteElementDual & shapeDisplacementDual(const std::string &mesh_tag)
Get the shape displacement finite element dual.
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.
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....
Serac 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.
Definition: mesh_utils.cpp:458
Accelerator functionality.
Definition: serac.cpp:36
Domain InteriorFaces(const mesh_t &mesh)
constructs a domain from all the interior face elements in a mesh
Definition: domain.cpp:625
mfem::Mesh buildMeshFromFile(const std::string &mesh_file)
Constructs an MFEM mesh from a file.
Definition: mesh_utils.cpp:25
Domain EntireBoundary(const mesh_t &mesh)
constructs a domain from all the boundary elements in a mesh
Definition: domain.cpp:609
Domain EntireDomain(const mesh_t &mesh)
constructs a domain from all the elements in a mesh
Definition: domain.cpp:594
This file contains the declaration of the StateManager class.
a class for representing a geometric region that can be used for integration
Definition: domain.hpp:33
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...
Definition: domain.cpp:368
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
Definition: domain.cpp:258