https://mooseframework.inl.gov
MFEMPointScalarCoefficientValueSampler.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 
14 #include "MFEMProblem.h"
15 #include "SubProblem.h"
16 
18 
19 namespace
20 {
21 mfem::ParMesh &
22 mainMesh(const InputParameters & parameters)
23 {
24  auto & problem =
25  static_cast<MFEMProblem &>(*parameters.getCheckedPointerParam<SubProblem *>("_subproblem"));
26  return problem.mesh().getMFEMParMesh();
27 }
28 }
29 
32 {
34  params.addClassDescription("Sample a real scalar MFEM coefficient at specific points.");
35  params.addRequiredParam<MFEMScalarCoefficientName>("coefficient",
36  "The scalar coefficient to sample.");
37  params.addRequiredParam<std::vector<Point>>("points",
38  "The points where the coefficient is evaluated.");
39  return params;
40 }
41 
43  const InputParameters & parameters)
44  : MFEMSamplerBase(parameters, parameters.get<std::vector<Point>>("points"), mainMesh(parameters)),
45  _coefficient(nullptr),
46  _interp_vals(_query_points.size()),
47  _declared_vals(declareVector(getParam<MFEMScalarCoefficientName>("coefficient")))
48 {
49  _declared_vals.resize(_query_points.size());
50 }
51 
52 void
54 {
55  _coefficient = &getScalarCoefficient("coefficient");
56  if (dynamic_cast<mfem::QuadratureFunctionCoefficient *>(_coefficient))
57  paramError("coefficient",
58  "Quadrature-function-backed coefficients can only be evaluated at the quadrature "
59  "points configured by their quadrature rule and cannot be sampled at arbitrary "
60  "points.");
61 
63 
64  const auto & point_codes = _finder.GetCode();
65  for (const auto i : index_range(_query_points))
66  if (PointLocationCode(point_codes[i]) == PointLocationCode::BORDER)
68  " found point ",
69  _query_points[i],
70  " on an element boundary. An arbitrary coefficient may be discontinuous "
71  "there, so the element selected by GSLIB will supply the sampled value.");
72 }
73 
74 void
76 {
77  mfem::Array<unsigned int> received_elements;
78  mfem::Array<unsigned int> received_codes;
79  mfem::Vector received_reference_points;
80  _finder.DistributePointInfoToOwningMPIRanks(
81  received_elements, received_reference_points, received_codes);
82 
83  const auto mesh_dim = _mesh.Dimension();
84  mfem::Vector evaluated_values(received_elements.Size());
85  for (const auto i : make_range(received_elements.Size()))
86  {
87  mfem::IntegrationPoint integration_point;
88  if (mesh_dim == 1)
89  integration_point.Set1(received_reference_points[i]);
90  else if (mesh_dim == 2)
91  integration_point.Set2(received_reference_points[2 * i],
92  received_reference_points[2 * i + 1]);
93  else
94  integration_point.Set3(received_reference_points[3 * i],
95  received_reference_points[3 * i + 1],
96  received_reference_points[3 * i + 2]);
97 
98  auto & transformation = *_mesh.GetElementTransformation(received_elements[i]);
99  transformation.SetIntPoint(&integration_point);
100  evaluated_values[i] = _coefficient->Eval(transformation, integration_point);
101  }
102 
103  // With one scalar value per point, byNODES and byVDIM orderings are identical.
104  _finder.DistributeInterpolatedValues(evaluated_values, 1, mfem::Ordering::byVDIM, _interp_vals);
105 }
106 
107 void
109 {
110  const auto * const interp_vals = _interp_vals.HostRead();
111  for (const auto i : index_range(_declared_vals))
112  _declared_vals[i] = interp_vals[i];
113 }
114 
115 #endif // MOOSE_MFEM_ENABLED
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:457
mfem::Vector _interp_vals
Values evaluated on owning ranks and returned to the querying ranks.
virtual MFEMMesh & mesh() override
Overwritten mesh() method from base MooseMesh to retrieve the correct mesh type, in this case MFEMMes...
Definition: MFEMProblem.C:777
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void initialSetup() override
Checks point locations and warns when GSLIB selects an element at a boundary.
Samples a real scalar MFEM coefficient at specified points.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void mooseWarning(Args &&... args) const
MFEMPointScalarCoefficientValueSampler(const InputParameters &parameters)
void initialSetup() override
Checks that all query points were found.
std::string typeAndName() const
Get the class&#39;s combined type and name; useful in error handling.
Definition: MooseBase.C:57
Abstract base class for sampling MFEM quantities at points.
mfem::ParMesh & _mesh
MFEM mesh on which the sampled quantity is defined.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
mfem::ParMesh & getMFEMParMesh()
Accessors for the _mfem_par_mesh object.
Definition: MFEMMesh.h:34
mfem::FindPointsGSLIB _finder
GSLIB point finder used to locate and interpolate the query points.
PointLocationCode
Classification returned by GSLIB for a query point&#39;s location.
registerMooseObject("MooseApp", MFEMPointScalarCoefficientValueSampler)
mfem::Coefficient & getScalarCoefficient(const std::string &name)
Retrieve a scalar MFEM coefficient using the value of an input parameter.
Definition: MFEMObject.C:58
IntRange< T > make_range(T beg, T end)
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
static InputParameters validParams()
VectorPostprocessorValue & _declared_vals
VectorPostprocessor output column for the coefficient.
const std::vector< Point > _query_points
Original query points used for point-location diagnostics.
mfem::Coefficient * _coefficient
Scalar coefficient being sampled, resolved after all coefficient-declaring objects exist...
void finalizeValues() override
Copies interpolated values into the subclass VPP vectors.
auto index_range(const T &sizable)
const Elem & get(const ElemType type_in)
void execute() override
Evaluates the coefficient in each point&#39;s owning element.