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