MFEM  v3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
fespace.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_FESPACE
13 #define MFEM_FESPACE
14 
15 #include "../config/config.hpp"
16 #include "../linalg/sparsemat.hpp"
17 #include "../mesh/mesh.hpp"
18 #include "fe_coll.hpp"
19 #include <iostream>
20 
21 namespace mfem
22 {
23 
26 class Ordering
27 {
28 public:
32  enum Type { byNODES, byVDIM };
33 
34  template <Type Ord>
35  static inline int Map(int ndofs, int vdim, int dof, int vd);
36 
37  template <Type Ord>
38  static void DofsToVDofs(int ndofs, int vdim, Array<int> &dofs);
39 };
40 
41 template <> inline int
42 Ordering::Map<Ordering::byNODES>(int ndofs, int vdim, int dof, int vd)
43 {
44  MFEM_ASSERT(dof < ndofs && -1-dof < ndofs && 0 <= vd && vd < vdim, "");
45  return (dof >= 0) ? dof+ndofs*vd : dof-ndofs*vd;
46 }
47 
48 template <> inline int
49 Ordering::Map<Ordering::byVDIM>(int ndofs, int vdim, int dof, int vd)
50 {
51  MFEM_ASSERT(dof < ndofs && -1-dof < ndofs && 0 <= vd && vd < vdim, "");
52  return (dof >= 0) ? vd+vdim*dof : -1-(vd+vdim*(-1-dof));
53 }
54 
55 
56 class NURBSExtension;
57 
61 {
62 protected:
65 
67 
69  int vdim;
70 
75 
77  int ndofs;
78 
80  int *fdofs, *bdofs;
81 
82  mutable Table *elem_dof;
84 
86 
88  int own_ext;
89 
96  bool cP_is_set;
97 
100  bool own_T;
101 
102  long sequence; // should match Mesh::GetSequence
103 
104  void UpdateNURBS();
105 
106  void Construct();
107  void Destroy();
108 
109  void BuildElementToDofTable() const;
110 
114  void GetEdgeFaceDofs(int type, int index, Array<int> &dofs);
115 
118 
119  void MakeVDimMatrix(SparseMatrix &mat) const;
120 
122  SparseMatrix* RefinementMatrix(int old_ndofs, const Table* old_elem_dof);
123 
125  DenseTensor &localR);
126 
128  SparseMatrix* DerefinementMatrix(int old_ndofs, const Table* old_elem_dof);
129 
130 
131 public:
133  int vdim = 1, int ordering = Ordering::byNODES);
134 
136  inline Mesh *GetMesh() const { return mesh; }
137 
140 
141  bool Conforming() const { return mesh->Conforming(); }
142  bool Nonconforming() const { return mesh->Nonconforming(); }
143 
146 
148  { return GetConformingRestriction(); }
149 
151  inline int GetVDim() const { return vdim; }
152 
154  int GetOrder(int i) const;
156  int GetFaceOrder(int i) const;
157 
159  inline int GetNDofs() const { return ndofs; }
160 
161  inline int GetVSize() const { return vdim * ndofs; }
162 
164  virtual int GetTrueVSize() { return GetConformingVSize(); }
165 
168  int GetNConformingDofs();
169 
171 
173  inline Ordering::Type GetOrdering() const { return ordering; }
174 
175  const FiniteElementCollection *FEColl() const { return fec; }
176 
177  int GetNVDofs() const { return nvdofs; }
178  int GetNEDofs() const { return nedofs; }
179  int GetNFDofs() const { return nfdofs; }
180 
182  inline int GetNE() const { return mesh->GetNE(); }
183 
185  inline int GetNV() const { return mesh->GetNV(); }
186 
188  inline int GetNBE() const { return mesh->GetNBE(); }
189 
191  inline int GetElementType(int i) const
192  { return mesh->GetElementType(i); }
193 
195  inline void GetElementVertices(int i, Array<int> &vertices) const
196  { mesh->GetElementVertices(i, vertices); }
197 
199  inline int GetBdrElementType(int i) const
200  { return mesh->GetBdrElementType(i); }
201 
204  { return mesh->GetElementTransformation(i); }
205 
209  { mesh->GetElementTransformation(i, ElTr); }
210 
213  { return mesh->GetBdrElementTransformation(i); }
214 
215  int GetAttribute(int i) const { return mesh->GetAttribute(i); }
216 
217  int GetBdrAttribute(int i) const { return mesh->GetBdrAttribute(i); }
218 
220  virtual void GetElementDofs(int i, Array<int> &dofs) const;
221 
223  virtual void GetBdrElementDofs(int i, Array<int> &dofs) const;
224 
227  virtual void GetFaceDofs(int i, Array<int> &dofs) const;
228 
231  void GetEdgeDofs(int i, Array<int> &dofs) const;
232 
233  void GetVertexDofs(int i, Array<int> &dofs) const;
234 
235  void GetElementInteriorDofs(int i, Array<int> &dofs) const;
236 
237  int GetNumElementInteriorDofs(int i) const
239 
240  void GetEdgeInteriorDofs(int i, Array<int> &dofs) const;
241 
242  void DofsToVDofs(Array<int> &dofs, int ndofs = -1) const;
243 
244  void DofsToVDofs(int vd, Array<int> &dofs, int ndofs = -1) const;
245 
246  int DofToVDof(int dof, int vd, int ndofs = -1) const;
247 
248  int VDofToDof(int vdof) const
249  { return (ordering == Ordering::byNODES) ? (vdof%ndofs) : (vdof/vdim); }
250 
251  static void AdjustVDofs(Array<int> &vdofs);
252 
254  void GetElementVDofs(int i, Array<int> &vdofs) const;
255 
257  void GetBdrElementVDofs(int i, Array<int> &vdofs) const;
258 
260  void GetFaceVDofs(int i, Array<int> &vdofs) const;
261 
263  void GetEdgeVDofs(int i, Array<int> &vdofs) const;
264 
265  void GetVertexVDofs(int i, Array<int> &vdofs) const;
266 
267  void GetElementInteriorVDofs(int i, Array<int> &vdofs) const;
268 
269  void GetEdgeInteriorVDofs(int i, Array<int> &vdofs) const;
270 
272 
273  void BuildDofToArrays();
274 
275  const Table &GetElementToDofTable() const { return *elem_dof; }
276  const Table &GetBdrElementToDofTable() const { return *bdrElem_dof; }
277 
278  int GetElementForDof(int i) { return dof_elem_array[i]; }
279  int GetLocalDofForDof(int i) { return dof_ldof_array[i]; }
280 
282  const FiniteElement *GetFE(int i) const;
283 
285  const FiniteElement *GetBE(int i) const;
286 
287  const FiniteElement *GetFaceElement(int i) const;
288 
289  const FiniteElement *GetEdgeElement(int i) const;
290 
292  const FiniteElement *GetTraceElement(int i, int geom_type) const;
293 
296  virtual void GetEssentialVDofs(const Array<int> &bdr_attr_is_ess,
297  Array<int> &ess_vdofs) const;
298 
301  virtual void GetEssentialTrueDofs(const Array<int> &bdr_attr_is_ess,
302  Array<int> &ess_tdof_list);
303 
305  static void MarkerToList(const Array<int> &marker, Array<int> &list);
306 
310  static void ListToMarker(const Array<int> &list, int marker_size,
311  Array<int> &marker, int mark_val = -1);
312 
317  void ConvertToConformingVDofs(const Array<int> &dofs, Array<int> &cdofs);
318 
325  void ConvertFromConformingVDofs(const Array<int> &cdofs, Array<int> &dofs);
326 
330 
334 
339 
343  virtual void Update(bool want_transform = true);
344 
346  const Operator* GetUpdateOperator() { Update(); return T; }
347 
351  void SetUpdateOperatorOwner(bool own) { own_T = own; }
352 
354  virtual void UpdatesFinished() { if (own_T) { delete T; } T = NULL; }
355 
357  long GetSequence() const { return sequence; }
358 
359  void Save(std::ostream &out) const;
360 
361  virtual ~FiniteElementSpace();
362 };
363 
364 }
365 
366 #endif
Abstract class for Finite Elements.
Definition: fe.hpp:44
Ordering::Type GetOrdering() const
Return the ordering method.
Definition: fespace.hpp:173
int GetVSize() const
Definition: fespace.hpp:161
void GetVertexVDofs(int i, Array< int > &vdofs) const
Definition: fespace.cpp:156
int GetAttribute(int i) const
Definition: fespace.hpp:215
int GetNDofs() const
Returns number of degrees of freedom.
Definition: fespace.hpp:159
int ndofs
Number of degrees of freedom. Number of unknowns are ndofs*vdim.
Definition: fespace.hpp:77
int GetBdrAttribute(int i) const
Return the attribute of boundary element i.
Definition: mesh.hpp:719
const Table & GetBdrElementToDofTable() const
Definition: fespace.hpp:276
void GetElementInteriorVDofs(int i, Array< int > &vdofs) const
Definition: fespace.cpp:162
int DofToVDof(int dof, int vd, int ndofs=-1) const
Definition: fespace.cpp:103
virtual void Update(bool want_transform=true)
Definition: fespace.cpp:1421
static int Map(int ndofs, int vdim, int dof, int vd)
void GetElementVertices(int i, Array< int > &vertices) const
Returns the vertices of element i.
Definition: fespace.hpp:195
void BuildElementToDofTable() const
Definition: fespace.cpp:174
bool Conforming() const
Definition: mesh.hpp:857
SparseMatrix * RefinementMatrix(int old_ndofs, const Table *old_elem_dof)
Calculate GridFunction interpolation matrix after mesh refinement.
Definition: fespace.cpp:689
int GetNBE() const
Returns number of boundary elements.
Definition: mesh.hpp:499
SparseMatrix * DerefinementMatrix(int old_ndofs, const Table *old_elem_dof)
Calculate GridFunction restriction matrix after mesh derefinement.
Definition: fespace.cpp:815
void GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i&#39;th element.
Definition: fespace.cpp:132
Ordering::Type ordering
Definition: fespace.hpp:74
const Geometry::Type geom
virtual void GetEssentialVDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_vdofs) const
Definition: fespace.cpp:237
int VDofToDof(int vdof) const
Definition: fespace.hpp:248
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list)
Definition: fespace.cpp:274
int GetFaceOrder(int i) const
Returns the order of the i&#39;th face finite element.
Definition: fespace.cpp:61
void GetEdgeFaceDofs(int type, int index, Array< int > &dofs)
Definition: fespace.cpp:474
int vdim
Vector dimension (number of unknowns per degree of freedom).
Definition: fespace.hpp:69
int GetNumElementInteriorDofs(int i) const
Definition: fespace.hpp:237
const FiniteElement * GetTraceElement(int i, int geom_type) const
Return the trace element from element &#39;i&#39; to the given &#39;geom_type&#39;.
Definition: fespace.cpp:1387
int GetBdrAttribute(int i) const
Definition: fespace.hpp:217
int GetNE() const
Returns number of elements.
Definition: mesh.hpp:496
int GetBdrElementType(int i) const
Returns the type of boundary element i.
Definition: fespace.hpp:199
void GetElementVertices(int i, Array< int > &dofs) const
Returns the indices of the dofs of element i.
Definition: mesh.hpp:558
int GetNV() const
Returns number of nodes in the mesh.
Definition: fespace.hpp:185
const FiniteElement * GetFaceElement(int i) const
Definition: fespace.cpp:1359
void GetConformingInterpolation()
Calculate the cP and cR matrices for a nonconforming mesh.
Definition: fespace.cpp:487
const FiniteElementCollection * fec
Definition: fespace.hpp:66
NURBSExtension * GetNURBSext()
Definition: fespace.hpp:138
Array< int > dof_elem_array
Definition: fespace.hpp:85
static void MarkerToList(const Array< int > &marker, Array< int > &list)
Convert a Boolean marker array to a list containing all marked indices.
Definition: fespace.cpp:292
virtual void GetFaceDofs(int i, Array< int > &dofs) const
Definition: fespace.cpp:1209
ElementTransformation * GetBdrElementTransformation(int i)
Returns the transformation defining the i-th boundary element.
Definition: mesh.cpp:310
void ConvertFromConformingVDofs(const Array< int > &cdofs, Array< int > &dofs)
Definition: fespace.cpp:328
int GetNE() const
Returns number of elements in the mesh.
Definition: fespace.hpp:182
void GetVertexDofs(int i, Array< int > &dofs) const
Definition: fespace.cpp:1297
bool Nonconforming() const
Definition: mesh.hpp:858
const FiniteElement * GetEdgeElement(int i) const
Definition: fespace.cpp:1382
const SparseMatrix * GetConformingRestriction()
Definition: fespace.cpp:676
int GetNBE() const
Returns number of boundary elements in the mesh.
Definition: fespace.hpp:188
Data type sparse matrix.
Definition: sparsemat.hpp:38
Mesh * GetMesh() const
Returns the mesh.
Definition: fespace.hpp:136
Operator * T
Transformation to apply to GridFunctions after space Update().
Definition: fespace.hpp:99
SparseMatrix * cR
Conforming restriction matrix such that cR.cP=I.
Definition: fespace.hpp:95
SparseMatrix * D2Const_GlobalRestrictionMatrix(FiniteElementSpace *cfes)
Definition: fespace.cpp:369
SparseMatrix * D2C_GlobalRestrictionMatrix(FiniteElementSpace *cfes)
Definition: fespace.cpp:337
virtual void GetElementDofs(int i, Array< int > &dofs) const
Returns indexes of degrees of freedom in array dofs for i&#39;th element.
Definition: fespace.cpp:1014
NURBSExtension * StealNURBSext()
Definition: fespace.cpp:923
ElementTransformation * GetBdrElementTransformation(int i) const
Returns ElementTransformation for the i&#39;th boundary element.
Definition: fespace.hpp:212
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: fespace.hpp:208
Array< int > dof_ldof_array
Definition: fespace.hpp:85
int GetElementType(int i) const
Returns the type of element i.
Definition: mesh.cpp:3680
const SparseMatrix * GetConformingProlongation()
Definition: fespace.cpp:669
bool Conforming() const
Definition: fespace.hpp:141
SparseMatrix * cP
Definition: fespace.hpp:93
int GetVDim() const
Returns vector dimension.
Definition: fespace.hpp:151
virtual const SparseMatrix * GetRestrictionMatrix()
Definition: fespace.hpp:147
void GetEdgeDofs(int i, Array< int > &dofs) const
Definition: fespace.cpp:1268
int GetBdrElementType(int i) const
Returns the type of boundary element i.
Definition: mesh.cpp:3685
void GetElementInteriorDofs(int i, Array< int > &dofs) const
Definition: fespace.cpp:1309
int GetLocalDofForDof(int i)
Definition: fespace.hpp:279
static void DofsToVDofs(int ndofs, int vdim, Array< int > &dofs)
int GetElementForDof(int i)
Definition: fespace.hpp:278
ElementTransformation * GetElementTransformation(int i) const
Returns ElementTransformation for the i&#39;th element.
Definition: fespace.hpp:203
virtual ~FiniteElementSpace()
Definition: fespace.cpp:1393
SparseMatrix * H2L_GlobalRestrictionMatrix(FiniteElementSpace *lfes)
Definition: fespace.cpp:400
int GetOrder(int i) const
Returns the order of the i&#39;th finite element.
Definition: fespace.cpp:55
void MakeVDimMatrix(SparseMatrix &mat) const
Definition: fespace.cpp:642
void GetEdgeInteriorVDofs(int i, Array< int > &vdofs) const
Definition: fespace.cpp:168
int GetElementBaseGeometry(int i=0) const
Definition: mesh.hpp:551
int GetElementType(int i) const
Returns the type of element i.
Definition: fespace.hpp:191
FiniteElementSpace(Mesh *mesh, const FiniteElementCollection *fec, int vdim=1, int ordering=Ordering::byNODES)
Definition: fespace.cpp:872
bool Nonconforming() const
Definition: fespace.hpp:142
virtual void GetBdrElementDofs(int i, Array< int > &dofs) const
Returns indexes of degrees of freedom for i&#39;th boundary element.
Definition: fespace.cpp:1126
int GetNV() const
Definition: mesh.hpp:493
int GetNVDofs() const
Definition: fespace.hpp:177
void ConvertToConformingVDofs(const Array< int > &dofs, Array< int > &cdofs)
Definition: fespace.cpp:320
virtual int GetTrueVSize()
Return the number of vector true (conforming) dofs.
Definition: fespace.hpp:164
Mesh * mesh
The mesh that FE space lives on.
Definition: fespace.hpp:64
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
Definition: mesh.cpp:237
void GetEdgeInteriorDofs(int i, Array< int > &dofs) const
Definition: fespace.cpp:1321
const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement associated with i&#39;th element.
Definition: fespace.cpp:1113
const Operator * GetUpdateOperator()
Get the GridFunction update matrix.
Definition: fespace.hpp:346
void SetUpdateOperatorOwner(bool own)
Set the ownership of the update operator: if set to false, the Operator returned by GetUpdateOperator...
Definition: fespace.hpp:351
void GetFaceVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom for i&#39;th face element (2D and 3D).
Definition: fespace.cpp:144
void GetEdgeVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom for i&#39;th edge.
Definition: fespace.cpp:150
static void ListToMarker(const Array< int > &list, int marker_size, Array< int > &marker, int mark_val=-1)
Definition: fespace.cpp:309
const FiniteElementCollection * FEColl() const
Definition: fespace.hpp:175
virtual void UpdatesFinished()
Free GridFunction transformation matrix (if any), to save memory.
Definition: fespace.hpp:354
const Table & GetElementToDofTable() const
Definition: fespace.hpp:275
Defines the coarse-fine transformations of all fine elements.
Definition: ncmesh.hpp:51
const FiniteElement * GetBE(int i) const
Returns pointer to the FiniteElement for the i&#39;th boundary element.
Definition: fespace.cpp:1333
NURBSExtension * NURBSext
Definition: fespace.hpp:87
void GetBdrElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom for i&#39;th boundary element.
Definition: fespace.cpp:138
virtual int DofForGeometry(int GeomType) const =0
Abstract operator.
Definition: operator.hpp:21
long GetSequence() const
Return update counter (see Mesh::sequence)
Definition: fespace.hpp:357
Rank 3 tensor (array of matrices)
Definition: densemat.hpp:569
void Save(std::ostream &out) const
Definition: fespace.cpp:1485
int GetAttribute(int i) const
Return the attribute of element i.
Definition: mesh.hpp:716
int GetNFDofs() const
Definition: fespace.hpp:179
int GetNEDofs() const
Definition: fespace.hpp:178
static void AdjustVDofs(Array< int > &vdofs)
Definition: fespace.cpp:119
void GetLocalDerefinementMatrices(int geom, const CoarseFineTransformations &dt, DenseTensor &localR)
Definition: fespace.cpp:770
void DofsToVDofs(Array< int > &dofs, int ndofs=-1) const
Definition: fespace.cpp:67