11#include "libmesh/parallel_algebra.h"
19 params.
addParam<PositionsName>(
"initial_positions",
20 "Positions at the beginning of the simulation");
25 "Wether Positions should be broadcasted across all ranks");
29 params.
addRequiredParam<
bool>(
"auto_sort",
"Whether Positions should be sorted by coordinates");
42 _initial_positions(isParamValid(
"initial_positions")
43 ? &getReporterValueByName<
std::vector<Point>>(
44 getParam<PositionsName>(
"initial_positions") +
"/positions_1d")
49 _need_broadcast(getParam<bool>(
"auto_broadcast")),
50 _need_sort(getParam<bool>(
"auto_sort")),
61 mooseAssert(
initialized(initial),
"Positions vector has not been initialized.");
64 mooseError(
"Initial positions is not sized or initialized appropriately");
70 mooseError(
"Initial positions and current positions array length do not match");
72 mooseError(
"Positions retrieved with an out-of-bound index: '",
74 "' when there are only ",
84 mooseError(
"Positions vector has not been initialized.");
90 mooseAssert(
initialized(initial),
"Positions vector has not been initialized.");
98 mooseAssert(
initialized(initial),
"Positions vector has not been initialized.");
99 std::vector<std::size_t> return_index(1);
112 return return_index[0];
115const std::vector<Point> &
123 mooseError(
"Positions vector has not been initialized.");
126const std::vector<std::vector<Point>> &
132 mooseError(
"2D positions vectors have not been initialized.");
135const std::vector<std::vector<std::vector<Point>>> &
141 mooseError(
"3D positions vectors have not been initialized.");
144const std::vector<std::vector<std::vector<std::vector<Point>>>> &
150 mooseError(
"4D positions vectors have not been initialized.");
166 std::vector<Point> temp_2d_unrolled;
167 std::vector<Point> temp_3d_unrolled;
168 std::vector<Point> temp_4d_unrolled;
170 temp_2d_unrolled.insert(temp_2d_unrolled.end(), vec.begin(), vec.end());
172 for (
const auto & vec : vec_vec)
173 temp_3d_unrolled.insert(temp_3d_unrolled.end(), vec.begin(), vec.end());
175 for (
const auto & vec_vec : vec_vec_vec)
176 for (
const auto & vec : vec_vec)
177 temp_4d_unrolled.insert(temp_4d_unrolled.end(), vec.begin(), vec.end());
182 mooseError(
"Inconsistency between the 2D and 1D position vectors detected. "
183 "The 2D positions must unroll into the 1D positions");
186 if (temp_3d_unrolled.size() && temp_2d_unrolled.size() && temp_3d_unrolled != temp_3d_unrolled)
187 mooseError(
"Inconsistency between the 3D and 2D position vectors detected. "
188 "The 3D positions must unroll the same way as the 2D positions");
190 mooseError(
"Inconsistency between the 3D and 1D position vectors detected. "
191 "The 3D positions must unroll into the 1D positions");
194 if (temp_4d_unrolled.size() && temp_3d_unrolled.size() && temp_4d_unrolled != temp_3d_unrolled)
195 mooseError(
"Inconsistency between the 4D and 3D position vectors detected. "
196 "The 4D positions must unroll the same way as the 3D positions");
197 if (temp_4d_unrolled.size() && temp_2d_unrolled.size() && temp_4d_unrolled != temp_2d_unrolled)
198 mooseError(
"Inconsistency between the 4D and 2D position vectors detected. "
199 "The 4D positions must unroll the same way as the 2D positions");
201 mooseError(
"Inconsistency between the 4D and 1D position vectors detected. "
202 "The 4D positions must unroll into the 1D positions");
207 if (temp_2d_unrolled.size())
209 else if (temp_3d_unrolled.size())
211 else if (temp_4d_unrolled.size())
214 mooseError(
"Positions::unrollMultiDPositions() may only be called if there is at least one "
215 "non-empty positions vector.");
223 mooseAssert(
initialized(
false),
"Positions vector has not been initialized.");
238 mooseAssert(
comm().verify(
_positions),
"Positions should be the same across all MPI processes.");
244 mooseAssert(
initialized(
false),
"Positions vector has not been initialized.");
247 Real min_distance_sq = std::numeric_limits<Real>::max();
249 for (
auto i2 = i1 + 1; i2 <
_positions.size(); i2++)
251 return std::sqrt(min_distance_sq);
257 mooseAssert(
initialized(
false),
"Positions vector has not been initialized.");
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
const ExecFlagType EXEC_NONE
const ReporterMode REPORTER_MODE_REPLICATED
A MultiMooseEnum object to hold "execute_on" flags.
const Positions & getPositionsObject(const std::string &name) const
Get the Positions object by its name.
Reporter object that has a single execution of the "execute" method for each execute flag.
static InputParameters validParams()
bool initialized(bool initial) const
Whether the positions object has been initialized.
const Point & getPosition(unsigned int index, bool initial) const
Getter for a single position at a known index.
std::unique_ptr< KDTree > _positions_kd_tree
const bool _need_sort
Whether positions should be sorted.
const std::vector< Point > *const _initial_positions
For initialization of the positions, another position reporter may be used.
bool arePositionsCoplanar() const
Report if the positions are co-planar or not.
std::unique_ptr< KDTree > _initial_positions_kd_tree
KDTree to be able to find the nearest position to a point in a fast and scalable manner.
unsigned int getNearestPositionIndex(const Point &target, bool initial) const
Find the nearest Position index for a given point.
Real getMinDistanceBetweenPositions() const
Find the minimum distance between positions.
bool _need_broadcast
Whether generation of positions is distributed or not (and therefore needs a broadcast)
const std::vector< std::vector< std::vector< Point > > > & getPositionsVector3D() const
std::vector< std::vector< std::vector< std::vector< Point > > > > _positions_4d
4D storage for all the positions : space & time
std::vector< std::vector< Point > > _positions_2d
2D storage for all the positions
Positions(const InputParameters ¶meters)
void clearPositions()
Clear all positions vectors.
const std::vector< std::vector< std::vector< std::vector< Point > > > > & getPositionsVector4D() const
const std::vector< std::vector< Point > > & getPositionsVector2D() const
const Point & getNearestPosition(const Point &target, bool initial) const
Find the nearest Position for a given point.
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
const std::vector< Point > & getPositions(bool initial) const
{ Getters for the positions vector for the desired dimension 1D will be the only one guaranteed to su...
void unrollMultiDPositions()
Unrolls the multi-dimensional position vectors.
static InputParameters validParams()
std::vector< std::vector< std::vector< Point > > > _positions_3d
3D storage for all the positions
virtual void finalize() override
In charge of reduction across all ranks & sorting for consistent output.
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...
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
const Parallel::Communicator & _communicator
const Parallel::Communicator & comm() const
bool isCoPlanar(const std::vector< Point > &vec_pts, const Point plane_nvec, const Point fixed_pt)
Decides whether all the Points of a vector of Points are in a plane that is defined by a normal vecto...