74 mooseError(
"variable() was called for a multi-variable Kokkos residual object. Use "
75 "variables() instead.");
80 virtual std::vector<const MooseVariableBase *>
variables()
const override
87 mooseError(
"computeOffDiagJacobian() is not used for Kokkos residual objects.");
99 const std::vector<MooseVariableFieldBase *>
_vars;
158 const unsigned int i,
159 const unsigned int comp)
const;
170 const unsigned int comp)
const;
181 const unsigned int i)
const;
193 const unsigned int i,
194 const unsigned int j,
195 const unsigned int jvar,
196 const unsigned int comp)
const;
207 const unsigned int i,
208 const unsigned int comp)
const;
220 const unsigned int jvar,
221 const unsigned int comp)
const;
234 const unsigned int i,
235 const unsigned int j,
236 const unsigned int jvar)
const;
248 const unsigned int comp)
const;
255 template <
typename function>
262 template <
typename function>
282KOKKOS_FUNCTION
inline void
285 const unsigned int i,
286 const unsigned int comp)
const
292 auto dof = sys.getElemLocalDofIndex(elem, i,
_kokkos_var.
var(comp));
293 auto constraints = sys.getLocalConstraints(dof);
299 if (sys.isResidualTagActive(tag))
301 if (constraints.size())
302 for (
unsigned int c = 0; c < constraints.size(); ++c)
304 auto [constraint_dof, weight] = constraints[c];
306 ::Kokkos::atomic_add(&sys.getVectorDofValue(constraint_dof, tag), weight * local_re);
309 ::Kokkos::atomic_add(&sys.getVectorDofValue(dof, tag), local_re);
314KOKKOS_FUNCTION
inline void
318 const unsigned int comp)
const
320 if (!local_re && add)
324 auto dof = sys.getNodeLocalDofIndex(node, 0,
_kokkos_var.
var(comp));
330 if (sys.isResidualTagActive(tag))
333 sys.getVectorDofValue(dof, tag) += local_re;
335 sys.getVectorDofValue(dof, tag) = local_re;
340KOKKOS_FUNCTION
inline void
344 const unsigned int i)
const
346 if (!local_re && add)
356 if (sys.isResidualTagActive(tag))
359 sys.getVectorDofValue(dof, tag) += local_re;
361 sys.getVectorDofValue(dof, tag) = local_re;
366KOKKOS_FUNCTION
inline void
369 const unsigned int i,
370 const unsigned int j,
371 const unsigned int jvar,
372 const unsigned int comp)
const
379 auto row = sys.getElemLocalDofIndex(elem, i, ivar);
380 auto col = sys.isScalarVariable(jvar) ? sys.getScalarLocalDofIndex(j, jvar)
381 : sys.getElemLocalDofIndex(elem, j, jvar);
382 auto col_global = sys.localToGlobalDofIndex(col);
383 auto row_constraints = sys.getLocalConstraints(row);
384 auto col_constraints = sys.getLocalConstraints(col);
390 if (sys.isMatrixTagActive(tag))
392 for (
unsigned int rc = 0; rc < ::Kokkos::max(1u, row_constraints.size()); ++rc)
394 auto constraint_row = row_constraints.
size() ? row_constraints[rc].first : row;
395 auto weight_row = row_constraints.size() ? row_constraints[rc].second : 1.0;
397 if (sys.hasNodalBCMatrixTag(constraint_row, tag))
400 for (
unsigned int cc = 0; cc < ::Kokkos::max(1u, col_constraints.size()); ++cc)
402 auto constraint_col = col_constraints.size()
403 ? sys.localToGlobalDofIndex(col_constraints[cc].first)
405 auto weight_col = col_constraints.size() ? col_constraints[cc].second : 1.0;
407 ::Kokkos::atomic_add(&sys.getMatrixValue(constraint_row, constraint_col, tag),
408 weight_row * weight_col * local_ke);
415KOKKOS_FUNCTION
inline void
418 const unsigned int i,
419 const unsigned int comp)
const
423 auto row = sys.getElemLocalDofIndex(datum.
elem().
id, i, ivar);
424 auto row_constraints = sys.getLocalConstraints(row);
430 if (sys.isMatrixTagActive(tag))
432 for (
unsigned int rc = 0; rc < ::Kokkos::max(1u, row_constraints.size()); ++rc)
434 auto constraint_row = row_constraints.
size() ? row_constraints[rc].first : row;
435 auto weight_row = row_constraints.size() ? row_constraints[rc].second : 1.0;
437 if (sys.hasNodalBCMatrixTag(constraint_row, tag))
440 for (
unsigned int j = 0; j < local_ke.size(); ++j)
442 auto col = local_ke.raw_index(j);
443 auto col_constraints = sys.getLocalConstraints(col);
445 for (
unsigned int cc = 0; cc < ::Kokkos::max(1u, col_constraints.size()); ++cc)
447 auto constraint_col =
448 sys.localToGlobalDofIndex(col_constraints.size() ? col_constraints[cc].first : col);
449 auto weight_col = col_constraints.size() ? col_constraints[cc].second : 1.0;
451 ::Kokkos::atomic_add(&sys.getMatrixValue(constraint_row, constraint_col, tag),
452 weight_row * weight_col * local_ke.raw_at(j));
460KOKKOS_FUNCTION
inline void
464 const unsigned int jvar,
465 const unsigned int comp)
const
467 if (!local_ke && add)
471 auto row = sys.getNodeLocalDofIndex(node, 0,
_kokkos_var.
var(comp));
472 auto col = sys.getNodeGlobalDofIndex(node, 0, jvar);
478 if (sys.isMatrixTagActive(tag))
480 auto & matrix = sys.getMatrix(tag);
483 matrix(row, col) += local_ke;
487 matrix(row, col) = local_ke;
493KOKKOS_FUNCTION
inline void
497 const unsigned int i,
498 const unsigned int j,
499 const unsigned int jvar)
const
501 if (!local_ke && add)
506 auto col = sys.getNodeGlobalDofIndex(node, j, jvar);
512 if (sys.isMatrixTagActive(tag))
514 auto & matrix = sys.getMatrix(tag);
517 matrix(row, col) += local_ke;
521 matrix(row, col) = local_ke;
527KOKKOS_FUNCTION
inline void
531 const unsigned int comp)
const
534 auto row = sys.getNodeLocalDofIndex(node, 0,
_kokkos_var.
var(comp));
539 auto & matrix = sys.getMatrix(tag);
541 if (sys.isMatrixTagActive(tag))
546 for (
unsigned int j = 0; j < local_ke.size(); ++j)
548 auto col = sys.localToGlobalDofIndex(local_ke.raw_index(j));
551 matrix(row, col) += local_ke.raw_at(j);
553 matrix(row, col) = local_ke.raw_at(j);
559template <
typename function>
565 const auto scaling_factor =
569 unsigned int num_batches = datum.
n_dofs() / stride;
571 if (datum.
n_dofs() % stride)
574 for (
unsigned int batch = 0; batch < num_batches; ++batch)
576 unsigned int ib = batch * stride;
577 unsigned int ie = ::Kokkos::min(ib + stride, datum.
n_dofs());
579 const unsigned int n = ie - ib;
584 ib += t * d + (t < m ? t : m);
585 ie = ib + d + (t < m ? 1 : 0);
587 for (
unsigned int i = ib; i < ie; ++i)
588 local_re[i - ib] = 0;
590 body(local_re - ib, ib, ie);
592 for (
unsigned int i = ib; i < ie; ++i)
594 local_re[i - ib] * scaling_factor, datum.
elem().
id, i, datum.
comp());
598template <
typename function>
604 const auto scaling_factor =
615 for (
unsigned int batch = 0; batch < num_batches; ++batch)
620 for (
unsigned int i = ib; i < ie; ++i)
621 local_ke[i - ib] = 0;
623 body(local_ke - ib, ib, ie, j);
625 for (
unsigned int i = ib; i < ie; ++i)
627 local_ke[i - ib] * scaling_factor, datum.
elem().
id, i, j, datum.
jvar(), datum.
comp());
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...
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.
KOKKOS_FUNCTION unsigned int comp() const
Get the variable component.
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 std::vector< const MooseVariableBase * > variables() const override
Returns all the variables that this object operates on.
virtual void computeResidualAndJacobian() override
Compute this object's contribution to the residual and Jacobian simultaneously.
std::vector< MooseVariableFieldBase * > getMooseVariables(Moose::VarFieldType field_type)
Get the MOOSE variables from the 'variable' or 'variables' parameter.
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.
ResidualObject(const ResidualObject &object)
Copy constructor for parallel dispatch.
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.
const unsigned int _dimension
Mesh dimension.
static InputParameters validParams()
KOKKOS_FUNCTION void accumulateTaggedNodalMatrix(const bool add, const Real local_ke, const ContiguousNodeID node, const unsigned int jvar, const unsigned int comp) const
Accumulate or set local nodal Jacobian contribution to tagged matrices.
std::unique_ptr< DispatcherBase > _offdiag_jacobian_scalar_dispatcher
static constexpr bool uses_precompute_hooks
Whether this object's hooks factor out the test function.
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.
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
KOKKOS_FUNCTION void accumulateTaggedNodalResidual(const bool add, const Real local_re, const ContiguousNodeID node, const unsigned int comp) const
Accumulate or set local nodal residual contribution to tagged vectors.
Scalar< int > _t_step
The number of the time step.
KOKKOS_FUNCTION void computeResidualInternal(AssemblyDatum &datum, function body) const
The common loop structure template for computing elemental residual.
const std::vector< MooseVariableFieldBase * > _vars
MOOSE variables.
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.