https://mooseframework.inl.gov
Loading...
Searching...
No Matches
MFEMVariableSamplerBase.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 "MooseEnum.h"
16#include "SubProblem.h"
17
18namespace Moose::MFEM
19{
20std::vector<Point>
21generateLinePoints(const Point & start_point, const Point & end_point, unsigned int num_points)
22{
23 // initialize and populate vector with linearly-spaced points along line
24 std::vector<Point> points;
25 points.reserve(num_points);
26 for (const auto i_point : make_range(num_points))
27 {
28 // fractional distance along line [0, 1]
29 Real t = static_cast<Real>(i_point) / static_cast<Real>(num_points - 1);
30 points.push_back(t * end_point + (1 - t) * start_point);
31 }
32
33 return points;
34}
35}
36
37namespace
38{
39CreateMooseEnumClass(L2AverageType, NONE, ARITHMETIC, HARMONIC);
40
41mfem::ParMesh &
42variableMesh(const InputParameters & parameters)
43{
44 auto & problem =
45 cast_ref<MFEMProblem &>(*parameters.getCheckedPointerParam<SubProblem *>("_subproblem"));
46 auto & variables = parameters.get<std::vector<VariableName>>("variables");
47
48 if (variables.empty())
49 parameters.paramError("variables", "In MFEMVariableSamplerBase: variables must not be empty.");
50
51 auto & first_variable = variables[0];
52 auto & mesh = const_cast<mfem::ParMesh &>(problem.getMFEMVariableMesh(first_variable));
53
54 // ensure that all variables are on the same mesh
55 for (const auto & variable : variables)
56 if (&problem.getMFEMVariableMesh(variable) != &mesh)
57 parameters.paramError("variables",
58 "In MFEMVariableSamplerBase:"
59 " all variables must be on the same mesh. Found: ",
60 variable,
61 " which is not on the same mesh as: ",
62 first_variable,
63 ".");
64
65 return mesh;
66}
67}
68
71{
73 MFEMExecutedObject::addRequiredDependencyParam<std::vector<VariableName>>(
74 params, "variables", "The variables that this VectorPostprocessor samples.");
75 MooseEnum avg_type(getL2AverageTypeOptions(), "ARITHMETIC");
76 params.addParam<MooseEnum>("side_interpolation_type",
77 avg_type,
78 "Average type used when sampling L2 functions at element boundaries.");
79 return params;
80}
81
83 const std::vector<Point> & points)
84 : MFEMSamplerBase(parameters, points, variableMesh(parameters)),
85 _var_names(getParam<std::vector<VariableName>>("variables"))
86{
87 _finder.SetL2AvgType(static_cast<mfem::FindPointsGSLIB::AvgType>(
88 getParam<MooseEnum>("side_interpolation_type").getEnum<L2AverageType>()));
89}
90
91void
93{
95
96 // Early return if all sampled variables are continuous
97 const auto var_indices = index_range(_var_names);
98 if (std::all_of(
99 var_indices.begin(),
100 var_indices.end(),
101 [this](size_t i)
102 { return getFESpaceContinuityType(i) == mfem::FiniteElementCollection::CONTINUOUS; }))
103 return;
104
105 const auto & point_codes = _finder.GetCode();
106 for (const auto i : index_range(_query_points))
107 if (PointLocationCode(point_codes[i]) == PointLocationCode::BORDER)
108 for (const auto i_var : index_range(_var_names))
109 switch (getFESpaceContinuityType(i_var))
110 {
111 case mfem::FiniteElementCollection::DISCONTINUOUS:
113 typeAndName(),
114 " found a point on an element boundary but the FE space is discontinuous at "
115 "element boundaries: ",
116 _query_points[i],
117 ". ",
118 _var_names[i_var],
119 " is discontinuous.");
120 break;
121 case mfem::FiniteElementCollection::TANGENTIAL:
123 typeAndName(),
124 " found point ",
125 _query_points[i],
126 " on an element boundary. The H(curl) finite element space has a continuous "
127 "tangential trace there, but the normal component may differ between "
128 "elements. The element selected by GSLIB will supply the sampled value.",
129 _var_names[i_var],
130 " has tangential continuity.");
131 break;
132 case mfem::FiniteElementCollection::NORMAL:
134 typeAndName(),
135 " found point ",
136 _query_points[i],
137 " on an element boundary. The H(div) finite element space has a continuous "
138 "normal trace there, but the tangential component may differ between "
139 "elements. The element selected by GSLIB will supply the sampled value.",
140 _var_names[i_var],
141 " has normal continuity.");
142 break;
143 }
144}
145
146#endif // MOOSE_MFEM_ENABLED
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition MooseError.h:345
CreateMooseEnumClass(Mortar3DSubpatchPlane, GEOMETRIC_NORMAL, AVERAGED_NODAL_NORMAL)
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
void paramError(const std::string &param, Args... args) const
Emits a parameter error prefixed with the parameter location and object information if available.
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.
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()
PointLocationCode
Classification returned by GSLIB for a query point's location.
const std::vector< Point > _query_points
Original query points used for point-location diagnostics.
void initialSetup() override
Checks that all query points were found and prepares coordinate output.
virtual int getFESpaceContinuityType(size_t i_var) const =0
Return the continuity type of the i-th sampled variable's finite element collection.
static InputParameters validParams()
void initialSetup() override
Checks point locations and warns when sampled components may be discontinuous at boundaries.
const std::vector< VariableName > _var_names
Names of the variables being sampled.
MFEMVariableSamplerBase(const InputParameters &parameters, const std::vector< Point > &points)
std::string typeAndName() const
Get the class's combined type and name; useful in error handling.
Definition MooseBase.C:57
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Generic class for solving transient nonlinear problems.
Definition SubProblem.h:79
MeshBase & mesh
Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).
std::vector< Point > generateLinePoints(const Point &start_point, const Point &end_point, unsigned int num_points)