www.mooseframework.org
NodalValueSampler.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "NodalValueSampler.h"
16 
17 // MOOSE includes
18 #include "MooseVariable.h"
19 
20 // C++ includes
21 #include <numeric>
22 
23 template <>
26 {
28 
29  params += validParams<SamplerBase>();
30 
31  return params;
32 }
33 
35  : NodalVariableVectorPostprocessor(parameters), SamplerBase(parameters, this, _communicator)
36 {
37  std::vector<std::string> var_names(_coupled_moose_vars.size());
38  _values.resize(_coupled_moose_vars.size());
39  _has_values.resize(_coupled_moose_vars.size());
40 
41  for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
42  var_names[i] = _coupled_moose_vars[i]->name();
43 
44  // Initialize the data structures in SamplerBase
45  SamplerBase::setupVariables(var_names);
46 }
47 
48 void
50 {
52 }
53 
54 void
56 {
57  // There may not be a nodal solution value at every node. This
58  // can happen if, for instance, you have a LINEAR, LAGRANGE
59  // variable defined on a mesh with quadratic elements.
60  //
61  // We currently handle the following cases:
62  // 1.) *none* of the coupled vars have values at the current node
63  // 2.) *all* of the coupled vars have values at the current node
64  //
65  // If you have two different discretizations, you'll have to use two
66  // separate NodalValueSampler objects to get their values.
67  for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
68  {
69  const VariableValue & nodal_solution = _coupled_moose_vars[i]->nodalSln();
70 
71  if (nodal_solution.size() > 0)
72  {
73  _values[i] = nodal_solution[_qp];
74  _has_values[i] = 1;
75  }
76  else
77  {
78  _values[i] = 0.; // arbitrary, will not be used
79  _has_values[i] = 0;
80  }
81  }
82 
83  // Sum the number of values we had
84  unsigned int num_values =
85  std::accumulate(_has_values.begin(), _has_values.end(), 0, std::plus<unsigned int>());
86 
87  // If the number of values matches the number of available values,
88  // call addSample() as normal. If there are more than zero values
89  // available but less than the number requested, throw an error.
90  // Otherwise, num_values==0, and we can skip adding the sample
91  // entirely without error.
92  if (num_values == _has_values.size())
94 
95  else if (num_values != 0 && num_values < _has_values.size())
96  mooseError("You must use separate NodalValueSampler objects for variables with different "
97  "discretizations.");
98 }
99 
100 void
102 {
104 }
105 
106 void
108 {
109  const NodalValueSampler & vpp = static_cast<const NodalValueSampler &>(y);
110 
112 }
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:47
Base class for VectorPostprocessors that need to do "sampling" of values in the domain.
Definition: SamplerBase.h:46
virtual void initialize()
Initialize the datastructures.
Definition: SamplerBase.C:75
std::vector< MooseVariable * > _coupled_moose_vars
Vector of coupled variables.
Definition: Coupleable.h:324
const Node *& _current_node
Reference to current node pointer.
virtual void execute() override
Execute method.
std::vector< Real > _values
So we don&#39;t have to create and destroy this vector over and over again.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void initialize() override
Initialize the datastructures.
NodalValueSampler(const InputParameters &parameters)
virtual void threadJoin(const UserObject &y) override
Must override.
void setupVariables(const std::vector< std::string > &variable_names)
You MUST call this in the constructor of the child class and pass down the name of the variables...
Definition: SamplerBase.C:51
virtual void threadJoin(const SamplerBase &y)
Join the values.
Definition: SamplerBase.C:141
std::vector< unsigned int > _has_values
Vector of 0 and 1 values which records whether values are present at the current node.
const unsigned int _qp
Quadrature point index.
virtual void finalize()
Finalize the values.
Definition: SamplerBase.C:87
virtual void finalize() override
Finalize the values.
virtual void addSample(const Point &p, const Real &id, const std::vector< Real > &values)
Call this with the value of every variable at each point you want to sample at.
Definition: SamplerBase.C:61
unsigned int size() const
The number of elements that can currently be stored in the array.
Definition: MooseArray.h:250
Base class VectorPostprocessors operating on nodal variables.
InputParameters validParams< SamplerBase >()
Definition: SamplerBase.C:26
InputParameters validParams< NodalValueSampler >()
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
InputParameters validParams< NodalVariableVectorPostprocessor >()
Base class for user-specific data.
Definition: UserObject.h:42