https://mooseframework.inl.gov
UpperBoundNodalKernel.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 "UpperBoundNodalKernel.h"
11 
13 
16 {
18  params.addClassDescription("Used to prevent a coupled variable from going above a upper bound");
19  params.addRequiredCoupledVar(
20  "v", "The coupled variable we require to be greater than the upper bound");
21  params.addParam<Real>("upper_bound", 0, "The upper bound on the coupled variable");
22  params.addParam<std::vector<BoundaryName>>(
23  "exclude_boundaries",
24  {},
25  "Boundaries on which not to execute the NodalKernel. This can be useful for avoiding "
26  "singuarility in the matrix in case a constraint is active in the same place that a "
27  "DirichletBC is set");
28  return params;
29 }
30 
32  : NodalKernel(parameters),
33  _v_var(coupled("v")),
34  _v(coupledValue("v")),
35  _upper_bound(getParam<Real>("upper_bound"))
36 {
37  if (_var.number() == _v_var)
38  mooseError("Coupled variable 'v' needs to be different from 'variable' with "
39  "UpperBoundNodalKernel");
40 
41  const auto & bnd_names = getParam<std::vector<BoundaryName>>("exclude_boundaries");
42  for (const auto & bnd_name : bnd_names)
43  _bnd_ids.insert(_mesh.getBoundaryID(bnd_name));
44 }
45 
46 Real
48 {
49  for (auto bnd_id : _bnd_ids)
50  if (_mesh.isBoundaryNode(_current_node->id(), bnd_id))
51  return _u[_qp];
52 
53  return std::min(_u[_qp], _upper_bound - _v[_qp]);
54 }
55 
56 Real
58 {
59  for (auto bnd_id : _bnd_ids)
60  if (_mesh.isBoundaryNode(_current_node->id(), bnd_id))
61  return 1;
62 
63  if (_u[_qp] <= _upper_bound - _v[_qp])
64  return 1;
65  return 0;
66 }
67 
68 Real
70 {
71  for (auto bnd_id : _bnd_ids)
72  if (_mesh.isBoundaryNode(_current_node->id(), bnd_id))
73  return 0;
74 
75  if (jvar == _v_var)
76  if (_upper_bound - _v[_qp] < _u[_qp])
77  return -1;
78 
79  return 0.0;
80 }
MooseMesh & _mesh
Reference to this Kernel&#39;s mesh object.
Class used to enforce a upper bound on a coupled variable.
virtual Real computeQpResidual() override
The user can override this function to compute the residual at a node.
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
This is the virtual that derived classes should override for computing an off-diagonal jacobian compo...
bool isBoundaryNode(dof_id_type node_id) const
Returns true if the requested node is in the list of boundary nodes, false otherwise.
Definition: MooseMesh.C:3565
unsigned int number() const
Get variable number coming from libMesh.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual Real computeQpJacobian() override
The user can override this function to compute the "on-diagonal" Jacobian contribution.
MooseVariable & _var
variable this works on
std::set< BoundaryID > _bnd_ids
Boundaries on which we should not execute this object.
const unsigned int _v_var
The number of the coupled variable.
UpperBoundNodalKernel(const InputParameters &parameters)
static InputParameters validParams()
const VariableValue & _u
Value of the unknown variable this is acting on.
Definition: NodalKernel.h:72
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
registerMooseObject("MooseApp", UpperBoundNodalKernel)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
const VariableValue & _v
The value of the coupled variable.
const Node *const & _current_node
current node being processed
static InputParameters validParams()
Class constructor.
Definition: NodalKernel.C:18
const Real _upper_bound
The upper bound on the coupled variable.
Base class for creating nodal kernels with hand-coded Jacobians.
Definition: NodalKernel.h:17
auto min(const L &left, const R &right)
unsigned int _qp
Quadrature point index.
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition: MooseMesh.C:1692