1 #ifndef TEMPUS_CDR_MODEL_FUNCTORS_HPP
2 #define TEMPUS_CDR_MODEL_FUNCTORS_HPP
4 #include "Kokkos_Core.hpp"
5 #include "Tpetra_Details_OrdinalTraits.hpp"
7 namespace Tempus_Test {
9 template <
class TpetraVectorType>
11 using SC =
typename TpetraVectorType::impl_scalar_type;
12 using LO =
typename TpetraVectorType::local_ordinal_type;
13 using GO =
typename TpetraVectorType::global_ordinal_type;
14 using Map =
typename TpetraVectorType::map_type;
16 using DV =
typename TpetraVectorType::dual_view_type;
17 using View =
typename DV::t_dev;
26 :
coordsView_(coords.getLocalViewDevice(Tpetra::Access::ReadWrite)),
33 KOKKOS_INLINE_FUNCTION
40 template <
class Scalar,
class LO>
44 KOKKOS_INLINE_FUNCTION
48 eta = -1.0 / sqrt(3.0);
52 eta = 1.0 / sqrt(3.0);
57 phi[0] = (1.0 -
eta) / 2.0;
58 phi[1] = (1.0 +
eta) / 2.0;
63 dz = 0.5 * (z[1] - z[0]);
70 for (LO i = 0; i < 2; i++) {
74 uu_dot += u_dot[i] * phi[i];
75 duu_dot += u_dot[i] * dphide[i];
97 template <
class TpetraVectorType,
class TpetraMatrixType>
99 using SC =
typename TpetraVectorType::impl_scalar_type;
100 using LO =
typename TpetraVectorType::local_ordinal_type;
101 using Map =
typename TpetraVectorType::map_type;
103 using DV =
typename TpetraVectorType::dual_view_type;
105 using LocalMat =
typename TpetraMatrixType::local_matrix_device_type;
120 const TpetraVectorType &u,
121 const TpetraVectorType &uDot,
const int &myRank,
122 const SC a,
const SC k,
const SC alpha,
124 :
jLocal_(J.getLocalMatrixDevice()),
125 xView_(x.getLocalViewDevice(Tpetra::Access::ReadOnly)),
126 uView_(u.getLocalViewDevice(Tpetra::Access::ReadOnly)),
127 uDotView_(uDot.getLocalViewDevice(Tpetra::Access::ReadOnly)),
128 rowMap_(J.getRowMap()->getLocalMap()),
129 colMap_(J.getColMap()->getLocalMap()),
139 KOKKOS_INLINE_FUNCTION
142 const auto invalid = Tpetra::Details::OrdinalTraits<LO>::invalid();
146 xx[1] =
xView_(ne + 1, 0);
150 uu[1] =
uView_(ne + 1, 0);
158 for (
LO gp = 0; gp < 2; ++gp) {
163 for (
LO i = 0; i < 2; ++i) {
167 if (localRow != invalid) {
169 for (
LO j = 0; j < 2; ++j) {
170 const auto localColumn = ne + j;
172 basis.
wt * basis.
dz *
176 + (1.0 / (basis.
dz * basis.
dz)) * basis.
dphide[j] *
178 + 2.0 *
k_ * basis.
uu * basis.
phi[j] *
182 jLocal_.sumIntoValues(localRow, &localColumn, 1, &jac,
false,
true);
188 if ((
myRank_ == 0) && (ne == 0)) {
192 jLocal_.replaceValues(row, &col, 1, &val);
196 jLocal_.replaceValues(row, &col, 1, &val);
204 template <
class TpetraVectorType,
class TpetraMatrixType>
206 using SC =
typename TpetraVectorType::impl_scalar_type;
207 using LO =
typename TpetraVectorType::local_ordinal_type;
208 using Map =
typename TpetraVectorType::map_type;
210 using DV =
typename TpetraVectorType::dual_view_type;
212 using LocalMat =
typename TpetraMatrixType::local_matrix_device_type;
227 const TpetraVectorType &x,
228 const TpetraVectorType &u,
229 const TpetraVectorType &uDot,
230 const int &myRank,
const SC a,
const SC k,
231 const SC alpha,
const SC beta)
232 :
mLocal_(M.getLocalMatrixDevice()),
233 xView_(x.getLocalViewDevice(Tpetra::Access::ReadOnly)),
234 uView_(u.getLocalViewDevice(Tpetra::Access::ReadOnly)),
235 uDotView_(uDot.getLocalViewDevice(Tpetra::Access::ReadOnly)),
236 rowMap_(M.getRowMap()->getLocalMap()),
237 colMap_(M.getColMap()->getLocalMap()),
247 KOKKOS_INLINE_FUNCTION
250 const auto invalid = Tpetra::Details::OrdinalTraits<LO>::invalid();
254 xx[1] =
xView_(ne + 1, 0);
258 uu[1] =
uView_(ne + 1, 0);
267 for (
LO gp = 0; gp < 2; ++gp) {
272 for (
LO i = 0; i < 2; ++i) {
277 if (localRow != invalid) {
278 for (
LO j = 0; j < 2; ++j) {
279 const auto localColumn = ne + j;
280 if (
rowMap_.getGlobalElement(localRow) ==
281 colMap_.getGlobalElement(localColumn)) {
282 auto value = basis.
wt * basis.
dz *
286 + (1.0 / (basis.
dz * basis.
dz)) *
289 + 2.0 *
k_ * basis.
uu * basis.
phi[j] *
292 mLocal_.sumIntoValues(localRow, &localColumn, 1, &value);
300 if ((
myRank_ == 0) && (ne == 0)) {
304 mLocal_.replaceValues(row, &column, 1, &value);
311 template <
class TpetraVectorType>
313 using SC =
typename TpetraVectorType::impl_scalar_type;
314 using LO =
typename TpetraVectorType::local_ordinal_type;
315 using Map =
typename TpetraVectorType::map_type;
317 using DV =
typename TpetraVectorType::dual_view_type;
318 using View =
typename DV::t_dev;
332 const TpetraVectorType &u,
const TpetraVectorType &uDot,
333 const int myRank,
SC a,
SC k)
334 :
fView_(f.getLocalViewDevice(Tpetra::Access::ReadWrite)),
335 xView_(x.getLocalViewDevice(Tpetra::Access::ReadOnly)),
336 uView_(u.getLocalViewDevice(Tpetra::Access::ReadOnly)),
337 uDotView_(uDot.getLocalViewDevice(Tpetra::Access::ReadOnly)),
338 rowMap_(f.getMap()->getLocalMap()),
339 colMap_(u.getMap()->getLocalMap()),
347 KOKKOS_INLINE_FUNCTION
350 const auto invalid = Tpetra::Details::OrdinalTraits<LO>::invalid();
354 xx[1] =
xView_(ne + 1, 0);
358 uu[1] =
uView_(ne + 1, 0);
366 for (
LO gp = 0; gp < 2; ++gp) {
371 for (
LO i = 0; i < 2; ++i) {
374 if (localRow != invalid) {
376 basis.
wt * basis.
dz *
379 + 1.0 / (basis.
dz * basis.
dz)) *
381 +
k_ * basis.
uu * basis.
uu * basis.
phi[i]);
382 Kokkos::atomic_add(&
fView_(localRow, 0), value);
388 if ((
myRank_ == 0) && (ne == 0)) {
390 Kokkos::atomic_exchange(&
fView_(0, 0), value);
397 #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)