LCOV - code coverage report
Current view: top level - src/constraints - MassFreeConstraint.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 30 33 90.9 %
Date: 2025-07-30 13:02:48 Functions: 4 6 66.7 %
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 "MassFreeConstraint.h"
      11             : #include "Assembly.h"
      12             : #include "SystemBase.h"
      13             : #include "MooseVariable.h"
      14             : 
      15             : registerMooseObject("ThermalHydraulicsApp", MassFreeConstraint);
      16             : 
      17             : InputParameters
      18          10 : MassFreeConstraint::validParams()
      19             : {
      20          10 :   InputParameters params = NodalConstraint::validParams();
      21          20 :   params.addRequiredParam<std::vector<Real>>("normals", "node normals");
      22          20 :   params.addRequiredParam<std::vector<dof_id_type>>("nodes", "node IDs");
      23          20 :   params.addRequiredCoupledVar("rhouA", "Momentum");
      24          10 :   params.addClassDescription(
      25             :       "Constrains the momentum at the user-specified nodes along the user-specified normals");
      26          10 :   return params;
      27           0 : }
      28             : 
      29           5 : MassFreeConstraint::MassFreeConstraint(const InputParameters & parameters)
      30             :   : NodalConstraint(parameters),
      31           5 :     _normals(getParam<std::vector<Real>>("normals")),
      32           5 :     _rhouA(coupledValue("rhouA")),
      33          10 :     _rhouA_var_number(coupled("rhouA"))
      34             : {
      35          10 :   _primary_node_vector = getParam<std::vector<dof_id_type>>("nodes");
      36             :   // just a dummy value that is never used
      37           5 :   _connected_nodes.push_back(*_primary_node_vector.begin());
      38           5 : }
      39             : 
      40             : void
      41          80 : MassFreeConstraint::computeResidual(NumericVector<Number> & /*residual*/)
      42             : {
      43          80 :   const auto & dofs = _var.dofIndices();
      44          80 :   std::vector<Number> re(dofs.size());
      45             : 
      46         240 :   for (unsigned int i = 0; i < dofs.size(); i++)
      47         160 :     re[i] = _rhouA[i] * _normals[i];
      48             : 
      49          80 :   addResiduals(_assembly, re, dofs, _var.scalingFactor());
      50          80 : }
      51             : 
      52           0 : Real MassFreeConstraint::computeQpResidual(Moose::ConstraintType /*type*/) { return 0; }
      53             : 
      54             : void
      55           5 : MassFreeConstraint::computeJacobian(SparseMatrix<Number> & /*jacobian*/)
      56             : {
      57           5 :   const auto & dofs = _var.dofIndices();
      58             : 
      59             :   // off-diag
      60             :   {
      61           5 :     MooseVariable & var_rhouA = _sys.getFieldVariable<Real>(_tid, _rhouA_var_number);
      62             :     auto && dofs_rhouA = var_rhouA.dofIndices();
      63           5 :     DenseMatrix<Number> Kee(dofs.size(), dofs_rhouA.size());
      64             : 
      65             :     Kee.zero();
      66          15 :     for (unsigned int i = 0; i < dofs.size(); i++)
      67          10 :       Kee(i, i) = _normals[i];
      68           5 :     addJacobian(_assembly, Kee, dofs, dofs_rhouA, _var.scalingFactor());
      69           5 :   }
      70           5 : }
      71             : 
      72           0 : Real MassFreeConstraint::computeQpJacobian(Moose::ConstraintJacobianType /*type*/) { return 0; }

Generated by: LCOV version 1.14