MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
fespacehierarchy.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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
15namespace 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
50 fespaces.DeleteAll();
51 meshes.DeleteAll();
52 prolongations.DeleteAll();
53}
54
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
117
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{
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
169
176
182
187#endif
188
189} // namespace mfem
int Append(const T &el)
Append element 'el' to array, resize if necessary.
Definition array.hpp:769
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Definition fe_coll.hpp:27
int GetNumLevels() const
Returns the number of levels in the hierarchy.
virtual const FiniteElementSpace & GetFinestFESpace() const
Returns the finite element space at the finest level.
int GetFinestLevelIndex() const
Returns the index of the finest level.
Operator * GetProlongationAtLevel(int level) const
Returns the prolongation operator from the finite element space at level to the finite element space ...
void AddLevel(Mesh *mesh, FiniteElementSpace *fespace, Operator *prolongation, bool ownM, bool ownFES, bool ownP)
Adds one level to the hierarchy.
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.
virtual ~FiniteElementSpaceHierarchy()
Destructor deleting all meshes and spaces that are owned.
virtual const FiniteElementSpace & GetFESpaceAtLevel(int level) const
Returns the finite element space at the given level.
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...
Array< FiniteElementSpace * > fespaces
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:220
const FiniteElementCollection * FEColl() const
Definition fespace.hpp:727
Mesh * GetMesh() const
Returns the mesh.
Definition fespace.hpp:559
Mesh data type.
Definition mesh.hpp:56
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Definition mesh.cpp:10970
Abstract operator.
Definition operator.hpp:25
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.
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...
const ParFiniteElementSpace & GetFinestFESpace() const override
Returns the finite element space at the finest level.
const ParFiniteElementSpace & GetFESpaceAtLevel(int level) const override
Returns the finite element space at the given level.
Abstract parallel finite element space.
Definition pfespace.hpp:29
ParMesh * GetParMesh() const
Definition pfespace.hpp:277
Class for parallel meshes.
Definition pmesh.hpp:34
Matrix-free transfer operator between finite element spaces.
Definition transfer.hpp:398
Matrix-free transfer operator between finite element spaces working on true degrees of freedom.
Definition transfer.hpp:502
int dim
Definition ex24.cpp:53
Mesh * GetMesh(int type)
Definition ex29.cpp:218