75 mooseError(
"computeOffDiagJacobian() is not used for Kokkos residual objects.");
146 const unsigned int i,
147 const unsigned int comp = 0)
const;
158 const unsigned int comp = 0)
const;
169 const unsigned int i)
const;
181 const unsigned int i,
182 const unsigned int j,
183 const unsigned int jvar,
184 const unsigned int comp = 0)
const;
195 const unsigned int i,
196 const unsigned int comp = 0)
const;
208 const unsigned int jvar,
209 const unsigned int comp = 0)
const;
222 const unsigned int i,
223 const unsigned int j,
224 const unsigned int jvar)
const;
236 const unsigned int comp = 0)
const;
243 template <
typename function>
250 template <
typename function>
263KOKKOS_FUNCTION
inline void
266 const unsigned int i,
267 const unsigned int comp)
const
274 auto dof = sys.getElemLocalDofIndex(elem, i, var);
275 const auto scaled_local_re = local_re * sys.getVariableScalingFactor(var);
281 if (sys.isResidualTagActive(tag))
282 ::Kokkos::atomic_add(&sys.getVectorDofValue(dof, tag), scaled_local_re);
286KOKKOS_FUNCTION
inline void
290 const unsigned int comp)
const
292 if (!local_re && add)
296 auto dof = sys.getNodeLocalDofIndex(node, 0,
_kokkos_var.
var(comp));
302 if (sys.isResidualTagActive(tag))
305 sys.getVectorDofValue(dof, tag) += local_re;
307 sys.getVectorDofValue(dof, tag) = local_re;
312KOKKOS_FUNCTION
inline void
316 const unsigned int i)
const
318 if (!local_re && add)
328 if (sys.isResidualTagActive(tag))
331 sys.getVectorDofValue(dof, tag) += local_re;
333 sys.getVectorDofValue(dof, tag) = local_re;
338KOKKOS_FUNCTION
inline void
341 const unsigned int i,
342 const unsigned int j,
343 const unsigned int jvar,
344 const unsigned int comp)
const
351 auto row = sys.getElemLocalDofIndex(elem, i, ivar);
352 auto col = sys.isScalarVariable(jvar) ? sys.getScalarGlobalDofIndex(j, jvar)
353 : sys.getElemGlobalDofIndex(elem, j, jvar);
354 const auto scaled_local_ke = local_ke * sys.getVariableScalingFactor(ivar);
360 if (sys.isMatrixTagActive(tag) && !sys.hasNodalBCMatrixTag(row, tag))
361 ::Kokkos::atomic_add(&sys.getMatrixValue(row, col, tag), scaled_local_ke);
365KOKKOS_FUNCTION
inline void
368 const unsigned int i,
369 const unsigned int comp)
const
373 auto row = sys.getElemLocalDofIndex(datum.
elem().
id, i, ivar);
374 const auto scaling_factor = sys.getVariableScalingFactor(ivar);
380 if (sys.isMatrixTagActive(tag) && !sys.hasNodalBCMatrixTag(row, tag))
381 for (
unsigned int j = 0; j < local_ke.size(); ++j)
383 auto col = local_ke.raw_index(j);
385 ::Kokkos::atomic_add(&sys.getMatrixValue(row, col, tag),
386 local_ke.raw_at(j) * scaling_factor);
391KOKKOS_FUNCTION
inline void
395 const unsigned int jvar,
396 const unsigned int comp)
const
398 if (!local_ke && add)
402 auto row = sys.getNodeLocalDofIndex(node, 0,
_kokkos_var.
var(comp));
403 auto col = sys.getNodeGlobalDofIndex(node, 0, jvar);
409 if (sys.isMatrixTagActive(tag))
411 auto & matrix = sys.getMatrix(tag);
414 matrix(row, col) += local_ke;
418 matrix(row, col) = local_ke;
424KOKKOS_FUNCTION
inline void
428 const unsigned int i,
429 const unsigned int j,
430 const unsigned int jvar)
const
432 if (!local_ke && add)
437 auto col = sys.getNodeGlobalDofIndex(node, j, jvar);
443 if (sys.isMatrixTagActive(tag))
445 auto & matrix = sys.getMatrix(tag);
448 matrix(row, col) += local_ke;
452 matrix(row, col) = local_ke;
458KOKKOS_FUNCTION
inline void
462 const unsigned int comp)
const
465 auto row = sys.getNodeLocalDofIndex(node, 0,
_kokkos_var.
var(comp));
470 auto & matrix = sys.getMatrix(tag);
472 if (sys.isMatrixTagActive(tag))
477 for (
unsigned int j = 0; j < local_ke.size(); ++j)
479 auto col = local_ke.raw_index(j);
482 matrix(row, col) += local_ke.raw_at(j);
484 matrix(row, col) = local_ke.raw_at(j);
490template <
typename function>
497 unsigned int num_batches = datum.
n_dofs() / stride;
499 if (datum.
n_dofs() % stride)
502 for (
unsigned int batch = 0; batch < num_batches; ++batch)
504 unsigned int ib = batch * stride;
505 unsigned int ie = ::Kokkos::min(ib + stride, datum.
n_dofs());
507 const unsigned int n = ie - ib;
512 ib += t * d + (t < m ? t : m);
513 ie = ib + d + (t < m ? 1 : 0);
515 for (
unsigned int i = ib; i < ie; ++i)
516 local_re[i - ib] = 0;
518 body(local_re - ib, ib, ie);
520 for (
unsigned int i = ib; i < ie; ++i)
525template <
typename function>
539 for (
unsigned int batch = 0; batch < num_batches; ++batch)
544 for (
unsigned int i = ib; i < ie; ++i)
545 local_ke[i - ib] = 0;
547 body(local_ke - ib, ib, ie, j);
549 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.
const unsigned int _dimension
Mesh dimension.
static InputParameters validParams()
std::unique_ptr< DispatcherBase > _offdiag_jacobian_scalar_dispatcher
static constexpr bool uses_precompute_hooks
Whether this object's hooks factor out the test function.
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.
static constexpr bool supports_scalar_jacobian
Whether this object has computeQpOffDiagJacobianScalar() hook.
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.