MFEM  v3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
pfespace.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_PFESPACE
13 #define MFEM_PFESPACE
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_MPI
18 
19 #include "../linalg/hypre.hpp"
20 #include "../mesh/pmesh.hpp"
21 #include "../mesh/nurbs.hpp"
22 #include "fespace.hpp"
23 
24 namespace mfem
25 {
26 
29 {
30 private:
32  MPI_Comm MyComm;
33  int NRanks, MyRank;
34 
36  ParMesh *pmesh;
37 
39  GroupCommunicator *gcomm;
40 
42  int ltdof_size;
43 
45  Array<int> ldof_group;
46 
48  Array<int> ldof_ltdof;
49 
51  Array<HYPRE_Int> dof_offsets;
52 
54  Array<HYPRE_Int> tdof_offsets;
55 
57  Array<HYPRE_Int> tdof_nb_offsets;
58 
60  Array<HYPRE_Int> old_dof_offsets;
61 
63  Array<int> ldof_sign;
64 
66  HypreParMatrix *P;
67 
69  SparseMatrix *R;
70 
71  ParNURBSExtension *pNURBSext()
72  { return dynamic_cast<ParNURBSExtension *>(NURBSext); }
73 
74  GroupTopology &GetGroupTopo()
75  { return (NURBSext) ? pNURBSext()->gtopo : pmesh->gtopo; }
76 
77  void Construct();
78  void Destroy();
79 
80  // ldof_type = 0 : DOFs communicator, otherwise VDOFs communicator
81  void GetGroupComm(GroupCommunicator &gcomm, int ldof_type,
82  Array<int> *ldof_sign = NULL);
83 
85  void GenerateGlobalOffsets();
86 
88  void ConstructTrueDofs();
89  void ConstructTrueNURBSDofs();
90 
91  void ApplyLDofSigns(Array<int> &dofs) const;
92 
94  struct Dependency
95  {
96  int rank, dof;
97  double coef;
98  Dependency(int r, int d, double c) : rank(r), dof(d), coef(c) {}
99  };
100 
102  struct DepList
103  {
104  Array<Dependency> list;
105  int type;
106 
107  DepList() : type(0) {}
108 
109  bool IsTrueDof(int my_rank) const
110  { return type == 0 || (type == 1 && list[0].rank == my_rank); }
111  };
112 
113  void AddSlaveDependencies(DepList deps[], int master_rank,
114  const Array<int> &master_dofs, int master_ndofs,
115  const Array<int> &slave_dofs, DenseMatrix& I);
116 
117  void Add1To1Dependencies(DepList deps[], int owner_rank,
118  const Array<int> &owner_dofs, int owner_ndofs,
119  const Array<int> &dependent_dofs);
120 
121  void GetDofs(int type, int index, Array<int>& dofs);
122  void ReorderFaceDofs(Array<int> &dofs, int orient);
123 
124  // Used when the ParMesh is non-conforming, i.e. pmesh->pncmesh != NULL.
125  // Constructs the matrices P and R. Determines ltdof_size. Calls
126  // GenerateGlobalOffsets(). Constructs ldof_ltdof.
127  void GetParallelConformingInterpolation();
128 
132  HypreParMatrix* RebalanceMatrix(int old_ndofs,
133  const Table* old_elem_dof);
134 
139  HypreParMatrix* ParallelDerefinementMatrix(int old_ndofs,
140  const Table *old_elem_dof);
141 
142 public:
143  // Face-neighbor data
144  // Number of face-neighbor dofs
146  // Face-neighbor-element to face-neighbor dof
148  // Face-neighbor to ldof in the face-neighbor numbering
150  // The global ldof indices of the face-neighbor dofs
152  // Local face-neighbor data: face-neighbor to ldof
154 
156  int dim = 1, int ordering = Ordering::byNODES);
157 
158  MPI_Comm GetComm() { return MyComm; }
159  int GetNRanks() { return NRanks; }
160  int GetMyRank() { return MyRank; }
161 
162  inline ParMesh *GetParMesh() { return pmesh; }
163 
164  int GetDofSign(int i)
165  { return NURBSext || Nonconforming() ? 1 : ldof_sign[VDofToDof(i)]; }
166  HYPRE_Int *GetDofOffsets() { return dof_offsets; }
167  HYPRE_Int *GetTrueDofOffsets() { return tdof_offsets; }
168  HYPRE_Int GlobalVSize()
169  { return Dof_TrueDof_Matrix()->GetGlobalNumRows(); }
170  HYPRE_Int GlobalTrueVSize()
171  { return Dof_TrueDof_Matrix()->GetGlobalNumCols(); }
172 
174  virtual int GetTrueVSize() { return ltdof_size; }
175 
177  virtual void GetElementDofs(int i, Array<int> &dofs) const;
178 
180  virtual void GetBdrElementDofs(int i, Array<int> &dofs) const;
181 
184  virtual void GetFaceDofs(int i, Array<int> &dofs) const;
185 
188 
193 
197  { return (new HypreParVector(MyComm,GlobalTrueVSize(),GetTrueDofOffsets()));}
198 
200  void DivideByGroupSize(double *vec);
201 
203  GroupCommunicator &GroupComm() { return *gcomm; }
204 
207 
210  void Synchronize(Array<int> &ldof_marker) const;
211 
213  virtual void GetEssentialVDofs(const Array<int> &bdr_attr_is_ess,
214  Array<int> &ess_dofs) const;
215 
218  virtual void GetEssentialTrueDofs(const Array<int> &bdr_attr_is_ess,
219  Array<int> &ess_tdof_list);
220 
223  int GetLocalTDofNumber(int ldof);
225  HYPRE_Int GetGlobalTDofNumber(int ldof);
229  HYPRE_Int GetGlobalScalarTDofNumber(int sldof);
230 
231  HYPRE_Int GetMyDofOffset() const;
232  HYPRE_Int GetMyTDofOffset() const;
233 
236  { if (!R) { Dof_TrueDof_Matrix(); } return R; }
237 
238  // Face-neighbor functions
239  void ExchangeFaceNbrData();
240  int GetFaceNbrVSize() const { return num_face_nbr_dofs; }
241  void GetFaceNbrElementVDofs(int i, Array<int> &vdofs) const;
242  void GetFaceNbrFaceVDofs(int i, Array<int> &vdofs) const;
243  const FiniteElement *GetFaceNbrFE(int i) const;
244  const FiniteElement *GetFaceNbrFaceFE(int i) const;
245  const HYPRE_Int *GetFaceNbrGlobalDofMap() { return face_nbr_glob_dof_map; }
246 
248  void LoseDofOffsets() { dof_offsets.LoseData(); }
249  void LoseTrueDofOffsets() { tdof_offsets.LoseData(); }
250 
251  bool Conforming() const { return pmesh->pncmesh == NULL; }
252  bool Nonconforming() const { return pmesh->pncmesh != NULL; }
253 
256  virtual void Update(bool want_transform = true);
257 
259  virtual void UpdatesFinished()
260  {
262  old_dof_offsets.DeleteAll();
263  }
264 
265  virtual ~ParFiniteElementSpace() { Destroy(); }
266 
267  // Obsolete, kept for backward compatibility
268  int TrueVSize() { return ltdof_size; }
269 };
270 
271 }
272 
273 #endif // MFEM_USE_MPI
274 
275 #endif
Abstract class for Finite Elements.
Definition: fe.hpp:44
virtual int GetTrueVSize()
Return the number of local vector true dofs.
Definition: pfespace.hpp:174
HypreParVector * NewTrueDofVector()
Definition: pfespace.hpp:196
Ordering::Type ordering
Definition: fespace.hpp:74
virtual void Update(bool want_transform=true)
Definition: pfespace.cpp:2155
int VDofToDof(int vdof) const
Definition: fespace.hpp:248
HYPRE_Int * GetDofOffsets()
Definition: pfespace.hpp:166
Data type dense matrix using column-major storage.
Definition: densemat.hpp:22
void DivideByGroupSize(double *vec)
Scale a vector of true dofs.
Definition: pfespace.cpp:413
Abstract parallel finite element space.
Definition: pfespace.hpp:28
void Synchronize(Array< int > &ldof_marker) const
Definition: pfespace.cpp:449
virtual const SparseMatrix * GetRestrictionMatrix()
Get the R matrix which restricts a local dof vector to true dof vector.
Definition: pfespace.hpp:235
HypreParMatrix * GetPartialConformingInterpolation()
For a non-conforming mesh, construct and return the interpolation matrix from the partially conformin...
Definition: pfespace.cpp:1503
const HYPRE_Int * GetFaceNbrGlobalDofMap()
Definition: pfespace.hpp:245
HYPRE_Int GetMyDofOffset() const
Definition: pfespace.cpp:571
void DeleteAll()
Delete whole array.
Definition: array.hpp:463
ParNCMesh * pncmesh
Definition: pmesh.hpp:113
HYPRE_Int * GetTrueDofOffsets()
Definition: pfespace.hpp:167
virtual void GetBdrElementDofs(int i, Array< int > &dofs) const
Returns indexes of degrees of freedom for i&#39;th boundary element.
Definition: pfespace.cpp:274
void GetFaceNbrElementVDofs(int i, Array< int > &vdofs) const
Definition: pfespace.cpp:801
HYPRE_Int GetGlobalNumRows() const
Definition: hypre.hpp:340
const FiniteElement * GetFaceNbrFE(int i) const
Definition: pfespace.cpp:835
int dim
Definition: ex3.cpp:47
HYPRE_Int GetGlobalNumCols() const
Definition: hypre.hpp:343
Data type sparse matrix.
Definition: sparsemat.hpp:38
void LoseData()
NULL-ifies the data.
Definition: array.hpp:103
HYPRE_Int GetMyTDofOffset() const
Definition: pfespace.cpp:576
int GetLocalTDofNumber(int ldof)
Definition: pfespace.cpp:489
virtual void GetFaceDofs(int i, Array< int > &dofs) const
Definition: pfespace.cpp:288
HypreParMatrix * Dof_TrueDof_Matrix()
The true dof-to-dof interpolation matrix.
Definition: pfespace.cpp:345
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:58
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list)
Definition: pfespace.cpp:479
GroupCommunicator & GroupComm()
Return a reference to the internal GroupCommunicator (on VDofs)
Definition: pfespace.hpp:203
HYPRE_Int GetGlobalScalarTDofNumber(int sldof)
Definition: pfespace.cpp:534
bool Nonconforming() const
Definition: pfespace.hpp:252
virtual void GetElementDofs(int i, Array< int > &dofs) const
Returns indexes of degrees of freedom in array dofs for i&#39;th element.
Definition: pfespace.cpp:260
const FiniteElement * GetFaceNbrFaceFE(int i) const
Definition: pfespace.cpp:849
int GetFaceNbrVSize() const
Definition: pfespace.hpp:240
void GetFaceNbrFaceVDofs(int i, Array< int > &vdofs) const
Definition: pfespace.cpp:807
virtual void UpdatesFinished()
Free GridFunction transformation matrix (if any), to save memory.
Definition: fespace.hpp:354
virtual void GetEssentialVDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_dofs) const
Determine the boundary degrees of freedom.
Definition: pfespace.cpp:466
NURBSExtension * NURBSext
Definition: fespace.hpp:87
GroupTopology gtopo
Definition: pmesh.hpp:100
Wrapper for hypre&#39;s ParCSR matrix class.
Definition: hypre.hpp:150
virtual void UpdatesFinished()
Free ParGridFunction transformation matrix (if any), to save memory.
Definition: pfespace.hpp:259
GroupCommunicator * ScalarGroupComm()
Return a new GroupCommunicator on Dofs.
Definition: pfespace.cpp:429
Class for parallel meshes.
Definition: pmesh.hpp:28
GroupTopology gtopo
Definition: nurbs.hpp:348
ParFiniteElementSpace(ParMesh *pm, const FiniteElementCollection *f, int dim=1, int ordering=Ordering::byNODES)
Definition: pfespace.cpp:26
HYPRE_Int GetGlobalTDofNumber(int ldof)
Returns the global tdof number of the given local degree of freedom.
Definition: pfespace.cpp:511
Array< HYPRE_Int > face_nbr_glob_dof_map
Definition: pfespace.hpp:151