https://mooseframework.inl.gov
KokkosADIntegratedBC.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "KokkosIntegratedBCBase.h"
13 
14 namespace Moose::Kokkos
15 {
16 
40 {
41 public:
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 
67 protected:
71  virtual void dispatch();
72 
100  bool _computing_residual = false;
104  bool _computing_jacobian = false;
105 };
106 
107 template <typename Derived>
108 KOKKOS_FUNCTION void
109 ADIntegratedBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
110 {
111  auto [elem, side] = kokkosBoundaryElementSideID(_thread(tid, 1));
112 
113  AssemblyDatum datum(
115 
116  datum.set_local_parallel(_thread(tid, 0), _thread.size(0));
117 
118  datum.do_derivatives(_computing_jacobian);
119 
120  bc.computeResidualInternal(bc, datum);
121 }
122 
123 template <typename Derived>
124 KOKKOS_FUNCTION void
125 ADIntegratedBC::computeResidualInternal(const Derived & bc, AssemblyDatum & datum) const
126 {
127  for (unsigned int i = datum.local_thread_id(); i < datum.n_dofs(); i += datum.num_local_threads())
128  {
129  ADReal local_re = 0;
130 
131  for (unsigned int qp = 0; qp < datum.n_qps(); ++qp)
132  local_re += datum.JxW(qp) * bc.template computeQpResidual<Derived>(i, qp, datum);
133 
135  accumulateTaggedElementalResidual(local_re.value(), datum.elem().id, i);
137  accumulateTaggedElementalMatrix(local_re.derivatives(), datum, i);
138  }
139 }
140 
141 } // namespace Moose::Kokkos
KOKKOS_FUNCTION void set_local_parallel(const unsigned int local_thread_id, const unsigned int num_local_threads)
Set local parallelization option.
Definition: KokkosDatum.h:187
const ADVariableGradient _grad_u
Gradient of the current solution at quadrature points.
ADIntegratedBC(const InputParameters &parameters)
Constructor.
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
virtual void computeResidual() override
Compute this object&#39;s contribution to the residual.
virtual void computeResidualAndJacobian() override
Compute this object&#39;s contribution to the residual and Jacobian simultaneously.
KOKKOS_FUNCTION unsigned int num_local_threads() const
Get the number of local threads.
Definition: KokkosDatum.h:202
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
bool _computing_residual
Whether computing residual.
KOKKOS_FUNCTION void computeResidualInternal(const Derived &bc, AssemblyDatum &datum) const
Compute residual.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Thread _thread
Kokkos thread object.
The base class for Kokkos integrated boundary conditions.
bool _computing_jacobian
Whether computing Jacobian.
The Kokkos wrapper classes for MOOSE-like shape function access.
DualNumber< Real, DNDerivativeType, false > ADReal
Definition: KokkosADReal.h:28
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
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=0) const
Accumulate local elemental Jacobian contribution to tagged matrices.
static InputParameters validParams()
KOKKOS_FUNCTION unsigned int n_qps() const
Get the number of local quadrature points.
Definition: KokkosDatum.h:118
KOKKOS_FUNCTION unsigned int local_thread_id() const
Get the current local thread ID.
Definition: KokkosDatum.h:197
The Kokkos wrapper classes for MOOSE-like variable value access.
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &bc) const
The parallel computation entry function called by Kokkos.
const ADVariableValue _u
Current solution at quadrature points.
KOKKOS_FUNCTION auto kokkosBoundaryElementSideID(Moose::Kokkos::ThreadID tid) const
Get the contiguous element ID - side index pair this Kokkos thread is operating on.
const ADVariablePhiValue _phi
Current shape function.
KOKKOS_FUNCTION void accumulateTaggedElementalResidual(const Real local_re, const ContiguousElementID elem, const unsigned int i, const unsigned int comp=0) const
Accumulate local elemental residual contribution to tagged vectors.
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
Definition: KokkosDatum.h:84
virtual void computeJacobian() override
Compute this object&#39;s contribution to the diagonal Jacobian entries.
virtual void dispatch()
Dispatch parallel calculation.
const ADVariablePhiGradient _grad_phi
Gradient of the current shape function.
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:364
KOKKOS_FUNCTION Real JxW(const unsigned int qp)
Get the transformed Jacobian weight.
Definition: KokkosDatum.h:311
Variable _kokkos_var
Kokkos variable.
The base class for a user to derive their own Kokkos integrated boundary conditions using automatic d...
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION unsigned int n_dofs() const
Get the number of local DOFs.
Definition: KokkosDatum.h:426
KOKKOS_FUNCTION thread_id_type size() const
Get the total thread pool size.
Definition: KokkosThread.h:50
const ADVariableTestGradient _grad_test
Gradient of the current test function.
const ADVariableTestValue _test
Current test function.
ContiguousElementID id
Contiguous element ID.
Definition: KokkosMesh.h:42
KOKKOS_FUNCTION const Array< System > & kokkosSystems() const
Get the const reference of the Kokkos systems.
Definition: KokkosSystem.h:775