MFEM  v3.2
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
gridfunc.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_GRIDFUNC
13 #define MFEM_GRIDFUNC
14 
15 #include "../config/config.hpp"
16 #include "fespace.hpp"
17 #include "coefficient.hpp"
18 #include "bilininteg.hpp"
19 #include <limits>
20 #include <ostream>
21 #include <string>
22 
23 namespace mfem
24 {
25 
27 class GridFunction : public Vector
28 {
29 protected:
32 
35 
36  long sequence; // see FiniteElementSpace::sequence, Mesh::sequence
37 
38  void SaveSTLTri(std::ostream &out, double p1[], double p2[], double p3[]);
39 
41 
42  // Project the delta coefficient without scaling and return the (local)
43  // integral of the projection.
44  void ProjectDeltaCoefficient(DeltaCoefficient &delta_coeff,
45  double &integral);
46 
47  // Sum fluxes to vertices and count element contributions
49  GridFunction &flux,
50  Array<int>& counts,
51  int wcoef,
52  int subdomain);
53 
57  void ProjectDiscCoefficient(VectorCoefficient &coeff, Array<int> &dof_attr);
58 
59  void Destroy();
60 
61 public:
62 
63  GridFunction() { fes = NULL; fec = NULL; sequence = 0; }
64 
66  GridFunction(FiniteElementSpace *f) : Vector(f->GetVSize())
67  { fes = f; fec = NULL; sequence = f->GetSequence(); }
68 
69  GridFunction(Mesh *m, std::istream &input);
70 
71  GridFunction(Mesh *m, GridFunction *gf_array[], int num_pieces);
72 
74  void MakeOwner(FiniteElementCollection *_fec) { fec = _fec; }
75 
77 
78  int VectorDim() const;
79 
81  void GetNodalValues(int i, Array<double> &nval, int vdim = 1) const;
82 
83  virtual double GetValue(int i, const IntegrationPoint &ip,
84  int vdim = 1) const;
85 
86  void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const;
87 
88  void GetValues(int i, const IntegrationRule &ir, Vector &vals,
89  int vdim = 1) const;
90 
91  void GetValues(int i, const IntegrationRule &ir, Vector &vals,
92  DenseMatrix &tr, int vdim = 1) const;
93 
94  int GetFaceValues(int i, int side, const IntegrationRule &ir, Vector &vals,
95  DenseMatrix &tr, int vdim = 1) const;
96 
98  DenseMatrix &vals) const;
99 
100  void GetVectorValues(int i, const IntegrationRule &ir,
101  DenseMatrix &vals, DenseMatrix &tr) const;
102 
103  int GetFaceVectorValues(int i, int side, const IntegrationRule &ir,
104  DenseMatrix &vals, DenseMatrix &tr) const;
105 
106  void GetValuesFrom(GridFunction &);
107 
109 
110  void GetVectorFieldValues(int i, const IntegrationRule &ir,
111  DenseMatrix &vals,
112  DenseMatrix &tr, int comp = 0) const;
113 
115  void ReorderByNodes();
116 
118  void GetNodalValues(Vector &nval, int vdim = 1) const;
119 
120  void GetVectorFieldNodalValues(Vector &val, int comp) const;
121 
122  void ProjectVectorFieldOn(GridFunction &vec_field, int comp = 0);
123 
124  void GetDerivative(int comp, int der_comp, GridFunction &der);
125 
127 
128  void GetCurl(ElementTransformation &tr, Vector &curl);
129 
130  void GetGradient(ElementTransformation &tr, Vector &grad);
131 
132  void GetGradients(const int elem, const IntegrationRule &ir,
133  DenseMatrix &grad);
134 
136 
140  void GetElementAverages(GridFunction &avgs);
141 
146  void ImposeBounds(int i, const Vector &weights,
147  const Vector &_lo, const Vector &_hi);
148  void ImposeBounds(int i, const Vector &weights,
149  double _min = 0.0, double _max = std::numeric_limits<double>::infinity());
150 
154  void ProjectGridFunction(const GridFunction &src);
155 
156  void ProjectCoefficient(Coefficient &coeff);
157 
158  // call fes -> BuildDofToArrays() before using this projection
159  void ProjectCoefficient(Coefficient &coeff, Array<int> &dofs, int vd = 0);
160 
162 
163  // call fes -> BuildDofToArrays() before using this projection
164  void ProjectCoefficient(VectorCoefficient &vcoeff, Array<int> &dofs);
165 
166  void ProjectCoefficient(Coefficient *coeff[]);
167 
172 
174  {
175  Coefficient *coeff_p = &coeff;
176  ProjectBdrCoefficient(&coeff_p, attr);
177  }
178 
179  void ProjectBdrCoefficient(Coefficient *coeff[], Array<int> &attr);
180 
185  Array<int> &bdr_attr);
186 
191  Array<int> &bdr_attr);
192 
194  const IntegrationRule *irs[] = NULL) const
195  { return ComputeLpError(2.0, exsol, NULL, irs); }
196 
197  double ComputeL2Error(Coefficient *exsol[],
198  const IntegrationRule *irs[] = NULL) const;
199 
200  double ComputeL2Error(VectorCoefficient &exsol,
201  const IntegrationRule *irs[] = NULL,
202  Array<int> *elems = NULL) const;
203 
204  double ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad,
205  Coefficient *ell_coef, double Nu,
206  int norm_type) const;
207 
209  const IntegrationRule *irs[] = NULL) const
210  {
211  return ComputeLpError(std::numeric_limits<double>::infinity(),
212  exsol, NULL, irs);
213  }
214 
215  double ComputeMaxError(Coefficient *exsol[],
216  const IntegrationRule *irs[] = NULL) const;
217 
219  const IntegrationRule *irs[] = NULL) const
220  {
221  return ComputeLpError(std::numeric_limits<double>::infinity(),
222  exsol, NULL, NULL, irs);
223  }
224 
226  const IntegrationRule *irs[] = NULL) const
227  { return ComputeLpError(1.0, exsol, NULL, irs); }
228 
229  double ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad,
230  int norm_type, Array<int> *elems = NULL,
231  const IntegrationRule *irs[] = NULL) const;
232 
234  const IntegrationRule *irs[] = NULL) const
235  { return ComputeLpError(1.0, exsol, NULL, NULL, irs); }
236 
237  double ComputeLpError(const double p, Coefficient &exsol,
238  Coefficient *weight = NULL,
239  const IntegrationRule *irs[] = NULL) const;
240 
244  double ComputeLpError(const double p, VectorCoefficient &exsol,
245  Coefficient *weight = NULL,
246  VectorCoefficient *v_weight = NULL,
247  const IntegrationRule *irs[] = NULL) const;
248 
249  virtual void ComputeFlux(BilinearFormIntegrator &blfi,
250  GridFunction &flux,
251  int wcoef = 1, int subdomain = -1);
252 
254  GridFunction &operator=(double value);
255 
256  GridFunction &operator=(const Vector &v);
257 
259 
261  void Update();
262 
264  const FiniteElementSpace *FESpace() const { return fes; }
265 
266  void SetSpace(FiniteElementSpace *f);
267 
268  void MakeRef(FiniteElementSpace *f, Vector &v, int v_offset);
269 
271  virtual void Save(std::ostream &out) const;
272 
276  void SaveVTK(std::ostream &out, const std::string &field_name, int ref);
277 
278  void SaveSTL(std::ostream &out, int TimesToRefine = 1);
279 
281  virtual ~GridFunction() { Destroy(); }
282 };
283 
284 
287 std::ostream &operator<<(std::ostream &out, const GridFunction &sol);
288 
289 
290 double ZZErrorEstimator(BilinearFormIntegrator &blfi,
291  GridFunction &u,
292  GridFunction &flux,
293  Vector &error_estimates,
294  Array<int> *aniso_flags = NULL,
295  int with_subdomains = 1);
296 
298 double ComputeElementLpDistance(double p, int i,
299  GridFunction& gf1, GridFunction& gf2);
300 
301 
304 {
305 private:
306  int n;
307  Mesh *mesh_in;
308  Coefficient &sol_in;
309 public:
311  : n(_n), mesh_in(m), sol_in(s) { }
312  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip);
313  virtual ~ExtrudeCoefficient() { }
314 };
315 
317 GridFunction *Extrude1DGridFunction(Mesh *mesh, Mesh *mesh2d,
318  GridFunction *sol, const int ny);
319 
320 }
321 
322 #endif
void SaveSTLTri(std::ostream &out, double p1[], double p2[], double p3[])
Definition: gridfunc.cpp:2208
virtual ~GridFunction()
Destroys grid function.
Definition: gridfunc.hpp:281
std::ostream & operator<<(std::ostream &out, const Mesh &mesh)
Definition: mesh.cpp:8230
Class for integration rule.
Definition: intrules.hpp:83
double ComputeL1Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:225
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:27
double ComputeMaxError(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:218
Class used for extruding scalar GridFunctions.
Definition: gridfunc.hpp:303
void MakeRef(FiniteElementSpace *f, Vector &v, int v_offset)
Definition: gridfunc.cpp:176
void ProjectDeltaCoefficient(DeltaCoefficient &delta_coeff, double &integral)
Definition: gridfunc.cpp:1101
double ZZErrorEstimator(BilinearFormIntegrator &blfi, GridFunction &u, GridFunction &flux, Vector &error_estimates, Array< int > *aniso_flags, int with_subdomains)
Definition: gridfunc.cpp:2330
void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Definition: gridfunc.cpp:316
GridFunction * Extrude1DGridFunction(Mesh *mesh, Mesh *mesh2d, GridFunction *sol, const int ny)
Extrude a scalar 1D GridFunction, after extruding the mesh with Extrude1D.
Definition: gridfunc.cpp:2484
void MakeOwner(FiniteElementCollection *_fec)
Make the GridFunction the owner of &#39;fec&#39; and &#39;fes&#39;.
Definition: gridfunc.hpp:74
void GetVectorGradientHat(ElementTransformation &T, DenseMatrix &gh)
Definition: gridfunc.cpp:798
virtual void ComputeFlux(BilinearFormIntegrator &blfi, GridFunction &flux, int wcoef=1, int subdomain=-1)
Definition: gridfunc.cpp:233
void ProjectDiscCoefficient(VectorCoefficient &coeff, Array< int > &dof_attr)
Definition: gridfunc.cpp:1293
void GetBdrValuesFrom(GridFunction &)
Definition: gridfunc.cpp:561
void GetGradient(ElementTransformation &tr, Vector &grad)
Definition: gridfunc.cpp:900
int VectorDim() const
Definition: gridfunc.cpp:248
Data type dense matrix using column-major storage.
Definition: densemat.hpp:22
Delta function coefficient.
void ImposeBounds(int i, const Vector &weights, const Vector &_lo, const Vector &_hi)
Definition: gridfunc.cpp:1017
void GetNodalValues(int i, Array< double > &nval, int vdim=1) const
Returns the values in the vertices of i&#39;th element for dimension vdim.
Definition: gridfunc.cpp:264
void GetVectorFieldNodalValues(Vector &val, int comp) const
Definition: gridfunc.cpp:667
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
Definition: gridfunc.cpp:2116
const FiniteElementSpace * FESpace() const
Definition: gridfunc.hpp:264
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Definition: gridfunc.cpp:2474
double ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:208
void GetDerivative(int comp, int der_comp, GridFunction &der)
Definition: gridfunc.cpp:738
void ProjectBdrCoefficientNormal(VectorCoefficient &vcoeff, Array< int > &bdr_attr)
Definition: gridfunc.cpp:1407
void SumFluxAndCount(BilinearFormIntegrator &blfi, GridFunction &flux, Array< int > &counts, int wcoef, int subdomain)
Definition: gridfunc.cpp:186
double GetDivergence(ElementTransformation &tr)
Definition: gridfunc.cpp:817
double ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:193
void GetVectorFieldValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr, int comp=0) const
Definition: gridfunc.cpp:598
double ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad, Coefficient *ell_coef, double Nu, int norm_type) const
Definition: gridfunc.cpp:1625
void GetCurl(ElementTransformation &tr, Vector &curl)
Definition: gridfunc.cpp:849
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
Definition: gridfunc.cpp:348
FiniteElementCollection * OwnFEC()
Definition: gridfunc.hpp:76
virtual ~ExtrudeCoefficient()
Definition: gridfunc.hpp:313
FiniteElementSpace * FESpace()
Definition: gridfunc.hpp:263
double ComputeLpError(const double p, Coefficient &exsol, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:1936
Abstract base class BilinearFormIntegrator.
Definition: bilininteg.hpp:22
Base class Coefficient that may optionally depend on time.
Definition: coefficient.hpp:31
FiniteElementSpace * fes
FE space on which grid function lives.
Definition: gridfunc.hpp:31
void ProjectGridFunction(const GridFunction &src)
Definition: gridfunc.cpp:984
double ComputeL1Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:233
FiniteElementCollection * fec
Used when the grid function is read from a file.
Definition: gridfunc.hpp:34
void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
Definition: gridfunc.cpp:141
double ComputeElementLpDistance(double p, int i, GridFunction &gf1, GridFunction &gf2)
Compute the Lp distance between two grid functions on the given element.
Definition: gridfunc.cpp:2417
int GetFaceVectorValues(int i, int side, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
Definition: gridfunc.cpp:481
Class for integration point with weight.
Definition: intrules.hpp:25
void SaveSTL(std::ostream &out, int TimesToRefine=1)
Definition: gridfunc.cpp:2228
int GetFaceValues(int i, int side, const IntegrationRule &ir, Vector &vals, DenseMatrix &tr, int vdim=1) const
Definition: gridfunc.cpp:379
void GetElementAverages(GridFunction &avgs)
Definition: gridfunc.cpp:954
void ProjectBdrCoefficientTangent(VectorCoefficient &vcoeff, Array< int > &bdr_attr)
Definition: gridfunc.cpp:1478
void GetVectorValues(ElementTransformation &T, const IntegrationRule &ir, DenseMatrix &vals) const
Definition: gridfunc.cpp:429
void ProjectCoefficient(Coefficient &coeff)
Definition: gridfunc.cpp:1164
void SetSpace(FiniteElementSpace *f)
Definition: gridfunc.cpp:168
void ReorderByNodes()
For a vector grid function, makes sure that the ordering is byNODES.
Definition: gridfunc.cpp:640
double ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad, int norm_type, Array< int > *elems=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:1830
ExtrudeCoefficient(Mesh *m, Coefficient &s, int _n)
Definition: gridfunc.hpp:310
GridFunction & operator=(double value)
Redefine &#39;=&#39; for GridFunction = constant.
Definition: gridfunc.cpp:2092
Vector data type.
Definition: vector.hpp:33
void GetGradients(const int elem, const IntegrationRule &ir, DenseMatrix &grad)
Definition: gridfunc.cpp:918
GridFunction(FiniteElementSpace *f)
Creates grid function associated with *f.
Definition: gridfunc.hpp:66
long GetSequence() const
Return update counter (see Mesh::sequence)
Definition: fespace.hpp:357
void GetVectorGradient(ElementTransformation &tr, DenseMatrix &grad)
Definition: gridfunc.cpp:942
void GetValuesFrom(GridFunction &)
Definition: gridfunc.cpp:524
void SaveVTK(std::ostream &out, const std::string &field_name, int ref)
Definition: gridfunc.cpp:2131
void ProjectBdrCoefficient(Coefficient &coeff, Array< int > &attr)
Definition: gridfunc.hpp:173
virtual double GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition: gridfunc.cpp:303
void ProjectVectorFieldOn(GridFunction &vec_field, int comp=0)
Definition: gridfunc.cpp:698