LCOV - code coverage report
Current view: top level - src/constraints - TiedValueConstraint.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 45 50 90.0 %
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 "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       14403 : TiedValueConstraint::validParams()
      22             : {
      23       14403 :   InputParameters params = NodeFaceConstraint::validParams();
      24       14403 :   params.addClassDescription("Constraint that forces the value of a variable to be the same on "
      25             :                              "both sides of an interface.");
      26       14403 :   params.addParam<Real>("scaling", 1, "scaling factor to be applied to constraint equations");
      27       14403 :   params.set<bool>("use_displaced_mesh") = true;
      28       14403 :   return params;
      29           0 : }
      30             : 
      31          69 : TiedValueConstraint::TiedValueConstraint(const InputParameters & parameters)
      32             :   : NodeFaceConstraint(parameters),
      33          69 :     _scaling(getParam<Real>("scaling")),
      34         138 :     _residual_copy(_sys.residualGhosted())
      35             : {
      36          69 : }
      37             : 
      38             : Real
      39        1848 : TiedValueConstraint::computeQpSecondaryValue()
      40             : {
      41        1848 :   return _u_primary[_qp];
      42             : }
      43             : 
      44             : Real
      45      195900 : TiedValueConstraint::computeQpResidual(Moose::ConstraintType type)
      46             : {
      47      195900 :   Real scaling_factor = _var.scalingFactor();
      48      195900 :   Real secondary_resid = 0;
      49      195900 :   Real retVal = 0;
      50      195900 :   switch (type)
      51             :   {
      52       39180 :     case Moose::Secondary:
      53       39180 :       retVal = (_u_secondary[_qp] - _u_primary[_qp]) * _test_secondary[_i][_qp] * _scaling;
      54       39180 :       break;
      55      156720 :     case Moose::Primary:
      56      156720 :       secondary_resid =
      57      156720 :           _residual_copy(_current_node->dof_number(0, _var.number(), 0)) / scaling_factor;
      58      156720 :       retVal = secondary_resid * _test_primary[_i][_qp];
      59      156720 :       break;
      60           0 :     default:
      61           0 :       break;
      62             :   }
      63      195900 :   return retVal;
      64             : }
      65             : 
      66             : Real
      67      170560 : TiedValueConstraint::computeQpJacobian(Moose::ConstraintJacobianType type)
      68             : {
      69      170560 :   Real scaling_factor = _var.scalingFactor();
      70      170560 :   Real secondary_jac = 0;
      71      170560 :   Real retVal = 0;
      72      170560 :   switch (type)
      73             :   {
      74       19584 :     case Moose::SecondarySecondary:
      75       19584 :       retVal = _phi_secondary[_j][_qp] * _test_secondary[_i][_qp] * _scaling;
      76       19584 :       break;
      77       14528 :     case Moose::SecondaryPrimary:
      78       14528 :       retVal = -_phi_primary[_j][_qp] * _test_secondary[_i][_qp] * _scaling;
      79       14528 :       break;
      80       78336 :     case Moose::PrimarySecondary:
      81             :       secondary_jac =
      82       78336 :           (*_jacobian)(_current_node->dof_number(0, _var.number(), 0), _connected_dof_indices[_j]);
      83       78336 :       retVal = secondary_jac * _test_primary[_i][_qp] / scaling_factor;
      84       78336 :       break;
      85       58112 :     case Moose::PrimaryPrimary:
      86       58112 :       retVal = 0;
      87       58112 :       break;
      88           0 :     default:
      89           0 :       mooseError("Unsupported type");
      90             :       break;
      91             :   }
      92      170560 :   return retVal;
      93             : }

Generated by: LCOV version 1.14