10 #ifndef TEMPUS_CDR_MODEL_FUNCTORS_HPP
11 #define TEMPUS_CDR_MODEL_FUNCTORS_HPP
13 #include "Kokkos_Core.hpp"
14 #include "Tpetra_Details_OrdinalTraits.hpp"
16 namespace Tempus_Test {
18 template <
class TpetraVectorType>
20 using SC =
typename TpetraVectorType::impl_scalar_type;
21 using LO =
typename TpetraVectorType::local_ordinal_type;
22 using GO =
typename TpetraVectorType::global_ordinal_type;
23 using Map =
typename TpetraVectorType::map_type;
25 using DV =
typename TpetraVectorType::dual_view_type;
26 using View =
typename DV::t_dev;
35 :
coordsView_(coords.getLocalViewDevice(Tpetra::Access::ReadWrite)),
42 KOKKOS_INLINE_FUNCTION
49 template <
class Scalar,
class LO>
53 KOKKOS_INLINE_FUNCTION
57 eta = -1.0 / sqrt(3.0);
61 eta = 1.0 / sqrt(3.0);
66 phi[0] = (1.0 -
eta) / 2.0;
67 phi[1] = (1.0 +
eta) / 2.0;
72 dz = 0.5 * (z[1] - z[0]);
79 for (LO i = 0; i < 2; i++) {
83 uu_dot += u_dot[i] * phi[i];
84 duu_dot += u_dot[i] * dphide[i];
106 template <
class TpetraVectorType,
class TpetraMatrixType>
108 using SC =
typename TpetraVectorType::impl_scalar_type;
109 using LO =
typename TpetraVectorType::local_ordinal_type;
110 using Map =
typename TpetraVectorType::map_type;
112 using DV =
typename TpetraVectorType::dual_view_type;
114 using LocalMat =
typename TpetraMatrixType::local_matrix_device_type;
129 const TpetraVectorType &u,
130 const TpetraVectorType &uDot,
const int &myRank,
131 const SC a,
const SC k,
const SC alpha,
133 :
jLocal_(J.getLocalMatrixDevice()),
134 xView_(x.getLocalViewDevice(Tpetra::Access::ReadOnly)),
135 uView_(u.getLocalViewDevice(Tpetra::Access::ReadOnly)),
136 uDotView_(uDot.getLocalViewDevice(Tpetra::Access::ReadOnly)),
137 rowMap_(J.getRowMap()->getLocalMap()),
138 colMap_(J.getColMap()->getLocalMap()),
148 KOKKOS_INLINE_FUNCTION
151 const auto invalid = Tpetra::Details::OrdinalTraits<LO>::invalid();
155 xx[1] =
xView_(ne + 1, 0);
159 uu[1] =
uView_(ne + 1, 0);
167 for (
LO gp = 0; gp < 2; ++gp) {
172 for (
LO i = 0; i < 2; ++i) {
176 if (localRow != invalid) {
178 for (
LO j = 0; j < 2; ++j) {
179 const auto localColumn = ne + j;
181 basis.
wt * basis.
dz *
185 + (1.0 / (basis.
dz * basis.
dz)) * basis.
dphide[j] *
187 + 2.0 *
k_ * basis.
uu * basis.
phi[j] *
191 jLocal_.sumIntoValues(localRow, &localColumn, 1, &jac,
false,
true);
197 if ((
myRank_ == 0) && (ne == 0)) {
201 jLocal_.replaceValues(row, &col, 1, &val);
205 jLocal_.replaceValues(row, &col, 1, &val);
213 template <
class TpetraVectorType,
class TpetraMatrixType>
215 using SC =
typename TpetraVectorType::impl_scalar_type;
216 using LO =
typename TpetraVectorType::local_ordinal_type;
217 using Map =
typename TpetraVectorType::map_type;
219 using DV =
typename TpetraVectorType::dual_view_type;
221 using LocalMat =
typename TpetraMatrixType::local_matrix_device_type;
236 const TpetraVectorType &x,
237 const TpetraVectorType &u,
238 const TpetraVectorType &uDot,
239 const int &myRank,
const SC a,
const SC k,
240 const SC alpha,
const SC beta)
241 :
mLocal_(M.getLocalMatrixDevice()),
242 xView_(x.getLocalViewDevice(Tpetra::Access::ReadOnly)),
243 uView_(u.getLocalViewDevice(Tpetra::Access::ReadOnly)),
244 uDotView_(uDot.getLocalViewDevice(Tpetra::Access::ReadOnly)),
245 rowMap_(M.getRowMap()->getLocalMap()),
246 colMap_(M.getColMap()->getLocalMap()),
256 KOKKOS_INLINE_FUNCTION
259 const auto invalid = Tpetra::Details::OrdinalTraits<LO>::invalid();
263 xx[1] =
xView_(ne + 1, 0);
267 uu[1] =
uView_(ne + 1, 0);
276 for (
LO gp = 0; gp < 2; ++gp) {
281 for (
LO i = 0; i < 2; ++i) {
286 if (localRow != invalid) {
287 for (
LO j = 0; j < 2; ++j) {
288 const auto localColumn = ne + j;
289 if (
rowMap_.getGlobalElement(localRow) ==
290 colMap_.getGlobalElement(localColumn)) {
291 auto value = basis.
wt * basis.
dz *
295 + (1.0 / (basis.
dz * basis.
dz)) *
298 + 2.0 *
k_ * basis.
uu * basis.
phi[j] *
301 mLocal_.sumIntoValues(localRow, &localColumn, 1, &value);
309 if ((
myRank_ == 0) && (ne == 0)) {
313 mLocal_.replaceValues(row, &column, 1, &value);
320 template <
class TpetraVectorType>
322 using SC =
typename TpetraVectorType::impl_scalar_type;
323 using LO =
typename TpetraVectorType::local_ordinal_type;
324 using Map =
typename TpetraVectorType::map_type;
326 using DV =
typename TpetraVectorType::dual_view_type;
327 using View =
typename DV::t_dev;
341 const TpetraVectorType &u,
const TpetraVectorType &uDot,
342 const int myRank,
SC a,
SC k)
343 :
fView_(f.getLocalViewDevice(Tpetra::Access::ReadWrite)),
344 xView_(x.getLocalViewDevice(Tpetra::Access::ReadOnly)),
345 uView_(u.getLocalViewDevice(Tpetra::Access::ReadOnly)),
346 uDotView_(uDot.getLocalViewDevice(Tpetra::Access::ReadOnly)),
347 rowMap_(f.getMap()->getLocalMap()),
348 colMap_(u.getMap()->getLocalMap()),
356 KOKKOS_INLINE_FUNCTION
359 const auto invalid = Tpetra::Details::OrdinalTraits<LO>::invalid();
363 xx[1] =
xView_(ne + 1, 0);
367 uu[1] =
uView_(ne + 1, 0);
375 for (
LO gp = 0; gp < 2; ++gp) {
380 for (
LO i = 0; i < 2; ++i) {
383 if (localRow != invalid) {
385 basis.
wt * basis.
dz *
388 + 1.0 / (basis.
dz * basis.
dz)) *
390 +
k_ * basis.
uu * basis.
uu * basis.
phi[i]);
391 Kokkos::atomic_add(&
fView_(localRow, 0), value);
397 if ((
myRank_ == 0) && (ne == 0)) {
399 Kokkos::atomic_exchange(&
fView_(0, 0), value);
406 #endif // TEMPUS_CDR_MODEL_FUNCTORS_HPP
typename TpetraVectorType::map_type Map
typename Map::local_map_type LocalMap
KOKKOS_INLINE_FUNCTION void operator()(const LO ne) const
typename Map::local_map_type LocalMap
typename Map::local_map_type LocalMap
typename TpetraVectorType::global_ordinal_type GO
typename TpetraVectorType::dual_view_type DV
typename DV::t_dev::const_type ConstView
typename DV::t_dev::const_type ConstView
KOKKOS_INLINE_FUNCTION void operator()(const LO i) const
typename TpetraVectorType::dual_view_type DV
const ConstView uDotView_
typename TpetraVectorType::local_ordinal_type LO
DfDp2EvaluatorFunctor(TpetraVectorType &f, const TpetraVectorType &x, const TpetraVectorType &u, const TpetraVectorType &uDot, const int myRank, SC a, SC k)
JacobianEvaluatorFunctor(const TpetraMatrixType &J, const TpetraVectorType &x, const TpetraVectorType &u, const TpetraVectorType &uDot, const int &myRank, const SC a, const SC k, const SC alpha, const SC beta)
const ConstView uDotView_
typename TpetraVectorType::dual_view_type DV
typename TpetraMatrixType::local_matrix_device_type LocalMat
typename TpetraVectorType::impl_scalar_type SC
typename TpetraVectorType::impl_scalar_type SC
KOKKOS_INLINE_FUNCTION void operator()(const LO ne) const
typename TpetraVectorType::local_ordinal_type LO
typename TpetraVectorType::impl_scalar_type SC
const ConstView uDotView_
typename Map::local_map_type LocalMap
typename TpetraVectorType::map_type Map
PreconditionerEvaluatorFunctor(const TpetraMatrixType &M, const TpetraVectorType &x, const TpetraVectorType &u, const TpetraVectorType &uDot, const int &myRank, const SC a, const SC k, const SC alpha, const SC beta)
typename TpetraVectorType::map_type Map
CoordFiller(TpetraVectorType &coords, const SC zMin, const SC dx, const GO minGI)
typename DV::t_dev::const_type ConstView
typename TpetraVectorType::local_ordinal_type LO
typename TpetraVectorType::local_ordinal_type LO
typename TpetraVectorType::dual_view_type DV
KOKKOS_INLINE_FUNCTION void operator()(const LO ne) const
typename TpetraMatrixType::local_matrix_device_type LocalMat
typename TpetraVectorType::map_type Map
typename TpetraVectorType::impl_scalar_type SC
KOKKOS_INLINE_FUNCTION void computeBasis(LO gp, Scalar *z, Scalar *u, Scalar *u_dot)