www.mooseframework.org
DGKernelBase.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 "DGKernelBase.h"
11 #include "Assembly.h"
12 #include "MooseVariable.h"
13 #include "Problem.h"
14 #include "SubProblem.h"
15 #include "SystemBase.h"
16 #include "MaterialData.h"
17 #include "ParallelUniqueId.h"
18 
19 #include "libmesh/dof_map.h"
20 #include "libmesh/dense_vector.h"
21 #include "libmesh/numeric_vector.h"
22 #include "libmesh/dense_subvector.h"
23 #include "libmesh/libmesh_common.h"
24 #include "libmesh/quadrature.h"
25 
26 template <>
29 {
37  params.addRequiredParam<NonlinearVariableName>(
38  "variable", "The name of the variable that this boundary condition applies to");
39  params.addParam<bool>("use_displaced_mesh",
40  false,
41  "Whether or not this object should use the "
42  "displaced mesh for computation. Note that in "
43  "the case this is true but no displacements "
44  "are provided in the Mesh block the "
45  "undisplaced mesh will still be used.");
46  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
47 
48  params.declareControllable("enable");
49  params.addParam<std::vector<AuxVariableName>>(
50  "save_in",
51  "The name of auxiliary variables to save this Kernel's residual contributions to. "
52  " Everything about that variable must match everything about this variable (the "
53  "type, what blocks it's on, etc.)");
54  params.addParam<std::vector<AuxVariableName>>(
55  "diag_save_in",
56  "The name of auxiliary variables to save this Kernel's diagonal Jacobian "
57  "contributions to. Everything about that variable must match everything "
58  "about this variable (the type, what blocks it's on, etc.)");
59 
60  // DG Kernels always need one layer of ghosting
61  params.addRelationshipManager("ElementSideNeighborLayers",
64  params.registerBase("DGKernel");
65 
66  return params;
67 }
68 
69 // Static mutex definitions
70 Threads::spin_mutex DGKernelBase::_resid_vars_mutex;
71 Threads::spin_mutex DGKernelBase::_jacoby_vars_mutex;
72 
74  : MooseObject(parameters),
75  BlockRestrictable(this),
76  BoundaryRestrictable(this, false), // false for _not_ nodal
77  SetupInterface(this),
78  TransientInterface(this),
79  FunctionInterface(this),
80  UserObjectInterface(this),
84  TwoMaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
85  Restartable(this, "DGKernels"),
86  MeshChangedInterface(parameters),
87  TaggingInterface(this),
88  _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
89  _sys(*getCheckedPointerParam<SystemBase *>("_sys")),
90  _tid(parameters.get<THREAD_ID>("_tid")),
91  _assembly(_subproblem.assembly(_tid)),
92  _var(*mooseVariable()),
93  _mesh(_subproblem.mesh()),
94 
95  _current_elem(_assembly.elem()),
96  _current_elem_volume(_assembly.elemVolume()),
97 
98  _neighbor_elem(_assembly.neighbor()),
99 
100  _current_side(_assembly.side()),
101  _current_side_elem(_assembly.sideElem()),
102  _current_side_volume(_assembly.sideElemVolume()),
103 
104  _coord_sys(_assembly.coordSystem()),
105  _q_point(_assembly.qPointsFace()),
106  _qrule(_assembly.qRuleFace()),
107  _JxW(_assembly.JxWFace()),
108  _coord(_assembly.coordTransformation()),
109 
110  _u(_is_implicit ? _var.sln() : _var.slnOld()),
111  _grad_u(_is_implicit ? _var.gradSln() : _var.gradSlnOld()),
112 
113  _phi(_assembly.phiFace(_var)),
114  _grad_phi(_assembly.gradPhiFace(_var)),
115 
116  _test(_var.phiFace()),
117  _grad_test(_var.gradPhiFace()),
118 
119  _normals(_assembly.normals()),
120 
121  _phi_neighbor(_assembly.phiFaceNeighbor(_var)),
122  _grad_phi_neighbor(_assembly.gradPhiFaceNeighbor(_var)),
123 
124  _test_neighbor(_var.phiFaceNeighbor()),
125  _grad_test_neighbor(_var.gradPhiFaceNeighbor()),
126 
127  _u_neighbor(_is_implicit ? _var.slnNeighbor() : _var.slnOldNeighbor()),
128  _grad_u_neighbor(_is_implicit ? _var.gradSlnNeighbor() : _var.gradSlnOldNeighbor()),
129 
130  _save_in_strings(parameters.get<std::vector<AuxVariableName>>("save_in")),
131  _diag_save_in_strings(parameters.get<std::vector<AuxVariableName>>("diag_save_in"))
132 {
134 
135  _save_in.resize(_save_in_strings.size());
136  _diag_save_in.resize(_diag_save_in_strings.size());
137 
138  for (unsigned int i = 0; i < _save_in_strings.size(); i++)
139  {
141  _save_in_strings[i],
144 
146  mooseError("Trying to use solution variable " + _save_in_strings[i] +
147  " as a save_in variable in " + name());
148 
149  if (var->feType() != _var.feType())
150  paramError(
151  "save_in",
152  "saved-in auxiliary variable is incompatible with the object's nonlinear variable: ",
154 
155  _save_in[i] = var;
158  }
159 
160  _has_save_in = _save_in.size() > 0;
161 
162  for (unsigned int i = 0; i < _diag_save_in_strings.size(); i++)
163  {
168 
170  mooseError("Trying to use solution variable " + _diag_save_in_strings[i] +
171  " as a diag_save_in variable in " + name());
172 
173  if (var->feType() != _var.feType())
174  paramError(
175  "diag_save_in",
176  "saved-in auxiliary variable is incompatible with the object's nonlinear variable: ",
178 
179  _diag_save_in[i] = var;
182  }
183 
184  _has_diag_save_in = _diag_save_in.size() > 0;
185 }
186 
188 
189 void
191 {
192  // Compute the residual for this element
194 
195  // Compute the residual for the neighbor
197 }
198 
199 void
201 {
202  // Compute element-element Jacobian
204 
205  // Compute element-neighbor Jacobian
207 
208  // Compute neighbor-element Jacobian
210 
211  // Compute neighbor-neighbor Jacobian
213 }
214 
215 void
217 {
218  if (jvar == _var.number())
219  computeJacobian();
220  else
221  {
222  // Compute element-element Jacobian
224 
225  // Compute element-neighbor Jacobian
227 
228  // Compute neighbor-element Jacobian
230 
231  // Compute neighbor-neighbor Jacobian
233  }
234 }
235 
238 {
239  return _var;
240 }
241 
242 SubProblem &
244 {
245  return _subproblem;
246 }
247 
248 const Real &
250 {
251  return _assembly.neighborVolume();
252 }
virtual void computeOffDiagElemNeighJacobian(Moose::DGJacobianType type, unsigned int jvar)=0
Computes the element-element off-diagonal Jacobian.
VarFieldType
Definition: MooseTypes.h:488
A class for creating restricted objects.
Definition: Restartable.h:29
std::string incompatVarMsg(MooseVariableFEBase &var1, MooseVariableFEBase &var2)
Builds and returns a string of the form:
Definition: MooseError.C:22
Intermediate base class that ties together all the interfaces for getting MooseVariables with the Moo...
SystemBase & _sys
Definition: DGKernelBase.h:112
InputParameters validParams< BlockRestrictable >()
unsigned int number() const
Get variable number coming from libMesh.
std::vector< AuxVariableName > _save_in_strings
Definition: DGKernelBase.h:183
virtual MooseVariableFEBase & getVariable(THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY)=0
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
const Real & getNeighborElemVolume()
The volume (or length) of the current neighbor.
Definition: DGKernelBase.C:249
DGKernelBase(const InputParameters &parameters)
Factory constructor initializes all internal references needed for residual computation.
Definition: DGKernelBase.C:73
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool _has_diag_save_in
The aux variables to save the diagonal Jacobian contributions to.
Definition: DGKernelBase.h:186
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
std::vector< MooseVariableFEBase * > _diag_save_in
Definition: DGKernelBase.h:187
Base class for a system (of equations)
Definition: SystemBase.h:92
virtual void computeElemNeighResidual(Moose::DGResidualType type)=0
Computes the residual for this element or the neighbor.
const FEType & feType() const
Get the type of finite element object.
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...
void addMooseVariableDependency(MooseVariableFEBase *var)
Call this function to add the passed in MooseVariableFEBase as a variable that this object depends on...
std::vector< MooseVariableFEBase * > _save_in
Definition: DGKernelBase.h:182
MooseVariableFE< Real > * mooseVariable() const
Get the variable that this object is using.
Interface for objects that needs transient capabilities.
Enhances MooseVariableInterface interface provide values from neighbor elements.
virtual MooseVariable & variable()
The variable number that this kernel operates on.
Definition: DGKernelBase.C:237
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
virtual void computeResidual()
Computes the residual for the current side.
Definition: DGKernelBase.C:190
InputParameters validParams< DGKernelBase >()
Definition: DGKernelBase.C:28
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:481
std::vector< AuxVariableName > _diag_save_in_strings
Definition: DGKernelBase.h:188
THREAD_ID _tid
Definition: DGKernelBase.h:114
InputParameters validParams< MeshChangedInterface >()
virtual ~DGKernelBase()
Definition: DGKernelBase.C:187
Interface for objects that need to use UserObjects.
static Threads::spin_mutex _resid_vars_mutex
Definition: DGKernelBase.h:199
virtual bool hasVariable(const std::string &var_name) const
Query a system for a variable.
Definition: SystemBase.C:668
InputParameters validParams< MooseObject >()
Definition: MooseObject.C:25
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
Assembly & _assembly
Definition: DGKernelBase.h:116
SubProblem & _subproblem
Definition: DGKernelBase.h:111
virtual void computeOffDiagJacobian(unsigned int jvar)
Computes d-residual / d-jvar...
Definition: DGKernelBase.C:216
virtual void computeJacobian()
Computes the jacobian for the current side.
Definition: DGKernelBase.C:200
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:59
virtual void addVariableToZeroOnResidual(std::string var_name)
Adds this variable to the list of variables to be zeroed during each residual evaluation.
Definition: SystemBase.C:178
InputParameters validParams< BoundaryRestrictable >()
InputParameters validParams< TaggingInterface >()
SubProblem & subProblem()
Return a reference to the subproblem.
Definition: DGKernelBase.C:243
An interface that restricts an object to subdomains via the &#39;blocks&#39; input parameter.
InputParameters validParams< TwoMaterialPropertyInterface >()
const std::string & name() const
Get the name of the object.
Definition: MooseObject.h:59
MooseVariable & _var
Definition: DGKernelBase.h:117
virtual void addVariableToZeroOnJacobian(std::string var_name)
Adds this variable to the list of variables to be zeroed during each Jacobian evaluation.
Definition: SystemBase.C:184
const Real & neighborVolume() const
Returns the reference to the current neighbor volume.
Definition: Assembly.C:480
Definition: Moose.h:112
virtual void computeElemNeighJacobian(Moose::DGJacobianType type)=0
Computes the element/neighbor-element/neighbor Jacobian.
SystemBase & sys()
Get the system this variable is part of.
Interface for objects that need to use functions.
InputParameters validParams< TransientInterface >()
static Threads::spin_mutex _jacoby_vars_mutex
Definition: DGKernelBase.h:200
unsigned int THREAD_ID
Definition: MooseTypes.h:161
bool _has_save_in
The aux variables to save the residual contributions to.
Definition: DGKernelBase.h:181