MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
gridfunc.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, 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#include "bounds.hpp"
20#ifdef MFEM_USE_ADIOS2
22#endif
23#include <limits>
24#include <ostream>
25#include <string>
26#include <variant>
27
28namespace mfem
29{
30
31/** @brief This enumerated type describes the main projection types used by
32 GridFunction::ProjectCoefficient():
33 - ELEMENT: assigns the degrees of freedom element by element, using the
34 nodal interpolation defined by the specific FiniteElement,
35 - GLOBAL_L2: solves a global L2 projection,
36 - ELEMENT_L2: solves element-local L2 projections, with inter-element
37 connectivity treated similarly to Bezier projection, see "Bezier
38 projection: A unified approach for local projection and quadrature-free
39 refinement and coarsening of NURBS and T-splines with particular
40 application to isogeometric design and analysis", CMAME 284 (2015),
41 pp. 55-105,
42 - DEFAULT: for NURBS spaces this is ELEMENT_L2, while for all other spaces
43 it is ELEMENT.
44
45 @note ELEMENT_L2 also works for non-NURBS elements.
46 @note For NURBS elements, the ELEMENT projection gives results without
47 overshoots and undershoots; however, the gradient near the boundary does
48 not converge. */
50
51/// Class for grid function - Vector with associated FE space.
52class GridFunction : public Vector
53{
54protected:
55 /// FE space on which the grid function lives. Owned if #fec_owned is not NULL.
57
58 /** @brief Used when the grid function is read from a file. It can also be
59 set explicitly, see MakeOwner().
60
61 If not NULL, this pointer is owned by the GridFunction. */
63
64 long fes_sequence; // see FiniteElementSpace::sequence, Mesh::sequence
65
66 /** Optional, internal true-dof vector: if the FiniteElementSpace #fes has a
67 non-trivial (i.e. not NULL) prolongation operator, this Vector may hold
68 associated true-dof values - either owned or external. */
70
71 void SaveSTLTri(std::ostream &out, real_t p1[], real_t p2[], real_t p3[]);
72
73 // Project the delta coefficient without scaling and return the (local)
74 // integral of the projection.
76 real_t &integral);
77
78 // Sum fluxes to vertices and count element contributions
80 GridFunction &flux,
81 Array<int>& counts,
82 bool wcoef,
83 int subdomain);
84
85 /** @brief Project a discontinuous (vector) coefficient as a grid function on
86 a continuous finite element space. Return in dof_attr the maximal
87 attribute of the elements containing each degree of freedom. */
88 virtual void ProjectDiscCoefficient(
89 std::variant<Coefficient*, VectorCoefficient*> coeff, Array<int> &dof_attr);
90
91 /** @brief Project a discontinuous (vector) coefficient as a grid function on
92 a continuous finite element space. The values in shared dofs are
93 determined from the element with maximal attribute. */
95 std::variant<Coefficient*, VectorCoefficient*> coeff)
96 { Array<int> dof_attr; ProjectDiscCoefficient(coeff, dof_attr); };
97
98 /** Helper function for ProjectCoefficientElementL2 */
101 Vector &Va);
102
103 /// Loading helper.
104 void LegacyNCReorder();
105
106 void Destroy();
107
108public:
109 GridFunction() { fes = NULL; fec_owned = NULL; fes_sequence = 0; UseDevice(true); }
110
111 /// Copy constructor. The internal true-dof vector #t_vec is not copied.
113 : Vector(orig), fes(orig.fes), fec_owned(NULL), fes_sequence(orig.fes_sequence)
114 { UseDevice(true); }
115
116 /// Construct a GridFunction associated with the FiniteElementSpace @a *f.
118 { fes = f; fec_owned = NULL; fes_sequence = f->GetSequence(); UseDevice(true); }
119
120 /// Same as above but specify the memory type
122 { fes = f; fec_owned = NULL; fes_sequence = f->GetSequence(); UseDevice(true); }
123
124 /// Construct a GridFunction using previously allocated array @a data.
125 /** The GridFunction does not assume ownership of @a data which is assumed to
126 be of size at least `f->GetVSize()`. Similar to the Vector constructor
127 for externally allocated array, the pointer @a data can be NULL. The data
128 array can be replaced later using the method SetData().
129 */
131 : Vector(data, f->GetVSize())
132 { fes = f; fec_owned = NULL; fes_sequence = f->GetSequence(); UseDevice(true); }
133
134 /** @brief Construct a GridFunction using previously allocated Vector @a base
135 starting at the given offset, @a base_offset. */
136 GridFunction(FiniteElementSpace *f, Vector &base, int base_offset = 0)
137 : Vector(base, base_offset, f->GetVSize())
138 { fes = f; fec_owned = NULL; fes_sequence = f->GetSequence(); UseDevice(true); }
139
140 /// Construct a GridFunction on the given Mesh, using the data from @a input.
141 /** The content of @a input should be in the format created by the method
142 Save(). The reconstructed FiniteElementSpace and FiniteElementCollection
143 are owned by the GridFunction. */
144 GridFunction(Mesh *m, std::istream &input);
145
146 GridFunction(Mesh *m, GridFunction *gf_array[], int num_pieces);
147
148 /// Copy assignment. Only the data of the base class Vector is copied.
149 /** It is assumed that this object and @a rhs use FiniteElementSpace%s that
150 have the same size.
151
152 @note Defining this method overwrites the implicitly defined copy
153 assignment operator. */
155 { return operator=((const Vector &)rhs); }
156
157 /// Make the GridFunction the owner of #fec_owned and #fes.
158 /** If the new FiniteElementCollection, @a fec_, is NULL, ownership of #fec_owned
159 and #fes is taken away. */
161
163
164 /** @brief Shortcut for calling FiniteElementSpace::GetVectorDim() on the
165 underlying #fes */
166 int VectorDim() const { return fes->GetVectorDim(); }
167
168 /** @brief Shortcut for calling FiniteElementSpace::GetCurlDim() on the
169 underlying #fes */
170 int CurlDim() const { return fes->GetCurlDim(); }
171
172 /// Read only access to the (optional) internal true-dof Vector.
173 const Vector &GetTrueVector() const
174 {
175 MFEM_VERIFY(t_vec.Size() > 0, "SetTrueVector() before GetTrueVector()");
176 return t_vec;
177 }
178 /// Read and write access to the (optional) internal true-dof Vector.
179 /** Note that @a t_vec is set if it is not allocated or set already.*/
181 { if (t_vec.Size() == 0) { SetTrueVector(); } return t_vec; }
182
183 /// Extract the true-dofs from the GridFunction.
184 void GetTrueDofs(Vector &tv) const;
185
186 /// Shortcut for calling GetTrueDofs() with GetTrueVector() as argument.
188
189 /// Set the GridFunction from the given true-dof vector.
190 virtual void SetFromTrueDofs(const Vector &tv);
191
192 /// Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
194
195 /** @brief Returns the values at the vertices of element @a i for the 1-based
196 dimension vdim. */
197 void GetNodalValues(int i, Array<real_t> &nval, int vdim = 1) const;
198
199 /** @name Element index Get Value Methods
200
201 These methods take an element index and return the interpolated value of
202 the field at a given reference point within the element.
203
204 @warning These methods retrieve and use the ElementTransformation object
205 from the mfem::Mesh. This can alter the state of the element
206 transformation object and can also lead to unexpected results when the
207 ElementTransformation object is already in use such as when these methods
208 are called from within an integration loop. Consider using
209 GetValue(ElementTransformation &T, ...) instead.
210 */
211 ///@{
212 /** Return a scalar value from within the given element. */
213 virtual real_t GetValue(int i, const IntegrationPoint &ip,
214 int vdim = 1) const;
215
216 /** Return a vector value from within the given element. */
217 virtual void GetVectorValue(int i, const IntegrationPoint &ip,
218 Vector &val) const;
219 ///@}
220
221 /** @name Element Index Get Values Methods
222
223 These are convenience methods for repeatedly calling GetValue for
224 multiple points within a given element. The GetValues methods are
225 optimized and should perform better than repeatedly calling GetValue. The
226 GetVectorValues method simply calls GetVectorValue repeatedly.
227
228 @warning These methods retrieve and use the ElementTransformation object
229 from the mfem::Mesh. This can alter the state of the element
230 transformation object and can also lead to unexpected results when the
231 ElementTransformation object is already in use such as when these methods
232 are called from within an integration loop. Consider using
233 GetValues(ElementTransformation &T, ...) instead.
234 */
235 ///@{
236 /** Compute a collection of scalar values from within the element indicated
237 by the index i. */
238 void GetValues(int i, const IntegrationRule &ir, Vector &vals,
239 int vdim = 1) const;
240
241 /** Compute a collection of vector values from within the element indicated
242 by the index i. */
243 void GetValues(int i, const IntegrationRule &ir, Vector &vals,
244 DenseMatrix &tr, int vdim = 1) const;
245
246 void GetVectorValues(int i, const IntegrationRule &ir,
247 DenseMatrix &vals, DenseMatrix &tr) const;
248 ///@}
249
250 /** @name ElementTransformation Get Value Methods
251
252 These member functions are designed for use within
253 GridFunctionCoefficient objects. These can be used with
254 ElementTransformation objects coming from either
255 Mesh::GetElementTransformation() or Mesh::GetBdrElementTransformation().
256
257 @note These methods do not reset the ElementTransformation object so they
258 should be safe to use within integration loops or other contexts where
259 the ElementTransformation is already in use.
260 */
261 ///@{
262 /** Return a scalar value from within the element indicated by the
263 ElementTransformation Object. */
265 int comp = 0, Vector *tr = NULL) const;
266
267 /** Return a vector value from within the element indicated by the
268 ElementTransformation Object. */
270 const IntegrationPoint &ip,
271 Vector &val, Vector *tr = NULL) const;
272 ///@}
273
274 /** @name ElementTransformation Get Values Methods
275
276 These are convenience methods for repeatedly calling GetValue for
277 multiple points within a given element. They work by calling either the
278 ElementTransformation or FaceElementTransformations versions described
279 above. Consequently, these methods should not be expected to run faster
280 than calling the above methods in an external loop.
281
282 @note These methods do not reset the ElementTransformation object so they
283 should be safe to use within integration loops or other contexts where
284 the ElementTransformation is already in use.
285
286 @note These methods can also be used with FaceElementTransformations
287 objects.
288 */
289 ///@{
290 /** Compute a collection of scalar values from within the element indicated
291 by the ElementTransformation object. */
293 Vector &vals, int comp = 0, DenseMatrix *tr = NULL) const;
294
295 /** Compute a collection of vector values from within the element indicated
296 by the ElementTransformation object. */
298 DenseMatrix &vals, DenseMatrix *tr = NULL) const;
299 ///@}
300
301 /** @name Face Index Get Values Methods
302
303 These methods are designed to work with Discontinuous Galerkin basis
304 functions. They compute field values on the interface between elements,
305 or on boundary elements, by interpolating the field in a neighboring
306 element. The \a side argument indices which neighboring element should be
307 used: 0, 1, or 2 (automatically chosen).
308
309 @warning These methods retrieve and use the FaceElementTransformations
310 object from the mfem::Mesh. This can alter the state of the face element
311 transformations object and can also lead to unexpected results when the
312 FaceElementTransformations object is already in use such as when these
313 methods are called from within an integration loop. Consider using
314 GetValues(ElementTransformation &T, ...) instead.
315 */
316 ///@{
317 /** Compute a collection of scalar values from within the face
318 indicated by the index i. */
319 int GetFaceValues(int i, int side, const IntegrationRule &ir, Vector &vals,
320 DenseMatrix &tr, int vdim = 1) const;
321
322 /** Compute a collection of vector values from within the face
323 indicated by the index i. */
324 int GetFaceVectorValues(int i, int side, const IntegrationRule &ir,
325 DenseMatrix &vals, DenseMatrix &tr) const;
326 ///@}
327
328 void GetLaplacians(int i, const IntegrationRule &ir, Vector &laps,
329 int vdim = 1) const;
330
331 void GetLaplacians(int i, const IntegrationRule &ir, Vector &laps,
332 DenseMatrix &tr, int vdim = 1) const;
333
334 void GetHessians(int i, const IntegrationRule &ir, DenseMatrix &hess,
335 int vdim = 1) const;
336
337 void GetHessians(int i, const IntegrationRule &ir, DenseMatrix &hess,
338 DenseMatrix &tr, int vdim = 1) const;
339
340 void GetValuesFrom(const GridFunction &orig_func);
341
342 void GetBdrValuesFrom(const GridFunction &orig_func);
343
344 void GetVectorFieldValues(int i, const IntegrationRule &ir,
345 DenseMatrix &vals,
346 DenseMatrix &tr, int comp = 0) const;
347
348 /// For a vector grid function, makes sure that the ordering is byNODES.
349 void ReorderByNodes();
350
351 /** @brief Returns the values as a vector at mesh vertices, for the 1-based
352 dimension vdim. */
353 void GetNodalValues(Vector &nval, int vdim = 1) const;
354
355 void GetVectorFieldNodalValues(Vector &val, int comp) const;
356
357 void ProjectVectorFieldOn(GridFunction &vec_field, int comp = 0);
358
359 /** @brief Compute a certain derivative of a function's component.
360 Derivatives of the function are computed at the DOF locations of @a der,
361 and averaged over overlapping DOFs. Thus this function projects the
362 derivative to the FiniteElementSpace of @a der.
363 @param[in] comp Index of the function's component to be differentiated.
364 The index is 1-based, i.e., use 1 for scalar functions.
365 @param[in] der_comp Use 0/1/2 for derivatives in x/y/z directions.
366 @param[out] der The resulting derivative (scalar function). The
367 FiniteElementSpace of this function must be set
368 before the call. */
369 void GetDerivative(int comp, int der_comp, GridFunction &der) const;
370
372
373 void GetCurl(ElementTransformation &tr, Vector &curl) const;
374
375 /** @brief Gradient of a scalar function at a quadrature point.
376
377 @note It is assumed that the IntegrationPoint of interest has been
378 specified by ElementTransformation::SetIntPoint() before calling
379 GetGradient().
380
381 @note Can be used from a ParGridFunction when @a tr is an
382 ElementTransformation of a face-neighbor element and face-neighbor data
383 has been exchanged. */
384 void GetGradient(ElementTransformation &tr, Vector &grad) const;
385
386 /// Extension of GetGradient(...) for a collection of IntegrationPoints.
388 DenseMatrix &grad) const;
389
390 /// Extension of GetGradient(...) for a collection of IntegrationPoints.
391 void GetGradients(const int elem, const IntegrationRule &ir,
392 DenseMatrix &grad) const
393 { GetGradients(*fes->GetElementTransformation(elem), ir, grad); }
394
395 /** @brief Compute the vector gradient with respect to the physical element
396 variable. */
398
399 /** @brief Compute the vector gradient with respect to the reference element
400 variable. */
402
403 /** @brief Evaluate the gradients of the GridFunction at the given quadrature
404 points, @a ir, in all mesh elements. */
405 /** This method assumes that all mesh elements are the same type and that the
406 IntegrationRule @a ir is consistent with that type of element.
407
408 @param[in] ir Quadrature points at which the gradients are to be
409 evaluated.
410 @param[out] grad Output vector of size `SDIM*VDIM*NQ*NE` where `SDIM` is
411 the spatial dimension of the mesh, `VDIM` is the vector
412 dimension of the GridFunction, `NQ` is the number of
413 quadrature points in @a ir, and `NE` is the number of
414 elements in the mesh. The layout of @a grad is
415 determined by the parameter @a ql: when @a ql is
416 QVectorLayout::byNODES, the layout is
417 `NQ x VDIM x SDIM x NE`; when @a ql is
418 QVectorLayout::byVDIM, the layout is
419 `VDIM x SDIM x NQ x NE`.
420 @param[in] ql Determines the layout of the output vector @a grad; see
421 the description of @a grad for details.
422 @param[in] d_mt MemoryType to use for allocating the output vector
423 @a grad, as well the GeometricFactors and temporary
424 vector used by the method. By default, the current
425 device memory type is used. */
426 void GetGradients(const IntegrationRule &ir, Vector &grad,
428 MemoryType d_mt = MemoryType::DEFAULT) const;
429
430 /** Compute $ (\int_{\Omega} (*this) \psi_i)/(\int_{\Omega} \psi_i) $,
431 where $ \psi_i $ are the basis functions for the FE space of avgs.
432 Both FE spaces should be scalar and on the same mesh. */
433 void GetElementAverages(GridFunction &avgs) const;
434
435 /** Sets the output vector @a dof_vals to the values of the degrees of
436 freedom of element @a el. */
437 virtual void GetElementDofValues(int el, Vector &dof_vals) const;
438
439 /** Impose the given bounds on the function's DOFs while preserving its local
440 * integral (described in terms of the given weights) on the i'th element
441 * through SLBPQ optimization.
442 * Intended to be used for discontinuous FE functions. */
443 void ImposeBounds(int i, const Vector &weights,
444 const Vector &lo_, const Vector &hi_);
445 void ImposeBounds(int i, const Vector &weights,
446 real_t min_ = 0.0, real_t max_ = infinity());
447
448 /** On a non-conforming mesh, make sure the function lies in the conforming
449 space by multiplying with R and then with P, the conforming restriction
450 and prolongation matrices of the space, respectively. */
451 void RestrictConforming();
452
453 /** @brief Project the @a src GridFunction to @a this GridFunction, both of
454 which must be on the same mesh. */
455 /** The current implementation assumes that all elements use the same
456 projection matrix. */
457 void ProjectGridFunction(const GridFunction &src);
458
459 /** @brief Project @a coeff Coefficient to @a this GridFunction. The
460 projection computation depends on the choice of the FiniteElementSpace
461 #fes. Note that this is usually interpolation at the degrees of freedom
462 in each element (not L2 projection). For elements without a projection
463 member function one could use ProjectCoefficientGlobalL2 instead.
464 @note For parallel simulations with NURBS elements some dofs might
465 not be defined, if the evaluation point does not reside on this rank.
466 If that is the case it is defined on another rank, and the issue is
467 rectified with the appropriate communication, see in ParGridFunction.
468 */
469 virtual void ProjectCoefficient(Coefficient &coeff,
471
472 /** @brief Project @a coeff Coefficient to @a this GridFunction. The
473 projection is a global L2 projection. This routine can be used as a
474 fallback for elements without a projection member function.*/
475 virtual void ProjectCoefficientGlobalL2(Coefficient &coeff,
476 real_t rtol = 1e-12,
477 int iter = 1000);
478
479 /** @brief Project @a coeff Coefficient to @a this GridFunction. The
480 projection is an element local L2 projection, with an appropriate
481 weighting for Dofs that are shared between elements. Inspired by
482 Bezier-Projection [CMAME (284) 2015 pg 55-105].
483 This routine can be used as a fallback for elements without a projection
484 member function.*/
485 virtual void ProjectCoefficientElementL2(Coefficient &coeff);
486
487 /** @brief Project @a coeff Coefficient to @a this GridFunction, using one
488 element for each degree of freedom in @a dofs and nodal interpolation on
489 that element. */
490 void ProjectCoefficient(Coefficient &coeff, Array<int> &dofs, int vd = 0);
491
492 /** @brief Project @a vcoeff VectorCoefficient to @a this GridFunction. The
493 projection computation depends on the choice of the FiniteElementSpace
494 #fes. Note that this is usually interpolation at the degrees of freedom
495 in each element (not L2 projection). For elements without a projection
496 member function one could use ProjectCoefficientGlobalL2 instead.
497 @note For parallel simulations with NURBS elements some dofs might
498 not be defined, if the evaluation point does not reside on this rank.
499 If that is the case it is defined on another rank, and the issue is
500 rectified with the appropriate communication, see in ParGridFunction.*/
501 virtual void ProjectCoefficient(VectorCoefficient &vcoeff,
503
504 /** @brief Project @a vcoeff VectorCoefficient to @a this GridFunction. The
505 projection is a global L2 projection. This routine can be used as a
506 fallback for elements without a projection member function.*/
508 real_t rtol = 1e-12,
509 int iter = 1000);
510
511 /** @brief Project @a vcoeff VectorCoefficient to @a this GridFunction. The
512 projection is an element local L2 projection, with an appropriate
513 weighting for Dofs that are shared between elements. Inspired by
514 Bezier-Projection [CMAME (284) 2015 pg 55-105].
515 This routine can be used as a fallback for elements without a projection
516 member function.*/
518
519 /** @brief Project @a vcoeff VectorCoefficient to @a this GridFunction, using
520 one element for each degree of freedom in @a dofs and nodal interpolation
521 on that element. */
523
524 /** @brief Project @a vcoeff VectorCoefficient to @a this GridFunction, only
525 projecting onto elements with the given @a attribute */
526 void ProjectCoefficient(VectorCoefficient &vcoeff, int attribute);
527
528 /** @brief Analogous to the version with argument @a vcoeff VectorCoefficient
529 but using an array of scalar coefficients for each component. */
530 void ProjectCoefficient(Coefficient *coeff[]);
531
532 /** @brief Project a discontinuous coefficient as a grid function on
533 a continuous finite element space. The values in shared dofs are
534 determined from the element with maximal attribute. */
536 { ProjectDiscCoefficient(&coeff); }
537
538 /** @brief Project a discontinuous vector coefficient as a grid function on
539 a continuous finite element space. The values in shared dofs are
540 determined from the element with maximal attribute. */
543
545 /** @brief Projects a discontinuous coefficient so that the values in shared
546 vdofs are computed by taking an average of the possible values. */
547 virtual void ProjectDiscCoefficient(Coefficient &coeff, AvgType type);
548 /** @brief Projects a discontinuous _vector_ coefficient so that the values
549 in shared vdofs are computed by taking an average of the possible values.
550 */
551 virtual void ProjectDiscCoefficient(VectorCoefficient &coeff, AvgType type);
552
553 /** @brief Return a GridFunction with the values of this, prolongated to the
554 maximum order of all elements in the mesh. */
555 std::unique_ptr<GridFunction> ProlongateToMaxOrder() const;
556
557protected:
559 const Array<int> &attr);
560
561 /** @brief Accumulates (depending on @a type) the values of @a coeff at all
562 shared vdofs and counts in how many zones each vdof appears. */
564 Array<int> &zones_per_vdof);
565
566 /** @brief Accumulates (depending on @a type) the values of @a vcoeff at all
567 shared vdofs and counts in how many zones each vdof appears. */
569 Array<int> &zones_per_vdof);
570
571 /** @brief Used for the serial and parallel implementations of the
572 GetDerivative() method; see its documentation. */
573 void AccumulateAndCountDerivativeValues(int comp, int der_comp,
574 GridFunction &der,
575 Array<int> &zones_per_dof) const;
576
578 VectorCoefficient *vcoeff,
579 const Array<int> &attr,
580 Array<int> &values_counter);
581
583 const Array<int> &bdr_attr,
584 Array<int> &values_counter);
585
587 VectorCoefficient *vcoeff,
588 Array<int> &values_counter);
589
591 Array<int> &values_counter);
592
593 // Complete the computation of averages; called e.g. after
594 // AccumulateAndCountZones().
595 void ComputeMeans(AvgType type, const Array<int> &zones_per_vdof);
596
597 /// P-refinement version of Update().
598 void UpdatePRef();
599
600 /** @brief Estimate the minimum value of the GridFunction in element @a elem
601 * if it is below a certain @a min_threshold.
602 *
603 * @details For a given element \p elem and grid function component \p vdim
604 * an estimate of the function minimum is the minimum of the piecewise
605 * linear lower bound obtained using the given PLBound object. The actual
606 * minimum is between [minimum lower bound, minimum upper bound]. We
607 * improve the estimate of the function minimum by recursively
608 * subdividing the interval with the lowest lower bound, and computing
609 * bounds on the sub-intervals.
610 * This process continues until (i) the maximum recursion depth is reached
611 * or (ii) the difference between the minimum upper bound and minimum lower
612 * bound is less than a certain tolerance (\p tol * [initial minimum
613 * upper bound - initial minimum lower bound]).
614 * The function also terminates if the lowest minima estimate is found
615 * to be above the given threshold \p min_threshold. This is useful when
616 * we are interested in computing the global minimum of the function
617 * over all elements. In this case we can reject elements where the lowest
618 * bound is above the current global minimum. In case the function
619 * minimum on the element is below the global minimum, we update
620 * \p min_threshold.
621 *
622 * We return a pair of values that bracket the actual minimum, i.e.
623 * [min_lower_bound, min_upper_bound].
624 */
625 std::pair<real_t,real_t> EstimateFunctionMinimum(const int elem,
626 const PLBound &plb,
627 const int vdim,
628 const int max_depth,
629 const real_t tol,
630 real_t &min_threshold)const;
631
632 /** @brief Estimate the maximum value of the GridFunction in element @a elem
633 * if it is above a certain @a max_threshold.
634 *
635 * @details For a given element \p elem and grid function component \p vdim
636 * an estimate of the function maximum is the maximum of the piecewise
637 * linear upper bound obtained using the given PLBound object. The actual
638 * maximum is between [maximum lower bound, maximum upper bound]. We
639 * improve the estimate of the function maximum by recursively
640 * subdividing the interval with the highest upper bound, and computing
641 * bounds on the sub-intervals.
642 * This process continues until (i) the maximum recursion depth is reached
643 * or (ii) the difference between the maximum upper bound and maximum lower
644 * bound is less than a certain tolerance (\p tol * [initial maximum
645 * upper bound - initial maximum lower bound]).
646 * The function also terminates if the highest maxima estimate is found
647 * to be below the given threshold \p max_threshold. This is useful when
648 * we are interested in computing the global maximum of the function
649 * over all elements. In this case we can reject elements where the upper
650 * bound is below the current global maximum. In case the function
651 * maximum on the element is above the global maximum, we update
652 * \p max_threshold.
653 *
654 * We return a pair of values that bracket the actual maximum, i.e.
655 * [max_lower_bound, max_upper_bound].
656 */
657 std::pair<real_t,real_t> EstimateFunctionMaximum(const int elem,
658 const PLBound &plb,
659 const int vdim,
660 const int max_depth,
661 const real_t tol,
662 real_t &max_threshold)const;
663
664public:
665 /** @brief For each vdof, counts how many elements contain the vdof,
666 as containment is determined by FiniteElementSpace::GetElementVDofs(). */
667 virtual void CountElementsPerVDof(Array<int> &elem_per_vdof) const;
668
669 /** @brief Project a Coefficient on the GridFunction, modifying only DOFs on
670 the boundary associated with the boundary attributes marked in the
671 @a attr array. */
673 {
674 Coefficient *coeff_p = &coeff;
675 ProjectBdrCoefficient(&coeff_p, attr);
676 }
677
678 /// Project a Coefficient on a GridFunction defined on H1 trace space
681
682 /** @brief Project a VectorCoefficient @a vcoeff on a GridFunction
683 defined on a Vector H1 trace space. Note that this also works
684 for a scalar H1 trace space, where only the first component of
685 @a vcoeff is used. */
687 /** @brief Project a VectorCoefficient on a GridFunction
688 defined on an RT trace space */
690 /** @brief Project a VectorCoefficient on a GridFunction
691 defined on an ND trace space */
693
694
695 /** @brief Project a VectorCoefficient on the GridFunction, modifying only
696 DOFs on the boundary associated with the boundary attributes marked in
697 the @a attr array. */
698 virtual void ProjectBdrCoefficient(VectorCoefficient &vcoeff,
699 const Array<int> &attr);
700
701 /** @brief Project a set of Coefficient%s on the components of the
702 GridFunction, modifying only DOFs on the boundary associated with the
703 boundary attributed marked in the @a attr array. */
704 /** If a Coefficient pointer in the array @a coeff is NULL, that component
705 will not be touched. */
706 virtual void ProjectBdrCoefficient(Coefficient *coeff[],
707 const Array<int> &attr);
708
709 /** @brief Project the normal component of the given VectorCoefficient on
710 the boundary. */
711 /** Only boundary attributes that are marked in @a bdr_attr are
712 projected. Assumes RT-type vector finite element GridFunction. */
714 const Array<int> &bdr_attr)
715 { ProjectBdrCoefficientNormal(NULL, &vcoeff, bdr_attr); }
716
717 /** @brief Project the given Coefficient in the normal direction on the
718 boundary. */
719 /** Only boundary attributes that are marked in @a bdr_attr are projected.
720 Assumes RT-type vector finite element GridFunction. */
722 const Array<int> &bdr_attr)
723 { ProjectBdrCoefficientNormal(&coeff, NULL, bdr_attr); }
724
725 /** @brief Project the tangential components of the given VectorCoefficient
726 on the boundary. */
727 /** Only boundary attributes that are marked in @a bdr_attr
728 are projected. Assumes ND-type vector finite element GridFunction. */
730 const Array<int> &bdr_attr);
731
732 /// @brief Returns ||exsol - u_h||_L2 for scalar or vector H1 or L2 elements
733 ///
734 /// @param[in] exsol Pointer to an array of scalar Coefficient objects,
735 /// one for each component of the vector field. The
736 /// length of the array should be at least equal to
737 /// FiniteElementSpace::GetVDim().
738 /// @param[in] irs Optional pointer to an array of custom integration
739 /// rules e.g. higher order than the default rules. If
740 /// present the array will be indexed by Geometry::Type.
741 /// @param[in] elems Optional pointer to a marker array, with a length
742 /// equal to the number of local elements, indicating
743 /// which elements to integrate over. Only those elements
744 /// corresponding to non-zero entries in @a elems will
745 /// contribute to the computed L2 error.
746 ///
747 /// @note If an array of integration rules is provided through @a irs, be
748 /// sure to include valid rules for each element type that may occur
749 /// in the list of elements.
750 ///
751 /// @note Quadratures with negative weights (as in some simplex integration
752 /// rules in MFEM) can produce negative integrals even with
753 /// non-negative integrands. To avoid returning negative errors this
754 /// function uses the absolute values of the element-wise integrals.
755 /// This may lead to results which are not entirely consistent with
756 /// such integration rules.
757 virtual real_t ComputeL2Error(Coefficient *exsol[],
758 const IntegrationRule *irs[] = NULL,
759 const Array<int> *elems = NULL) const;
760
761 /// @brief Returns ||grad u_ex - grad u_h||_L2 in element ielem for
762 /// H1 or L2 elements
763 ///
764 /// @param[in] ielem Index of the element in which to compute the L2 error.
765 /// @param[in] exgrad Pointer to a VectorCoefficient object reproducing the
766 /// expected gradient of the scalar field, grad u_ex.
767 /// @param[in] irs Optional pointer to an array of custom integration
768 /// rules e.g. higher order than the default rules. If
769 /// present the array will be indexed by Geometry::Type.
770 ///
771 /// @note If an array of integration rules is provided through @a irs, be
772 /// sure to include valid rules for each element type that may occur
773 /// in the list of elements.
774 ///
775 /// @note Quadratures with negative weights (as in some simplex integration
776 /// rules in MFEM) can produce negative integrals even with
777 /// non-negative integrands. To avoid returning negative errors this
778 /// function uses the absolute values of the element-wise integrals.
779 /// This may lead to results which are not entirely consistent with
780 /// such integration rules.
781 virtual real_t ComputeElementGradError(int ielem, VectorCoefficient *exgrad,
782 const IntegrationRule *irs[] = NULL) const;
783
784 /// @brief Returns ||u_ex - u_h||_L2 for H1 or L2 elements
785 ///
786 /// @param[in] exsol Coefficient object reproducing the anticipated values
787 /// of the scalar field, u_ex.
788 /// @param[in] irs Optional pointer to an array of custom integration
789 /// rules e.g. higher order than the default rules. If
790 /// present the array will be indexed by Geometry::Type.
791 /// @param[in] elems Optional pointer to a marker array, with a length
792 /// equal to the number of local elements, indicating
793 /// which elements to integrate over. Only those elements
794 /// corresponding to non-zero entries in @a elems will
795 /// contribute to the computed L2 error.
796 ///
797 /// @note If an array of integration rules is provided through @a irs, be
798 /// sure to include valid rules for each element type that may occur
799 /// in the list of elements.
800 ///
801 /// @note Quadratures with negative weights (as in some simplex integration
802 /// rules in MFEM) can produce negative integrals even with
803 /// non-negative integrands. To avoid returning negative errors this
804 /// function uses the absolute values of the element-wise integrals.
805 /// This may lead to results which are not entirely consistent with
806 /// such integration rules.
808 const IntegrationRule *irs[] = NULL,
809 const Array<int> *elems = NULL) const
810 { return GridFunction::ComputeLpError(2.0, exsol, NULL, irs, elems); }
811
812 /// @brief Returns ||u_ex - u_h||_L2 for vector fields
813 ///
814 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
815 /// values of the vector field, u_ex.
816 /// @param[in] irs Optional pointer to an array of custom integration
817 /// rules e.g. higher order than the default rules. If
818 /// present the array will be indexed by Geometry::Type.
819 /// @param[in] elems Optional pointer to a marker array, with a length
820 /// equal to the number of local elements, indicating
821 /// which elements to integrate over. Only those elements
822 /// corresponding to non-zero entries in @a elems will
823 /// contribute to the computed L2 error.
824 ///
825 /// @note If an array of integration rules is provided through @a irs, be
826 /// sure to include valid rules for each element type that may occur
827 /// in the list of elements.
828 ///
829 /// @note Quadratures with negative weights (as in some simplex integration
830 /// rules in MFEM) can produce negative integrals even with
831 /// non-negative integrands. To avoid returning negative errors this
832 /// function uses the absolute values of the element-wise integrals.
833 /// This may lead to results which are not entirely consistent with
834 /// such integration rules.
836 const IntegrationRule *irs[] = NULL,
837 const Array<int> *elems = NULL) const;
838
839 /// @brief Returns ||grad u_ex - grad u_h||_L2 for H1 or L2 elements
840 ///
841 /// @param[in] exgrad Pointer to a VectorCoefficient object reproducing the
842 /// expected gradient of the scalar field, grad u_ex.
843 /// @param[in] irs Optional pointer to an array of custom integration
844 /// rules e.g. higher order than the default rules. If
845 /// present the array will be indexed by Geometry::Type.
846 ///
847 /// @note This function only computes the error of the gradient in the
848 /// interior of the elements. In the context of discontinuous
849 /// Galerkin (DG) methods it may also be desirable to compute the
850 /// error in the jumps across element interfaces using
851 /// ComputeDGFaceJumpError().
852 ///
853 /// @note If an array of integration rules is provided through @a irs, be
854 /// sure to include valid rules for each element type that may occur
855 /// in the list of elements.
856 ///
857 /// @note Quadratures with negative weights (as in some simplex integration
858 /// rules in MFEM) can produce negative integrals even with
859 /// non-negative integrands. To avoid returning negative errors this
860 /// function uses the absolute values of the element-wise integrals.
861 /// This may lead to results which are not entirely consistent with
862 /// such integration rules.
864 const IntegrationRule *irs[] = NULL) const;
865
866 /// @brief Returns ||curl u_ex - curl u_h||_L2 for ND elements
867 ///
868 /// @param[in] excurl Pointer to a VectorCoefficient object reproducing the
869 /// expected curl of the vector field, curl u_ex.
870 /// @param[in] irs Optional pointer to an array of custom integration
871 /// rules e.g. higher order than the default rules. If
872 /// present the array will be indexed by Geometry::Type.
873 ///
874 /// @note If an array of integration rules is provided through @a irs, be
875 /// sure to include valid rules for each element type that may occur
876 /// in the list of elements.
877 ///
878 /// @note Quadratures with negative weights (as in some simplex integration
879 /// rules in MFEM) can produce negative integrals even with
880 /// non-negative integrands. To avoid returning negative errors this
881 /// function uses the absolute values of the element-wise integrals.
882 /// This may lead to results which are not entirely consistent with
883 /// such integration rules.
885 const IntegrationRule *irs[] = NULL) const;
886
887 /// @brief Returns ||div u_ex - div u_h||_L2 for RT elements
888 ///
889 /// @param[in] exdiv Pointer to a Coefficient object reproducing the
890 /// expected divergence of the vector field, div u_ex.
891 /// @param[in] irs Optional pointer to an array of custom integration
892 /// rules e.g. higher order than the default rules. If
893 /// present the array will be indexed by Geometry::Type.
894 ///
895 /// @note If an array of integration rules is provided through @a irs, be
896 /// sure to include valid rules for each element type that may occur
897 /// in the list of elements.
898 ///
899 /// @note Quadratures with negative weights (as in some simplex integration
900 /// rules in MFEM) can produce negative integrals even with
901 /// non-negative integrands. To avoid returning negative errors this
902 /// function uses the absolute values of the element-wise integrals.
903 /// This may lead to results which are not entirely consistent with
904 /// such integration rules.
905 virtual real_t ComputeDivError(Coefficient *exdiv,
906 const IntegrationRule *irs[] = NULL) const;
907
908 /// @brief Returns the Face Jumps error for L2 elements.
909 ///
910 /// Computes:
911 /// $$\sqrt{\sum_{f\in faces}\int_f js(f) ell(f)
912 /// (2 u_{ex} - u_1 - u_2)^2}$$
913 ///
914 /// Where js[f] is the jump_scaling evaluated on the face f and ell is the
915 /// average of ell_coef evaluated in the two elements sharing the face f.
916 ///
917 /// @param[in] exsol Pointer to a Coefficient object reproducing the
918 /// anticipated values of the scalar field, u_ex.
919 /// @param[in] ell_coeff Pointer to a Coefficient object used to compute
920 /// the averaged value ell in the above integral.
921 /// @param[in] jump_scaling Can be configured to provide scaling by
922 /// nu, nu/h, or nu*p^2/h
923 /// @param[in] irs Optional pointer to an array of custom
924 /// integration rules e.g. higher order than the
925 /// default rules. If present the array will be
926 /// indexed by Geometry::Type.
927 ///
928 /// @note If an array of integration rules is provided through @a irs, be
929 /// sure to include valid rules for each element type that may occur
930 /// in the list of faces.
931 ///
932 /// @note Quadratures with negative weights (as in some simplex integration
933 /// rules in MFEM) can produce negative integrals even with
934 /// non-negative integrands. To avoid returning negative errors this
935 /// function uses the absolute values of the element-wise integrals.
936 /// This may lead to results which are not entirely consistent with
937 /// such integration rules.
939 Coefficient *ell_coeff,
940 class JumpScaling jump_scaling,
941 const IntegrationRule *irs[] = NULL)
942 const;
943
944 /// @brief Returns the Face Jumps error for L2 elements, with 1/h scaling.
945 ///
946 /// @note Quadratures with negative weights (as in some simplex integration
947 /// rules in MFEM) can produce negative integrals even with
948 /// non-negative integrands. To avoid returning negative errors this
949 /// function uses the absolute values of the element-wise integrals.
950 /// This may lead to results which are not entirely consistent with
951 /// such integration rules.
952 ///
953 /// @deprecated See @ref ComputeDGFaceJumpError(Coefficient *exsol,
954 /// Coefficient *ell_coeff,
955 /// class JumpScaling jump_scaling,
956 /// const IntegrationRule *irs[]) const
957 /// for the preferred implementation.
958 MFEM_DEPRECATED
960 Coefficient *ell_coeff,
961 real_t Nu,
962 const IntegrationRule *irs[] = NULL) const;
963
964 /** This method is kept for backward compatibility.
965
966 Returns either the H1-seminorm, or the DG face jumps error, or both
967 depending on norm_type = 1, 2, 3. Additional arguments for the DG face
968 jumps norm: ell_coeff: mesh-depended coefficient (weight) Nu: scalar
969 constant weight */
970 virtual real_t ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad,
971 Coefficient *ell_coef, real_t Nu,
972 int norm_type) const;
973
974 /// @brief Returns the error measured in H1-norm for H1 or L2 elements
975 ///
976 /// Computes the norm using the $L^2$ norms of the function and its gradient
977 /// $$\sqrt{norm\_u^2 + norm\_du^2}$$
978 /// Where
979 /// $$norm\_u = \|u_{ex} - u_h\|_{L^2}$$
980 /// and
981 /// $$norm\_du = \|du_{ex} - \nabla u_h\|_{L^2}$$
982 ///
983 /// @param[in] exsol Coefficient object reproducing the anticipated values
984 /// of the scalar field, u_ex.
985 /// @param[in] exgrad VectorCoefficient object reproducing the anticipated
986 /// values of the gradient of the scalar field, du_ex.
987 /// @param[in] irs Optional pointer to an array of custom integration
988 /// rules e.g. higher order than the default rules. If
989 /// present the array will be indexed by Geometry::Type.
990 ///
991 /// @note If an array of integration rules is provided through @a irs, be
992 /// sure to include valid rules for each element type that may occur
993 /// in the list of elements.
994 ///
995 /// @note Quadratures with negative weights (as in some simplex integration
996 /// rules in MFEM) can produce negative integrals even with
997 /// non-negative integrands. To avoid returning negative errors this
998 /// function uses the absolute values of the element-wise integrals.
999 /// This may lead to results which are not entirely consistent with
1000 /// such integration rules.
1001 ///
1002 /// @note For L2 elements this returns what could be called a "broken"
1003 /// H1-norm.
1004 virtual real_t ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad,
1005 const IntegrationRule *irs[] = NULL) const;
1006
1007 /// @brief Returns the error measured in H(div)-norm for RT elements
1008 ///
1009 /// Computes the norm using the $L^2$ norms of the function and its
1010 /// divergence
1011 /// $$\sqrt{norm\_u^2 + norm\_du^2}$$
1012 /// Where
1013 /// $$norm\_u = \|u_{ex} - u_h\|_{L^2}$$
1014 /// and
1015 /// $$norm\_du = \|du_{ex} - \nabla\cdot u_h\|_{L^2}$$
1016 ///
1017 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
1018 /// values of the vector field, u_ex.
1019 /// @param[in] exdiv Coefficient object reproducing the anticipated
1020 /// values of the divergence of the vector field, du_ex.
1021 /// @param[in] irs Optional pointer to an array of custom integration
1022 /// rules e.g. higher order than the default rules. If
1023 /// present the array will be indexed by Geometry::Type.
1024 ///
1025 /// @note If an array of integration rules is provided through @a irs, be
1026 /// sure to include valid rules for each element type that may occur
1027 /// in the list of elements.
1028 ///
1029 /// @note Quadratures with negative weights (as in some simplex integration
1030 /// rules in MFEM) can produce negative integrals even with
1031 /// non-negative integrands. To avoid returning negative errors this
1032 /// function uses the absolute values of the element-wise integrals.
1033 /// This may lead to results which are not entirely consistent with
1034 /// such integration rules.
1036 Coefficient *exdiv,
1037 const IntegrationRule *irs[] = NULL) const;
1038
1039 /// @brief Returns the error measured in H(curl)-norm for ND elements
1040 ///
1041 /// Computes the norm using the $L^2$ norms of the function and its curl
1042 /// $$\sqrt{norm\_u^2 + norm\_du^2}$$
1043 /// Where
1044 /// $$norm\_u = \|u_{ex} - u_h\|_{L^2}$$
1045 /// and
1046 /// $$norm\_du = \|du_{ex} - \nabla\times u_h\|_{L^2}$$
1047 ///
1048 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
1049 /// values of the vector field, u_ex.
1050 /// @param[in] excurl VectorCoefficient object reproducing the anticipated
1051 /// values of the curl of the vector field, du_ex.
1052 /// @param[in] irs Optional pointer to an array of custom integration
1053 /// rules e.g. higher order than the default rules. If
1054 /// present the array will be indexed by Geometry::Type.
1055 ///
1056 /// @note If an array of integration rules is provided through @a irs, be
1057 /// sure to include valid rules for each element type that may occur
1058 /// in the list of elements.
1059 ///
1060 /// @note Quadratures with negative weights (as in some simplex integration
1061 /// rules in MFEM) can produce negative integrals even with
1062 /// non-negative integrands. To avoid returning negative errors this
1063 /// function uses the absolute values of the element-wise integrals.
1064 /// This may lead to results which are not entirely consistent with
1065 /// such integration rules.
1067 VectorCoefficient *excurl,
1068 const IntegrationRule *irs[] = NULL) const;
1069
1070 /// @brief Returns Max|u_ex - u_h| error for H1 or L2 elements
1071 ///
1072 /// Compute the $L^\infty$ error across the entire domain.
1073 ///
1074 /// @param[in] exsol Coefficient object reproducing the anticipated
1075 /// values of the scalar field, u_ex.
1076 /// @param[in] irs Optional pointer to an array of custom integration
1077 /// rules e.g. higher order than the default rules. If
1078 /// present the array will be indexed by
1079 /// Geometry::Type.
1080 ///
1081 /// @note Uses ComputeLpError internally. See the ComputeLpError
1082 /// documentation for generalizations of this error computation.
1083 ///
1084 /// @note If an array of integration rules is provided through @a irs, be
1085 /// sure to include valid rules for each element type that may occur
1086 /// in the list of elements.
1087 ///
1089 const IntegrationRule *irs[] = NULL) const
1090 {
1091 return ComputeLpError(infinity(), exsol, NULL, irs);
1092 }
1093
1094 /// @brief Returns Max|u_ex - u_h| error for scalar or vector fields
1095 ///
1096 /// Compute the $L^\infty$ error across the entire domain.
1097 ///
1098 /// Computes:
1099 /// $$max_{elems} (max_{elem} |scalar\_error|)$$
1100 ///
1101 /// Where
1102 /// $$scalar\_error = max_{d=0\ldots vdim}|u_{ex}[d] - u_h[d]|$$
1103 ///
1104 /// @param[in] exsol Pointer to an array of scalar Coefficient objects,
1105 /// one for each component of the vector field. The
1106 /// length of the array should be at least equal to
1107 /// FiniteElementSpace::GetVDim().
1108 /// @param[in] irs Optional pointer to an array of custom integration
1109 /// rules e.g. higher order than the default rules. If
1110 /// present the array will be indexed by Geometry::Type.
1111 ///
1112 /// @note This implementation of the max error of a vector field computes
1113 /// the max norm over vector components rather than the magnitude of
1114 /// the vector.
1115 ///
1116 /// @note If an array of integration rules is provided through @a irs, be
1117 /// sure to include valid rules for each element type that may occur
1118 /// in the list of elements.
1119 ///
1120 virtual real_t ComputeMaxError(Coefficient *exsol[],
1121 const IntegrationRule *irs[] = NULL) const;
1122
1123 /// @brief Returns Max|u_ex - u_h| error for vector fields
1124 ///
1125 /// Compute the $L^\infty$ error across the entire domain.
1126 ///
1127 /// Computes:
1128 /// $$max_{elems} (max_{elem} |scalar\_error|)$$
1129 ///
1130 /// Where
1131 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1132 ///
1133 /// @param[in] exsol VectorCoefficient object reproducing the
1134 /// anticipated values of the vector field, u_ex.
1135 /// @param[in] irs Optional pointer to an array of custom integration
1136 /// rules e.g. higher order than the default rules. If
1137 /// present the array will be indexed by
1138 /// Geometry::Type.
1139 ///
1140 /// @note Uses ComputeLpError internally. See the ComputeLpError
1141 /// documentation for generalizations of this error computation.
1142 ///
1143 /// @note Computes the maximum magnitude of the difference vector not the
1144 /// component-wise maximum difference of the vector fields.
1145 ///
1146 /// @note If an array of integration rules is provided through @a irs, be
1147 /// sure to include valid rules for each element type that may occur
1148 /// in the list of elements.
1149 ///
1151 const IntegrationRule *irs[] = NULL) const
1152 {
1153 return ComputeLpError(infinity(), exsol, NULL, NULL, irs);
1154 }
1155
1156 /// @brief Returns ||u_ex - u_h||_L1 for H1 or L2 elements
1157 ///
1158 /// Computes:
1159 /// $$\sum_{elems} \int_{elem} |u_{ex} - u_h|$$
1160 ///
1161 /// @param[in] exsol Coefficient object reproducing the anticipated values
1162 /// of the scalar field, u_ex.
1163 /// @param[in] irs Optional pointer to an array of custom integration
1164 /// rules e.g. higher order than the default rules. If
1165 /// present the array will be indexed by Geometry::Type.
1166 ///
1167 /// @note Quadratures with negative weights (as in some simplex integration
1168 /// rules in MFEM) can produce negative integrals even with
1169 /// non-negative integrands. To avoid returning negative errors this
1170 /// function uses the absolute values of the element-wise integrals.
1171 /// This may lead to results which are not entirely consistent with
1172 /// such integration rules.
1173 ///
1174 /// @note Uses ComputeLpError internally. See the ComputeLpError
1175 /// documentation for generalizations of this error computation.
1176 ///
1177 /// @note If an array of integration rules is provided through @a irs, be
1178 /// sure to include valid rules for each element type that may occur
1179 /// in the list of elements.
1180 ///
1182 const IntegrationRule *irs[] = NULL) const
1183 { return ComputeLpError(1.0, exsol, NULL, irs); }
1184
1185 /// @brief Returns ||u_ex - u_h||_L1 for H1 or L2 elements
1186 ///
1187 /// Computes:
1188 /// $$\sum_{elems} \int_{elem} |u_{ex} - u_h|$$
1189 ///
1190 /// @param[in] exsol Pointer to an array of Coefficient objects
1191 /// reproducing the anticipated values of the scalar
1192 /// field, u_ex. Only the first entry of this array will
1193 /// be accessed.
1194 /// @param[in] irs Optional pointer to an array of custom integration
1195 /// rules e.g. higher order than the default rules. If
1196 /// present the array will be indexed by Geometry::Type.
1197 ///
1198 /// @note If an array of integration rules is provided through @a irs, be
1199 /// sure to include valid rules for each element type that may occur
1200 /// in the list of elements.
1201 ///
1202 /// @note Quadratures with negative weights (as in some simplex integration
1203 /// rules in MFEM) can produce negative integrals even with
1204 /// non-negative integrands. To avoid returning negative errors this
1205 /// function uses the absolute values of the element-wise integrals.
1206 /// This may lead to results which are not entirely consistent with
1207 /// such integration rules.
1208 ///
1209 /// @note Uses ComputeW11Error internally. See the ComputeW11Error
1210 /// documentation for generalizations of this error computation.
1211 ///
1212 /// @warning While this function is nominally equivalent to ComputeLpError,
1213 /// with appropriate arguments, the returned errors may differ
1214 /// noticeably because ComputeLpError uses a higher order
1215 /// integration rule by default.
1216 ///
1217 /// @deprecated See @ref ComputeL1Error(Coefficient &exsol,
1218 /// const IntegrationRule *irs[]) const
1219 /// for the preferred implementation.
1220 MFEM_DEPRECATED
1222 const IntegrationRule *irs[] = NULL) const
1223 { return ComputeW11Error(*exsol, NULL, 1, NULL, irs); }
1224
1225 /// @brief Returns $W^1_1$ norm (or portions thereof) for H1 or L2 elements
1226 ///
1227 /// Computes for norm_type == 1 the $L^1$ norm of $u$:
1228 /// $$(\sum_{elems} \int_{elem} |u_{ex} - u_h|$$
1229 ///
1230 /// Computes for norm_type == 2 the $L^1$ semi-norm of $\nabla u$:
1231 /// $$(\sum_{elems} \int_{elem} |du_{ex} - \nabla u_h|$$
1232 ///
1233 /// Computes for norm_type == 3 the $W^1_1$ norm of $u$:
1234 /// $$(\sum_{elems} \int_{elem} |u_{ex} - u_h| + |du_{ex} - \nabla u_h|$$
1235 ///
1236 /// @param[in] exsol Pointer to Coefficient object reproducing the
1237 /// anticipated values of the scalar field, u_ex.
1238 /// @param[in] exgrad Pointer to VectorCoefficient object reproducing the
1239 /// anticipated values of the gradient of the scalar
1240 /// field, du_ex.
1241 /// @param[in] norm_type Integer value of 1, 2, or 3 indicating the type of
1242 /// norm to compute (see above).
1243 /// @param[in] elems Optional pointer to a marker array, with a length
1244 /// equal to the number of local elements, indicating
1245 /// which elements to integrate over. Only those
1246 /// elements corresponding to non-zero entries in
1247 /// @a elems will contribute to the computed $W^1_1$
1248 /// error.
1249 /// @param[in] irs Optional pointer to an array of custom integration
1250 /// rules e.g. higher order than the default rules. If
1251 /// present the array will be indexed by Geometry::Type.
1252 ///
1253 /// @note If an array of integration rules is provided through @a irs, be
1254 /// sure to include valid rules for each element type that may occur
1255 /// in the list of elements.
1256 ///
1257 /// @note Quadratures with negative weights (as in some simplex integration
1258 /// rules in MFEM) can produce negative integrals even with
1259 /// non-negative integrands. To avoid returning negative errors this
1260 /// function uses the absolute values of the element-wise integrals.
1261 /// This may lead to results which are not entirely consistent with
1262 /// such integration rules.
1263 virtual real_t ComputeW11Error(Coefficient *exsol, VectorCoefficient *exgrad,
1264 int norm_type, const Array<int> *elems = NULL,
1265 const IntegrationRule *irs[] = NULL) const;
1266
1267 /// @brief Returns ||u_ex - u_h||_L1 for vector fields
1268 ///
1269 /// Computes:
1270 /// $$\sum_{elems} \int_{elem} |scalar\_error|$$
1271 ///
1272 /// Where
1273 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1274 ///
1275 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
1276 /// values of the vector field, u_ex.
1277 /// @param[in] irs Optional pointer to an array of custom integration
1278 /// rules e.g. higher order than the default rules. If
1279 /// present the array will be indexed by Geometry::Type.
1280 ///
1281 /// @note If an array of integration rules is provided through @a irs, be
1282 /// sure to include valid rules for each element type that may occur
1283 /// in the list of elements.
1284 ///
1285 /// @note Quadratures with negative weights (as in some simplex integration
1286 /// rules in MFEM) can produce negative integrals even with
1287 /// non-negative integrands. To avoid returning negative errors this
1288 /// function uses the absolute values of the element-wise integrals.
1289 /// This may lead to results which are not entirely consistent with
1290 /// such integration rules.
1291 ///
1292 /// @note Uses ComputeLpError internally. See the ComputeLpError
1293 /// documentation for generalizations of this error computation.
1295 const IntegrationRule *irs[] = NULL) const
1296 { return ComputeLpError(1.0, exsol, NULL, NULL, irs); }
1297
1298 /// @brief Returns ||u_ex - u_h||_Lp for H1 or L2 elements
1299 ///
1300 /// Computes:
1301 /// $$(\sum_{elems} \int_{elem} w \, |u_{ex} - u_h|^p)^{1/p}$$
1302 ///
1303 /// @param[in] p Real value indicating the exponent of the $L^p$ norm.
1304 /// To avoid domain errors p should have a positive value,
1305 /// either finite or infinite.
1306 /// @param[in] exsol Coefficient object reproducing the anticipated values
1307 /// of the scalar field, u_ex.
1308 /// @param[in] weight Optional pointer to a Coefficient object reproducing
1309 /// a weighting function, w.
1310 /// @param[in] irs Optional pointer to an array of custom integration
1311 /// rules e.g. higher order than the default rules. If
1312 /// present the array will be indexed by Geometry::Type.
1313 /// @param[in] elems Optional pointer to a marker array, with a length
1314 /// equal to the number of local elements, indicating
1315 /// which elements to integrate over. Only those elements
1316 /// corresponding to non-zero entries in @a elems will
1317 /// contribute to the computed L2 error.
1318 ///
1319 /// @note If an array of integration rules is provided through @a irs, be
1320 /// sure to include valid rules for each element type that may occur
1321 /// in the list of elements.
1322 ///
1323 /// @note Quadratures with negative weights (as in some simplex integration
1324 /// rules in MFEM) can produce negative integrals even with
1325 /// non-negative integrands. To avoid returning negative errors this
1326 /// function uses the absolute values of the element-wise integrals.
1327 /// This may lead to results which are not entirely consistent with
1328 /// such integration rules.
1329 virtual real_t ComputeLpError(const real_t p, Coefficient &exsol,
1330 Coefficient *weight = NULL,
1331 const IntegrationRule *irs[] = NULL,
1332 const Array<int> *elems = NULL) const;
1333
1334 /// @brief Returns ||u_ex - u_h||_Lp elementwise for H1 or L2 elements
1335 ///
1336 /// Compute the Lp error in each element of the mesh and store the results in
1337 /// the Vector @a error. The result should be of length number of elements,
1338 /// for example an L2 GridFunction of order zero using map type @ref
1339 /// map_type_value "VALUE".
1340 ///
1341 /// Computes:
1342 /// $$(\int_{elem} w \, |u_{ex} - u_h|^p)^{1/p}$$
1343 ///
1344 /// @param[in] p Real value indicating the exponent of the $L^p$
1345 /// norm. To avoid domain errors p should have a
1346 /// positive value, either finite or infinite.
1347 /// @param[in] exsol Coefficient object reproducing the anticipated
1348 /// values of the scalar field, u_ex.
1349 /// @param[in,out] error Vector to contain the element-wise $L^p$ errors
1350 /// @param[in] weight Optional pointer to a Coefficient object
1351 /// reproducing a weighting function, w.
1352 /// @param[in] irs Optional pointer to an array of custom integration
1353 /// rules e.g. higher order than the default rules. If
1354 /// present the array will be indexed by
1355 /// Geometry::Type.
1356 ///
1357 /// @note If an array of integration rules is provided through @a irs, be
1358 /// sure to include valid rules for each element type that may occur
1359 /// in the list of elements.
1360 ///
1361 /// @note Quadratures with negative weights (as in some simplex integration
1362 /// rules in MFEM) can produce negative integrals even with
1363 /// non-negative integrands. To avoid returning negative errors this
1364 /// function uses the absolute values of the element-wise integrals.
1365 /// This may lead to results which are not entirely consistent with
1366 /// such integration rules.
1367 virtual void ComputeElementLpErrors(const real_t p, Coefficient &exsol,
1368 Vector &error,
1369 Coefficient *weight = NULL,
1370 const IntegrationRule *irs[] = NULL
1371 ) const;
1372
1373 /// @brief Returns ||u_ex - u_h||_L1 elementwise for H1 or L2 elements
1374 ///
1375 /// Compute the $L^1$ error in each element of the mesh and store the
1376 /// results in the Vector @a error. The result should be of length number of
1377 /// elements, for example an L2 GridFunction of order zero using map type
1378 /// @ref map_type_value "VALUE".
1379 ///
1380 /// @param[in] exsol Coefficient object reproducing the anticipated
1381 /// values of the scalar field, u_ex.
1382 /// @param[in,out] error Vector to contain the element-wise $L^1$ errors
1383 /// @param[in] irs Optional pointer to an array of custom integration
1384 /// rules e.g. higher order than the default rules. If
1385 /// present the array will be indexed by
1386 /// Geometry::Type.
1387 ///
1388 /// @note If an array of integration rules is provided through @a irs, be
1389 /// sure to include valid rules for each element type that may occur
1390 /// in the list of elements.
1391 ///
1392 /// @note Quadratures with negative weights (as in some simplex integration
1393 /// rules in MFEM) can produce negative integrals even with
1394 /// non-negative integrands. To avoid returning negative errors this
1395 /// function uses the absolute values of the element-wise integrals.
1396 /// This may lead to results which are not entirely consistent with
1397 /// such integration rules.
1398 ///
1399 /// @note Uses ComputeElementLpError internally. See the
1400 /// ComputeElementLpError documentation for generalizations of this
1401 /// error computation.
1403 Vector &error,
1404 const IntegrationRule *irs[] = NULL
1405 ) const
1406 { ComputeElementLpErrors(1.0, exsol, error, NULL, irs); }
1407
1408 /// @brief Returns ||u_ex - u_h||_L2 elementwise for H1 or L2 elements
1409 ///
1410 /// Compute the $L^2$ error in each element of the mesh and store the results
1411 /// in the Vector @a error. The result should be of length number of
1412 /// elements, for example an L2 GridFunction of order zero using map type
1413 /// @ref map_type_value "VALUE".
1414 ///
1415 /// Computes:
1416 /// $$(\int_{elem} |u_{ex} - u_h|^2)^{1/2}$$
1417 ///
1418 /// @param[in] exsol Coefficient object reproducing the anticipated
1419 /// values of the scalar field, u_ex.
1420 /// @param[in,out] error Vector to contain the element-wise $L^2$ errors
1421 /// @param[in] irs Optional pointer to an array of custom integration
1422 /// rules e.g. higher order than the default rules. If
1423 /// present the array will be indexed by
1424 /// Geometry::Type.
1425 ///
1426 /// @note If an array of integration rules is provided through @a irs, be
1427 /// sure to include valid rules for each element type that may occur
1428 /// in the list of elements.
1429 ///
1430 /// @note Quadratures with negative weights (as in some simplex integration
1431 /// rules in MFEM) can produce negative integrals even with
1432 /// non-negative integrands. To avoid returning negative errors this
1433 /// function uses the absolute values of the element-wise integrals.
1434 /// This may lead to results which are not entirely consistent with
1435 /// such integration rules.
1436 ///
1437 /// @note Uses ComputeElementLpError internally. See the
1438 /// ComputeElementLpError documentation for generalizations of this
1439 /// error computation.
1441 Vector &error,
1442 const IntegrationRule *irs[] = NULL
1443 ) const
1444 { ComputeElementLpErrors(2.0, exsol, error, NULL, irs); }
1445
1446 /// @brief Returns Max|u_ex - u_h| elementwise for H1 or L2 elements
1447 ///
1448 /// Compute the $L^\infty$ error in each element of the mesh and store the
1449 /// results in the Vector @a error. The result should be of length number of
1450 /// elements, for example an L2 GridFunction of order zero using map type
1451 /// @ref map_type_value "VALUE".
1452 ///
1453 /// @param[in] exsol Coefficient object reproducing the anticipated
1454 /// values of the scalar field, u_ex.
1455 /// @param[in,out] error Vector to contain the element-wise $L^\infty$
1456 /// errors
1457 /// @param[in] irs Optional pointer to an array of custom integration
1458 /// rules e.g. higher order than the default rules. If
1459 /// present the array will be indexed by
1460 /// Geometry::Type.
1461 ///
1462 /// @note If an array of integration rules is provided through @a irs, be
1463 /// sure to include valid rules for each element type that may occur
1464 /// in the list of elements.
1465 ///
1466 /// @note Uses ComputeElementLpError internally. See the
1467 /// ComputeElementLpError documentation for generalizations of this
1468 /// error computation.
1470 Vector &error,
1471 const IntegrationRule *irs[] = NULL
1472 ) const
1473 { ComputeElementLpErrors(infinity(), exsol, error, NULL, irs); }
1474
1475 /// @brief Returns ||u_ex - u_h||_Lp for vector fields
1476 ///
1477 /// When given a vector weight, compute the pointwise (scalar) error as the
1478 /// dot product of the vector error with the vector weight. Otherwise, the
1479 /// scalar error is the l_2 norm of the vector error.
1480 ///
1481 /// Computes:
1482 /// $$(\sum_{elems} \int_{elem} w \, |scalar\_error|^p)^{1/p}$$
1483 ///
1484 /// Where
1485 /// $$scalar\_error = |v\_weight \cdot (u_{ex} - u_h)|$$
1486 /// or
1487 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1488 ///
1489 /// @param[in] p Real value indicating the exponent of the $L^p$
1490 /// norm. To avoid domain errors p should have a
1491 /// positive value, either finite or infinite.
1492 /// @param[in] exsol VectorCoefficient object reproducing the anticipated
1493 /// values of the vector field, u_ex.
1494 /// @param[in] weight Optional pointer to a Coefficient object reproducing
1495 /// a weighting function, w.
1496 /// @param[in] v_weight Optional pointer to a VectorCoefficient object
1497 /// reproducing a weighting vector as shown above.
1498 /// @param[in] irs Optional pointer to an array of custom integration
1499 /// rules e.g. higher order than the default rules. If
1500 /// present the array will be indexed by Geometry::Type.
1501 ///
1502 /// @note If an array of integration rules is provided through @a irs, be
1503 /// sure to include valid rules for each element type that may occur
1504 /// in the list of elements.
1505 ///
1506 /// @note Quadratures with negative weights (as in some simplex integration
1507 /// rules in MFEM) can produce negative integrals even with
1508 /// non-negative integrands. To avoid returning negative errors this
1509 /// function uses the absolute values of the element-wise integrals.
1510 /// This may lead to results which are not entirely consistent with
1511 /// such integration rules.
1512 virtual real_t ComputeLpError(const real_t p, VectorCoefficient &exsol,
1513 Coefficient *weight = NULL,
1514 VectorCoefficient *v_weight = NULL,
1515 const IntegrationRule *irs[] = NULL) const;
1516
1517 /// @brief Returns ||u_ex - u_h||_Lp elementwise for vector fields
1518 ///
1519 /// Compute the $L^p$ error in each element of the mesh and store the results
1520 /// in the Vector @a error. The result should be of length number of
1521 /// elements, for example an L2 GridFunction of order zero using map type
1522 /// @ref map_type_value "VALUE".
1523 ///
1524 /// Computes:
1525 /// $$(\int_{elem} w \, |scalar\_error|^p)^{1/p}$$
1526 ///
1527 /// Where
1528 /// $$scalar\_error = |v\_weight \cdot (u_{ex} - u_h)|$$
1529 /// or
1530 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1531 ///
1532 /// @param[in] p Real value indicating the exponent of the $L^p$
1533 /// norm. To avoid domain errors p should have a
1534 /// positive value, either finite or infinite.
1535 /// @param[in] exsol VectorCoefficient object reproducing the
1536 /// anticipated values of the vector field, u_ex.
1537 /// @param[in,out] error Vector to contain the element-wise $L^p$ errors
1538 /// @param[in] weight Optional pointer to a Coefficient object
1539 /// reproducing a weighting function, w.
1540 /// @param[in] v_weight Optional pointer to a VectorCoefficient object
1541 /// reproducing a weighting vector as shown above.
1542 /// @param[in] irs Optional pointer to an array of custom integration
1543 /// rules e.g. higher order than the default rules. If
1544 /// present the array will be indexed by
1545 /// Geometry::Type.
1546 ///
1547 /// @note If an array of integration rules is provided through @a irs, be
1548 /// sure to include valid rules for each element type that may occur
1549 /// in the list of elements.
1550 ///
1551 /// @note Quadratures with negative weights (as in some simplex integration
1552 /// rules in MFEM) can produce negative integrals even with
1553 /// non-negative integrands. To avoid returning negative errors this
1554 /// function uses the absolute values of the element-wise integrals.
1555 /// This may lead to results which are not entirely consistent with
1556 /// such integration rules.
1557 virtual void ComputeElementLpErrors(const real_t p, VectorCoefficient &exsol,
1558 Vector &error,
1559 Coefficient *weight = NULL,
1560 VectorCoefficient *v_weight = NULL,
1561 const IntegrationRule *irs[] = NULL
1562 ) const;
1563
1564 /// @brief Returns ||u_ex - u_h||_L1 elementwise for vector fields
1565 ///
1566 /// Compute the $L^1$ error in each element of the mesh and store the
1567 /// results in the Vector @a error. The result should be of length number of
1568 /// elements, for example an L2 GridFunction of order zero using map type
1569 /// @ref map_type_value "VALUE".
1570 ///
1571 /// Computes:
1572 /// $$\int_{elem} |scalar\_error|$$
1573 ///
1574 /// Where
1575 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1576 ///
1577 /// @param[in] exsol VectorCoefficient object reproducing the
1578 /// anticipated values of the vector field, u_ex.
1579 /// @param[in,out] error Vector to contain the element-wise $L^1$ errors
1580 /// @param[in] irs Optional pointer to an array of custom integration
1581 /// rules e.g. higher order than the default rules. If
1582 /// present the array will be indexed by
1583 /// Geometry::Type.
1584 ///
1585 /// @note If an array of integration rules is provided through @a irs, be
1586 /// sure to include valid rules for each element type that may occur
1587 /// in the list of elements.
1588 ///
1589 /// @note Quadratures with negative weights (as in some simplex integration
1590 /// rules in MFEM) can produce negative integrals even with
1591 /// non-negative integrands. To avoid returning negative errors this
1592 /// function uses the absolute values of the element-wise integrals.
1593 /// This may lead to results which are not entirely consistent with
1594 /// such integration rules.
1595 ///
1596 /// @note Uses ComputeElementLpError internally. See the
1597 /// ComputeElementLpError documentation for generalizations of this
1598 /// error computation.
1600 Vector &error,
1601 const IntegrationRule *irs[] = NULL
1602 ) const
1603 { ComputeElementLpErrors(1.0, exsol, error, NULL, NULL, irs); }
1604
1605 /// @brief Returns ||u_ex - u_h||_L2 elementwise for vector fields
1606 ///
1607 /// Compute the $L^2$ error in each element of the mesh and store the
1608 /// results in the Vector @a error. The result should be of length number of
1609 /// elements, for example an L2 GridFunction of order zero using map type
1610 /// @ref map_type_value "VALUE".
1611 ///
1612 /// Computes:
1613 /// $$(\int_{elem} |scalar\_error|^2)^{1/2}$$
1614 ///
1615 /// Where
1616 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1617 ///
1618 /// @param[in] exsol VectorCoefficient object reproducing the
1619 /// anticipated values of the vector field, u_ex.
1620 /// @param[in,out] error Vector to contain the element-wise $L^2$ errors
1621 /// @param[in] irs Optional pointer to an array of custom integration
1622 /// rules e.g. higher order than the default rules. If
1623 /// present the array will be indexed by
1624 /// Geometry::Type.
1625 ///
1626 /// @note If an array of integration rules is provided through @a irs, be
1627 /// sure to include valid rules for each element type that may occur
1628 /// in the list of elements.
1629 ///
1630 /// @note Quadratures with negative weights (as in some simplex integration
1631 /// rules in MFEM) can produce negative integrals even with
1632 /// non-negative integrands. To avoid returning negative errors this
1633 /// function uses the absolute values of the element-wise integrals.
1634 /// This may lead to results which are not entirely consistent with
1635 /// such integration rules.
1636 ///
1637 /// @note Uses ComputeElementLpError internally. See the
1638 /// ComputeElementLpError documentation for generalizations of this
1639 /// error computation.
1641 Vector &error,
1642 const IntegrationRule *irs[] = NULL
1643 ) const
1644 { ComputeElementLpErrors(2.0, exsol, error, NULL, NULL, irs); }
1645
1646 /// @brief Returns Max|u_ex - u_h| elementwise for vector fields
1647 ///
1648 /// Compute the $L^\infty$ error in each element of the mesh and store the
1649 /// results in the Vector @a error. The result should be of length number of
1650 /// elements, for example an L2 GridFunction of order zero using map type
1651 /// @ref map_type_value "VALUE".
1652 ///
1653 /// Computes:
1654 /// $$max_{elem} |scalar\_error|$$
1655 ///
1656 /// Where
1657 /// $$scalar\_error = \sqrt{(u_{ex} - u_h) \cdot (u_{ex} - u_h)}$$
1658 ///
1659 /// @param[in] exsol VectorCoefficient object reproducing the
1660 /// anticipated values of the vector field, u_ex.
1661 /// @param[in,out] error Vector to contain the element-wise $L^\infty$
1662 /// errors
1663 /// @param[in] irs Optional pointer to an array of custom integration
1664 /// rules e.g. higher order than the default rules. If
1665 /// present the array will be indexed by
1666 /// Geometry::Type.
1667 ///
1668 /// @note If an array of integration rules is provided through @a irs, be
1669 /// sure to include valid rules for each element type that may occur
1670 /// in the list of elements.
1671 ///
1672 /// @note Uses ComputeElementLpError internally. See the
1673 /// ComputeElementLpError documentation for generalizations of this
1674 /// error computation.
1675 ///
1676 /// @note Computes the maximum magnitude of the difference vector not the
1677 /// component-wise maximum difference of the vector fields.
1679 Vector &error,
1680 const IntegrationRule *irs[] = NULL
1681 ) const
1682 { ComputeElementLpErrors(infinity(), exsol, error, NULL, NULL, irs); }
1683
1684 virtual void ComputeFlux(BilinearFormIntegrator &blfi,
1685 GridFunction &flux,
1686 bool wcoef = true, int subdomain = -1);
1687
1688 /// Redefine '=' for GridFunction = constant.
1690
1691 /// Copy the data from @a v.
1692 /** The size of @a v must be equal to the size of the associated
1693 FiniteElementSpace #fes. */
1694 GridFunction &operator=(const Vector &v);
1695
1696 /// Transform by the Space UpdateMatrix (e.g., on Mesh change).
1697 virtual void Update();
1698
1699 /** Return update counter, similar to Mesh::GetSequence(). Used to
1700 check if it is up to date with the space. */
1701 long GetSequence() const { return fes_sequence; }
1702
1704 const FiniteElementSpace *FESpace() const { return fes; }
1705
1706 /// Associate a new FiniteElementSpace with the GridFunction.
1707 /** The GridFunction is resized using the SetSize() method. */
1708 virtual void SetSpace(FiniteElementSpace *f);
1709
1710 using Vector::MakeRef;
1711
1712 /** @brief Make the GridFunction reference external data on a new
1713 FiniteElementSpace. */
1714 /** This method changes the FiniteElementSpace associated with the
1715 GridFunction and sets the pointer @a v as external data in the
1716 GridFunction. */
1717 virtual void MakeRef(FiniteElementSpace *f, real_t *v);
1718
1719 /** @brief Make the GridFunction reference external data on a new
1720 FiniteElementSpace. */
1721 /** This method changes the FiniteElementSpace associated with the
1722 GridFunction and sets the data of the Vector @a v (plus the @a v_offset)
1723 as external data in the GridFunction.
1724 @note This version of the method will also perform bounds checks when
1725 the build option MFEM_DEBUG is enabled. */
1726 virtual void MakeRef(FiniteElementSpace *f, Vector &v, int v_offset);
1727
1728 /** @brief Associate a new FiniteElementSpace and new true-dof data with the
1729 GridFunction. */
1730 /** - If the prolongation matrix of @a f is trivial (i.e. its method
1731 FiniteElementSpace::GetProlongationMatrix() returns NULL), then the
1732 method MakeRef() is called with the same arguments.
1733 - Otherwise, the method SetSpace() is called with argument @a f.
1734 - The internal true-dof vector is set to reference @a tv. */
1735 void MakeTRef(FiniteElementSpace *f, real_t *tv);
1736
1737 /** @brief Associate a new FiniteElementSpace and new true-dof data with the
1738 GridFunction. */
1739 /** - If the prolongation matrix of @a f is trivial (i.e. its method
1740 FiniteElementSpace::GetProlongationMatrix() returns NULL), this method
1741 calls MakeRef() with the same arguments.
1742 - Otherwise, this method calls SetSpace() with argument @a f.
1743 - The internal true-dof vector is set to reference the sub-vector of
1744 @a tv starting at the offset @a tv_offset. */
1745 void MakeTRef(FiniteElementSpace *f, Vector &tv, int tv_offset);
1746
1747 /// Save the GridFunction to an output stream.
1748 virtual void Save(std::ostream &out) const;
1749
1750 /// Save the GridFunction to a file. The given @a precision will be used for
1751 /// ASCII output.
1752 virtual void Save(const char *fname, int precision=16) const;
1753
1754#ifdef MFEM_USE_ADIOS2
1755 /// Save the GridFunction to a binary output stream using adios2 bp format.
1756 virtual void Save(adios2stream &out, const std::string& variable_name,
1759#endif
1760
1761 /** @brief Write the GridFunction in VTK format. Note that Mesh::PrintVTK
1762 must be called first. The parameter ref > 0 must match the one used in
1763 Mesh::PrintVTK. */
1764 void SaveVTK(std::ostream &out, const std::string &field_name, int ref);
1765
1766#ifdef MFEM_USE_HDF5
1767 /// @brief Save the GridFunction in %VTKHDF format.
1768 ///
1769 /// If @a high-order is true, then @a ref controls the order of output. If
1770 /// @a ref is -1, then the order of the grid function will be used.
1771 ///
1772 /// If @a high-order is false, then low-order output will be used. @a ref
1773 /// controls the number of mesh refinements; if @a ref is -1, no refinements
1774 /// will be performed.
1775 void SaveVTKHDF(const std::string &fname, const std::string &name="u",
1776 bool high_order=true, int ref=-1);
1777#endif
1778
1779 /** @brief Write the GridFunction in STL format. Note that the mesh dimension
1780 must be 2 and that quad elements will be broken into two triangles.*/
1781 void SaveSTL(std::ostream &out, int TimesToRefine = 1);
1782
1783 /** @name Methods to compute bounds on the grid function
1784 \brief See bounds.hpp for \ref PLBound that constructs piecewise linear
1785 bounds for a given set of bases. These piecewise bounds can be used to compute bounds on a grid function. Currently tensor-product elements are
1786 supported with Lagrange interpolants on Gauss Legendre nodes and Gauss Lobatto Legendre nodes, and Bernstein bases.
1787 */
1788 ///@{
1789 /// Computes the \ref PLBound for the gridfunction with number of control
1790 /// points based on \p ref_factor, and returns the overall bounds for each
1791 /// vdim (across all elements) in \p lower and \p upper. We also return the
1792 /// PLBound object used to compute the bounds.
1793 /// We compute the bounds for each vdim if \p vdim < 1.
1794 /// Note: For most cases, this method/interface will be sufficient.
1795 virtual PLBound GetBounds(Vector &lower, Vector &upper,
1796 const int ref_factor=1, const int vdim=-1) const;
1797
1798 /// Computes the \ref PLBound for the gridfunction with number of control
1799 /// points based on @a ref_factor, and returns the bounds for each element
1800 /// ordered byNODES:
1801 /// lower_{0,0}, lower_{1,0}, ..., lower_{ne-1,0},
1802 /// lower_{0,1}, ..., lower_{ne-1,vdim-1}. We also return the
1803 /// PLBound object used to compute the bounds.
1804 /// We compute the bounds for each vdim if \p vdim < 1.
1805 PLBound GetElementBounds(Vector &lower, Vector &upper,
1806 const int ref_factor=1, const int vdim=-1) const;
1807
1808 /// Compute piecewise linear bounds on the given element at the grid of
1809 /// [plb.ncp x plb.ncp x plb.ncp] control points for each of the vdim
1810 /// components of the gridfunction.
1811 void GetElementBoundsAtControlPoints(const int elem, const PLBound &plb,
1812 Vector &lower, Vector &upper,
1813 const int vdim = -1) const;
1814
1815 /** @brief Gets the bounds on given reference range inside an element.
1816 *
1817 * @details @a ref_range is a vector of size 2*dim that specifies the
1818 * lower and upper limits in each dimension of the reference element.
1819 * For example, in 2D, ref_range = [rmin, smin, rmax, smax].
1820 */
1821 void GetElementBoundsAtControlPoints(const int elem, const PLBound &plb,
1822 const Vector &ref_range,
1823 const int vdim,
1824 Vector &lower, Vector &upper,
1825 Vector &control_pos) const;
1826
1827 /// Compute bounds on the grid function for the given element.
1828 /// The bounds are stored in @b lower and @b upper.
1829 void GetElementBounds(const int elem, const PLBound &plb,
1830 Vector &lower, Vector &upper,
1831 const int vdim = -1) const;
1832
1833 /// Compute bounds on the grid function for all the elements. The bounds
1834 /// are returned in @b lower and @b upper, ordered byNODES:
1835 /// lower_{0,0}, lower_{1,0}, ..., lower_{ne-1,0},
1836 /// lower_{0,1}, ..., lower_{ne-1,vdim-1}
1837 void GetElementBounds(const PLBound &plb, Vector &lower, Vector &upper,
1838 const int vdim=-1) const;
1839
1840 /** @brief Estimate the minimum value of the GridFunction in element @a elem.
1841 *
1842 * @details See the protected version of EstimateFunctionMinimum for
1843 * details.
1844 */
1845 std::pair<real_t, real_t> EstimateFunctionMinimum(const int elem,
1846 const PLBound &plb,
1847 const int vdim,
1848 const int max_depth,
1849 const real_t tol) const;
1850
1851 /** @brief Estimate the maximum value of the GridFunction in element @a elem.
1852 *
1853 * @details See the protected version of EstimateFunctionMaximum for
1854 * details.
1855 */
1856 std::pair<real_t, real_t> EstimateFunctionMaximum(const int elem,
1857 const PLBound &plb,
1858 const int vdim,
1859 const int max_depth,
1860 const real_t tol) const;
1861
1862 /** @brief Estimate the GridFunction minimum across all elements. */
1863 virtual std::pair<real_t,real_t> EstimateFunctionMinimum(const int vdim,
1864 const PLBound &plb,
1865 const int max_depth,
1866 const real_t tol) const;
1867
1868 /** @brief Estimate the GridFunction maximum across all elements. */
1869 virtual std::pair<real_t,real_t> EstimateFunctionMaximum(const int vdim,
1870 const PLBound &plb,
1871 const int max_depth,
1872 const real_t tol) const;
1873 ///@}
1874
1875 /// Destroys grid function.
1876 virtual ~GridFunction() { Destroy(); }
1877};
1878
1879/** Overload operator<< for std::ostream and GridFunction; valid also for the
1880 derived class ParGridFunction */
1881std::ostream &operator<<(std::ostream &out, const GridFunction &sol);
1882
1883/// Class used to specify how the jump terms in
1884/// GridFunction::ComputeDGFaceJumpError are scaled.
1886{
1887public:
1894private:
1895 real_t nu;
1896 JumpScalingType type;
1897public:
1899 : nu(nu_), type(type_) { }
1900 real_t Eval(real_t h, int p) const
1901 {
1902 real_t val = nu;
1903 if (type != CONSTANT) { val /= h; }
1904 if (type == P_SQUARED_OVER_H) { val *= p*p; }
1905 return val;
1906 }
1907};
1908
1909/// Overload operator<< for std::ostream and QuadratureFunction.
1910std::ostream &operator<<(std::ostream &out, const QuadratureFunction &qf);
1911
1912
1914 GridFunction &u,
1915 GridFunction &flux,
1916 Vector &error_estimates,
1917 Array<int> *aniso_flags = NULL,
1918 int with_subdomains = 1,
1919 bool with_coeff = false);
1920
1921/// Defines the global tensor product polynomial space used by NewZZErorrEstimator
1922/**
1923 * See BoundingBox(...) for a description of @a angle and @a midpoint
1924 */
1925void TensorProductLegendre(int dim, // input
1926 int order, // input
1927 const Vector &x_in, // input
1928 const Vector &xmax, // input
1929 const Vector &xmin, // input
1930 Vector &poly, // output
1931 real_t angle=0.0, // input (optional)
1932 const Vector *midpoint=NULL); // input (optional)
1933
1934/// Defines the bounding box for the face patches used by NewZZErorrEstimator
1935/**
1936 * By default, BoundingBox(...) computes the parameters of a minimal bounding box
1937 * for the given @a face_patch that is aligned with the physical (i.e. global)
1938 * Cartesian axes. This means that the size of the bounding box will depend on the
1939 * orientation of the patch. It is better to construct an orientation-independent box.
1940 * This is implemented for 2D patches. The parameters @a angle and @a midpoint encode
1941 * the necessary additional geometric information.
1942 *
1943 * @a iface : Index of the face that the patch corresponds to.
1944 * This is used to compute @a angle and @a midpoint.
1945 *
1946 * @a angle : The angle the patch face makes with the x-axis.
1947 * @a midpoint : The midpoint of the face.
1948 */
1949void BoundingBox(const Array<int> &face_patch, // input
1950 FiniteElementSpace *ufes, // input
1951 int order, // input
1952 Vector &xmin, // output
1953 Vector &xmax, // output
1954 real_t &angle, // output
1955 Vector &midpoint, // output
1956 int iface=-1); // input (optional)
1957
1958/// A ``true'' ZZ error estimator that uses face-based patches for flux reconstruction.
1959/**
1960 * Only two-element face patches are ever used:
1961 * - For conforming faces, the face patch consists of its two neighboring elements.
1962 * - In the non-conforming setting, only the face patches associated to fine-scale
1963 * element faces are used. These face patches always consist of two elements
1964 * delivered by mesh::GetFaceElements(Face, *Elem1, *Elem2).
1965 */
1967 GridFunction &u, // input
1968 Vector &error_estimates, // output
1969 bool subdomain_reconstruction = true, // input (optional)
1970 bool with_coeff = false, // input (optional)
1971 real_t tichonov_coeff = 0.0); // input (optional)
1972
1973/// Compute the Lp distance between two grid functions on the given element.
1975 GridFunction& gf1, GridFunction& gf2);
1976
1977
1978/// Class used for extruding a scalar coefficient
1980{
1981private:
1982 int n;
1983 Mesh *mesh_in;
1984 Coefficient &sol_in;
1985public:
1986 /// Constructs an instance of ExtrudeCoefficient
1987 /**
1988 * @param m 1D mesh
1989 * @param s 1D scalar coefficient
1990 * @param n_ number of transverse elements of the extruded mesh
1991 */
1993 : n(n_), mesh_in(m), sol_in(s)
1994 { MFEM_VERIFY(n > 0, "Number of transverse elements must be positive!"); }
1995
1996 real_t Eval(ElementTransformation &T, const IntegrationPoint &ip) override;
1997
1999};
2000
2001/// Class used for extruding a vector coefficient
2003{
2004private:
2005 int n;
2006 Mesh *mesh_in;
2007 VectorCoefficient &sol_in;
2008public:
2009 /// Constructs an instance of VectorExtrudeCoefficient
2010 /**
2011 * @param m 1D mesh
2012 * @param s 1D vector coefficient
2013 * @param n_ number of transverse elements of the extruded mesh
2014 */
2016 : VectorCoefficient(s.GetVDim()), n(n_), mesh_in(m), sol_in(s)
2017 { MFEM_VERIFY(n > 0, "Number of transverse elements must be positive!"); }
2018
2019 void Eval(Vector &v, ElementTransformation &T,
2020 const IntegrationPoint &ip) override;
2022
2024};
2025
2026/// Extrude a 1D GridFunction, after extruding the mesh with Extrude1D()
2027/**
2028 * @param mesh 1D mesh
2029 * @param mesh2d extruded mesh
2030 * @param sol grid function
2031 * @param ny number of transverse elements of the extruded mesh
2032 */
2033GridFunction *Extrude1DGridFunction(Mesh *mesh, Mesh *mesh2d,
2034 GridFunction *sol, const int ny);
2035
2036} // namespace mfem
2037
2038#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 a scalar coefficient.
ExtrudeCoefficient(Mesh *m, Coefficient &s, int n_)
Constructs an instance of ExtrudeCoefficient.
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:210
int GetVectorDim() const
Return the total dimension of a vector in the space.
Definition fespace.cpp:1456
ElementTransformation * GetElementTransformation(int i) const
Definition fespace.hpp:903
int GetCurlDim() const
Return the dimension of the curl of a GridFunction defined on this space.
Definition fespace.cpp:1466
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:53
GridFunction(const GridFunction &orig)
Copy constructor. The internal true-dof vector t_vec is not copied.
Definition gridfunc.hpp:112
void GetLaplacians(int i, const IntegrationRule &ir, Vector &laps, int vdim=1) const
Definition gridfunc.cpp:542
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:130
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:807
void ProjectVectorFieldOn(GridFunction &vec_field, int comp=0)
virtual void ProjectDiscCoefficient(Coefficient &coeff)
Project a discontinuous coefficient as a grid function on a continuous finite element space....
Definition gridfunc.hpp:535
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:429
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:497
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:207
virtual real_t ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad, Coefficient *ell_coef, real_t Nu, int norm_type) const
virtual void ProjectDiscCoefficient(VectorCoefficient &coeff)
Project a discontinuous vector coefficient as a grid function on a continuous finite element space....
Definition gridfunc.hpp:541
void GetGradients(ElementTransformation &tr, const IntegrationRule &ir, DenseMatrix &grad) const
Extension of GetGradient(...) for a collection of IntegrationPoints.
virtual void ProjectCoefficientGlobalL2(Coefficient &coeff, real_t rtol=1e-12, int iter=1000)
Project coeff Coefficient to this GridFunction. The projection is a global L2 projection....
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.
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
Definition gridfunc.cpp:169
FiniteElementCollection * OwnFEC()
Definition gridfunc.hpp:162
virtual PLBound GetBounds(Vector &lower, Vector &upper, const int ref_factor=1, const int vdim=-1) const
virtual void MakeRef(FiniteElementSpace *f, real_t *v)
Make the GridFunction reference external data on a new FiniteElementSpace.
Definition gridfunc.cpp:235
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:187
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:253
virtual real_t ComputeL1Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const
Returns ||u_ex - u_h||_L1 for H1 or L2 elements.
virtual void ProjectDiscCoefficient(std::variant< Coefficient *, VectorCoefficient * > coeff)
Project a discontinuous (vector) coefficient as a grid function on a continuous finite element space....
Definition gridfunc.hpp:94
void SetFromTrueVector()
Shortcut for calling SetFromTrueDofs() with GetTrueVector() as argument.
Definition gridfunc.hpp:193
void ProjectBdrCoefficientNormal(Coefficient &coeff, const Array< int > &bdr_attr)
Project the given Coefficient in the normal direction on the boundary.
Definition gridfunc.hpp:721
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:136
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.
PLBound GetElementBounds(Vector &lower, Vector &upper, const int ref_factor=1, const int vdim=-1) const
const Vector & GetTrueVector() const
Read only access to the (optional) internal true-dof Vector.
Definition gridfunc.hpp:173
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:160
Vector & GetTrueVector()
Read and write access to the (optional) internal true-dof Vector.
Definition gridfunc.hpp:180
void ProjectTraceCoefficientNormal(VectorCoefficient &vcoeff)
Project a VectorCoefficient on a GridFunction defined on an RT trace space.
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:363
virtual void GetElementDofValues(int el, Vector &dof_vals) const
virtual void ProjectDiscCoefficient(std::variant< Coefficient *, VectorCoefficient * > coeff, Array< int > &dof_attr)
Project a discontinuous (vector) coefficient as a grid function on a continuous finite element space....
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:117
void GetGradients(const int elem, const IntegrationRule &ir, DenseMatrix &grad) const
Extension of GetGradient(...) for a collection of IntegrationPoints.
Definition gridfunc.hpp:391
void SaveSTLTri(std::ostream &out, real_t p1[], real_t p2[], real_t p3[])
GridFunction(FiniteElementSpace *f, MemoryType mt)
Same as above but specify the memory type.
Definition gridfunc.hpp:121
virtual void ComputeElementMaxErrors(VectorCoefficient &exsol, Vector &error, const IntegrationRule *irs[]=NULL) const
Returns Max|u_ex - u_h| elementwise for vector fields.
void AccumulateAndCountTraceValues(Coefficient *coeff[], VectorCoefficient *vcoeff, Array< int > &values_counter)
std::pair< real_t, real_t > EstimateFunctionMinimum(const int elem, const PLBound &plb, const int vdim, const int max_depth, const real_t tol, real_t &min_threshold) const
Estimate the minimum value of the GridFunction in element elem if it is below a certain min_threshold...
void ComputeMeans(AvgType type, const Array< int > &zones_per_vdof)
int GetFaceVectorValues(int i, int side, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
std::pair< real_t, real_t > EstimateFunctionMaximum(const int elem, const PLBound &plb, const int vdim, const int max_depth, const real_t tol, real_t &max_threshold) const
Estimate the maximum value of the GridFunction in element elem if it is above a certain max_threshold...
void ProjectTraceCoefficient(Coefficient *coeff[])
Project a Coefficient on a GridFunction defined on H1 trace space.
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 SaveVTKHDF(const std::string &fname, const std::string &name="u", bool high_order=true, int ref=-1)
Save the GridFunction in VTKHDF format.
void LegacyNCReorder()
Loading helper.
void ProjectDeltaCoefficient(DeltaCoefficient &delta_coeff, real_t &integral)
virtual void ComputeFlux(BilinearFormIntegrator &blfi, GridFunction &flux, bool wcoef=true, int subdomain=-1)
Definition gridfunc.cpp:333
virtual void ProjectCoefficientElementL2(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection is an element local L2 projection,...
FiniteElementSpace * fes
FE space on which the grid function lives. Owned if fec_owned is not NULL.
Definition gridfunc.hpp:56
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.hpp:166
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.
void AccumulateAndCountTraceTangentValues(VectorCoefficient &vcoeff, Array< int > &values_counter)
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:637
FiniteElementCollection * fec_owned
Used when the grid function is read from a file. It can also be set explicitly, see MakeOwner().
Definition gridfunc.hpp:62
int CurlDim() const
Shortcut for calling FiniteElementSpace::GetCurlDim() on the underlying fes.
Definition gridfunc.hpp:170
void ProjectTraceCoefficientTangent(VectorCoefficient &vcoeff)
Project a VectorCoefficient on a GridFunction defined on an ND trace space.
virtual real_t ComputeMaxError(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const
Returns Max|u_ex - u_h| error for vector fields.
void SumFluxAndCount(BilinearFormIntegrator &blfi, GridFunction &flux, Array< int > &counts, bool wcoef, int subdomain)
Definition gridfunc.cpp:283
GridFunction & operator=(const GridFunction &rhs)
Copy assignment. Only the data of the base class Vector is copied.
Definition gridfunc.hpp:154
virtual real_t ComputeDivError(Coefficient *exdiv, const IntegrationRule *irs[]=NULL) const
Returns ||div u_ex - div u_h||_L2 for RT elements.
void ProjectBdrCoefficientNormal(Coefficient *coeff, VectorCoefficient *vcoeff, const Array< int > &attr)
virtual void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
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 GetElementBoundsAtControlPoints(const int elem, const PLBound &plb, Vector &lower, Vector &upper, const int vdim=-1) const
void GetTrueDofs(Vector &tv) const
Extract the true-dofs from the GridFunction.
Definition gridfunc.cpp:348
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...
void ProjectCoefficientElementL2_(Coefficient &coeff, Vector &sol, Vector &Va)
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 at the vertices of element i for the 1-based dimension vdim.
Definition gridfunc.cpp:377
virtual void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const
Definition gridfunc.cpp:454
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)
Project the normal component of the given VectorCoefficient on the boundary.
Definition gridfunc.hpp:713
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:227
void GetHessians(int i, const IntegrationRule &ir, DenseMatrix &hess, int vdim=1) const
Definition gridfunc.cpp:581
void GetVectorValues(int i, const IntegrationRule &ir, DenseMatrix &vals, DenseMatrix &tr) const
Definition gridfunc.cpp:687
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:672
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:96
JumpScaling(real_t nu_=1.0, JumpScalingType type_=CONSTANT)
real_t Eval(real_t h, int p) const
Mesh data type.
Definition mesh.hpp:67
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.
int GetVDim()
Returns dimension of the vector.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
Class used for extruding a vector coefficient.
void Eval(Vector &v, ElementTransformation &T, const IntegrationPoint &ip) override
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
VectorExtrudeCoefficient(Mesh *m, VectorCoefficient &s, int n_)
Constructs an instance of VectorExtrudeCoefficient.
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:148
int Size() const
Returns the size of the vector.
Definition vector.hpp:234
void MakeRef(Vector &base, int offset, int size)
Reset the Vector to be a reference to a sub-vector of base.
Definition vector.hpp:709
int dim
Definition ex24.cpp:53
real_t weight(const Vector &x)
std::ostream & operator<<(std::ostream &os, SparseMatrix const &mat)
ProjectType
This enumerated type describes the main projection types used by GridFunction::ProjectCoefficient():
Definition gridfunc.hpp:49
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.
GridFunction * Extrude1DGridFunction(Mesh *mesh, Mesh *mesh2d, GridFunction *sol, const int ny)
Extrude a 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.
QVectorLayout
Type describing possible layouts for Q-vectors.
Definition fespace.hpp:33
float real_t
Definition config.hpp:46
MemoryType
Memory types supported by MFEM.
std::function< real_t(const Vector &)> f(real_t mass_coeff)
Definition lor_mms.hpp:30
constexpr real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
Definition vector.hpp:47
real_t p(const Vector &x, real_t t)
real_t sol(const Vector &x)