LCOV - code coverage report
Current view: top level - include/kokkos/kernels - KokkosMatCoupledForce.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 11 15 73.3 %
Date: 2026-05-29 20:35:17 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 "KokkosKernelValue.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 : public Moose::Kokkos::KernelValue
      22             : {
      23             : public:
      24             :   static InputParameters validParams();
      25             : 
      26             :   KokkosMatCoupledForce(const InputParameters & parameters);
      27             : 
      28             :   template <typename Derived>
      29             :   KOKKOS_FUNCTION Real computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const;
      30             :   template <typename Derived>
      31             :   KOKKOS_FUNCTION Real computeQpOffDiagJacobian(const unsigned int j,
      32             :                                                 const unsigned int jvar,
      33             :                                                 const unsigned int qp,
      34             :                                                 AssemblyDatum & datum) const;
      35             : 
      36             : private:
      37             :   const unsigned int _n_coupled;
      38             :   const bool _coupled_props;
      39             :   std::vector<unsigned int> _v_var;
      40             :   const Moose::Kokkos::VariableValue _v;
      41             :   Moose::Kokkos::Array<Real> _coef;
      42             :   Moose::Kokkos::Map<unsigned int, unsigned int> _v_var_to_index;
      43             :   Moose::Kokkos::Array<Moose::Kokkos::MaterialProperty<Real>> _mat_props;
      44             : };
      45             : 
      46             : template <typename Derived>
      47             : KOKKOS_FUNCTION Real
      48       20800 : KokkosMatCoupledForce::computeQpResidual(const unsigned int qp, AssemblyDatum & datum) const
      49             : {
      50       20800 :   Real r = 0;
      51       20800 :   if (_coupled_props)
      52       62400 :     for (unsigned int j = 0; j < _n_coupled; ++j)
      53       41600 :       r += -_coef[j] * _mat_props[j](datum, qp) * _v(datum, qp, j);
      54             :   else
      55           0 :     for (unsigned int j = 0; j < _n_coupled; ++j)
      56           0 :       r += -_coef[j] * _v(datum, qp, j);
      57       20800 :   return r;
      58             : }
      59             : 
      60             : template <typename Derived>
      61             : KOKKOS_FUNCTION Real
      62       11200 : KokkosMatCoupledForce::computeQpOffDiagJacobian(const unsigned int j,
      63             :                                                 const unsigned int jvar,
      64             :                                                 const unsigned int qp,
      65             :                                                 AssemblyDatum & datum) const
      66             : {
      67       11200 :   if (!_v_var_to_index.exists(jvar))
      68           0 :     return 0;
      69             : 
      70       11200 :   unsigned int p = _v_var_to_index[jvar];
      71             : 
      72       11200 :   if (_coupled_props)
      73       11200 :     return -_coef[p] * _mat_props[p](datum, qp) * _phi(datum, j, qp);
      74           0 :   return -_coef[p] * _phi(datum, j, qp);
      75             : }

Generated by: LCOV version 1.14