www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
LayeredBase Class Reference

This base class computes volume integrals of a variable storing partial sums for the specified number of intervals in a direction (x,y,z). More...

#include <LayeredBase.h>

Inheritance diagram for LayeredBase:
[legend]

Public Member Functions

 LayeredBase (const InputParameters &parameters)
 
virtual Real integralValue (Point p) const
 Given a Point return the integral value associated with the layer that point falls in. More...
 
virtual Real getLayerValue (unsigned int layer) const
 Get the value for a given layer. More...
 
virtual unsigned int getLayer (Point p) const
 Helper function to return the layer the point lies in. More...
 
const std::vector< Real > & getLayerCenters () const
 Get the center coordinates for the layers (along given direction) More...
 
unsigned int direction () const
 Get direction of the layers. More...
 
virtual void initialize ()
 
virtual void finalize ()
 
virtual void threadJoin (const UserObject &y)
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

void setLayerValue (unsigned int layer, Real value)
 Set the value for a particular layer. More...
 
bool layerHasValue (unsigned int layer) const
 Whether or not a layer has a value. More...
 
void getBounds ()
 Compute bounds, restricted to blocks if given. More...
 
void computeLayerCenters ()
 Compute the center points for each layer. More...
 

Protected Attributes

std::string _layered_base_name
 Name of this object. More...
 
const InputParameters_layered_base_params
 Params for this object. More...
 
MooseEnum _direction_enum
 The MooseEnum direction the layers are going in. More...
 
unsigned int _direction
 The component direction the layers are going in. We cache this for speed (so we're not always going through the MooseEnum) More...
 
bool _interval_based
 Whether or not this object is based on equally spaced intervals or "bounds". More...
 
unsigned int _num_layers
 Number of layers to split the mesh into. More...
 
std::vector< Real_layer_bounds
 The boundaries of the layers. More...
 
unsigned int _sample_type
 How to sample the values. More...
 
unsigned int _average_radius
 How many layers both above and below the found layer will be used in the average. More...
 
bool _using_displaced_mesh
 true if this object operates on the displaced mesh, otherwise false More...
 
std::vector< Real_layer_centers
 center coordinates of each layer More...
 
Real _direction_min
 
Real _direction_max
 
std::vector< Real > & _layer_values
 Value of the integral for each layer. More...
 
std::vector< int > & _layer_has_value
 Whether or not each layer has had any value summed into it. More...
 
bool _cumulative
 Whether the values are cumulative over the layers. More...
 
const bool _positive_cumulative_direction
 Whether the cumulative values should be summed in the positive or negative direction. More...
 

Private Member Functions

template<typename T , typename... Args>
T & declareRestartableData (const std::string &data_name, Args &&... args)
 Declare a piece of data as "restartable" and initialize it. More...
 
template<typename T , typename... Args>
ManagedValue< T > declareManagedRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 Declares a piece of "managed" restartable data and initialize it. More...
 
template<typename T , typename... Args>
const T & getRestartableData (const std::string &data_name) const
 Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but returns a const reference to the object. More...
 
template<typename T , typename... Args>
T & declareRestartableDataWithContext (const std::string &data_name, void *context, Args &&... args)
 Declare a piece of data as "restartable" and initialize it. More...
 
template<typename T , typename... Args>
T & declareRecoverableData (const std::string &data_name, Args &&... args)
 Declare a piece of data as "recoverable" and initialize it. More...
 
template<typename T , typename... Args>
T & declareRestartableDataWithObjectName (const std::string &data_name, const std::string &object_name, Args &&... args)
 Declare a piece of data as "restartable". More...
 
template<typename T , typename... Args>
T & declareRestartableDataWithObjectNameWithContext (const std::string &data_name, const std::string &object_name, void *context, Args &&... args)
 Declare a piece of data as "restartable". More...
 
std::string restartableName (const std::string &data_name) const
 Gets the name of a piece of restartable data given a data name, adding the system name and object name prefix. More...
 

Private Attributes

SubProblem_layered_base_subproblem
 Subproblem for the child object. More...
 
std::vector< SubdomainID_layer_bounding_blocks
 List of SubdomainIDs, if given. More...
 
bool _has_direction_max_min
 whether the max/min coordinate in the direction is known from user input More...
 
MooseApp_restartable_app
 Reference to the application. More...
 
const std::string _restartable_system_name
 The system name this object is in. More...
 
const THREAD_ID _restartable_tid
 The thread ID for this object. More...
 
const bool _restartable_read_only
 Flag for toggling read only status (see ReporterData) More...
 

Detailed Description

This base class computes volume integrals of a variable storing partial sums for the specified number of intervals in a direction (x,y,z).

Definition at line 36 of file LayeredBase.h.

Constructor & Destructor Documentation

◆ LayeredBase()

LayeredBase::LayeredBase ( const InputParameters parameters)

Definition at line 78 of file LayeredBase.C.

79  : Restartable(parameters.getCheckedPointerParam<SubProblem *>("_subproblem")->getMooseApp(),
80  parameters.get<std::string>("_object_name") + "_layered_base",
81  "LayeredBase",
82  parameters.get<THREAD_ID>("_tid")),
83  _layered_base_name(parameters.get<std::string>("_object_name")),
84  _layered_base_params(parameters),
85  _direction_enum(parameters.get<MooseEnum>("direction")),
87  _sample_type(parameters.get<MooseEnum>("sample_type")),
88  _average_radius(parameters.get<unsigned int>("average_radius")),
89  _using_displaced_mesh(_layered_base_params.get<bool>("use_displaced_mesh")),
90  _layer_values(declareRestartableData<std::vector<Real>>("layer_values")),
91  _layer_has_value(declareRestartableData<std::vector<int>>("layer_has_value")),
92  _cumulative(parameters.get<bool>("cumulative")),
93  _positive_cumulative_direction(parameters.get<bool>("positive_cumulative_direction")),
94  _layered_base_subproblem(*parameters.getCheckedPointerParam<SubProblem *>("_subproblem")),
97 {
98  if (_layered_base_params.isParamValid("num_layers") &&
100  mooseError("'bounds' and 'num_layers' cannot both be set");
101 
102  if (!_cumulative && parameters.isParamSetByUser("positive_cumulative_direction"))
103  mooseWarning(
104  "The 'positive_cumulative_direction' parameter is unused when 'cumulative' is false");
105 
106  if (_layered_base_params.isParamValid("num_layers"))
107  {
108  _num_layers = _layered_base_params.get<unsigned int>("num_layers");
109  _interval_based = true;
110  }
111  else if (_layered_base_params.isParamValid("bounds"))
112  {
113  _interval_based = false;
114 
115  _layer_bounds = _layered_base_params.get<std::vector<Real>>("bounds");
116 
117  // Make sure the bounds are sorted - we're going to depend on this
118  std::sort(_layer_bounds.begin(), _layer_bounds.end());
119 
120  _num_layers = _layer_bounds.size() - 1; // Layers are only in-between the bounds
121  _direction_min = _layer_bounds.front();
122  _direction_max = _layer_bounds.back();
123  _has_direction_max_min = true;
124  }
125  else
126  mooseError("One of 'bounds' or 'num_layers' must be specified");
127 
128  if (!_interval_based && _sample_type == 1)
129  mooseError("'sample_type = interpolate' not supported with 'bounds'");
130 
131  bool has_layer_bounding_block = _layered_base_params.isParamValid("layer_bounding_block");
132  bool has_block = _layered_base_params.isParamValid("block");
133  bool has_direction_min = _layered_base_params.isParamValid("direction_min");
134  bool has_direction_max = _layered_base_params.isParamValid("direction_max");
135 
136  if (_has_direction_max_min && has_direction_min)
137  mooseWarning("'direction_min' is unused when providing 'bounds'");
138 
139  if (_has_direction_max_min && has_direction_max)
140  mooseWarning("'direction_max' is unused when providing 'bounds'");
141 
142  // can only specify one of layer_bounding_block or the pair direction_max/min
143  if (has_layer_bounding_block && (has_direction_min || has_direction_max))
144  mooseError("Only one of 'layer_bounding_block' and the pair 'direction_max' and "
145  "'direction_min' can be provided");
146 
147  // if either one of direction_min or direction_max is specified, must provide the other one
148  if (has_direction_min != has_direction_max)
149  mooseError("If providing the layer max/min directions, both 'direction_max' and "
150  "'direction_min' must be specified.");
151 
152  if (has_layer_bounding_block)
154  _layered_base_params.get<std::vector<SubdomainName>>("layer_bounding_block"));
155  else if (has_block)
157  _layered_base_params.get<std::vector<SubdomainName>>("block"));
158 
159  // specifying the direction max/min overrides anything set with the 'block'
160  if (has_direction_min && has_direction_max)
161  {
162  _direction_min = parameters.get<Real>("direction_min");
163  _direction_max = parameters.get<Real>("direction_max");
164  _has_direction_max_min = true;
165 
167  mooseError("'direction_max' must be larger than 'direction_min'");
168  }
169 
170  _layer_values.resize(_num_layers);
172 
173  // if we haven't already figured out the max/min in specified direction
174  // (either with the 'bounds' or explicit specification from the user), do so
176  getBounds();
177 
179 }
virtual MooseMesh & mesh()=0
std::vector< Real > & _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:139
bool _using_displaced_mesh
true if this object operates on the displaced mesh, otherwise false
Definition: LayeredBase.h:130
std::string _layered_base_name
Name of this object.
Definition: LayeredBase.h:103
SubProblem & _layered_base_subproblem
Subproblem for the child object.
Definition: LayeredBase.h:152
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
Definition: MooseError.h:333
bool _interval_based
Whether or not this object is based on equally spaced intervals or "bounds".
Definition: LayeredBase.h:115
bool _cumulative
Whether the values are cumulative over the layers.
Definition: LayeredBase.h:145
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
void getBounds()
Compute bounds, restricted to blocks if given.
Definition: LayeredBase.C:414
T & declareRestartableData(const std::string &data_name, Args &&... args)
Declare a piece of data as "restartable" and initialize it.
Definition: Restartable.h:269
std::vector< int > & _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:142
const InputParameters & _layered_base_params
Params for this object.
Definition: LayeredBase.h:106
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:45
unsigned int _direction
The component direction the layers are going in. We cache this for speed (so we&#39;re not always going t...
Definition: LayeredBase.h:112
std::vector< SubdomainID > _layer_bounding_blocks
List of SubdomainIDs, if given.
Definition: LayeredBase.h:155
unsigned int _average_radius
How many layers both above and below the found layer will be used in the average. ...
Definition: LayeredBase.h:127
void computeLayerCenters()
Compute the center points for each layer.
Definition: LayeredBase.C:388
const bool _positive_cumulative_direction
Whether the cumulative values should be summed in the positive or negative direction.
Definition: LayeredBase.h:148
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
unsigned int _num_layers
Number of layers to split the mesh into.
Definition: LayeredBase.h:118
Restartable(const MooseObject *moose_object, const std::string &system_name)
Class constructor.
Definition: Restartable.C:18
std::vector< Real > _layer_bounds
The boundaries of the layers.
Definition: LayeredBase.h:121
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:75
Real _direction_min
Definition: LayeredBase.h:135
std::vector< SubdomainID > getSubdomainIDs(const std::vector< SubdomainName > &subdomain_name) const
Get the associated subdomainIDs for the subdomain names that are passed in.
Definition: MooseMesh.C:1520
unsigned int _sample_type
How to sample the values.
Definition: LayeredBase.h:124
Real _direction_max
Definition: LayeredBase.h:136
unsigned int THREAD_ID
Definition: MooseTypes.h:198
bool _has_direction_max_min
whether the max/min coordinate in the direction is known from user input
Definition: LayeredBase.h:158
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
MooseEnum _direction_enum
The MooseEnum direction the layers are going in.
Definition: LayeredBase.h:109

Member Function Documentation

◆ computeLayerCenters()

void LayeredBase::computeLayerCenters ( )
protected

Compute the center points for each layer.

Definition at line 388 of file LayeredBase.C.

Referenced by LayeredBase().

389 {
390  _layer_centers.resize(_num_layers);
391 
392  if (_interval_based)
393  {
395 
396  for (const auto i : make_range(_num_layers))
397  _layer_centers[i] = (i + 0.5) * dx;
398  }
399  else
400  {
401  for (const auto i : make_range(_num_layers))
402  _layer_centers[i] = 0.5 * (_layer_bounds[i + 1] + _layer_bounds[i]);
403  }
404 }
bool _interval_based
Whether or not this object is based on equally spaced intervals or "bounds".
Definition: LayeredBase.h:115
std::vector< Real > _layer_centers
center coordinates of each layer
Definition: LayeredBase.h:133
unsigned int _num_layers
Number of layers to split the mesh into.
Definition: LayeredBase.h:118
std::vector< Real > _layer_bounds
The boundaries of the layers.
Definition: LayeredBase.h:121
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
Real _direction_min
Definition: LayeredBase.h:135
Real _direction_max
Definition: LayeredBase.h:136

◆ declareManagedRestartableDataWithContext()

template<typename T , typename... Args>
Restartable::ManagedValue< T > Restartable::declareManagedRestartableDataWithContext ( const std::string &  data_name,
void context,
Args &&...  args 
)
protectedinherited

Declares a piece of "managed" restartable data and initialize it.

Here, "managed" restartable data means that the caller can destruct this data upon destruction of the return value of this method. Therefore, this ManagedValue<T> wrapper should survive after the final calls to dataStore() for it. That is... at the very end.

This is needed for objects whose destruction ordering is important, and enables natural c++ destruction in reverse construction order of the object that declares it.

See delcareRestartableData and declareRestartableDataWithContext for more information.

Definition at line 276 of file Restartable.h.

279 {
280  auto & data_ptr =
281  declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...);
282  return Restartable::ManagedValue<T>(data_ptr);
283 }
Wrapper class for restartable data that is "managed.
Definition: Restartable.h:42

◆ declareRecoverableData()

template<typename T , typename... Args>
T & Restartable::declareRecoverableData ( const std::string &  data_name,
Args &&...  args 
)
protectedinherited

Declare a piece of data as "recoverable" and initialize it.

This means that in the event of a restart this piece of data will be restored back to its previous value.

Note - this data will NOT be restored on Restart!

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
argsArguments to forward to the constructor of the data

Definition at line 351 of file Restartable.h.

352 {
353  const auto full_name = restartableName(data_name);
354 
356 
357  return declareRestartableDataWithContext<T>(data_name, nullptr, std::forward<Args>(args)...);
358 }
std::string restartableName(const std::string &data_name) const
Gets the name of a piece of restartable data given a data name, adding the system name and object nam...
Definition: Restartable.C:66
void registerRestartableNameWithFilterOnApp(const std::string &name, Moose::RESTARTABLE_FILTER filter)
Helper function for actually registering the restartable data.
Definition: Restartable.C:59

◆ declareRestartableData()

template<typename T , typename... Args>
T & Restartable::declareRestartableData ( const std::string &  data_name,
Args &&...  args 
)
protectedinherited

Declare a piece of data as "restartable" and initialize it.

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
argsArguments to forward to the constructor of the data

Definition at line 269 of file Restartable.h.

270 {
271  return declareRestartableDataWithContext<T>(data_name, nullptr, std::forward<Args>(args)...);
272 }

◆ declareRestartableDataWithContext()

template<typename T , typename... Args>
T & Restartable::declareRestartableDataWithContext ( const std::string &  data_name,
void context,
Args &&...  args 
)
protectedinherited

Declare a piece of data as "restartable" and initialize it.

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
contextContext pointer that will be passed to the load and store functions
argsArguments to forward to the constructor of the data

Definition at line 294 of file Restartable.h.

297 {
298  return declareRestartableDataHelper<T>(data_name, context, std::forward<Args>(args)...).set();
299 }

◆ declareRestartableDataWithObjectName()

template<typename T , typename... Args>
T & Restartable::declareRestartableDataWithObjectName ( const std::string &  data_name,
const std::string &  object_name,
Args &&...  args 
)
protectedinherited

Declare a piece of data as "restartable".

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
object_nameA supplied name for the object that is declaring this data.
argsArguments to forward to the constructor of the data

Definition at line 323 of file Restartable.h.

326 {
327  return declareRestartableDataWithObjectNameWithContext<T>(
328  data_name, object_name, nullptr, std::forward<Args>(args)...);
329 }

◆ declareRestartableDataWithObjectNameWithContext()

template<typename T , typename... Args>
T & Restartable::declareRestartableDataWithObjectNameWithContext ( const std::string &  data_name,
const std::string &  object_name,
void context,
Args &&...  args 
)
protectedinherited

Declare a piece of data as "restartable".

This means that in the event of a restart this piece of data will be restored back to its previous value.

NOTE: This returns a reference! Make sure you store it in a reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)
object_nameA supplied name for the object that is declaring this data.
contextContext pointer that will be passed to the load and store functions
argsArguments to forward to the constructor of the data

Definition at line 333 of file Restartable.h.

337 {
338  std::string old_name = _restartable_name;
339 
340  _restartable_name = object_name;
341 
342  T & value = declareRestartableDataWithContext<T>(data_name, context, std::forward<Args>(args)...);
343 
344  _restartable_name = old_name;
345 
346  return value;
347 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:243
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ direction()

unsigned int LayeredBase::direction ( ) const
inline

Get direction of the layers.

Returns
layer direction

Definition at line 73 of file LayeredBase.h.

73 { return _direction; }
unsigned int _direction
The component direction the layers are going in. We cache this for speed (so we&#39;re not always going t...
Definition: LayeredBase.h:112

◆ finalize()

void LayeredBase::finalize ( )
virtual

Reimplemented in FunctionLayeredIntegral, LayeredExtremumMaterialProperty, LayeredIntegral, LayeredSideIntegralBase< UserObjectType >, LayeredSideIntegralBase< SideIntegralFunctorUserObject >, LayeredSideIntegralBase< SideIntegralVariableUserObject >, LayeredSideAverageBase< LayeredSideIntegralFunctor >, LayeredSideAverageBase< LayeredSideIntegral >, and LayeredAverage.

Definition at line 314 of file LayeredBase.C.

Referenced by LayeredSideIntegralBase< SideIntegralVariableUserObject >::finalize(), LayeredIntegral::finalize(), and FunctionLayeredIntegral::finalize().

315 {
318 
319  if (_cumulative)
320  {
321  Real value = 0;
322 
324  for (const auto i : make_range(_num_layers))
325  {
326  value += getLayerValue(i);
327  setLayerValue(i, value);
328  }
329  else
330  for (int i = _num_layers - 1; i >= 0; i--)
331  {
332  value += getLayerValue(i);
333  setLayerValue(i, value);
334  }
335  }
336 }
std::vector< Real > & _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:139
SubProblem & _layered_base_subproblem
Subproblem for the child object.
Definition: LayeredBase.h:152
bool _cumulative
Whether the values are cumulative over the layers.
Definition: LayeredBase.h:145
const Parallel::Communicator & comm() const
std::vector< int > & _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:142
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
virtual Real getLayerValue(unsigned int layer) const
Get the value for a given layer.
Definition: LayeredBase.C:293
void setLayerValue(unsigned int layer, Real value)
Set the value for a particular layer.
Definition: LayeredBase.C:407
const bool _positive_cumulative_direction
Whether the cumulative values should be summed in the positive or negative direction.
Definition: LayeredBase.h:148
unsigned int _num_layers
Number of layers to split the mesh into.
Definition: LayeredBase.h:118
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void max(const T &r, T &o, Request &req) const
IntRange< T > make_range(T beg, T end)

◆ getBounds()

void LayeredBase::getBounds ( )
protected

Compute bounds, restricted to blocks if given.

Definition at line 414 of file LayeredBase.C.

Referenced by initialize(), and LayeredBase().

415 {
416  if (_layer_bounding_blocks.size() == 0)
417  {
418  BoundingBox bounding_box = MeshTools::create_bounding_box(_layered_base_subproblem.mesh());
419  _direction_min = bounding_box.min()(_direction);
420  _direction_max = bounding_box.max()(_direction);
421  }
422  else
423  {
424  _direction_min = std::numeric_limits<Real>::infinity();
425  _direction_max = -std::numeric_limits<Real>::infinity();
426 
428 
429  for (auto & elem_ptr : *mesh.getActiveLocalElementRange())
430  {
431  auto subdomain_id = elem_ptr->subdomain_id();
432 
433  if (std::find(_layer_bounding_blocks.begin(), _layer_bounding_blocks.end(), subdomain_id) ==
435  continue;
436 
437  for (auto & node : elem_ptr->node_ref_range())
438  {
441  }
442  }
443 
444  mesh.comm().min(_direction_min);
445  mesh.comm().max(_direction_max);
446  }
447 }
virtual MooseMesh & mesh()=0
SubProblem & _layered_base_subproblem
Subproblem for the child object.
Definition: LayeredBase.h:152
MeshBase & mesh
auto max(const L &left, const R &right)
unsigned int _direction
The component direction the layers are going in. We cache this for speed (so we&#39;re not always going t...
Definition: LayeredBase.h:112
std::vector< SubdomainID > _layer_bounding_blocks
List of SubdomainIDs, if given.
Definition: LayeredBase.h:155
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
Real _direction_min
Definition: LayeredBase.h:135
Real _direction_max
Definition: LayeredBase.h:136
auto min(const L &left, const R &right)

◆ getLayer()

unsigned int LayeredBase::getLayer ( Point  p) const
virtual

Helper function to return the layer the point lies in.

Parameters
pThe point.
Returns
The layer the Point is found in.

Definition at line 348 of file LayeredBase.C.

Referenced by LayeredAverage::execute(), LayeredIntegral::execute(), LayeredExtremumMaterialProperty::execute(), FunctionLayeredIntegral::execute(), and integralValue().

349 {
350  Real direction_x = p(_direction);
351 
352  if (direction_x < _direction_min)
353  return 0;
354 
355  if (_interval_based)
356  {
357  unsigned int layer =
358  std::floor(((direction_x - _direction_min) / (_direction_max - _direction_min)) *
359  static_cast<Real>(_num_layers));
360 
361  if (layer >= _num_layers)
362  layer = _num_layers - 1;
363 
364  return layer;
365  }
366  else // Figure out what layer we are in from the bounds
367  {
368  // This finds the first entry in the vector that is larger than what we're looking for
369  std::vector<Real>::const_iterator one_higher =
370  std::upper_bound(_layer_bounds.begin(), _layer_bounds.end(), direction_x);
371 
372  if (one_higher == _layer_bounds.end())
373  {
374  return static_cast<unsigned int>(
375  _layer_bounds.size() -
376  2); // Just return the last layer. -2 because layers are "in-between" bounds
377  }
378  else if (one_higher == _layer_bounds.begin())
379  return 0; // Return the first layer
380  else
381  // The -1 is because the interval that we fall in is just _before_ the number that is bigger
382  // (which is what we found
383  return static_cast<unsigned int>(std::distance(_layer_bounds.begin(), one_higher - 1));
384  }
385 }
bool _interval_based
Whether or not this object is based on equally spaced intervals or "bounds".
Definition: LayeredBase.h:115
unsigned int _direction
The component direction the layers are going in. We cache this for speed (so we&#39;re not always going t...
Definition: LayeredBase.h:112
unsigned int _num_layers
Number of layers to split the mesh into.
Definition: LayeredBase.h:118
std::vector< Real > _layer_bounds
The boundaries of the layers.
Definition: LayeredBase.h:121
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real _direction_min
Definition: LayeredBase.h:135
Real _direction_max
Definition: LayeredBase.h:136

◆ getLayerCenters()

const std::vector<Real>& LayeredBase::getLayerCenters ( ) const
inline

Get the center coordinates for the layers (along given direction)

Definition at line 67 of file LayeredBase.h.

Referenced by NearestPointBase< LayeredSideDiffusiveFluxAverage, SideIntegralVariableUserObject >::spatialPoints().

67 { return _layer_centers; }
std::vector< Real > _layer_centers
center coordinates of each layer
Definition: LayeredBase.h:133

◆ getLayerValue()

Real LayeredBase::getLayerValue ( unsigned int  layer) const
virtual

Get the value for a given layer.

Parameters
layerThe layer index
Returns
The value for the given layer

Definition at line 293 of file LayeredBase.C.

Referenced by LayeredExtremumMaterialProperty::execute(), LayeredIntegral::execute(), FunctionLayeredIntegral::execute(), LayeredAverage::finalize(), LayeredExtremumMaterialProperty::finalize(), finalize(), LayeredExtremumMaterialProperty::threadJoin(), and threadJoin().

294 {
295  if (layer >= _layer_values.size())
296  mooseError("Layer '", layer, "' not found in '", _layered_base_name, "'.");
297  return _layer_values[layer];
298 }
std::vector< Real > & _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:139
std::string _layered_base_name
Name of this object.
Definition: LayeredBase.h:103
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299

◆ getRestartableData()

template<typename T , typename... Args>
const T & Restartable::getRestartableData ( const std::string &  data_name) const
protectedinherited

Declare a piece of data as "restartable" and initialize it Similar to declareRestartableData but returns a const reference to the object.

Forwarded arguments are not allowed in this case because we assume that the object is restarted and we won't need different constructors to initialize it.

NOTE: This returns a const reference! Make sure you store it in a const reference!

Parameters
data_nameThe name of the data (usually just use the same name as the member variable)

Definition at line 287 of file Restartable.h.

288 {
289  return declareRestartableDataHelper<T>(data_name, nullptr).get();
290 }

◆ initialize()

void LayeredBase::initialize ( )
virtual

Reimplemented in FunctionLayeredIntegral, LayeredExtremumMaterialProperty, LayeredIntegral, LayeredSideIntegralBase< UserObjectType >, LayeredSideIntegralBase< SideIntegralFunctorUserObject >, LayeredSideIntegralBase< SideIntegralVariableUserObject >, LayeredSideAverageBase< LayeredSideIntegralFunctor >, LayeredSideAverageBase< LayeredSideIntegral >, and LayeredAverage.

Definition at line 301 of file LayeredBase.C.

Referenced by LayeredSideIntegralBase< SideIntegralVariableUserObject >::initialize(), LayeredIntegral::initialize(), LayeredExtremumMaterialProperty::initialize(), and FunctionLayeredIntegral::initialize().

302 {
304  getBounds();
305 
306  for (const auto i : index_range(_layer_values))
307  {
308  _layer_values[i] = 0.0;
309  _layer_has_value[i] = false;
310  }
311 }
std::vector< Real > & _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:139
bool _using_displaced_mesh
true if this object operates on the displaced mesh, otherwise false
Definition: LayeredBase.h:130
void getBounds()
Compute bounds, restricted to blocks if given.
Definition: LayeredBase.C:414
std::vector< int > & _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:142
auto index_range(const T &sizable)

◆ integralValue()

Real LayeredBase::integralValue ( Point  p) const
virtual

Given a Point return the integral value associated with the layer that point falls in.

Parameters
pThe point to look for in the layers.

Definition at line 182 of file LayeredBase.C.

Referenced by LayeredSideIntegralBase< SideIntegralVariableUserObject >::spatialValue(), LayeredExtremumMaterialProperty::spatialValue(), LayeredIntegral::spatialValue(), and FunctionLayeredIntegral::spatialValue().

183 {
184  unsigned int layer = getLayer(p);
185 
186  int higher_layer = -1;
187  int lower_layer = -1;
188 
189  for (unsigned int i = layer; i < _layer_values.size(); i++)
190  {
191  if (_layer_has_value[i])
192  {
193  higher_layer = i;
194  break;
195  }
196  }
197 
198  for (int i = layer - 1; i >= 0; i--)
199  {
200  if (_layer_has_value[i])
201  {
202  lower_layer = i;
203  break;
204  }
205  }
206 
207  if (higher_layer == -1 && lower_layer == -1)
208  return 0; // TODO: We could error here but there are startup dependency problems
209 
210  switch (_sample_type)
211  {
212  case 0: // direct
213  {
214  if (higher_layer == -1) // Didn't find a higher layer
215  return _layer_values[lower_layer];
216 
217  if (unsigned(higher_layer) == layer) // constant in a layer
218  return _layer_values[higher_layer];
219 
220  if (lower_layer == -1) // Didn't find a lower layer
221  return _layer_values[higher_layer];
222 
223  return (_layer_values[higher_layer] + _layer_values[lower_layer]) / 2;
224  }
225  case 1: // interpolate
226  {
227  if (higher_layer == -1) // Didn't find a higher layer
228  return _layer_values[lower_layer];
229 
230  Real layer_length = (_direction_max - _direction_min) / _num_layers;
231  Real lower_coor = _direction_min;
232  Real lower_value = 0;
233  if (lower_layer != -1)
234  {
235  lower_coor += (lower_layer + 1) * layer_length;
236  lower_value = _layer_values[lower_layer];
237  }
238 
239  // Interpolate between the two points
240  Real higher_value = _layer_values[higher_layer];
241 
242  // Linear interpolation
243  return lower_value +
244  (higher_value - lower_value) * (p(_direction) - lower_coor) / layer_length;
245  }
246  case 2: // average
247  {
248  Real total = 0;
249  unsigned int num_values = 0;
250 
251  if (higher_layer != -1)
252  {
253  for (const auto i : make_range(_average_radius))
254  {
255  int current_layer = higher_layer + i;
256 
257  if ((size_t)current_layer >= _layer_values.size())
258  break;
259 
260  if (_layer_has_value[current_layer])
261  {
262  total += _layer_values[current_layer];
263  num_values += 1;
264  }
265  }
266  }
267 
268  if (lower_layer != -1)
269  {
270  for (const auto i : make_range(_average_radius))
271  {
272  int current_layer = lower_layer - i;
273 
274  if (current_layer < 0)
275  break;
276 
277  if (_layer_has_value[current_layer])
278  {
279  total += _layer_values[current_layer];
280  num_values += 1;
281  }
282  }
283  }
284 
285  return total / num_values;
286  }
287  default:
288  mooseError("Unknown sample type!");
289  }
290 }
std::vector< Real > & _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:139
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
std::vector< int > & _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:142
unsigned int _direction
The component direction the layers are going in. We cache this for speed (so we&#39;re not always going t...
Definition: LayeredBase.h:112
unsigned int _average_radius
How many layers both above and below the found layer will be used in the average. ...
Definition: LayeredBase.h:127
unsigned int _num_layers
Number of layers to split the mesh into.
Definition: LayeredBase.h:118
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual unsigned int getLayer(Point p) const
Helper function to return the layer the point lies in.
Definition: LayeredBase.C:348
IntRange< T > make_range(T beg, T end)
Real _direction_min
Definition: LayeredBase.h:135
unsigned int _sample_type
How to sample the values.
Definition: LayeredBase.h:124
Real _direction_max
Definition: LayeredBase.h:136

◆ layerHasValue()

bool LayeredBase::layerHasValue ( unsigned int  layer) const
inlineprotected

Whether or not a layer has a value.

Definition at line 90 of file LayeredBase.h.

Referenced by LayeredAverage::finalize().

90 { return _layer_has_value[layer]; }
std::vector< int > & _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:142

◆ restartableName()

std::string Restartable::restartableName ( const std::string &  data_name) const
protectedinherited

Gets the name of a piece of restartable data given a data name, adding the system name and object name prefix.

This should only be used in this interface and in testing.

Definition at line 66 of file Restartable.C.

Referenced by Restartable::declareRecoverableData(), and Restartable::declareRestartableDataHelper().

67 {
68  return _restartable_system_name + "/" + _restartable_name + "/" + data_name;
69 }
std::string _restartable_name
The name of the object.
Definition: Restartable.h:243
const std::string _restartable_system_name
The system name this object is in.
Definition: Restartable.h:230

◆ setLayerValue()

void LayeredBase::setLayerValue ( unsigned int  layer,
Real  value 
)
protected

Set the value for a particular layer.

Parameters
layerThe layer you are setting the value for
valueThe value to set

Definition at line 407 of file LayeredBase.C.

Referenced by LayeredExtremumMaterialProperty::execute(), LayeredIntegral::execute(), FunctionLayeredIntegral::execute(), LayeredAverage::finalize(), LayeredExtremumMaterialProperty::finalize(), finalize(), LayeredExtremumMaterialProperty::initialize(), LayeredExtremumMaterialProperty::threadJoin(), and threadJoin().

408 {
409  _layer_values[layer] = value;
410  _layer_has_value[layer] = true;
411 }
std::vector< Real > & _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:139
std::vector< int > & _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:142
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ threadJoin()

void LayeredBase::threadJoin ( const UserObject y)
virtual

Reimplemented in FunctionLayeredIntegral, LayeredExtremumMaterialProperty, LayeredIntegral, LayeredSideIntegralBase< UserObjectType >, LayeredSideIntegralBase< SideIntegralFunctorUserObject >, LayeredSideIntegralBase< SideIntegralVariableUserObject >, LayeredSideAverageBase< LayeredSideIntegralFunctor >, LayeredSideAverageBase< LayeredSideIntegral >, and LayeredAverage.

Definition at line 339 of file LayeredBase.C.

Referenced by LayeredSideIntegralBase< SideIntegralVariableUserObject >::threadJoin(), LayeredIntegral::threadJoin(), and FunctionLayeredIntegral::threadJoin().

340 {
341  const auto & lb = dynamic_cast<const LayeredBase &>(y);
342  for (const auto i : index_range(_layer_values))
343  if (lb.layerHasValue(i))
344  setLayerValue(i, getLayerValue(i) + lb._layer_values[i]);
345 }
std::vector< Real > & _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:139
virtual Real getLayerValue(unsigned int layer) const
Get the value for a given layer.
Definition: LayeredBase.C:293
void setLayerValue(unsigned int layer, Real value)
Set the value for a particular layer.
Definition: LayeredBase.C:407
This base class computes volume integrals of a variable storing partial sums for the specified number...
Definition: LayeredBase.h:36
auto index_range(const T &sizable)

◆ validParams()

InputParameters LayeredBase::validParams ( )
static

Definition at line 22 of file LayeredBase.C.

Referenced by LayeredSideIntegralBase< SideIntegralVariableUserObject >::validParams(), LayeredIntegral::validParams(), LayeredExtremumMaterialProperty::validParams(), and FunctionLayeredIntegral::validParams().

23 {
25  MooseEnum directions("x y z");
26 
27  params.addRequiredParam<MooseEnum>("direction", directions, "The direction of the layers.");
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 "
32  "positions.");
33 
34  MooseEnum sample_options("direct interpolate average", "direct");
35  params.addParam<MooseEnum>("sample_type",
36  sample_options,
37  "How to sample the layers. 'direct' means get the value of the layer "
38  "the point falls in directly (or average if that layer has no value). "
39  " 'interpolate' does a linear interpolation between the two closest "
40  "layers. 'average' averages the two closest layers.");
41 
42  params.addParam<unsigned int>("average_radius",
43  1,
44  "When using 'average' sampling this is how "
45  "the number of values both above and below "
46  "the layer that will be averaged.");
47 
48  params.addParam<bool>(
49  "cumulative",
50  false,
51  "When true the value in each layer is the sum of the values up to and including that layer");
52  params.addParam<bool>(
53  "positive_cumulative_direction",
54  true,
55  "When 'cumulative' is true, whether the direction for summing the cumulative value "
56  "is the positive direction or negative direction");
57 
58  params.addParam<std::vector<SubdomainName>>(
59  "block", "The list of block ids (SubdomainID) that this object will be applied");
60 
61  params.addParam<std::vector<SubdomainName>>("layer_bounding_block",
62  "List of block ids (SubdomainID) that are used to "
63  "determine the upper and lower geometric bounds for "
64  "all layers. If this is not specified, the ids "
65  "specified in 'block' are used for this purpose.");
66 
67  params.addParam<Real>("direction_min",
68  "Minimum coordinate along 'direction' that bounds the layers");
69  params.addParam<Real>("direction_max",
70  "Maximum coordinate along 'direction' that bounds the layers");
71  params.addParamNamesToGroup("direction num_layers bounds direction_min direction_max",
72  "Layers extent and definition");
73  params.addParamNamesToGroup("sample_type average_radius cumulative positive_cumulative_direction",
74  "Value sampling / aggregating");
75  return params;
76 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
InputParameters emptyInputParameters()
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...

Member Data Documentation

◆ _average_radius

unsigned int LayeredBase::_average_radius
protected

How many layers both above and below the found layer will be used in the average.

Definition at line 127 of file LayeredBase.h.

Referenced by integralValue().

◆ _cumulative

bool LayeredBase::_cumulative
protected

Whether the values are cumulative over the layers.

Definition at line 145 of file LayeredBase.h.

Referenced by LayeredExtremumMaterialProperty::finalize(), finalize(), and LayeredBase().

◆ _direction

unsigned int LayeredBase::_direction
protected

The component direction the layers are going in. We cache this for speed (so we're not always going through the MooseEnum)

Definition at line 112 of file LayeredBase.h.

Referenced by direction(), getBounds(), getLayer(), integralValue(), LayeredExtremumMaterialProperty::spatialPoints(), LayeredIntegral::spatialPoints(), and FunctionLayeredIntegral::spatialPoints().

◆ _direction_enum

MooseEnum LayeredBase::_direction_enum
protected

The MooseEnum direction the layers are going in.

Definition at line 109 of file LayeredBase.h.

◆ _direction_max

Real LayeredBase::_direction_max
protected

Definition at line 136 of file LayeredBase.h.

Referenced by computeLayerCenters(), getBounds(), getLayer(), integralValue(), and LayeredBase().

◆ _direction_min

Real LayeredBase::_direction_min
protected

Definition at line 135 of file LayeredBase.h.

Referenced by computeLayerCenters(), getBounds(), getLayer(), integralValue(), and LayeredBase().

◆ _has_direction_max_min

bool LayeredBase::_has_direction_max_min
private

whether the max/min coordinate in the direction is known from user input

Definition at line 158 of file LayeredBase.h.

Referenced by LayeredBase().

◆ _interval_based

bool LayeredBase::_interval_based
protected

Whether or not this object is based on equally spaced intervals or "bounds".

Definition at line 115 of file LayeredBase.h.

Referenced by computeLayerCenters(), getLayer(), and LayeredBase().

◆ _layer_bounding_blocks

std::vector<SubdomainID> LayeredBase::_layer_bounding_blocks
private

List of SubdomainIDs, if given.

Definition at line 155 of file LayeredBase.h.

Referenced by getBounds(), and LayeredBase().

◆ _layer_bounds

std::vector<Real> LayeredBase::_layer_bounds
protected

The boundaries of the layers.

Definition at line 121 of file LayeredBase.h.

Referenced by computeLayerCenters(), getLayer(), and LayeredBase().

◆ _layer_centers

std::vector<Real> LayeredBase::_layer_centers
protected

◆ _layer_has_value

std::vector<int>& LayeredBase::_layer_has_value
protected

Whether or not each layer has had any value summed into it.

Definition at line 142 of file LayeredBase.h.

Referenced by LayeredExtremumMaterialProperty::finalize(), finalize(), initialize(), integralValue(), LayeredBase(), layerHasValue(), and setLayerValue().

◆ _layer_values

std::vector<Real>& LayeredBase::_layer_values
protected

Value of the integral for each layer.

Definition at line 139 of file LayeredBase.h.

Referenced by LayeredExtremumMaterialProperty::finalize(), finalize(), getLayerValue(), initialize(), integralValue(), LayeredBase(), setLayerValue(), and threadJoin().

◆ _layered_base_name

std::string LayeredBase::_layered_base_name
protected

Name of this object.

Definition at line 103 of file LayeredBase.h.

Referenced by getLayerValue().

◆ _layered_base_params

const InputParameters& LayeredBase::_layered_base_params
protected

Params for this object.

Definition at line 106 of file LayeredBase.h.

Referenced by LayeredBase().

◆ _layered_base_subproblem

SubProblem& LayeredBase::_layered_base_subproblem
private

Subproblem for the child object.

Definition at line 152 of file LayeredBase.h.

Referenced by finalize(), getBounds(), and LayeredBase().

◆ _num_layers

unsigned int LayeredBase::_num_layers
protected

◆ _positive_cumulative_direction

const bool LayeredBase::_positive_cumulative_direction
protected

Whether the cumulative values should be summed in the positive or negative direction.

Definition at line 148 of file LayeredBase.h.

Referenced by LayeredExtremumMaterialProperty::finalize(), and finalize().

◆ _restartable_app

MooseApp& Restartable::_restartable_app
protectedinherited

Reference to the application.

Definition at line 227 of file Restartable.h.

Referenced by Restartable::registerRestartableDataOnApp(), and Restartable::registerRestartableNameWithFilterOnApp().

◆ _restartable_read_only

const bool Restartable::_restartable_read_only
protectedinherited

Flag for toggling read only status (see ReporterData)

Definition at line 236 of file Restartable.h.

Referenced by Restartable::registerRestartableDataOnApp().

◆ _restartable_system_name

const std::string Restartable::_restartable_system_name
protectedinherited

The system name this object is in.

Definition at line 230 of file Restartable.h.

Referenced by Restartable::restartableName().

◆ _restartable_tid

const THREAD_ID Restartable::_restartable_tid
protectedinherited

The thread ID for this object.

Definition at line 233 of file Restartable.h.

Referenced by Restartable::declareRestartableDataHelper().

◆ _sample_type

unsigned int LayeredBase::_sample_type
protected

How to sample the values.

Definition at line 124 of file LayeredBase.h.

Referenced by integralValue(), and LayeredBase().

◆ _using_displaced_mesh

bool LayeredBase::_using_displaced_mesh
protected

true if this object operates on the displaced mesh, otherwise false

Definition at line 130 of file LayeredBase.h.

Referenced by initialize().


The documentation for this class was generated from the following files: