|
| 1 | +#include <cctk.h> |
| 2 | +#include <cctk_Arguments.h> |
| 3 | +#include <cctk_Parameters.h> |
| 4 | + |
| 5 | +#ifdef __CUDACC__ |
| 6 | +// Disable CCTK_DEBUG since the debug information takes too much |
| 7 | +// parameter space to launch the kernels |
| 8 | +#ifdef CCTK_DEBUG |
| 9 | +#undef CCTK_DEBUG |
| 10 | +#endif |
| 11 | +#endif |
| 12 | + |
| 13 | +#include <derivs.hxx> |
| 14 | +#include <loop_device.hxx> |
| 15 | +#include <simd.hxx> |
| 16 | + |
| 17 | +#ifdef __CUDACC__ |
| 18 | +#include <nvtx3/nvToolsExt.h> |
| 19 | +#endif |
| 20 | + |
| 21 | +#include <cmath> |
| 22 | + |
| 23 | +namespace ADMconstraints { |
| 24 | +using namespace Arith; |
| 25 | +using namespace Loop; |
| 26 | + |
| 27 | +template <typename T> |
| 28 | +CCTK_DEVICE CCTK_HOST CCTK_ATTRIBUTE_ALWAYS_INLINE inline T Power(T x, int y) { |
| 29 | + return (y == 2) ? Arith::pow2(x) : Arith::pown(x, y); |
| 30 | +} |
| 31 | + |
| 32 | +extern "C" void ADMconstraints_Sync(CCTK_ARGUMENTS) { |
| 33 | + // do nothing |
| 34 | +} |
| 35 | + |
| 36 | +extern "C" void ADMconstraints_CalcConstraints(CCTK_ARGUMENTS) { |
| 37 | + DECLARE_CCTK_ARGUMENTSX_ADMconstraints_CalcConstraints; |
| 38 | + DECLARE_CCTK_PARAMETERS; |
| 39 | + |
| 40 | + for (int d = 0; d < 3; ++d) |
| 41 | + if (cctk_nghostzones[d] < deriv_order / 2) |
| 42 | + CCTK_VERROR("Need at least %d ghost zones", deriv_order / 2); |
| 43 | + |
| 44 | + const vect<CCTK_REAL, dim> dx{ |
| 45 | + CCTK_DELTA_SPACE(0), |
| 46 | + CCTK_DELTA_SPACE(1), |
| 47 | + CCTK_DELTA_SPACE(2), |
| 48 | + }; |
| 49 | + |
| 50 | + const array<int, dim> indextype = {0, 0, 0}; |
| 51 | + const array<int, dim> nghostzones = {cctk_nghostzones[0], cctk_nghostzones[1], |
| 52 | + cctk_nghostzones[2]}; |
| 53 | + vect<int, dim> imin, imax; |
| 54 | + GridDescBase(cctkGH).box_int<0, 0, 0>(nghostzones, imin, imax); |
| 55 | + // suffix 2: with ghost zones, suffix 5: without ghost zones |
| 56 | + const GF3D2layout layout2(cctkGH, indextype); |
| 57 | + const GF3D5layout layout5(imin, imax); |
| 58 | + |
| 59 | + // Input grid functions |
| 60 | + const smat<GF3D2<const CCTK_REAL>, 3> gf_gam{gxx, gxy, gxz, gyy, gyz, gzz}; |
| 61 | + const smat<GF3D2<const CCTK_REAL>, 3> gf_exK{kxx, kxy, kxz, kyy, kyz, kzz}; |
| 62 | + const GF3D2<const CCTK_REAL> &gf_alpha = alp; |
| 63 | + const vec<GF3D2<const CCTK_REAL>, 3> gf_beta{betax, betay, betaz}; |
| 64 | + |
| 65 | + // More input grid functions |
| 66 | + const GF3D2<const CCTK_REAL> &gf_eTtt = eTtt; |
| 67 | + const vec<GF3D2<const CCTK_REAL>, 3> gf_eTt{eTtx, eTty, eTtz}; |
| 68 | + const smat<GF3D2<const CCTK_REAL>, 3> gf_eT{eTxx, eTxy, eTxz, |
| 69 | + eTyy, eTyz, eTzz}; |
| 70 | + |
| 71 | + // Output grid functions |
| 72 | + const GF3D2<CCTK_REAL> &gf_HC = HC; |
| 73 | + const vec<GF3D2<CCTK_REAL>, 3> gf_MC{MCx, MCy, MCz}; |
| 74 | + |
| 75 | + // Define derivs lambdas |
| 76 | + const auto calccopy = [&](const auto &gf, const auto &gf0) { |
| 77 | + Derivs::calc_copy<0, 0, 0>(gf, layout5, grid, gf0); |
| 78 | + }; |
| 79 | + const auto calcderivs = [&](const auto &gf, const auto &dgf, |
| 80 | + const auto &gf0) { |
| 81 | + Derivs::calc_derivs<0, 0, 0>(gf, dgf, layout5, grid, gf0, dx, deriv_order); |
| 82 | + }; |
| 83 | + const auto calcderivs2 = [&](const auto &gf, const auto &dgf, |
| 84 | + const auto &ddgf, const auto &gf0) { |
| 85 | + Derivs::calc_derivs2<0, 0, 0>(gf, dgf, ddgf, layout5, grid, gf0, dx, |
| 86 | + deriv_order); |
| 87 | + }; |
| 88 | + |
| 89 | + // Tile variables for derivatives and so on |
| 90 | + const int ntmps = 88; |
| 91 | + GF3D5vector<CCTK_REAL> tmps(layout5, ntmps); |
| 92 | + int itmp = 0; |
| 93 | + |
| 94 | + const auto make_gf = [&]() { return GF3D5<CCTK_REAL>(tmps(itmp++)); }; |
| 95 | + const auto make_vec = [&](const auto &f) { |
| 96 | + return vec<result_of_t<decltype(f)()>, 3>([&](int) { return f(); }); |
| 97 | + }; |
| 98 | + const auto make_mat = [&](const auto &f) { |
| 99 | + return smat<result_of_t<decltype(f)()>, 3>([&](int, int) { return f(); }); |
| 100 | + }; |
| 101 | + const auto make_vec_gf = [&]() { return make_vec(make_gf); }; |
| 102 | + const auto make_mat_gf = [&]() { return make_mat(make_gf); }; |
| 103 | + const auto make_mat_vec_gf = [&]() { return make_mat(make_vec_gf); }; |
| 104 | + const auto make_mat_mat_gf = [&]() { return make_mat(make_mat_gf); }; |
| 105 | + |
| 106 | + const smat<GF3D5<CCTK_REAL>, 3> tl_gam(make_mat_gf()); |
| 107 | + const smat<vec<GF3D5<CCTK_REAL>, 3>, 3> tl_dgam(make_mat_vec_gf()); |
| 108 | + const smat<smat<GF3D5<CCTK_REAL>, 3>, 3> tl_ddgam(make_mat_mat_gf()); |
| 109 | + calcderivs2(tl_gam, tl_dgam, tl_ddgam, gf_gam); |
| 110 | + |
| 111 | + const smat<GF3D5<CCTK_REAL>, 3> tl_exK(make_mat_gf()); |
| 112 | + const smat<vec<GF3D5<CCTK_REAL>, 3>, 3> tl_dexK(make_mat_vec_gf()); |
| 113 | + calcderivs(tl_exK, tl_dexK, gf_exK); |
| 114 | + |
| 115 | + const GF3D5<CCTK_REAL> tl_alpha(make_gf()); |
| 116 | + calccopy(tl_alpha, gf_alpha); |
| 117 | + |
| 118 | + const vec<GF3D5<CCTK_REAL>, 3> tl_beta(make_vec_gf()); |
| 119 | + calccopy(tl_beta, gf_beta); |
| 120 | + |
| 121 | + if (itmp != ntmps) |
| 122 | + CCTK_VERROR("Wrong number of temporary variables: ntmps=%d itmp=%d", ntmps, |
| 123 | + itmp); |
| 124 | + itmp = -1; |
| 125 | + |
| 126 | + // simd types |
| 127 | + typedef simd<CCTK_REAL> vreal; |
| 128 | + typedef simdl<CCTK_REAL> vbool; |
| 129 | + constexpr size_t vsize = tuple_size_v<vreal>; |
| 130 | + |
| 131 | + // parameters |
| 132 | + const CCTK_REAL cpi = M_PI; |
| 133 | + |
| 134 | +#ifdef __CUDACC__ |
| 135 | + const nvtxRangeId_t range = nvtxRangeStartA("ADMconstraints::constraints"); |
| 136 | +#endif |
| 137 | + |
| 138 | +#include "../wolfram/ADM_set_constraint.hxx" |
| 139 | + |
| 140 | +#ifdef __CUDACC__ |
| 141 | + nvtxRangeEnd(range); |
| 142 | +#endif |
| 143 | +} |
| 144 | + |
| 145 | +} // namespace ADMconstraints |
0 commit comments