https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
MFEMScalarQuadratureFunctionCoefficient Class Reference

Scalar coefficient holding precomputed values of a source coefficient at the quadrature points of a QuadratureFunction. More...

#include <MFEMScalarQuadratureFunctionCoefficient.h>

Inheritance diagram for MFEMScalarQuadratureFunctionCoefficient:
[legend]

Public Member Functions

 MFEMScalarQuadratureFunctionCoefficient (mfem::Coefficient &source, mfem::QuadratureFunction &qf, UpdatePolicy update_policy, const std::string &name)
 
void SetTime (mfem::real_t t) override
 Set the time for the coefficient, invalidating the stored values unless the update policy is NONE. More...
 
mfem::real_t Eval (mfem::ElementTransformation &T, const mfem::IntegrationPoint &ip) override
 Return the stored value at ip, re-projecting the source first if invalidated. More...
 
void Project (mfem::QuadratureFunction &qf) override
 Copy the stored values into qf, re-projecting the source first if invalidated. More...
 
 CreateMooseEnumClass (UpdatePolicy, NONE, TIME, NONLINEAR)
 Policy controlling when the stored values are re-projected from the source coefficient. More...
 
void MarkSolutionChanged ()
 Mark the stored values as stale following a change of solution variables, forcing the source to be re-projected on next use. More...
 

Protected Member Functions

void MarkTimeChanged ()
 Mark the stored values as stale following a change of time. More...
 
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 quadrature rule the values in qf are stored on. More...
 

Protected Attributes

const UpdatePolicy _update_policy
 When the stored values are re-projected from the source coefficient. More...
 
const std::string _name
 Name of the owning MOOSE object, used in error messages. More...
 
bool _dirty
 Whether the stored values are stale and must be re-projected before use. More...
 

Private Member Functions

void Refresh ()
 Project the source coefficient into the quadrature function if invalidated. More...
 

Private Attributes

mfem::Coefficient & _source
 Source coefficient the stored values are projected from. More...
 
mfem::QuadratureFunction & _qf
 Storage for the projected values, shared with the owning MOOSE object. More...
 

Detailed Description

Scalar coefficient holding precomputed values of a source coefficient at the quadrature points of a QuadratureFunction.

The stored values are (re)projected lazily: evaluation triggers a projection of the source coefficient only if the values have been invalidated since the last projection.

Definition at line 27 of file MFEMScalarQuadratureFunctionCoefficient.h.

Constructor & Destructor Documentation

◆ MFEMScalarQuadratureFunctionCoefficient()

MFEMScalarQuadratureFunctionCoefficient::MFEMScalarQuadratureFunctionCoefficient ( mfem::Coefficient &  source,
mfem::QuadratureFunction &  qf,
UpdatePolicy  update_policy,
const std::string &  name 
)

Definition at line 15 of file MFEMScalarQuadratureFunctionCoefficient.C.

20  : mfem::QuadratureFunctionCoefficient(qf),
21  MFEMQuadratureFunctionCoefficientBase(update_policy, name),
22  _source(source),
23  _qf(qf)
24 {
25 }
MFEMQuadratureFunctionCoefficientBase(UpdatePolicy update_policy, const std::string &name)
mfem::Coefficient & _source
Source coefficient the stored values are projected from.
mfem::QuadratureFunction & _qf
Storage for the projected values, shared with the owning MOOSE object.

Member Function Documentation

◆ CheckIntegrationRule()

void MFEMQuadratureFunctionCoefficientBase::CheckIntegrationRule ( const mfem::QuadratureFunction &  qf,
mfem::ElementTransformation &  T,
const mfem::IntegrationPoint &  ip 
) const
protectedinherited

Verify that the integration point ip supplied by a consuming integrator belongs to the same quadrature rule the values in qf are stored on.

Errors, naming the quadrature order the coefficient should use, if the rules do not match. The stored values are indexed by quadrature point, so a mismatched rule would silently read values from the wrong points.

Definition at line 37 of file MFEMQuadratureFunctionCoefficientBase.C.

Referenced by Eval(), and MFEMVectorQuadratureFunctionCoefficient::Eval().

40 {
41  const mfem::QuadratureSpaceBase & qspace = *qf.GetSpace();
42  const int el_idx = qspace.GetEntityIndex(T);
43  // Entity not in this space (e.g. a boundary evaluation)
44  if (el_idx < 0)
45  return;
46 
47  const mfem::Geometry::Type geom = qspace.GetGeometry(el_idx);
48  const int dim = mfem::Geometry::Dimension[geom];
49  const mfem::IntegrationRule & stored_rule = qspace.GetIntRule(el_idx);
50  // Fast path: the consuming integrator's point at this index coincides with the stored rule's,
51  // so the rules match.
52  if (ip.index < stored_rule.Size() && SamePoint(stored_rule.IntPoint(ip.index), ip, dim))
53  return;
54 
55  // Rules differ. Recover the quadrature order the coefficient should have used by finding the
56  // lowest order whose rule for this geometry reproduces the consuming integrator's point at
57  // ip.index. This runs only on the error path.
58  const int stored_order = qspace.GetOrder();
59  int suggested_order = -1;
60  // The consuming integrator's order is not known here, but is realistically bounded. The upper
61  // limit is just a generous finite cap so this error-path search always terminates: a multiple
62  // of the stored order, plus a constant so low-order stored rules still search far enough. If the
63  // true order somehow exceeds the cap, suggested_order stays -1 and a generic message is emitted.
64  for (int order = 0; order <= 2 * stored_order + 64; ++order)
65  {
66  const mfem::IntegrationRule & candidate = mfem::IntRules.Get(geom, order);
67  if (ip.index < candidate.Size() && SamePoint(candidate.IntPoint(ip.index), ip, dim))
68  {
69  suggested_order = order;
70  break;
71  }
72  }
73 
74  if (suggested_order >= 0)
75  mooseError("MFEM quadrature function '",
76  _name,
77  "' stores values on the order-",
78  stored_order,
79  " quadrature rule (",
80  stored_rule.Size(),
81  " points on this element), but it is being evaluated by an integrator using a "
82  "different quadrature rule (",
83  mfem::IntRules.Get(geom, suggested_order).Size(),
84  " points). The stored values are indexed by quadrature point, so the orders must "
85  "match. Set 'order = ",
86  suggested_order,
87  "' on '",
88  _name,
89  "'.");
90  else
91  mooseError("MFEM quadrature function '",
92  _name,
93  "' stores values on the order-",
94  stored_order,
95  " quadrature rule, but it is being evaluated by an integrator using a different "
96  "quadrature rule. The stored values are indexed by quadrature point, so the orders "
97  "must match; adjust 'order' on '",
98  _name,
99  "' to match the consuming integrator.");
100 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:165
const std::string _name
Name of the owning MOOSE object, used in error messages.

◆ CreateMooseEnumClass()

MFEMQuadratureFunctionCoefficientBase::CreateMooseEnumClass ( UpdatePolicy  ,
NONE  ,
TIME  ,
NONLINEAR   
)
inherited

Policy controlling when the stored values are re-projected from the source coefficient.

NONE - the source never changes after initialization; project exactly once. TIME - the source changes with time only; re-project when the time is set. NONLINEAR - the source may additionally depend on solution variables; also re-project whenever trial variables are updated (i.e. on each nonlinear iteration).

◆ Eval()

mfem::real_t MFEMScalarQuadratureFunctionCoefficient::Eval ( mfem::ElementTransformation &  T,
const mfem::IntegrationPoint &  ip 
)
override

Return the stored value at ip, re-projecting the source first if invalidated.

Definition at line 35 of file MFEMScalarQuadratureFunctionCoefficient.C.

37 {
38  if (_dirty)
39  Refresh();
40  CheckIntegrationRule(_qf, T, ip);
41  return mfem::QuadratureFunctionCoefficient::Eval(T, ip);
42 }
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...
void Refresh()
Project the source coefficient into the quadrature function if invalidated.
bool _dirty
Whether the stored values are stale and must be re-projected before use.
mfem::QuadratureFunction & _qf
Storage for the projected values, shared with the owning MOOSE object.

◆ MarkSolutionChanged()

void MFEMQuadratureFunctionCoefficientBase::MarkSolutionChanged ( )
inlineinherited

Mark the stored values as stale following a change of solution variables, forcing the source to be re-projected on next use.

Definition at line 51 of file MFEMQuadratureFunctionCoefficientBase.h.

52  {
54  _dirty = true;
55  }
bool _dirty
Whether the stored values are stale and must be re-projected before use.
const UpdatePolicy _update_policy
When the stored values are re-projected from the source coefficient.

◆ MarkTimeChanged()

void MFEMQuadratureFunctionCoefficientBase::MarkTimeChanged ( )
inlineprotectedinherited

Mark the stored values as stale following a change of time.

Definition at line 59 of file MFEMQuadratureFunctionCoefficientBase.h.

Referenced by SetTime(), and MFEMVectorQuadratureFunctionCoefficient::SetTime().

60  {
61  if (_update_policy != UpdatePolicy::NONE)
62  _dirty = true;
63  }
bool _dirty
Whether the stored values are stale and must be re-projected before use.
const UpdatePolicy _update_policy
When the stored values are re-projected from the source coefficient.

◆ Project()

void MFEMScalarQuadratureFunctionCoefficient::Project ( mfem::QuadratureFunction &  qf)
override

Copy the stored values into qf, re-projecting the source first if invalidated.

Definition at line 45 of file MFEMScalarQuadratureFunctionCoefficient.C.

46 {
47  if (_dirty)
48  Refresh();
49  mfem::QuadratureFunctionCoefficient::Project(qf);
50 }
void Refresh()
Project the source coefficient into the quadrature function if invalidated.
bool _dirty
Whether the stored values are stale and must be re-projected before use.

◆ Refresh()

void MFEMScalarQuadratureFunctionCoefficient::Refresh ( )
private

Project the source coefficient into the quadrature function if invalidated.

Definition at line 53 of file MFEMScalarQuadratureFunctionCoefficient.C.

Referenced by Eval(), and Project().

54 {
55  // Equivalent to _source.Project(_qf), except performed with a caller-owned element
56  // transformation: the mesh-owned shared transformation used by mfem::Coefficient::Project
57  // may belong to an in-flight assembly loop that is evaluating this coefficient, and
58  // projecting through it would corrupt that loop's state.
59  const mfem::QuadratureSpaceBase & qspace = *_qf.GetSpace();
60  const mfem::Mesh & mesh = *qspace.GetMesh();
61  mfem::IsoparametricTransformation T;
62  mfem::Vector values;
63  _qf.HostWrite();
64  for (const auto iel : libMesh::make_range(qspace.GetNE()))
65  {
66  _qf.GetValues(iel, values);
67  const mfem::IntegrationRule & ir = qspace.GetIntRule(iel);
68  mesh.GetElementTransformation(iel, &T);
69  for (const auto iq : libMesh::make_range(ir.Size()))
70  {
71  const mfem::IntegrationPoint & ip = ir[iq];
72  T.SetIntPoint(&ip);
73  values[iq] = _source.Eval(T, ip);
74  }
75  }
76  _dirty = false;
77 }
bool _dirty
Whether the stored values are stale and must be re-projected before use.
MeshBase & mesh
mfem::Coefficient & _source
Source coefficient the stored values are projected from.
IntRange< T > make_range(T beg, T end)
mfem::QuadratureFunction & _qf
Storage for the projected values, shared with the owning MOOSE object.

◆ SetTime()

void MFEMScalarQuadratureFunctionCoefficient::SetTime ( mfem::real_t  t)
override

Set the time for the coefficient, invalidating the stored values unless the update policy is NONE.

Definition at line 28 of file MFEMScalarQuadratureFunctionCoefficient.C.

29 {
30  mfem::Coefficient::SetTime(t);
32 }
void MarkTimeChanged()
Mark the stored values as stale following a change of time.

Member Data Documentation

◆ _dirty

bool MFEMQuadratureFunctionCoefficientBase::_dirty
protectedinherited

◆ _name

const std::string MFEMQuadratureFunctionCoefficientBase::_name
protectedinherited

Name of the owning MOOSE object, used in error messages.

Definition at line 76 of file MFEMQuadratureFunctionCoefficientBase.h.

Referenced by MFEMQuadratureFunctionCoefficientBase::CheckIntegrationRule().

◆ _qf

mfem::QuadratureFunction& MFEMScalarQuadratureFunctionCoefficient::_qf
private

Storage for the projected values, shared with the owning MOOSE object.

Definition at line 53 of file MFEMScalarQuadratureFunctionCoefficient.h.

Referenced by Eval(), and Refresh().

◆ _source

mfem::Coefficient& MFEMScalarQuadratureFunctionCoefficient::_source
private

Source coefficient the stored values are projected from.

Definition at line 51 of file MFEMScalarQuadratureFunctionCoefficient.h.

Referenced by Refresh().

◆ _update_policy

const UpdatePolicy MFEMQuadratureFunctionCoefficientBase::_update_policy
protectedinherited

When the stored values are re-projected from the source coefficient.

Definition at line 74 of file MFEMQuadratureFunctionCoefficientBase.h.

Referenced by MFEMQuadratureFunctionCoefficientBase::MarkSolutionChanged(), and MFEMQuadratureFunctionCoefficientBase::MarkTimeChanged().


The documentation for this class was generated from the following files: