MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
submesh.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_SUBMESH
13#define MFEM_SUBMESH
14
15#include "../mesh.hpp"
16#include "transfermap.hpp"
17#include <unordered_map>
18
19namespace mfem
20{
21
22/**
23 * @brief Subdomain representation of a topological parent in another Mesh.
24 *
25 * SubMesh is a subdomain representation of a Mesh defined on its parents
26 * attributes. The current implementation creates either a domain or surface
27 * subset of the parents Mesh and reuses the parallel distribution.
28 *
29 * The attributes are taken from the parent. That means if a volume is extracted
30 * from a volume, it has the same domain attribute as the parent. Its boundary
31 * attributes are generated (there will be one boundary attribute 1 for all of
32 * the boundaries).
33 *
34 * If a surface is extracted from a volume, the boundary attribute from the
35 * parent is assigned to be the new domain attribute. Its boundary attributes
36 * are generated (there will be one boundary attribute 1 for all of the
37 * boundaries).
38 *
39 * For more customized boundary attributes, the resulting SubMesh has to be
40 * postprocessed.
41 */
42class SubMesh : public Mesh
43{
44public:
45 /// Indicator from which part of the parent Mesh the SubMesh is created.
46 enum From
47 {
50 };
51
52 static const int GENERATED_ATTRIBUTE = 900;
53
54 SubMesh() = delete;
55
56 /**
57 * @brief Create a domain SubMesh from its parent.
58 *
59 * The SubMesh object expects the parent Mesh object to be valid for the
60 * entire object lifetime. The @a domain_attributes have to mark exactly one
61 * connected subset of the parent Mesh.
62 *
63 * @param[in] parent Parent Mesh
64 * @param[in] domain_attributes Domain attributes to extract
65 */
66 static SubMesh CreateFromDomain(const Mesh &parent,
67 Array<int> domain_attributes);
68
69 /**
70 * @brief Create a surface SubMesh from its parent.
71 *
72 * The SubMesh object expects the parent Mesh object to be valid for the
73 * entire object lifetime. The @a boundary_attributes have to mark exactly one
74 * connected subset of the parent Mesh.
75 *
76 * @param[in] parent Parent Mesh
77 * @param[in] boundary_attributes Boundary attributes to extract
78
79 */
80 static SubMesh CreateFromBoundary(const Mesh &parent,
81 Array<int> boundary_attributes);
82
83 /**
84 * @brief Get the parent Mesh object
85 *
86 */
87 const Mesh* GetParent() const
88 {
89 return &parent_;
90 }
91
92 /**
93 * @brief Get the From indicator.
94 *
95 * Indicates whether the SubMesh has been created from a domain or
96 * surface.
97 */
98 From GetFrom() const
99 {
100 return from_;
101 }
102
103 /**
104 * @brief Get the parent element id map.
105 *
106 * SubMesh element id (array index) to parent Mesh element id.
107 */
109 {
110 return parent_element_ids_;
111 }
112
113 /**
114 * @brief Get the face id map
115 *
116 * SubMesh element id (array index) to parent Mesh face id.
117 */
119 {
120 return parent_face_ids_;
121 }
122
123 /**
124 * @brief Get the relative face orientations
125 *
126 * SubMesh element id (array index) to parent Mesh face orientation.
127 */
129 {
130 return parent_face_ori_;
131 }
132
133 /**
134 * @brief Get the parent vertex id map.
135 *
136 * SubMesh vertex id (array index) to parent Mesh vertex id.
137 */
139 {
140 return parent_vertex_ids_;
141 }
142
143 /**
144 * @brief Transfer the dofs of a GridFunction.
145 *
146 * The @a src GridFunction can either be defined on a Mesh or a SubMesh and
147 * is transferred appropriately.
148 *
149 * @note Either @a src or @a dst has to be defined on a SubMesh.
150 *
151 * @param[in] src
152 * @param[out] dst
153 */
154 static void Transfer(const GridFunction &src, GridFunction &dst);
155
156 /**
157 * @brief Create a Transfer Map object.
158 *
159 * The @a src GridFunction can either be defined on a Mesh or a
160 * SubMesh and is transferred appropriately.
161 *
162 * @note Either @a src or @a dst has to be defined on a SubMesh.
163 */
165 const GridFunction &dst);
166
167 /**
168 * @brief Check if Mesh @a m is a SubMesh.
169 *
170 * @param m The input Mesh
171 */
172 static bool IsSubMesh(const Mesh *m)
173 {
174 return dynamic_cast<const SubMesh *>(m) != nullptr;
175 }
176
177 ~SubMesh();
178
179private:
180 /// Private constructor
181 SubMesh(const Mesh &parent, From from, Array<int> attributes);
182
183 /// The parent Mesh
184 const Mesh &parent_;
185
186 /// Indicator from which part of the parent ParMesh the ParSubMesh is going
187 /// to be created.
188 From from_;
189
190 /// Attributes on the parent ParMesh on which the ParSubMesh is created.
191 /// Could either be domain or boundary attributes (determined by from_).
192 Array<int> attributes_;
193
194 /// Mapping from submesh element ids (index of the array), to the parent
195 /// element ids.
196 Array<int> parent_element_ids_;
197
198 /// Mapping from submesh vertex ids (index of the array), to the parent
199 /// vertex ids.
200 Array<int> parent_vertex_ids_;
201
202 /// Mapping from SubMesh edge ids (index of the array), to the parent Mesh
203 /// face ids.
204 Array<int> parent_edge_ids_;
205
206 /// Mapping from SubMesh face ids (index of the array), to the parent Mesh
207 /// face ids.
208 Array<int> parent_face_ids_;
209
210 /// Mapping from SubMesh face ids (index of the array), to the orientation
211 /// of the face relative to the parent face.
212 Array<int> parent_face_ori_;
213
214 Array<int> face_to_be;
215};
216
217} // namespace mfem
218
219#endif
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:31
Mesh data type.
Definition mesh.hpp:56
Array< int > attributes
A list of all unique element attributes used by the Mesh.
Definition mesh.hpp:280
Subdomain representation of a topological parent in another Mesh.
Definition submesh.hpp:43
static SubMesh CreateFromBoundary(const Mesh &parent, Array< int > boundary_attributes)
Create a surface SubMesh from its parent.
Definition submesh.cpp:25
const Array< int > & GetParentElementIDMap() const
Get the parent element id map.
Definition submesh.hpp:108
const Array< int > & GetParentFaceIDMap() const
Get the face id map.
Definition submesh.hpp:118
const Array< int > & GetParentVertexIDMap() const
Get the parent vertex id map.
Definition submesh.hpp:138
static void Transfer(const GridFunction &src, GridFunction &dst)
Transfer the dofs of a GridFunction.
Definition submesh.cpp:198
From GetFrom() const
Get the From indicator.
Definition submesh.hpp:98
static const int GENERATED_ATTRIBUTE
Definition submesh.hpp:52
static SubMesh CreateFromDomain(const Mesh &parent, Array< int > domain_attributes)
Create a domain SubMesh from its parent.
Definition submesh.cpp:19
static TransferMap CreateTransferMap(const GridFunction &src, const GridFunction &dst)
Create a Transfer Map object.
Definition submesh.cpp:204
SubMesh()=delete
const Array< int > & GetParentFaceOrientations() const
Get the relative face orientations.
Definition submesh.hpp:128
static bool IsSubMesh(const Mesh *m)
Check if Mesh m is a SubMesh.
Definition submesh.hpp:172
const Mesh * GetParent() const
Get the parent Mesh object.
Definition submesh.hpp:87
From
Indicator from which part of the parent Mesh the SubMesh is created.
Definition submesh.hpp:47
TransferMap represents a mapping of degrees of freedom from a source GridFunction to a destination Gr...