Skip to content

Commit dc2a421

Browse files
NewRadX: Relaxed requirements of specific patch system setup
1 parent cc0df57 commit dc2a421

3 files changed

Lines changed: 31 additions & 28 deletions

File tree

NewRadX/param.ccl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
# Parameter definitions for thorn NewRadX
2+
3+
CCTK_BOOLEAN apply_inner_boundary "Apply radiative BC at inner boundary of a multipatch systems, if such boundary exists (e.g. Thornburg06 inner sphere)" STEERABLE=always
4+
{
5+
} "no"

NewRadX/src/newradx.cxx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <cctk.h>
2+
#include <cctk_Parameters.h>
23

34
#include <loop_device.hxx>
45
#include <driver.hxx>
@@ -207,6 +208,7 @@ void NewRadX_Apply(const cGH *restrict const cctkGH,
207208
using namespace CapyrX::MultiPatch::GlobalDerivatives;
208209

209210
DECLARE_CCTK_ARGUMENTS;
211+
DECLARE_CCTK_PARAMETERS;
210212

211213
const auto symmetries = CarpetX::ghext->patchdata.at(cctk_patch).symmetries;
212214
const vect<vect<bool, Loop::dim>, 2> is_sym_bnd{
@@ -221,35 +223,41 @@ void NewRadX_Apply(const cGH *restrict const cctkGH,
221223
grid.loop_outermost_int_device<0, 0, 0>(
222224
grid.nghostzones, is_sym_bnd,
223225
[=] CCTK_DEVICE(const Loop::PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {
224-
// Make sure we are always on the outer boundary of a patch system
225-
assert(p.patch != 0);
226-
assert(p.NI[2] >= 0);
226+
// Skip inner radial boundary unless requested
227+
if (!apply_inner_boundary && p.NI[2] == -1) {
228+
return;
229+
}
230+
231+
// At the outer boundary absorb outgoing waves; at the inner
232+
// boundary absorb incoming waves (flip sign of v0).
233+
const CCTK_REAL sign = (p.NI[2] == -1) ? -1.0 : 1.0;
234+
const auto sv0 = sign * v0;
227235

228236
// Find local wave speeds at radiative boundary point p.I
229237
const auto x = vcoordx(p.I);
230238
const auto y = vcoordy(p.I);
231239
const auto z = vcoordz(p.I);
232240
const auto r = sqrt(pow2(x) + pow2(y) + pow2(z));
233241

234-
const auto vx = v0 * vcoordx(p.I) / r;
235-
const auto vy = v0 * vcoordy(p.I) / r;
236-
const auto vz = v0 * vcoordz(p.I) / r;
242+
const auto vx = sv0 * x / r;
243+
const auto vy = sv0 * y / r;
244+
const auto vz = sv0 * z / r;
237245

238-
// Local derivatives
239-
const LocalFirstDerivatives l_dvar{.da = r2o<0>(p, p.I, var),
240-
.db = r2o<1>(p, p.I, var),
241-
.dc = r2o<2>(p, p.I, var)};
246+
// Local derivatives (stencil auto-selected by boundary location)
247+
const LocalFirstDerivatives l_dvar{.da = calc_deriv<0>(p, var),
248+
.db = calc_deriv<1>(p, var),
249+
.dc = calc_deriv<2>(p, var)};
242250

243251
// Global derivatives
244252
const Jacobians jac{VERTEX_JACOBIANS(p)};
245253
const auto g_dvar{project_first(l_dvar, jac)};
246254

247255
// radiative rhs
248256
rhs(p.I) = -vx * g_dvar.dx - vy * g_dvar.dy - vz * g_dvar.dz -
249-
v0 * (var(p.I) - var0) / r;
257+
sv0 * (var(p.I) - var0) / r;
250258

251259
if (radpower > 0.0) {
252-
// TODO
260+
// TODO: Coulomb correction (port from Cartesian overload)
253261
}
254262
});
255263
}

NewRadX/src/newradx.hxx

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef NEWRADX_HXX
2+
#define NEWRADX_HXX
3+
14
#include <cctk.h>
25
#include <loop_device.hxx>
36

@@ -27,22 +30,8 @@ void NewRadX_Apply(const cGH *restrict const cctkGH,
2730
vJ_db_dz, vJ_dc_dx, vJ_dc_dy, vJ_dc_dz
2831

2932
/**
30-
* @brief Applies radiative boundary condition to the RHS of a state variable.
31-
* Assumes that:
32-
* 1. Using multiple patches
33-
* 2. Patch 0 is cartesian
34-
* 3. Patches != 0 are spherical-like
35-
* 4. The local c coordinate is radial and points outward
36-
*
37-
* @param cctkGH Pointer to Cactus grid hierarchy struct.
38-
* @param var State variable which will have boundary conditions applied to it.
39-
* @param rhs RHS of the evolution equation for @param var
40-
* @param vcoordx x coordinates grid function.
41-
* @param vcoordy y coordinates grid function.
42-
* @param vcoordz z coordinates grid function.
43-
* @param var0 Value at infinity.
44-
* @param v0 Propagation speed.
45-
* @param radpower Radial fall-off exponent
33+
* @brief Applies radiative boundary condition to the RHS of a state variable
34+
* on multipatch grids.
4635
*/
4736
void NewRadX_Apply(const cGH *restrict const cctkGH,
4837
const Loop::GF3D2<const CCTK_REAL> &var,
@@ -63,3 +52,5 @@ void NewRadX_Apply(const cGH *restrict const cctkGH,
6352
const CCTK_REAL radpower);
6453

6554
} // namespace NewRadX
55+
56+
#endif // NEWRADX_HXX

0 commit comments

Comments
 (0)