https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMQuadratureFunctionCoefficientBase.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#ifdef MOOSE_MFEM_ENABLED
11
13#include "MooseError.h"
14
15namespace
16{
17
18bool
19SamePoint(const mfem::IntegrationPoint & a, const mfem::IntegrationPoint & b, const int dim)
20{
21 Point p(a.x, dim > 1 ? a.y : 0, dim > 2 ? a.z : 0);
22 Point q(b.x, dim > 1 ? b.y : 0, dim > 2 ? b.z : 0);
23 return MooseUtils::absoluteFuzzyEqual(p, q) && MooseUtils::absoluteFuzzyEqual(a.weight, b.weight);
24}
25}
26
27void
29 mfem::ElementTransformation & T,
30 const mfem::IntegrationPoint & ip) const
31{
32 const mfem::QuadratureSpaceBase & qspace = *qf.GetSpace();
33 const int el_idx = qspace.GetEntityIndex(T);
34 // Entity not in this space (e.g. a boundary evaluation)
35 if (el_idx < 0)
36 return;
37
38 const mfem::Geometry::Type geom = qspace.GetGeometry(el_idx);
39 const int dim = mfem::Geometry::Dimension[geom];
40 const mfem::IntegrationRule & stored_rule = qspace.GetIntRule(el_idx);
41 // Fast path: the consuming integrator's point at this index coincides with the stored rule's,
42 // so the rules match.
43 if (ip.index < stored_rule.Size() && SamePoint(stored_rule.IntPoint(ip.index), ip, dim))
44 return;
45
46 // Rules differ. Recover the quadrature order the coefficient should have used by finding the
47 // lowest order whose rule for this geometry reproduces the consuming integrator's point at
48 // ip.index. This runs only on the error path.
49 const int stored_order = qspace.GetOrder();
50 int suggested_order = -1;
51 // The consuming integrator's order is not known here, but is realistically bounded. The upper
52 // limit is just a generous finite cap so this error-path search always terminates: a multiple
53 // of the stored order, plus a constant so low-order stored rules still search far enough. If the
54 // true order somehow exceeds the cap, suggested_order stays -1 and a generic message is emitted.
55 for (int order = 0; order <= 2 * stored_order + 64; ++order)
56 {
57 const mfem::IntegrationRule & candidate = mfem::IntRules.Get(geom, order);
58 if (ip.index < candidate.Size() && SamePoint(candidate.IntPoint(ip.index), ip, dim))
59 {
60 suggested_order = order;
61 break;
62 }
63 }
64
65 if (suggested_order >= 0)
66 mooseError("MFEM quadrature function '",
67 _name,
68 "' stores values on the order-",
69 stored_order,
70 " quadrature rule (",
71 stored_rule.Size(),
72 " points on this element), but it is being evaluated by an integrator using a "
73 "different quadrature rule (",
74 mfem::IntRules.Get(geom, suggested_order).Size(),
75 " points). The stored values are indexed by quadrature point, so the orders must "
76 "match. Set 'order = ",
77 suggested_order,
78 "' on '",
79 _name,
80 "'.");
81 else
82 mooseError("MFEM quadrature function '",
83 _name,
84 "' stores values on the order-",
85 stored_order,
86 " quadrature rule, but it is being evaluated by an integrator using a different "
87 "quadrature rule. The stored values are indexed by quadrature point, so the orders "
88 "must match; adjust 'order' on '",
89 _name,
90 "' to match the consuming integrator.");
91}
92
93#endif
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int dim
const std::string _name
Name of the owning MOOSE object, used in error messages.
void CheckIntegrationRule(const mfem::QuadratureFunction &qf, mfem::ElementTransformation &T, const mfem::IntegrationPoint &ip) const
Verify that the integration point ip supplied by a consuming integrator belongs to the same quadratur...