https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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 {
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
52}
53
54void
59
60void
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 auto & dof_indices = _coupled_standard_moose_vars[i]->dofIndices();
76
77 if (dof_indices.size() > 0)
78 {
79 const VariableValue & nodal_solution = _coupled_standard_moose_vars[i]->dofValues();
80 mooseAssert(nodal_solution.size() == dof_indices.size(), "These must be the same length");
81 _values[i] = nodal_solution[_qp];
82 _has_values[i] = 1;
83 }
84 else
85 {
86 _values[i] = 0.; // arbitrary, will not be used
87 _has_values[i] = 0;
88 }
89 }
90
91 // Sum the number of values we had
92 unsigned int num_values =
93 std::accumulate(_has_values.begin(), _has_values.end(), 0, std::plus<unsigned int>());
94
95 // If the number of values matches the number of available values,
96 // call addSample() as normal. If there are more than zero values
97 // available but less than the number requested, throw an error.
98 // Otherwise, num_values==0, and we can skip adding the sample
99 // entirely without error.
100 if (num_values == _has_values.size())
102
103 else if (num_values != 0 && num_values < _has_values.size())
104 mooseError("You must use separate NodalValueSampler objects for variables with different "
105 "discretizations.");
106}
107
108void
113
114void
116{
117 const auto & vpp = static_cast<const NodalValueSampler &>(y);
118
120}
121
122std::set<MooseVariableFieldBase *>
124 const libMesh::Node &,
125 const std::set<MooseVariableFieldBase *> & libmesh_dbg_var(vars_to_check))
126{
127 mooseAssert(vars_to_check ==
128 std::set<MooseVariableFieldBase *>(_coupled_standard_moose_vars.begin(),
130 "The constructor should have caught any non-standard MOOSE variables");
131 // This class implements its own handling of its variables which don't have dof indices on a given
132 // node
133 return {};
134}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
OutputTools< Real >::VariableValue VariableValue
Definition MooseTypes.h:348
registerMooseObject("MooseApp", NodalValueSampler)
std::vector< MooseVariable * > _coupled_standard_moose_vars
Vector of standard coupled variables.
std::vector< MooseVariableFieldBase * > _coupled_moose_vars
Vector of all coupled variables.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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 ...
Definition MooseBase.h:457
const Node *const & _current_node
Reference to current node pointer.
const unsigned int _qp
Quadrature point index.
Samples values of nodal variable(s).
virtual void execute() override
Execute method.
std::vector< Real > _values
So we don't have to create and destroy this vector over and over again.
virtual std::set< MooseVariableFieldBase * > checkVariables(const libMesh::Node &node, const std::set< MooseVariableFieldBase * > &vars_to_check) override
Check whether all of the supplied variables have degree of freedom indices on the supplied node.
static InputParameters validParams()
virtual void threadJoin(const UserObject &y) override
Must override.
std::vector< unsigned int > _has_values
Vector of 0 and 1 values which records whether values are present at the current node.
virtual void finalize() override
Finalize.
NodalValueSampler(const InputParameters &parameters)
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
Base class VectorPostprocessors operating on nodal variables.
bool isNodal() const
Base class for VectorPostprocessors that need to do "sampling" of values in the domain.
Definition SamplerBase.h:38
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:91
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:69
virtual void initialize()
Initialize the datastructures.
virtual void threadJoin(const SamplerBase &y)
Join the values.
virtual void finalize()
Finalize the values.
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.
static InputParameters validParams()
Definition SamplerBase.C:24
Base class for user-specific data.
Definition UserObject.h:20