www.mooseframework.org
AuxScalarKernel.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 "AuxScalarKernel.h"
11 #include "Assembly.h"
12 #include "MooseVariableScalar.h"
13 #include "Problem.h"
14 #include "SubProblem.h"
15 #include "SystemBase.h"
16 
19 {
21  params += SetupInterface::validParams();
23 
24  params.addRequiredParam<AuxVariableName>("variable",
25  "The name of the variable that this kernel operates on");
26  params.addParam<bool>("use_displaced_mesh",
27  false,
28  "Whether or not this object should use the "
29  "displaced mesh for computation. Note that "
30  "in the case this is true but no "
31  "displacements are provided in the Mesh block "
32  "the undisplaced mesh will still be used.");
33  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
34 
35  params.declareControllable("enable"); // allows Control to enable/disable this type of object
36  params.registerBase("AuxScalarKernel");
37 
38  return params;
39 }
40 
42  : MooseObject(parameters),
43  ScalarCoupleable(this),
44  SetupInterface(this),
45  FunctionInterface(this),
46  UserObjectInterface(this),
49  TransientInterface(this),
50  MeshChangedInterface(parameters),
51  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
52  _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
53  _tid(parameters.get<THREAD_ID>("_tid")),
54  _assembly(_subproblem.assembly(_tid, 0)),
55  _var(_sys.getScalarVariable(_tid, parameters.get<AuxVariableName>("variable"))),
56  _mesh(_subproblem.mesh()),
57  _u(_var.sln())
58 {
59  _supplied_vars.insert(parameters.get<AuxVariableName>("variable"));
60 
61  const std::vector<MooseVariableScalar *> & coupled_vars = getCoupledMooseScalarVars();
62  for (const auto & var : coupled_vars)
63  _depend_vars.insert(var->name());
64 }
65 
67 
68 void
70 {
71  // In general, we want to compute AuxScalarKernel values
72  // redundantly, on every processor, to avoid communication.
73  //
74  // However, in rare cases not all processors will have access to a
75  // particular scalar variable, in which case we skip computation
76  // there.
77  if (_var.dofIndices().empty() || !_var.dofMap().all_semilocal_indices(_var.dofIndices()))
78  return;
79 
80  for (_i = 0; _i < _var.order(); ++_i)
81  {
83  _var.setValue(_i, value); // update variable data, which is referenced by other kernels, so the
84  // value is up-to-date
85  }
86 }
87 
88 const std::set<std::string> &
90 {
91  return _depend_vars;
92 }
93 
94 const std::set<std::string> &
96 {
97  return _supplied_vars;
98 }
99 
100 bool
102 {
103  return true;
104 }
105 
106 const VariableValue &
108 {
110  mooseError("The solution states have already been initialized when calling ",
111  type(),
112  "::uOld().\n\n",
113  "Make sure to call uOld() within the object constructor.");
114 
115  return _var.slnOld();
116 }
MooseVariableScalar & _var
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1147
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool solutionStatesInitialized() const
Whether or not the solution states have been initialized via initSolutionState()
Definition: SystemBase.h:888
Base class for a system (of equations)
Definition: SystemBase.h:84
virtual bool isActive()
Use this to enable/disable the constraint.
SystemBase & _sys
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
virtual const std::set< std::string > & getSuppliedItems() override
Return a set containing the names of items owned by the object.
const VariableValue & uOld() const
Retrieves the old value of the variable that this AuxScalarKernel operates on.
void registerBase(const std::string &value)
This method must be called from every base "Moose System" to create linkage with the Action System...
const VariableValue & slnOld() const
Interface for objects that needs transient capabilities.
virtual void compute()
Evaluate the kernel.
const std::vector< MooseVariableScalar * > & getCoupledMooseScalarVars()
Get the list of coupled scalar variables.
static InputParameters validParams()
std::set< std::string > _supplied_vars
Interface for notifications that the mesh has changed.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:33
void setValue(unsigned int i, Number value)
Set the nodal value for this variable (to keep everything up to date.
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:50
Interface for objects that need to use UserObjects.
static InputParameters validParams()
const DofMap & dofMap() const
The DofMap associated with the system this variable is in.
OutputTools< Real >::VariableValue VariableValue
Definition: MooseTypes.h:302
Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int...
virtual Real computeValue()=0
Compute the value of this kernel.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:75
std::set< std::string > _depend_vars
Depend AuxKernels.
static InputParameters validParams()
Interface for sorting dependent vectors of objects.
Interface for objects that needs scalar coupling capabilities.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
unsigned int _i
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
AuxScalarKernel(const InputParameters &parameters)
static InputParameters validParams()
Definition: MooseObject.C:24
virtual const std::set< std::string > & getRequestedItems() override
Return a set containing the names of items requested by the object.
Interface for objects that need to use functions.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.
virtual ~AuxScalarKernel()
Interface class for classes which interact with Postprocessors.
unsigned int THREAD_ID
Definition: MooseTypes.h:198
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...