MFEM  v3.0
 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.googlecode.com.
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 <limits>
19 #include <ostream>
20 #include <string>
21 
22 namespace mfem
23 {
24 
26 class GridFunction : public Vector
27 {
28 protected:
31 
34 
35  void SaveSTLTri(std::ostream &out, double p1[], double p2[], double p3[]);
36 
38 
39  // Project the delta coefficient without scaling and return the (local)
40  // integral of the projection.
41  void ProjectDeltaCoefficient(DeltaCoefficient &delta_coeff,
42  double &integral);
43 
44 public:
45 
46  GridFunction() { fes = NULL; fec = NULL; }
47 
49  GridFunction(FiniteElementSpace *f) : Vector(f->GetVSize())
50  { fes = f; fec = NULL; }
51 
52  GridFunction(Mesh *m, std::istream &input);
53 
54  GridFunction(Mesh *m, GridFunction *gf_array[], int num_pieces);
55 
58  { fec = _fec; }
59 
61 
62  int VectorDim() const;
63 
65  void GetNodalValues(int i, Array<double> &nval, int vdim = 1) const;
66 
67  virtual double GetValue(int i, const IntegrationPoint &ip,
68  int vdim = 1) const;
69 
70  void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const;
71 
72  void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim = 1) const;
73 
74  void GetValues(int i, const IntegrationRule &ir, Vector &vals,
75  DenseMatrix &tr, int vdim = 1) const;
76 
77  int GetFaceValues(int i, int side, const IntegrationRule &ir, Vector &vals,
78  DenseMatrix &tr, int vdim = 1) const;
79 
81  DenseMatrix &vals) const;
82 
83  void GetVectorValues(int i, const IntegrationRule &ir,
84  DenseMatrix &vals, DenseMatrix &tr) const;
85 
86  int GetFaceVectorValues(int i, int side, const IntegrationRule &ir,
87  DenseMatrix &vals, DenseMatrix &tr) const;
88 
90 
92 
93  void GetVectorFieldValues(int i, const IntegrationRule &ir,
94  DenseMatrix &vals,
95  DenseMatrix &tr, int comp = 0) const;
96 
98  void ReorderByNodes();
99 
101  void GetNodalValues(Vector &nval, int vdim = 1) const;
102 
103  void GetVectorFieldNodalValues(Vector &val, int comp) const;
104 
105  void ProjectVectorFieldOn(GridFunction &vec_field, int comp = 0);
106 
107  void GetDerivative(int comp, int der_comp, GridFunction &der);
108 
110 
111  void GetGradient(ElementTransformation &tr, Vector &grad);
112 
113  void GetGradients(const int elem, const IntegrationRule &ir,
114  DenseMatrix &grad);
115 
117 
121  void GetElementAverages(GridFunction &avgs);
122 
127  void ImposeBounds(int i, const Vector &weights,
128  const Vector &_lo, const Vector &_hi);
129  void ImposeBounds(int i, const Vector &weights,
130  double _min = 0.0, double _max = std::numeric_limits<double>::infinity());
131 
135  void ProjectGridFunction(const GridFunction &src);
136 
137  void ProjectCoefficient(Coefficient &coeff);
138 
139  // call fes -> BuildDofToArrays() before using this projection
140  void ProjectCoefficient(Coefficient &coeff, Array<int> &dofs, int vd = 0);
141 
143 
144  void ProjectCoefficient(Coefficient *coeff[]);
145 
147  {
148  Coefficient *coeff_p = &coeff;
149  ProjectBdrCoefficient(&coeff_p, attr);
150  }
151 
152  void ProjectBdrCoefficient(Coefficient *coeff[], Array<int> &attr);
153 
158  Array<int> &bdr_attr);
159 
164  Array<int> &bdr_attr);
165 
167  const IntegrationRule *irs[] = NULL) const
168  { return ComputeLpError(2.0, exsol, NULL, irs); }
169 
170  double ComputeL2Error(Coefficient *exsol[],
171  const IntegrationRule *irs[] = NULL) const;
172 
173  double ComputeL2Error(VectorCoefficient &exsol,
174  const IntegrationRule *irs[] = NULL,
175  Array<int> *elems = NULL) const;
176 
177  double ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad,
178  Coefficient *ell_coef, double Nu,
179  int norm_type) const;
180 
182  const IntegrationRule *irs[] = NULL) const
183  {
184  return ComputeLpError(std::numeric_limits<double>::infinity(),
185  exsol, NULL, irs);
186  }
187 
188  double ComputeMaxError(Coefficient *exsol[],
189  const IntegrationRule *irs[] = NULL) const;
190 
192  const IntegrationRule *irs[] = NULL) const
193  {
194  return ComputeLpError(std::numeric_limits<double>::infinity(),
195  exsol, NULL, NULL, irs);
196  }
197 
199  const IntegrationRule *irs[] = NULL) const
200  { return ComputeLpError(1.0, exsol, NULL, irs); }
201 
202  double ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad,
203  int norm_type, Array<int> *elems = NULL,
204  const IntegrationRule *irs[] = NULL) const;
205 
207  const IntegrationRule *irs[] = NULL) const
208  { return ComputeLpError(1.0, exsol, NULL, NULL, irs); }
209 
210  double ComputeLpError(const double p, Coefficient &exsol,
211  Coefficient *weight = NULL,
212  const IntegrationRule *irs[] = NULL) const;
213 
217  double ComputeLpError(const double p, VectorCoefficient &exsol,
218  Coefficient *weight = NULL,
219  VectorCoefficient *v_weight = NULL,
220  const IntegrationRule *irs[] = NULL) const;
221 
223  GridFunction &operator=(double value);
224 
225  GridFunction &operator=(const Vector &v);
226 
228 
231  void ConformingProlongate(const Vector &x);
232 
234  void ConformingProlongate();
235 
238  void ConformingProject(Vector &x) const;
239 
244  void ConformingProject();
245 
247 
248  void Update() { SetSize(fes->GetVSize()); }
249 
250  void Update(FiniteElementSpace *f);
251 
252  void Update(FiniteElementSpace *f, Vector &v, int v_offset);
253 
255  virtual void Save(std::ostream &out) const;
256 
260  void SaveVTK(std::ostream &out, const std::string &field_name, int ref);
261 
262  void SaveSTL(std::ostream &out, int TimesToRefine = 1);
263 
265  virtual ~GridFunction();
266 };
267 
270 std::ostream &operator<<(std::ostream &out, const GridFunction &sol);
271 
272 
273 void ComputeFlux(BilinearFormIntegrator &blfi,
274  GridFunction &u,
275  GridFunction &flux, int wcoef = 1, int sd = -1);
276 
277 void ZZErrorEstimator(BilinearFormIntegrator &blfi,
278  GridFunction &u,
279  GridFunction &flux, Vector &ErrorEstimates,
280  int wsd = 1);
281 
282 
285 {
286 private:
287  int n;
288  Mesh *mesh_in;
289  Coefficient &sol_in;
290 public:
292  : n(_n), mesh_in(m), sol_in(s) { }
293  virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip);
294  virtual ~ExtrudeCoefficient() { }
295 };
296 
298 GridFunction *Extrude1DGridFunction(Mesh *mesh, Mesh *mesh2d,
299  GridFunction *sol, const int ny);
300 
301 }
302 
303 #endif
void SaveSTLTri(std::ostream &out, double p1[], double p2[], double p3[])
Definition: gridfunc.cpp:1878
std::ostream & operator<<(std::ostream &out, const Mesh &mesh)
Definition: mesh.cpp:8243
int GetVSize() const
Definition: fespace.hpp:151
Class for integration rule.
Definition: intrules.hpp:63
double ComputeL1Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:198
Class for grid function - Vector with associated FE space.
Definition: gridfunc.hpp:26
double ComputeMaxError(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:191
Class used for extruding scalar GridFunctions.
Definition: gridfunc.hpp:284
void ComputeFlux(BilinearFormIntegrator &blfi, GridFunction &u, GridFunction &flux, int wcoef, int sd)
Definition: gridfunc.cpp:1984
void ProjectDeltaCoefficient(DeltaCoefficient &delta_coeff, double &integral)
Definition: gridfunc.cpp:906
void ConformingProlongate()
Definition: gridfunc.cpp:1764
void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Definition: gridfunc.cpp:224
void SetSize(int s)
Resizes the vector if the new size is different.
Definition: vector.hpp:248
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:2109
void MakeOwner(FiniteElementCollection *_fec)
Make the GridFunction the owner of &#39;fec&#39; and &#39;fes&#39;.
Definition: gridfunc.hpp:57
void GetVectorGradientHat(ElementTransformation &T, DenseMatrix &gh)
Definition: gridfunc.cpp:666
void GetBdrValuesFrom(GridFunction &)
Definition: gridfunc.cpp:454
void GetGradient(ElementTransformation &tr, Vector &grad)
Definition: gridfunc.cpp:715
int VectorDim() const
Definition: gridfunc.cpp:160
Data type dense matrix.
Definition: densemat.hpp:22
Delta function coefficient.
void ImposeBounds(int i, const Vector &weights, const Vector &_lo, const Vector &_hi)
Definition: gridfunc.cpp:826
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:172
void GetVectorFieldNodalValues(Vector &val, int comp) const
Definition: gridfunc.cpp:550
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
Definition: gridfunc.cpp:1797
virtual double Eval(ElementTransformation &T, const IntegrationPoint &ip)
Definition: gridfunc.cpp:2099
double ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:181
void ZZErrorEstimator(BilinearFormIntegrator &blfi, GridFunction &u, GridFunction &flux, Vector &ErrorEstimates, int wsd)
Definition: gridfunc.cpp:2041
void GetDerivative(int comp, int der_comp, GridFunction &der)
Definition: gridfunc.cpp:612
void ProjectBdrCoefficientNormal(VectorCoefficient &vcoeff, Array< int > &bdr_attr)
Definition: gridfunc.cpp:1150
double GetDivergence(ElementTransformation &tr)
Definition: gridfunc.cpp:685
virtual ~GridFunction()
Destroys grid function.
Definition: gridfunc.cpp:127
double ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:166
void GetVectorFieldValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr, int comp=0) const
Definition: gridfunc.cpp:491
double ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad, Coefficient *ell_coef, double Nu, int norm_type) const
Definition: gridfunc.cpp:1324
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
Definition: gridfunc.cpp:256
FiniteElementCollection * OwnFEC()
Definition: gridfunc.hpp:60
virtual ~ExtrudeCoefficient()
Definition: gridfunc.hpp:294
FiniteElementSpace * FESpace()
Definition: gridfunc.hpp:246
double ComputeLpError(const double p, Coefficient &exsol, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:1593
Abstract finite element space.
Definition: fespace.hpp:61
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:30
void ProjectGridFunction(const GridFunction &src)
Definition: gridfunc.cpp:797
double ComputeL1Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.hpp:206
FiniteElementCollection * fec
Used when the grid function is read from a file.
Definition: gridfunc.hpp:33
int GetFaceVectorValues(int i, int side, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
Definition: gridfunc.cpp:380
Class for integration point with weight.
Definition: intrules.hpp:25
void SaveSTL(std::ostream &out, int TimesToRefine=1)
Definition: gridfunc.cpp:1897
int GetFaceValues(int i, int side, const IntegrationRule &ir, Vector &vals, DenseMatrix &tr, int vdim=1) const
Definition: gridfunc.cpp:286
void ConformingProject()
Definition: gridfunc.cpp:1787
void GetElementAverages(GridFunction &avgs)
Definition: gridfunc.cpp:769
void ProjectBdrCoefficientTangent(VectorCoefficient &vcoeff, Array< int > &bdr_attr)
Definition: gridfunc.cpp:1217
void GetVectorValues(ElementTransformation &T, const IntegrationRule &ir, DenseMatrix &vals) const
Definition: gridfunc.cpp:328
void ProjectCoefficient(Coefficient &coeff)
Definition: gridfunc.cpp:967
void ReorderByNodes()
For a vector grid function, makes sure that the ordering is byNODES.
Definition: gridfunc.cpp:529
double ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad, int norm_type, Array< int > *elems=NULL, const IntegrationRule *irs[]=NULL) const
Definition: gridfunc.cpp:1503
ExtrudeCoefficient(Mesh *m, Coefficient &s, int _n)
Definition: gridfunc.hpp:291
GridFunction & operator=(double value)
Redefine &#39;=&#39; for GridFunction = constant.
Definition: gridfunc.cpp:1731
Vector data type.
Definition: vector.hpp:29
void GetGradients(const int elem, const IntegrationRule &ir, DenseMatrix &grad)
Definition: gridfunc.cpp:733
GridFunction(FiniteElementSpace *f)
Creates grid function associated with *f.
Definition: gridfunc.hpp:49
void GetVectorGradient(ElementTransformation &tr, DenseMatrix &grad)
Definition: gridfunc.cpp:757
void GetValuesFrom(GridFunction &)
Definition: gridfunc.cpp:417
void SaveVTK(std::ostream &out, const std::string &field_name, int ref)
Definition: gridfunc.cpp:1807
void ProjectBdrCoefficient(Coefficient &coeff, Array< int > &attr)
Definition: gridfunc.hpp:146
virtual double GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition: gridfunc.cpp:211
void ProjectVectorFieldOn(GridFunction &vec_field, int comp=0)
Definition: gridfunc.cpp:579