MFEM  v4.5.1
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
submesh.cpp
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 #include "submesh.hpp"
13 #include "submesh_utils.hpp"
14 #include "../../fem/gridfunc.hpp"
15 
16 namespace mfem
17 {
18 
20  Array<int> domain_attributes)
21 {
22  return SubMesh(parent, From::Domain, domain_attributes);
23 }
24 
26  Array<int> boundary_attributes)
27 {
28  return SubMesh(parent, From::Boundary, boundary_attributes);
29 }
30 
31 SubMesh::SubMesh(const Mesh &parent, From from,
32  Array<int> attributes) : parent_(parent), from_(from), attributes_(attributes)
33 {
34  if (Nonconforming())
35  {
36  MFEM_ABORT("SubMesh does not support non-conforming meshes");
37  }
38 
39  if (from == From::Domain)
40  {
41  InitMesh(parent.Dimension(), parent.SpaceDimension(), 0, 0, 0);
42 
43  std::tie(parent_vertex_ids_,
44  parent_element_ids_) = SubMeshUtils::AddElementsToMesh(parent_, *this,
45  attributes_);
46  }
47  else if (from == From::Boundary)
48  {
49  InitMesh(parent.Dimension() - 1, parent.SpaceDimension(), 0, 0, 0);
50 
51  std::tie(parent_vertex_ids_,
52  parent_element_ids_) = SubMeshUtils::AddElementsToMesh(parent_, *this,
53  attributes_, true);
54  }
55 
56  FinalizeTopology(true);
57 
58  if (Dim == 3)
59  {
60  parent_face_ids_ = SubMeshUtils::BuildFaceMap(parent, *this,
61  parent_element_ids_);
62 
63  Array<int> parent_face_to_be = parent.GetFaceToBdrElMap();
64 
65  for (int i = 0; i < NumOfBdrElements; i++)
66  {
67  int pbeid = parent_face_to_be[parent_face_ids_[GetBdrFace(i)]];
68  if (pbeid != -1)
69  {
70  int attr = parent.GetBdrElement(pbeid)->GetAttribute();
71  GetBdrElement(i)->SetAttribute(attr);
72  }
73  else
74  {
75  // This case happens when a domain is extracted, but the root parent
76  // mesh didn't have a boundary element on the surface that defined
77  // it's boundary. It still creates a valid mesh, so we allow it.
79  }
80  }
81  }
82 
83  // If the parent Mesh has nodes and therefore is defined on a higher order
84  // geometry, we define this SubMesh as a curved Mesh and transfer the
85  // GridFunction from the parent Mesh to the SubMesh.
86  const GridFunction *parent_nodes = parent.GetNodes();
87  if (parent_nodes)
88  {
89  const FiniteElementSpace *parent_fes = parent_nodes->FESpace();
90 
92  parent_fes->FEColl()->GetOrder(),
93  parent_fes->IsDGSpace(),
94  spaceDim,
95  parent_fes->GetOrdering());
96 
97  Transfer(*parent.GetNodes(), *GetNodes());
98  }
99 
100  SetAttributes();
101  Finalize();
102 }
103 
105 
107 {
108  TransferMap map(src, dst);
109  map.Transfer(src, dst);
110 }
111 
113  const GridFunction &dst)
114 {
115  return TransferMap(src, dst);
116 }
117 
118 } // namespace mfem
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:30
static SubMesh CreateFromDomain(const Mesh &parent, Array< int > domain_attributes)
Create a domain SubMesh from its parent.
Definition: submesh.cpp:19
bool Nonconforming() const
Definition: mesh.hpp:1651
virtual void SetAttributes()
Definition: mesh.cpp:1559
void Transfer(const GridFunction &src, GridFunction &dst) const
Transfer the source GridFunction to the destination GridFunction.
Definition: transfermap.cpp:90
TransferMap represents a mapping of degrees of freedom from a source GridFunction to a destination Gr...
Definition: transfermap.hpp:30
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
Definition: mesh.cpp:5343
int GetAttribute() const
Return element&#39;s attribute.
Definition: element.hpp:55
int Dimension() const
Definition: mesh.hpp:1006
int NumOfBdrElements
Definition: mesh.hpp:69
int SpaceDimension() const
Definition: mesh.hpp:1007
static const int GENERATED_ATTRIBUTE
Definition: submesh.hpp:52
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.
void FinalizeTopology(bool generate_bdr=true)
Finalize the construction of the secondary topology (connectivity) data of a Mesh.
Definition: mesh.cpp:2890
GridFunction * GetNodes()
Return a pointer to the internal node GridFunction (may be NULL).
Definition: mesh.hpp:1541
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...
void InitMesh(int Dim_, int spaceDim_, int NVert, int NElem, int NBdrElem)
Begin construction of a mesh.
Definition: mesh.cpp:1590
virtual void Finalize(bool refine=false, bool fix_orientation=false)
Finalize the construction of a general Mesh.
Definition: mesh.cpp:2983
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
void SetAttribute(const int attr)
Set element&#39;s attribute.
Definition: element.hpp:58
static SubMesh CreateFromBoundary(const Mesh &parent, Array< int > boundary_attributes)
Create a surface SubMesh from its parent.
Definition: submesh.cpp:25
int Dim
Definition: mesh.hpp:66
void GetNodes(Vector &node_coord) const
Definition: mesh.cpp:7908
Array< int > GetFaceToBdrElMap() const
Definition: mesh.cpp:1437
int GetBdrFace(int BdrElemNo) const
Return the local face index for the given boundary face.
Definition: mesh.cpp:1113
int spaceDim
Definition: mesh.hpp:67
SubMesh()=delete
const Element * GetBdrElement(int i) const
Definition: mesh.hpp:1044