Line data Source code
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 "LowerBoundNodalKernel.h" 11 : 12 : registerMooseObject("MooseApp", LowerBoundNodalKernel); 13 : 14 : InputParameters 15 14370 : LowerBoundNodalKernel::validParams() 16 : { 17 14370 : InputParameters params = NodalKernel::validParams(); 18 14370 : params.addClassDescription("Used to prevent a coupled variable from going below a lower bound"); 19 14370 : params.addRequiredCoupledVar( 20 : "v", "The coupled variable we require to be greater than the lower bound"); 21 14370 : params.addParam<Real>("lower_bound", 0, "The lower bound on the coupled variable"); 22 14370 : 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 14370 : return params; 29 0 : } 30 : 31 55 : LowerBoundNodalKernel::LowerBoundNodalKernel(const InputParameters & parameters) 32 : : NodalKernel(parameters), 33 55 : _v_var(coupled("v")), 34 55 : _v(coupledValue("v")), 35 110 : _lower_bound(getParam<Real>("lower_bound")) 36 : { 37 55 : if (_var.number() == _v_var) 38 0 : mooseError("Coupled variable 'v' needs to be different from 'variable' with " 39 : "LowerBoundNodalKernel"); 40 : 41 55 : const auto & bnd_names = getParam<std::vector<BoundaryName>>("exclude_boundaries"); 42 165 : for (const auto & bnd_name : bnd_names) 43 110 : _bnd_ids.insert(_mesh.getBoundaryID(bnd_name)); 44 55 : } 45 : 46 : Real 47 88381 : LowerBoundNodalKernel::computeQpResidual() 48 : { 49 262050 : for (auto bnd_id : _bnd_ids) 50 175731 : if (_mesh.isBoundaryNode(_current_node->id(), bnd_id)) 51 2062 : return _u[_qp]; 52 : 53 86319 : return std::min(_u[_qp], _v[_qp] - _lower_bound); 54 : } 55 : 56 : Real 57 68825 : LowerBoundNodalKernel::computeQpJacobian() 58 : { 59 204150 : for (auto bnd_id : _bnd_ids) 60 136875 : if (_mesh.isBoundaryNode(_current_node->id(), bnd_id)) 61 1550 : return 1; 62 : 63 67275 : if (_u[_qp] <= _v[_qp] - _lower_bound) 64 50299 : return 1; 65 16976 : return 0; 66 : } 67 : 68 : Real 69 68825 : LowerBoundNodalKernel::computeQpOffDiagJacobian(unsigned int jvar) 70 : { 71 204150 : for (auto bnd_id : _bnd_ids) 72 136875 : if (_mesh.isBoundaryNode(_current_node->id(), bnd_id)) 73 1550 : return 0; 74 : 75 67275 : if (jvar == _v_var) 76 67275 : if (_v[_qp] - _lower_bound < _u[_qp]) 77 16976 : return 1; 78 : 79 50299 : return 0.0; 80 : }