MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
submesh.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, 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
18namespace mfem
19{
20
21class NCSubMesh;
22
23/**
24 * @brief Subdomain representation of a topological parent in another Mesh.
25 *
26 * SubMesh is a subdomain representation of a Mesh defined on its parents
27 * attributes. The current implementation creates either a domain or surface
28 * subset of the parents Mesh and reuses the parallel distribution.
29 *
30 * The attributes are taken from the parent. That means if a volume is extracted
31 * from a volume, it has the same domain attribute as the parent. Its new
32 * boundary attributes are, for any boundary common to the parent and the new
33 * submesh, the boundary attribute of the parent; and, for all new boundaries,
34 * a single, generated, common attribute equal to one plus the largest boundary
35 * attribute of the parent.
36 *
37 * If a surface is extracted from a volume, the boundary attribute from the
38 * parent is assigned to be the new domain attribute. Its new boundary attribute
39 * is a single, generated, common attribute equal to one plus the largest
40 * boundary attribute of the parent.
41 *
42 * For more customized boundary attributes, the resulting SubMesh has to be
43 * postprocessed.
44 */
45class SubMesh : public Mesh
46{
47 friend class NCSubMesh;
48public:
49 /// Indicator from which part of the parent Mesh the SubMesh is created.
50 enum class From
51 {
52 Domain,
54 };
55
56 SubMesh() = delete;
57 SubMesh(SubMesh &&) = default;
58 SubMesh &operator=(SubMesh &&) = default;
59
60 /**
61 * @brief Create a domain SubMesh from its parent.
62 *
63 * The SubMesh object expects the parent Mesh object to be valid for the
64 * entire object lifetime. The @a domain_attributes have to mark exactly one
65 * connected subset of the parent Mesh.
66 *
67 * @param[in] parent Parent Mesh
68 * @param[in] domain_attributes Domain attributes to extract
69 */
70 static SubMesh CreateFromDomain(const Mesh &parent,
71 const Array<int> &domain_attributes);
72
73 /**
74 * @brief Create a surface SubMesh from its parent.
75 *
76 * The SubMesh object expects the parent Mesh object to be valid for the
77 * entire object lifetime. The @a boundary_attributes have to mark exactly one
78 * connected subset of the parent Mesh.
79 *
80 * @param[in] parent Parent Mesh
81 * @param[in] boundary_attributes Boundary attributes to extract
82
83 */
84 static SubMesh CreateFromBoundary(const Mesh &parent,
85 const Array<int> &boundary_attributes);
86
87 ///Get the parent Mesh object
88 const Mesh* GetParent() const
89 {
90 return parent_;
91 }
92
93 /**
94 * @brief Get the From indicator.
95 *
96 * Indicates whether the SubMesh has been created from a domain or 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 face id (array index) to parent Mesh face id.
117 */
119 {
120 return parent_face_ids_;
121 }
122
123 /**
124 * @brief Get the edge id map
125 *
126 * Submesh edge id (array index) to parent Mesh edge id.
127 */
129 {
130 return parent_edge_ids_;
131 }
132
133 /**
134 * @brief Get the relative face orientations
135 *
136 * SubMesh element id (array index) to parent Mesh face orientation.
137 */
139 {
140 return parent_face_ori_;
141 }
142
143 /**
144 * @brief Get the parent vertex id map.
145 *
146 * SubMesh vertex id (array index) to parent Mesh vertex id.
147 */
149 {
150 return parent_vertex_ids_;
151 }
152
153 /**
154 * @brief Get the submesh element corresponding to a parent element. -1 ==
155 * not present.
156 * @param pe The parent element id.
157 * @return int
158 */
160 {
161 return pe == -1 ? pe : parent_to_submesh_element_ids_[pe];
162 }
163 /**
164 * @brief Get the submesh vertex corresponding to a parent vertex. -1 == not
165 * present.
166 * @param pv The parent vertex id.
167 * @return int
168 */
170 {
171 return pv == -1 ? pv : parent_to_submesh_vertex_ids_[pv];
172 }
173 /**
174 * @brief Get the submesh edge corresponding to a parent edge. -1 == not
175 * present.
176 * @param pe The parent edge id.
177 * @return int
178 */
179 int GetSubMeshEdgeFromParent(int pe) const
180 {
181 return pe == -1 ? pe : parent_to_submesh_edge_ids_[pe];
182 }
183 /**
184 * @brief Get the submesh face corresponding to a parent face. -1 == not
185 * present.
186 * @param pf The parent face id.
187 * @return int
188 */
189 int GetSubMeshFaceFromParent(int pf) const
190 {
191 return pf == -1 ? pf : parent_to_submesh_face_ids_[pf];
192 }
193
194 /**
195 * @brief Transfer the dofs of a GridFunction.
196 *
197 * The @a src GridFunction can either be defined on a Mesh or a SubMesh and
198 * is transferred appropriately.
199 *
200 * @note Either @a src or @a dst has to be defined on a SubMesh.
201 *
202 * @param[in] src
203 * @param[out] dst
204 */
205 static void Transfer(const GridFunction &src, GridFunction &dst);
206
207 /**
208 * @brief Create a Transfer Map object.
209 *
210 * The @a src GridFunction can either be defined on a Mesh or a SubMesh and
211 * is transferred appropriately.
212 *
213 * @note Either @a src or @a dst has to be defined on a SubMesh.
214 */
216 const GridFunction &dst);
217
218 /**
219 * @brief Check if Mesh @a m is a SubMesh.
220 *
221 * @param m The input Mesh
222 */
223 static bool IsSubMesh(const Mesh *m)
224 {
225 return dynamic_cast<const SubMesh *>(m) != nullptr;
226 }
227
228 /**
229 * @brief Check if Mesh @a sub is a SubMesh of Mesh @a parent.
230 *
231 * @param sub The potential submesh Mesh
232 * @param parent The potential parent Mesh
233 */
234 static bool IsSubMesh(const Mesh* sub, const Mesh* parent)
235 {
236 while (IsSubMesh(sub) &&
237 (sub = static_cast<const SubMesh *>(sub)->GetParent()) &&
238 sub != parent);
239 return sub == parent;
240 }
241
242private:
243 /// Private constructor
244 SubMesh(const Mesh &parent, From from, const Array<int> &attributes);
245
246 /// The parent Mesh. Not owned.
247 const Mesh *parent_;
248
249 /// Optional nonconformal submesh. Managed via ncmesh pointer in base class.
250 NCSubMesh *ncsubmesh_;
251
252 /// Indicator from which part of the parent ParMesh the ParSubMesh is going
253 /// to be created.
254 From from_;
255
256 /// Attributes on the parent ParMesh on which the ParSubMesh is created.
257 /// Could either be domain or boundary attributes (determined by from_).
258 Array<int> attributes_;
259
260 /// Mapping from submesh element ids (index of the array), to the parent
261 /// element ids.
262 Array<int> parent_element_ids_;
263
264 /// Mapping from submesh vertex ids (index of the array), to the parent
265 /// vertex ids.
266 Array<int> parent_vertex_ids_;
267
268 /// Mapping from SubMesh edge ids (index of the array), to the parent Mesh
269 /// edge ids.
270 Array<int> parent_edge_ids_;
271
272 /// Mapping from SubMesh face ids (index of the array), to the parent Mesh
273 /// face ids.
274 Array<int> parent_face_ids_;
275
276 /// Mapping from SubMesh face ids (index of the array), to the orientation of
277 /// the face relative to the parent face.
278 Array<int> parent_face_ori_;
279
280 /// Mapping from parent Mesh element ids (index of the array), to the
281 /// SubMesh element ids. Inverse map of parent_element_ids_.
282 Array<int> parent_to_submesh_element_ids_;
283
284 /// Mapping from parent Mesh vertex ids (index of the array), to the SubMesh
285 /// vertex ids. Inverse map of parent_vertex_ids_.
286 Array<int> parent_to_submesh_vertex_ids_;
287
288 /// Mapping from parent Mesh edge ids (index of the array), to the SubMesh
289 /// edge ids. Inverse map of parent_edge_ids_.
290 Array<int> parent_to_submesh_edge_ids_;
291
292 /// Mapping from parent Mesh face ids (index of the array), to the SubMesh
293 /// face ids. Inverse map of parent_face_ids_.
294 Array<int> parent_to_submesh_face_ids_;
295};
296
297} // namespace mfem
298
299#endif
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:53
Mesh data type.
Definition mesh.hpp:67
Array< int > attributes
A list of all unique element attributes used by the Mesh.
Definition mesh.hpp:307
Class representing a Nonconformal SubMesh. This is only used by SubMesh.
Definition ncsubmesh.hpp:28
Subdomain representation of a topological parent in another Mesh.
Definition submesh.hpp:46
const Array< int > & GetParentElementIDMap() const
Get the parent element id map.
Definition submesh.hpp:108
static SubMesh CreateFromBoundary(const Mesh &parent, const Array< int > &boundary_attributes)
Create a surface SubMesh from its parent.
Definition submesh.cpp:27
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:148
static void Transfer(const GridFunction &src, GridFunction &dst)
Transfer the dofs of a GridFunction.
Definition submesh.cpp:260
const Array< int > & GetParentEdgeIDMap() const
Get the edge id map.
Definition submesh.hpp:128
int GetSubMeshFaceFromParent(int pf) const
Get the submesh face corresponding to a parent face. -1 == not present.
Definition submesh.hpp:189
SubMesh & operator=(SubMesh &&)=default
SubMesh(SubMesh &&)=default
static SubMesh CreateFromDomain(const Mesh &parent, const Array< int > &domain_attributes)
Create a domain SubMesh from its parent.
Definition submesh.cpp:21
From GetFrom() const
Get the From indicator.
Definition submesh.hpp:98
int GetSubMeshEdgeFromParent(int pe) const
Get the submesh edge corresponding to a parent edge. -1 == not present.
Definition submesh.hpp:179
static TransferMap CreateTransferMap(const GridFunction &src, const GridFunction &dst)
Create a Transfer Map object.
Definition submesh.cpp:265
int GetSubMeshElementFromParent(int pe) const
Get the submesh element corresponding to a parent element. -1 == not present.
Definition submesh.hpp:159
SubMesh()=delete
const Array< int > & GetParentFaceOrientations() const
Get the relative face orientations.
Definition submesh.hpp:138
static bool IsSubMesh(const Mesh *m)
Check if Mesh m is a SubMesh.
Definition submesh.hpp:223
const Mesh * GetParent() const
Get the parent Mesh object.
Definition submesh.hpp:88
int GetSubMeshVertexFromParent(int pv) const
Get the submesh vertex corresponding to a parent vertex. -1 == not present.
Definition submesh.hpp:169
static bool IsSubMesh(const Mesh *sub, const Mesh *parent)
Check if Mesh sub is a SubMesh of Mesh parent.
Definition submesh.hpp:234
From
Indicator from which part of the parent Mesh the SubMesh is created.
Definition submesh.hpp:51
TransferMap represents a mapping of degrees of freedom from a source GridFunction to a destination Gr...