https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMScalarQuadratureFunctionCoefficient.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 "libmesh/int_range.h"
14
16 mfem::Coefficient & source,
17 mfem::QuadratureFunction & qf,
18 UpdatePolicy update_policy,
19 const std::string & name)
20 : mfem::QuadratureFunctionCoefficient(qf),
21 MFEMQuadratureFunctionCoefficientBase(update_policy, name),
22 _source(source),
23 _qf(qf)
24{
25}
26
27void
29{
30 mfem::Coefficient::SetTime(t);
32}
33
34mfem::real_t
35MFEMScalarQuadratureFunctionCoefficient::Eval(mfem::ElementTransformation & T,
36 const mfem::IntegrationPoint & ip)
37{
38 if (_dirty)
39 Refresh();
41 return mfem::QuadratureFunctionCoefficient::Eval(T, ip);
42}
43
44void
46{
47 if (_dirty)
48 Refresh();
49 mfem::QuadratureFunctionCoefficient::Project(qf);
50}
51
52void
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}
78
79#endif
std::array< Real, 2 > values
Definition MortarUtils.C:52
Shared lazy-update state for quadrature function coefficients.
void MarkTimeChanged()
Mark the stored values as stale following a change of time.
bool _dirty
Whether the stored values are stale and must be re-projected before use.
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...
mfem::Coefficient & _source
Source coefficient the stored values are projected from.
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.
void Refresh()
Project the source coefficient into the quadrature function if invalidated.
void Project(mfem::QuadratureFunction &qf) override
Copy the stored values into qf, re-projecting the source first if invalidated.
mfem::QuadratureFunction & _qf
Storage for the projected values, shared with the owning MOOSE object.
void SetTime(mfem::real_t t) override
Set the time for the coefficient, invalidating the stored values unless the update policy is NONE.
MFEMScalarQuadratureFunctionCoefficient(mfem::Coefficient &source, mfem::QuadratureFunction &qf, UpdatePolicy update_policy, const std::string &name)
MeshBase & mesh
IntRange< T > make_range(T beg, T end)