Skip to content

Commit

Permalink
TestSymmetries: Beautify code
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnett committed Oct 30, 2024
1 parent 8e80691 commit 4735fab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
2 changes: 2 additions & 0 deletions TestSymmetries/configuration.ccl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Configuration definitions for thorn TestSymmetries

REQUIRES Arith
REQUIRES CarpetX
REQUIRES Loop
1 change: 1 addition & 0 deletions TestSymmetries/interface.ccl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
IMPLEMENTS: TestSymmetries

USES INCLUDE HEADER: loop_device.hxx
USES INCLUDE HEADER: vect.hxx

CCTK_REAL var_vvv_ppp TYPE=gf CENTERING={vvv} TAGS="parities={+1 +1 +1}" "var_vvv_ppp"
CCTK_REAL var_vvc_ppp TYPE=gf CENTERING={vvc} TAGS="parities={+1 +1 +1}" "var_vvc_ppp"
Expand Down
35 changes: 19 additions & 16 deletions TestSymmetries/src/init.cxx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
#include <loop_device.hxx>

#include <vect.hxx>

#include <cctk.h>
#include <cctk_Arguments.h>
#include <cctk_Parameters.h>

#include <array>
#include <cassert>
#include <cmath>
#include <limits>
#include <string>

namespace TestSymmetries {

using Arith::vect;

bool get_parameter(const std::string &name, const std::string &thorn) {
int type;
const void *const ptr = CCTK_ParameterGet(name.c_str(), thorn.c_str(), &type);
Expand All @@ -23,21 +26,21 @@ bool get_parameter(const std::string &name, const std::string &thorn) {

template <int CI, int CJ, int CK, Loop::where_t where, typename F>
void map_centering_parity(const cGH *restrict const cctkGH,
const std::array<int, 3> &parity, const F &f) {
const vect<int, 3> &parity, const F &f) {
DECLARE_CCTK_ARGUMENTS;
DECLARE_CCTK_PARAMETERS;

const std::array<bool, 3> periodic{
const vect<bool, 3> periodic{
get_parameter("periodic_x", "CarpetX"),
get_parameter("periodic_y", "CarpetX"),
get_parameter("periodic_z", "CarpetX"),
};
const std::array<bool, 3> reflection_lower{
const vect<bool, 3> reflection_lower{
get_parameter("reflection_x", "CarpetX"),
get_parameter("reflection_y", "CarpetX"),
get_parameter("reflection_z", "CarpetX"),
};
const std::array<bool, 3> reflection_upper{
const vect<bool, 3> reflection_upper{
get_parameter("reflection_upper_x", "CarpetX"),
get_parameter("reflection_upper_y", "CarpetX"),
get_parameter("reflection_upper_z", "CarpetX"),
Expand All @@ -46,7 +49,7 @@ void map_centering_parity(const cGH *restrict const cctkGH,
// We assume the domain is [-1; +1]

const auto makevalue =
[=] CCTK_DEVICE CCTK_HOST(const std::array<CCTK_REAL, Loop::dim> &x)
[=] CCTK_DEVICE CCTK_HOST(const vect<CCTK_REAL, Loop::dim> &x)
CCTK_ATTRIBUTE_ALWAYS_INLINE {
using std::acos, std::cos, std::sin;
const CCTK_REAL pi = acos(CCTK_REAL(-1));
Expand Down Expand Up @@ -89,9 +92,9 @@ void map_centering_parity(const cGH *restrict const cctkGH,
for (int k = -3; k <= 3; ++k) {
for (int j = -3; j <= 3; ++j) {
for (int i = -3; i <= 3; ++i) {
const std::array<CCTK_REAL, 3> x{
CCTK_REAL(0.5) * i, CCTK_REAL(0.5) * j, CCTK_REAL(0.5) * k};
std::array<CCTK_REAL, 3> x0 = x;
const vect<CCTK_REAL, 3> x{CCTK_REAL(0.5) * i, CCTK_REAL(0.5) * j,
CCTK_REAL(0.5) * k};
vect<CCTK_REAL, 3> x0 = x;
CCTK_REAL f = makevalue(x);
// map f back into the domain
for (int d = 0; d < 3; ++d) {
Expand Down Expand Up @@ -129,15 +132,15 @@ void map_centering_parity(const cGH *restrict const cctkGH,
10 * std::numeric_limits<CCTK_REAL>::epsilon());
}
} // for i
} // for j
} // for k
} // for j
} // for k
// Test that the function is not just zero
for (int k = -5; k <= 5; ++k) {
for (int j = -5; j <= 5; ++j) {
for (int i = -5; i <= 5; ++i) {
if (abs(i) >= 3 && abs(j) >= 3 && abs(k) >= 3) {
const std::array<CCTK_REAL, 3> x{
CCTK_REAL(0.25) * i, CCTK_REAL(0.25) * j, CCTK_REAL(0.25) * k};
const vect<CCTK_REAL, 3> x{CCTK_REAL(0.25) * i, CCTK_REAL(0.25) * j,
CCTK_REAL(0.25) * k};
const CCTK_REAL f = makevalue(x);
const bool want_zero =
(parity[0] < 0 && reflection_lower[0] && i == -4) ||
Expand All @@ -160,9 +163,9 @@ void map_centering_parity(const cGH *restrict const cctkGH,
}
}

constexpr std::array<int, Loop::dim> centering{CI, CJ, CK};
constexpr vect<int, Loop::dim> centering{CI, CJ, CK};
const Loop::GF3D2layout layout(cctkGH, centering);
const std::array<std::array<CCTK_REAL *, 8>, 2> gfptrs{{
const vect<vect<CCTK_REAL *, 8>, 2> gfptrs{{
{{
var_vvv_mmm,
var_vvc_mmm,
Expand Down Expand Up @@ -202,7 +205,7 @@ void map_centering_all_parities(const cGH *restrict const cctkGH, const F &f) {
for (int pk = -1; pk <= +1; pk += 2) {
for (int pj = -1; pj <= +1; pj += 2) {
for (int pi = -1; pi <= +1; pi += 2) {
const std::array<int, 3> parity{pi, pj, pk};
const vect<int, 3> parity{pi, pj, pk};

// Other parities are not (yet?) implemented and tested
if (!((pi < 0 && pj < 0 && pk < 0) || (pi > 0 && pj > 0 && pk > 0)))
Expand Down

0 comments on commit 4735fab

Please sign in to comment.