LCOV - code coverage report
Current view: top level - src/scalarkernels - AverageValueConstraint.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 3501bd Lines: 17 22 77.3 %
Date: 2025-09-04 20:01:23 Functions: 5 7 71.4 %
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 "AverageValueConstraint.h"
      11             : #include "libmesh/system.h"
      12             : 
      13             : registerMooseObject("MooseApp", AverageValueConstraint);
      14             : 
      15             : InputParameters
      16       14623 : AverageValueConstraint::validParams()
      17             : {
      18       14623 :   InputParameters params = ScalarKernel::validParams();
      19       29246 :   params.addClassDescription("This class is used to enforce integral of phi with a "
      20             :                              "Lagrange multiplier approach.");
      21       58492 :   params.addRequiredParam<PostprocessorName>(
      22             :       "pp_name", "Name of the Postprocessor value we are trying to equate with 'value'.");
      23       43869 :   params.addRequiredParam<Real>(
      24             :       "value", "Given (constant) which we want the integral of the solution variable to match.");
      25       14623 :   return params;
      26           0 : }
      27             : 
      28         179 : AverageValueConstraint::AverageValueConstraint(const InputParameters & parameters)
      29             :   : ScalarKernel(parameters),
      30         179 :     _value(getParam<Real>("value")),
      31         358 :     _pp_value(getPostprocessorValue("pp_name")),
      32         358 :     _add_jacobian(!_sys.system().has_static_condensation())
      33             : {
      34         179 : }
      35             : 
      36             : void
      37         522 : AverageValueConstraint::reinit()
      38             : {
      39         522 : }
      40             : 
      41             : Real
      42         306 : AverageValueConstraint::computeQpResidual()
      43             : {
      44         306 :   return _pp_value - _value;
      45             : }
      46             : 
      47             : Real
      48         135 : AverageValueConstraint::computeQpJacobian()
      49             : {
      50             :   // Note: Here, the true on-diagonal Jacobian contribution is
      51             :   // actually zero, i.e. we are not making any approximation
      52             :   // here. That is because the "lambda"-equation in this system of
      53             :   // equations does not depend on lambda. For more information, see
      54             :   // the detailed writeup [0].
      55             :   //
      56             :   // [0]: https://github.com/idaholab/large_media/blob/master/scalar_constraint_kernel.pdf
      57         135 :   return 0.;
      58             : }
      59             : 
      60             : void
      61           0 : AverageValueConstraint::computeOffDiagJacobianScalar(unsigned int /*jvar*/)
      62             : {
      63           0 : }
      64             : 
      65             : Real
      66           0 : AverageValueConstraint::computeQpOffDiagJacobianScalar(unsigned int /*jvar*/)
      67             : {
      68             :   // The off-diagonal contribution for this ScalarKernel (derivative
      69             :   // wrt the "primal" field variable) is not _actually_ zero, but we
      70             :   // are computing it elsewhere (see ScalarLagrangeMultiplier.C) so
      71             :   // here we simply return zero. For more information on this, see the
      72             :   // detailed writeup [0].
      73             :   //
      74             :   // [0]: https://github.com/idaholab/large_media/blob/master/scalar_constraint_kernel.pdf
      75           0 :   return 0.;
      76             : }

Generated by: LCOV version 1.14