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::QuadratureFunction & qf, UpdatePolicy update_policy, const std::string & name)
17 : mfem::QuadratureFunctionCoefficient(qf),
18 MFEMQuadratureFunctionCoefficientBase(update_policy, name),
19 _source(nullptr),
20 _qf(qf)
21{
22}
23
24void
26{
27 mfem::Coefficient::SetTime(t);
29}
30
31mfem::real_t
32MFEMScalarQuadratureFunctionCoefficient::Eval(mfem::ElementTransformation & T,
33 const mfem::IntegrationPoint & ip)
34{
35 if (_dirty)
36 Refresh();
38 return mfem::QuadratureFunctionCoefficient::Eval(T, ip);
39}
40
41void
43{
44 if (_dirty)
45 Refresh();
46 mfem::QuadratureFunctionCoefficient::Project(qf);
47}
48
49void
51{
52 // Equivalent to _source.Project(_qf), except performed with a caller-owned element
53 // transformation: the mesh-owned shared transformation used by mfem::Coefficient::Project
54 // may belong to an in-flight assembly loop that is evaluating this coefficient, and
55 // projecting through it would corrupt that loop's state.
56 const mfem::QuadratureSpaceBase & qspace = *_qf.GetSpace();
57 const mfem::Mesh & mesh = *qspace.GetMesh();
58 mfem::IsoparametricTransformation T;
59 mfem::Vector values;
60 _qf.HostWrite();
61 for (const auto iel : make_range(qspace.GetNE()))
62 {
63 _qf.GetValues(iel, values);
64 const mfem::IntegrationRule & ir = qspace.GetIntRule(iel);
65 mesh.GetElementTransformation(iel, &T);
66 for (const auto iq : make_range(ir.Size()))
67 {
68 const mfem::IntegrationPoint & ip = ir[iq];
69 T.SetIntPoint(&ip);
70 values[iq] = _source->Eval(T, ip);
71 }
72 }
73 _dirty = false;
74}
75
76#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::QuadratureFunction &qf, UpdatePolicy update_policy, const std::string &name)
MeshBase & mesh