MFEM  v3.3
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
pgridfunc.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_PGRIDFUNC
13 #define MFEM_PGRIDFUNC
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_MPI
18 
19 #include "pfespace.hpp"
20 #include "gridfunc.hpp"
21 #include <iostream>
22 #include <limits>
23 
24 namespace mfem
25 {
26 
27 /// Compute a global Lp norm from the local Lp norms computed by each processor
28 double GlobalLpNorm(const double p, double loc_norm, MPI_Comm comm);
29 
30 /// Class for parallel grid function
32 {
33 protected:
35 
37 
38 public:
39  ParGridFunction() { pfes = NULL; }
40 
42 
43  /// Construct a ParGridFunction using previously allocated array @a data.
44  /** The ParGridFunction does not assume ownership of @a data which is assumed
45  to be of size at least `pf->GetVSize()`. Similar to the GridFunction and
46  Vector constructors for externally allocated array, the pointer @a data
47  can be NULL. The data array can be replaced later using the method
48  SetData().
49  */
51  GridFunction(pf, data), pfes(pf) { }
52 
53  /// Construct a ParGridFunction using a GridFunction as external data.
54  /** The parallel space @a *pf and the space used by @a *gf should match. The
55  data from @a *gf is used as the local data of the ParGridFunction on each
56  processor. The ParGridFunction does not assume ownership of the data. */
58 
59  /** Creates grid function on (all) dofs from a given vector on the true dofs,
60  i.e. P tv. */
62 
63  /** Construct a ParGridFunction from the given serial GridFunction.
64  If partitioning == NULL (default), the data from 'gf' is NOT copied. */
65  ParGridFunction(ParMesh *pmesh, GridFunction *gf, int * partitioning = NULL);
66 
67  /// Assign constant values to the ParGridFunction data.
68  ParGridFunction &operator=(double value)
69  { GridFunction::operator=(value); return *this; }
70 
71  /// Copy the data from a Vector to the ParGridFunction data.
73  { GridFunction::operator=(v); return *this; }
74 
75  ParFiniteElementSpace *ParFESpace() const { return pfes; }
76 
77  void Update();
78 
80 
81  /** @brief Make the ParGridFunction reference external data on a new
82  ParFiniteElementSpace. */
83  /** This method changes the ParFiniteElementSpace associated with the
84  ParGridFunction and sets the pointer @a v as external data in the
85  ParGridFunction. */
86  void MakeRef(ParFiniteElementSpace *f, double *v);
87 
88  /** @brief Make the ParGridFunction reference external data on a new
89  ParFiniteElementSpace. */
90  /** This method changes the ParFiniteElementSpace associated with the
91  ParGridFunction and sets the data of the Vector @a v (plus the
92  @a v_offset) as external data in the ParGridFunction.
93  @note This version of the method will also perform bounds checks when
94  the build option MFEM_DEBUG is enabled. */
95  void MakeRef(ParFiniteElementSpace *f, Vector &v, int v_offset);
96 
97  /** Set the grid function on (all) dofs from a given vector on the
98  true dofs, i.e. P tv. */
99  void Distribute(const Vector *tv);
100  void Distribute(const Vector &tv) { Distribute(&tv); }
101  void AddDistribute(double a, const Vector *tv);
102  void AddDistribute(double a, const Vector &tv) { AddDistribute(a, &tv); }
103 
104  /// Set the GridFunction from the given true-dof vector.
105  virtual void SetFromTrueDofs(const Vector &tv) { Distribute(tv); }
106 
107  /// Short semantic for Distribute
109  { Distribute(&tv); return (*this); }
110 
112 
113  /// Returns the true dofs in a new HypreParVector
114  HypreParVector *GetTrueDofs() const;
115 
116  /// Returns the vector averaged on the true dofs.
117  void ParallelAverage(Vector &tv) const;
118 
119  /// Returns the vector averaged on the true dofs.
120  void ParallelAverage(HypreParVector &tv) const;
121 
122  /// Returns a new vector averaged on the true dofs.
124 
125  /// Returns the vector restricted to the true dofs.
126  void ParallelProject(Vector &tv) const;
127 
128  /// Returns the vector restricted to the true dofs.
129  void ParallelProject(HypreParVector &tv) const;
130 
131  /// Returns a new vector restricted to the true dofs.
133 
134  /// Returns the vector assembled on the true dofs.
135  void ParallelAssemble(Vector &tv) const;
136 
137  /// Returns the vector assembled on the true dofs.
138  void ParallelAssemble(HypreParVector &tv) const;
139 
140  /// Returns a new vector assembled on the true dofs.
142 
143  void ExchangeFaceNbrData();
145  const Vector &FaceNbrData() const { return face_nbr_data; }
146 
147  // Redefine to handle the case when i is a face-neighbor element
148  virtual double GetValue(int i, const IntegrationPoint &ip,
149  int vdim = 1) const;
151  { return GetValue(T.ElementNo, T.GetIntPoint()); }
152 
154  void ProjectCoefficient(Coefficient &coeff);
155 
157  /** Project a discontinuous vector coefficient as a grid function on a
158  continuous parallel finite element space. The values in shared dofs are
159  determined from the element with maximal attribute. */
161 
162  double ComputeL1Error(Coefficient *exsol[],
163  const IntegrationRule *irs[] = NULL) const
164  {
166  *exsol, NULL, 1, NULL, irs), pfes->GetComm());
167  }
168 
170  const IntegrationRule *irs[] = NULL) const
171  { return ComputeLpError(1.0, exsol, NULL, irs); }
172 
174  const IntegrationRule *irs[] = NULL) const
175  { return ComputeLpError(1.0, exsol, NULL, NULL, irs); }
176 
177  double ComputeL2Error(Coefficient *exsol[],
178  const IntegrationRule *irs[] = NULL) const
179  {
180  return GlobalLpNorm(2.0, GridFunction::ComputeL2Error(exsol, irs),
181  pfes->GetComm());
182  }
183 
185  const IntegrationRule *irs[] = NULL) const
186  { return ComputeLpError(2.0, exsol, NULL, irs); }
187 
189  const IntegrationRule *irs[] = NULL,
190  Array<int> *elems = NULL) const
191  {
192  return GlobalLpNorm(2.0, GridFunction::ComputeL2Error(exsol, irs, elems),
193  pfes->GetComm());
194  }
195 
196  double ComputeMaxError(Coefficient *exsol[],
197  const IntegrationRule *irs[] = NULL) const
198  {
199  return GlobalLpNorm(std::numeric_limits<double>::infinity(),
200  GridFunction::ComputeMaxError(exsol, irs),
201  pfes->GetComm());
202  }
203 
205  const IntegrationRule *irs[] = NULL) const
206  {
207  return ComputeLpError(std::numeric_limits<double>::infinity(),
208  exsol, NULL, irs);
209  }
210 
212  const IntegrationRule *irs[] = NULL) const
213  {
214  return ComputeLpError(std::numeric_limits<double>::infinity(),
215  exsol, NULL, NULL, irs);
216  }
217 
218  double ComputeLpError(const double p, Coefficient &exsol,
219  Coefficient *weight = NULL,
220  const IntegrationRule *irs[] = NULL) const
221  {
223  p, exsol, weight, irs), pfes->GetComm());
224  }
225 
226  /** When given a vector weight, compute the pointwise (scalar) error as the
227  dot product of the vector error with the vector weight. Otherwise, the
228  scalar error is the l_2 norm of the vector error. */
229  double ComputeLpError(const double p, VectorCoefficient &exsol,
230  Coefficient *weight = NULL,
231  VectorCoefficient *v_weight = NULL,
232  const IntegrationRule *irs[] = NULL) const
233  {
235  p, exsol, weight, v_weight, irs), pfes->GetComm());
236  }
237 
238  virtual void ComputeFlux(BilinearFormIntegrator &blfi,
239  GridFunction &flux,
240  int wcoef = 1, int subdomain = -1);
241 
242  /** Save the local portion of the ParGridFunction. It differs from the
243  serial GridFunction::Save in that it takes into account the signs of
244  the local dofs. */
245  virtual void Save(std::ostream &out) const;
246 
247  /// Merge the local grid functions
248  void SaveAsOne(std::ostream &out = std::cout);
249 
250  virtual ~ParGridFunction() { }
251 };
252 
253 
254 /** Performs a global L2 projection (through a HypreBoomerAMG solve) of flux
255  from supplied discontinuous space into supplied smooth (continuous, or at
256  least conforming) space, and computes the Lp norms of the differences
257  between them on each element. This is one approach to handling conforming
258  and non-conforming elements in parallel. Returns the total error estimate. */
259 double L2ZZErrorEstimator(BilinearFormIntegrator &flux_integrator,
260  const ParGridFunction &x,
261  ParFiniteElementSpace &smooth_flux_fes,
262  ParFiniteElementSpace &flux_fes,
263  Vector &errors, int norm_p = 2, double solver_tol = 1e-12,
264  int solver_max_it = 200);
265 
266 }
267 
268 #endif // MFEM_USE_MPI
269 
270 #endif
Class for an integration rule - an Array of IntegrationPoint.
Definition: intrules.hpp:83
void SetSpace(ParFiniteElementSpace *f)
Definition: pgridfunc.cpp:71
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:27
void SaveAsOne(std::ostream &out=std::cout)
Merge the local grid functions.
Definition: pgridfunc.cpp:329
void AddDistribute(double a, const Vector &tv)
Definition: pgridfunc.hpp:102
double ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:177
HypreParVector * ParallelAssemble() const
Returns a new vector assembled on the true dofs.
Definition: pgridfunc.cpp:155
HypreParVector * ParallelProject() const
Returns a new vector restricted to the true dofs.
Definition: pgridfunc.cpp:138
virtual ~ParGridFunction()
Definition: pgridfunc.hpp:250
void ProjectDiscCoefficient(VectorCoefficient &coeff, Array< int > &dof_attr)
Definition: gridfunc.cpp:1361
ParFiniteElementSpace * pfes
Definition: pgridfunc.hpp:34
ParGridFunction & operator=(const HypreParVector &tv)
Short semantic for Distribute.
Definition: pgridfunc.hpp:108
ParGridFunction(ParFiniteElementSpace *pf)
Definition: pgridfunc.hpp:41
virtual double GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition: pgridfunc.cpp:213
virtual void Save(std::ostream &out) const
Definition: pgridfunc.cpp:314
void ProjectDiscCoefficient(VectorCoefficient &coeff)
Definition: pgridfunc.cpp:270
Abstract parallel finite element space.
Definition: pfespace.hpp:28
void ProjectCoefficient(Coefficient &coeff)
Definition: pgridfunc.cpp:249
const IntegrationPoint & GetIntPoint()
Definition: eltrans.hpp:53
void Distribute(const Vector &tv)
Definition: pgridfunc.hpp:100
double GetValue(ElementTransformation &T)
Definition: pgridfunc.hpp:150
void MakeRef(ParFiniteElementSpace *f, double *v)
Make the ParGridFunction reference external data on a new ParFiniteElementSpace.
Definition: pgridfunc.cpp:78
double ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:232
double ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:217
ParGridFunction & operator=(double value)
Assign constant values to the ParGridFunction data.
Definition: pgridfunc.hpp:68
virtual void SetFromTrueDofs(const Vector &tv)
Set the GridFunction from the given true-dof vector.
Definition: pgridfunc.hpp:105
const Vector & FaceNbrData() const
Definition: pgridfunc.hpp:145
void GetTrueDofs(Vector &tv) const
Extract the true-dofs from the GridFunction. If all dofs are true, then tv will be set to point to th...
Definition: gridfunc.cpp:280
double ComputeMaxError(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:211
double ComputeLpError(const double p, VectorCoefficient &exsol, Coefficient *weight=NULL, VectorCoefficient *v_weight=NULL, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:229
double ComputeLpError(const double p, Coefficient &exsol, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:2004
double ComputeL1Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:169
double ComputeL1Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:173
ParGridFunction & operator=(const Vector &v)
Copy the data from a Vector to the ParGridFunction data.
Definition: pgridfunc.hpp:72
Vector & FaceNbrData()
Definition: pgridfunc.hpp:144
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:72
double GlobalLpNorm(const double p, double loc_norm, MPI_Comm comm)
Compute a global Lp norm from the local Lp norms computed by each processor.
Definition: pgridfunc.cpp:461
Abstract base class BilinearFormIntegrator.
Definition: bilininteg.hpp:22
Base class Coefficient that may optionally depend on time.
Definition: coefficient.hpp:31
double ComputeMaxError(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:196
double L2ZZErrorEstimator(BilinearFormIntegrator &flux_integrator, const ParGridFunction &x, ParFiniteElementSpace &smooth_flux_fes, ParFiniteElementSpace &flux_fes, Vector &errors, int norm_p, double solver_tol, int solver_max_it)
Definition: pgridfunc.cpp:544
void Distribute(const Vector *tv)
Definition: pgridfunc.cpp:92
double ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:184
Class for integration point with weight.
Definition: intrules.hpp:25
double ComputeLpError(const double p, Coefficient &exsol, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:218
HypreParVector * ParallelAverage() const
Returns a new vector averaged on the true dofs.
Definition: pgridfunc.cpp:121
double ComputeL2Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL, Array< int > *elems=NULL) const
Definition: pgridfunc.hpp:188
HypreParVector * GetTrueDofs() const
Returns the true dofs in a new HypreParVector.
Definition: pgridfunc.cpp:102
void AddDistribute(double a, const Vector *tv)
Definition: pgridfunc.cpp:97
void ProjectCoefficient(Coefficient &coeff)
Definition: gridfunc.cpp:1232
double ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad, int norm_type, Array< int > *elems=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:1898
GridFunction & operator=(double value)
Redefine &#39;=&#39; for GridFunction = constant.
Definition: gridfunc.cpp:2160
Vector data type.
Definition: vector.hpp:36
Class for parallel grid function.
Definition: pgridfunc.hpp:31
double * data
Definition: vector.hpp:41
Class for parallel meshes.
Definition: pmesh.hpp:28
double ComputeL1Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:162
ParGridFunction(ParFiniteElementSpace *pf, double *data)
Construct a ParGridFunction using previously allocated array data.
Definition: pgridfunc.hpp:50
double ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:204
virtual void ComputeFlux(BilinearFormIntegrator &blfi, GridFunction &flux, int wcoef=1, int subdomain=-1)
Definition: pgridfunc.cpp:497
ParFiniteElementSpace * ParFESpace() const
Definition: pgridfunc.hpp:75