LCOV - code coverage report
Current view: top level - src/bcs - VectorNodalBC.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 30 43 69.8 %
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 "VectorNodalBC.h"
      11             : 
      12             : #include "Assembly.h"
      13             : #include "MooseVariableFE.h"
      14             : #include "SystemBase.h"
      15             : #include "NonlinearSystemBase.h"
      16             : #include "FEProblemBase.h"
      17             : 
      18             : InputParameters
      19       57816 : VectorNodalBC::validParams()
      20             : {
      21       57816 :   InputParameters params = NodalBCBase::validParams();
      22       57816 :   return params;
      23             : }
      24             : 
      25         374 : VectorNodalBC::VectorNodalBC(const InputParameters & parameters)
      26             :   : NodalBCBase(parameters),
      27             :     MooseVariableInterface<RealVectorValue>(this,
      28             :                                             true,
      29             :                                             "variable",
      30             :                                             Moose::VarKindType::VAR_SOLVER,
      31             :                                             Moose::VarFieldType::VAR_FIELD_VECTOR),
      32         748 :     _var(*mooseVariable()),
      33         374 :     _current_node(_var.node()),
      34         748 :     _u(_var.nodalValue())
      35             : {
      36         374 :   if (_var.feType().family != LAGRANGE_VEC)
      37           0 :     mooseError("Vector nodal boundary conditions only make sense for LAGRANGE_VEC variables");
      38         374 :   addMooseVariableDependency(mooseVariable());
      39         374 : }
      40             : 
      41             : void
      42      183196 : VectorNodalBC::computeResidual()
      43             : {
      44      183196 :   const std::vector<dof_id_type> & dof_indices = _var.dofIndices();
      45      183196 :   if (dof_indices.empty())
      46           0 :     return;
      47             : 
      48      183196 :   const RealVectorValue res = computeQpResidual();
      49             : 
      50      601970 :   for (const auto i : index_range(dof_indices))
      51      418774 :     setResidual(_sys, res(i), dof_indices[i]);
      52             : }
      53             : 
      54             : void
      55       13106 : VectorNodalBC::computeJacobian()
      56             : {
      57       13106 :   const std::vector<dof_id_type> & cached_rows = _var.dofIndices();
      58       13106 :   if (cached_rows.empty())
      59           0 :     return;
      60             : 
      61       13106 :   const RealVectorValue cached_val = computeQpJacobian();
      62             : 
      63             :   // Cache the user's computeQpJacobian() value for later use.
      64       43372 :   for (const auto i : index_range(cached_rows))
      65       30266 :     addJacobianElement(_fe_problem.assembly(0, _sys.number()),
      66       30266 :                        cached_val(i),
      67       30266 :                        cached_rows[i],
      68       30266 :                        cached_rows[i],
      69             :                        /*scaling_factor=*/1);
      70             : }
      71             : 
      72             : void
      73       13106 : VectorNodalBC::computeOffDiagJacobian(const unsigned int jvar_num)
      74             : {
      75       13106 :   if (jvar_num == _var.number())
      76       13106 :     computeJacobian();
      77             :   else
      78             :   {
      79           0 :     const std::vector<dof_id_type> & cached_rows = _var.dofIndices();
      80           0 :     if (cached_rows.empty())
      81           0 :       return;
      82             : 
      83           0 :     const Real cached_val = computeQpOffDiagJacobian(jvar_num);
      84             :     // Note: this only works for Lagrange variables...
      85           0 :     const dof_id_type cached_col = _current_node->dof_number(_sys.number(), jvar_num, 0);
      86             : 
      87             :     // Cache the user's computeQpJacobian() value for later use.
      88           0 :     for (const auto i : index_range(cached_rows))
      89           0 :       addJacobianElement(_fe_problem.assembly(0, _sys.number()),
      90             :                          cached_val,
      91           0 :                          cached_rows[i],
      92             :                          cached_col,
      93             :                          /*scaling_factor=*/1);
      94             :   }
      95             : }
      96             : 
      97             : RealVectorValue
      98       13106 : VectorNodalBC::computeQpJacobian()
      99             : {
     100       13106 :   return RealVectorValue(1., 1., 1.);
     101             : }
     102             : 
     103             : Real
     104           0 : VectorNodalBC::computeQpOffDiagJacobian(unsigned int /*jvar*/)
     105             : {
     106           0 :   return 0.;
     107             : }

Generated by: LCOV version 1.14