MFEM  v3.2
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 
28 double GlobalLpNorm(const double p, double loc_norm, MPI_Comm comm);
29 
32 {
33 protected:
35 
37 
38 public:
39  ParGridFunction() { pfes = NULL; }
40 
42 
46 
50 
53  ParGridFunction(ParMesh *pmesh, GridFunction *gf, int * partitioning = NULL);
54 
55  ParGridFunction &operator=(double value)
56  { GridFunction::operator=(value); return *this; }
57 
59  { GridFunction::operator=(v); return *this; }
60 
61  ParFiniteElementSpace *ParFESpace() const { return pfes; }
62 
63  void Update();
64 
66 
67  void MakeRef(ParFiniteElementSpace *f, Vector &v, int v_offset);
68 
71  void Distribute(const Vector *tv);
72  void Distribute(const Vector &tv) { Distribute(&tv); }
73  void AddDistribute(double a, const Vector *tv);
74  void AddDistribute(double a, const Vector &tv)
75  { AddDistribute(a, &tv); }
76 
79  { Distribute(&tv); return (*this); }
80 
82  void GetTrueDofs(Vector &tv) const;
83 
85  HypreParVector *GetTrueDofs() const;
86 
88  void ParallelAverage(Vector &tv) const;
89 
91  void ParallelAverage(HypreParVector &tv) const;
92 
95 
97  void ParallelProject(Vector &tv) const;
98 
100  void ParallelProject(HypreParVector &tv) const;
101 
104 
106  void ParallelAssemble(Vector &tv) const;
107 
109  void ParallelAssemble(HypreParVector &tv) const;
110 
113 
114  void ExchangeFaceNbrData();
116  const Vector &FaceNbrData() const { return face_nbr_data; }
117 
118  // Redefine to handle the case when i is a face-neighbor element
119  virtual double GetValue(int i, const IntegrationPoint &ip,
120  int vdim = 1) const;
122  { return GetValue(T.ElementNo, T.GetIntPoint()); }
123 
125  void ProjectCoefficient(Coefficient &coeff);
126 
132 
133  double ComputeL1Error(Coefficient *exsol[],
134  const IntegrationRule *irs[] = NULL) const
135  {
137  *exsol, NULL, 1, NULL, irs), pfes->GetComm());
138  }
139 
141  const IntegrationRule *irs[] = NULL) const
142  { return ComputeLpError(1.0, exsol, NULL, irs); }
143 
145  const IntegrationRule *irs[] = NULL) const
146  { return ComputeLpError(1.0, exsol, NULL, NULL, irs); }
147 
148  double ComputeL2Error(Coefficient *exsol[],
149  const IntegrationRule *irs[] = NULL) const
150  {
151  return GlobalLpNorm(2.0, GridFunction::ComputeL2Error(exsol, irs),
152  pfes->GetComm());
153  }
154 
156  const IntegrationRule *irs[] = NULL) const
157  { return ComputeLpError(2.0, exsol, NULL, irs); }
158 
160  const IntegrationRule *irs[] = NULL,
161  Array<int> *elems = NULL) const
162  {
163  return GlobalLpNorm(2.0, GridFunction::ComputeL2Error(exsol, irs, elems),
164  pfes->GetComm());
165  }
166 
167  double ComputeMaxError(Coefficient *exsol[],
168  const IntegrationRule *irs[] = NULL) const
169  {
170  return GlobalLpNorm(std::numeric_limits<double>::infinity(),
171  GridFunction::ComputeMaxError(exsol, irs),
172  pfes->GetComm());
173  }
174 
176  const IntegrationRule *irs[] = NULL) const
177  {
178  return ComputeLpError(std::numeric_limits<double>::infinity(),
179  exsol, NULL, irs);
180  }
181 
183  const IntegrationRule *irs[] = NULL) const
184  {
185  return ComputeLpError(std::numeric_limits<double>::infinity(),
186  exsol, NULL, NULL, irs);
187  }
188 
189  double ComputeLpError(const double p, Coefficient &exsol,
190  Coefficient *weight = NULL,
191  const IntegrationRule *irs[] = NULL) const
192  {
194  p, exsol, weight, irs), pfes->GetComm());
195  }
196 
200  double ComputeLpError(const double p, VectorCoefficient &exsol,
201  Coefficient *weight = NULL,
202  VectorCoefficient *v_weight = NULL,
203  const IntegrationRule *irs[] = NULL) const
204  {
206  p, exsol, weight, v_weight, irs), pfes->GetComm());
207  }
208 
209  virtual void ComputeFlux(BilinearFormIntegrator &blfi,
210  GridFunction &flux,
211  int wcoef = 1, int subdomain = -1);
212 
216  virtual void Save(std::ostream &out) const;
217 
219  void SaveAsOne(std::ostream &out = std::cout);
220 
221  virtual ~ParGridFunction() { }
222 };
223 
224 
230 double L2ZZErrorEstimator(BilinearFormIntegrator &flux_integrator,
231  const ParGridFunction &x,
232  ParFiniteElementSpace &smooth_flux_fes,
233  ParFiniteElementSpace &flux_fes,
234  Vector &errors, int norm_p = 2, double solver_tol = 1e-12,
235  int solver_max_it = 200);
236 
237 }
238 
239 #endif // MFEM_USE_MPI
240 
241 #endif
Class for integration rule.
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:327
void AddDistribute(double a, const Vector &tv)
Definition: pgridfunc.hpp:74
double ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:148
HypreParVector * ParallelAssemble() const
Returns a new vector assembled on the true dofs.
Definition: pgridfunc.cpp:153
HypreParVector * ParallelProject() const
Returns a new vector restricted to the true dofs.
Definition: pgridfunc.cpp:136
virtual ~ParGridFunction()
Definition: pgridfunc.hpp:221
void ProjectDiscCoefficient(VectorCoefficient &coeff, Array< int > &dof_attr)
Definition: gridfunc.cpp:1293
ParFiniteElementSpace * pfes
Definition: pgridfunc.hpp:34
ParGridFunction & operator=(const HypreParVector &tv)
Short semantic for Distribute.
Definition: pgridfunc.hpp:78
ParGridFunction(ParFiniteElementSpace *pf)
Definition: pgridfunc.hpp:41
virtual double GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition: pgridfunc.cpp:211
virtual void Save(std::ostream &out) const
Definition: pgridfunc.cpp:312
void ProjectDiscCoefficient(VectorCoefficient &coeff)
Definition: pgridfunc.cpp:268
Abstract parallel finite element space.
Definition: pfespace.hpp:28
void ProjectCoefficient(Coefficient &coeff)
Definition: pgridfunc.cpp:247
const IntegrationPoint & GetIntPoint()
Definition: eltrans.hpp:37
void Distribute(const Vector &tv)
Definition: pgridfunc.hpp:72
double GetValue(ElementTransformation &T)
Definition: pgridfunc.hpp:121
double ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:208
double ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:193
ParGridFunction & operator=(double value)
Definition: pgridfunc.hpp:55
const Vector & FaceNbrData() const
Definition: pgridfunc.hpp:116
double ComputeMaxError(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:182
double ComputeLpError(const double p, VectorCoefficient &exsol, Coefficient *weight=NULL, VectorCoefficient *v_weight=NULL, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:200
double ComputeLpError(const double p, Coefficient &exsol, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:1936
double ComputeL1Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:140
double ComputeL1Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:144
ParGridFunction & operator=(const Vector &v)
Definition: pgridfunc.hpp:58
Vector & FaceNbrData()
Definition: pgridfunc.hpp:115
Wrapper for hypre&#39;s parallel vector class.
Definition: hypre.hpp:58
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:459
void MakeRef(ParFiniteElementSpace *f, Vector &v, int v_offset)
Definition: pgridfunc.cpp:78
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:167
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:542
void Distribute(const Vector *tv)
Definition: pgridfunc.cpp:85
double ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:155
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:189
HypreParVector * ParallelAverage() const
Returns a new vector averaged on the true dofs.
Definition: pgridfunc.cpp:119
double ComputeL2Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL, Array< int > *elems=NULL) const
Definition: pgridfunc.hpp:159
HypreParVector * GetTrueDofs() const
Returns the true dofs in a new HypreParVector.
Definition: pgridfunc.cpp:100
void AddDistribute(double a, const Vector *tv)
Definition: pgridfunc.cpp:90
void ProjectCoefficient(Coefficient &coeff)
Definition: gridfunc.cpp:1164
double ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad, int norm_type, Array< int > *elems=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:1830
GridFunction & operator=(double value)
Redefine &#39;=&#39; for GridFunction = constant.
Definition: gridfunc.cpp:2092
Vector data type.
Definition: vector.hpp:33
Class for parallel grid function.
Definition: pgridfunc.hpp:31
Class for parallel meshes.
Definition: pmesh.hpp:28
double ComputeL1Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:133
double ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: pgridfunc.hpp:175
virtual void ComputeFlux(BilinearFormIntegrator &blfi, GridFunction &flux, int wcoef=1, int subdomain=-1)
Definition: pgridfunc.cpp:495
ParFiniteElementSpace * ParFESpace() const
Definition: pgridfunc.hpp:61