LCOV - code coverage report
Current view: top level - src/nodalkernels - LowerBoundNodalKernel.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 36 38 94.7 %
Date: 2025-07-17 01:28:37 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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       14366 : LowerBoundNodalKernel::validParams()
      16             : {
      17       14366 :   InputParameters params = NodalKernel::validParams();
      18       14366 :   params.addClassDescription("Used to prevent a coupled variable from going below a lower bound");
      19       14366 :   params.addRequiredCoupledVar(
      20             :       "v", "The coupled variable we require to be greater than the lower bound");
      21       14366 :   params.addParam<Real>("lower_bound", 0, "The lower bound on the coupled variable");
      22       14366 :   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       14366 :   return params;
      29           0 : }
      30             : 
      31          53 : LowerBoundNodalKernel::LowerBoundNodalKernel(const InputParameters & parameters)
      32             :   : NodalKernel(parameters),
      33          53 :     _v_var(coupled("v")),
      34          53 :     _v(coupledValue("v")),
      35         106 :     _lower_bound(getParam<Real>("lower_bound"))
      36             : {
      37          53 :   if (_var.number() == _v_var)
      38           0 :     mooseError("Coupled variable 'v' needs to be different from 'variable' with "
      39             :                "LowerBoundNodalKernel");
      40             : 
      41          53 :   const auto & bnd_names = getParam<std::vector<BoundaryName>>("exclude_boundaries");
      42         159 :   for (const auto & bnd_name : bnd_names)
      43         106 :     _bnd_ids.insert(_mesh.getBoundaryID(bnd_name));
      44          53 : }
      45             : 
      46             : Real
      47       77877 : LowerBoundNodalKernel::computeQpResidual()
      48             : {
      49      230850 :   for (auto bnd_id : _bnd_ids)
      50      154827 :     if (_mesh.isBoundaryNode(_current_node->id(), bnd_id))
      51        1854 :       return _u[_qp];
      52             : 
      53       76023 :   return std::min(_u[_qp], _v[_qp] - _lower_bound);
      54             : }
      55             : 
      56             : Real
      57       60543 : LowerBoundNodalKernel::computeQpJacobian()
      58             : {
      59      179550 :   for (auto bnd_id : _bnd_ids)
      60      120393 :     if (_mesh.isBoundaryNode(_current_node->id(), bnd_id))
      61        1386 :       return 1;
      62             : 
      63       59157 :   if (_u[_qp] <= _v[_qp] - _lower_bound)
      64       44311 :     return 1;
      65       14846 :   return 0;
      66             : }
      67             : 
      68             : Real
      69       60543 : LowerBoundNodalKernel::computeQpOffDiagJacobian(unsigned int jvar)
      70             : {
      71      179550 :   for (auto bnd_id : _bnd_ids)
      72      120393 :     if (_mesh.isBoundaryNode(_current_node->id(), bnd_id))
      73        1386 :       return 0;
      74             : 
      75       59157 :   if (jvar == _v_var)
      76       59157 :     if (_v[_qp] - _lower_bound < _u[_qp])
      77       14846 :       return 1;
      78             : 
      79       44311 :   return 0.0;
      80             : }

Generated by: LCOV version 1.14