https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMScalarCoefficientPointValueSampler.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
19namespace
20{
21mfem::ParMesh &
22mainMesh(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
52void
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
65void
67{
68 mfem::Array<unsigned int> received_elements;
69 mfem::Array<unsigned int> received_codes;
70 mfem::Vector received_reference_points;
71 _finder.DistributePointInfoToOwningMPIRanks(
72 received_elements, received_reference_points, received_codes);
73
74 const auto mesh_dim = _mesh.Dimension();
75 mfem::Vector evaluated_values(received_elements.Size());
76 for (const auto i : make_range(received_elements.Size()))
77 {
78 mfem::IntegrationPoint integration_point;
79 integration_point.Set(&received_reference_points[mesh_dim * i], mesh_dim);
80
81 auto & transformation = *_mesh.GetElementTransformation(received_elements[i]);
82 transformation.SetIntPoint(&integration_point);
83 evaluated_values[i] = _coefficient->Eval(transformation, integration_point);
84 }
85
86 // With one scalar value per point, byNODES and byVDIM orderings are identical.
87 _finder.DistributeInterpolatedValues(evaluated_values, 1, mfem::Ordering::byVDIM, _interp_vals);
88}
89
90void
92{
93 const auto * const interp_vals = _interp_vals.HostRead();
94 for (const auto i : index_range(_declared_vals))
95 _declared_vals[i] = interp_vals[i];
96}
97
98#endif // MOOSE_MFEM_ENABLED
registerMooseObject("MooseApp", MFEMScalarCoefficientPointValueSampler)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
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.
mfem::ParMesh & getMFEMParMesh()
Accessors for the _mfem_par_mesh object.
Definition MFEMMesh.h:34
mfem::Coefficient & getScalarCoefficient(const std::string &name)
Retrieve a scalar MFEM coefficient using the value of an input parameter.
Definition MFEMObject.C:58
virtual MFEMMesh & mesh() override
Overwritten mesh() method from base MooseMesh to retrieve the correct mesh type, in this case MFEMMes...
Abstract base class for sampling MFEM quantities at points.
mfem::FindPointsGSLIB _finder
GSLIB point finder used to locate and interpolate the query points.
static InputParameters validParams()
mfem::ParMesh & _mesh
MFEM mesh on which the sampled quantity is defined.
const std::vector< Point > _query_points
Original query points used for point-location diagnostics.
void initialSetup() override
Checks that all query points were found.
Samples a real scalar MFEM coefficient at specified points.
mfem::Vector _interp_vals
Values evaluated on owning ranks and returned to the querying ranks.
mfem::Coefficient * _coefficient
Scalar coefficient being sampled, resolved after all coefficient-declaring objects exist.
VectorPostprocessorValue & _declared_vals
VectorPostprocessor output column for the coefficient.
void execute() override
Evaluates the coefficient in each point's owning element.
void finalizeValues() override
Copies interpolated values into the subclass VPP vectors.
void initialSetup() override
Checks point locations and warns when GSLIB selects an element at a boundary.
MFEMScalarCoefficientPointValueSampler(const InputParameters &parameters)
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
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79