18 #include "libmesh/mesh_tools.h" 19 #include "libmesh/point.h" 28 params.
addParam<
unsigned int>(
"num_layers",
"The number of layers.");
29 params.
addParam<std::vector<Real>>(
"bounds",
30 "The 'bounding' positions of the layers i.e.: '0, " 31 "1.2, 3.7, 4.2' will mean 3 layers between those " 34 "bound_uniform_splits > 0",
35 "The number of times the bins specified in 'bounds' " 36 "should be split uniformly.");
38 MooseEnum sample_options(
"direct interpolate average",
"direct");
41 "How to sample the layers. 'direct' means get the value of the layer " 42 "the point falls in directly (or average if that layer has no value). " 43 " 'interpolate' does a linear interpolation between the two closest " 44 "layers. 'average' averages the two closest layers.");
46 params.
addParam<
unsigned int>(
"average_radius",
48 "When using 'average' sampling this is how " 49 "the number of values both above and below " 50 "the layer that will be averaged.");
55 "When true the value in each layer is the sum of the values up to and including that layer");
57 "positive_cumulative_direction",
59 "When 'cumulative' is true, whether the direction for summing the cumulative value " 60 "is the positive direction or negative direction");
62 params.
addParam<std::vector<SubdomainName>>(
63 "block",
"The list of block ids (SubdomainID) that this object will be applied");
65 params.
addParam<std::vector<SubdomainName>>(
"layer_bounding_block",
66 "List of block ids (SubdomainID) that are used to " 67 "determine the upper and lower geometric bounds for " 68 "all layers. If this is not specified, the ids " 69 "specified in 'block' are used for this purpose.");
72 "Minimum coordinate along 'direction' that bounds the layers");
74 "Maximum coordinate along 'direction' that bounds the layers");
76 "direction num_layers bounds direction_min direction_max bound_uniform_splits",
77 "Layers extent and definition");
78 params.
addParamNamesToGroup(
"sample_type average_radius cumulative positive_cumulative_direction",
79 "Value sampling / aggregating");
85 parameters.
get<
std::string>(
"_object_name") +
"_layered_base",
88 _layered_base_name(parameters.
get<
std::string>(
"_object_name")),
89 _layered_base_params(parameters),
91 _direction(_direction_enum),
93 _average_radius(parameters.
get<unsigned
int>(
"average_radius")),
94 _using_displaced_mesh(_layered_base_params.
get<bool>(
"use_displaced_mesh")),
95 _layer_values(declareRestartableData<
std::vector<
Real>>(
"layer_values")),
96 _layer_has_value(declareRestartableData<
std::vector<
int>>(
"layer_has_value")),
97 _cumulative(parameters.
get<bool>(
"cumulative")),
98 _positive_cumulative_direction(parameters.
get<bool>(
"positive_cumulative_direction")),
99 _layered_base_subproblem(*parameters.getCheckedPointerParam<
SubProblem *>(
"_subproblem")),
100 _layer_bounding_blocks(),
101 _has_direction_max_min(false)
105 mooseError(
"'bounds' and 'num_layers' cannot both be set");
109 "The 'positive_cumulative_direction' parameter is unused when 'cumulative' is false");
123 mooseError(
"At least two boundaries must be provided in 'bounds' to form layers!");
132 for (
unsigned int s = 0; s < splits; ++s)
134 std::vector<Real> new_bnds;
151 mooseError(
"One of 'bounds' or 'num_layers' must be specified");
154 mooseError(
"'sample_type = interpolate' not supported with 'bounds'");
162 mooseWarning(
"'direction_min' is unused when providing 'bounds'");
165 mooseWarning(
"'direction_max' is unused when providing 'bounds'");
168 if (has_layer_bounding_block && (has_direction_min || has_direction_max))
169 mooseError(
"Only one of 'layer_bounding_block' and the pair 'direction_max' and " 170 "'direction_min' can be provided");
173 if (has_direction_min != has_direction_max)
174 mooseError(
"If providing the layer max/min directions, both 'direction_max' and " 175 "'direction_min' must be specified.");
177 if (has_layer_bounding_block)
185 if (has_direction_min && has_direction_max)
192 mooseError(
"'direction_max' must be larger than 'direction_min'");
211 int higher_layer = -1;
212 int lower_layer = -1;
223 for (
int i = layer - 1; i >= 0; i--)
232 if (higher_layer == -1 && lower_layer == -1)
239 if (higher_layer == -1)
242 if (
unsigned(higher_layer) == layer)
245 if (lower_layer == -1)
252 if (higher_layer == -1)
257 Real lower_value = 0;
258 if (lower_layer != -1)
260 lower_coor += (lower_layer + 1) * layer_length;
269 (higher_value - lower_value) * (p(
_direction) - lower_coor) / layer_length;
274 unsigned int num_values = 0;
276 if (higher_layer != -1)
280 int current_layer = higher_layer + i;
293 if (lower_layer != -1)
297 int current_layer = lower_layer - i;
299 if (current_layer < 0)
310 return total / num_values;
366 const auto & lb =
dynamic_cast<const LayeredBase &
>(y);
368 if (lb.layerHasValue(i))
394 std::vector<Real>::const_iterator one_higher =
399 return static_cast<unsigned int>(
408 return static_cast<unsigned int>(std::distance(
_layer_bounds.begin(), one_higher - 1));
454 for (
auto & elem_ptr : *
mesh.getActiveLocalElementRange())
456 auto subdomain_id = elem_ptr->subdomain_id();
462 for (
auto & node : elem_ptr->node_ref_range())
virtual MooseMesh & mesh()=0
std::vector< Real > & _layer_values
Value of the integral for each layer.
bool _using_displaced_mesh
true if this object operates on the displaced mesh, otherwise false
A class for creating restricted objects.
std::string _layered_base_name
Name of this object.
SubProblem & _layered_base_subproblem
Subproblem for the child object.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
bool _interval_based
Whether or not this object is based on equally spaced intervals or "bounds".
bool _cumulative
Whether the values are cumulative over the layers.
void getBounds()
Compute bounds, restricted to blocks if given.
const Parallel::Communicator & comm() const
std::vector< int > & _layer_has_value
Whether or not each layer has had any value summed into it.
static InputParameters validParams()
const InputParameters & _layered_base_params
Params for this object.
std::vector< Real > _layer_centers
center coordinates of each layer
std::vector< SubdomainID > getSubdomainIDs(const std::vector< SubdomainName > &subdomain_names) const
Get the associated subdomainIDs for the subdomain names that are passed in.
auto max(const L &left, const R &right)
virtual void threadJoin(const UserObject &y)
unsigned int _direction
The component direction the layers are going in. We cache this for speed (so we're not always going t...
std::vector< SubdomainID > _layer_bounding_blocks
List of SubdomainIDs, if given.
unsigned int _average_radius
How many layers both above and below the found layer will be used in the average. ...
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
virtual Real getLayerValue(unsigned int layer) const
Get the value for a given layer.
void computeLayerCenters()
Compute the center points for each layer.
void setLayerValue(unsigned int layer, Real value)
Set the value for a particular layer.
virtual Real integralValue(const Point &p) const
Given a Point return the integral value associated with the layer that point falls in...
const bool _positive_cumulative_direction
Whether the cumulative values should be summed in the positive or negative direction.
virtual unsigned int getLayer(const Point &p) const
Helper function to return the layer the point lies in.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
virtual void initialize()
unsigned int _num_layers
Number of layers to split the mesh into.
std::vector< Real > _layer_bounds
The boundaries of the layers.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Generic class for solving transient nonlinear problems.
void max(const T &r, T &o, Request &req) const
This base class computes volume integrals of a variable storing partial sums for the specified number...
IntRange< T > make_range(T beg, T end)
unsigned int _sample_type
How to sample the values.
LayeredBase(const InputParameters ¶meters)
auto min(const L &left, const R &right)
void ErrorVector unsigned int
auto index_range(const T &sizable)
Base class for user-specific data.
bool _has_direction_max_min
whether the max/min coordinate in the direction is known from user input