LCOV - code coverage report
Current view: top level - include/kokkos/kernels - KokkosMatCoupledForce.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 6f668f Lines: 11 15 73.3 %
Date: 2025-09-22 20:01:15 Functions: 2 2 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             : #pragma once
      11             : 
      12             : #include "KokkosKernel.h"
      13             : #include "KokkosMap.h"
      14             : 
      15             : /**
      16             :  * Represents a right hand side force term of the form
      17             :  * Sum_j c_j * m_j * v_j, where c is a vector of real numbers,
      18             :  * m_j is a vector of material properties, and v_j is a vector
      19             :  * of variables
      20             :  */
      21             : class KokkosMatCoupledForce final : public Moose::Kokkos::Kernel<KokkosMatCoupledForce>
      22             : {
      23             : public:
      24             :   static InputParameters validParams();
      25             : 
      26             :   KokkosMatCoupledForce(const InputParameters & parameters);
      27             : 
      28             :   KOKKOS_FUNCTION Real computeQpResidual(const unsigned int i,
      29             :                                          const unsigned int qp,
      30             :                                          ResidualDatum & datum) const;
      31             :   KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int i,
      32             :                                                 const unsigned int j,
      33             :                                                 const unsigned int jvar,
      34             :                                                 const unsigned int qp,
      35             :                                                 ResidualDatum & datum) const;
      36             : 
      37             : private:
      38             :   const unsigned int _n_coupled;
      39             :   const bool _coupled_props;
      40             :   std::vector<unsigned int> _v_var;
      41             :   const Moose::Kokkos::VariableValue _v;
      42             :   Moose::Kokkos::Array<Real> _coef;
      43             :   Moose::Kokkos::Map<unsigned int, unsigned int> _v_var_to_index;
      44             :   Moose::Kokkos::Array<Moose::Kokkos::MaterialProperty<Real>> _mat_props;
      45             : };
      46             : 
      47             : KOKKOS_FUNCTION inline Real
      48       20800 : KokkosMatCoupledForce::computeQpResidual(const unsigned int i,
      49             :                                          const unsigned int qp,
      50             :                                          ResidualDatum & datum) const
      51             : {
      52       20800 :   Real r = 0;
      53       20800 :   if (_coupled_props)
      54       62400 :     for (unsigned int j = 0; j < _n_coupled; ++j)
      55       41600 :       r += -_coef[j] * _mat_props[j](datum, qp) * _v(datum, qp, j);
      56             :   else
      57           0 :     for (unsigned int j = 0; j < _n_coupled; ++j)
      58           0 :       r += -_coef[j] * _v(datum, qp, j);
      59       20800 :   return r * _test(datum, i, qp);
      60             : }
      61             : 
      62             : KOKKOS_FUNCTION inline Real
      63       44800 : KokkosMatCoupledForce::computeQpOffDiagJacobian(const unsigned int i,
      64             :                                                 const unsigned int j,
      65             :                                                 const unsigned int jvar,
      66             :                                                 const unsigned int qp,
      67             :                                                 ResidualDatum & datum) const
      68             : {
      69       44800 :   if (!_v_var_to_index.exists(jvar))
      70           0 :     return 0;
      71             : 
      72       44800 :   unsigned int p = _v_var_to_index[jvar];
      73             : 
      74       44800 :   if (_coupled_props)
      75       44800 :     return -_coef[p] * _mat_props[p](datum, qp) * _phi(datum, j, qp) * _test(datum, i, qp);
      76           0 :   return -_coef[p] * _phi(datum, j, qp) * _test(datum, i, qp);
      77             : }

Generated by: LCOV version 1.14