MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
pgridfunc.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_PGRIDFUNC
13#define MFEM_PGRIDFUNC
14
15#include "../config/config.hpp"
16
17#ifdef MFEM_USE_MPI
18
20#include "pfespace.hpp"
21#include "gridfunc.hpp"
22#include <iostream>
23#include <limits>
24
25namespace mfem
26{
27
28/// @brief Compute a global Lp norm from the local Lp norms computed by each
29/// processor
30///
31/// @param[in] p Real value indicating the exponent of the $L^p$ norm.
32/// To avoid domain errors p should have a positive
33/// value, either finite or infinite.
34/// @param[in] loc_norm Local $L^p$ norm as computed separately on each
35/// processor.
36/// @param[in] comm MPI Communicator
37///
38/// @return Global $L^p$ norm, returned on every processor
39///
40/// @note Quadratures with negative weights (as in some simplex integration
41/// rules in MFEM) can produce negative integrals even with
42/// non-negative integrands. To avoid returning negative norms this
43/// function uses the absolute values of the local norms.
44/// This may lead to results which are not entirely consistent with
45/// such integration rules.
46real_t GlobalLpNorm(const real_t p, real_t loc_norm, MPI_Comm comm);
47
48/// Class for parallel grid function
50{
51protected:
52 ParFiniteElementSpace *pfes; ///< Points to the same object as #fes
53
54 /** @brief Vector used to store data from face-neighbor processors,
55 initialized by ExchangeFaceNbrData(). */
57
58 /** @brief Vector used as an MPI buffer to send face-neighbor data
59 in ExchangeFaceNbrData() to neighboring processors. */
60 //TODO: Use temporary memory to avoid CUDA malloc allocation cost.
62
64 const Array<int> &attr);
65
66 /** @brief Project a discontinuous (vector) coefficient as a grid function on
67 a continuous finite element space. The values in shared dofs are
68 determined from the element with maximal attribute. */
69 virtual void ProjectDiscCoefficient(
70 std::variant<Coefficient*, VectorCoefficient*> coeff) override;
71
72public:
73 ParGridFunction() { pfes = NULL; }
74
75 /// Copy constructor. The internal vector #face_nbr_data is not copied.
77 : GridFunction(orig), pfes(orig.pfes) { }
78
80
81 /// Same as above but specify the device memory type
84
85 /// Construct a ParGridFunction using previously allocated array @a data.
86 /** The ParGridFunction does not assume ownership of @a data which is assumed
87 to be of size at least `pf->GetVSize()`. Similar to the GridFunction and
88 Vector constructors for externally allocated array, the pointer @a data
89 can be NULL. The data array can be replaced later using the method
90 SetData().
91 */
94
95 /** @brief Construct a ParGridFunction using previously allocated Vector
96 @a base starting at the given offset, @a base_offset. */
97 ParGridFunction(ParFiniteElementSpace *pf, Vector &base, int base_offset = 0)
98 : GridFunction(pf, base, base_offset), pfes(pf) { }
99
100 /// Construct a ParGridFunction using a GridFunction as external data.
101 /** The parallel space @a *pf and the space used by @a *gf should match. The
102 data from @a *gf is used as the local data of the ParGridFunction on each
103 processor. The ParGridFunction does not assume ownership of the data.
104 The boolean, @a preserve, indicates that the data stored in @a *gf should
105 remain unchanged. An error will occur if @a preserve is true and
106 construction of a valid ParGridFunction requires the data to change. */
108 bool preserve = true);
109
110 /** @brief Creates grid function on (all) dofs from a given vector on the
111 true dofs, i.e. P tv. */
113
114 /** @brief Construct a local ParGridFunction from the given *global*
115 GridFunction. If @a partitioning is NULL (default), the data from @a gf
116 is NOT copied. */
117 ParGridFunction(ParMesh *pmesh, const GridFunction *gf,
118 const int *partitioning = NULL);
119
120 /** @brief Construct a ParGridFunction on a given ParMesh, @a pmesh, reading
121 from an std::istream.
122
123 In the process, a ParFiniteElementSpace and a FiniteElementCollection are
124 constructed. The new ParGridFunction assumes ownership of both. */
125 ParGridFunction(ParMesh *pmesh, std::istream &input);
126
127 /// Copy assignment. Only the data of the base class Vector is copied.
128 /** It is assumed that this object and @a rhs use ParFiniteElementSpace%s
129 that have the same size.
130
131 @note Defining this method overwrites the implicitly defined copy
132 assignment operator. */
134 { return operator=((const Vector &)rhs); }
135
136 /// Assign constant values to the ParGridFunction data.
138 { GridFunction::operator=(value); return *this; }
139
140 /// Copy the data from a Vector to the ParGridFunction data.
142 { GridFunction::operator=(v); return *this; }
143
145
146 void Update() override;
147
148 /// Associate a new FiniteElementSpace with the ParGridFunction.
149 /** The ParGridFunction is resized using the SetSize() method. The new space
150 @a f is expected to be a ParFiniteElementSpace. */
151 void SetSpace(FiniteElementSpace *f) override;
152
153 /// Associate a new parallel space with the ParGridFunction.
155
157
158 /** @brief Make the ParGridFunction reference external data on a new
159 FiniteElementSpace. */
160 /** This method changes the FiniteElementSpace associated with the
161 ParGridFunction and sets the pointer @a v as external data in the
162 ParGridFunction. The new space @a f is expected to be a
163 ParFiniteElementSpace. */
164 void MakeRef(FiniteElementSpace *f, real_t *v) override;
165
166 /** @brief Make the ParGridFunction reference external data on a new
167 ParFiniteElementSpace. */
168 /** This method changes the ParFiniteElementSpace associated with the
169 ParGridFunction and sets the pointer @a v as external data in the
170 ParGridFunction. */
172
173 /** @brief Make the ParGridFunction reference external data on a new
174 FiniteElementSpace. */
175 /** This method changes the FiniteElementSpace associated with the
176 ParGridFunction and sets the data of the Vector @a v (plus the @a
177 v_offset) as external data in the ParGridFunction. The new space @a f is
178 expected to be a ParFiniteElementSpace.
179 @note This version of the method will also perform bounds checks when
180 the build option MFEM_DEBUG is enabled. */
181 void MakeRef(FiniteElementSpace *f, Vector &v, int v_offset) override;
182
183 /** @brief Make the ParGridFunction reference external data on a new
184 ParFiniteElementSpace. */
185 /** This method changes the ParFiniteElementSpace associated with the
186 ParGridFunction and sets the data of the Vector @a v (plus the
187 @a v_offset) as external data in the ParGridFunction.
188 @note This version of the method will also perform bounds checks when
189 the build option MFEM_DEBUG is enabled. */
190 void MakeRef(ParFiniteElementSpace *f, Vector &v, int v_offset);
191
192 /** Set the grid function on (all) dofs from a given vector on the
193 true dofs, i.e. P tv. */
194 void Distribute(const Vector *tv);
195 void Distribute(const Vector &tv) { Distribute(&tv); }
196 void AddDistribute(real_t a, const Vector *tv);
197 void AddDistribute(real_t a, const Vector &tv) { AddDistribute(a, &tv); }
198
199 /// Set the GridFunction from the given true-dof vector.
200 void SetFromTrueDofs(const Vector &tv) override { Distribute(tv); }
201
202 /// Short semantic for Distribute()
204 { Distribute(&tv); return (*this); }
205
207
208 /// Returns the true dofs in a new HypreParVector
210
211 /// Returns the vector averaged on the true dofs.
212 void ParallelAverage(Vector &tv) const;
213
214 /// Returns the vector averaged on the true dofs.
215 void ParallelAverage(HypreParVector &tv) const;
216
217 /// Returns a new vector averaged on the true dofs.
219
220 /// Returns the vector restricted to the true dofs.
221 void ParallelProject(Vector &tv) const;
222
223 /// Returns the vector restricted to the true dofs.
224 void ParallelProject(HypreParVector &tv) const;
225
226 /// Returns a new vector restricted to the true dofs.
228
229 /// Returns the vector assembled on the true dofs.
230 void ParallelAssemble(Vector &tv) const;
231
232 /// Returns the vector assembled on the true dofs.
233 void ParallelAssemble(HypreParVector &tv) const;
234
235 /// Returns a new vector assembled on the true dofs.
237
238 void ExchangeFaceNbrData();
240 const Vector &FaceNbrData() const { return face_nbr_data; }
241
242 // Redefine to handle the case when i is a face-neighbor element
243 real_t GetValue(int i, const IntegrationPoint &ip,
244 int vdim = 1) const override;
247
248 // Redefine to handle the case when T describes a face-neighbor element
250 int comp = 0, Vector *tr = NULL) const override;
251
252 void GetVectorValue(int i, const IntegrationPoint &ip,
253 Vector &val) const override;
254
255 // Redefine to handle the case when T describes a face-neighbor element
257 const IntegrationPoint &ip,
258 Vector &val, Vector *tr = NULL) const override;
259
260 /** @brief For each vdof, counts how many elements contain the vdof,
261 as containment is determined by FiniteElementSpace::GetElementVDofs(). */
262 void CountElementsPerVDof(Array<int> &elem_per_vdof) const override;
263
264 /// Parallel version of GridFunction::GetDerivative(); see its documentation.
265 void GetDerivative(int comp, int der_comp, ParGridFunction &der) const;
266
267 /** Sets the output vector @a dof_vals to the values of the degrees of
268 freedom of element @a el. If @a el is greater than or equal to the number
269 of local elements, it will be interpreted as a shifted index of a face
270 neighbor element. */
271 void GetElementDofValues(int el, Vector &dof_vals) const override;
272
275 ProjectType type = ProjectType::DEFAULT) override;
276
278 ProjectType type = ProjectType::DEFAULT) override;
279
281 void ProjectDiscCoefficient(Coefficient &coeff, AvgType type) override;
282
283 void ProjectDiscCoefficient(VectorCoefficient &vcoeff, AvgType type) override;
284
286
288 const Array<int> &attr) override;
289
291 const Array<int> &attr) override
292 { ProjectBdrCoefficient(coeff, NULL, attr); }
293
295 const Array<int> &bdr_attr) override;
296
298 real_t rtol = 1e-12,
299 int iter = 1000) override;
300
301 void ProjectCoefficientElementL2(Coefficient &coeff) override;
302
304 real_t rtol = 1e-12,
305 int iter = 1000) override;
306
307 void ProjectCoefficientElementL2(VectorCoefficient &vcoeff) override;
308
309 /// @brief Returns ||u_ex - u_h||_L1 in parallel for H1 or L2 elements
310 ///
311 /// @see GridFunction::ComputeL1Error(Coefficient *exsol[],
312 /// const IntegrationRule *irs[]) const
313 /// for more detailed documentation.
314 ///
315 /// @warning While this function is nominally equivalent to ComputeLpError,
316 /// with appropriate arguments, the returned errors may differ
317 /// noticeably because ComputeLpError uses a higher order
318 /// integration rule by default.
319 ///
320 /// @deprecated See @ref ComputeL1Error(Coefficient &exsol,
321 /// const IntegrationRule *irs[]) const
322 /// for the preferred implementation.
323 MFEM_DEPRECATED
325 const IntegrationRule *irs[] = NULL) const override
326 {
327#ifdef MFEM_HAVE_GCC_PRAGMA_DIAGNOSTIC
328#pragma GCC diagnostic push
329#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
330#endif
331 real_t glb_err = GlobalLpNorm(1.0,
333 pfes->GetComm());
334#ifdef MFEM_HAVE_GCC_PRAGMA_DIAGNOSTIC
335#pragma GCC diagnostic pop
336#endif
337 return glb_err;
338 }
339
340 /// @brief Returns ||u_ex - u_h||_L1 in parallel for scalar fields
341 ///
342 /// @see GridFunction::ComputeL1Error(Coefficient &exsol,
343 /// const IntegrationRule *irs[]) const
344 /// for more detailed documentation.
346 const IntegrationRule *irs[] = NULL) const override
347 { return ComputeLpError(1.0, exsol, NULL, irs); }
348
349 /// @brief Returns ||u_ex - u_h||_L1 in parallel for vector fields
350 ///
351 /// @see GridFunction::ComputeL1Error(VectorCoefficient &exsol,
352 /// const IntegrationRule *irs[]) const
353 /// for more detailed documentation.
355 const IntegrationRule *irs[] = NULL) const override
356 { return ComputeLpError(1.0, exsol, NULL, NULL, irs); }
357
358 /// @brief Returns ||u_ex - u_h||_L2 in parallel for H1 or L2 elements
359 ///
360 /// @see GridFunction::ComputeL2Error(Coefficient *exsol[],
361 /// const IntegrationRule *irs[],
362 /// const Array<int> *elems) const
363 /// for more detailed documentation.
365 const IntegrationRule *irs[] = NULL,
366 const Array<int> *elems = NULL) const override
367 {
368 return GlobalLpNorm(2.0, GridFunction::ComputeL2Error(exsol, irs, elems),
369 pfes->GetComm());
370 }
371
372 /// @brief Returns ||u_ex - u_h||_L2 in parallel for scalar fields
373 ///
374 /// @see GridFunction::ComputeL2Error(Coefficient &exsol,
375 /// const IntegrationRule *irs[],
376 /// const Array<int> *elems) const
377 /// for more detailed documentation.
379 const IntegrationRule *irs[] = NULL,
380 const Array<int> *elems = NULL) const override
381 {
382 return GlobalLpNorm(2.0, GridFunction::ComputeL2Error(exsol, irs, elems),
383 pfes->GetComm());
384 }
385
386 /// @brief Returns ||u_ex - u_h||_L2 in parallel for vector fields
387 ///
388 /// @see GridFunction::ComputeL2Error(VectorCoefficient &exsol,
389 /// const IntegrationRule *irs[],
390 /// const Array<int> *elems) const
391 /// for more detailed documentation.
393 const IntegrationRule *irs[] = NULL,
394 const Array<int> *elems = NULL) const override
395 {
396 return GlobalLpNorm(2.0, GridFunction::ComputeL2Error(exsol, irs, elems),
397 pfes->GetComm());
398 }
399
400 /// @brief Returns ||grad u_ex - grad u_h||_L2 in parallel for H1 or L2
401 /// elements
402 ///
403 /// @see GridFunction::ComputeGradError(VectorCoefficient *exgrad,
404 /// const IntegrationRule *irs[]) const
405 /// for more detailed documentation.
407 const IntegrationRule *irs[] = NULL) const override
408 {
409 return GlobalLpNorm(2.0, GridFunction::ComputeGradError(exgrad,irs),
410 pfes->GetComm());
411 }
412
413 /// @brief Returns ||curl u_ex - curl u_h||_L2 in parallel for ND elements
414 ///
415 /// @see GridFunction::ComputeCurlError(VectorCoefficient *excurl,
416 /// const IntegrationRule *irs[]) const
417 /// for more detailed documentation.
419 const IntegrationRule *irs[] = NULL) const override
420 {
421 return GlobalLpNorm(2.0, GridFunction::ComputeCurlError(excurl,irs),
422 pfes->GetComm());
423 }
424
425 /// @brief Returns ||div u_ex - div u_h||_L2 in parallel for RT elements
426 ///
427 /// @see GridFunction::ComputeDivError(Coefficient *exdiv,
428 /// const IntegrationRule *irs[]) const
429 /// for more detailed documentation.
431 const IntegrationRule *irs[] = NULL) const override
432 {
433 return GlobalLpNorm(2.0, GridFunction::ComputeDivError(exdiv,irs),
434 pfes->GetComm());
435 }
436
437 /// @brief Returns the Face Jumps error for L2 elements.
438 ///
439 /// Computes:
440 /// $$\sqrt{\sum_{faces} \int_f js[f] ell[f] (2 u_{ex} - u_1 - u_2)^2}$$
441 ///
442 /// Where js[f] is the jump_scaling evaluated on the face f and ell is the
443 /// average of ell_coef evaluated in the two elements sharing the face f.
444 ///
445 /// @param[in] exsol Pointer to a Coefficient object reproducing the
446 /// anticipated values of the scalar field, u_ex.
447 /// @param[in] ell_coeff Pointer to a Coefficient object used to compute
448 /// the averaged value ell in the above integral.
449 /// @param[in] jump_scaling Can be configured to provide scaling by
450 /// nu, nu/h, or nu*p^2/h
451 /// @param[in] irs Optional pointer to a custom integration rule
452 /// e.g. higher order than the default rule.
453 ///
454 /// @note Quadratures with negative weights (as in some simplex integration
455 /// rules in MFEM) can produce negative integrals even with
456 /// non-negative integrands. To avoid returning negative errors this
457 /// function uses the absolute values of the element-wise integrals.
458 /// This may lead to results which are not entirely consistent with
459 /// such integration rules.
461 Coefficient *ell_coeff,
462 JumpScaling jump_scaling,
463 const IntegrationRule *irs[]=NULL
464 ) const override;
465
466 /// Returns either the H1-seminorm or the DG Face Jumps error or both
467 /// depending on norm_type = 1, 2, 3
468 ///
469 /// @see GridFunction::ComputeH1Error(Coefficient *exsol,
470 /// VectorCoefficient *exgrad,
471 /// Coefficient *ell_coef,
472 /// real_t NU,
473 /// int norm_type) const
474 /// for more detailed documentation.
476 Coefficient *ell_coef, real_t Nu,
477 int norm_type) const override
478 {
479 return GlobalLpNorm(2.0,
480 GridFunction::ComputeH1Error(exsol,exgrad,ell_coef,
481 Nu, norm_type),
482 pfes->GetComm());
483 }
484
485 /// @brief Returns the error measured in H1-norm in parallel for H1 or L2
486 /// elements
487 ///
488 /// @see GridFunction::ComputeH1Error(Coefficient *exsol,
489 /// VectorCoefficient *exgrad,
490 /// const IntegrationRule *irs[]) const
491 /// for more detailed documentation.
493 const IntegrationRule *irs[] = NULL) const override
494 {
495 return GlobalLpNorm(2.0, GridFunction::ComputeH1Error(exsol,exgrad,irs),
496 pfes->GetComm());
497 }
498
499 /// @brief Returns the error measured H(div)-norm in parallel for RT elements
500 ///
501 /// @see GridFunction::ComputeHDivError(VectorCoefficient *exsol,
502 /// Coefficient *exdiv,
503 /// const IntegrationRule *irs[]) const
504 /// for more detailed documentation.
506 Coefficient *exdiv,
507 const IntegrationRule *irs[] = NULL) const override
508 {
509 return GlobalLpNorm(2.0, GridFunction::ComputeHDivError(exsol,exdiv,irs),
510 pfes->GetComm());
511 }
512
513 /// @brief Returns the error measured H(curl)-norm in parallel for ND
514 /// elements
515 ///
516 /// @see GridFunction::ComputeHCurlError(VectorCoefficient *exsol,
517 /// VectorCoefficient *excurl,
518 /// const IntegrationRule *irs[]) const
519 /// for more detailed documentation.
521 VectorCoefficient *excurl,
522 const IntegrationRule *irs[] = NULL) const override
523 {
524 return GlobalLpNorm(2.0,
525 GridFunction::ComputeHCurlError(exsol,excurl,irs),
526 pfes->GetComm());
527 }
528
529 /// @brief Returns Max|u_ex - u_h| error in parallel for scalar or vector
530 /// fields
531 ///
532 /// @note This implementation of the max error of a vector field computes
533 /// the max norm over vector components rather than the magnitude of
534 /// the vector.
535 ///
536 /// @see GridFunction::ComputeMaxError(Coefficient *exsol[],
537 /// const IntegrationRule *irs[]) const
538 /// for more detailed documentation.
540 const IntegrationRule *irs[] = NULL) const override
541 {
542 return GlobalLpNorm(infinity(),
544 pfes->GetComm());
545 }
546
547 /// @brief Returns Max|u_ex - u_h| error in parallel for scalar fields
548 ///
549 /// @see GridFunction::ComputeMaxError(Coefficient &exsol,
550 /// const IntegrationRule *irs[]) const
551 /// for more detailed documentation.
553 const IntegrationRule *irs[] = NULL) const override
554 {
555 return ComputeLpError(infinity(), exsol, NULL, irs);
556 }
557
558 /// @brief Returns Max|u_ex - u_h| error in parallel for vector fields
559 ///
560 /// @see GridFunction::ComputeMaxError(VectorCoefficient &exsol,
561 /// const IntegrationRule *irs[]) const
562 /// for more detailed documentation.
564 const IntegrationRule *irs[] = NULL) const override
565 {
566 return ComputeLpError(infinity(), exsol, NULL, NULL, irs);
567 }
568
569 /// @brief Returns ||u_ex - u_h||_Lp in parallel for scalar fields
570 ///
571 /// @see GridFunction::ComputeLpError(const real_t p,
572 /// Coefficient &exsol,
573 /// Coefficient *weight,
574 /// const IntegrationRule *irs[],
575 /// const Array<int> *elems) const
576 /// for more detailed documentation.
578 Coefficient *weight = NULL,
579 const IntegrationRule *irs[] = NULL,
580 const Array<int> *elems = NULL) const override
581 {
583 irs, elems),
584 pfes->GetComm());
585 }
586
587 /// @brief Returns ||u_ex - u_h||_Lp in parallel for vector fields
588 ///
589 /// @see GridFunction::ComputeLpError(const real_t p,
590 /// VectorCoefficient &exsol,
591 /// Coefficient *weight,
592 /// VectorCoefficient *v_weight,
593 /// const IntegrationRule *irs[]) const
594 /// for more detailed documentation.
596 Coefficient *weight = NULL,
597 VectorCoefficient *v_weight = NULL,
598 const IntegrationRule *irs[] = NULL) const override
599 {
601 p, exsol, weight, v_weight, irs), pfes->GetComm());
602 }
603
605 GridFunction &flux,
606 bool wcoef = true, int subdomain = -1) override;
607
608 /// Computes the PLBound for the gridfunction with number of control
609 /// points based on @a ref_factor, and returns the bounds for each
610 /// vdim across all elements in @b lower and @b upper. We also return the
611 /// PLBound object used to compute the bounds. Note: if vdim < 1, we compute
612 /// the bounds for each vector dimension.
613 PLBound GetBounds(Vector &lower, Vector &upper,
614 const int ref_factor=1, const int vdim=-1) const override;
615
616 /** @brief Estimate the GridFunction minimum across all elements. */
617 std::pair<real_t, real_t> EstimateFunctionMinimum(const int vdim,
618 const PLBound &plb,
619 const int max_depth,
620 const real_t tol) const override;
621
622 /** @brief Estimate the GridFunction maximum across all elements. */
623 std::pair<real_t, real_t> EstimateFunctionMaximum(const int vdim,
624 const PLBound &plb,
625 const int max_depth,
626 const real_t tol) const override;
627
628 /** Save the local portion of the ParGridFunction. This differs from the
629 serial GridFunction::Save in that it takes into account the signs of
630 the local dofs. */
631 void Save(std::ostream &out) const override;
632
633 /// Save the ParGridFunction to a single file (written using MPI rank 0). The
634 /// given @a precision will be used for ASCII output.
635 void SaveAsOne(const char *fname, int precision=16) const;
636
637 /// Save the ParGridFunction to files (one for each MPI rank). The files will
638 /// be given suffixes according to the MPI rank. The given @a precision will
639 /// be used for ASCII output.
640 void Save(const char *fname, int precision=16) const override;
641
642 /// @brief Returns a GridFunction on MPI rank @a save_rank that does not have
643 /// any duplication of vertices/nodes at processor boundaries.
644 ///
645 /// The @a serial_mesh is obtained using ParMesh::GetSerialMesh. Note that
646 /// the @a save_rank must be the same as that used in ParMesh::GetSerialMesh.
647 ///
648 /// @note The returned GridFunction will own the newly created
649 /// FiniteElementCollection and FiniteElementSpace objects.
650 GridFunction GetSerialGridFunction(int save_rank, Mesh &serial_mesh) const;
651
652 /// @brief Returns a GridFunction on MPI rank @a save_rank that does not have
653 /// any duplication of vertices/nodes at processor boundaries.
654 ///
655 /// The given @a serial_fes must be defined on the mesh returned by
656 /// ParMesh::GetSerialMesh (with @a save_rank ranks), for example using the
657 /// space belonging to the GridFunction obtained from @ref
658 /// ParGridFunction::GetSerialGridFunction(int,Mesh &) const.
659 ///
660 /// @note The returned GridFunction does not assume ownership of @a
661 /// serial_fes.
663 int save_rank, FiniteElementSpace &serial_fes) const;
664
665 /// Write the serial GridFunction to a single file (written using MPI rank 0).
666 /// The given @a precision will be used for ASCII output.
667 void SaveAsSerial(const char *fname, int precision=16, int save_rank=0) const;
668
669#ifdef MFEM_USE_ADIOS2
670 /** Save the local portion of the ParGridFunction. This differs from the
671 serial GridFunction::Save in that it takes into account the signs of
672 the local dofs. */
673 void Save(
674 adios2stream &out, const std::string &variable_name,
676 override;
677#endif
678
679 /// Merge the local grid functions
680 void SaveAsOne(std::ostream &out = mfem::out) const;
681
682 /** @brief Return a GridFunction with the values of this, prolongated to the
683 maximum order of all elements in the mesh. */
684 std::unique_ptr<ParGridFunction> ProlongateToMaxOrder() const;
685
686 virtual ~ParGridFunction() = default;
687};
688
689
690/** Performs a global L2 projection (through a HypreBoomerAMG solve) of flux
691 from supplied discontinuous space into supplied smooth (continuous, or at
692 least conforming) space, and computes the Lp norms of the differences
693 between them on each element. This is one approach to handling conforming
694 and non-conforming elements in parallel. Returns the total error estimate. */
696 const ParGridFunction &x,
697 ParFiniteElementSpace &smooth_flux_fes,
698 ParFiniteElementSpace &flux_fes,
699 Vector &errors, int norm_p = 2, real_t solver_tol = 1e-12,
700 int solver_max_it = 200);
701
702}
703
704#endif // MFEM_USE_MPI
705
706#endif
Abstract base class BilinearFormIntegrator.
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
const IntegrationPoint & GetIntPoint()
Get a const reference to the currently set integration point. This will return NULL if no integration...
Definition eltrans.hpp:111
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Definition fespace.hpp:210
Class for grid function - Vector with associated FE space.
Definition gridfunc.hpp:53
virtual real_t ComputeHCurlError(VectorCoefficient *exsol, VectorCoefficient *excurl, const IntegrationRule *irs[]=NULL) const
Returns the error measured in H(curl)-norm for ND elements.
virtual real_t ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad, Coefficient *ell_coef, real_t Nu, int norm_type) const
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 MakeRef(FiniteElementSpace *f, real_t *v)
Make the GridFunction reference external data on a new FiniteElementSpace.
Definition gridfunc.cpp:235
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.
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, 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.
virtual real_t ComputeCurlError(VectorCoefficient *excurl, const IntegrationRule *irs[]=NULL) const
Returns ||curl u_ex - curl u_h||_L2 for ND elements.
virtual real_t ComputeHDivError(VectorCoefficient *exsol, Coefficient *exdiv, const IntegrationRule *irs[]=NULL) const
Returns the error measured in H(div)-norm for RT elements.
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.
virtual void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
void GetTrueDofs(Vector &tv) const
Extract the true-dofs from the GridFunction.
Definition gridfunc.cpp:348
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 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
Wrapper for hypre's parallel vector class.
Definition hypre.hpp:230
Class for integration point with weight.
Definition intrules.hpp:35
Class for an integration rule - an Array of IntegrationPoint.
Definition intrules.hpp:96
Mesh data type.
Definition mesh.hpp:67
Abstract parallel finite element space.
Definition pfespace.hpp:31
MPI_Comm GetComm() const
Definition pfespace.hpp:337
Class for parallel grid function.
Definition pgridfunc.hpp:50
void CountElementsPerVDof(Array< int > &elem_per_vdof) const override
For each vdof, counts how many elements contain the vdof, as containment is determined by FiniteEleme...
void GetDerivative(int comp, int der_comp, ParGridFunction &der) const
Parallel version of GridFunction::GetDerivative(); see its documentation.
real_t ComputeMaxError(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const override
Returns Max|u_ex - u_h| error in parallel for vector fields.
ParGridFunction(ParFiniteElementSpace *pf, Vector &base, int base_offset=0)
Construct a ParGridFunction using previously allocated Vector base starting at the given offset,...
Definition pgridfunc.hpp:97
HypreParVector * ParallelAverage() const
Returns a new vector averaged on the true dofs.
real_t ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad, Coefficient *ell_coef, real_t Nu, int norm_type) const override
real_t ComputeDGFaceJumpError(Coefficient *exsol, Coefficient *ell_coeff, JumpScaling jump_scaling, const IntegrationRule *irs[]=NULL) const override
Returns the Face Jumps error for L2 elements.
void Save(std::ostream &out) const override
real_t ComputeL1Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const override
Returns ||u_ex - u_h||_L1 in parallel for scalar fields.
ParGridFunction(ParFiniteElementSpace *pf, real_t *data)
Construct a ParGridFunction using previously allocated array data.
Definition pgridfunc.hpp:92
real_t ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const override
Returns ||u_ex - u_h||_L2 in parallel for H1 or L2 elements.
void ProjectCoefficient(Coefficient &coeff, ProjectType type=ProjectType::DEFAULT) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
real_t GetValue(int i, const IntegrationPoint &ip, int vdim=1) const override
real_t ComputeH1Error(Coefficient *exsol, VectorCoefficient *exgrad, const IntegrationRule *irs[]=NULL) const override
Returns the error measured in H1-norm in parallel for H1 or L2 elements.
ParGridFunction(ParFiniteElementSpace *pf, MemoryType mt)
Same as above but specify the device memory type.
Definition pgridfunc.hpp:82
const Vector & FaceNbrData() const
HypreParVector * GetTrueDofs() const
Returns the true dofs in a new HypreParVector.
void ProjectCoefficientGlobalL2(Coefficient &coeff, real_t rtol=1e-12, int iter=1000) override
Project coeff Coefficient to this GridFunction. The projection is a global L2 projection....
ParGridFunction(const ParGridFunction &orig)
Copy constructor. The internal vector face_nbr_data is not copied.
Definition pgridfunc.hpp:76
real_t ComputeLpError(const real_t p, Coefficient &exsol, Coefficient *weight=NULL, const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const override
Returns ||u_ex - u_h||_Lp in parallel for scalar fields.
void AddDistribute(real_t a, const Vector &tv)
real_t ComputeLpError(const real_t p, VectorCoefficient &exsol, Coefficient *weight=NULL, VectorCoefficient *v_weight=NULL, const IntegrationRule *irs[]=NULL) const override
Returns ||u_ex - u_h||_Lp in parallel for vector fields.
void SetFromTrueDofs(const Vector &tv) override
Set the GridFunction from the given true-dof vector.
void ComputeFlux(BilinearFormIntegrator &blfi, GridFunction &flux, bool wcoef=true, int subdomain=-1) override
ParGridFunction & operator=(real_t value)
Assign constant values to the ParGridFunction data.
MFEM_DEPRECATED real_t ComputeL1Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const override
Returns ||u_ex - u_h||_L1 in parallel for H1 or L2 elements.
ParGridFunction & operator=(const HypreParVector &tv)
Short semantic for Distribute()
void ProjectBdrCoefficient(Coefficient *coeff[], VectorCoefficient *vcoeff, const Array< int > &attr)
real_t ComputeMaxError(Coefficient &exsol, const IntegrationRule *irs[]=NULL) const override
Returns Max|u_ex - u_h| error in parallel for scalar fields.
real_t ComputeHDivError(VectorCoefficient *exsol, Coefficient *exdiv, const IntegrationRule *irs[]=NULL) const override
Returns the error measured H(div)-norm in parallel for RT elements.
void ProjectBdrCoefficient(Coefficient *coeff[], const Array< int > &attr) override
Project a set of Coefficients on the components of the GridFunction, modifying only DOFs on the bound...
std::pair< real_t, real_t > EstimateFunctionMaximum(const int vdim, const PLBound &plb, const int max_depth, const real_t tol) const override
Estimate the GridFunction maximum across all elements.
ParFiniteElementSpace * pfes
Points to the same object as fes.
Definition pgridfunc.hpp:52
Vector send_data
Vector used as an MPI buffer to send face-neighbor data in ExchangeFaceNbrData() to neighboring proce...
Definition pgridfunc.hpp:61
HypreParVector * ParallelProject() const
Returns a new vector restricted to the true dofs.
HypreParVector * ParallelAssemble() const
Returns a new vector assembled on the true dofs.
void Distribute(const Vector &tv)
std::pair< real_t, real_t > EstimateFunctionMinimum(const int vdim, const PLBound &plb, const int max_depth, const real_t tol) const override
Estimate the GridFunction minimum across all elements.
real_t ComputeL1Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL) const override
Returns ||u_ex - u_h||_L1 in parallel for vector fields.
ParFiniteElementSpace * ParFESpace() const
real_t ComputeL2Error(Coefficient &exsol, const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const override
Returns ||u_ex - u_h||_L2 in parallel for scalar fields.
virtual ~ParGridFunction()=default
void AddDistribute(real_t a, const Vector *tv)
void MakeRef(FiniteElementSpace *f, real_t *v) override
Make the ParGridFunction reference external data on a new FiniteElementSpace.
void GetVectorValue(int i, const IntegrationPoint &ip, Vector &val) const override
real_t ComputeL2Error(VectorCoefficient &exsol, const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const override
Returns ||u_ex - u_h||_L2 in parallel for vector fields.
virtual void ProjectDiscCoefficient(std::variant< Coefficient *, VectorCoefficient * > coeff) override
Project a discontinuous (vector) coefficient as a grid function on a continuous finite element space....
real_t ComputeGradError(VectorCoefficient *exgrad, const IntegrationRule *irs[]=NULL) const override
Returns ||grad u_ex - grad u_h||_L2 in parallel for H1 or L2 elements.
real_t ComputeDivError(Coefficient *exdiv, const IntegrationRule *irs[]=NULL) const override
Returns ||div u_ex - div u_h||_L2 in parallel for RT elements.
void ProjectCoefficientElementL2(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection is an element local L2 projection,...
void SaveAsSerial(const char *fname, int precision=16, int save_rank=0) const
ParGridFunction(ParFiniteElementSpace *pf)
Definition pgridfunc.hpp:79
Vector face_nbr_data
Vector used to store data from face-neighbor processors, initialized by ExchangeFaceNbrData().
Definition pgridfunc.hpp:56
void SaveAsOne(const char *fname, int precision=16) const
GridFunction GetSerialGridFunction(int save_rank, Mesh &serial_mesh) const
Returns a GridFunction on MPI rank save_rank that does not have any duplication of vertices/nodes at ...
PLBound GetBounds(Vector &lower, Vector &upper, const int ref_factor=1, const int vdim=-1) const override
void Update() override
Transform by the Space UpdateMatrix (e.g., on Mesh change).
Definition pgridfunc.cpp:97
real_t ComputeMaxError(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const override
Returns Max|u_ex - u_h| error in parallel for scalar or vector fields.
void SetSpace(FiniteElementSpace *f) override
Associate a new FiniteElementSpace with the ParGridFunction.
real_t ComputeHCurlError(VectorCoefficient *exsol, VectorCoefficient *excurl, const IntegrationRule *irs[]=NULL) const override
Returns the error measured H(curl)-norm in parallel for ND elements.
void Distribute(const Vector *tv)
std::unique_ptr< ParGridFunction > ProlongateToMaxOrder() const
Return a GridFunction with the values of this, prolongated to the maximum order of all elements in th...
void GetElementDofValues(int el, Vector &dof_vals) const override
ParGridFunction & operator=(const Vector &v)
Copy the data from a Vector to the ParGridFunction data.
real_t ComputeCurlError(VectorCoefficient *excurl, const IntegrationRule *irs[]=NULL) const override
Returns ||curl u_ex - curl u_h||_L2 in parallel for ND elements.
void ProjectBdrCoefficientTangent(VectorCoefficient &vcoeff, const Array< int > &bdr_attr) override
Project the tangential components of the given VectorCoefficient on the boundary.
real_t GetValue(ElementTransformation &T)
ParGridFunction & operator=(const ParGridFunction &rhs)
Copy assignment. Only the data of the base class Vector is copied.
Class for parallel meshes.
Definition pmesh.hpp:35
Base class for vector Coefficients that optionally depend on time and space.
Vector data type.
Definition vector.hpp:82
Memory< real_t > data
Definition vector.hpp:85
real_t a
Definition lissajous.cpp:41
real_t weight(const Vector &x)
mfem::real_t real_t
ProjectType
This enumerated type describes the main projection types used by GridFunction::ProjectCoefficient():
Definition gridfunc.hpp:49
real_t L2ZZErrorEstimator(BilinearFormIntegrator &flux_integrator, const ParGridFunction &x, ParFiniteElementSpace &smooth_flux_fes, ParFiniteElementSpace &flux_fes, Vector &errors, int norm_p, real_t solver_tol, int solver_max_it)
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 GlobalLpNorm(const real_t p, real_t loc_norm, MPI_Comm comm)
Compute a global Lp norm from the local Lp norms computed by each processor.
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)