MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
submesh.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, 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 
19 namespace 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  */
42 class SubMesh : public Mesh
43 {
44 public:
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 parent vertex id map.
125  *
126  * SubMesh vertex id (array index) to parent Mesh vertex id.
127  */
129  {
130  return parent_vertex_ids_;
131  }
132 
133  /**
134  * @brief Transfer the dofs of a GridFunction.
135  *
136  * The @a src GridFunction can either be defined on a Mesh or a SubMesh and
137  * is transferred appropriately.
138  *
139  * @note Either @a src or @a dst has to be defined on a SubMesh.
140  *
141  * @param[in] src
142  * @param[out] dst
143  */
144  static void Transfer(const GridFunction &src, GridFunction &dst);
145 
146  /**
147  * @brief Create a Transfer Map object.
148  *
149  * The @a src GridFunction can either be defined on a Mesh or a
150  * SubMesh and is transferred appropriately.
151  *
152  * @note Either @a src or @a dst has to be defined on a SubMesh.
153  */
154  static TransferMap CreateTransferMap(const GridFunction &src,
155  const GridFunction &dst);
156 
157  /**
158  * @brief Check if Mesh @a m is a SubMesh.
159  *
160  * @param m The input Mesh
161  */
162  static bool IsSubMesh(const Mesh *m)
163  {
164  return dynamic_cast<const SubMesh *>(m) != nullptr;
165  }
166 
167  ~SubMesh();
168 
169 private:
170  /// Private constructor
171  SubMesh(const Mesh &parent, From from, Array<int> attributes);
172 
173  /// The parent Mesh
174  const Mesh &parent_;
175 
176  /// Indicator from which part of the parent ParMesh the ParSubMesh is going
177  /// to be created.
178  From from_;
179 
180  /// Attributes on the parent ParMesh on which the ParSubMesh is created.
181  /// Could either be domain or boundary attributes (determined by from_).
182  Array<int> attributes_;
183 
184  /// Mapping from submesh element ids (index of the array), to the parent
185  /// element ids.
186  Array<int> parent_element_ids_;
187 
188  /// Mapping from submesh vertex ids (index of the array), to the parent
189  /// vertex ids.
190  Array<int> parent_vertex_ids_;
191 
192  /// Mapping from SubMesh face ids (index of the array), to the parent Mesh
193  /// face ids.
194  Array<int> parent_face_ids_;
195 
196  Array<int> face_to_be;
197 };
198 
199 } // namespace mfem
200 
201 #endif
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:30
const Array< int > & GetParentFaceIDMap() const
Get the face id map.
Definition: submesh.hpp:118
const Array< int > & GetParentElementIDMap() const
Get the parent element id map.
Definition: submesh.hpp:108
static SubMesh CreateFromDomain(const Mesh &parent, Array< int > domain_attributes)
Create a domain SubMesh from its parent.
Definition: submesh.cpp:19
const Mesh * GetParent() const
Get the parent Mesh object.
Definition: submesh.hpp:87
const Array< int > & GetParentVertexIDMap() const
Get the parent vertex id map.
Definition: submesh.hpp:128
TransferMap represents a mapping of degrees of freedom from a source GridFunction to a destination Gr...
Definition: transfermap.hpp:30
static bool IsSubMesh(const Mesh *m)
Check if Mesh m is a SubMesh.
Definition: submesh.hpp:162
static const int GENERATED_ATTRIBUTE
Definition: submesh.hpp:52
From GetFrom() const
Get the From indicator.
Definition: submesh.hpp:98
From
Indicator from which part of the parent Mesh the SubMesh is created.
Definition: submesh.hpp:46
static void Transfer(const GridFunction &src, GridFunction &dst)
Transfer the dofs of a GridFunction.
Definition: submesh.cpp:106
static TransferMap CreateTransferMap(const GridFunction &src, const GridFunction &dst)
Create a Transfer Map object.
Definition: submesh.cpp:112
Subdomain representation of a topological parent in another Mesh.
Definition: submesh.hpp:42
static SubMesh CreateFromBoundary(const Mesh &parent, Array< int > boundary_attributes)
Create a surface SubMesh from its parent.
Definition: submesh.cpp:25
SubMesh()=delete
Array< int > attributes
A list of all unique element attributes used by the Mesh.
Definition: mesh.hpp:268