https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LowerBoundNodalKernel.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
11
13
16{
18 params.addClassDescription("Used to prevent a coupled variable from going below a lower bound");
20 "v", "The coupled variable we require to be greater than the lower bound");
21 params.addParam<Real>("lower_bound", 0, "The lower 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 _lower_bound(getParam<Real>("lower_bound"))
36{
37 if (_var.number() == _v_var)
38 mooseError("Coupled variable 'v' needs to be different from 'variable' with "
39 "LowerBoundNodalKernel");
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
46Real
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], _v[_qp] - _lower_bound);
54}
55
56Real
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] <= _v[_qp] - _lower_bound)
64 return 1;
65 return 0;
66}
67
68Real
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 (_v[_qp] - _lower_bound < _u[_qp])
77 return 1;
78
79 return 0.0;
80}
registerMooseObject("MooseApp", LowerBoundNodalKernel)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
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.
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.
Class used to enforce a lower bound on a coupled variable.
std::set< BoundaryID > _bnd_ids
Boundaries on which we should not execute this object.
const VariableValue & _v
The value of the coupled variable.
const Real _lower_bound
The lower bound on the coupled variable.
virtual Real computeQpJacobian() override
The user can override this function to compute the "on-diagonal" Jacobian contribution.
static InputParameters validParams()
virtual Real computeQpResidual() override
The user can override this function to compute the residual at a node.
const unsigned int _v_var
The number of the coupled variable.
virtual Real computeQpOffDiagJacobian(unsigned int jvar) override
This is the virtual that derived classes should override for computing an off-diagonal jacobian compo...
LowerBoundNodalKernel(const InputParameters &parameters)
BoundaryID getBoundaryID(const BoundaryName &boundary_name) const
Get the associated BoundaryID for the boundary name.
Definition MooseMesh.C:1681
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:3666
unsigned int number() const
Get variable number coming from libMesh.
unsigned int _qp
Quadrature point index.
const Node *const & _current_node
current node being processed
Base class for creating nodal kernels with hand-coded Jacobians.
Definition NodalKernel.h:19
static InputParameters validParams()
Class constructor.
Definition NodalKernel.C:18
MooseVariable & _var
variable this works on
Definition NodalKernel.h:79
const VariableValue & _u
Value of the unknown variable this is acting on.
Definition NodalKernel.h:82
MooseMesh & _mesh
Reference to this Kernel's mesh object.