MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
submesh_utils.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_UTILS
13 #define MFEM_SUBMESH_UTILS
14 
15 #include <type_traits>
16 #include <unordered_map>
17 #include "submesh.hpp"
18 #include "../../fem/fespace.hpp"
19 
20 namespace mfem
21 {
22 namespace SubMeshUtils
23 {
24 
25 /**
26  * @brief Convenience object to create unique indices.
27  */
29 {
30  int counter = 0;
31  std::unordered_map<int, int> idx;
32 
33  /**
34  * @brief Returns the unique index from an index set.
35  *
36  * @param i index
37  * @param new_index indicates if the index is new or was already present in
38  * the set.
39  */
40  int Get(int i, bool &new_index);
41 };
42 
43 /**
44  * @brief Given an element @a el and a list of @a attributes, determine if that
45  * element is in at least one attribute of @a attributes.
46  *
47  * @param el The element
48  * @param attributes The attributes
49  */
50 bool ElementHasAttribute(const Element &el, const Array<int> &attributes);
51 
52 /**
53  * @brief Given a Mesh @a parent and another Mesh @a mesh using the list of
54  * attributes in @a attributes, this function adds matching elements with those
55  * attributes from @a parent to @a mesh.
56  *
57  * It also returns a tuple containing first the parent vertex ids (mapping from
58  * mesh vertex ids (index of the array), to the parent vertex ids) and second
59  * the parent element ids (mapping from submesh element ids (index of the
60  * array), to the parent element ids)
61  *
62  * @note Works with ParMesh.
63  *
64  * @param parent The Mesh where the elements are "extracted" from.
65  * @param mesh The Mesh where the elements are extracted to.
66  * @param attributes The attributes of the desired elements.
67  * @param from_boundary Indication if the desired elements come from the
68  * boundary of the parent.
69  */
70 std::tuple< Array<int>, Array<int> >
71 AddElementsToMesh(const Mesh& parent,
72  Mesh& mesh, const Array<int> &attributes,
73  bool from_boundary = false);
74 
75 /**
76  * @brief Given two meshes that have a parent to SubMesh relationship create a
77  * face map, using a SubMesh to parent Mesh element id map.
78  *
79  * @param parent The parent Mesh.
80  * @param mesh The Mesh to match its parents faces.
81  * @param parent_element_ids The Mesh element to parent element id map.
82  */
83 Array<int> BuildFaceMap(const Mesh& parent, const Mesh& mesh,
84  const Array<int> &parent_element_ids);
85 
86 /**
87  * @brief Build the vdof to vdof mapping between two FiniteElementSpace objects.
88  *
89  * Given two FiniteElementSpace objects and the map parent_element_ids, which
90  * maps the element ids of the subfes to elements on the parentfes (or boundary
91  * elements depending on the type of transfer, volume or surface), create a vdof
92  * to vdof map.
93  *
94  * This map is entirely serial and has no knowledge about parallel groups.
95  *
96  * @param[in] subfes
97  * @param[in] parentfes
98  * @param[in] from
99  * @param[in] parent_element_ids
100  * @param[out] vdof_to_vdof_map
101  */
102 void BuildVdofToVdofMap(const FiniteElementSpace& subfes,
103  const FiniteElementSpace& parentfes,
104  const SubMesh::From& from,
105  const Array<int>& parent_element_ids,
106  Array<int>& vdof_to_vdof_map);
107 
108 /**
109  * @brief Identify the root parent of a given SubMesh.
110  *
111  * @tparam T The type of the input object which has to fulfill the
112  * SubMesh::GetParent() interface.
113  */
114 template <class T, class RT>
115 const RT* GetRootParent(const T &m)
116 {
117  const RT* parent = m.GetParent();
118  while (true)
119  {
120  const T* next = dynamic_cast<const T*>(parent);
121  if (next == nullptr)
122  {
123  return static_cast<const RT *>(parent);
124  }
125  else
126  {
127  parent = next->GetParent();
128  }
129  }
130 }
131 
132 } // namespace SubMeshUtils
133 } // namespace mfem
134 
135 #endif
std::unordered_map< int, int > idx
Convenience object to create unique indices.
void BuildVdofToVdofMap(const FiniteElementSpace &subfes, const FiniteElementSpace &parentfes, const SubMesh::From &from, const Array< int > &parent_element_ids, Array< int > &vdof_to_vdof_map)
Build the vdof to vdof mapping between two FiniteElementSpace objects.
const RT * GetRootParent(const T &m)
Identify the root parent of a given SubMesh.
int Get(int i, bool &new_index)
Returns the unique index from an index set.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:96
std::tuple< Array< int >, Array< int > > AddElementsToMesh(const Mesh &parent, Mesh &mesh, const Array< int > &attributes, bool from_boundary)
Given a Mesh parent and another Mesh mesh using the list of attributes in attributes, this function adds matching elements with those attributes from parent to mesh.
Array< int > BuildFaceMap(const Mesh &pm, const Mesh &sm, const Array< int > &parent_element_ids)
Given two meshes that have a parent to SubMesh relationship create a face map, using a SubMesh to par...
From
Indicator from which part of the parent Mesh the SubMesh is created.
Definition: submesh.hpp:46
bool ElementHasAttribute(const Element &el, const Array< int > &attributes)
Given an element el and a list of attributes, determine if that element is in at least one attribute ...
Abstract data type element.
Definition: element.hpp:28