Skip to content

Commit

Permalink
TestDerivs: beautify interface.ccl and test.cxx
Browse files Browse the repository at this point in the history
  • Loading branch information
lwJi committed Dec 25, 2024
1 parent 8791c63 commit 457a4ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion TestDerivs/interface.ccl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CCTK_REAL chi_diss TYPE=gf CENTERING={VVV} TAGS='checkpoint="no"' "dissipation t
CCTK_REAL beta TYPE=gf CENTERING={VVV}
{
betax, betay, betaz
}"velocity function used for calculating upwind term"
} "velocity function used for calculating upwind term"

CCTK_REAL chi_upwind TYPE=gf CENTERING={VVV} TAGS='checkpoint="no"' "upwind term"

Expand Down
39 changes: 20 additions & 19 deletions TestDerivs/src/test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ template <typename T>
constexpr void poly_derivs(const T kxx, const T kxy, const T kyz, const T x,
const T y, const T z, Arith::vec<T, dim> &du,
Arith::smat<T, dim> &ddu) {
const T sinx = std::sin(x);
const T siny = std::sin(y);
const T sinz = std::sin(z);
const T cosx = std::cos(x);
const T cosy = std::cos(y);
const T cosz = std::cos(z);
using std::sin, std::cos, std::sqrt;
const T sinx = sin(x);
const T siny = sin(y);
const T sinz = sin(z);
const T cosx = cos(x);
const T cosy = cos(y);
const T cosz = cos(z);
du(0) = -2 * kxx * cosx * sinx - kxy * sinx * siny;
du(1) = kxy * cosx * cosy + kyz * cosy * sinz;
du(2) = kyz * cosz * siny;
Expand All @@ -43,21 +44,22 @@ constexpr void poly_derivs(const T kxx, const T kxy, const T kyz, const T x,

template <typename T>
constexpr Arith::vec<T, dim> beta_profile(const T x, const T y, const T z) {
const T vx = 1 * std::sin(x);
const T vy = 2 * std::sin(y);
const T vz = 3 * std::sin(z);
const T norm = std::sqrt(vx * vx + vy * vy + vz * vz);
const T vx = 1 * sin(x);
const T vy = 2 * sin(y);
const T vz = 3 * sin(z);
const T norm = sqrt(vx * vx + vy * vy + vz * vz);
return Arith::vec<T, dim>({vx / norm, vy / norm, vy / norm});
}

template <typename T>
constexpr T poly_diss(const T kxx, const T kxy, const T kyz, const T x,
const T y, const T z, const int diss_order,
const Arith::vect<T, dim> &dx) {
const T sinx = std::sin(x);
const T siny = std::sin(y);
const T sinz = std::sin(z);
const T cosx = std::cos(x);
using std::sin, std::cos, std::fabs;
const T sinx = sin(x);
const T siny = sin(y);
const T sinz = sin(z);
const T cosx = cos(x);
int coeff = 0;

switch (diss_order) {
Expand All @@ -77,7 +79,7 @@ constexpr T poly_diss(const T kxx, const T kxy, const T kyz, const T x,
assert(0);
}

const int abc = std::abs(coeff);
const int abc = fabs(coeff);
const int sig = (abc == coeff) ? 1 : -1;
return sig * ((abc * kxx * cosx * cosx - abc * kxx * sinx * sinx +
kxy * cosx * siny) /
Expand All @@ -104,6 +106,7 @@ extern "C" void TestDerivs_Set(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTSX_TestDerivs_Set;
DECLARE_CCTK_PARAMETERS;

using std::sin;
using vreal = Arith::simd<CCTK_REAL>;
using vbool = Arith::simdl<CCTK_REAL>;
constexpr std::size_t vsize = std::tuple_size_v<vreal>;
Expand All @@ -115,8 +118,7 @@ extern "C" void TestDerivs_Set(CCTK_ARGUMENTS) {
const vreal x0 = p.x + Arith::iota<vreal>() * p.dx;
const CCTK_REAL y0 = p.y;
const CCTK_REAL z0 = p.z;
chi.store(mask, p.I,
poly(kxx, kxy, kyz, cos(x0), std::sin(y0), std::sin(z0)));
chi.store(mask, p.I, poly(kxx, kxy, kyz, cos(x0), sin(y0), sin(z0)));
});

grid.loop_int_device<0, 0, 0>(
Expand Down Expand Up @@ -334,8 +336,7 @@ extern "C" void TestDerivs_CalcError(CCTK_ARGUMENTS) {

const int diss_order = deriv_order + 2;
const CCTK_REAL diss =
Arith::pown(-1, diss_order / 2.0 - 1.0) /
Arith::pown(2, diss_order) *
Arith::pown(-1, diss_order / 2 - 1) / Arith::pown(2, diss_order) *
poly_diss(kxx, kxy, kyz, p.x, p.y, p.z, diss_order, dx);
chi_diss_error(p.I) = diss - chi_diss(p.I);

Expand Down

0 comments on commit 457a4ea

Please sign in to comment.