MFEM v4.8.0
Finite element discretization library
Loading...
Searching...
No Matches
gridfunc.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
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#ifdef MFEM_USE_ADIOS2
21#endif
22#include <limits>
23#include <ostream>
24#include <string>
25
26namespace mfem
27{
28
29/// Class for grid function - Vector with associated FE space.
30class GridFunction : public Vector
31{
32protected:
33 /// FE space on which the grid function lives. Owned if #fec_owned is not NULL.
35
36 /** @brief Used when the grid function is read from a file. It can also be
37 set explicitly, see MakeOwner().
38
39 If not NULL, this pointer is owned by the GridFunction. */
41
42 long fes_sequence; // see FiniteElementSpace::sequence, Mesh::sequence
43
44 /** Optional, internal true-dof vector: if the FiniteElementSpace #fes has a
45 non-trivial (i.e. not NULL) prolongation operator, this Vector may hold
46 associated true-dof values - either owned or external. */
48
49 void SaveSTLTri(std::ostream &out, real_t p1[], real_t p2[], real_t p3[]);
50
51 // Project the delta coefficient without scaling and return the (local)
52 // integral of the projection.
54 real_t &integral);
55
56 // Sum fluxes to vertices and count element contributions
58 GridFunction &flux,
59 Array<int>& counts,
60 bool wcoef,
61 int subdomain);
62
63 /** Project a discontinuous vector coefficient in a continuous space and
64 return in dof_attr the maximal attribute of the elements containing each
65 degree of freedom. */
67
68 /// Loading helper.
69 void LegacyNCReorder();
70
71 void Destroy();
72
73public:
74
75 GridFunction() { fes = NULL; fec_owned = NULL; fes_sequence = 0; UseDevice(true); }
76
77 /// Copy constructor. The internal true-dof vector #t_vec is not copied.
79 : Vector(orig), fes(orig.fes), fec_owned(NULL), fes_sequence(orig.fes_sequence)
80 { UseDevice(true); }
81
82 /// Construct a GridFunction associated with the FiniteElementSpace @a *f.
84 { fes = f; fec_owned = NULL; fes_sequence = f->GetSequence(); UseDevice(true); }
85
86 /// Construct a GridFunction using previously allocated array @a data.
87 /** The GridFunction does not assume ownership of @a data which is assumed to
88 be of size at least `f->GetVSize()`. Similar to the Vector constructor
89 for externally allocated array, the pointer @a data can be NULL. The data
90 array can be replaced later using the method SetData().
91 */
93 : Vector(data, f->GetVSize())
94 { fes = f; fec_owned = NULL; fes_sequence = f->GetSequence(); UseDevice(true); }
95
96 /** @brief Construct a GridFunction using previously allocated Vector @a base
97 starting at the given offset, @a base_offset. */
98 GridFunction(FiniteElementSpace *f, Vector &base, int base_offset = 0)
99 : Vector(base, base_offset, f->GetVSize())
100 { fes = f; fec_owned = NULL; fes_sequence = f->GetSequence(); UseDevice(true); }
101
102 /// Construct a GridFunction on the given Mesh, using the data from @a input.
103 /** The content of @a input should be in the format created by the method
104 Save(). The reconstructed FiniteElementSpace and FiniteElementCollection
105 are owned by the GridFunction. */
106 GridFunction(Mesh *m, std::istream &input);
107
108 GridFunction(Mesh *m, GridFunction *gf_array[], int num_pieces);
109
110 /// Copy assignment. Only the data of the base class Vector is copied.
111 /** It is assumed that this object and @a rhs use FiniteElementSpace%s that
112 have the same size.
113
114 @note Defining this method overwrites the implicitly defined copy
115 assignment operator. */
117 { return operator=((const Vector &)rhs); }
118
119 /// Make the GridFunction the owner of #fec_owned and #fes.
120 /** If the new FiniteElementCollection, @a fec_, is NULL, ownership of #fec_owned
121 and #fes is taken away. */
123
125
126 /// Shortcut for calling FiniteElementSpace::GetVectorDim() on the underlying #fes
127 int VectorDim() const;
128
129 /// Shortcut for calling FiniteElementSpace::GetCurlDim() on the underlying #fes
130 int CurlDim() const;
131
132 /// Read only access to the (optional) internal true-dof Vector.
133 const Vector &GetTrueVector() const
134 {
135 MFEM_VERIFY(t_vec.Size() > 0, "SetTrueVector() before GetTrueVector()");
136 return t_vec;
137 }
138 /// Read and write access to the (optional) internal true-dof Vector.
139 /** Note that @a t_vec is set if it is not allocated or set already.*/
141 { if (t_vec.Size() == 0) { SetTrueVector(); } return t_vec; }
142
143 /// Extract the true-dofs from the GridFunction.
144 void GetTrueDofs(Vector &tv) const;
145
146 /// Shortcut for calling GetTrueDofs() with GetTrueVector() as argument.
148
149 /// Set the GridFunction from the given true-dof vector.
150 virtual void SetFromTrueDofs(const Vector &tv);
151
152 /// Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
154
155 /// Returns the values in the vertices of i'th element for dimension vdim.
156 void GetNodalValues(int i, Array<real_t> &nval, int vdim = 1) const;
157
158 /** @name Element index Get Value Methods
159
160 These methods take an element index and return the interpolated value of
161 the field at a given reference point within the element.
162
163 @warning These methods retrieve and use the ElementTransformation object
164 from the mfem::Mesh. This can alter the state of the element
165 transformation object and can also lead to unexpected results when the
166 ElementTransformation object is already in use such as when these methods
167 are called from within an integration loop. Consider using
168 GetValue(ElementTransformation &T, ...) instead.
169 */
170 ///@{
171 /** Return a scalar value from within the given element. */
172 virtual real_t GetValue(int i, const IntegrationPoint &ip,
173 int vdim = 1) const;
174
175 /** Return a vector value from within the given element. */
176 virtual void GetVectorValue(int i, const IntegrationPoint &ip,
177 Vector &val) const;
178 ///@}
179
180 /** @name Element Index Get Values Methods
181
182 These are convenience methods for repeatedly calling GetValue for
183 multiple points within a given element. The GetValues methods are
184 optimized and should perform better than repeatedly calling GetValue. The
185 GetVectorValues method simply calls GetVectorValue repeatedly.
186
187 @warning These methods retrieve and use the ElementTransformation object
188 from the mfem::Mesh. This can alter the state of the element
189 transformation object and can also lead to unexpected results when the
190 ElementTransformation object is already in use such as when these methods
191 are called from within an integration loop. Consider using
192 GetValues(ElementTransformation &T, ...) instead.
193 */
194 ///@{
195 /** Compute a collection of scalar values from within the element indicated
196 by the index i. */
197 void GetValues(int i, const IntegrationRule &ir, Vector &vals,
198 int vdim = 1) const;
199
200 /** Compute a collection of vector values from within the element indicated
201 by the index i. */
202 void GetValues(int i, const IntegrationRule &ir, Vector &vals,
203 DenseMatrix &tr, int vdim = 1) const;
204
205 void GetVectorValues(int i, const IntegrationRule &ir,
206 DenseMatrix &vals, DenseMatrix &tr) const;
207 ///@}
208
209 /** @name ElementTransformation Get Value Methods
210
211 These member functions are designed for use within
212 GridFunctionCoefficient objects. These can be used with
213 ElementTransformation objects coming from either
214 Mesh::GetElementTransformation() or Mesh::GetBdrElementTransformation().
215
216 @note These methods do not reset the ElementTransformation object so they
217 should be safe to use within integration loops or other contexts where
218 the ElementTransformation is already in use.
219 */
220 ///@{
221 /** Return a scalar value from within the element indicated by the
222 ElementTransformation Object. */
224 int comp = 0, Vector *tr = NULL) const;
225
226 /** Return a vector value from within the element indicated by the
227 ElementTransformation Object. */
229 const IntegrationPoint &ip,
230 Vector &val, Vector *tr = NULL) const;
231 ///@}
232
233 /** @name ElementTransformation Get Values Methods
234
235 These are convenience methods for repeatedly calling GetValue for
236 multiple points within a given element. They work by calling either the
237 ElementTransformation or FaceElementTransformations versions described
238 above. Consequently, these methods should not be expected to run faster
239 than calling the above methods in an external loop.
240
241 @note These methods do not reset the ElementTransformation object so they
242 should be safe to use within integration loops or other contexts where
243 the ElementTransformation is already in use.
244
245 @note These methods can also be used with FaceElementTransformations
246 objects.
247 */
248 ///@{
249 /** Compute a collection of scalar values from within the element indicated
250 by the ElementTransformation object. */
252 Vector &vals, int comp = 0, DenseMatrix *tr = NULL) const;
253
254 /** Compute a collection of vector values from within the element indicated
255 by the ElementTransformation object. */
257 DenseMatrix &vals, DenseMatrix *tr = NULL) const;
258 ///@}
259
260 /** @name Face Index Get Values Methods
261
262 These methods are designed to work with Discontinuous Galerkin basis
263 functions. They compute field values on the interface between elements,
264 or on boundary elements, by interpolating the field in a neighboring
265 element. The \a side argument indices which neighboring element should be
266 used: 0, 1, or 2 (automatically chosen).
267
268 @warning These methods retrieve and use the FaceElementTransformations
269 object from the mfem::Mesh. This can alter the state of the face element
270 transformations object and can also lead to unexpected results when the
271 FaceElementTransformations object is already in use such as when these
272 methods are called from within an integration loop. Consider using
273 GetValues(ElementTransformation &T, ...) instead.
274 */
275 ///@{
276 /** Compute a collection of scalar values from within the face
277 indicated by the index i. */
278 int GetFaceValues(int i, int side, const IntegrationRule &ir, Vector &vals,
279 DenseMatrix &tr, int vdim = 1) const;
280
281 /** Compute a collection of vector values from within the face
282 indicated by the index i. */
283 int GetFaceVectorValues(int i, int side, const IntegrationRule &ir,
284 DenseMatrix &vals, DenseMatrix &tr) const;
285 ///@}
286
287 void GetLaplacians(int i, const IntegrationRule &ir, Vector &laps,
288 int vdim = 1) const;
289
290 void GetLaplacians(int i, const IntegrationRule &ir, Vector &laps,
291 DenseMatrix &tr, int vdim = 1) const;
292
293 void GetHessians(int i, const IntegrationRule &ir, DenseMatrix &hess,
294 int vdim = 1) const;
295
296 void GetHessians(int i, const IntegrationRule &ir, DenseMatrix &hess,
297 DenseMatrix &tr, int vdim = 1) const;
298
299 void GetValuesFrom(const GridFunction &orig_func);
300
301 void GetBdrValuesFrom(const GridFunction &orig_func);
302
303 void GetVectorFieldValues(int i, const IntegrationRule &ir,
304 DenseMatrix &vals,
305 DenseMatrix &tr, int comp = 0) const;
306
307 /// For a vector grid function, makes sure that the ordering is byNODES.
308 void ReorderByNodes();
309
310 /// Return the values as a vector on mesh vertices for dimension vdim.
311 void GetNodalValues(Vector &nval, int vdim = 1) const;
312
313 void GetVectorFieldNodalValues(Vector &val, int comp) const;
314
315 void ProjectVectorFieldOn(GridFunction &vec_field, int comp = 0);
316
317 /** @brief Compute a certain derivative of a function's component.
318 Derivatives of the function are computed at the DOF locations of @a der,
319 and averaged over overlapping DOFs. Thus this function projects the
320 derivative to the FiniteElementSpace of @a der.
321 @param[in] comp Index of the function's component to be differentiated.
322 The index is 1-based, i.e., use 1 for scalar functions.
323 @param[in] der_comp Use 0/1/2 for derivatives in x/y/z directions.
324 @param[out] der The resulting derivative (scalar function). The
325 FiniteElementSpace of this function must be set
326 before the call. */
327 void GetDerivative(int comp, int der_comp, GridFunction &der) const;
328
330
331 void GetCurl(ElementTransformation &tr, Vector &curl) const;
332
333 /** @brief Gradient of a scalar function at a quadrature point.
334
335 @note It is assumed that the IntegrationPoint of interest has been
336 specified by ElementTransformation::SetIntPoint() before calling
337 GetGradient().
338
339 @note Can be used from a ParGridFunction when @a tr is an
340 ElementTransformation of a face-neighbor element and face-neighbor data
341 has been exchanged. */
342 void GetGradient(ElementTransformation &tr, Vector &grad) const;
343
344 /// Extension of GetGradient(...) for a collection of IntegrationPoints.
346 DenseMatrix &grad) const;
347
348 /// Extension of GetGradient(...) for a collection of IntegrationPoints.
349 void GetGradients(const int elem, const IntegrationRule &ir,
350 DenseMatrix &grad) const
351 { GetGradients(*fes->GetElementTransformation(elem), ir, grad); }
352
353 /** @brief Compute the vector gradient with respect to the physical element
354 variable. */
356
357 /** @brief Compute the vector gradient with respect to the reference element
358 variable. */
360
361 /** Compute $ (\int_{\Omega} (*this) \psi_i)/(\int_{\Omega} \psi_i) $,
362 where $ \psi_i $ are the basis functions for the FE space of avgs.
363 Both FE spaces should be scalar and on the same mesh. */
364 void GetElementAverages(GridFunction &avgs) const;
365
366 /** Sets the output vector @a dof_vals to the values of the degrees of
367 freedom of element @a el. */
368 virtual void GetElementDofValues(int el, Vector &dof_vals) const;
369
370 /** Impose the given bounds on the function's DOFs while preserving its local
371 * integral (described in terms of the given weights) on the i'th element
372 * through SLBPQ optimization.
373 * Intended to be used for discontinuous FE functions. */
374 void ImposeBounds(int i, const Vector &weights,
375 const Vector &lo_, const Vector &hi_);
376 void ImposeBounds(int i, const Vector &weights,
377 real_t min_ = 0.0, real_t max_ = infinity());
378
379 /** On a non-conforming mesh, make sure the function lies in the conforming
380 space by multiplying with R and then with P, the conforming restriction
381 and prolongation matrices of the space, respectively. */
382 void RestrictConforming();
383
384 /** @brief Project the @a src GridFunction to @a this GridFunction, both of
385 which must be on the same mesh. */
386 /** The current implementation assumes that all elements use the same
387 projection matrix. */
388 void ProjectGridFunction(const GridFunction &src);
389
390 /** @brief Project @a coeff Coefficient to @a this GridFunction. The
391 projection computation depends on the choice of the FiniteElementSpace
392 #fes. Note that this is usually interpolation at the degrees of freedom
393 in each element (not L2 projection). For NURBS spaces these degrees of
394 freedom are not available and L2 projection is resorted to as fallback. */
395 virtual void ProjectCoefficient(Coefficient &coeff);
396
397 /** @brief Project @a coeff Coefficient to @a this GridFunction, using one
398 element for each degree of freedom in @a dofs and nodal interpolation on
399 that element. */
400 void ProjectCoefficient(Coefficient &coeff, Array<int> &dofs, int vd = 0);
401
402 /** @brief Project @a vcoeff VectorCoefficient to @a this GridFunction. The
403 projection computation depends on the choice of the FiniteElementSpace
404 #fes. Note that this is usually interpolation at the degrees of freedom
405 in each element (not L2 projection). For NURBS spaces these degrees of
406 freedom are not available and L2 projection is resorted to as fallback. */
408
409 /** @brief Project @a vcoeff VectorCoefficient to @a this GridFunction, using
410 one element for each degree of freedom in @a dofs and nodal interpolation
411 on that element. */
413
414 /** @brief Project @a vcoeff VectorCoefficient to @a this GridFunction, only
415 projecting onto elements with the given @a attribute */
416 void ProjectCoefficient(VectorCoefficient &vcoeff, int attribute);
417
418 /** @brief Analogous to the version with argument @a vcoeff VectorCoefficient
419 but using an array of scalar coefficients for each component. */
420 void ProjectCoefficient(Coefficient *coeff[]);
421
422 /** @brief Project a discontinuous vector coefficient as a grid function on
423 a continuous finite element space. The values in shared dofs are
424 determined from the element with maximal attribute. */
425 virtual void ProjectDiscCoefficient(VectorCoefficient &coeff);
426
428 /** @brief Projects a discontinuous coefficient so that the values in shared
429 vdofs are computed by taking an average of the possible values. */
430 virtual void ProjectDiscCoefficient(Coefficient &coeff, AvgType type);
431 /** @brief Projects a discontinuous _vector_ coefficient so that the values
432 in shared vdofs are computed by taking an average of the possible values.
433 */
434 virtual void ProjectDiscCoefficient(VectorCoefficient &coeff, AvgType type);
435
436 /** @brief Return a GridFunction with the values of this, prolongated to the
437 maximum order of all elements in the mesh. */
438 std::unique_ptr<GridFunction> ProlongateToMaxOrder() const;
439
440protected:
441 /** @brief Accumulates (depending on @a type) the values of @a coeff at all
442 shared vdofs and counts in how many zones each vdof appears. */
444 Array<int> &zones_per_vdof);
445
446 /** @brief Accumulates (depending on @a type) the values of @a vcoeff at all
447 shared vdofs and counts in how many zones each vdof appears. */
449 Array<int> &zones_per_vdof);
450
451 /** @brief Used for the serial and parallel implementations of the
452 GetDerivative() method; see its documentation. */
453 void AccumulateAndCountDerivativeValues(int comp, int der_comp,
454 GridFunction &der,
455 Array<int> &zones_per_dof) const;
456
458 VectorCoefficient *vcoeff,
459 const Array<int> &attr,
460 Array<int> &values_counter);
461
463 const Array<int> &bdr_attr,
464 Array<int> &values_counter);
465
466 // Complete the computation of averages; called e.g. after
467 // AccumulateAndCountZones().
468 void ComputeMeans(AvgType type, Array<int> &zones_per_vdof);
469
470 /// P-refinement version of Update().
471 void UpdatePRef();
472
473public:
474 /** @brief For each vdof, counts how many elements contain the vdof,
475 as containment is determined by FiniteElementSpace::GetElementVDofs(). */
476 virtual void CountElementsPerVDof(Array<int> &elem_per_vdof) const;
477
478 /** @brief Project a Coefficient on the GridFunction, modifying only DOFs on
479 the boundary associated with the boundary attributes marked in the
480 @a attr array. */
482 {
483 Coefficient *coeff_p = &coeff;
484 ProjectBdrCoefficient(&coeff_p, attr);
485 }
486
487 /** @brief Project a VectorCoefficient on the GridFunction, modifying only
488 DOFs on the boundary associated with the boundary attributes marked in
489 the @a attr array. */
490 virtual void ProjectBdrCoefficient(VectorCoefficient &vcoeff,
491 const Array<int> &attr);
492
493 /** @brief Project a set of Coefficient%s on the components of the
494 GridFunction, modifying only DOFs on the boundary associated with the
495 boundary attributed marked in the @a attr array. */
496 /** If a Coefficient pointer in the array @a coeff is NULL, that component
497 will not be touched. */
498 virtual void ProjectBdrCoefficient(Coefficient *coeff[],
499 const Array<int> &attr);
500
501 /** Project the normal component of the given VectorCoefficient on
502 the boundary. Only boundary attributes that are marked in
503 'bdr_attr' are projected. Assumes RT-type VectorFE GridFunction. */
505 const Array<int> &bdr_attr);
506
507 /** @brief Project the tangential components of the given VectorCoefficient
508 on the boundary. Only boundary attributes that are marked in @a bdr_attr
509 are projected. Assumes ND-type VectorFE GridFunction. */
511 const Array<int> &bdr_attr);
512
513 /// @brief Returns ||exsol - u_h||_L2 for scalar or vector H1 or L2 elements
514 ///
515 /// @param[in] exsol Pointer to an array of scalar Coefficient objects,
516 /// one for each component of the vector field. The
517 /// length of the array should be at least equal to
518 /// FiniteElementSpace::GetVDim().
519 /// @param[in] irs Optional pointer to an array of custom integration
520 /// rules e.g. higher order than the default rules. If
521 /// present the array will be indexed by Geometry::Type.
522 /// @param[in] elems Optional pointer to a marker array, with a length
523 /// equal to the number of local elements, indicating
524 /// which elements to integrate over. Only those elements
525 /// corresponding to non-zero entries in @a elems will
526 /// contribute to the computed L2 error.
527 ///
528 /// @note If an array of integration rules is provided through @a irs, be
529 /// sure to include valid rules for each element type that may occur
530 /// in the list of elements.
531 ///
532 /// @note Quadratures with negative weights (as in some simplex integration
533 /// rules in MFEM) can produce negative integrals even with
534 /// non-negative integrands. To avoid returning negative errors this
535 /// function uses the absolute values of the element-wise integrals.
536 /// This may lead to results which are not entirely consistent with
537 /// such integration rules.
538 virtual real_t ComputeL2Error(Coefficient *exsol[],
539 const IntegrationRule *irs[] = NULL,
540 const Array<int> *elems = NULL) const;
541
542 /// @brief Returns ||grad u_ex - grad u_h||_L2 in element ielem for
543 /// H1 or L2 elements
544 ///
545 /// @param[in] ielem Index of the element in which to compute the L2 error.
546 /// @param[in] exgrad Pointer to a VectorCoefficient object reproducing the
547 /// expected gradient of the scalar field, grad u_ex.
548 /// @param[in] irs Optional pointer to an array of custom integration
549 /// rules e.g. higher order than the default rules. If
550 /// present the array will be indexed by Geometry::Type.
551 ///
552 /// @note If an array of integration rules is provided through @a irs, be
553 /// sure to include valid rules for each element type that may occur
554 /// in the list of elements.
555 ///
556 /// @note Quadratures with negative weights (as in some simplex integration
557 /// rules in MFEM) can produce negative integrals even with
558 /// non-negative integrands. To avoid returning negative errors this
559 /// function uses the absolute values of the element-wise integrals.
560 /// This may lead to results which are not entirely consistent with
561 /// such integration rules.
562 virtual real_t ComputeElementGradError(int ielem, VectorCoefficient *exgrad,
563 const IntegrationRule *irs[] = NULL) const;
564
565 /// @brief Returns ||u_ex - u_h||_L2 for H1 or L2 elements
566 ///
567 /// @param[in] exsol Coefficient object reproducing the anticipated values
568 /// of the scalar field, u_ex.
569 /// @param[in] irs Optional pointer to an array of custom integration
570 /// rules e.g. higher order than the default rules. If
571 /// present the array will be indexed by Geometry::Type.
572 /// @param[in] elems Optional pointer to a marker array, with a length
573 /// equal to the number of local elements, indicating
574 /// which elements to integrate over. Only those elements
575 /// corresponding to non-zero entries in @a elems will
576 /// contribute to the computed L2 error.
577 ///
578 /// @note If an array of integration rules is provided through @a irs, be
579 /// sure to include valid rules for each element type that may occur
580 /// in the list of elements.
581 ///
582 /// @note Quadratures with negative weights (as in some simplex integration
583 /// rules in MFEM) can produce negative integrals even with
584 /// non-negative integrands. To avoid returning negative errors this
585 /// function uses the absolute values of the element-wise integrals.
586 /// This may lead to results which are not entirely consistent with
587 /// such integration rules.
589 const IntegrationRule *irs[] = NULL,
590 const Array<int> *elems = NULL) const
591 { return GridFunction::ComputeLpError(2.0, exsol, NULL, irs, elems); }
592
593 /// @brief Returns ||u_ex - u_h||_L2 for vector fields
594 ///
595 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
596 /// values of the vector field, u_ex.
597 /// @param[in] irs Optional pointer to an array of custom integration
598 /// rules e.g. higher order than the default rules. If
599 /// present the array will be indexed by Geometry::Type.
600 /// @param[in] elems Optional pointer to a marker array, with a length
601 /// equal to the number of local elements, indicating
602 /// which elements to integrate over. Only those elements
603 /// corresponding to non-zero entries in @a elems will
604 /// contribute to the computed L2 error.
605 ///
606 /// @note If an array of integration rules is provided through @a irs, be
607 /// sure to include valid rules for each element type that may occur
608 /// in the list of elements.
609 ///
610 /// @note Quadratures with negative weights (as in some simplex integration
611 /// rules in MFEM) can produce negative integrals even with
612 /// non-negative integrands. To avoid returning negative errors this
613 /// function uses the absolute values of the element-wise integrals.
614 /// This may lead to results which are not entirely consistent with
615 /// such integration rules.
617 const IntegrationRule *irs[] = NULL,
618 const Array<int> *elems = NULL) const;
619
620 /// @brief Returns ||grad u_ex - grad u_h||_L2 for H1 or L2 elements
621 ///
622 /// @param[in] exgrad Pointer to a VectorCoefficient object reproducing the
623 /// expected gradient of the scalar field, grad u_ex.
624 /// @param[in] irs Optional pointer to an array of custom integration
625 /// rules e.g. higher order than the default rules. If
626 /// present the array will be indexed by Geometry::Type.
627 ///
628 /// @note This function only computes the error of the gradient in the
629 /// interior of the elements. In the context of discontinuous
630 /// Galerkin (DG) methods it may also be desirable to compute the
631 /// error in the jumps across element interfaces using
632 /// ComputeDGFaceJumpError().
633 ///
634 /// @note If an array of integration rules is provided through @a irs, be
635 /// sure to include valid rules for each element type that may occur
636 /// in the list of elements.
637 ///
638 /// @note Quadratures with negative weights (as in some simplex integration
639 /// rules in MFEM) can produce negative integrals even with
640 /// non-negative integrands. To avoid returning negative errors this
641 /// function uses the absolute values of the element-wise integrals.
642 /// This may lead to results which are not entirely consistent with
643 /// such integration rules.
645 const IntegrationRule *irs[] = NULL) const;
646
647 /// @brief Returns ||curl u_ex - curl u_h||_L2 for ND elements
648 ///
649 /// @param[in] excurl Pointer to a VectorCoefficient object reproducing the
650 /// expected curl of the vector field, curl u_ex.
651 /// @param[in] irs Optional pointer to an array of custom integration
652 /// rules e.g. higher order than the default rules. If
653 /// present the array will be indexed by Geometry::Type.
654 ///
655 /// @note If an array of integration rules is provided through @a irs, be
656 /// sure to include valid rules for each element type that may occur
657 /// in the list of elements.
658 ///
659 /// @note Quadratures with negative weights (as in some simplex integration
660 /// rules in MFEM) can produce negative integrals even with
661 /// non-negative integrands. To avoid returning negative errors this
662 /// function uses the absolute values of the element-wise integrals.
663 /// This may lead to results which are not entirely consistent with
664 /// such integration rules.
666 const IntegrationRule *irs[] = NULL) const;
667
668 /// @brief Returns ||div u_ex - div u_h||_L2 for RT elements
669 ///
670 /// @param[in] exdiv Pointer to a Coefficient object reproducing the
671 /// expected divergence of the vector field, div u_ex.
672 /// @param[in] irs Optional pointer to an array of custom integration
673 /// rules e.g. higher order than the default rules. If
674 /// present the array will be indexed by Geometry::Type.
675 ///
676 /// @note If an array of integration rules is provided through @a irs, be
677 /// sure to include valid rules for each element type that may occur
678 /// in the list of elements.
679 ///
680 /// @note Quadratures with negative weights (as in some simplex integration
681 /// rules in MFEM) can produce negative integrals even with
682 /// non-negative integrands. To avoid returning negative errors this
683 /// function uses the absolute values of the element-wise integrals.
684 /// This may lead to results which are not entirely consistent with
685 /// such integration rules.
686 virtual real_t ComputeDivError(Coefficient *exdiv,
687 const IntegrationRule *irs[] = NULL) const;
688
689 /// @brief Returns the Face Jumps error for L2 elements.
690 ///
691 /// Computes:
692 /// $$\sqrt{\sum_{f\in faces}\int_f js(f) ell(f)
693 /// (2 u_{ex} - u_1 - u_2)^2}$$
694 ///
695 /// Where js[f] is the jump_scaling evaluated on the face f and ell is the
696 /// average of ell_coef evaluated in the two elements sharing the face f.
697 ///
698 /// @param[in] exsol Pointer to a Coefficient object reproducing the
699 /// anticipated values of the scalar field, u_ex.
700 /// @param[in] ell_coeff Pointer to a Coefficient object used to compute
701 /// the averaged value ell in the above integral.
702 /// @param[in] jump_scaling Can be configured to provide scaling by
703 /// nu, nu/h, or nu*p^2/h
704 /// @param[in] irs Optional pointer to an array of custom
705 /// integration rules e.g. higher order than the
706 /// default rules. If present the array will be
707 /// indexed by Geometry::Type.
708 ///
709 /// @note If an array of integration rules is provided through @a irs, be
710 /// sure to include valid rules for each element type that may occur
711 /// in the list of faces.
712 ///
713 /// @note Quadratures with negative weights (as in some simplex integration
714 /// rules in MFEM) can produce negative integrals even with
715 /// non-negative integrands. To avoid returning negative errors this
716 /// function uses the absolute values of the element-wise integrals.
717 /// This may lead to results which are not entirely consistent with
718 /// such integration rules.
720 Coefficient *ell_coeff,
721 class JumpScaling jump_scaling,
722 const IntegrationRule *irs[] = NULL)
723 const;
724
725 /// @brief Returns the Face Jumps error for L2 elements, with 1/h scaling.
726 ///
727 /// @note Quadratures with negative weights (as in some simplex integration
728 /// rules in MFEM) can produce negative integrals even with
729 /// non-negative integrands. To avoid returning negative errors this
730 /// function uses the absolute values of the element-wise integrals.
731 /// This may lead to results which are not entirely consistent with
732 /// such integration rules.
733 ///
734 /// @deprecated See @ref ComputeDGFaceJumpError(Coefficient *exsol,
735 /// Coefficient *ell_coeff,
736 /// class JumpScaling jump_scaling,
737 /// const IntegrationRule *irs[]) const
738 /// for the preferred implementation.
739 MFEM_DEPRECATED
741 Coefficient *ell_coeff,
742 real_t Nu,
743 const IntegrationRule *irs[] = NULL) const;
744
745 /** This method is kept for backward compatibility.
746
747 Returns either the H1-seminorm, or the DG face jumps error, or both
748 depending on norm_type = 1, 2, 3. Additional arguments for the DG face
749 jumps norm: ell_coeff: mesh-depended coefficient (weight) Nu: scalar
750 constant weight */
751 virtual real_t ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad,
752 Coefficient *ell_coef, real_t Nu,
753 int norm_type) const;
754
755 /// @brief Returns the error measured in H1-norm for H1 or L2 elements
756 ///
757 /// Computes the norm using the $L^2$ norms of the function and its gradient
758 /// $$\sqrt{norm\_u^2 + norm\_du^2}$$
759 /// Where
760 /// $$norm\_u = \|u_{ex} - u_h\|_{L^2}$$
761 /// and
762 /// $$norm\_du = \|du_{ex} - \nabla u_h\|_{L^2}$$
763 ///
764 /// @param[in] exsol Coefficient object reproducing the anticipated values
765 /// of the scalar field, u_ex.
766 /// @param[in] exgrad VectorCoefficient object reproducing the anticipated
767 /// values of the gradient of the scalar field, du_ex.
768 /// @param[in] irs Optional pointer to an array of custom integration
769 /// rules e.g. higher order than the default rules. If
770 /// present the array will be indexed by Geometry::Type.
771 ///
772 /// @note If an array of integration rules is provided through @a irs, be
773 /// sure to include valid rules for each element type that may occur
774 /// in the list of elements.
775 ///
776 /// @note Quadratures with negative weights (as in some simplex integration
777 /// rules in MFEM) can produce negative integrals even with
778 /// non-negative integrands. To avoid returning negative errors this
779 /// function uses the absolute values of the element-wise integrals.
780 /// This may lead to results which are not entirely consistent with
781 /// such integration rules.
782 ///
783 /// @note For L2 elements this returns what could be called a "broken"
784 /// H1-norm.
785 virtual real_t ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad,
786 const IntegrationRule *irs[] = NULL) const;
787
788 /// @brief Returns the error measured in H(div)-norm for RT elements
789 ///
790 /// Computes the norm using the $L^2$ norms of the function and its
791 /// divergence
792 /// $$\sqrt{norm\_u^2 + norm\_du^2}$$
793 /// Where
794 /// $$norm\_u = \|u_{ex} - u_h\|_{L^2}$$
795 /// and
796 /// $$norm\_du = \|du_{ex} - \nabla\cdot u_h\|_{L^2}$$
797 ///
798 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
799 /// values of the vector field, u_ex.
800 /// @param[in] exdiv VectorCoefficient object reproducing the anticipated
801 /// values of the divergence of the vector field, du_ex.
802 /// @param[in] irs Optional pointer to an array of custom integration
803 /// rules e.g. higher order than the default rules. If
804 /// present the array will be indexed by Geometry::Type.
805 ///
806 /// @note If an array of integration rules is provided through @a irs, be
807 /// sure to include valid rules for each element type that may occur
808 /// in the list of elements.
809 ///
810 /// @note Quadratures with negative weights (as in some simplex integration
811 /// rules in MFEM) can produce negative integrals even with
812 /// non-negative integrands. To avoid returning negative errors this
813 /// function uses the absolute values of the element-wise integrals.
814 /// This may lead to results which are not entirely consistent with
815 /// such integration rules.
817 Coefficient *exdiv,
818 const IntegrationRule *irs[] = NULL) const;
819
820 /// @brief Returns the error measured in H(curl)-norm for ND elements
821 ///
822 /// Computes the norm using the $L^2$ norms of the function and its curl
823 /// $$\sqrt{norm\_u^2 + norm\_du^2}$$
824 /// Where
825 /// $$norm\_u = \|u_{ex} - u_h\|_{L^2}$$
826 /// and
827 /// $$norm\_du = \|du_{ex} - \nabla\times u_h\|_{L^2}$$
828 ///
829 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
830 /// values of the vector field, u_ex.
831 /// @param[in] excurl VectorCoefficient object reproducing the anticipated
832 /// values of the curl of the vector field, du_ex.
833 /// @param[in] irs Optional pointer to an array of custom integration
834 /// rules e.g. higher order than the default rules. If
835 /// present the array will be indexed by Geometry::Type.
836 ///
837 /// @note If an array of integration rules is provided through @a irs, be
838 /// sure to include valid rules for each element type that may occur
839 /// in the list of elements.
840 ///
841 /// @note Quadratures with negative weights (as in some simplex integration
842 /// rules in MFEM) can produce negative integrals even with
843 /// non-negative integrands. To avoid returning negative errors this
844 /// function uses the absolute values of the element-wise integrals.
845 /// This may lead to results which are not entirely consistent with
846 /// such integration rules.
848 VectorCoefficient *excurl,
849 const IntegrationRule *irs[] = NULL) const;
850
851 /// @brief Returns Max|u_ex - u_h| error for H1 or L2 elements
852 ///
853 /// Compute the $L^\infty$ error across the entire domain.
854 ///
855 /// @param[in] exsol Coefficient object reproducing the anticipated
856 /// values of the scalar field, u_ex.
857 /// @param[in] irs Optional pointer to an array of custom integration
858 /// rules e.g. higher order than the default rules. If
859 /// present the array will be indexed by
860 /// Geometry::Type.
861 ///
862 /// @note Uses ComputeLpError internally. See the ComputeLpError
863 /// documentation for generalizations of this error computation.
864 ///
865 /// @note If an array of integration rules is provided through @a irs, be
866 /// sure to include valid rules for each element type that may occur
867 /// in the list of elements.
868 ///
870 const IntegrationRule *irs[] = NULL) const
871 {
872 return ComputeLpError(infinity(), exsol, NULL, irs);
873 }
874
875 /// @brief Returns Max|u_ex - u_h| error for scalar or vector fields
876 ///
877 /// Compute the $L^\infty$ error across the entire domain.
878 ///
879 /// Computes:
880 /// $$max_{elems} (max_{elem} |scalar\_error|)$$
881 ///
882 /// Where
883 /// $$scalar\_error = max_{d=0\ldots vdim}|u_{ex}[d] - u_h[d]|$$
884 ///
885 /// @param[in] exsol Pointer to an array of scalar Coefficient objects,
886 /// one for each component of the vector field. The
887 /// length of the array should be at least equal to
888 /// FiniteElementSpace::GetVDim().
889 /// @param[in] irs Optional pointer to an array of custom integration
890 /// rules e.g. higher order than the default rules. If
891 /// present the array will be indexed by Geometry::Type.
892 ///
893 /// @note This implementation of the max error of a vector field computes
894 /// the max norm over vector components rather than the magnitude of
895 /// the vector.
896 ///
897 /// @note If an array of integration rules is provided through @a irs, be
898 /// sure to include valid rules for each element type that may occur
899 /// in the list of elements.
900 ///
901 virtual real_t ComputeMaxError(Coefficient *exsol[],
902 const IntegrationRule *irs[] = NULL) const;
903
904 /// @brief Returns Max|u_ex - u_h| error for vector fields
905 ///
906 /// Compute the $L^\infty$ error across the entire domain.
907 ///
908 /// Computes:
909 /// $$max_{elems} (max_{elem} |scalar\_error|)$$
910 ///
911 /// Where
912 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
913 ///
914 /// @param[in] exsol VectorCoefficient object reproducing the
915 /// anticipated values of the vector field, u_ex.
916 /// @param[in] irs Optional pointer to an array of custom integration
917 /// rules e.g. higher order than the default rules. If
918 /// present the array will be indexed by
919 /// Geometry::Type.
920 ///
921 /// @note Uses ComputeLpError internally. See the ComputeLpError
922 /// documentation for generalizations of this error computation.
923 ///
924 /// @note Computes the maximum magnitude of the difference vector not the
925 /// component-wise maximum difference of the vector fields.
926 ///
927 /// @note If an array of integration rules is provided through @a irs, be
928 /// sure to include valid rules for each element type that may occur
929 /// in the list of elements.
930 ///
932 const IntegrationRule *irs[] = NULL) const
933 {
934 return ComputeLpError(infinity(), exsol, NULL, NULL, irs);
935 }
936
937 /// @brief Returns ||u_ex - u_h||_L1 for H1 or L2 elements
938 ///
939 /// Computes:
940 /// $$\sum_{elems} \int_{elem} |u_{ex} - u_h|$$
941 ///
942 /// @param[in] exsol Coefficient object reproducing the anticipated values
943 /// of the scalar field, u_ex.
944 /// @param[in] irs Optional pointer to an array of custom integration
945 /// rules e.g. higher order than the default rules. If
946 /// present the array will be indexed by Geometry::Type.
947 ///
948 /// @note Quadratures with negative weights (as in some simplex integration
949 /// rules in MFEM) can produce negative integrals even with
950 /// non-negative integrands. To avoid returning negative errors this
951 /// function uses the absolute values of the element-wise integrals.
952 /// This may lead to results which are not entirely consistent with
953 /// such integration rules.
954 ///
955 /// @note Uses ComputeLpError internally. See the ComputeLpError
956 /// documentation for generalizations of this error computation.
957 ///
958 /// @note If an array of integration rules is provided through @a irs, be
959 /// sure to include valid rules for each element type that may occur
960 /// in the list of elements.
961 ///
963 const IntegrationRule *irs[] = NULL) const
964 { return ComputeLpError(1.0, exsol, NULL, irs); }
965
966 /// @brief Returns ||u_ex - u_h||_L1 for H1 or L2 elements
967 ///
968 /// Computes:
969 /// $$\sum_{elems} \int_{elem} |u_{ex} - u_h|$$
970 ///
971 /// @param[in] exsol Pointer to an array of Coefficient objects
972 /// reproducing the anticipated values of the scalar
973 /// field, u_ex. Only the first entry of this array will
974 /// be accessed.
975 /// @param[in] irs Optional pointer to an array of custom integration
976 /// rules e.g. higher order than the default rules. If
977 /// present the array will be indexed by Geometry::Type.
978 ///
979 /// @note If an array of integration rules is provided through @a irs, be
980 /// sure to include valid rules for each element type that may occur
981 /// in the list of elements.
982 ///
983 /// @note Quadratures with negative weights (as in some simplex integration
984 /// rules in MFEM) can produce negative integrals even with
985 /// non-negative integrands. To avoid returning negative errors this
986 /// function uses the absolute values of the element-wise integrals.
987 /// This may lead to results which are not entirely consistent with
988 /// such integration rules.
989 ///
990 /// @note Uses ComputeW11Error internally. See the ComputeW11Error
991 /// documentation for generalizations of this error computation.
992 ///
993 /// @warning While this function is nominally equivalent to ComputeLpError,
994 /// with appropriate arguments, the returned errors may differ
995 /// noticeably because ComputeLpError uses a higher order
996 /// integration rule by default.
997 ///
998 /// @deprecated See @ref ComputeL1Error(Coefficient &exsol,
999 /// const IntegrationRule *irs[]) const
1000 /// for the preferred implementation.
1001 MFEM_DEPRECATED
1003 const IntegrationRule *irs[] = NULL) const
1004 { return ComputeW11Error(*exsol, NULL, 1, NULL, irs); }
1005
1006 /// @brief Returns $W^1_1$ norm (or portions thereof) for H1 or L2 elements
1007 ///
1008 /// Computes for norm_type == 1 the $L^1$ norm of $u$:
1009 /// $$(\sum_{elems} \int_{elem} |u_{ex} - u_h|$$
1010 ///
1011 /// Computes for norm_type == 2 the $L^1$ semi-norm of $\nabla u$:
1012 /// $$(\sum_{elems} \int_{elem} |du_{ex} - \nabla u_h|$$
1013 ///
1014 /// Computes for norm_type == 3 the $W^1_1$ norm of $u$:
1015 /// $$(\sum_{elems} \int_{elem} |u_{ex} - u_h| + |du_{ex} - \nabla u_h|$$
1016 ///
1017 /// @param[in] exsol Pointer to Coefficient object reproducing the
1018 /// anticipated values of the scalar field, u_ex.
1019 /// @param[in] exgrad Pointer to VectorCoefficient object reproducing the
1020 /// anticipated values of the gradient of the scalar
1021 /// field, du_ex.
1022 /// @param[in] norm_type Integer value of 1, 2, or 3 indicating the type of
1023 /// norm to compute (see above).
1024 /// @param[in] elems Optional pointer to a marker array, with a length
1025 /// equal to the number of local elements, indicating
1026 /// which elements to integrate over. Only those
1027 /// elements corresponding to non-zero entries in
1028 /// @a elems will contribute to the computed $W^1_1$
1029 /// error.
1030 /// @param[in] irs Optional pointer to an array of custom integration
1031 /// rules e.g. higher order than the default rules. If
1032 /// present the array will be indexed by Geometry::Type.
1033 ///
1034 /// @note If an array of integration rules is provided through @a irs, be
1035 /// sure to include valid rules for each element type that may occur
1036 /// in the list of elements.
1037 ///
1038 /// @note Quadratures with negative weights (as in some simplex integration
1039 /// rules in MFEM) can produce negative integrals even with
1040 /// non-negative integrands. To avoid returning negative errors this
1041 /// function uses the absolute values of the element-wise integrals.
1042 /// This may lead to results which are not entirely consistent with
1043 /// such integration rules.
1044 virtual real_t ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad,
1045 int norm_type, const Array<int> *elems = NULL,
1046 const IntegrationRule *irs[] = NULL) const;
1047
1048 /// @brief Returns ||u_ex - u_h||_L1 for vector fields
1049 ///
1050 /// Computes:
1051 /// $$\sum_{elems} \int_{elem} |scalar\_error|$$
1052 ///
1053 /// Where
1054 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1055 ///
1056 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
1057 /// values of the vector field, u_ex.
1058 /// @param[in] irs Optional pointer to an array of custom integration
1059 /// rules e.g. higher order than the default rules. If
1060 /// present the array will be indexed by Geometry::Type.
1061 ///
1062 /// @note If an array of integration rules is provided through @a irs, be
1063 /// sure to include valid rules for each element type that may occur
1064 /// in the list of elements.
1065 ///
1066 /// @note Quadratures with negative weights (as in some simplex integration
1067 /// rules in MFEM) can produce negative integrals even with
1068 /// non-negative integrands. To avoid returning negative errors this
1069 /// function uses the absolute values of the element-wise integrals.
1070 /// This may lead to results which are not entirely consistent with
1071 /// such integration rules.
1072 ///
1073 /// @note Uses ComputeLpError internally. See the ComputeLpError
1074 /// documentation for generalizations of this error computation.
1076 const IntegrationRule *irs[] = NULL) const
1077 { return ComputeLpError(1.0, exsol, NULL, NULL, irs); }
1078
1079 /// @brief Returns ||u_ex - u_h||_Lp for H1 or L2 elements
1080 ///
1081 /// Computes:
1082 /// $$(\sum_{elems} \int_{elem} w \, |u_{ex} - u_h|^p)^{1/p}$$
1083 ///
1084 /// @param[in] p Real value indicating the exponent of the $L^p$ norm.
1085 /// To avoid domain errors p should have a positive value,
1086 /// either finite or infinite.
1087 /// @param[in] exsol Coefficient object reproducing the anticipated values
1088 /// of the scalar field, u_ex.
1089 /// @param[in] weight Optional pointer to a Coefficient object reproducing
1090 /// a weighting function, w.
1091 /// @param[in] irs Optional pointer to an array of custom integration
1092 /// rules e.g. higher order than the default rules. If
1093 /// present the array will be indexed by Geometry::Type.
1094 /// @param[in] elems Optional pointer to a marker array, with a length
1095 /// equal to the number of local elements, indicating
1096 /// which elements to integrate over. Only those elements
1097 /// corresponding to non-zero entries in @a elems will
1098 /// contribute to the computed L2 error.
1099 ///
1100 /// @note If an array of integration rules is provided through @a irs, be
1101 /// sure to include valid rules for each element type that may occur
1102 /// in the list of elements.
1103 ///
1104 /// @note Quadratures with negative weights (as in some simplex integration
1105 /// rules in MFEM) can produce negative integrals even with
1106 /// non-negative integrands. To avoid returning negative errors this
1107 /// function uses the absolute values of the element-wise integrals.
1108 /// This may lead to results which are not entirely consistent with
1109 /// such integration rules.
1110 virtual real_t ComputeLpError(const real_t p, Coefficient &exsol,
1111 Coefficient *weight = NULL,
1112 const IntegrationRule *irs[] = NULL,
1113 const Array<int> *elems = NULL) const;
1114
1115 /// @brief Returns ||u_ex - u_h||_Lp elementwise for H1 or L2 elements
1116 ///
1117 /// Compute the Lp error in each element of the mesh and store the results in
1118 /// the Vector @a error. The result should be of length number of elements,
1119 /// for example an L2 GridFunction of order zero using map type @ref
1120 /// map_type_value "VALUE".
1121 ///
1122 /// Computes:
1123 /// $$(\int_{elem} w \, |u_{ex} - u_h|^p)^{1/p}$$
1124 ///
1125 /// @param[in] p Real value indicating the exponent of the $L^p$
1126 /// norm. To avoid domain errors p should have a
1127 /// positive value, either finite or infinite.
1128 /// @param[in] exsol Coefficient object reproducing the anticipated
1129 /// values of the scalar field, u_ex.
1130 /// @param[in,out] error Vector to contain the element-wise $L^p$ errors
1131 /// @param[in] weight Optional pointer to a Coefficient object
1132 /// reproducing a weighting function, w.
1133 /// @param[in] irs Optional pointer to an array of custom integration
1134 /// rules e.g. higher order than the default rules. If
1135 /// present the array will be indexed by
1136 /// Geometry::Type.
1137 ///
1138 /// @note If an array of integration rules is provided through @a irs, be
1139 /// sure to include valid rules for each element type that may occur
1140 /// in the list of elements.
1141 ///
1142 /// @note Quadratures with negative weights (as in some simplex integration
1143 /// rules in MFEM) can produce negative integrals even with
1144 /// non-negative integrands. To avoid returning negative errors this
1145 /// function uses the absolute values of the element-wise integrals.
1146 /// This may lead to results which are not entirely consistent with
1147 /// such integration rules.
1148 virtual void ComputeElementLpErrors(const real_t p, Coefficient &exsol,
1149 Vector &error,
1150 Coefficient *weight = NULL,
1151 const IntegrationRule *irs[] = NULL
1152 ) const;
1153
1154 /// @brief Returns ||u_ex - u_h||_L1 elementwise for H1 or L2 elements
1155 ///
1156 /// Compute the $L^1$ error in each element of the mesh and store the
1157 /// results in the Vector @a error. The result should be of length number of
1158 /// elements, for example an L2 GridFunction of order zero using map type
1159 /// @ref map_type_value "VALUE".
1160 ///
1161 /// @param[in] exsol Coefficient object reproducing the anticipated
1162 /// values of the scalar field, u_ex.
1163 /// @param[in,out] error Vector to contain the element-wise $L^1$ errors
1164 /// @param[in] irs Optional pointer to an array of custom integration
1165 /// rules e.g. higher order than the default rules. If
1166 /// present the array will be indexed by
1167 /// Geometry::Type.
1168 ///
1169 /// @note If an array of integration rules is provided through @a irs, be
1170 /// sure to include valid rules for each element type that may occur
1171 /// in the list of elements.
1172 ///
1173 /// @note Quadratures with negative weights (as in some simplex integration
1174 /// rules in MFEM) can produce negative integrals even with
1175 /// non-negative integrands. To avoid returning negative errors this
1176 /// function uses the absolute values of the element-wise integrals.
1177 /// This may lead to results which are not entirely consistent with
1178 /// such integration rules.
1179 ///
1180 /// @note Uses ComputeElementLpError internally. See the
1181 /// ComputeElementLpError documentation for generalizations of this
1182 /// error computation.
1184 Vector &error,
1185 const IntegrationRule *irs[] = NULL
1186 ) const
1187 { ComputeElementLpErrors(1.0, exsol, error, NULL, irs); }
1188
1189 /// @brief Returns ||u_ex - u_h||_L2 elementwise for H1 or L2 elements
1190 ///
1191 /// Compute the $L^2$ error in each element of the mesh and store the results
1192 /// in the Vector @a error. The result should be of length number of
1193 /// elements, for example an L2 GridFunction of order zero using map type
1194 /// @ref map_type_value "VALUE".
1195 ///
1196 /// Computes:
1197 /// $$(\int_{elem} |u_{ex} - u_h|^2)^{1/2}$$
1198 ///
1199 /// @param[in] exsol Coefficient object reproducing the anticipated
1200 /// values of the scalar field, u_ex.
1201 /// @param[in,out] error Vector to contain the element-wise $L^2$ errors
1202 /// @param[in] irs Optional pointer to an array of custom integration
1203 /// rules e.g. higher order than the default rules. If
1204 /// present the array will be indexed by
1205 /// Geometry::Type.
1206 ///
1207 /// @note If an array of integration rules is provided through @a irs, be
1208 /// sure to include valid rules for each element type that may occur
1209 /// in the list of elements.
1210 ///
1211 /// @note Quadratures with negative weights (as in some simplex integration
1212 /// rules in MFEM) can produce negative integrals even with
1213 /// non-negative integrands. To avoid returning negative errors this
1214 /// function uses the absolute values of the element-wise integrals.
1215 /// This may lead to results which are not entirely consistent with
1216 /// such integration rules.
1217 ///
1218 /// @note Uses ComputeElementLpError internally. See the
1219 /// ComputeElementLpError documentation for generalizations of this
1220 /// error computation.
1222 Vector &error,
1223 const IntegrationRule *irs[] = NULL
1224 ) const
1225 { ComputeElementLpErrors(2.0, exsol, error, NULL, irs); }
1226
1227 /// @brief Returns Max|u_ex - u_h| elementwise for H1 or L2 elements
1228 ///
1229 /// Compute the $L^\infty$ error in each element of the mesh and store the
1230 /// results in the Vector @a error. The result should be of length number of
1231 /// elements, for example an L2 GridFunction of order zero using map type
1232 /// @ref map_type_value "VALUE".
1233 ///
1234 /// @param[in] exsol Coefficient object reproducing the anticipated
1235 /// values of the scalar field, u_ex.
1236 /// @param[in,out] error Vector to contain the element-wise $L^\infty$
1237 /// errors
1238 /// @param[in] irs Optional pointer to an array of custom integration
1239 /// rules e.g. higher order than the default rules. If
1240 /// present the array will be indexed by
1241 /// Geometry::Type.
1242 ///
1243 /// @note If an array of integration rules is provided through @a irs, be
1244 /// sure to include valid rules for each element type that may occur
1245 /// in the list of elements.
1246 ///
1247 /// @note Uses ComputeElementLpError internally. See the
1248 /// ComputeElementLpError documentation for generalizations of this
1249 /// error computation.
1251 Vector &error,
1252 const IntegrationRule *irs[] = NULL
1253 ) const
1254 { ComputeElementLpErrors(infinity(), exsol, error, NULL, irs); }
1255
1256 /// @brief Returns ||u_ex - u_h||_Lp for vector fields
1257 ///
1258 /// When given a vector weight, compute the pointwise (scalar) error as the
1259 /// dot product of the vector error with the vector weight. Otherwise, the
1260 /// scalar error is the l_2 norm of the vector error.
1261 ///
1262 /// Computes:
1263 /// $$(\sum_{elems} \int_{elem} w \, |scalar\_error|^p)^{1/p}$$
1264 ///
1265 /// Where
1266 /// $$scalar\_error = |v\_weight \cdot (u_{ex} - u_h)|$$
1267 /// or
1268 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1269 ///
1270 /// @param[in] p Real value indicating the exponent of the $L^p$
1271 /// norm. To avoid domain errors p should have a
1272 /// positive value, either finite or infinite.
1273 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
1274 /// values of the vector field, u_ex.
1275 /// @param[in] weight Optional pointer to a Coefficient object reproducing
1276 /// a weighting function, w.
1277 /// @param[in] v_weight Optional pointer to a VectorCoefficient object
1278 /// reproducing a weighting vector as shown above.
1279 /// @param[in] irs Optional pointer to an array of custom integration
1280 /// rules e.g. higher order than the default rules. If
1281 /// present the array will be indexed by Geometry::Type.
1282 ///
1283 /// @note If an array of integration rules is provided through @a irs, be
1284 /// sure to include valid rules for each element type that may occur
1285 /// in the list of elements.
1286 ///
1287 /// @note Quadratures with negative weights (as in some simplex integration
1288 /// rules in MFEM) can produce negative integrals even with
1289 /// non-negative integrands. To avoid returning negative errors this
1290 /// function uses the absolute values of the element-wise integrals.
1291 /// This may lead to results which are not entirely consistent with
1292 /// such integration rules.
1293 virtual real_t ComputeLpError(const real_t p, VectorCoefficient &exsol,
1294 Coefficient *weight = NULL,
1295 VectorCoefficient *v_weight = NULL,
1296 const IntegrationRule *irs[] = NULL) const;
1297
1298 /// @brief Returns ||u_ex - u_h||_Lp elementwise for vector fields
1299 ///
1300 /// Compute the $L^p$ error in each element of the mesh and store the results
1301 /// in the Vector @a error. The result should be of length number of
1302 /// elements, for example an L2 GridFunction of order zero using map type
1303 /// @ref map_type_value "VALUE".
1304 ///
1305 /// Computes:
1306 /// $$(\int_{elem} w \, |scalar\_error|^p)^{1/p}$$
1307 ///
1308 /// Where
1309 /// $$scalar\_error = |v\_weight \cdot (u_{ex} - u_h)|$$
1310 /// or
1311 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1312 ///
1313 /// @param[in] p Real value indicating the exponent of the $L^p$
1314 /// norm. To avoid domain errors p should have a
1315 /// positive value, either finite or infinite.
1316 /// @param[in] exsol VectorCoefficient object reproducing the
1317 /// anticipated values of the vector field, u_ex.
1318 /// @param[in,out] error Vector to contain the element-wise $L^p$ errors
1319 /// @param[in] weight Optional pointer to a Coefficient object
1320 /// reproducing a weighting function, w.
1321 /// @param[in] v_weight Optional pointer to a VectorCoefficient object
1322 /// reproducing a weighting vector as shown above.
1323 /// @param[in] irs Optional pointer to an array of custom integration
1324 /// rules e.g. higher order than the default rules. If
1325 /// present the array will be indexed by
1326 /// Geometry::Type.
1327 ///
1328 /// @note If an array of integration rules is provided through @a irs, be
1329 /// sure to include valid rules for each element type that may occur
1330 /// in the list of elements.
1331 ///
1332 /// @note Quadratures with negative weights (as in some simplex integration
1333 /// rules in MFEM) can produce negative integrals even with
1334 /// non-negative integrands. To avoid returning negative errors this
1335 /// function uses the absolute values of the element-wise integrals.
1336 /// This may lead to results which are not entirely consistent with
1337 /// such integration rules.
1338 virtual void ComputeElementLpErrors(const real_t p, VectorCoefficient &exsol,
1339 Vector &error,
1340 Coefficient *weight = NULL,
1341 VectorCoefficient *v_weight = NULL,
1342 const IntegrationRule *irs[] = NULL
1343 ) const;
1344
1345 /// @brief Returns ||u_ex - u_h||_L1 elementwise for vector fields
1346 ///
1347 /// Compute the $L^1$ error in each element of the mesh and store the
1348 /// results in the Vector @a error. The result should be of length number of
1349 /// elements, for example an L2 GridFunction of order zero using map type
1350 /// @ref map_type_value "VALUE".
1351 ///
1352 /// Computes:
1353 /// $$\int_{elem} |scalar\_error|$$
1354 ///
1355 /// Where
1356 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1357 ///
1358 /// @param[in] exsol VectorCoefficient object reproducing the
1359 /// anticipated values of the vector field, u_ex.
1360 /// @param[in,out] error Vector to contain the element-wise $L^1$ errors
1361 /// @param[in] irs Optional pointer to an array of custom integration
1362 /// rules e.g. higher order than the default rules. If
1363 /// present the array will be indexed by
1364 /// Geometry::Type.
1365 ///
1366 /// @note If an array of integration rules is provided through @a irs, be
1367 /// sure to include valid rules for each element type that may occur
1368 /// in the list of elements.
1369 ///
1370 /// @note Quadratures with negative weights (as in some simplex integration
1371 /// rules in MFEM) can produce negative integrals even with
1372 /// non-negative integrands. To avoid returning negative errors this
1373 /// function uses the absolute values of the element-wise integrals.
1374 /// This may lead to results which are not entirely consistent with
1375 /// such integration rules.
1376 ///
1377 /// @note Uses ComputeElementLpError internally. See the
1378 /// ComputeElementLpError documentation for generalizations of this
1379 /// error computation.
1381 Vector &error,
1382 const IntegrationRule *irs[] = NULL
1383 ) const
1384 { ComputeElementLpErrors(1.0, exsol, error, NULL, NULL, irs); }
1385
1386 /// @brief Returns ||u_ex - u_h||_L2 elementwise for vector fields
1387 ///
1388 /// Compute the $L^2$ error in each element of the mesh and store the
1389 /// results in the Vector @a error. The result should be of length number of
1390 /// elements, for example an L2 GridFunction of order zero using map type
1391 /// @ref map_type_value "VALUE".
1392 ///
1393 /// Computes:
1394 /// $$(\int_{elem} |scalar\_error|^2)^{1/2}$$
1395 ///
1396 /// Where
1397 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1398 ///
1399 /// @param[in] exsol VectorCoefficient object reproducing the
1400 /// anticipated values of the vector field, u_ex.
1401 /// @param[in,out] error Vector to contain the element-wise $L^2$ errors
1402 /// @param[in] irs Optional pointer to an array of custom integration
1403 /// rules e.g. higher order than the default rules. If
1404 /// present the array will be indexed by
1405 /// Geometry::Type.
1406 ///
1407 /// @note If an array of integration rules is provided through @a irs, be
1408 /// sure to include valid rules for each element type that may occur
1409 /// in the list of elements.
1410 ///
1411 /// @note Quadratures with negative weights (as in some simplex integration
1412 /// rules in MFEM) can produce negative integrals even with
1413 /// non-negative integrands. To avoid returning negative errors this
1414 /// function uses the absolute values of the element-wise integrals.
1415 /// This may lead to results which are not entirely consistent with
1416 /// such integration rules.
1417 ///
1418 /// @note Uses ComputeElementLpError internally. See the
1419 /// ComputeElementLpError documentation for generalizations of this
1420 /// error computation.
1422 Vector &error,
1423 const IntegrationRule *irs[] = NULL
1424 ) const
1425 { ComputeElementLpErrors(2.0, exsol, error, NULL, NULL, irs); }
1426
1427 /// @brief Returns Max|u_ex - u_h| elementwise for vector fields
1428 ///
1429 /// Compute the $L^\infty$ error in each element of the mesh and store the
1430 /// results in the Vector @a error. The result should be of length number of
1431 /// elements, for example an L2 GridFunction of order zero using map type
1432 /// @ref map_type_value "VALUE".
1433 ///
1434 /// Computes:
1435 /// $$max_{elem} |scalar\_error|$$
1436 ///
1437 /// Where
1438 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1439 ///
1440 /// @param[in] exsol VectorCoefficient object reproducing the
1441 /// anticipated values of the vector field, u_ex.
1442 /// @param[in,out] error Vector to contain the element-wise $L^\infty$
1443 /// errors
1444 /// @param[in] irs Optional pointer to an array of custom integration
1445 /// rules e.g. higher order than the default rules. If
1446 /// present the array will be indexed by
1447 /// Geometry::Type.
1448 ///
1449 /// @note If an array of integration rules is provided through @a irs, be
1450 /// sure to include valid rules for each element type that may occur
1451 /// in the list of elements.
1452 ///
1453 /// @note Uses ComputeElementLpError internally. See the
1454 /// ComputeElementLpError documentation for generalizations of this
1455 /// error computation.
1456 ///
1457 /// @note Computes the maximum magnitude of the difference vector not the
1458 /// component-wise maximum difference of the vector fields.
1460 Vector &error,
1461 const IntegrationRule *irs[] = NULL
1462 ) const
1463 { ComputeElementLpErrors(infinity(), exsol, error, NULL, NULL, irs); }
1464
1465 virtual void ComputeFlux(BilinearFormIntegrator &blfi,
1466 GridFunction &flux,
1467 bool wcoef = true, int subdomain = -1);
1468
1469 /// Redefine '=' for GridFunction = constant.
1471
1472 /// Copy the data from @a v.
1473 /** The size of @a v must be equal to the size of the associated
1474 FiniteElementSpace #fes. */
1475 GridFunction &operator=(const Vector &v);
1476
1477 /// Transform by the Space UpdateMatrix (e.g., on Mesh change).
1478 virtual void Update();
1479
1480 /** Return update counter, similar to Mesh::GetSequence(). Used to
1481 check if it is up to date with the space. */
1482 long GetSequence() const { return fes_sequence; }
1483
1485 const FiniteElementSpace *FESpace() const { return fes; }
1486
1487 /// Associate a new FiniteElementSpace with the GridFunction.
1488 /** The GridFunction is resized using the SetSize() method. */
1489 virtual void SetSpace(FiniteElementSpace *f);
1490
1491 using Vector::MakeRef;
1492
1493 /** @brief Make the GridFunction reference external data on a new
1494 FiniteElementSpace. */
1495 /** This method changes the FiniteElementSpace associated with the
1496 GridFunction and sets the pointer @a v as external data in the
1497 GridFunction. */
1498 virtual void MakeRef(FiniteElementSpace *f, real_t *v);
1499
1500 /** @brief Make the GridFunction reference external data on a new
1501 FiniteElementSpace. */
1502 /** This method changes the FiniteElementSpace associated with the
1503 GridFunction and sets the data of the Vector @a v (plus the @a v_offset)
1504 as external data in the GridFunction.
1505 @note This version of the method will also perform bounds checks when
1506 the build option MFEM_DEBUG is enabled. */
1507 virtual void MakeRef(FiniteElementSpace *f, Vector &v, int v_offset);
1508
1509 /** @brief Associate a new FiniteElementSpace and new true-dof data with the
1510 GridFunction. */
1511 /** - If the prolongation matrix of @a f is trivial (i.e. its method
1512 FiniteElementSpace::GetProlongationMatrix() returns NULL), then the
1513 method MakeRef() is called with the same arguments.
1514 - Otherwise, the method SetSpace() is called with argument @a f.
1515 - The internal true-dof vector is set to reference @a tv. */
1516 void MakeTRef(FiniteElementSpace *f, real_t *tv);
1517
1518 /** @brief Associate a new FiniteElementSpace and new true-dof data with the
1519 GridFunction. */
1520 /** - If the prolongation matrix of @a f is trivial (i.e. its method
1521 FiniteElementSpace::GetProlongationMatrix() returns NULL), this method
1522 calls MakeRef() with the same arguments.
1523 - Otherwise, this method calls SetSpace() with argument @a f.
1524 - The internal true-dof vector is set to reference the sub-vector of
1525 @a tv starting at the offset @a tv_offset. */
1526 void MakeTRef(FiniteElementSpace *f, Vector &tv, int tv_offset);
1527
1528 /// Save the GridFunction to an output stream.
1529 virtual void Save(std::ostream &out) const;
1530
1531 /// Save the GridFunction to a file. The given @a precision will be used for
1532 /// ASCII output.
1533 virtual void Save(const char *fname, int precision=16) const;
1534
1535#ifdef MFEM_USE_ADIOS2
1536 /// Save the GridFunction to a binary output stream using adios2 bp format.
1537 virtual void Save(adios2stream &out, const std::string& variable_name,
1540#endif
1541
1542 /** @brief Write the GridFunction in VTK format. Note that Mesh::PrintVTK
1543 must be called first. The parameter ref > 0 must match the one used in
1544 Mesh::PrintVTK. */
1545 void SaveVTK(std::ostream &out, const std::string &field_name, int ref);
1546
1547 /** @brief Write the GridFunction in STL format. Note that the mesh dimension
1548 must be 2 and that quad elements will be broken into two triangles.*/
1549 void SaveSTL(std::ostream &out, int TimesToRefine = 1);
1550
1551 /// Destroys grid function.
1552 virtual ~GridFunction() { Destroy(); }
1553};
1554
1555
1556/** Overload operator<< for std::ostream and GridFunction; valid also for the
1557 derived class ParGridFunction */
1558std::ostream &operator<<(std::ostream &out, const GridFunction &sol);
1559
1560/// Class used to specify how the jump terms in
1561/// GridFunction::ComputeDGFaceJumpError are scaled.
1563{
1564public:
1571private:
1572 real_t nu;
1573 JumpScalingType type;
1574public:
1576 : nu(nu_), type(type_) { }
1577 real_t Eval(real_t h, int p) const
1578 {
1579 real_t val = nu;
1580 if (type != CONSTANT) { val /= h; }
1581 if (type == P_SQUARED_OVER_H) { val *= p*p; }
1582 return val;
1583 }
1584};
1585
1586/// Overload operator<< for std::ostream and QuadratureFunction.
1587std::ostream &operator<<(std::ostream &out, const QuadratureFunction &qf);
1588
1589
1591 GridFunction &u,
1592 GridFunction &flux,
1593 Vector &error_estimates,
1594 Array<int> *aniso_flags = NULL,
1595 int with_subdomains = 1,
1596 bool with_coeff = false);
1597
1598/// Defines the global tensor product polynomial space used by NewZZErorrEstimator
1599/**
1600 * See BoundingBox(...) for a description of @a angle and @a midpoint
1601 */
1602void TensorProductLegendre(int dim, // input
1603 int order, // input
1604 const Vector &x_in, // input
1605 const Vector &xmax, // input
1606 const Vector &xmin, // input
1607 Vector &poly, // output
1608 real_t angle=0.0, // input (optional)
1609 const Vector *midpoint=NULL); // input (optional)
1610
1611/// Defines the bounding box for the face patches used by NewZZErorrEstimator
1612/**
1613 * By default, BoundingBox(...) computes the parameters of a minimal bounding box
1614 * for the given @a face_patch that is aligned with the physical (i.e. global)
1615 * Cartesian axes. This means that the size of the bounding box will depend on the
1616 * orientation of the patch. It is better to construct an orientation-independent box.
1617 * This is implemented for 2D patches. The parameters @a angle and @a midpoint encode
1618 * the necessary additional geometric information.
1619 *
1620 * @a iface : Index of the face that the patch corresponds to.
1621 * This is used to compute @a angle and @a midpoint.
1622 *
1623 * @a angle : The angle the patch face makes with the x-axis.
1624 * @a midpoint : The midpoint of the face.
1625 */
1626void BoundingBox(const Array<int> &face_patch, // input
1627 FiniteElementSpace *ufes, // input
1628 int order, // input
1629 Vector &xmin, // output
1630 Vector &xmax, // output
1631 real_t &angle, // output
1632 Vector &midpoint, // output
1633 int iface=-1); // input (optional)
1634
1635/// A ``true'' ZZ error estimator that uses face-based patches for flux reconstruction.
1636/**
1637 * Only two-element face patches are ever used:
1638 * - For conforming faces, the face patch consists of its two neighboring elements.
1639 * - In the non-conforming setting, only the face patches associated to fine-scale
1640 * element faces are used. These face patches always consist of two elements
1641 * delivered by mesh::GetFaceElements(Face, *Elem1, *Elem2).
1642 */
1644 GridFunction &u, // input
1645 Vector &error_estimates, // output
1646 bool subdomain_reconstruction = true, // input (optional)
1647 bool with_coeff = false, // input (optional)
1648 real_t tichonov_coeff = 0.0); // input (optional)
1649
1650/// Compute the Lp distance between two grid functions on the given element.
1652 GridFunction& gf1, GridFunction& gf2);
1653
1654
1655/// Class used for extruding scalar GridFunctions
1657{
1658private:
1659 int n;
1660 Mesh *mesh_in;
1661 Coefficient &sol_in;
1662public:
1664 : n(n_), mesh_in(m), sol_in(s) { }
1665 real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override;
1667};
1668
1669/// Extrude a scalar 1D GridFunction, after extruding the mesh with Extrude1D.
1670GridFunction *Extrude1DGridFunction(Mesh *mesh, Mesh *mesh2d,
1671 GridFunction *sol, const int ny);
1672
1673} // namespace mfem
1674
1675#endif
Abstract base class BilinearFormIntegrator.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
Delta function coefficient optionally multiplied by a weight coefficient and a scaled time dependent ...
Data type dense matrix using column-major storage.
Definition densemat.hpp:24
Class used for extruding scalar GridFunctions.
ExtrudeCoefficient(Mesh *m, Coefficient &s, int n_)
real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the coefficient in the element described by T at the point ip.
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Definition fe_coll.hpp:27
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:244
ElementTransformation * GetElementTransformation(int i) const
Returns ElementTransformation for the i-th element.
Definition fespace.hpp:924
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:31
GridFunction(const GridFunction &orig)
Copy constructor. The internal true-dof vector t_vec is not copied.
Definition gridfunc.hpp:78
void ComputeMeans(AvgType type, Array< int > &zones_per_vdof)
void GetLaplacians(int i, const IntegrationRule &ir, Vector &laps, int vdim=1) const
Definition gridfunc.cpp:566
void AccumulateAndCountBdrTangentValues(VectorCoefficient &vcoeff, const Array< int > &bdr_attr, Array< int > &values_counter)
GridFunction(FiniteElementSpace *f, real_t *data)
Construct a GridFunction using previously allocated array data.
Definition gridfunc.hpp:92
virtual real_t ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
Returns ||u_ex - u_h||_L2 for H1 or L2 elements.
Definition gridfunc.hpp:588
void ProjectVectorFieldOn(GridFunction &vec_field, int comp=0)
virtual void CountElementsPerVDof(Array< int > &elem_per_vdof) const
For each vdof, counts how many elements contain the vdof, as containment is determined by FiniteEleme...
virtual real_t GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Definition gridfunc.cpp:446
virtual void ComputeElementL1Errors(Coefficient &exsol, Vector &error, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L1 elementwise for H1 or L2 elements.
void SaveVTK(std::ostream &out, const std::string &field_name, int ref)
Write the GridFunction in VTK format. Note that Mesh::PrintVTK must be called first....
virtual real_t ComputeDGFaceJumpError(Coefficient *exsol, Coefficient *ell_coeff, class JumpScaling jump_scaling, const IntegrationRule *irs[]=NULL) const
Returns the Face Jumps error for L2 elements.
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
Definition gridfunc.cpp:518
virtual real_t ComputeHCurlError(VectorCoefficient *exsol, VectorCoefficient *excurl, const IntegrationRule *irs[]=NULL) const
Returns the error measured in H(curl)-norm for ND elements.
void UpdatePRef()
P-refinement version of Update().
Definition gridfunc.cpp:205
virtual real_t ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad, Coefficient *ell_coef, real_t Nu, int norm_type) const
void GetGradients(ElementTransformation &tr, const IntegrationRule &ir, DenseMatrix &grad) const
Extension of GetGradient(...) for a collection of IntegrationPoints.
virtual ~GridFunction()
Destroys grid function.
void AccumulateAndCountBdrValues(Coefficient *coeff[], VectorCoefficient *vcoeff, const Array< int > &attr, Array< int > &values_counter)
void GetDerivative(int comp, int der_comp, GridFunction &der) const
Compute a certain derivative of a function's component. Derivatives of the function are computed at t...
virtual void ComputeElementL2Errors(Coefficient &exsol, Vector &error, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L2 elementwise for H1 or L2 elements.
void GetVectorGradient(ElementTransformation &tr, DenseMatrix &grad) const
Compute the vector gradient with respect to the physical element variable.
virtual real_t ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Returns Max|u_ex - u_h| error for H1 or L2 elements.
Definition gridfunc.hpp:869
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
Definition gridfunc.cpp:167
FiniteElementCollection * OwnFEC()
Definition gridfunc.hpp:124
virtual void MakeRef(FiniteElementSpace *f, real_t *v)
Make the GridFunction reference external data on a new FiniteElementSpace.
Definition gridfunc.cpp:233
void ImposeBounds(int i, const Vector &weights, const Vector &lo_, const Vector &hi_)
void SetTrueVector()
Shortcut for calling GetTrueDofs() with GetTrueVector() as argument.
Definition gridfunc.hpp:147
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
virtual real_t ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
Returns ||exsol - u_h||_L2 for scalar or vector H1 or L2 elements.
void MakeTRef(FiniteElementSpace *f, real_t *tv)
Associate a new FiniteElementSpace and new true-dof data with the GridFunction.
Definition gridfunc.cpp:251
virtual real_t ComputeL1Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L1 for H1 or L2 elements.
Definition gridfunc.hpp:962
void SetFromTrueVector()
Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
Definition gridfunc.hpp:153
GridFunction(FiniteElementSpace *f, Vector &base, int base_offset=0)
Construct a GridFunction using previously allocated Vector base starting at the given offset,...
Definition gridfunc.hpp:98
void GetVectorFieldValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr, int comp=0) const
virtual real_t ComputeL1Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L1 for vector fields.
virtual void ProjectBdrCoefficientTangent(VectorCoefficient &vcoeff, const Array< int > &bdr_attr)
Project the tangential components of the given VectorCoefficient on the boundary. Only boundary attri...
const Vector & GetTrueVector() const
Read only access to the (optional) internal true-dof Vector.
Definition gridfunc.hpp:133
void GetElementAverages(GridFunction &avgs) const
virtual real_t ComputeElementGradError(int ielem, VectorCoefficient *exgrad, const IntegrationRule *irs[]=NULL) const
Returns ||grad u_ex - grad u_h||_L2 in element ielem for H1 or L2 elements.
void MakeOwner(FiniteElementCollection *fec_)
Make the GridFunction the owner of fec_owned and fes.
Definition gridfunc.hpp:122
Vector & GetTrueVector()
Read and write access to the (optional) internal true-dof Vector.
Definition gridfunc.hpp:140
void SaveSTL(std::ostream &out, int TimesToRefine=1)
Write the GridFunction in STL format. Note that the mesh dimension must be 2 and that quad elements w...
const FiniteElementSpace * FESpace() const
virtual void ComputeElementLpErrors(const real_t p, Coefficient &exsol, Vector &error, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_Lp elementwise for H1 or L2 elements.
virtual void SetFromTrueDofs(const Vector &tv)
Set the GridFunction from the given true-dof vector.
Definition gridfunc.cpp:378
virtual void GetElementDofValues(int el, Vector &dof_vals) const
virtual real_t ComputeLpError(const real_t p, Coefficient &exsol, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
Returns ||u_ex - u_h||_Lp for H1 or L2 elements.
FiniteElementSpace * FESpace()
GridFunction(FiniteElementSpace *f)
Construct a GridFunction associated with the FiniteElementSpace *f.
Definition gridfunc.hpp:83
void GetGradients(const int elem, const IntegrationRule &ir, DenseMatrix &grad) const
Extension of GetGradient(...) for a collection of IntegrationPoints.
Definition gridfunc.hpp:349
void SaveSTLTri(std::ostream &out, real_t p1[], real_t p2[], real_t p3[])
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
virtual void ComputeElementMaxErrors(VectorCoefficient &exsol, Vector &error, const IntegrationRule *irs[]=NULL) const
Returns Max|u_ex - u_h| elementwise for vector fields.
int GetFaceVectorValues(int i, int side, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
virtual void ComputeElementL2Errors(VectorCoefficient &exsol, Vector &error, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L2 elementwise for vector fields.
virtual void ComputeElementL1Errors(VectorCoefficient &exsol, Vector &error, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L1 elementwise for vector fields.
void GetValuesFrom(const GridFunction &orig_func)
void LegacyNCReorder()
Loading helper.
void ProjectDeltaCoefficient(DeltaCoefficient &delta_coeff, real_t &integral)
void ProjectDiscCoefficient(VectorCoefficient &coeff, Array< int > &dof_attr)
virtual void ComputeFlux(BilinearFormIntegrator &blfi, GridFunction &flux, bool wcoef=true, int subdomain=-1)
Definition gridfunc.cpp:338
FiniteElementSpace * fes
FE space on which the grid function lives. Owned if fec_owned is not NULL.
Definition gridfunc.hpp:34
virtual real_t ComputeCurlError(VectorCoefficient *excurl, const IntegrationRule *irs[]=NULL) const
Returns ||curl u_ex - curl u_h||_L2 for ND elements.
void GetBdrValuesFrom(const GridFunction &orig_func)
virtual real_t ComputeHDivError(VectorCoefficient *exsol, Coefficient *exdiv, const IntegrationRule *irs[]=NULL) const
Returns the error measured in H(div)-norm for RT elements.
int VectorDim() const
Shortcut for calling FiniteElementSpace::GetVectorDim() on the underlying fes.
Definition gridfunc.cpp:353
long GetSequence() const
virtual real_t ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad, int norm_type, const Array< int > *elems=NULL, const IntegrationRule *irs[]=NULL) const
Returns norm (or portions thereof) for H1 or L2 elements.
std::unique_ptr< GridFunction > ProlongateToMaxOrder() const
Return a GridFunction with the values of this, prolongated to the maximum order of all elements in th...
int GetFaceValues(int i, int side, const IntegrationRule &ir, Vector &vals, DenseMatrix &tr, int vdim=1) const
Definition gridfunc.cpp:661
FiniteElementCollection * fec_owned
Used when the grid function is read from a file. It can also be set explicitly, see MakeOwner().
Definition gridfunc.hpp:40
int CurlDim() const
Shortcut for calling FiniteElementSpace::GetCurlDim() on the underlying fes.
Definition gridfunc.cpp:358
virtual real_t ComputeMaxError(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Returns Max|u_ex - u_h| error for vector fields.
Definition gridfunc.hpp:931
void SumFluxAndCount(BilinearFormIntegrator &blfi, GridFunction &flux, Array< int > &counts, bool wcoef, int subdomain)
Definition gridfunc.cpp:281
GridFunction & operator=(const GridFunction &rhs)
Copy assignment. Only the data of the base class Vector is copied.
Definition gridfunc.hpp:116
virtual real_t ComputeDivError(Coefficient *exdiv, const IntegrationRule *irs[]=NULL) const
Returns ||div u_ex - div u_h||_L2 for RT elements.
virtual void ComputeElementMaxErrors(Coefficient &exsol, Vector &error, const IntegrationRule *irs[]=NULL) const
Returns Max|u_ex - u_h| elementwise for H1 or L2 elements.
void GetTrueDofs(Vector &tv) const
Extract the true-dofs from the GridFunction.
Definition gridfunc.cpp:363
void AccumulateAndCountDerivativeValues(int comp, int der_comp, GridFunction &der, Array< int > &zones_per_dof) const
Used for the serial and parallel implementations of the GetDerivative() method; see its documentation...
virtual real_t ComputeGradError(VectorCoefficient *exgrad, const IntegrationRule *irs[]=NULL) const
Returns ||grad u_ex - grad u_h||_L2 for H1 or L2 elements.
void GetNodalValues(int i, Array< real_t > &nval, int vdim=1) const
Returns the values in the vertices of i'th element for dimension vdim.
Definition gridfunc.cpp:392
virtual void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Definition gridfunc.cpp:473
virtual MFEM_DEPRECATED real_t ComputeL1Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L1 for H1 or L2 elements.
real_t GetDivergence(ElementTransformation &tr) const
void AccumulateAndCountZones(Coefficient &coeff, AvgType type, Array< int > &zones_per_vdof)
Accumulates (depending on type) the values of coeff at all shared vdofs and counts in how many zones ...
void ProjectBdrCoefficientNormal(VectorCoefficient &vcoeff, const Array< int > &bdr_attr)
void GetCurl(ElementTransformation &tr, Vector &curl) const
void GetGradient(ElementTransformation &tr, Vector &grad) const
Gradient of a scalar function at a quadrature point.
void GetVectorGradientHat(ElementTransformation &T, DenseMatrix &gh) const
Compute the vector gradient with respect to the reference element variable.
virtual void SetSpace(FiniteElementSpace *f)
Associate a new FiniteElementSpace with the GridFunction.
Definition gridfunc.cpp:225
void GetHessians(int i, const IntegrationRule &ir, DenseMatrix &hess, int vdim=1) const
Definition gridfunc.cpp:605
void GetVectorValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
Definition gridfunc.cpp:711
void ProjectGridFunction(const GridFunction &src)
Project the src GridFunction to this GridFunction, both of which must be on the same mesh.
void GetVectorFieldNodalValues(Vector &val, int comp) const
void ProjectBdrCoefficient(Coefficient &coeff, const Array< int > &attr)
Project a Coefficient on the GridFunction, modifying only DOFs on the boundary associated with the bo...
Definition gridfunc.hpp:481
void ReorderByNodes()
For a vector grid function, makes sure that the ordering is byNODES.
Class for integration point with weight.
Definition intrules.hpp:35
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:100
JumpScaling(real_t nu_=1.0, JumpScalingType type_=CONSTANT)
real_t Eval(real_t h, int p) const
Mesh data type.
Definition mesh.hpp:64
Represents values or vectors of values at quadrature points on a mesh.
Definition qfunction.hpp:24
Base class for vector Coefficients that optionally depend on time and space.
Vector data type.
Definition vector.hpp:82
Memory< real_t > data
Definition vector.hpp:85
virtual bool UseDevice() const
Return the device flag of the Memory object used by the Vector.
Definition vector.hpp:147
int Size() const
Returns the size of the vector.
Definition vector.hpp:226
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
Definition vector.hpp:622
int dim
Definition ex24.cpp:53
std::ostream & operator<<(std::ostream &os, SparseMatrix const &mat)
void TensorProductLegendre(int dim, int order, const Vector &x_in, const Vector &xmax, const Vector &xmin, Vector &poly, real_t angle, const Vector *midpoint)
Defines the global tensor product polynomial space used by NewZZErorrEstimator.
real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
Definition vector.hpp:47
GridFunction * Extrude1DGridFunction(Mesh *mesh, Mesh *mesh2d, GridFunction *sol, const int ny)
Extrude a scalar 1D GridFunction, after extruding the mesh with Extrude1D.
real_t u(const Vector &xvec)
Definition lor_mms.hpp:22
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition globals.hpp:66
real_t ZZErrorEstimator(BilinearFormIntegrator &blfi, GridFunction &u, GridFunction &flux, Vector &error_estimates, Array< int > *aniso_flags, int with_subdomains, bool with_coeff)
real_t LSZZErrorEstimator(BilinearFormIntegrator &blfi, GridFunction &u, Vector &error_estimates, bool subdomain_reconstruction, bool with_coeff, real_t tichonov_coeff)
A `‘true’' ZZ error estimator that uses face-based patches for flux reconstruction.
void BoundingBox(const Array< int > &patch, FiniteElementSpace *ufes, int order, Vector &xmin, Vector &xmax, real_t &angle, Vector &midpoint, int iface)
Defines the bounding box for the face patches used by NewZZErorrEstimator.
real_t ComputeElementLpDistance(real_t p, int i, GridFunction &gf1, GridFunction &gf2)
Compute the Lp distance between two grid functions on the given element.
float real_t
Definition config.hpp:43
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
real_t p(const Vector &x, real_t t)