Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
NodalValueSampler.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 #include "NodalValueSampler.h"
11 
12 // MOOSE includes
13 #include "MooseVariableFE.h"
14 
15 // C++ includes
16 #include <numeric>
17 
19 
22 {
24 
25  params.addClassDescription("Samples values of nodal variable(s).");
26 
27  params += SamplerBase::validParams();
28 
29  return params;
30 }
31 
33  : NodalVariableVectorPostprocessor(parameters), SamplerBase(parameters, this, _communicator)
34 {
35  // ensure that variables are 'nodal' (they have DoFs at nodes)
36  for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
37  {
38  if (!_coupled_moose_vars[i]->isNodal())
39  paramError("variable", "The variable '", _coupled_moose_vars[i]->name(), "' is not nodal.");
41  }
42 
43  std::vector<std::string> var_names(_coupled_moose_vars.size());
44  _values.resize(_coupled_moose_vars.size());
45  _has_values.resize(_coupled_moose_vars.size());
46 
47  for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
48  var_names[i] = _coupled_moose_vars[i]->name();
49 
50  // Initialize the data structures in SamplerBase
51  SamplerBase::setupVariables(var_names);
52 }
53 
54 void
56 {
58 }
59 
60 void
62 {
63  // There may not be a nodal solution value at every node. This
64  // can happen if, for instance, you have a LINEAR, LAGRANGE
65  // variable defined on a mesh with quadratic elements.
66  //
67  // We currently handle the following cases:
68  // 1.) *none* of the coupled vars have values at the current node
69  // 2.) *all* of the coupled vars have values at the current node
70  //
71  // If you have two different discretizations, you'll have to use two
72  // separate NodalValueSampler objects to get their values.
73  for (unsigned int i = 0; i < _coupled_standard_moose_vars.size(); i++)
74  {
75  const VariableValue & nodal_solution = _coupled_standard_moose_vars[i]->dofValues();
76 
77  if (nodal_solution.size() > 0)
78  {
79  _values[i] = nodal_solution[_qp];
80  _has_values[i] = 1;
81  }
82  else
83  {
84  _values[i] = 0.; // arbitrary, will not be used
85  _has_values[i] = 0;
86  }
87  }
88 
89  // Sum the number of values we had
90  unsigned int num_values =
91  std::accumulate(_has_values.begin(), _has_values.end(), 0, std::plus<unsigned int>());
92 
93  // If the number of values matches the number of available values,
94  // call addSample() as normal. If there are more than zero values
95  // available but less than the number requested, throw an error.
96  // Otherwise, num_values==0, and we can skip adding the sample
97  // entirely without error.
98  if (num_values == _has_values.size())
100 
101  else if (num_values != 0 && num_values < _has_values.size())
102  mooseError("You must use separate NodalValueSampler objects for variables with different "
103  "discretizations.");
104 }
105 
106 void
108 {
110 }
111 
112 void
114 {
115  const auto & vpp = static_cast<const NodalValueSampler &>(y);
116 
118 }
Base class for VectorPostprocessors that need to do "sampling" of values in the domain.
Definition: SamplerBase.h:36
virtual void initialize()
Initialize the datastructures.
Definition: SamplerBase.C:77
const Node *const & _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.
Samples values of nodal variable(s).
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
std::vector< MooseVariable * > _coupled_standard_moose_vars
Vector of standard coupled variables.
Definition: Coupleable.h:1415
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:53
virtual void threadJoin(const SamplerBase &y)
Join the values.
Definition: SamplerBase.C:174
std::vector< unsigned int > _has_values
Vector of 0 and 1 values which records whether values are present at the current node.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
const unsigned int _qp
Quadrature point index.
bool isNodal() const
static InputParameters validParams()
Definition: SamplerBase.C:24
std::vector< MooseVariableFieldBase * > _coupled_moose_vars
Vector of all coupled variables.
Definition: Coupleable.h:1412
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:314
virtual void finalize()
Finalize the values.
Definition: SamplerBase.C:120
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:63
Base class VectorPostprocessors operating on nodal variables.
static InputParameters validParams()
registerMooseObject("MooseApp", NodalValueSampler)
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...
void checkForStandardFieldVariableType(const MooseVariableFieldBase *const var_ptr, const std::string &var_param_name="variable") const
Checks whether the passed variable pointer corresponds to a regular single-valued field variable...
Definition: SamplerBase.C:93
Base class for user-specific data.
Definition: UserObject.h:39