Skip to content

Commit

Permalink
Switch Eigen matrices to arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-jonasganderton committed Jan 23, 2025
1 parent 295bc88 commit e29d729
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 38 deletions.
14 changes: 6 additions & 8 deletions src/atlas/grid/detail/grid/CubedSphere2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <cmath>

#include "eckit/geometry/Sphere.h"
#include "eckit/utils/Hash.h"

namespace atlas {
Expand Down Expand Up @@ -115,15 +114,14 @@ PointXY CubedSphere2::ij_to_tangent_coord(idx_t i, idx_t j) const {

// Transform a point on the tangent plane to a point on a cube
PointXYZ CubedSphere2::tangent_to_xyz_coord(const PointXY& tan_coord, idx_t tile) const {
Vector tan_point(3);
Vector xyz(3);
PointXYZ xyz;
const Matrix& transform = lfric_rotations_transposed_[tile];

tan_point << tan_coord[0], tan_coord[1], 1;
xyz[0] = transform[0][0] * tan_coord[0] + transform[0][1] * tan_coord[1] + transform[0][2];
xyz[1] = transform[1][0] * tan_coord[0] + transform[1][1] * tan_coord[1] + transform[1][2];
xyz[2] = transform[2][0] * tan_coord[0] + transform[2][1] * tan_coord[1] + transform[2][2];

xyz = lfric_rotations_transposed_[tile] * tan_point;
xyz.normalize();

return {xyz(0), xyz(1), xyz(2)};
return PointXYZ::normalize(xyz);
}

} // namespace grid
Expand Down
49 changes: 19 additions & 30 deletions src/atlas/grid/detail/grid/CubedSphere2.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
#include "atlas/runtime/Exception.h"
#include "atlas/util/Config.h"
#include "atlas/util/Point.h"
#if eckit_HAVE_EIGEN
#include "eckit/maths/Eigen.h"
#else
#include "eckit/maths/Matrix.h"
#endif

namespace atlas {
namespace grid {
Expand Down Expand Up @@ -164,31 +159,25 @@ class CubedSphere2 : public Grid {
private:
std::string type_ = {"cubedsphere2"};

#if eckit_HAVE_EIGEN
using Matrix = Eigen::Matrix3d;
using Vector = Eigen::Vector3d;
#else
using Matrix = eckit::maths::Matrix<double>;
using Vector = eckit::maths::ColVector<double>;
#endif

std::array<Matrix, 6> lfric_rotations_ = {
Matrix({{0, 1, 0}, {0, 0, -1}, {1, 0, 0}}),
Matrix({{-1, 0, 0}, {0, 0, -1}, {0, 1, 0}}),
Matrix({{0, -1, 0}, {0, 0, -1}, {-1, 0, 0}}),
Matrix({{1, 0, 0}, {0, 0, -1}, {0, -1, 0}}),
Matrix({{-1, 0, 0}, {0, 1, 0}, {0, 0, 1}}),
Matrix({{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}})
};

std::array<Matrix, 6> lfric_rotations_transposed_ = {
Matrix({{0, 0, 1}, {1, 0, 0}, {0, -1, 0}}),
Matrix({{-1, 0, 0}, {0, 0, 1}, {0, -1, 0}}),
Matrix({{0, 0, -1}, {-1, 0, 0}, {0, -1, 0}}),
Matrix({{1, 0, 0}, {0, 0, -1}, {0, -1, 0}}),
Matrix({{-1, 0, 0}, {0, 1, 0}, {0, 0, 1}}),
Matrix({{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}})
};
using Matrix = std::array<std::array<double, 3>, 3>;

std::array<Matrix, 6> lfric_rotations_ = {{
{{ {0, 1, 0}, {0, 0, -1}, {1, 0, 0} }},
{{ {-1, 0, 0}, {0, 0, -1}, {0, 1, 0} }},
{{ {0, -1, 0}, {0, 0, -1}, {-1, 0, 0} }},
{{ {1, 0, 0}, {0, 0, -1}, {0, -1, 0} }},
{{ {-1, 0, 0}, {0, 1, 0}, {0, 0, 1} }},
{{ {-1, 0, 0}, {0, -1, 0}, {0, 0, -1} }}
}};

std::array<Matrix, 6> lfric_rotations_transposed_ = {{
{{ {0, 0, 1}, {1, 0, 0}, {0, -1, 0} }},
{{ {-1, 0, 0}, {0, 0, 1}, {0, -1, 0} }},
{{ {0, 0, -1}, {-1, 0, 0}, {0, -1, 0} }},
{{ {1, 0, 0}, {0, 0, -1}, {0, -1, 0} }},
{{ {-1, 0, 0}, {0, 1, 0}, {0, 0, 1} }},
{{ {-1, 0, 0}, {0, -1, 0}, {0, 0, -1} }}
}};

};

Expand Down

0 comments on commit e29d729

Please sign in to comment.