69 mooseError(
"computeOffDiagJacobian() is not used for Kokkos residual objects.");
139 const unsigned int i,
140 const unsigned int comp = 0)
const;
151 const unsigned int comp = 0)
const;
162 const unsigned int i)
const;
174 const unsigned int i,
175 const unsigned int j,
176 const unsigned int jvar,
177 const unsigned int comp = 0)
const;
188 const unsigned int i,
189 const unsigned int comp = 0)
const;
201 const unsigned int jvar,
202 const unsigned int comp = 0)
const;
215 const unsigned int i,
216 const unsigned int j,
217 const unsigned int jvar)
const;
229 const unsigned int comp = 0)
const;
236 template <
typename function>
243 template <
typename function>
256KOKKOS_FUNCTION
inline void
259 const unsigned int i,
260 const unsigned int comp)
const
266 auto dof = sys.getElemLocalDofIndex(elem, i,
_kokkos_var.
var(comp));
272 if (sys.isResidualTagActive(tag))
273 ::Kokkos::atomic_add(&sys.getVectorDofValue(dof, tag), local_re);
277KOKKOS_FUNCTION
inline void
281 const unsigned int comp)
const
283 if (!local_re && add)
287 auto dof = sys.getNodeLocalDofIndex(node, 0,
_kokkos_var.
var(comp));
293 if (sys.isResidualTagActive(tag))
296 sys.getVectorDofValue(dof, tag) += local_re;
298 sys.getVectorDofValue(dof, tag) = local_re;
303KOKKOS_FUNCTION
inline void
307 const unsigned int i)
const
309 if (!local_re && add)
319 if (sys.isResidualTagActive(tag))
322 sys.getVectorDofValue(dof, tag) += local_re;
324 sys.getVectorDofValue(dof, tag) = local_re;
329KOKKOS_FUNCTION
inline void
332 const unsigned int i,
333 const unsigned int j,
334 const unsigned int jvar,
335 const unsigned int comp)
const
341 auto row = sys.getElemLocalDofIndex(elem, i,
_kokkos_var.
var(comp));
342 auto col = sys.getElemGlobalDofIndex(elem, j, jvar);
348 if (sys.isMatrixTagActive(tag) && !sys.hasNodalBCMatrixTag(row, tag))
349 ::Kokkos::atomic_add(&sys.getMatrixValue(row, col, tag), local_ke);
353KOKKOS_FUNCTION
inline void
356 const unsigned int i,
357 const unsigned int comp)
const
366 if (sys.isMatrixTagActive(tag) && !sys.hasNodalBCMatrixTag(row, tag))
367 for (
unsigned int j = 0; j < local_ke.size(); ++j)
369 auto col = local_ke.raw_index(j);
371 ::Kokkos::atomic_add(&sys.getMatrixValue(row, col, tag), local_ke.raw_at(j));
376KOKKOS_FUNCTION
inline void
380 const unsigned int jvar,
381 const unsigned int comp)
const
383 if (!local_ke && add)
387 auto row = sys.getNodeLocalDofIndex(node, 0,
_kokkos_var.
var(comp));
388 auto col = sys.getNodeGlobalDofIndex(node, 0, jvar);
394 if (sys.isMatrixTagActive(tag))
396 auto & matrix = sys.getMatrix(tag);
399 matrix(row, col) += local_ke;
403 matrix(row, col) = local_ke;
409KOKKOS_FUNCTION
inline void
413 const unsigned int i,
414 const unsigned int j,
415 const unsigned int jvar)
const
417 if (!local_ke && add)
422 auto col = sys.getNodeGlobalDofIndex(node, j, jvar);
428 if (sys.isMatrixTagActive(tag))
430 auto & matrix = sys.getMatrix(tag);
433 matrix(row, col) += local_ke;
437 matrix(row, col) = local_ke;
443KOKKOS_FUNCTION
inline void
447 const unsigned int comp)
const
450 auto row = sys.getNodeLocalDofIndex(node, 0,
_kokkos_var.
var(comp));
455 auto & matrix = sys.getMatrix(tag);
457 if (sys.isMatrixTagActive(tag))
462 for (
unsigned int j = 0; j < local_ke.size(); ++j)
464 auto col = local_ke.raw_index(j);
467 matrix(row, col) += local_ke.raw_at(j);
469 matrix(row, col) = local_ke.raw_at(j);
475template <
typename function>
482 unsigned int num_batches = datum.
n_dofs() / stride;
484 if (datum.
n_dofs() % stride)
487 for (
unsigned int batch = 0; batch < num_batches; ++batch)
489 unsigned int ib = batch * stride;
490 unsigned int ie = ::Kokkos::min(ib + stride, datum.
n_dofs());
492 const unsigned int n = ie - ib;
497 ib += t * d + (t < m ? t : m);
498 ie = ib + d + (t < m ? 1 : 0);
500 for (
unsigned int i = ib; i < ie; ++i)
501 local_re[i - ib] = 0;
503 body(local_re - ib, ib, ie);
505 for (
unsigned int i = ib; i < ie; ++i)
510template <
typename function>
524 for (
unsigned int batch = 0; batch < num_batches; ++batch)
529 for (
unsigned int i = ib; i < ie; ++i)
530 local_ke[i - ib] = 0;
532 body(local_ke - ib, ib, ie, j);
534 for (
unsigned int i = ib; i < ie; ++i)
dof_id_type ContiguousElementID
dof_id_type ContiguousNodeID
const InputParameters & parameters() const
Get the parameters of the object.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
This class provides an interface for common operations on field variables of both FE and FV types wit...
KOKKOS_FUNCTION index_type size() const
Get the total array size.
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 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.
The Kokkos interface that holds the host reference of the Kokkos assembly and copies it to device dur...
KOKKOS_FUNCTION unsigned int num_local_threads() const
Get the number of local threads.
KOKKOS_FUNCTION unsigned int local_thread_id() const
Get the current local thread ID.
KOKKOS_FUNCTION const ElementInfo & elem() const
Get the element information object.
The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device during ...
The base class for Kokkos residual objects.
virtual void computeResidualAndJacobian() override
Compute this object's contribution to the residual and Jacobian simultaneously.
Scalar< const Real > _t_old
Old time.
ResidualObject(const InputParameters ¶meters, Moose::VarFieldType field_type, bool nodal=false)
Constructor.
std::unique_ptr< DispatcherBase > _residual_dispatcher
Kokkos functor dispatchers.
Scalar< Real > _t
TODO: Move to TransientInterface.
Scalar< Real > _dt_old
Size of the old time step.
KOKKOS_FUNCTION void accumulateTaggedVectorNodalMatrix(const bool add, const Real local_ke, const ContiguousNodeID node, const unsigned int i, const unsigned int j, const unsigned int jvar) const
Accumulate or set local nodal Jacobian contribution to tagged matrices for vector FE variables.
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.
ResidualObject(const ResidualObject &object)
Copy constructor for parallel dispatch.
Variable _kokkos_var
Kokkos variable.
Thread _thread
Kokkos thread object.
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.
static constexpr bool use_precompute_hooks
Whether this object's hooks factor out the test function.
const unsigned int _dimension
Mesh dimension.
static InputParameters validParams()
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.
Array< TagID > _vector_tags
Tags this object operates on.
KOKKOS_FUNCTION void accumulateTaggedVectorNodalResidual(const bool add, const Real local_re, const ContiguousNodeID node, const unsigned int i) const
Accumulate or set local nodal residual contribution to tagged vectors for vector FE variables.
MooseVariableFieldBase & _var
Reference of the MOOSE variable.
virtual void computeOffDiagJacobian(unsigned int) override final
Computes this object's contribution to off-diagonal blocks of the system Jacobian matrix.
KOKKOS_FUNCTION void computeJacobianInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental Jacobian.
Scalar< Real > _dt
Time step size.
std::unique_ptr< DispatcherBase > _offdiag_jacobian_dispatcher
virtual const MooseVariableBase & variable() const override
Returns the variable that this object operates on.
std::unique_ptr< DispatcherBase > _jacobian_dispatcher
Array< TagID > _matrix_tags
Scalar< int > _t_step
The number of the time step.
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.
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.
The Kokkos wrapper class that can hold the reference of an arithmetic scalar variable.
The Kokkos thread object that aids in converting the one-dimensional thread index into multi-dimensio...
The Kokkos variable object that carries the coupled variable and tag information.
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.
This is the common base class for objects that give residual contributions.
virtual void computeResidual()=0
Compute this object's contribution to the residual.
virtual void computeJacobian()=0
Compute this object's contribution to the diagonal Jacobian entries.
KokkosSemiDynamicSparseNumberArray< Real, libMesh::dof_id_type, NWrapper< MOOSE_AD_MAX_DOFS_PER_ELEM > > DNDerivativeType
constexpr unsigned int MAX_CACHED_DOF
Maximum number of DOFs to cache during residual and Jacobian computation.
ContiguousElementID id
Contiguous element ID.