8#include <Kokkos_Core.hpp>
11inline T sum(
T* array,
int size)
14 for (
int i(0); i < size; ++i) {
20template <
class ElementType,
class LayoutPolicy,
class AccessorPolicy, std::
size_t Ext>
21inline ElementType sum(Kokkos::mdspan<
23 Kokkos::extents<std::size_t, Ext>,
25 AccessorPolicy>
const& array)
28 for (std::size_t i(0); i < array.extent(0); ++i) {
34template <
class ElementType,
class LayoutPolicy,
class AccessorPolicy, std::
size_t Ext>
35inline ElementType sum(
38 Kokkos::extents<std::size_t, Ext>,
40 AccessorPolicy>
const& array,
45 for (
int i(start); i < end; ++i) {
52inline T modulo(
T x,
T y)
54 return x - y * std::floor(
double(x) / y);
57constexpr inline double ipow(
double a, std::size_t i)
60 for (std::size_t j(0); j < i; ++j) {
66inline double ipow(
double a,
int i)
70 for (
int j(0); j < i; ++j) {
74 for (
int j(0); j < -i; ++j) {
82inline std::size_t factorial(std::size_t f)
85 for (std::size_t i(2); i < f + 1; ++i) {
91template <
class T, std::
size_t D>
92inline T dot_product(std::array<T, D>
const& a, std::array<T, D>
const& b)
95 for (std::size_t i(0); i < D; ++i) {
96 result += a[i] * b[i];
102inline T min(
T x,
T y)
104 return x < y ? x : y;
108inline T max(
T x,
T y)
110 return x > y ? x : y;
113template <std::
size_t N, std::
size_t M, std::
size_t P>
114KOKKOS_INLINE_FUNCTION std::array<std::array<double, N>, P> mat_mul(
115 std::array<std::array<double, N>, M>
const& a,
116 std::array<std::array<double, M>, P>
const& b)
118 std::array<std::array<double, N>, P> result;
119 for (std::size_t i(0); i < N; ++i) {
120 for (std::size_t j(0); j < P; ++j) {
122 for (std::size_t k(0); k < M; ++k) {
123 result[i][j] += a[i][k] * b[k][j];
130template <std::
size_t N, std::
size_t M>
131KOKKOS_INLINE_FUNCTION std::array<double, N> mat_vec_mul(
132 std::array<std::array<double, N>, M>
const& a,
133 std::array<double, M>
const& b)
135 std::array<double, N> result;
136 for (std::size_t i(0); i < N; ++i) {
138 for (std::size_t k(0); k < M; ++k) {
139 result[i] += a[i][k] * b[k];
145KOKKOS_INLINE_FUNCTION
double determinant(std::array<std::array<double, 2>, 2> arr)
147 return arr[0][0] * arr[1][1] - arr[0][1] * arr[1][0];
150KOKKOS_INLINE_FUNCTION std::array<std::array<double, 2>, 2> inverse(
151 std::array<std::array<double, 2>, 2> arr)
153 std::array<std::array<double, 2>, 2> inv;
154 double det = determinant(arr);
155 inv[0][0] = arr[1][1] / det;
156 inv[1][0] = -arr[1][0] / det;
157 inv[0][1] = -arr[0][1] / det;
158 inv[1][1] = arr[0][0] / det;
A class which describes the real space in the temporal direction.
Definition geometry.hpp:44