30template <
typename UserObjectType,
typename BaseType>
84 using BaseType::_communicator;
85 using BaseType::_current_elem;
86 using BaseType::isParamValid;
87 using BaseType::processor_id;
91template <
typename UserObjectType,
typename BaseType>
97 params.
addParam<std::vector<Point>>(
"points",
98 "Computations will be lumped into values at these points.");
99 params.
addParam<FileName>(
"points_file",
100 "A filename that should be looked in for points. Each "
101 "set of 3 values in that file will represent a Point. "
102 "This and 'points' cannot be both supplied.");
105 "The name of a Positions object that will contain "
106 "the locations. This, 'points' and 'points(_file)' cannot be both supplied. "
107 "Note that only the vector of initial Positions are used at this time. "
108 "Updates to the 'positions' vector are not supported.");
110 MooseEnum distnorm(
"point=0 radius=1",
"point");
112 "dist_norm", distnorm,
"To specify whether the distance is defined based on point or radius");
114 params.
addParam<
MooseEnum>(
"axis", axis,
"The axis around which the radius is determined");
116 params.
addParamNamesToGroup(
"points points_file dist_norm axis",
"Points and distance to points");
119 params += UserObjectType::validParams();
124template <
typename UserObjectType,
typename BaseType>
127 _dist_norm(this->template getParam<
MooseEnum>(
"dist_norm")),
128 _axis(this->template getParam<
MooseEnum>(
"axis"))
130 if (this->
template getParam<MooseEnum>(
"dist_norm") !=
"radius" &&
132 this->paramError(
"axis",
"'axis' should only be set if 'dist_norm' is set to 'radius'");
143 const auto uo_type = MooseUtils::prettyCppType<UserObjectType>();
144 auto sub_params = this->_app.getFactory().getValidParams(uo_type);
145 sub_params.applyParameters(parameters, {},
true);
147 const auto sub_name =
name() +
"_sub" + std::to_string(i);
148 auto uo = this->_app.getFactory().template createUnique<UserObjectType>(
149 uo_type, sub_name, sub_params, this->_tid);
154template <
typename UserObjectType,
typename BaseType>
159template <
typename UserObjectType,
typename BaseType>
163 if (isParamValid(
"points"))
165 _points = this->
template getParam<std::vector<Point>>(
"points");
166 if (isParamValid(
"points_file"))
167 this->paramError(
"points_file",
"Cannot be specified together with 'points'");
168 if (isParamValid(
"positions_object"))
169 this->paramError(
"positions_object",
"Cannot be specified together with 'points'");
171 else if (isParamValid(
"points_file"))
173 const FileName & points_file = this->
template getParam<FileName>(
"points_file");
180 if (isParamValid(
"positions_object"))
181 this->paramError(
"positions_object",
"Cannot be specified together with 'points_file'");
183 else if (isParamValid(
"positions_object"))
185 const auto & positions_name = this->
template getParam<PositionsName>(
"positions_object");
186 const auto problem = this->
template getCheckedPointerParam<FEProblemBase *>(
"_fe_problem_base");
187 _points = problem->getPositionsObject(positions_name).getPositions(
true);
192 ": You need to supply either 'points', 'points_file' or 'positions_object' parameter.");
195template <
typename UserObjectType,
typename BaseType>
199 for (
auto & user_object : _user_objects)
200 user_object->initialize();
203template <
typename UserObjectType,
typename BaseType>
207 nearestUserObject(_current_elem->vertex_average()).execute();
210template <
typename UserObjectType,
typename BaseType>
214 for (
auto & user_object : _user_objects)
215 user_object->finalize();
218template <
typename UserObjectType,
typename BaseType>
224 for (MooseIndex(_user_objects) i = 0; i < _user_objects.size(); ++i)
225 _user_objects[i]->threadJoin(*npla._user_objects[i]);
228template <
typename UserObjectType,
typename BaseType>
232 return nearestUserObject(p).spatialValue(p);
235template <
typename UserObjectType,
typename BaseType>
239 unsigned int closest = 0;
240 Real closest_distance = std::numeric_limits<Real>::max();
244 const auto & current_point = it.value();
246 Real current_distance;
249 current_distance = (p - current_point).norm();
263 current_distance = std::abs(
264 std::sqrt(p(i) * p(i) + p(j) * p(j)) -
265 std::sqrt(current_point(i) * current_point(i) + current_point(j) * current_point(j)));
268 if (current_distance < closest_distance)
270 closest_distance = current_distance;
271 closest = it.index();
275 return *_user_objects[closest];
278template <
typename UserObjectType,
typename BaseType>
279const std::vector<Point>
282 std::vector<Point> points;
284 for (MooseIndex(_points) i = 0; i < _points.size(); ++i)
286 auto layered_base =
dynamic_cast<LayeredBase *
>(_user_objects[i].get());
290 auto direction = layered_base->direction();
292 for (
const auto & l : layers)
294 Point pt = _points[i];
296 points.push_back(pt);
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
This base class computes volume integrals of a variable storing partial sums for the specified number...
const std::vector< Real > & getLayerCenters() const
Get the center coordinates for the layers (along given direction)
const std::string & name() const
Get the name of the class.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Utility class for reading delimited data (e.g., CSV data).
const std::vector< Point > getDataAsPoints() const
Get the data in Point format.
void setFormatFlag(FormatFlag value)
void read()
Perform the actual data reading.
This UserObject computes averages of a variable storing partial sums for the specified number of inte...
virtual void finalize() override
virtual void threadJoin(const UserObject &y) override
void fillPoints()
Fills in the _points variable from either 'points' or 'points_file' parameter.
virtual Real spatialValue(const Point &p) const override
Given a Point return the integral value associated with the layer that point falls in for the layered...
virtual void initialize() override
NearestPointBase(const InputParameters ¶meters)
static InputParameters validParams()
const std::string & name() const
Get the name of the class.
virtual const std::vector< Point > spatialPoints() const override
virtual const std::vector< Point > & getPoints() const
Get the points at which the nearest operation is performed.
std::vector< std::unique_ptr< UserObjectType > > _user_objects
const unsigned int _dist_norm
std::vector< Point > _points
UserObjectType & nearestUserObject(const Point &p) const
Get the UserObject that is closest to the point.
virtual void execute() override
Base class for creating a user object with the SpatialUserObject and Moose::Functor APIs.
static InputParameters validParams()
Base class for user-specific data.
_enumerate_range< Iterator > enumerate(Iterator first, Iterator last, typename std::iterator_traits< Iterator >::difference_type initial)
Enumerate function for iterating over a range and obtaining both a reference to the underlying type a...