https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosLinearSystemContributionObject.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 "KokkosDispatcher.h"
13#include "KokkosMesh.h"
14#include "KokkosSystem.h"
15#include "KokkosVariable.h"
16
17#include "MooseObject.h"
18#include "SetupInterface.h"
19#include "FunctionInterface.h"
20#include "UserObjectInterface.h"
21#include "TransientInterface.h"
24#include "Restartable.h"
26#include "TaggingInterface.h"
28
29class InputParameters;
30class FEProblemBase;
31
32namespace Moose::Kokkos
33{
34
41 public SetupInterface,
42 public FunctionInterface,
44 public TransientInterface,
47 public Restartable,
49 public TaggingInterface,
50 public MeshHolder,
51 public SystemHolder
52{
53public:
55
58
63 Variable variable() const { return _var; }
64
67 {
68 };
71 {
72 };
73
77 virtual void computeRightHandSide() = 0;
81 virtual void computeMatrix() = 0;
82
83protected:
86 {
87 Atomic,
89 };
90
91 template <AccumulationMode mode = AccumulationMode::Atomic>
92 KOKKOS_FUNCTION void accumulateTaggedVector(Real value, dof_id_type row) const;
93 template <AccumulationMode mode = AccumulationMode::Atomic>
94 KOKKOS_FUNCTION void accumulateTaggedMatrix(Real value, dof_id_type row, dof_id_type col) const;
95
98
101
106
108 std::unique_ptr<DispatcherBase> _rhs_dispatcher;
110 std::unique_ptr<DispatcherBase> _matrix_dispatcher;
111
119};
120
121template <LinearSystemContributionObject::AccumulationMode mode>
122KOKKOS_FUNCTION inline void
124 const dof_id_type row) const
125{
126 if (!value)
127 return;
128
129 KOKKOS_ASSERT(_var.components() == 1);
130 auto & sys = kokkosSystem(_var.sys());
131 const MOOSE_KOKKOS_INDEX_TYPE tags_size = _vector_tags.size();
132 for (MOOSE_KOKKOS_INDEX_TYPE index = 0; index < tags_size; ++index)
133 {
134 const auto tag = _vector_tags[index];
135 if (sys.isResidualTagActive(tag))
136 {
137 if constexpr (mode == AccumulationMode::Atomic)
138 ::Kokkos::atomic_add(&sys.getVectorDofValue(row, tag), value);
139 else
140 sys.getVectorDofValue(row, tag) += value;
141 }
142 }
143}
144
145template <LinearSystemContributionObject::AccumulationMode mode>
146KOKKOS_FUNCTION inline void
148 const dof_id_type row,
149 const dof_id_type col) const
150{
151 if (!value)
152 return;
153
154 KOKKOS_ASSERT(_var.components() == 1);
155 auto & sys = kokkosSystem(_var.sys());
156 const MOOSE_KOKKOS_INDEX_TYPE tags_size = _matrix_tags.size();
157 for (MOOSE_KOKKOS_INDEX_TYPE index = 0; index < tags_size; ++index)
158 {
159 const auto tag = _matrix_tags[index];
160 if (sys.isMatrixTagActive(tag))
161 {
162 if constexpr (mode == AccumulationMode::Atomic)
163 ::Kokkos::atomic_add(&sys.getMatrixValue(row, col, tag), value);
164 else
165 sys.getMatrixValue(row, col, tag) += value;
166 }
167 }
168}
169
170} // namespace Moose::Kokkos
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
Interface for objects that need to use functions.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Interface for notifications that the mesh has changed.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
KOKKOS_FUNCTION index_type size() const
Get the total array size.
The Kokkos array class.
Base class for Kokkos objects that contribute to a linear system, i.e.
KOKKOS_FUNCTION void accumulateTaggedMatrix(Real value, dof_id_type row, dof_id_type col) const
FEProblemBase & _fe_problem
Reference to the finite element problem.
AccumulationMode
Whether tagged vector/matrix accumulation must use atomics.
Array< TagID > _matrix_tags
Matrix tags this object contributes to.
LinearSystemContributionObject(const InputParameters &parameters)
LinearSystemContributionObject(const LinearSystemContributionObject &object)
Variable variable() const
Get the Kokkos variable this object contributes to.
KOKKOS_FUNCTION void accumulateTaggedVector(Real value, dof_id_type row) const
virtual void computeRightHandSide()=0
Compute the right-hand side contributions of this object.
Scalar< Real > _t
TODO: Move to TransientInterface.
std::unique_ptr< DispatcherBase > _matrix_dispatcher
Dispatcher for the matrix computation loop.
Array< TagID > _vector_tags
Vector (residual) tags this object contributes to.
std::unique_ptr< DispatcherBase > _rhs_dispatcher
Dispatcher for the right-hand side computation loop.
virtual void computeMatrix()=0
Compute the matrix contributions of this object.
The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device during ...
Definition KokkosMesh.h:630
The Kokkos wrapper class that can hold the reference of an arithmetic scalar variable.
The Kokkos variable object that carries the coupled variable and tag information.
KOKKOS_FUNCTION unsigned int components() const
Get the number of components.
KOKKOS_FUNCTION unsigned int sys(unsigned int comp=0) const
Get the system number of a component.
Interface class for classes which interact with Postprocessors.
A class for creating restricted objects.
Definition Restartable.h:29
Interface for objects that needs transient capabilities.
Interface for objects that need to use UserObjects.
Tag dispatch type for the right-hand side computation loop.