www.mooseframework.org
NearestPointIntegralVariablePostprocessor.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 // MOOSE includes
12 
14 
17 {
20 
21  params.addClassDescription(
22  "Compute element variable integrals for nearest-point based subdomains");
23 
24  params.registerBase("VectorPostprocessor");
25 
26  return params;
27 }
28 
30  const InputParameters & parameters)
32  parameters),
33  _np_post_processor_values(declareVector("np_post_processor_values"))
34 {
36 }
37 
38 Real
40 {
41  unsigned int i = nearestPointIndex(point);
42 
43  if (i >= _np_post_processor_values.size())
44  mooseError("The vector length of vector post processor is ",
46  " but nearestPointIndex() return ",
47  i);
48 
49  return _np_post_processor_values[i];
50 }
51 
52 Real
54 {
55  if (i >= _np_post_processor_values.size())
56  mooseError("The vector length of vector post processor is ",
58  " but you pass in ",
59  i);
60 
61  return _np_post_processor_values[i];
62 }
63 
64 void
66 {
67  if (_user_objects.size() != _np_post_processor_values.size())
68  mooseError("The vector length of the vector postprocessor ",
70  " is different from the number of user objects ",
71  _user_objects.size());
72 
73  unsigned int i = 0;
74  for (auto & user_object : _user_objects)
75  {
76  user_object->finalize();
77  const auto & const_user_object = *user_object;
78  _np_post_processor_values[i++] = const_user_object.getValue();
79  }
80 }
81 
82 unsigned int
84 {
85  unsigned int closest = 0;
86  Real closest_distance = std::numeric_limits<Real>::max();
87 
88  for (auto it : Moose::enumerate(_points))
89  {
90  const auto & current_point = it.value();
91 
92  Real current_distance = (p - current_point).norm();
93 
94  if (current_distance < closest_distance)
95  {
96  closest_distance = current_distance;
97  closest = it.index();
98  }
99  }
100 
101  return closest;
102 }
This UserObject computes averages of a variable storing partial sums for the specified number of inte...
NearestPointIntegralVariablePostprocessor(const InputParameters &parameters)
Given a list of points this object computes the variable integral closest to each one of those points...
This postprocessor computes a volume integral of the specified variable.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
_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...
Definition: Enumerate.h:52
std::vector< std::unique_ptr< ElementIntegralVariablePostprocessor > > _user_objects
auto max(const L &left, const R &right)
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
Base class VectorPostprocessors operating on elemental variables.
auto norm(const T &a) -> decltype(std::abs(a))
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
registerMooseObject("MooseApp", NearestPointIntegralVariablePostprocessor)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
virtual Real spatialValue(const Point &point) const override
Given a Point return the integral value associated with the layer that point falls in for the layered...