LCOV - code coverage report
Current view: top level - src/constraints - NodeElemConstraint.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 86 92 93.5 %
Date: 2025-07-17 01:28:37 Functions: 6 7 85.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 "NodeElemConstraint.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "Assembly.h"
      14             : #include "MooseMesh.h"
      15             : 
      16             : InputParameters
      17       28768 : NodeElemConstraint::validParams()
      18             : {
      19       28768 :   InputParameters params = NodeElemConstraintBase::validParams();
      20       28768 :   return params;
      21             : }
      22             : 
      23         120 : NodeElemConstraint::NodeElemConstraint(const InputParameters & parameters)
      24             :   : NodeElemConstraintBase(parameters),
      25         240 :     _u_primary(_primary_var.slnNeighbor()),
      26         120 :     _u_secondary(_var.dofValues()),
      27         120 :     _grad_phi_primary(_assembly.gradPhiNeighbor(_primary_var)),
      28         120 :     _grad_test_primary(_var.gradPhiNeighbor()),
      29         240 :     _grad_u_primary(_primary_var.gradSlnNeighbor())
      30             : {
      31         120 : }
      32             : 
      33             : void
      34        5740 : NodeElemConstraint::computeResidual()
      35             : {
      36        5740 :   _qp = 0;
      37             : 
      38        5740 :   prepareVectorTagNeighbor(_assembly, _primary_var.number());
      39       43260 :   for (_i = 0; _i < _test_primary.size(); _i++)
      40       37520 :     _local_re(_i) += computeQpResidual(Moose::Primary);
      41        5740 :   accumulateTaggedLocalResidual();
      42             : 
      43        5740 :   prepareVectorTag(_assembly, _var.number());
      44       11480 :   for (_i = 0; _i < _test_secondary.size(); _i++)
      45        5740 :     _local_re(_i) += computeQpResidual(Moose::Secondary);
      46        5740 :   accumulateTaggedLocalResidual();
      47        5740 : }
      48             : 
      49             : void
      50        2870 : NodeElemConstraint::computeJacobian()
      51             : {
      52        2870 :   getConnectedDofIndices(_var.number());
      53             : 
      54        2870 :   _Kee.resize(_test_secondary.size(), _connected_dof_indices.size());
      55        2870 :   _Kne.resize(_test_primary.size(), _connected_dof_indices.size());
      56             : 
      57        5740 :   for (_i = 0; _i < _test_secondary.size(); _i++)
      58             :     // Loop over the connected dof indices so we can get all the jacobian contributions
      59       33740 :     for (_j = 0; _j < _connected_dof_indices.size(); _j++)
      60       30870 :       _Kee(_i, _j) += computeQpJacobian(Moose::SecondarySecondary);
      61             : 
      62        2870 :   prepareMatrixTagNeighbor(_assembly, _var.number(), _primary_var.number(), Moose::ElementNeighbor);
      63        2870 :   if (_local_ke.m() && _local_ke.n())
      64        5740 :     for (_i = 0; _i < _test_secondary.size(); _i++)
      65       21630 :       for (_j = 0; _j < _phi_primary.size(); _j++)
      66       18760 :         _local_ke(_i, _j) += computeQpJacobian(Moose::SecondaryPrimary);
      67        2870 :   accumulateTaggedLocalMatrix();
      68             : 
      69       21630 :   for (_i = 0; _i < _test_primary.size(); _i++)
      70             :     // Loop over the connected dof indices so we can get all the jacobian contributions
      71      238000 :     for (_j = 0; _j < _connected_dof_indices.size(); _j++)
      72      219240 :       _Kne(_i, _j) += computeQpJacobian(Moose::PrimarySecondary);
      73             : 
      74        2870 :   prepareMatrixTagNeighbor(
      75        2870 :       _assembly, _primary_var.number(), _primary_var.number(), Moose::NeighborNeighbor);
      76        2870 :   if (_local_ke.m() && _local_ke.n())
      77       21630 :     for (_i = 0; _i < _test_primary.size(); _i++)
      78      152040 :       for (_j = 0; _j < _phi_primary.size(); _j++)
      79      133280 :         _local_ke(_i, _j) += computeQpJacobian(Moose::PrimaryPrimary);
      80        2870 :   accumulateTaggedLocalMatrix();
      81        2870 : }
      82             : 
      83             : void
      84         280 : NodeElemConstraint::computeOffDiagJacobian(const unsigned int jvar_num)
      85             : {
      86         280 :   getConnectedDofIndices(jvar_num);
      87             : 
      88         280 :   _Kee.resize(_test_secondary.size(), _connected_dof_indices.size());
      89         280 :   _Kne.resize(_test_primary.size(), _connected_dof_indices.size());
      90             : 
      91         560 :   for (_i = 0; _i < _test_secondary.size(); _i++)
      92             :     // Loop over the connected dof indices so we can get all the jacobian contributions
      93         280 :     for (_j = 0; _j < _connected_dof_indices.size(); _j++)
      94           0 :       _Kee(_i, _j) += computeQpOffDiagJacobian(Moose::SecondarySecondary, jvar_num);
      95             : 
      96         280 :   prepareMatrixTagNeighbor(_assembly, _var.number(), jvar_num, Moose::ElementNeighbor);
      97         560 :   for (_i = 0; _i < _test_secondary.size(); _i++)
      98        1400 :     for (_j = 0; _j < _phi_primary.size(); _j++)
      99        1120 :       _local_ke(_i, _j) += computeQpOffDiagJacobian(Moose::SecondaryPrimary, jvar_num);
     100         280 :   accumulateTaggedLocalMatrix();
     101             : 
     102         280 :   if (_Kne.m() && _Kne.n())
     103           0 :     for (_i = 0; _i < _test_primary.size(); _i++)
     104             :       // Loop over the connected dof indices so we can get all the jacobian contributions
     105           0 :       for (_j = 0; _j < _connected_dof_indices.size(); _j++)
     106           0 :         _Kne(_i, _j) += computeQpOffDiagJacobian(Moose::PrimarySecondary, jvar_num);
     107             : 
     108         280 :   prepareMatrixTagNeighbor(_assembly, _primary_var.number(), jvar_num, Moose::NeighborNeighbor);
     109        1400 :   for (_i = 0; _i < _test_primary.size(); _i++)
     110        5600 :     for (_j = 0; _j < _phi_primary.size(); _j++)
     111        4480 :       _local_ke(_i, _j) += computeQpOffDiagJacobian(Moose::PrimaryPrimary, jvar_num);
     112         280 :   accumulateTaggedLocalMatrix();
     113         280 : }
     114             : 
     115             : void
     116        3150 : NodeElemConstraint::getConnectedDofIndices(unsigned int var_num)
     117             : {
     118        3150 :   MooseVariableFEBase & var = _sys.getVariable(0, var_num);
     119             : 
     120        3150 :   _connected_dof_indices.clear();
     121        3150 :   std::set<dof_id_type> unique_dof_indices;
     122             : 
     123        3150 :   auto node_to_elem_pair = _node_to_elem_map.find(_current_node->id());
     124             :   mooseAssert(node_to_elem_pair != _node_to_elem_map.end(), "Missing entry in node to elem map");
     125        3150 :   const std::vector<dof_id_type> & elems = node_to_elem_pair->second;
     126             : 
     127             :   // Get the dof indices from each elem connected to the node
     128       12810 :   for (const auto & cur_elem : elems)
     129             :   {
     130        9660 :     std::vector<dof_id_type> dof_indices;
     131             : 
     132        9660 :     var.getDofIndices(_mesh.elemPtr(cur_elem), dof_indices);
     133             : 
     134       61460 :     for (const auto & dof : dof_indices)
     135       51800 :       unique_dof_indices.insert(dof);
     136        9660 :   }
     137             : 
     138       34020 :   for (const auto & dof : unique_dof_indices)
     139       30870 :     _connected_dof_indices.push_back(dof);
     140             : 
     141        3150 :   _phi_secondary.resize(_connected_dof_indices.size());
     142             : 
     143        3150 :   const dof_id_type current_node_var_dof_index = _sys.getVariable(0, var_num).nodalDofIndex();
     144             : 
     145             :   // Fill up _phi_secondary so that it is 1 when j corresponds to the dof associated with this node
     146             :   // and 0 for every other dof
     147             :   // This corresponds to evaluating all of the connected shape functions at _this_ node
     148        3150 :   _qp = 0;
     149       34020 :   for (unsigned int j = 0; j < _connected_dof_indices.size(); j++)
     150             :   {
     151       30870 :     _phi_secondary[j].resize(1);
     152             : 
     153       30870 :     if (_connected_dof_indices[j] == current_node_var_dof_index)
     154        2870 :       _phi_secondary[j][_qp] = 1.0;
     155             :     else
     156       28000 :       _phi_secondary[j][_qp] = 0.0;
     157             :   }
     158        3150 : }
     159             : 
     160             : Real
     161           0 : NodeElemConstraint::computeQpJacobian(Moose::ConstraintJacobianType /*type*/)
     162             : {
     163           0 :   mooseError("Derived classes must implement computeQpJacobian.");
     164             :   return 0;
     165             : }

Generated by: LCOV version 1.14