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 
17 template <>
20 {
22  params += validParams<SetupInterface>();
24 
25  params.addRequiredParam<AuxVariableName>("variable",
26  "The name of the variable that this kernel operates on");
27  params.addParam<bool>("use_displaced_mesh",
28  false,
29  "Whether or not this object should use the "
30  "displaced mesh for computation. Note that "
31  "in the case this is true but no "
32  "displacements are provided in the Mesh block "
33  "the undisplaced mesh will still be used.");
34  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
35 
36  params.declareControllable("enable"); // allows Control to enable/disable this type of object
37  params.registerBase("AuxScalarKernel");
38 
39  return params;
40 }
41 
43  : MooseObject(parameters),
44  ScalarCoupleable(this),
45  SetupInterface(this),
46  FunctionInterface(this),
47  UserObjectInterface(this),
50  TransientInterface(this),
51  MeshChangedInterface(parameters),
52  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
53  _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
54  _tid(parameters.get<THREAD_ID>("_tid")),
55  _assembly(_subproblem.assembly(_tid)),
56  _var(_sys.getScalarVariable(_tid, parameters.get<AuxVariableName>("variable"))),
57  _mesh(_subproblem.mesh()),
58  _u(_var.sln()),
59  _u_old(_var.slnOld())
60 {
61  _supplied_vars.insert(parameters.get<AuxVariableName>("variable"));
62 
63  const std::vector<MooseVariableScalar *> & coupled_vars = getCoupledMooseScalarVars();
64  for (const auto & var : coupled_vars)
65  _depend_vars.insert(var->name());
66 }
67 
69 
70 void
72 {
73  // In general, we want to compute AuxScalarKernel values
74  // redundantly, on every processor, to avoid communication.
75  //
76  // However, in rare cases not all processors will have access to a
77  // particular scalar variable, in which case we skip computation
78  // there.
79  if (_var.dofIndices().empty() || !_var.dofMap().all_semilocal_indices(_var.dofIndices()))
80  return;
81 
82  for (_i = 0; _i < _var.order(); ++_i)
83  {
84  Real value = computeValue();
85  _var.setValue(_i, value); // update variable data, which is referenced by other kernels, so the
86  // value is up-to-date
87  }
88 }
89 
90 const std::set<std::string> &
92 {
93  return _depend_vars;
94 }
95 
96 const std::set<std::string> &
98 {
99  return _supplied_vars;
100 }
101 
102 bool
104 {
105  return true;
106 }
MooseVariableScalar & _var
InputParameters validParams< AuxScalarKernel >()
const std::vector< MooseVariableScalar * > & getCoupledMooseScalarVars()
Get the list of coupled scalar variables.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams< SetupInterface >()
Base class for a system (of equations)
Definition: SystemBase.h:92
virtual bool isActive()
Use this to enable/disable the constraint.
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.
Interface for objects that needs transient capabilities.
virtual void compute()
Evaluate the kernel.
std::set< std::string > _supplied_vars
Interface for notifications that the mesh has changed.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:42
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:65
void setValue(unsigned int i, Number value)
Set the nodal value for this variable (to keep everything up to date.
InputParameters validParams< MeshChangedInterface >()
virtual const std::vector< dof_id_type > & dofIndices() const
Get local DoF indices.
Interface for objects that need to use UserObjects.
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:25
const DofMap & dofMap() const
The DofMap associated with the system this variable is in.
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.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:59
std::set< std::string > _depend_vars
Depend AuxKernels.
Interface for sorting dependent vectors of objects.
Interface for objects that needs scalar coupling capabilities.
unsigned int _i
AuxScalarKernel(const InputParameters &parameters)
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.
virtual ~AuxScalarKernel()
Interface class for classes which interact with Postprocessors.
unsigned int THREAD_ID
Definition: MooseTypes.h:161