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");
150 std::vector<short> keep_positions(n_points, PositionSelection::Error);
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)
173 if (!
hasBlocks(elem->subdomain_id()) && (keep_positions[i_pos] != PositionSelection::Keep))
175 keep_positions[i_pos] = PositionSelection::Discard;
202 keep_positions[i_pos] = PositionSelection::Keep;
206 else if (keep_positions[i_pos] != PositionSelection::Keep)
207 keep_positions[i_pos] = PositionSelection::Discard;
215 for (
const auto & pos : pos_ptr->getPositions(initial))
217 if (keep_positions[i_pos] == PositionSelection::Keep)
219 else if (keep_positions[i_pos] == PositionSelection::Error)
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!");
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
std::string name(const ElemQuality q)
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
A MultiMooseEnum object to hold "execute_on" flags.
static InputParameters validParams()
std::vector< const Positions * > _positions_ptrs
Vector of pointers to positions objects.
void mooseInfo(Args &&... args) const
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
void clearPositions()
Clear all positions vectors.
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
const ExecFlagType EXEC_NONE
Positions objects are under the hood Reporters.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
const Parallel::Communicator & comm() const
registerMooseObject("MooseApp", ParsedDownSelectionPositions)
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
const Positions & getPositionsObject(const std::string &name) const
Get the Positions object by its name.
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
static InputParameters validParams()
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
const ExecFlagType EXEC_TIMESTEP_BEGIN
static InputParameters validParams()
ParsedDownSelectionPositions(const InputParameters ¶meters)
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
std::vector< const Moose::Functor< Real > * > _functors
Vector of pointers to functors.
const unsigned int _n_functors
Number of functors.
const ExecFlagType EXEC_LINEAR
std::string stringify(const T &t)
conversion to string
void max(const T &r, T &o, Request &req) const
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
An interface that restricts an object to subdomains via the 'blocks' input parameter.
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void initialize() override
In charge of computing / loading the positions.
static InputParameters validParams()
static InputParameters validParams()
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
processor_id_type processor_id() const
SymFunctionPtr _func_F
function parser object for the local value of the expression
Positions of the centroids of all elements meeting the parsed expression criterion.
auto index_range(const T &sizable)
const ExecFlagType EXEC_INITIAL