https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosTimeDerivative.h
Go to the documentation of this file.
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
13
15{
16public:
18
20
21 template <typename Derived>
22 KOKKOS_FUNCTION void computeJacobianInternal(const Derived & kernel, AssemblyDatum & datum) const;
23
24 template <typename Derived>
25 KOKKOS_FUNCTION Real precomputeQpResidual(const unsigned int qp, AssemblyDatum & datum) const;
26 template <typename Derived>
27 KOKKOS_FUNCTION Real precomputeQpJacobian(const unsigned int j,
28 const unsigned int qp,
29 AssemblyDatum & datum) const;
30
31protected:
32 const bool _lumping;
33};
34
35template <typename Derived>
36KOKKOS_FUNCTION void
38{
40
41 Real local_ke[MAX_CACHED_DOF];
42
43 const auto scaling_factor =
44 kokkosSystem(_kokkos_var.sys()).getVariableScalingFactor(_kokkos_var.var());
45
46 for (unsigned int j = datum.local_thread_id(); j < datum.n_jdofs();
47 j += datum.num_local_threads())
48 {
49 unsigned int num_batches = datum.n_idofs() / MAX_CACHED_DOF;
50
51 if (datum.n_idofs() % MAX_CACHED_DOF)
52 ++num_batches;
53
54 for (unsigned int batch = 0; batch < num_batches; ++batch)
55 {
56 unsigned int ib = batch * MAX_CACHED_DOF;
57 unsigned int ie = ::Kokkos::min(ib + MAX_CACHED_DOF, datum.n_idofs());
58
59 for (unsigned int i = ib; i < ie; ++i)
60 local_ke[i - ib] = 0;
61
62 for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
63 {
64 Real value = datum.JxW(qp) * kernel.template precomputeQpJacobian<Derived>(j, qp, datum);
65
66 for (unsigned int i = ib; i < ie; ++i)
67 local_ke[i - ib] += value * _test(datum, i, qp);
68 }
69
70 for (unsigned int i = ib; i < ie; ++i)
71 accumulateTaggedElementalMatrix(local_ke[i - ib] * scaling_factor,
72 datum.elem().id,
73 i,
74 _lumping ? i : j,
75 datum.jvar(),
76 datum.comp());
77 }
78 }
79}
80
81template <typename Derived>
82KOKKOS_FUNCTION Real
83KokkosTimeDerivative::precomputeQpResidual(const unsigned int qp, AssemblyDatum & datum) const
84{
85 return _u_dot(datum, qp);
86}
87
88template <typename Derived>
89KOKKOS_FUNCTION Real
91 const unsigned int qp,
92 AssemblyDatum & datum) const
93{
94 return _phi(datum, j, qp) * _du_dot_du[datum.comp()];
95}
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
KokkosTimeDerivative(const InputParameters &parameters)
KOKKOS_FUNCTION Real precomputeQpJacobian(const unsigned int j, const unsigned int qp, AssemblyDatum &datum) const
KOKKOS_FUNCTION void computeJacobianInternal(const Derived &kernel, AssemblyDatum &datum) const
static InputParameters validParams()
KOKKOS_FUNCTION Real precomputeQpResidual(const unsigned int qp, AssemblyDatum &datum) const
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels.
KOKKOS_FUNCTION unsigned int jvar() const
Get the coupled variable number.
KOKKOS_FUNCTION unsigned int n_idofs() const
Get the number of local DOFs.
KOKKOS_FUNCTION unsigned int n_jdofs() const
Get the number of local DOFs for the coupled variable.
KOKKOS_FUNCTION unsigned int comp() const
Get the variable component.
KOKKOS_FUNCTION unsigned int num_local_threads() const
Get the number of local threads.
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
KOKKOS_FUNCTION unsigned int local_thread_id() const
Get the current local thread ID.
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
const VariableTestValue _test
Current test function.
const VariablePhiValue _phi
Current shape function.
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
Definition KokkosDatum.h:46
Variable _kokkos_var
Kokkos variable.
KOKKOS_FUNCTION void accumulateTaggedElementalMatrix(const Real local_ke, const ContiguousElementID elem, const unsigned int i, const unsigned int j, const unsigned int jvar, const unsigned int comp) const
Accumulate local elemental Jacobian contribution to tagged matrices.
The base class for Kokkos time kernels whose test function can be factored out.
const VariableValue _u_dot
Time derivative of the current solution at quadrature points.
Array< Real > _du_dot_du
Derivative of u_dot with respect to u.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
constexpr unsigned int MAX_CACHED_DOF
Maximum number of DOFs to cache during residual and Jacobian computation.
ContiguousElementID id
Contiguous element ID.
Definition KokkosMesh.h:42