LCOV - code coverage report
Current view: top level - include/kokkos/auxkernels - KokkosVariableTimeIntegrationAux.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #31653 (2d163b) with base 0cc44f Lines: 21 21 100.0 %
Date: 2025-11-04 20:38:02 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 "KokkosAuxKernel.h"
      13             : 
      14             : /**
      15             :  * An AuxKernel that can be used to integrate a field variable in time
      16             :  * using a variety of different integration methods.  The result is
      17             :  * stored in another field variable.
      18             :  */
      19             : class KokkosVariableTimeIntegrationAux : public Moose::Kokkos::AuxKernel
      20             : {
      21             : public:
      22             :   static InputParameters validParams();
      23             : 
      24             :   KokkosVariableTimeIntegrationAux(const InputParameters & parameters);
      25             : 
      26             :   KOKKOS_FUNCTION Real computeValue(const unsigned int qp, AssemblyDatum & datum) const;
      27             : 
      28             : protected:
      29             :   KOKKOS_FUNCTION Real getIntegralValue(const unsigned int qp, AssemblyDatum & datum) const;
      30             : 
      31             :   Moose::Kokkos::Array<Moose::Kokkos::VariableValue> _coupled_vars;
      32             :   const Real _coef;
      33             :   const unsigned int _order;
      34             :   Moose::Kokkos::Array<Real> _integration_coef;
      35             : 
      36             :   /// The old variable value (zero if order == 3)
      37             :   const Moose::Kokkos::VariableValue _u_old;
      38             :   /// The older variable value (zero if order != 3)
      39             :   const Moose::Kokkos::VariableValue _u_older;
      40             : };
      41             : 
      42             : KOKKOS_FUNCTION inline Real
      43      569184 : KokkosVariableTimeIntegrationAux::computeValue(const unsigned int qp, AssemblyDatum & datum) const
      44             : {
      45      569184 :   Real integral = getIntegralValue(qp, datum);
      46             : 
      47      569184 :   if (_order == 3)
      48      189728 :     return _u_older(datum, qp) + _coef * integral;
      49             : 
      50      379456 :   return _u_old(datum, qp) + _coef * integral;
      51             : }
      52             : 
      53             : KOKKOS_FUNCTION inline Real
      54      569184 : KokkosVariableTimeIntegrationAux::getIntegralValue(const unsigned int qp,
      55             :                                                    AssemblyDatum & datum) const
      56             : {
      57      569184 :   Real integral_value = 0.0;
      58             : 
      59     1707552 :   for (unsigned int i = 0; i < _order; ++i)
      60     1138368 :     integral_value += _integration_coef[i] * _coupled_vars[i](datum, qp) * _dt;
      61             : 
      62             :   /**
      63             :    * Subsequent timesteps may be unequal, so the standard Simpson rule
      64             :    * cannot be used. Use a different set of coefficients here.
      65             :    * J. McNAMEE, "A PROGRAM TO INTEGRATE A FUNCTION TABULATED AT
      66             :    * UNEQUAL INTERVALS," Internation Journal for Numerical Methods in
      67             :    * Engineering, Vol. 17, 217-279. (1981).
      68             :    */
      69      569184 :   if (_order == 3 && _dt != _dt_old)
      70             :   {
      71      131285 :     Real x0 = 0.0;
      72      131285 :     Real x1 = _dt_old;
      73      131285 :     Real x2 = _dt + _dt_old;
      74      131285 :     Real y0 = _coupled_vars[2](datum, qp);
      75      131285 :     Real y1 = _coupled_vars[1](datum, qp);
      76      131285 :     Real y2 = _coupled_vars[0](datum, qp);
      77      131285 :     Real term1 = (x2 - x0) * (y0 + (x2 - x0) * (y1 - y0) / (2.0 * (x1 - x0)));
      78      131285 :     Real term2 = (2.0 * x2 * x2 - x0 * x2 - x0 * x0 + 3.0 * x0 * x1 - 3.0 * x1 * x2) / 6.0;
      79      131285 :     Real term3 = (y2 - y1) / (x2 - x1) - (y1 - y0) / (x1 - x0);
      80      131285 :     integral_value = term1 + term2 * term3;
      81             :   }
      82             : 
      83      569184 :   return integral_value;
      84             : }

Generated by: LCOV version 1.14