Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jdolence committed Feb 5, 2025
1 parent 0cb6f0e commit 483395c
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 110 deletions.
5 changes: 3 additions & 2 deletions src/coordinates/uniform_cartesian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ namespace parthenon {
class UniformCartesian : public UniformCoordinates<UniformCartesian> {
public:
UniformCartesian() = default;
UniformCartesian(const RegionSize &rs, ParameterInput *pin)
: UniformCoordinates<UniformCartesian>(rs, pin) {}
UniformCartesian(const RegionSize &rs, ParameterInput *pin)
: UniformCoordinates<UniformCartesian>(rs, pin) {}
UniformCartesian(const UniformCartesian &src, int coarsen)
: UniformCoordinates<UniformCartesian>(src, coarsen) {}

constexpr static const char *name_ = "UniformCartesian";

private:
};

Expand Down
85 changes: 55 additions & 30 deletions src/coordinates/uniform_coordinates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,24 @@ class UniformCoordinates {
template <int dir>
KOKKOS_FORCEINLINE_FUNCTION Real Dxc(const int k, const int j, const int i) const {
static_assert(dir > 0 && dir < 4);
if constexpr (dir == X1DIR) return static_cast<const System *>(this)->template Dxc<dir>(i);
else if constexpr (dir == X2DIR) return static_cast<const System *>(this)->template Dxc<dir>(j);
else if constexpr (dir == X3DIR) return static_cast<const System *>(this)->template Dxc<dir>(k);
if constexpr (dir == X1DIR)
return static_cast<const System *>(this)->template Dxc<dir>(i);
else if constexpr (dir == X2DIR)
return static_cast<const System *>(this)->template Dxc<dir>(j);
else if constexpr (dir == X3DIR)
return static_cast<const System *>(this)->template Dxc<dir>(k);
PARTHENON_FAIL("Unknown dir.");
return 0.0;
}
KOKKOS_FORCEINLINE_FUNCTION Real Dxc(const int dir, const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real Dxc(const int dir, const int k, const int j,
const int i) const {
assert(dir > 0 && dir < 4);
if (dir == X1DIR) return static_cast<const System *>(this)->template Dxc<X1DIR>(k, j, i);
else if (dir == X2DIR) return static_cast<const System *>(this)->template Dxc<X2DIR>(k, j, i);
else if (dir == X3DIR) return static_cast<const System *>(this)->template Dxc<X3DIR>(k, j, i);
if (dir == X1DIR)
return static_cast<const System *>(this)->template Dxc<X1DIR>(k, j, i);
else if (dir == X2DIR)
return static_cast<const System *>(this)->template Dxc<X2DIR>(k, j, i);
else if (dir == X3DIR)
return static_cast<const System *>(this)->template Dxc<X3DIR>(k, j, i);
PARTHENON_FAIL("Unknown dir.");
return 0.0;
}
Expand Down Expand Up @@ -115,9 +122,12 @@ class UniformCoordinates {
template <int dir>
KOKKOS_FORCEINLINE_FUNCTION Real Xc(const int k, const int j, const int i) const {
static_assert(dir > 0 && dir < 4);
if constexpr (dir == X1DIR) return static_cast<const System *>(this)->template Xc<dir>(i);
else if constexpr (dir == X2DIR) return static_cast<const System *>(this)->template Xc<dir>(j);
else if constexpr (dir == X3DIR) return static_cast<const System *>(this)->template Xc<dir>(k);
if constexpr (dir == X1DIR)
return static_cast<const System *>(this)->template Xc<dir>(i);
else if constexpr (dir == X2DIR)
return static_cast<const System *>(this)->template Xc<dir>(j);
else if constexpr (dir == X3DIR)
return static_cast<const System *>(this)->template Xc<dir>(k);
return 0; // To appease compiler
}

Expand Down Expand Up @@ -171,55 +181,67 @@ class UniformCoordinates {
template <int dir, TopologicalElement el>
KOKKOS_FORCEINLINE_FUNCTION Real X(const int k, const int j, const int i) const {
static_assert(dir > 0 && dir < 4);
if constexpr (dir == X1DIR) return X<dir, el>(i);
else if constexpr (dir == X2DIR) return X<dir, el>(j);
else if constexpr (dir == X3DIR) return X<dir, el>(k);
if constexpr (dir == X1DIR)
return X<dir, el>(i);
else if constexpr (dir == X2DIR)
return X<dir, el>(j);
else if constexpr (dir == X3DIR)
return X<dir, el>(k);
return 0.0;
}

template <int dir, TopologicalElement el>
KOKKOS_FORCEINLINE_FUNCTION
Real Scale(const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real Scale(const int k, const int j, const int i) const {
if constexpr (dir > 0 && dir < 4) return 1.0;
PARTHENON_FAIL("Unknown dir");
return 0.0;
}

template <TopologicalElement el>
KOKKOS_FORCEINLINE_FUNCTION
Real Scale(const int dir, const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real Scale(const int dir, const int k, const int j,
const int i) const {
assert(dir > 0 && dir < 4);
if (dir == X1DIR) return static_cast<const System *>(this)->template Scale<X1DIR, el>(k, j, i);
else if (dir == X2DIR) return static_cast<const System *>(this)->template Scale<X2DIR, el>(k, j, i);
else if (dir == X3DIR) return static_cast<const System *>(this)->template Scale<X3DIR, el>(k, j, i);
if (dir == X1DIR)
return static_cast<const System *>(this)->template Scale<X1DIR, el>(k, j, i);
else if (dir == X2DIR)
return static_cast<const System *>(this)->template Scale<X2DIR, el>(k, j, i);
else if (dir == X3DIR)
return static_cast<const System *>(this)->template Scale<X3DIR, el>(k, j, i);
return 0.0;
}

//----------------------------------------
// CellWidth: Width of cells at cell centers
//----------------------------------------
template <int dir>
KOKKOS_FORCEINLINE_FUNCTION Real CellWidth(const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real CellWidth(const int k, const int j,
const int i) const {
assert(dir > 0 && dir < 4);
return dx_[dir - 1];
}
KOKKOS_FORCEINLINE_FUNCTION Real CellWidth(const int dir, const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real CellWidth(const int dir, const int k, const int j,
const int i) const {
assert(dir > 0 && dir < 4);
if (dir == X1DIR) return static_cast<const System *>(this)->template CellWidth<X1DIR>(k, j, i);
else if (dir == X2DIR) return static_cast<const System *>(this)->template CellWidth<X2DIR>(k, j, i);
else if (dir == X3DIR) return static_cast<const System *>(this)->template CellWidth<X3DIR>(k, j, i);
if (dir == X1DIR)
return static_cast<const System *>(this)->template CellWidth<X1DIR>(k, j, i);
else if (dir == X2DIR)
return static_cast<const System *>(this)->template CellWidth<X2DIR>(k, j, i);
else if (dir == X3DIR)
return static_cast<const System *>(this)->template CellWidth<X3DIR>(k, j, i);
return 0.0;
}

//----------------------------------------
// EdgeLength: Length of cell edges
//----------------------------------------
template <int dir>
KOKKOS_FORCEINLINE_FUNCTION Real EdgeLength(const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real EdgeLength(const int k, const int j,
const int i) const {
assert(dir > 0 && dir < 4);
return CellWidth<dir>(k, j, i);
}
KOKKOS_FORCEINLINE_FUNCTION Real EdgeLength(const int dir, const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real EdgeLength(const int dir, const int k, const int j,
const int i) const {
return CellWidth(dir, k, j, i);
}

Expand All @@ -231,9 +253,10 @@ class UniformCoordinates {
static_assert(dir > 0 && dir < 4);
return area_[dir - 1];
}
KOKKOS_FORCEINLINE_FUNCTION Real FaceArea(const int dir, const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real FaceArea(const int dir, const int k, const int j,
const int i) const {
assert(dir > 0 && dir < 4);
switch(dir) {
switch (dir) {
case X1DIR:
return static_cast<const System *>(this)->template FaceArea<X1DIR>(k, j, i);
case X2DIR:
Expand All @@ -249,7 +272,8 @@ class UniformCoordinates {
//----------------------------------------
// CellVolume
//----------------------------------------
KOKKOS_FORCEINLINE_FUNCTION Real CellVolume(const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real CellVolume(const int k, const int j,
const int i) const {
return cell_volume_;
}

Expand Down Expand Up @@ -330,6 +354,7 @@ class UniformCoordinates {
const std::array<Real, 3> &GetXmin() const { return xmin_; }
const std::array<int, 3> &GetStartIndex() const { return istart_; }
const char *Name() const { return System::name_; }

private:
std::array<int, 3> istart_;
std::array<Real, 3> xmin_, dx_, area_;
Expand Down
72 changes: 44 additions & 28 deletions src/coordinates/uniform_cylindrical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
namespace parthenon {

class UniformCylindrical : public UniformCoordinates<UniformCylindrical> {
using base_t = UniformCoordinates<UniformCylindrical>;
using base_t = UniformCoordinates<UniformCylindrical>;

public:
using base_t::CellWidth;
using base_t::Dxc;
using base_t::Xc;
using base_t::Scale;
using base_t::CellWidth;
using base_t::Volume;
using base_t::Xc;
UniformCylindrical() = default;
UniformCylindrical(const RegionSize &rs, ParameterInput *pin)
: UniformCoordinates<UniformCylindrical>(rs, pin) {}
UniformCylindrical(const RegionSize &rs, ParameterInput *pin)
: UniformCoordinates<UniformCylindrical>(rs, pin) {}
UniformCylindrical(const UniformCylindrical &src, int coarsen)
: UniformCoordinates<UniformCylindrical>(src, coarsen) {}
constexpr static const char *name_ = "UniformCylindrical";
Expand All @@ -38,7 +39,7 @@ class UniformCylindrical : public UniformCoordinates<UniformCylindrical> {
template <int dir>
KOKKOS_FORCEINLINE_FUNCTION Real Dxc(const int idx) const {
static_assert(dir > 0 && dir < 4);
return Xc<dir>(idx) - Xc<dir>(idx-1);
return Xc<dir>(idx) - Xc<dir>(idx - 1);
}

//----------------------------------------
Expand All @@ -58,8 +59,7 @@ class UniformCylindrical : public UniformCoordinates<UniformCylindrical> {
}

template <int dir, TopologicalElement el>
KOKKOS_FORCEINLINE_FUNCTION
Real Scale(const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real Scale(const int k, const int j, const int i) const {
static_assert(dir > 0 && dir < 4);
using TE = TopologicalElement;
if constexpr (dir == X1DIR || dir == X2DIR) return 1.0;
Expand All @@ -71,7 +71,8 @@ class UniformCylindrical : public UniformCoordinates<UniformCylindrical> {
// CellWidth: width of cell through the centroid
//----------------------------------------
template <int dir>
KOKKOS_FORCEINLINE_FUNCTION Real CellWidth(const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real CellWidth(const int k, const int j,
const int i) const {
using TE = TopologicalElement;
static_assert(dir > 0 && dir < 4);
if constexpr (dir == X1DIR || dir == X2DIR) return Dx<dir>();
Expand All @@ -83,7 +84,8 @@ class UniformCylindrical : public UniformCoordinates<UniformCylindrical> {
// EdgeLength: Length of cell edges
//----------------------------------------
template <int dir>
KOKKOS_FORCEINLINE_FUNCTION Real EdgeLength(const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real EdgeLength(const int k, const int j,
const int i) const {
static_assert(dir > 0 && dir < 4);
if constexpr (dir == X1DIR || dir == X2DIR) {
// radial and z directions are trivial
Expand All @@ -92,10 +94,13 @@ class UniformCylindrical : public UniformCoordinates<UniformCylindrical> {
// phi direction
return Xf<X1DIR>(k, j, i) * Dx<dir>();
}
KOKKOS_FORCEINLINE_FUNCTION Real EdgeLength(const int dir, const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real EdgeLength(const int dir, const int k, const int j,
const int i) const {
assert(dir > 0 && dir < 4);
if (dir == X1DIR) return EdgeLength<X1DIR>(k, j, i);
else if (dir == X2DIR) return EdgeLength<X2DIR>(k, j, i);
if (dir == X1DIR)
return EdgeLength<X1DIR>(k, j, i);
else if (dir == X2DIR)
return EdgeLength<X2DIR>(k, j, i);
return EdgeLength<X3DIR>(k, j, i);
}

Expand All @@ -109,35 +114,46 @@ class UniformCylindrical : public UniformCoordinates<UniformCylindrical> {
return Xf<X1DIR>(k, j, i) * Dx<X2DIR>() * Dx<X3DIR>();
} else if constexpr (dir == X2DIR) {
Real r0 = Xf<X1DIR>(k, j, i);
Real r1 = Xf<X1DIR>(k, j, i+1);
return 0.5 * (r1*r1 - r0*r0) * Dx<X3DIR>();
Real r1 = Xf<X1DIR>(k, j, i + 1);
return 0.5 * (r1 * r1 - r0 * r0) * Dx<X3DIR>();
}
Real r0 = Xf<X1DIR>(k, j, i);
Real r1 = Xf<X1DIR>(k, j, i+1);
return 0.5 * (r1*r1 - r0*r0) * Dx<X2DIR>();
Real r1 = Xf<X1DIR>(k, j, i + 1);
return 0.5 * (r1 * r1 - r0 * r0) * Dx<X2DIR>();
}

//----------------------------------------
// CellVolume
//----------------------------------------
KOKKOS_FORCEINLINE_FUNCTION Real CellVolume(const int k, const int j, const int i) const {
KOKKOS_FORCEINLINE_FUNCTION Real CellVolume(const int k, const int j,
const int i) const {
return FaceArea<X3DIR>(k, j, i) * Dx<X3DIR>();
}

KOKKOS_FORCEINLINE_FUNCTION
Real Volume(CellLevel cl, TopologicalElement el, const int k, const int j, const int i) {
Real Volume(CellLevel cl, TopologicalElement el, const int k, const int j,
const int i) {
using TE = TopologicalElement;
if (cl == CellLevel::same) {
if (el == TE::CC) return CellVolume(k, j, i);
else if (el == TE::F1) return FaceArea<X1DIR>(k, j, i);
else if (el == TE::F2) return FaceArea<X2DIR>(k, j, i);
else if (el == TE::F3) return FaceArea<X3DIR>(k, j, i);
else if (el == TE::E1) return EdgeLength<X1DIR>(k, j, i);
else if (el == TE::E2) return EdgeLength<X2DIR>(k, j, i);
else if (el == TE::E3) return EdgeLength<X3DIR>(k, j, i);
else if (el == TE::NN) return 1.0;
if (el == TE::CC)
return CellVolume(k, j, i);
else if (el == TE::F1)
return FaceArea<X1DIR>(k, j, i);
else if (el == TE::F2)
return FaceArea<X2DIR>(k, j, i);
else if (el == TE::F3)
return FaceArea<X3DIR>(k, j, i);
else if (el == TE::E1)
return EdgeLength<X1DIR>(k, j, i);
else if (el == TE::E2)
return EdgeLength<X2DIR>(k, j, i);
else if (el == TE::E3)
return EdgeLength<X3DIR>(k, j, i);
else if (el == TE::NN)
return 1.0;
} else {
PARTHENON_FAIL("Have not yet implemented fine fields for UniformCylindrical coordinates.");
PARTHENON_FAIL(
"Have not yet implemented fine fields for UniformCylindrical coordinates.");
}
PARTHENON_FAIL("If you reach this point, someone has added a new value to the the "
"TopologicalElement enum.");
Expand Down
Loading

0 comments on commit 483395c

Please sign in to comment.