Skip to content

Commit

Permalink
Z4cow: replace index2 with p.I
Browse files Browse the repository at this point in the history
  • Loading branch information
lwJi committed Sep 11, 2024
1 parent 4ca6dbb commit e4615de
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 107 deletions.
3 changes: 0 additions & 3 deletions Z4cow/src/adm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ extern "C" void Z4cow_ADM(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTSX_Z4cow_ADM;
DECLARE_CCTK_PARAMETERS;

const array<int, dim> indextype = {0, 0, 0};
const GF3D2layout layout2(cctkGH, indextype);

// Input Z4c grid functions
const GF3D2<const CCTK_REAL> &gf_W = W;
const smat<GF3D2<const CCTK_REAL>, 3> gf_gamt{gammatxx, gammatxy, gammatxz,
Expand Down
2 changes: 0 additions & 2 deletions Z4cow/src/constraint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ extern "C" void Z4cow_Constraints(CCTK_ARGUMENTS) {
CCTK_DELTA_SPACE(2),
};

const array<int, dim> indextype = {0, 0, 0};
const array<int, dim> nghostzones = {cctk_nghostzones[0], cctk_nghostzones[1],
cctk_nghostzones[2]};
vect<int, dim> imin, imax;
GridDescBase(cctkGH).box_int<0, 0, 0>(nghostzones, imin, imax);
// suffix 2: with ghost zones, suffix 5: without ghost zones
const GF3D2layout layout2(cctkGH, indextype);
const GF3D5layout layout5(imin, imax);

// Input grid functions
Expand Down
20 changes: 8 additions & 12 deletions Z4cow/src/enforce.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ extern "C" void Z4cow_Enforce(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTSX_Z4cow_Enforce;
DECLARE_CCTK_PARAMETERS;

const array<int, dim> indextype = {0, 0, 0};
const GF3D2layout layout1(cctkGH, indextype);

const GF3D2<CCTK_REAL> &gf_W = W;
const GF3D2<CCTK_REAL> &gf_alphaG = alphaG;
const smat<GF3D2<CCTK_REAL>, 3> gf_gammat{gammatxx, gammatxy, gammatxz,
Expand All @@ -41,13 +38,12 @@ extern "C" void Z4cow_Enforce(CCTK_ARGUMENTS) {
grid.loop_int_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index1(layout1, p.I);

// Load
const vreal W_old = gf_W(mask, index1);
const vreal alphaG_old = gf_alphaG(mask, index1);
const smat<vreal, 3> gammat_old = gf_gammat(mask, index1);
const smat<vreal, 3> At_old = gf_At(mask, index1);
const vreal W_old = gf_W(mask, p.I);
const vreal alphaG_old = gf_alphaG(mask, p.I);
const smat<vreal, 3> gammat_old = gf_gammat(mask, p.I);
const smat<vreal, 3> At_old = gf_At(mask, p.I);

// Enforce floors
const vreal W = fmax(vreal(W_floor), W_old);
Expand Down Expand Up @@ -102,10 +98,10 @@ extern "C" void Z4cow_Enforce(CCTK_ARGUMENTS) {
#endif

// Store
gf_W.store(mask, index1, W);
gf_gammat.store(mask, index1, gammat);
gf_At.store(mask, index1, At);
gf_alphaG.store(mask, index1, alphaG);
gf_W.store(mask, p.I, W);
gf_gammat.store(mask, p.I, gammat);
gf_At.store(mask, p.I, At);
gf_alphaG.store(mask, p.I, alphaG);
});
#ifdef __CUDACC__
nvtxRangeEnd(range);
Expand Down
26 changes: 11 additions & 15 deletions Z4cow/src/initial1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ using namespace Loop;
extern "C" void Z4cow_Initial1(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTSX_Z4cow_Initial1;

const array<int, dim> indextype = {0, 0, 0};
const GF3D2layout layout1(cctkGH, indextype);

// Input grid functions
const smat<GF3D2<const CCTK_REAL>, 3> gf_g1{gxx, gxy, gxz, gyy, gyz, gzz};
const smat<GF3D2<const CCTK_REAL>, 3> gf_K1{kxx, kxy, kxz, kyy, kyz, kzz};
Expand All @@ -48,13 +45,12 @@ extern "C" void Z4cow_Initial1(CCTK_ARGUMENTS) {
grid.loop_int_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index1(layout1, p.I);

// Load (initilize those masked grid with more reasonable value)
const smat<vreal, 3> g = gf_g1(mask, index1, one<smat<int, 3>>()());
const smat<vreal, 3> K = gf_K1(mask, index1);
const vreal alp = gf_alp1(mask, index1, 1);
const vec<vreal, 3> beta = gf_beta1(mask, index1);
const smat<vreal, 3> g = gf_g1(mask, p.I, one<smat<int, 3>>()());
const smat<vreal, 3> K = gf_K1(mask, p.I);
const vreal alp = gf_alp1(mask, p.I, 1);
const vec<vreal, 3> beta = gf_beta1(mask, p.I);

// Calculate Z4c variables (all except Gammat)
const vreal detg = calc_det(g);
Expand All @@ -74,13 +70,13 @@ extern "C" void Z4cow_Initial1(CCTK_ARGUMENTS) {
const vec<vreal, 3> betaG([&](int a) ARITH_INLINE { return beta(a); });

// Store
gf_W1.store(mask, index1, W);
gf_gammat1.store(mask, index1, gammat);
gf_Kh1.store(mask, index1, Kh);
gf_At1.store(mask, index1, At);
gf_Theta1.store(mask, index1, Theta);
gf_alphaG1.store(mask, index1, alphaG);
gf_betaG1.store(mask, index1, betaG);
gf_W1.store(mask, p.I, W);
gf_gammat1.store(mask, p.I, gammat);
gf_Kh1.store(mask, p.I, Kh);
gf_At1.store(mask, p.I, At);
gf_Theta1.store(mask, p.I, Theta);
gf_alphaG1.store(mask, p.I, alphaG);
gf_betaG1.store(mask, p.I, betaG);
});
#ifdef __CUDACC__
nvtxRangeEnd(range);
Expand Down
8 changes: 2 additions & 6 deletions Z4cow/src/initial2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ extern "C" void Z4cow_Initial2(CCTK_ARGUMENTS) {
CCTK_DELTA_SPACE(2),
};

const array<int, dim> indextype = {0, 0, 0};
const GF3D2layout layout1(cctkGH, indextype);

// Input grid functions
const smat<GF3D2<const CCTK_REAL>, 3> gf_gammat1{
gammatxx, gammatxy, gammatxz, gammatyy, gammatyz, gammatzz};
Expand Down Expand Up @@ -87,10 +84,9 @@ extern "C" void Z4cow_Initial2(CCTK_ARGUMENTS) {
grid.loop_int_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index1(layout1, p.I);

// Load
const smat<vreal, 3> gammat = gf_gammat1(mask, index1);
const smat<vreal, 3> gammat = gf_gammat1(mask, p.I);

// Calculate Z4c variables (only Gamt)
const smat<vreal, 3> gammatu = calc_inv(gammat, vreal(1));
Expand All @@ -108,7 +104,7 @@ extern "C" void Z4cow_Initial2(CCTK_ARGUMENTS) {
});

// Store
gf_Gamt1.store(mask, index1, Gamt);
gf_Gamt1.store(mask, p.I, Gamt);
});
#ifdef __CUDACC__
nvtxRangeEnd(range);
Expand Down
2 changes: 0 additions & 2 deletions Z4cow/src/rhs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,11 @@ extern "C" void Z4cow_RHS(CCTK_ARGUMENTS) {
CCTK_DELTA_SPACE(2),
};

const array<int, dim> indextype = {0, 0, 0};
const array<int, dim> nghostzones = {cctk_nghostzones[0], cctk_nghostzones[1],
cctk_nghostzones[2]};
vect<int, dim> imin, imax;
GridDescBase(cctkGH).box_int<0, 0, 0>(nghostzones, imin, imax);
// suffix 2: with ghost zones, suffix 5: without ghost zones
const GF3D2layout layout2(cctkGH, indextype);
const GF3D5layout layout5(imin, imax);

// Input grid functions
Expand Down
47 changes: 23 additions & 24 deletions Z4cow/wolfram/Z4cow_set_ADM.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ const GF3D2<CCTK_REAL> &local_ADMbeta3 = gf_ADMbeta(2);
grid.loop_all_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index2(layout2, p.I);

const auto &tmp_W = gf_W(mask, index2);
const auto &tmp_gamt = gf_gamt(mask, index2);
const auto &tmp_exKh = gf_exKh(mask, index2);
const auto &tmp_exAt = gf_exAt(mask, index2);
const auto &tmp_Theta = gf_Theta(mask, index2);
const auto &tmp_alpha = gf_alpha(mask, index2);
const auto &tmp_beta = gf_beta(mask, index2);
const auto &tmp_W = gf_W(mask, p.I);
const auto &tmp_gamt = gf_gamt(mask, p.I);
const auto &tmp_exKh = gf_exKh(mask, p.I);
const auto &tmp_exAt = gf_exAt(mask, p.I);
const auto &tmp_Theta = gf_Theta(mask, p.I);
const auto &tmp_alpha = gf_alpha(mask, p.I);
const auto &tmp_beta = gf_beta(mask, p.I);

const vreal W = tmp_W;
const vreal gamt11 = tmp_gamt(0,0);
Expand All @@ -54,67 +53,67 @@ const vreal beta1 = tmp_beta(0);
const vreal beta2 = tmp_beta(1);
const vreal beta3 = tmp_beta(2);

local_ADMgam11.store(mask, index2,
local_ADMgam11.store(mask, p.I,
gamt11/Power(W,2)
);

local_ADMgam12.store(mask, index2,
local_ADMgam12.store(mask, p.I,
gamt12/Power(W,2)
);

local_ADMgam13.store(mask, index2,
local_ADMgam13.store(mask, p.I,
gamt13/Power(W,2)
);

local_ADMgam22.store(mask, index2,
local_ADMgam22.store(mask, p.I,
gamt22/Power(W,2)
);

local_ADMgam23.store(mask, index2,
local_ADMgam23.store(mask, p.I,
gamt23/Power(W,2)
);

local_ADMgam33.store(mask, index2,
local_ADMgam33.store(mask, p.I,
gamt33/Power(W,2)
);

local_ADMK11.store(mask, index2,
local_ADMK11.store(mask, p.I,
(exAt11 + (gamt11*(exKh + 2*Theta))/3.)/Power(W,2)
);

local_ADMK12.store(mask, index2,
local_ADMK12.store(mask, p.I,
(exAt12 + (gamt12*(exKh + 2*Theta))/3.)/Power(W,2)
);

local_ADMK13.store(mask, index2,
local_ADMK13.store(mask, p.I,
(exAt13 + (gamt13*(exKh + 2*Theta))/3.)/Power(W,2)
);

local_ADMK22.store(mask, index2,
local_ADMK22.store(mask, p.I,
(exAt22 + (gamt22*(exKh + 2*Theta))/3.)/Power(W,2)
);

local_ADMK23.store(mask, index2,
local_ADMK23.store(mask, p.I,
(exAt23 + (gamt23*(exKh + 2*Theta))/3.)/Power(W,2)
);

local_ADMK33.store(mask, index2,
local_ADMK33.store(mask, p.I,
(exAt33 + (gamt33*(exKh + 2*Theta))/3.)/Power(W,2)
);

local_ADMalpha.store(mask, index2,
local_ADMalpha.store(mask, p.I,
alpha
);

local_ADMbeta1.store(mask, index2,
local_ADMbeta1.store(mask, p.I,
beta1
);

local_ADMbeta2.store(mask, index2,
local_ADMbeta2.store(mask, p.I,
beta2
);

local_ADMbeta3.store(mask, index2,
local_ADMbeta3.store(mask, p.I,
beta3
);

Expand Down
3 changes: 1 addition & 2 deletions Z4cow/wolfram/Z4cow_set_ADM.wl
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ $MainPrint[] :=
pr["grid.loop_all_device<0, 0, 0, vsize>("];
pr[" grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {"];
pr[" const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);"];
pr[" const GF3D2index index2(layout2, p.I);"];
pr[];

PrintListInitializations[Drop[EvolVarlist, {5}], "gf_", "index2"];
PrintListInitializations[Drop[EvolVarlist, {5}], "gf_", "p.I"];
pr[];

PrintInitializations[{Mode -> "MainIn"}, Drop[EvolVarlist, {5}]];
Expand Down
21 changes: 10 additions & 11 deletions Z4cow/wolfram/Z4cow_set_constraint.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ noinline([&]() __attribute__((__flatten__, __hot__)) {
grid.loop_int_device<0, 0, 0, vsize>(
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);
const GF3D2index index2(layout2, p.I);
const GF3D5index index5(layout5, p.I);

const auto &tmp_eTtt = gf_eTtt(mask, index2);
const auto &tmp_eTt = gf_eTt(mask, index2);
const auto &tmp_eT = gf_eT(mask, index2);
const auto &tmp_eTtt = gf_eTtt(mask, p.I);
const auto &tmp_eTt = gf_eTt(mask, p.I);
const auto &tmp_eT = gf_eT(mask, p.I);
const auto &tmp_W = tl_W(mask, index5);
const auto &tmp_gamt = tl_gamt(mask, index5);
const auto &tmp_exKh = tl_exKh(mask, index5);
Expand Down Expand Up @@ -980,25 +979,25 @@ vreal trdexAtUU3
;


local_ZtC1.store(mask, index2,
local_ZtC1.store(mask, p.I,
(trGt1 - trGtd1)/2.
);

local_ZtC2.store(mask, index2,
local_ZtC2.store(mask, p.I,
(trGt2 - trGtd2)/2.
);

local_ZtC3.store(mask, index2,
local_ZtC3.store(mask, p.I,
(trGt3 - trGtd3)/2.
);

local_HC.store(mask, index2,
local_HC.store(mask, p.I,
exAt11*exAtUU11 + 2*exAt12*exAtUU12 + 2*exAt13*exAtUU13 + exAt22*exAtUU22 +
2*exAt23*exAtUU23 + exAt33*exAtUU33 - (2*Power(exKh,2))/3. - 16*cpi*rho -
(8*exKh*Theta)/3. - (8*Power(Theta,2))/3. + trR
);

local_MtC1.store(mask, index2,
local_MtC1.store(mask, p.I,
(-4*dlnW1*exAtUU11 - 4*dlnW2*exAtUU12 - 4*dlnW3*exAtUU13 +
3*exAtUU11*Gt111 + 6*exAtUU12*Gt112 + 6*exAtUU13*Gt113 +
3*exAtUU22*Gt122 + 6*exAtUU23*Gt123 + 3*exAtUU33*Gt133 -
Expand All @@ -1008,7 +1007,7 @@ local_MtC1.store(mask, index2,
3*trdexAtUU1)/3.
);

local_MtC2.store(mask, index2,
local_MtC2.store(mask, p.I,
(-4*dlnW1*exAtUU12 - 4*dlnW2*exAtUU22 - 4*dlnW3*exAtUU23 +
3*exAtUU11*Gt211 + 6*exAtUU12*Gt212 + 6*exAtUU13*Gt213 +
3*exAtUU22*Gt222 + 6*exAtUU23*Gt223 + 3*exAtUU33*Gt233 -
Expand All @@ -1018,7 +1017,7 @@ local_MtC2.store(mask, index2,
3*trdexAtUU2)/3.
);

local_MtC3.store(mask, index2,
local_MtC3.store(mask, p.I,
(-4*dlnW1*exAtUU13 - 4*dlnW2*exAtUU23 - 4*dlnW3*exAtUU33 +
3*exAtUU11*Gt311 + 6*exAtUU12*Gt312 + 6*exAtUU13*Gt313 +
3*exAtUU22*Gt322 + 6*exAtUU23*Gt323 + 3*exAtUU33*Gt333 -
Expand Down
3 changes: 1 addition & 2 deletions Z4cow/wolfram/Z4cow_set_constraint.wl
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ $MainPrint[] :=
pr[" grid.loop_int_device<0, 0, 0, vsize>("];
pr[" grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {"];
pr[" const vbool mask = mask_for_loop_tail<vbool>(p.i, p.imax);"];
pr[" const GF3D2index index2(layout2, p.I);"];
pr[" const GF3D5index index5(layout5, p.I);"];
pr[];

PrintListInitializations[TmunuVarlist, "gf_", "index2"];
PrintListInitializations[TmunuVarlist, "gf_", "p.I"];
PrintListInitializations[EvolVarlist, "tl_", "index5"];
PrintListInitializations[Drop[dEvolVarlist, -2], "tl_", "index5"];
PrintListInitializations[Drop[ddEvolVarlist, -2], "tl_", "index5"];
Expand Down
Loading

0 comments on commit e4615de

Please sign in to comment.