11#include "libmesh/parallel.h"
12#include "libmesh/parallel_algebra.h"
13#include "libmesh/vector_value.h"
25 "functor",
"Functor of which the extremas are going to form the list of positions");
27 MooseEnum(
"max=0 min=1 max_abs=2",
"max"),
28 "Type of extreme value to return. 'max' "
29 "returns the location(s) of the maximum value(s). 'min' returns "
30 "the location(s) of the minimum value(s). 'max_abs' returns the "
31 "locations of the maximum(a) of the absolute value.");
32 params.
addParam<
unsigned int>(
"num_extrema", 1,
"Number of extrema to look for");
39 params.
set<
bool>(
"auto_sort") =
false;
42 params.
set<
bool>(
"auto_broadcast") =
false;
56 _functor(getFunctor<Real>(
"functor")),
57 _n_extrema(getParam<unsigned
int>(
"num_extrema")),
63 const auto & functor_name = getParam<MooseFunctorName>(
"functor");
68 "Postprocessors and constants do not have extrema, they are constant over the domain.");
70 if (getParam<ExecFlagEnum>(
"execute_on").contains(
EXEC_NONE))
72 "NONE execution flag not supported. Most functors (functions, variables, spatial "
73 "user objects for example) are not initialized at construction.");
83 std::list<Real> extrema;
84 std::list<Point> extrema_locs;
86 extrema.resize(
_n_extrema, -std::numeric_limits<Real>::max());
88 extrema.resize(
_n_extrema, std::numeric_limits<Real>::max());
94 for (
const auto & elem :
98 auto value =
_functor(elem_arg, time_arg);
100 auto extremum = extrema.begin();
101 auto extremum_loc = extrema_locs.begin();
106 bool extrema_found =
false;
110 value = std::abs(value);
114 if (value > *extremum)
115 extrema_found =
true;
120 if (value < *extremum)
121 extrema_found =
true;
128 extrema.insert(extremum, value);
129 extrema_locs.insert(extremum_loc, elem->true_centroid());
131 extrema_locs.pop_back();
136 std::advance(extremum, 1);
137 std::advance(extremum_loc, 1);
142 auto current_candidate = extrema.begin();
143 auto current_candidate_loc = extrema_locs.begin();
148 auto copy = *current_candidate;
154 RealVectorValue extreme_point(0., 0., 0.);
157 extreme_point = *current_candidate_loc;
159 std::advance(current_candidate, 1);
160 std::advance(current_candidate_loc, 1);
170 "Positions extrema should be the same across all MPI processes.");
registerMooseObject("MooseApp", FunctorExtremaPositions)
const ExecFlagType EXEC_TIMESTEP_BEGIN
const ExecFlagType EXEC_LINEAR
const ExecFlagType EXEC_NONE
const ReporterMode REPORTER_MODE_REPLICATED
void ErrorVector unsigned int
An interface that restricts an object to subdomains via the 'blocks' input parameter.
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted,...
static InputParameters validParams()
A MultiMooseEnum object to hold "execute_on" flags.
bool hasPostprocessorValueByName(const PostprocessorName &name) const
Whether or not a Postprocessor value exists by a given name.
Positions from the extrema of a functor.
static InputParameters validParams()
ExtremeType
Type of extreme value we are going to compute.
void initialize() override
In charge of computing / loading the positions.
const unsigned int _n_extrema
Number of extrema to keep track of.
const Moose::Functor< Real > & _functor
Functor providing the value.
enum FunctorExtremaPositions::ExtremeType _type
std::vector< Real > & _positions_values
Values of the functor at the extrema.
FunctorExtremaPositions(const InputParameters ¶meters)
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
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 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.
This context is specific for vector types of reporters, mainly for declaring a vector of the type fro...
virtual MooseMesh & mesh()=0
void maxloc(T &r, unsigned int &max_id) const
void minloc(T &r, unsigned int &min_id) const
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
SubProblem & _subproblem
Reference to the Subproblem for this user object.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
bool parsesToReal(const std::string &input, Real *parsed_real)
A structure that is used to evaluate Moose functors logically at an element/cell center.