MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
fespacehierarchy.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, 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 "fespacehierarchy.hpp"
13 #include "transfer.hpp"
14 
15 namespace mfem
16 {
17 
19  FiniteElementSpace* fespace,
20  bool ownM, bool ownFES)
21 {
22  meshes.Append(mesh);
23  fespaces.Append(fespace);
24  ownedMeshes.Append(ownM);
25  ownedFES.Append(ownFES);
26 }
27 
29 {
30  for (int i = 0; i < meshes.Size(); ++i)
31  {
32  if (ownedFES[i])
33  {
34  delete fespaces[i];
35  }
36  if (ownedMeshes[i])
37  {
38  delete meshes[i];
39  }
40  }
41 
42  for (int i = 0; i < prolongations.Size(); ++i)
43  {
44  if (ownedProlongations[i])
45  {
46  delete prolongations[i];
47  }
48  }
49 
51  meshes.DeleteAll();
52  prolongations.DeleteAll();
53 }
54 
55 int FiniteElementSpaceHierarchy::GetNumLevels() const { return meshes.Size(); }
56 
58 
60  FiniteElementSpace* fespace,
61  Operator* prolongation,
62  bool ownM, bool ownFES,
63  bool ownP)
64 {
65  meshes.Append(mesh);
66  fespaces.Append(fespace);
67  prolongations.Append(prolongation);
68  ownedMeshes.Append(ownM);
69  ownedFES.Append(ownFES);
71 }
72 
74  int ordering)
75 {
76  MFEM_VERIFY(GetNumLevels() > 0, "There is no level which can be refined");
77  Mesh* mesh = new Mesh(*GetFinestFESpace().GetMesh());
78  mesh->UniformRefinement();
79  FiniteElementSpace& coarseFEspace = GetFinestFESpace();
80  FiniteElementSpace* fineFEspace =
81  new FiniteElementSpace(mesh, coarseFEspace.FEColl(), dim, ordering);
82  Operator* P = new TransferOperator(coarseFEspace, *fineFEspace);
83  AddLevel(mesh, fineFEspace, P, true, true, true);
84 }
85 
87  fec, int dim,
88  int ordering)
89 {
90  MFEM_VERIFY(GetNumLevels() > 0, "There is no level which can be refined");
91  Mesh* mesh = GetFinestFESpace().GetMesh();
92  FiniteElementSpace* newFEspace =
93  new FiniteElementSpace(mesh, fec, dim, ordering);
94  Operator* P = new TransferOperator(GetFinestFESpace(), *newFEspace);
95  AddLevel(mesh, newFEspace, P, false, true, true);
96 }
97 
99  int level) const
100 {
101  MFEM_ASSERT(level < fespaces.Size(),
102  "FE space at given level does not exist.");
103  return *fespaces[level];
104 }
105 
107 {
108  MFEM_ASSERT(level < fespaces.Size(),
109  "FE space at given level does not exist.");
110  return *fespaces[level];
111 }
112 
114 {
116 }
117 
119 {
121 }
122 
124 {
125  MFEM_ASSERT(level < prolongations.Size(),
126  "Prolongation at given level does not exist.");
127  return prolongations[level];
128 }
129 
130 #ifdef MFEM_USE_MPI
131 
133  ParFiniteElementSpace* fespace,
134  bool ownM,
135  bool ownFES)
136  : FiniteElementSpaceHierarchy(mesh, fespace, ownM, ownFES)
137 {
138 }
139 
141  int ordering)
142 {
143  ParMesh* mesh = new ParMesh(*GetFinestFESpace().GetParMesh());
144  mesh->UniformRefinement();
145  ParFiniteElementSpace& coarseFEspace = GetFinestFESpace();
146  ParFiniteElementSpace* fineFEspace =
147  new ParFiniteElementSpace(mesh, coarseFEspace.FEColl(), dim, ordering);
148  Operator* P = new TrueTransferOperator(coarseFEspace, *fineFEspace);
149  AddLevel(mesh, fineFEspace, P, true, true, true);
150 }
151 
154  int dim, int ordering)
155 {
156  ParMesh* mesh = GetFinestFESpace().GetParMesh();
157  ParFiniteElementSpace* newFEspace =
158  new ParFiniteElementSpace(mesh, fec, dim, ordering);
159  Operator* P = new TrueTransferOperator(GetFinestFESpace(), *newFEspace);
160  AddLevel(mesh, newFEspace, P, false, true, true);
161 }
162 
165 {
166  return static_cast<const ParFiniteElementSpace&>(
168 }
169 
171  int level)
172 {
173  return static_cast<ParFiniteElementSpace&>(
175 }
176 
178 const
179 {
181 }
182 
184 {
186 }
187 #endif
188 
189 } // namespace mfem
virtual void AddOrderRefinedLevel(FiniteElementCollection *fec, int dim=1, int ordering=Ordering::byVDIM)
Adds one level to the hierarchy by using a different finite element order defined through FiniteEleme...
int Size() const
Return the logical size of the array.
Definition: array.hpp:124
ParMesh * GetParMesh() const
Definition: pfespace.hpp:243
const ParFiniteElementSpace & GetFinestFESpace() const override
Returns the finite element space at the finest level.
Abstract parallel finite element space.
Definition: pfespace.hpp:28
void DeleteAll()
Delete the whole array.
Definition: array.hpp:821
const ParFiniteElementSpace & GetFESpaceAtLevel(int level) const override
Returns the finite element space at the given level.
void AddOrderRefinedLevel(FiniteElementCollection *fec, int dim=1, int ordering=Ordering::byVDIM) override
Adds one level to the hierarchy by using a different finite element order defined through FiniteEleme...
void AddUniformlyRefinedLevel(int dim=1, int ordering=Ordering::byVDIM) override
Adds one level to the hierarchy by uniformly refining the mesh on the previous level.
int Append(const T &el)
Append element &#39;el&#39; to array, resize if necessary.
Definition: array.hpp:726
Mesh * GetMesh() const
Returns the mesh.
Definition: fespace.hpp:314
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition: mesh.cpp:8382
virtual ~FiniteElementSpaceHierarchy()
Destructor deleting all meshes and spaces that are owned.
Array< FiniteElementSpace * > fespaces
int GetNumLevels() const
Returns the number of levels in the hierarchy.
void AddLevel(Mesh *mesh, FiniteElementSpace *fespace, Operator *prolongation, bool ownM, bool ownFES, bool ownP)
Adds one level to the hierarchy.
int GetFinestLevelIndex() const
Returns the index of the finest level.
virtual const FiniteElementSpace & GetFESpaceAtLevel(int level) const
Returns the finite element space at the given level.
Matrix-free transfer operator between finite element spaces.
Definition: transfer.hpp:26
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition: fespace.hpp:87
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Definition: fe_coll.hpp:26
FiniteElementSpaceHierarchy(Mesh *mesh, FiniteElementSpace *fespace, bool ownM, bool ownFES)
Constructs a space hierarchy with the given mesh and space on the coarsest level. ...
virtual void AddUniformlyRefinedLevel(int dim=1, int ordering=Ordering::byVDIM)
Adds one level to the hierarchy by uniformly refining the mesh on the previous level.
ParFiniteElementSpaceHierarchy(ParMesh *mesh, ParFiniteElementSpace *fespace, bool ownM, bool ownFES)
Constructs a parallel space hierarchy with the given mesh and spaces on level zero.
int dim
Definition: ex24.cpp:53
const FiniteElementCollection * FEColl() const
Definition: fespace.hpp:414
Operator * GetProlongationAtLevel(int level) const
Returns the prolongation operator from the finite element space at level to the finite element space ...
Abstract operator.
Definition: operator.hpp:24
Class for parallel meshes.
Definition: pmesh.hpp:32
virtual const FiniteElementSpace & GetFinestFESpace() const
Returns the finite element space at the finest level.
Matrix-free transfer operator between finite element spaces working on true degrees of freedom...
Definition: transfer.hpp:130