https://mooseframework.inl.gov
KokkosADNodalBC.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 "KokkosNodalBCBase.h"
13 
14 namespace Moose::Kokkos
15 {
16 
37 class ADNodalBC : public NodalBCBase
38 {
39 public:
41 
46 
47  virtual void computeResidual() override;
48  virtual void computeJacobian() override;
49  virtual void computeResidualAndJacobian() override;
50 
54  template <typename Derived>
55  KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const;
56 
57 protected:
61  virtual void dispatch();
62 
70  bool _computing_residual = false;
74  bool _computing_jacobian = false;
75 };
76 
77 template <typename Derived>
78 KOKKOS_FUNCTION void
79 ADNodalBC::operator()(ResidualLoop, const ThreadID tid, const Derived & bc) const
80 {
81  auto node = kokkosBoundaryNodeID(tid);
82  auto & sys = kokkosSystem(_kokkos_var.sys());
83 
84  if (!sys.isNodalDefined(node, _kokkos_var.var()))
85  return;
86 
88 
90 
91  ADReal local_re = bc.template computeQpResidual<Derived>(0, datum);
92 
94  accumulateTaggedNodalResidual(false, local_re.value(), node);
96  accumulateTaggedNodalMatrix(false, local_re.derivatives(), node);
97 }
98 
99 } // namespace Moose::Kokkos
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
KOKKOS_FUNCTION void operator()(ResidualLoop, const ThreadID tid, const Derived &bc) const
The parallel computation entry function called by Kokkos.
KOKKOS_FUNCTION const Assembly & kokkosAssembly() const
Get the const reference of the Kokkos assembly.
KOKKOS_FUNCTION ContiguousNodeID kokkosBoundaryNodeID(Moose::Kokkos::ThreadID tid) const
Get the contiguous node ID this Kokkos thread is operating on.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
virtual void computeResidual() override
Compute this object&#39;s contribution to the residual.
KOKKOS_FUNCTION void accumulateTaggedNodalResidual(const bool add, const Real local_re, const ContiguousNodeID node, const unsigned int comp=0) const
Accumulate or set local nodal residual contribution to tagged vectors.
KOKKOS_FUNCTION void do_derivatives(const bool flag)
Set whether to compute derivatives for automatic differentiation (AD)
Definition: KokkosDatum.h:476
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
bool _computing_residual
Whether computing residual.
DualNumber< Real, DNDerivativeType, false > ADReal
Definition: KokkosADReal.h:28
bool _computing_jacobian
Whether computing Jacobian.
MOOSE_KOKKOS_INDEX_TYPE ThreadID
Definition: KokkosThread.h:22
virtual void dispatch()
Dispatch parallel calculation.
ADNodalBC(const InputParameters &parameters)
Constructor.
KOKKOS_FUNCTION const System & kokkosSystem(unsigned int sys) const
Get the const reference of a Kokkos system.
Definition: KokkosSystem.h:792
The Kokkos wrapper classes for MOOSE-like variable value access.
const ADVariableValue _u
Current solution at nodes.
The base class for Kokkos nodal boundary conditions.
static InputParameters validParams()
virtual void computeResidualAndJacobian() override
Compute this object&#39;s contribution to the residual and Jacobian simultaneously.
The Kokkos object that holds thread-private data in the parallel operations of Kokkos kernels...
Definition: KokkosDatum.h:364
Variable _kokkos_var
Kokkos variable.
KOKKOS_FUNCTION unsigned int var(unsigned int comp=0) const
Get the variable number of a component.
KOKKOS_FUNCTION void accumulateTaggedNodalMatrix(const bool add, const Real local_ke, const ContiguousNodeID node, const unsigned int jvar, const unsigned int comp=0) const
Accumulate or set local nodal Jacobian contribution to tagged matrices.
The base class for a user to derive their own Kokkos nodal boundary conditions using automatic differ...
virtual void computeJacobian() override
Compute this object&#39;s contribution to the diagonal Jacobian entries.
KOKKOS_FUNCTION const Array< System > & kokkosSystems() const
Get the const reference of the Kokkos systems.
Definition: KokkosSystem.h:775