LCOV - code coverage report
Current view: top level - src/constraints - TiedValueConstraint.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 45 50 90.0 %
Date: 2025-08-08 20:01:16 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 "TiedValueConstraint.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "MooseVariableFE.h"
      14             : #include "SystemBase.h"
      15             : 
      16             : #include "libmesh/sparse_matrix.h"
      17             : 
      18             : registerMooseObject("MooseApp", TiedValueConstraint);
      19             : 
      20             : InputParameters
      21       14415 : TiedValueConstraint::validParams()
      22             : {
      23       14415 :   InputParameters params = NodeFaceConstraint::validParams();
      24       14415 :   params.addClassDescription("Constraint that forces the value of a variable to be the same on "
      25             :                              "both sides of an interface.");
      26       14415 :   params.addParam<Real>("scaling", 1, "scaling factor to be applied to constraint equations");
      27       14415 :   params.set<bool>("use_displaced_mesh") = true;
      28       14415 :   return params;
      29           0 : }
      30             : 
      31          75 : TiedValueConstraint::TiedValueConstraint(const InputParameters & parameters)
      32             :   : NodeFaceConstraint(parameters),
      33          75 :     _scaling(getParam<Real>("scaling")),
      34         150 :     _residual_copy(_sys.residualGhosted())
      35             : {
      36          75 : }
      37             : 
      38             : Real
      39        2092 : TiedValueConstraint::computeQpSecondaryValue()
      40             : {
      41        2092 :   return _u_primary[_qp];
      42             : }
      43             : 
      44             : Real
      45      220630 : TiedValueConstraint::computeQpResidual(Moose::ConstraintType type)
      46             : {
      47      220630 :   Real scaling_factor = _var.scalingFactor();
      48      220630 :   Real secondary_resid = 0;
      49      220630 :   Real retVal = 0;
      50      220630 :   switch (type)
      51             :   {
      52       44126 :     case Moose::Secondary:
      53       44126 :       retVal = (_u_secondary[_qp] - _u_primary[_qp]) * _test_secondary[_i][_qp] * _scaling;
      54       44126 :       break;
      55      176504 :     case Moose::Primary:
      56      176504 :       secondary_resid =
      57      176504 :           _residual_copy(_current_node->dof_number(0, _var.number(), 0)) / scaling_factor;
      58      176504 :       retVal = secondary_resid * _test_primary[_i][_qp];
      59      176504 :       break;
      60           0 :     default:
      61           0 :       break;
      62             :   }
      63      220630 :   return retVal;
      64             : }
      65             : 
      66             : Real
      67      193100 : TiedValueConstraint::computeQpJacobian(Moose::ConstraintJacobianType type)
      68             : {
      69      193100 :   Real scaling_factor = _var.scalingFactor();
      70      193100 :   Real secondary_jac = 0;
      71      193100 :   Real retVal = 0;
      72      193100 :   switch (type)
      73             :   {
      74       22172 :     case Moose::SecondarySecondary:
      75       22172 :       retVal = _phi_secondary[_j][_qp] * _test_secondary[_i][_qp] * _scaling;
      76       22172 :       break;
      77       16448 :     case Moose::SecondaryPrimary:
      78       16448 :       retVal = -_phi_primary[_j][_qp] * _test_secondary[_i][_qp] * _scaling;
      79       16448 :       break;
      80       88688 :     case Moose::PrimarySecondary:
      81             :       secondary_jac =
      82       88688 :           (*_jacobian)(_current_node->dof_number(0, _var.number(), 0), _connected_dof_indices[_j]);
      83       88688 :       retVal = secondary_jac * _test_primary[_i][_qp] / scaling_factor;
      84       88688 :       break;
      85       65792 :     case Moose::PrimaryPrimary:
      86       65792 :       retVal = 0;
      87       65792 :       break;
      88           0 :     default:
      89           0 :       mooseError("Unsupported type");
      90             :       break;
      91             :   }
      92      193100 :   return retVal;
      93             : }

Generated by: LCOV version 1.14