11#include "libmesh/parallel.h"
12#include "libmesh/parallel_algebra.h"
13#include "libmesh/vector_value.h"
28 "Positions object(s) that will be down-selected by this object. The order of the "
29 "down-selected positions is kept the same");
35 "Parsed function expression to compute the selection criterion. Note that x,y,z and t can be "
36 "used in the expression without being declared as functors.");
37 params.
addParam<std::vector<MooseFunctorName>>(
38 "functor_names", {},
"Functors to use in the parsed expression");
39 params.
addParam<std::vector<std::string>>(
42 "Symbolic name to use for each functor in 'functor_names' in the parsed expression. If not "
43 "provided, then the actual functor names will be used in the parsed expression.");
46 params.
set<
bool>(
"auto_sort") =
false;
49 params.
set<
bool>(
"auto_broadcast") =
false;
54 params.
addClassDescription(
"Examines input positions object(s) to find all positions matching a "
55 "user-specifed parsed expression criterion. The order of the "
56 "positions in the input is kept.");
65 _expression(getParam<
std::string>(
"expression")),
66 _xyzt({
"x",
"y",
"z",
"t"}),
67 _functor_names(getParam<std::vector<MooseFunctorName>>(
"functor_names")),
68 _n_functors(_functor_names.size()),
69 _functor_symbols(getParam<std::vector<std::string>>(
"functor_symbols"))
71 if (getParam<ExecFlagEnum>(
"execute_on").contains(
EXEC_NONE))
72 paramError(
"execute_on",
73 "NONE execution flag not supported. Most functors (functions, variables, spatial "
74 "user objects for example) are not initialized at construction.");
77 if (!_functor_symbols.empty() && (_functor_symbols.size() != _n_functors))
78 paramError(
"functor_symbols",
"functor_symbols must be the same length as functor_names.");
81 for (
const auto & name : _functor_symbols)
82 if (
std::find(_xyzt.begin(), _xyzt.end(), name) != _xyzt.end())
83 paramError(
"functor_symbols",
"x, y, z, and t cannot be used in 'functor_symbols'.");
84 for (
const auto & name : _functor_names)
85 if (
std::find(_xyzt.begin(), _xyzt.end(), name) != _xyzt.end())
86 paramError(
"functor_names",
87 "x, y, z, and t cannot be used in 'functor_names'. Use functor_symbols to "
88 "disambiguate by using a different symbol in the expression.");
91 std::string variables;
94 if (_functor_symbols.size())
95 for (
const auto & symbol : _functor_symbols)
96 variables += (variables.empty() ?
"" :
",") + symbol;
98 for (
const auto & name : _functor_names)
99 variables += (variables.empty() ?
"" :
",") + name;
102 for (
auto & v : _xyzt)
103 variables += (variables.empty() ?
"" :
",") + v;
106 _func_F = std::make_shared<SymFunction>();
107 parsedFunctionSetup(_func_F, _expression, variables, {}, {}, comm());
110 _func_params.resize(_n_functors + 4);
113 for (
const auto & name : _functor_names)
114 _functors.push_back(&getFunctor<
Real>(
name));
123 const auto & base_names = getParam<std::vector<PositionsName>>(
"input_positions");
124 for (
const auto & base_name : base_names)
133 "' is not executing on ",
135 ". This could mean this position is not updated when down-selecting.");
142 unsigned int n_points = 0;
144 n_points += pos_ptr->getNumPositions(initial);
146 mooseAssert(
comm().verify(n_points),
"Input positions should be synchronized");
154 pl->enable_out_of_mesh_mode();
158 unsigned int i_pos, counter = 0;
160 for (
const auto & pos : pos_ptr->getPositions(initial))
165 std::set<const Elem *> candidate_elements;
166 (*pl)(pos, candidate_elements);
168 for (
const auto elem : candidate_elements)
189 for (
const auto i : index_range(
_functors))
215 for (
const auto & pos : pos_ptr->getPositions(initial))
221 "No process has made a decision on whether position '",
223 "' from Positions object '" + pos_ptr->name() +
224 "' should be discarded or kept during down-selection. This usually means this "
225 "position is outside the mesh!");
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
const ExecFlagType EXEC_TIMESTEP_BEGIN
const ExecFlagType EXEC_INITIAL
const ExecFlagType EXEC_LINEAR
const ExecFlagType EXEC_NONE
registerMooseObject("MooseApp", ParsedDownSelectionPositions)
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
An interface that restricts an object to subdomains via the 'blocks' input parameter.
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
static InputParameters validParams()
A MultiMooseEnum object to hold "execute_on" flags.
const Positions & getPositionsObject(const std::string &name) const
Get the Positions object by its name.
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
virtual MooseMesh & mesh() override
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
static InputParameters validParams()
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
static InputParameters validParams()
Positions of the centroids of all elements meeting the parsed expression criterion.
ParsedDownSelectionPositions(const InputParameters ¶meters)
static InputParameters validParams()
const unsigned int _n_functors
Number of functors.
SymFunctionPtr _func_F
function parser object for the local value of the expression
std::vector< const Moose::Functor< Real > * > _functors
Vector of pointers to functors.
std::vector< const Positions * > _positions_ptrs
Vector of pointers to positions objects.
void initialize() override
In charge of computing / loading the positions.
Positions objects are under the hood Reporters.
void clearPositions()
Clear all positions vectors.
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
static InputParameters validParams()
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
void max(const T &r, T &o, Request &req) const
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
std::string stringify(const T &t)
conversion to string
std::string name(const ElemQuality q)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...