www.mooseframework.org
NodalValueSampler.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 #include "NodalValueSampler.h"
11 
12 // MOOSE includes
13 #include "MooseVariableFE.h"
14 
15 // C++ includes
16 #include <numeric>
17 
19 
20 template <>
23 {
25 
26  params.addClassDescription("Samples values of nodal variable(s).");
27 
28  params += validParams<SamplerBase>();
29 
30  return params;
31 }
32 
34  : NodalVariableVectorPostprocessor(parameters), SamplerBase(parameters, this, _communicator)
35 {
36  // ensure that variables are nodal, i.e., not scalar and and not elemental
37  for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
38  if (_coupled_moose_vars[i]->feType().family == SCALAR || !_coupled_moose_vars[i]->isNodal())
39  paramError("variable", "The variable '", _coupled_moose_vars[i]->name(), "' is not nodal.");
40 
41  std::vector<std::string> var_names(_coupled_moose_vars.size());
42  _values.resize(_coupled_moose_vars.size());
43  _has_values.resize(_coupled_moose_vars.size());
44 
45  for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
46  var_names[i] = _coupled_moose_vars[i]->name();
47 
48  // Initialize the data structures in SamplerBase
49  SamplerBase::setupVariables(var_names);
50 }
51 
52 void
54 {
56 }
57 
58 void
60 {
61  // There may not be a nodal solution value at every node. This
62  // can happen if, for instance, you have a LINEAR, LAGRANGE
63  // variable defined on a mesh with quadratic elements.
64  //
65  // We currently handle the following cases:
66  // 1.) *none* of the coupled vars have values at the current node
67  // 2.) *all* of the coupled vars have values at the current node
68  //
69  // If you have two different discretizations, you'll have to use two
70  // separate NodalValueSampler objects to get their values.
71  for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
72  {
73  const VariableValue & nodal_solution = _coupled_moose_vars[i]->dofValues();
74 
75  if (nodal_solution.size() > 0)
76  {
77  _values[i] = nodal_solution[_qp];
78  _has_values[i] = 1;
79  }
80  else
81  {
82  _values[i] = 0.; // arbitrary, will not be used
83  _has_values[i] = 0;
84  }
85  }
86 
87  // Sum the number of values we had
88  unsigned int num_values =
89  std::accumulate(_has_values.begin(), _has_values.end(), 0, std::plus<unsigned int>());
90 
91  // If the number of values matches the number of available values,
92  // call addSample() as normal. If there are more than zero values
93  // available but less than the number requested, throw an error.
94  // Otherwise, num_values==0, and we can skip adding the sample
95  // entirely without error.
96  if (num_values == _has_values.size())
98 
99  else if (num_values != 0 && num_values < _has_values.size())
100  mooseError("You must use separate NodalValueSampler objects for variables with different "
101  "discretizations.");
102 }
103 
104 void
106 {
108 }
109 
110 void
112 {
113  const NodalValueSampler & vpp = static_cast<const NodalValueSampler &>(y);
114 
116 }
Base class for VectorPostprocessors that need to do "sampling" of values in the domain.
Definition: SamplerBase.h:40
virtual void initialize()
Initialize the datastructures.
Definition: SamplerBase.C:76
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...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
virtual void initialize() override
Initialize the datastructures.
Samples values of nodal variable(s).
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:52
virtual void threadJoin(const SamplerBase &y)
Join the values.
Definition: SamplerBase.C:146
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.
void paramError(const std::string &param, Args... args)
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseObject.h:108
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:197
virtual void finalize()
Finalize the values.
Definition: SamplerBase.C:92
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:62
Base class VectorPostprocessors operating on nodal variables.
std::vector< MooseVariableFEBase * > _coupled_moose_vars
Vector of all coupled variables.
Definition: Coupleable.h:740
InputParameters validParams< SamplerBase >()
Definition: SamplerBase.C:23
registerMooseObject("MooseApp", NodalValueSampler)
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
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...
InputParameters validParams< NodalValueSampler >()
InputParameters validParams< NodalVariableVectorPostprocessor >()
Base class for user-specific data.
Definition: UserObject.h:37