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

This UserObject 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...
 
virtual void initialize ()
 
virtual void finalize ()
 
virtual void threadJoin (const UserObject &y)
 

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...
 

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...
 
Real _direction_min
 
Real _direction_max
 

Private Attributes

std::vector< Real > _layer_values
 Value of the integral for each layer. More...
 
std::vector< bool > _layer_has_value
 Whether or not each layer has had any value summed into it. More...
 
SubProblem_layered_base_subproblem
 Subproblem for the child object. More...
 
bool _cumulative
 Whether the values are cumulative over the layers. More...
 

Detailed Description

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

Definition at line 44 of file LayeredBase.h.

Constructor & Destructor Documentation

LayeredBase::LayeredBase ( const InputParameters parameters)

Definition at line 62 of file LayeredBase.C.

63  : _layered_base_name(parameters.get<std::string>("_object_name")),
64  _layered_base_params(parameters),
65  _direction_enum(parameters.get<MooseEnum>("direction")),
67  _sample_type(parameters.get<MooseEnum>("sample_type")),
68  _average_radius(parameters.get<unsigned int>("average_radius")),
69  _layered_base_subproblem(*parameters.get<SubProblem *>("_subproblem")),
70  _cumulative(parameters.get<bool>("cumulative"))
71 {
72  if (_layered_base_params.isParamValid("num_layers") &&
74  mooseError("'bounds' and 'num_layers' cannot both be set in ", _layered_base_name);
75 
76  if (_layered_base_params.isParamValid("num_layers"))
77  {
78  _num_layers = _layered_base_params.get<unsigned int>("num_layers");
79  _interval_based = true;
80  }
81  else if (_layered_base_params.isParamValid("bounds"))
82  {
83  _interval_based = false;
84 
85  _layer_bounds = _layered_base_params.get<std::vector<Real>>("bounds");
86 
87  // Make sure the bounds are sorted - we're going to depend on this
88  std::sort(_layer_bounds.begin(), _layer_bounds.end());
89 
90  _num_layers = _layer_bounds.size() - 1; // Layers are only in-between the bounds
91  }
92  else
93  mooseError("One of 'bounds' or 'num_layers' must be specified for ", _layered_base_name);
94 
95  if (!_interval_based && _sample_type == 1)
96  mooseError("'sample_type = interpolate' not supported with 'bounds' in ", _layered_base_name);
97 
98  BoundingBox bounding_box = MeshTools::create_bounding_box(_layered_base_subproblem.mesh());
99  _layer_values.resize(_num_layers);
100  _layer_has_value.resize(_num_layers);
101 
102  _direction_min = bounding_box.min()(_direction);
103  _direction_max = bounding_box.max()(_direction);
104 }
virtual MooseMesh & mesh()=0
std::string _layered_base_name
Name of this object.
Definition: LayeredBase.h:88
SubProblem & _layered_base_subproblem
Subproblem for the child object.
Definition: LayeredBase.h:125
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
bool _interval_based
Whether or not this object is based on equally spaced intervals or "bounds".
Definition: LayeredBase.h:100
bool _cumulative
Whether the values are cumulative over the layers.
Definition: LayeredBase.h:128
const InputParameters & _layered_base_params
Params for this object.
Definition: LayeredBase.h:91
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:97
std::vector< Real > _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:119
unsigned int _average_radius
How many layers both above and below the found layer will be used in the average. ...
Definition: LayeredBase.h:112
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:37
unsigned int _num_layers
Number of layers to split the mesh into.
Definition: LayeredBase.h:103
std::vector< Real > _layer_bounds
The boundaries of the layers.
Definition: LayeredBase.h:106
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:53
Real _direction_min
Definition: LayeredBase.h:114
unsigned int _sample_type
How to sample the values.
Definition: LayeredBase.h:109
Real _direction_max
Definition: LayeredBase.h:115
std::vector< bool > _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:122
MooseEnum _direction_enum
The MooseEnum direction the layers are going in.
Definition: LayeredBase.h:94

Member Function Documentation

void LayeredBase::finalize ( )
virtual

Reimplemented in LayeredSideIntegral, LayeredIntegral, LayeredSideAverage, and LayeredAverage.

Definition at line 236 of file LayeredBase.C.

Referenced by LayeredIntegral::finalize(), and LayeredSideIntegral::finalize().

237 {
240 
241  if (_cumulative)
242  {
243  Real value = 0;
244 
245  for (unsigned i = 0; i < _num_layers; ++i)
246  {
247  value += getLayerValue(i);
248  setLayerValue(i, value);
249  }
250  }
251 }
SubProblem & _layered_base_subproblem
Subproblem for the child object.
Definition: LayeredBase.h:125
bool _cumulative
Whether the values are cumulative over the layers.
Definition: LayeredBase.h:128
virtual Real getLayerValue(unsigned int layer) const
Get the value for a given layer.
Definition: LayeredBase.C:218
std::vector< Real > _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:119
void setLayerValue(unsigned int layer, Real value)
Set the value for a particular layer.
Definition: LayeredBase.C:303
unsigned int _num_layers
Number of layers to split the mesh into.
Definition: LayeredBase.h:103
std::vector< bool > _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:122
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 263 of file LayeredBase.C.

Referenced by LayeredAverage::execute(), LayeredSideAverage::execute(), LayeredIntegral::execute(), LayeredSideIntegral::execute(), and integralValue().

264 {
265  Real direction_x = p(_direction);
266 
267  if (direction_x < _direction_min)
268  return 0;
269 
270  if (_interval_based)
271  {
272  unsigned int layer =
273  std::floor(((direction_x - _direction_min) / (_direction_max - _direction_min)) *
274  static_cast<Real>(_num_layers));
275 
276  if (layer >= _num_layers)
277  layer = _num_layers - 1;
278 
279  return layer;
280  }
281  else // Figure out what layer we are in from the bounds
282  {
283  // This finds the first entry in the vector that is larger than what we're looking for
284  std::vector<Real>::const_iterator one_higher =
285  std::upper_bound(_layer_bounds.begin(), _layer_bounds.end(), direction_x);
286 
287  if (one_higher == _layer_bounds.end())
288  {
289  return static_cast<unsigned int>(
290  _layer_bounds.size() -
291  2); // Just return the last layer. -2 because layers are "in-between" bounds
292  }
293  else if (one_higher == _layer_bounds.begin())
294  return 0; // Return the first layer
295  else
296  // The -1 is because the interval that we fall in is just _before_ the number that is bigger
297  // (which is what we found
298  return static_cast<unsigned int>(std::distance(_layer_bounds.begin(), one_higher - 1));
299  }
300 }
bool _interval_based
Whether or not this object is based on equally spaced intervals or "bounds".
Definition: LayeredBase.h:100
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:97
unsigned int _num_layers
Number of layers to split the mesh into.
Definition: LayeredBase.h:103
std::vector< Real > _layer_bounds
The boundaries of the layers.
Definition: LayeredBase.h:106
Real _direction_min
Definition: LayeredBase.h:114
Real _direction_max
Definition: LayeredBase.h:115
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 218 of file LayeredBase.C.

Referenced by LayeredIntegral::execute(), LayeredSideIntegral::execute(), LayeredAverage::finalize(), LayeredSideAverage::finalize(), finalize(), and threadJoin().

219 {
220  if (layer >= _layer_values.size())
221  mooseError("Layer '", layer, "' not found in '", _layered_base_name, "'.");
222  return _layer_values[layer];
223 }
std::string _layered_base_name
Name of this object.
Definition: LayeredBase.h:88
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::vector< Real > _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:119
void LayeredBase::initialize ( )
virtual

Reimplemented in LayeredSideIntegral, LayeredIntegral, LayeredSideAverage, and LayeredAverage.

Definition at line 226 of file LayeredBase.C.

Referenced by LayeredIntegral::initialize(), and LayeredSideIntegral::initialize().

227 {
228  for (unsigned int i = 0; i < _layer_values.size(); i++)
229  {
230  _layer_values[i] = 0.0;
231  _layer_has_value[i] = false;
232  }
233 }
std::vector< Real > _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:119
std::vector< bool > _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:122
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 107 of file LayeredBase.C.

Referenced by LayeredIntegral::spatialValue(), and LayeredSideIntegral::spatialValue().

108 {
109  unsigned int layer = getLayer(p);
110 
111  int higher_layer = -1;
112  int lower_layer = -1;
113 
114  for (unsigned int i = layer; i < _layer_values.size(); i++)
115  {
116  if (_layer_has_value[i])
117  {
118  higher_layer = i;
119  break;
120  }
121  }
122 
123  for (int i = layer - 1; i >= 0; i--)
124  {
125  if (_layer_has_value[i])
126  {
127  lower_layer = i;
128  break;
129  }
130  }
131 
132  if (higher_layer == -1 && lower_layer == -1)
133  return 0; // TODO: We could error here but there are startup dependency problems
134 
135  switch (_sample_type)
136  {
137  case 0: // direct
138  {
139  if (higher_layer == -1) // Didn't find a higher layer
140  return _layer_values[lower_layer];
141 
142  if (unsigned(higher_layer) == layer) // constant in a layer
143  return _layer_values[higher_layer];
144 
145  if (lower_layer == -1) // Didn't find a lower layer
146  return _layer_values[higher_layer];
147 
148  return (_layer_values[higher_layer] + _layer_values[lower_layer]) / 2;
149  }
150  case 1: // interpolate
151  {
152  if (higher_layer == -1) // Didn't find a higher layer
153  return _layer_values[lower_layer];
154 
155  Real layer_length = (_direction_max - _direction_min) / _num_layers;
156  Real lower_coor = _direction_min;
157  Real lower_value = 0;
158  if (lower_layer != -1)
159  {
160  lower_coor += (lower_layer + 1) * layer_length;
161  lower_value = _layer_values[lower_layer];
162  }
163 
164  // Interpolate between the two points
165  Real higher_value = _layer_values[higher_layer];
166 
167  // Linear interpolation
168  return lower_value +
169  (higher_value - lower_value) * (p(_direction) - lower_coor) / layer_length;
170  }
171  case 2: // average
172  {
173  Real total = 0;
174  unsigned int num_values = 0;
175 
176  if (higher_layer != -1)
177  {
178  for (unsigned int i = 0; i < _average_radius; i++)
179  {
180  int current_layer = higher_layer + i;
181 
182  if ((size_t)current_layer >= _layer_values.size())
183  break;
184 
185  if (_layer_has_value[current_layer])
186  {
187  total += _layer_values[current_layer];
188  num_values += 1;
189  }
190  }
191  }
192 
193  if (lower_layer != -1)
194  {
195  for (unsigned int i = 0; i < _average_radius; i++)
196  {
197  int current_layer = lower_layer - i;
198 
199  if (current_layer < 0)
200  break;
201 
202  if (_layer_has_value[current_layer])
203  {
204  total += _layer_values[current_layer];
205  num_values += 1;
206  }
207  }
208  }
209 
210  return total / num_values;
211  }
212  default:
213  mooseError("Unknown sample type!");
214  }
215 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
virtual unsigned int getLayer(Point p) const
Helper function to return the layer the point lies in.
Definition: LayeredBase.C:263
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:97
std::vector< Real > _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:119
unsigned int _average_radius
How many layers both above and below the found layer will be used in the average. ...
Definition: LayeredBase.h:112
unsigned int _num_layers
Number of layers to split the mesh into.
Definition: LayeredBase.h:103
Real _direction_min
Definition: LayeredBase.h:114
unsigned int _sample_type
How to sample the values.
Definition: LayeredBase.h:109
Real _direction_max
Definition: LayeredBase.h:115
std::vector< bool > _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:122
bool LayeredBase::layerHasValue ( unsigned int  layer) const
inlineprotected

Whether or not a layer has a value.

Definition at line 85 of file LayeredBase.h.

Referenced by LayeredAverage::finalize(), LayeredSideAverage::finalize(), LayeredSideAverage::threadJoin(), and threadJoin().

85 { return _layer_has_value[layer]; }
std::vector< bool > _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:122
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 303 of file LayeredBase.C.

Referenced by LayeredIntegral::execute(), LayeredSideIntegral::execute(), LayeredAverage::finalize(), LayeredSideAverage::finalize(), finalize(), and threadJoin().

304 {
305  _layer_values[layer] = value;
306  _layer_has_value[layer] = true;
307 }
std::vector< Real > _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:119
std::vector< bool > _layer_has_value
Whether or not each layer has had any value summed into it.
Definition: LayeredBase.h:122
void LayeredBase::threadJoin ( const UserObject y)
virtual

Reimplemented in LayeredSideIntegral, LayeredIntegral, LayeredSideAverage, and LayeredAverage.

Definition at line 254 of file LayeredBase.C.

Referenced by LayeredIntegral::threadJoin(), and LayeredSideIntegral::threadJoin().

255 {
256  const LayeredBase & lb = dynamic_cast<const LayeredBase &>(y);
257  for (unsigned int i = 0; i < _layer_values.size(); i++)
258  if (lb.layerHasValue(i))
260 }
bool layerHasValue(unsigned int layer) const
Whether or not a layer has a value.
Definition: LayeredBase.h:85
virtual Real getLayerValue(unsigned int layer) const
Get the value for a given layer.
Definition: LayeredBase.C:218
std::vector< Real > _layer_values
Value of the integral for each layer.
Definition: LayeredBase.h:119
void setLayerValue(unsigned int layer, Real value)
Set the value for a particular layer.
Definition: LayeredBase.C:303
This UserObject computes volume integrals of a variable storing partial sums for the specified number...
Definition: LayeredBase.h:44

Member Data Documentation

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 112 of file LayeredBase.h.

Referenced by integralValue().

bool LayeredBase::_cumulative
private

Whether the values are cumulative over the layers.

Definition at line 128 of file LayeredBase.h.

Referenced by finalize().

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 97 of file LayeredBase.h.

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

MooseEnum LayeredBase::_direction_enum
protected

The MooseEnum direction the layers are going in.

Definition at line 94 of file LayeredBase.h.

Real LayeredBase::_direction_max
protected

Definition at line 115 of file LayeredBase.h.

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

Real LayeredBase::_direction_min
protected

Definition at line 114 of file LayeredBase.h.

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

bool LayeredBase::_interval_based
protected

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

Definition at line 100 of file LayeredBase.h.

Referenced by getLayer(), and LayeredBase().

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

The boundaries of the layers.

Definition at line 106 of file LayeredBase.h.

Referenced by getLayer(), and LayeredBase().

std::vector<bool> LayeredBase::_layer_has_value
private

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

Definition at line 122 of file LayeredBase.h.

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

std::vector<Real> LayeredBase::_layer_values
private

Value of the integral for each layer.

Definition at line 119 of file LayeredBase.h.

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

std::string LayeredBase::_layered_base_name
protected

Name of this object.

Definition at line 88 of file LayeredBase.h.

Referenced by getLayerValue(), and LayeredBase().

const InputParameters& LayeredBase::_layered_base_params
protected

Params for this object.

Definition at line 91 of file LayeredBase.h.

Referenced by LayeredBase().

SubProblem& LayeredBase::_layered_base_subproblem
private

Subproblem for the child object.

Definition at line 125 of file LayeredBase.h.

Referenced by finalize(), and LayeredBase().

unsigned int LayeredBase::_num_layers
protected

Number of layers to split the mesh into.

Definition at line 103 of file LayeredBase.h.

Referenced by finalize(), getLayer(), integralValue(), LayeredAverage::LayeredAverage(), LayeredBase(), and LayeredSideAverage::LayeredSideAverage().

unsigned int LayeredBase::_sample_type
protected

How to sample the values.

Definition at line 109 of file LayeredBase.h.

Referenced by integralValue(), and LayeredBase().


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