Skip to content

Commit

Permalink
TestDerivs: beautify test.cxx
Browse files Browse the repository at this point in the history
  • Loading branch information
lwJi committed Oct 28, 2024
1 parent d737ef9 commit 209f9f0
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 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 Down

0 comments on commit 209f9f0

Please sign in to comment.