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 : template <typename Derived> 27 : KOKKOS_FUNCTION Real computeValue(const unsigned int qp, AssemblyDatum & datum) const; 28 : 29 : protected: 30 : KOKKOS_FUNCTION Real getIntegralValue(const unsigned int qp, AssemblyDatum & datum) const; 31 : 32 : Moose::Kokkos::Array<Moose::Kokkos::VariableValue> _coupled_vars; 33 : const Real _coef; 34 : const unsigned int _order; 35 : Moose::Kokkos::Array<Real> _integration_coef; 36 : 37 : /// The old variable value (zero if order == 3) 38 : const Moose::Kokkos::VariableValue _u_old; 39 : /// The older variable value (zero if order != 3) 40 : const Moose::Kokkos::VariableValue _u_older; 41 : }; 42 : 43 : template <typename Derived> 44 : KOKKOS_FUNCTION Real 45 569184 : KokkosVariableTimeIntegrationAux::computeValue(const unsigned int qp, AssemblyDatum & datum) const 46 : { 47 569184 : Real integral = getIntegralValue(qp, datum); 48 : 49 569184 : if (_order == 3) 50 189728 : return _u_older(datum, qp) + _coef * integral; 51 : 52 379456 : return _u_old(datum, qp) + _coef * integral; 53 : } 54 : 55 : KOKKOS_FUNCTION inline Real 56 569184 : KokkosVariableTimeIntegrationAux::getIntegralValue(const unsigned int qp, 57 : AssemblyDatum & datum) const 58 : { 59 569184 : Real integral_value = 0.0; 60 : 61 1707552 : for (unsigned int i = 0; i < _order; ++i) 62 1138368 : integral_value += _integration_coef[i] * _coupled_vars[i](datum, qp) * _dt; 63 : 64 : /** 65 : * Subsequent timesteps may be unequal, so the standard Simpson rule 66 : * cannot be used. Use a different set of coefficients here. 67 : * J. McNAMEE, "A PROGRAM TO INTEGRATE A FUNCTION TABULATED AT 68 : * UNEQUAL INTERVALS," Internation Journal for Numerical Methods in 69 : * Engineering, Vol. 17, 217-279. (1981). 70 : */ 71 569184 : if (_order == 3 && _dt != _dt_old) 72 : { 73 131285 : Real x0 = 0.0; 74 131285 : Real x1 = _dt_old; 75 131285 : Real x2 = _dt + _dt_old; 76 131285 : Real y0 = _coupled_vars[2](datum, qp); 77 131285 : Real y1 = _coupled_vars[1](datum, qp); 78 131285 : Real y2 = _coupled_vars[0](datum, qp); 79 131285 : Real term1 = (x2 - x0) * (y0 + (x2 - x0) * (y1 - y0) / (2.0 * (x1 - x0))); 80 131285 : Real term2 = (2.0 * x2 * x2 - x0 * x2 - x0 * x0 + 3.0 * x0 * x1 - 3.0 * x1 * x2) / 6.0; 81 131285 : Real term3 = (y2 - y1) / (x2 - x1) - (y1 - y0) / (x1 - x0); 82 131285 : integral_value = term1 + term2 * term3; 83 : } 84 : 85 569184 : return integral_value; 86 : }