https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosADIntegratedBC.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
14namespace Moose::Kokkos
15{
16
40{
41public:
43
48
49 virtual void computeResidual() override;
50 virtual void computeJacobian() override;
51 virtual void computeResidualAndJacobian() override;
52
56 template <typename Derived>
57 KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const;
58
64 template <typename Derived>
65 KOKKOS_FUNCTION void computeResidualInternal(const Derived & bc, AssemblyDatum & datum) const;
66
67protected:
71 virtual void dispatch();
72
105};
106
107template <typename Derived>
108KOKKOS_FUNCTION void
109ADIntegratedBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
110{
111 auto comp = _thread(tid, 1);
112 auto [elem, side] = kokkosBoundaryElementSideID(_thread(tid, 2));
113
114 AssemblyDatum datum(
115 elem, side, kokkosAssembly(), kokkosSystems(), _kokkos_var, _kokkos_var.var(comp), comp);
116
117 datum.set_local_parallel(_thread(tid, 0), _thread.size(0));
118
120
121 bc.computeResidualInternal(bc, datum);
122}
123
124template <typename Derived>
125KOKKOS_FUNCTION void
126ADIntegratedBC::computeResidualInternal(const Derived & bc, AssemblyDatum & datum) const
127{
128 const auto scaling_factor =
129 kokkosSystem(_kokkos_var.sys()).getVariableScalingFactor(_kokkos_var.var());
130
131 for (unsigned int i = datum.local_thread_id(); i < datum.n_dofs(); i += datum.num_local_threads())
132 {
133 ADReal local_re = 0;
134
135 for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
136 local_re += datum.JxW(qp) * bc.template computeQpResidual<Derived>(i, qp, datum);
137
138 local_re *= scaling_factor;
139
141 accumulateTaggedElementalResidual(local_re.value(), datum.elem().id, i, datum.comp());
143 accumulateTaggedElementalMatrix(local_re.derivatives(), datum, i, datum.comp());
144 }
145}
146
147} // namespace Moose::Kokkos
KOKKOS_FUNCTION auto kokkosBoundaryElementSideID(Moose::Kokkos::ThreadID tid) const
Get the contiguous element ID - side index pair this Kokkos thread is operating on.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
The base class for a user to derive their own Kokkos integrated boundary conditions using automatic d...
const ADVariableGradient _grad_u
Gradient of the current solution at quadrature points.
virtual void computeResidual() override
Compute this object's contribution to the residual.
const ADVariablePhiGradient _grad_phi
Gradient of the current shape function.
bool _computing_residual
Whether computing residual.
virtual void dispatch()
Dispatch parallel calculation.
const ADVariableValue _u
Current solution at quadrature points.
virtual void computeResidualAndJacobian() override
Compute this object's contribution to the residual and Jacobian simultaneously.
const ADVariableTestValue _test
Current test function.
static InputParameters validParams()
const ADVariableTestGradient _grad_test
Gradient of the current test function.
ADIntegratedBC(const InputParameters &parameters)
Constructor.
virtual void computeJacobian() override
Compute this object's contribution to the diagonal Jacobian entries.
KOKKOS_FUNCTION void computeResidualInternal(const Derived &bc, AssemblyDatum &datum) const
Compute residual.
bool _computing_jacobian
Whether computing Jacobian.
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &bc) const
The parallel computation entry function called by Kokkos.
const ADVariablePhiValue _phi
Current shape function.
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels.
KOKKOS_FUNCTION unsigned int n_dofs() const
Get the number of local DOFs.
KOKKOS_FUNCTION void do_derivatives(const bool flag)
Set whether to compute derivatives for automatic differentiation (AD)
KOKKOS_FUNCTION unsigned int comp() const
Get the variable component.
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
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 void set_local_parallel(const unsigned int local_thread_id, const unsigned int num_local_threads)
Set local parallelization option.
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
The base class for Kokkos integrated boundary conditions.
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
Definition KokkosDatum.h:46
Variable _kokkos_var
Kokkos variable.
Thread _thread
Kokkos thread object.
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.
KOKKOS_FUNCTION void accumulateTaggedElementalResidual(const Real local_re, const ContiguousElementID elem, const unsigned int i, const unsigned int comp) const
Accumulate local elemental residual contribution to tagged vectors.
KOKKOS_FUNCTION thread_id_type size() const
Get the total thread pool size.
The Kokkos wrapper classes for MOOSE-like shape function access.
The Kokkos wrapper classes for MOOSE-like variable value access.
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.
MOOSE_KOKKOS_INDEX_TYPE ThreadID
DualNumber< Real, DNDerivativeType, false > ADReal
ContiguousElementID id
Contiguous element ID.
Definition KokkosMesh.h:42