MFEM  v3.1
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  void SaveSTLTri(std::ostream &out, double p1[], double p2[], double p3[]);
37 
39 
40  // Project the delta coefficient without scaling and return the (local)
41  // integral of the projection.
42  void ProjectDeltaCoefficient(DeltaCoefficient &delta_coeff,
43  double &integral);
44 
45  // Sum fluxes to vertices and count element contributions
47  GridFunction &flux,
48  Array<int>& counts,
49  int wcoef,
50  int subdomain);
51 
55  void ProjectDiscCoefficient(VectorCoefficient &coeff, Array<int> &dof_attr);
56 
57 public:
58 
59  GridFunction() { fes = NULL; fec = NULL; }
60 
62  GridFunction(FiniteElementSpace *f) : Vector(f->GetVSize())
63  { fes = f; fec = NULL; }
64 
65  GridFunction(Mesh *m, std::istream &input);
66 
67  GridFunction(Mesh *m, GridFunction *gf_array[], int num_pieces);
68 
71  { fec = _fec; }
72 
74 
75  int VectorDim() const;
76 
78  void GetNodalValues(int i, Array<double> &nval, int vdim = 1) const;
79 
80  virtual double GetValue(int i, const IntegrationPoint &ip,
81  int vdim = 1) const;
82 
83  void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const;
84 
85  void GetValues(int i, const IntegrationRule &ir, Vector &vals,
86  int vdim = 1) const;
87 
88  void GetValues(int i, const IntegrationRule &ir, Vector &vals,
89  DenseMatrix &tr, int vdim = 1) const;
90 
91  int GetFaceValues(int i, int side, const IntegrationRule &ir, Vector &vals,
92  DenseMatrix &tr, int vdim = 1) const;
93 
95  DenseMatrix &vals) const;
96 
97  void GetVectorValues(int i, const IntegrationRule &ir,
98  DenseMatrix &vals, DenseMatrix &tr) const;
99 
100  int GetFaceVectorValues(int i, int side, const IntegrationRule &ir,
101  DenseMatrix &vals, DenseMatrix &tr) const;
102 
103  void GetValuesFrom(GridFunction &);
104 
106 
107  void GetVectorFieldValues(int i, const IntegrationRule &ir,
108  DenseMatrix &vals,
109  DenseMatrix &tr, int comp = 0) const;
110 
112  void ReorderByNodes();
113 
115  void GetNodalValues(Vector &nval, int vdim = 1) const;
116 
117  void GetVectorFieldNodalValues(Vector &val, int comp) const;
118 
119  void ProjectVectorFieldOn(GridFunction &vec_field, int comp = 0);
120 
121  void GetDerivative(int comp, int der_comp, GridFunction &der);
122 
124 
125  void GetCurl(ElementTransformation &tr, Vector &curl);
126 
127  void GetGradient(ElementTransformation &tr, Vector &grad);
128 
129  void GetGradients(const int elem, const IntegrationRule &ir,
130  DenseMatrix &grad);
131 
133 
137  void GetElementAverages(GridFunction &avgs);
138 
143  void ImposeBounds(int i, const Vector &weights,
144  const Vector &_lo, const Vector &_hi);
145  void ImposeBounds(int i, const Vector &weights,
146  double _min = 0.0, double _max = std::numeric_limits<double>::infinity());
147 
151  void ProjectGridFunction(const GridFunction &src);
152 
153  void ProjectCoefficient(Coefficient &coeff);
154 
155  // call fes -> BuildDofToArrays() before using this projection
156  void ProjectCoefficient(Coefficient &coeff, Array<int> &dofs, int vd = 0);
157 
159 
160  // call fes -> BuildDofToArrays() before using this projection
161  void ProjectCoefficient(VectorCoefficient &vcoeff, Array<int> &dofs);
162 
163  void ProjectCoefficient(Coefficient *coeff[]);
164 
169 
171  {
172  Coefficient *coeff_p = &coeff;
173  ProjectBdrCoefficient(&coeff_p, attr);
174  }
175 
176  void ProjectBdrCoefficient(Coefficient *coeff[], Array<int> &attr);
177 
182  Array<int> &bdr_attr);
183 
188  Array<int> &bdr_attr);
189 
191  const IntegrationRule *irs[] = NULL) const
192  { return ComputeLpError(2.0, exsol, NULL, irs); }
193 
194  double ComputeL2Error(Coefficient *exsol[],
195  const IntegrationRule *irs[] = NULL) const;
196 
197  double ComputeL2Error(VectorCoefficient &exsol,
198  const IntegrationRule *irs[] = NULL,
199  Array<int> *elems = NULL) const;
200 
201  double ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad,
202  Coefficient *ell_coef, double Nu,
203  int norm_type) const;
204 
206  const IntegrationRule *irs[] = NULL) const
207  {
208  return ComputeLpError(std::numeric_limits<double>::infinity(),
209  exsol, NULL, irs);
210  }
211 
212  double ComputeMaxError(Coefficient *exsol[],
213  const IntegrationRule *irs[] = NULL) const;
214 
216  const IntegrationRule *irs[] = NULL) const
217  {
218  return ComputeLpError(std::numeric_limits<double>::infinity(),
219  exsol, NULL, NULL, irs);
220  }
221 
223  const IntegrationRule *irs[] = NULL) const
224  { return ComputeLpError(1.0, exsol, NULL, irs); }
225 
226  double ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad,
227  int norm_type, Array<int> *elems = NULL,
228  const IntegrationRule *irs[] = NULL) const;
229 
231  const IntegrationRule *irs[] = NULL) const
232  { return ComputeLpError(1.0, exsol, NULL, NULL, irs); }
233 
234  double ComputeLpError(const double p, Coefficient &exsol,
235  Coefficient *weight = NULL,
236  const IntegrationRule *irs[] = NULL) const;
237 
241  double ComputeLpError(const double p, VectorCoefficient &exsol,
242  Coefficient *weight = NULL,
243  VectorCoefficient *v_weight = NULL,
244  const IntegrationRule *irs[] = NULL) const;
245 
247  GridFunction &operator=(double value);
248 
249  GridFunction &operator=(const Vector &v);
250 
252 
255  void ConformingProlongate(const Vector &x);
256 
258  void ConformingProlongate();
259 
262  void ConformingProject(Vector &x) const;
263 
268  void ConformingProject();
269 
271 
272  void Update() { SetSize(fes->GetVSize()); }
273 
274  void Update(FiniteElementSpace *f);
275 
276  void Update(FiniteElementSpace *f, Vector &v, int v_offset);
277 
278  virtual void ComputeFlux(BilinearFormIntegrator &blfi,
279  GridFunction &flux,
280  int wcoef = 1, int subdomain = -1);
281 
283  virtual void Save(std::ostream &out) const;
284 
288  void SaveVTK(std::ostream &out, const std::string &field_name, int ref);
289 
290  void SaveSTL(std::ostream &out, int TimesToRefine = 1);
291 
293  virtual ~GridFunction();
294 };
295 
298 std::ostream &operator<<(std::ostream &out, const GridFunction &sol);
299 
300 void ZZErrorEstimator(BilinearFormIntegrator &blfi,
301  GridFunction &u,
302  GridFunction &flux,
303  Vector &error_estimates,
304  Array<int> *aniso_flags = NULL,
305  int with_subdomains = 1);
306 
308 double ComputeElementLpDistance(double p, int i,
309  GridFunction& gf1, GridFunction& gf2);
310 
313 {
314 private:
315  int n;
316  Mesh *mesh_in;
317  Coefficient &sol_in;
318 public:
320  : n(_n), mesh_in(m), sol_in(s) { }
321  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip);
322  virtual ~ExtrudeCoefficient() { }
323 };
324 
326 GridFunction *Extrude1DGridFunction(Mesh *mesh, Mesh *mesh2d,
327  GridFunction *sol, const int ny);
328 
329 }
330 
331 #endif
void SaveSTLTri(std::ostream &out, double p1[], double p2[], double p3[])
Definition: gridfunc.cpp:2228
std::ostream & operator<<(std::ostream &out, const Mesh &mesh)
Definition: mesh.cpp:9824
int GetVSize() const
Definition: fespace.hpp:164
Class for integration rule.
Definition: intrules.hpp:83
double ComputeL1Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:222
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:215
Class used for extruding scalar GridFunctions.
Definition: gridfunc.hpp:312
void ProjectDeltaCoefficient(DeltaCoefficient &delta_coeff, double &integral)
Definition: gridfunc.cpp:1077
void ConformingProlongate()
Definition: gridfunc.cpp:2105
void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Definition: gridfunc.cpp:292
void SetSize(int s)
Resizes the vector if the new size is different.
Definition: vector.hpp:259
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:2498
void MakeOwner(FiniteElementCollection *_fec)
Make the GridFunction the owner of &#39;fec&#39; and &#39;fes&#39;.
Definition: gridfunc.hpp:70
void GetVectorGradientHat(ElementTransformation &T, DenseMatrix &gh)
Definition: gridfunc.cpp:774
virtual void ComputeFlux(BilinearFormIntegrator &blfi, GridFunction &flux, int wcoef=1, int subdomain=-1)
Definition: gridfunc.cpp:209
void ProjectDiscCoefficient(VectorCoefficient &coeff, Array< int > &dof_attr)
Definition: gridfunc.cpp:1269
void GetBdrValuesFrom(GridFunction &)
Definition: gridfunc.cpp:537
void GetGradient(ElementTransformation &tr, Vector &grad)
Definition: gridfunc.cpp:876
int VectorDim() const
Definition: gridfunc.cpp:224
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:993
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:240
void GetVectorFieldNodalValues(Vector &val, int comp) const
Definition: gridfunc.cpp:643
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
Definition: gridfunc.cpp:2138
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Definition: gridfunc.cpp:2488
double ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:205
void GetDerivative(int comp, int der_comp, GridFunction &der)
Definition: gridfunc.cpp:714
void ProjectBdrCoefficientNormal(VectorCoefficient &vcoeff, Array< int > &bdr_attr)
Definition: gridfunc.cpp:1383
void SumFluxAndCount(BilinearFormIntegrator &blfi, GridFunction &flux, Array< int > &counts, int wcoef, int subdomain)
Definition: gridfunc.cpp:162
double GetDivergence(ElementTransformation &tr)
Definition: gridfunc.cpp:793
virtual ~GridFunction()
Destroys grid function.
Definition: gridfunc.cpp:128
double ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:190
void GetVectorFieldValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr, int comp=0) const
Definition: gridfunc.cpp:574
double ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad, Coefficient *ell_coef, double Nu, int norm_type) const
Definition: gridfunc.cpp:1601
void GetCurl(ElementTransformation &tr, Vector &curl)
Definition: gridfunc.cpp:825
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
Definition: gridfunc.cpp:324
FiniteElementCollection * OwnFEC()
Definition: gridfunc.hpp:73
virtual ~ExtrudeCoefficient()
Definition: gridfunc.hpp:322
FiniteElementSpace * FESpace()
Definition: gridfunc.hpp:270
double ComputeLpError(const double p, Coefficient &exsol, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:1912
void ZZErrorEstimator(BilinearFormIntegrator &blfi, GridFunction &u, GridFunction &flux, Vector &error_estimates, Array< int > *aniso_flags, int with_subdomains)
Definition: gridfunc.cpp:2350
Abstract base class BilinearFormIntegrator.
Definition: bilininteg.hpp:22
Abstract finite element space.
Definition: fespace.hpp:62
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:960
double ComputeL1Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:230
FiniteElementCollection * fec
Used when the grid function is read from a file.
Definition: gridfunc.hpp:34
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:2431
int GetFaceVectorValues(int i, int side, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
Definition: gridfunc.cpp:457
Class for integration point with weight.
Definition: intrules.hpp:25
void SaveSTL(std::ostream &out, int TimesToRefine=1)
Definition: gridfunc.cpp:2248
int GetFaceValues(int i, int side, const IntegrationRule &ir, Vector &vals, DenseMatrix &tr, int vdim=1) const
Definition: gridfunc.cpp:355
void ConformingProject()
Definition: gridfunc.cpp:2128
void GetElementAverages(GridFunction &avgs)
Definition: gridfunc.cpp:930
void ProjectBdrCoefficientTangent(VectorCoefficient &vcoeff, Array< int > &bdr_attr)
Definition: gridfunc.cpp:1454
void GetVectorValues(ElementTransformation &T, const IntegrationRule &ir, DenseMatrix &vals) const
Definition: gridfunc.cpp:405
void ProjectCoefficient(Coefficient &coeff)
Definition: gridfunc.cpp:1140
void ReorderByNodes()
For a vector grid function, makes sure that the ordering is byNODES.
Definition: gridfunc.cpp:616
double ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad, int norm_type, Array< int > *elems=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:1806
ExtrudeCoefficient(Mesh *m, Coefficient &s, int _n)
Definition: gridfunc.hpp:319
GridFunction & operator=(double value)
Redefine &#39;=&#39; for GridFunction = constant.
Definition: gridfunc.cpp:2068
Vector data type.
Definition: vector.hpp:33
void GetGradients(const int elem, const IntegrationRule &ir, DenseMatrix &grad)
Definition: gridfunc.cpp:894
GridFunction(FiniteElementSpace *f)
Creates grid function associated with *f.
Definition: gridfunc.hpp:62
void GetVectorGradient(ElementTransformation &tr, DenseMatrix &grad)
Definition: gridfunc.cpp:918
void GetValuesFrom(GridFunction &)
Definition: gridfunc.cpp:500
void SaveVTK(std::ostream &out, const std::string &field_name, int ref)
Definition: gridfunc.cpp:2152
void ProjectBdrCoefficient(Coefficient &coeff, Array< int > &attr)
Definition: gridfunc.hpp:170
virtual double GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition: gridfunc.cpp:279
void ProjectVectorFieldOn(GridFunction &vec_field, int comp=0)
Definition: gridfunc.cpp:674