Skip to content

Commit f149063

Browse files
authored
Add thorn ADMconstraints (#50)
* ADMconstraints: add admconstraints.cxx * ADMconstraints: add ADM_vars.wl * ADMconstraints: add ADM_rhs.wl * ADMconstraints: add type_in_rhs.nb * ADMconstraints: nv type_in_rhs.nb outside wl * ADMconstraints: update type_in_rhs.nb * ADMconstraints: update ADM_vars.wl * ADMconstraints: update type_in_rhs.nb * ADMconstraints: update type_in_rhs.nb * ADMconstraints: update ADM_rhs.wl * ADMconstraints: add check_rhs.ipynb * ADMconstraints: update check_rhs.ipynb * ADMconstraints: add ADM_set_constraint.wl * ADMconstraints: add ADM_set_constraint.hxx * ADMconstraints: add interface.ccl * ADMconstraints: rename MtC to MC * ADMconstraints: add param.ccl * ADMconstraints: update admconstraints.cxx * ADMconstraints: update admconstraints.cxx * ADMconstraints: remove prefix ADM for variables * ADMconstraints: update admconstraints.cxx * ADMconstraints: update admconstraints.cxx * ADMconstraints: add make.code.defn * ADMconstraints: add configuration.ccl * ADMconstraints: add schedule.ccl * ADMconstraints: make it compile * ADMconstraints: format ADM_rhs.wl * ADMconstraints: treat DexK separatedly to remove warnings * ADMconstraints: treat dexK separatedly to remove warnings * ADMconstraints: add lapse mask * ADMconstraints: add extra SYNCs * ADMconstraints: fix comments in schedule * ADMconstraints: add par lapse_mask_outer_radius * ADMconstraints: mask out region which is larger than a radius * ADMconstraints: fix type of default value for lapse_mask_outer_radius * ADMconstraints: use or instead of and when apply mask * ADMconstraints: sync HC and MC after calculation
1 parent 708e1c3 commit f149063

File tree

13 files changed

+3609
-0
lines changed

13 files changed

+3609
-0
lines changed

ADMconstraints/configuration.ccl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Configuration definitions for thorn ADMconstraints
2+
3+
REQUIRES Arith Loop Derivs

ADMconstraints/interface.ccl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Interface definition for thorn ADMconstraints
2+
3+
IMPLEMENTS: ADMconstraints
4+
5+
INHERITS: ADMBaseX TmunuBaseX
6+
7+
USES INCLUDE HEADER: defs.hxx
8+
USES INCLUDE HEADER: derivs.hxx
9+
USES INCLUDE HEADER: div.hxx
10+
USES INCLUDE HEADER: dual.hxx
11+
USES INCLUDE HEADER: loop_device.hxx
12+
USES INCLUDE HEADER: mat.hxx
13+
USES INCLUDE HEADER: simd.hxx
14+
USES INCLUDE HEADER: sum.hxx
15+
USES INCLUDE HEADER: vec.hxx
16+
USES INCLUDE HEADER: vect.hxx
17+
18+
CCTK_REAL HC TYPE=gf TAGS='checkpoint="no"' "H"
19+
20+
CCTK_REAL MC TYPE=gf TAGS='parities={-1 +1 +1 +1 -1 +1 +1 +1 -1} checkpoint="no"' { MCx MCy MCz } "M"

ADMconstraints/param.ccl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Parameter definitions for thorn ADMconstraints
2+
3+
BOOLEAN calc_constraints "Calculate constraints" STEERABLE=recover
4+
{
5+
} yes
6+
7+
CCTK_INT deriv_order "Order of spatial finite differencing" STEERABLE=never
8+
{
9+
2 :: "Second order finite difference"
10+
4 :: "Fourth order finite difference"
11+
6 :: "Sixth order finite difference"
12+
8 :: "Eighth order finite difference"
13+
} 4
14+
15+
BOOLEAN use_lapse_mask "Exclude the region when lapse is small" STEERABLE=recover
16+
{
17+
} yes
18+
19+
CCTK_REAL lapse_mask_cutoff "Exclude the region when lapse is smaller than the cutoff" STEERABLE=always
20+
{
21+
*:* :: ""
22+
} 0.3
23+
24+
CCTK_REAL lapse_mask_outer_radius "Exclude the region when the distance to the origin is larger than the radius" STEERABLE=always
25+
{
26+
*:* :: ""
27+
} 30.0

ADMconstraints/schedule.ccl

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Schedule definitions for thorn ADMconstraints
2+
3+
STORAGE: HC
4+
STORAGE: MC
5+
6+
7+
8+
9+
SCHEDULE GROUP ADMconstraints_AnalysisGroup AT analysis
10+
{
11+
} "Analyse ADM variables"
12+
13+
14+
if (calc_constraints) {
15+
SCHEDULE ADMconstraints_Sync IN ADMconstraints_AnalysisGroup
16+
{
17+
LANG: C
18+
OPTIONS: global
19+
SYNC: ADMBaseX::metric
20+
SYNC: ADMBaseX::curv
21+
SYNC: ADMBaseX::lapse
22+
SYNC: ADMBaseX::shift
23+
} "Synchronize"
24+
25+
SCHEDULE ADMconstraints_CalcConstraints IN ADMconstraints_AnalysisGroup AFTER ADMconstraints_Sync
26+
{
27+
LANG: C
28+
READS: ADMBaseX::metric(everywhere)
29+
READS: ADMBaseX::curv(everywhere)
30+
READS: ADMBaseX::lapse(everywhere)
31+
READS: ADMBaseX::shift(everywhere)
32+
READS: TmunuBaseX::eTtt(interior)
33+
READS: TmunuBaseX::eTti(interior)
34+
READS: TmunuBaseX::eTij(interior)
35+
WRITES: HC(interior)
36+
WRITES: MC(interior)
37+
SYNC: HC MC
38+
} "Calculate ADM Constraints"
39+
40+
if (use_lapse_mask) {
41+
SCHEDULE ADMconstraints_LapseMask IN ADMconstraints_AnalysisGroup AFTER ADMconstraints_CalcConstraints
42+
{
43+
LANG: C
44+
READS: ADMBaseX::lapse(interior)
45+
READS: HC(interior)
46+
READS: MC(interior)
47+
WRITES: HC(interior)
48+
WRITES: MC(interior)
49+
SYNC: HC MC
50+
} "Apply lapse mask"
51+
}
52+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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

ADMconstraints/src/lapsemask.cxx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <loop_device.hxx>
2+
3+
#include <cctk.h>
4+
#include <cctk_Arguments.h>
5+
6+
namespace ADMconstraints {
7+
using namespace Arith;
8+
using namespace Loop;
9+
10+
extern "C" void ADMconstraints_LapseMask(CCTK_ARGUMENTS) {
11+
DECLARE_CCTK_ARGUMENTSX_ADMconstraints_LapseMask;
12+
DECLARE_CCTK_PARAMETERS;
13+
14+
const CCTK_REAL local_cutoff = lapse_mask_cutoff;
15+
const CCTK_REAL local_outer_radius = lapse_mask_outer_radius;
16+
17+
grid.loop_int_device<0, 0, 0>(
18+
grid.nghostzones, [=] ARITH_DEVICE(const PointDesc &p) ARITH_INLINE {
19+
const CCTK_REAL rad = sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
20+
if (alp(p.I) < local_cutoff || rad > local_outer_radius) {
21+
HC(p.I) = 0.0;
22+
MCx(p.I) = 0.0;
23+
MCy(p.I) = 0.0;
24+
MCz(p.I) = 0.0;
25+
}
26+
});
27+
}
28+
29+
} // namespace ADMconstraints

ADMconstraints/src/make.code.defn

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Main make.code.defn file for thorn Z4c
2+
3+
# Source files in this directory
4+
SRCS = \
5+
admconstraints.cxx \
6+
lapsemask.cxx
7+
8+
# Subdirectories containing source files
9+
SUBDIRS =

0 commit comments

Comments
 (0)