Skip to content

Commit 394648a

Browse files
mo-jonasgandertonwdeconinck
authored andcommitted
Switch Eigen matrices to arrays
1 parent 9100e51 commit 394648a

File tree

2 files changed

+25
-38
lines changed

2 files changed

+25
-38
lines changed

src/atlas/grid/detail/grid/CubedSphere2.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <cmath>
44

5-
#include "eckit/geometry/Sphere.h"
65
#include "eckit/utils/Hash.h"
76

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

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

121-
tan_point << tan_coord[0], tan_coord[1], 1;
120+
xyz[0] = transform[0][0] * tan_coord[0] + transform[0][1] * tan_coord[1] + transform[0][2];
121+
xyz[1] = transform[1][0] * tan_coord[0] + transform[1][1] * tan_coord[1] + transform[1][2];
122+
xyz[2] = transform[2][0] * tan_coord[0] + transform[2][1] * tan_coord[1] + transform[2][2];
122123

123-
xyz = lfric_rotations_transposed_[tile] * tan_point;
124-
xyz.normalize();
125-
126-
return {xyz(0), xyz(1), xyz(2)};
124+
return PointXYZ::normalize(xyz);
127125
}
128126

129127
} // namespace grid

src/atlas/grid/detail/grid/CubedSphere2.h

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
#include "atlas/runtime/Exception.h"
55
#include "atlas/util/Config.h"
66
#include "atlas/util/Point.h"
7-
#if eckit_HAVE_EIGEN
8-
#include "eckit/maths/Eigen.h"
9-
#else
10-
#include "eckit/maths/Matrix.h"
11-
#endif
127

138
namespace atlas {
149
namespace grid {
@@ -164,31 +159,25 @@ class CubedSphere2 : public Grid {
164159
private:
165160
std::string type_ = {"cubedsphere2"};
166161

167-
#if eckit_HAVE_EIGEN
168-
using Matrix = Eigen::Matrix3d;
169-
using Vector = Eigen::Vector3d;
170-
#else
171-
using Matrix = eckit::maths::Matrix<double>;
172-
using Vector = eckit::maths::ColVector<double>;
173-
#endif
174-
175-
std::array<Matrix, 6> lfric_rotations_ = {
176-
Matrix({{0, 1, 0}, {0, 0, -1}, {1, 0, 0}}),
177-
Matrix({{-1, 0, 0}, {0, 0, -1}, {0, 1, 0}}),
178-
Matrix({{0, -1, 0}, {0, 0, -1}, {-1, 0, 0}}),
179-
Matrix({{1, 0, 0}, {0, 0, -1}, {0, -1, 0}}),
180-
Matrix({{-1, 0, 0}, {0, 1, 0}, {0, 0, 1}}),
181-
Matrix({{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}})
182-
};
183-
184-
std::array<Matrix, 6> lfric_rotations_transposed_ = {
185-
Matrix({{0, 0, 1}, {1, 0, 0}, {0, -1, 0}}),
186-
Matrix({{-1, 0, 0}, {0, 0, 1}, {0, -1, 0}}),
187-
Matrix({{0, 0, -1}, {-1, 0, 0}, {0, -1, 0}}),
188-
Matrix({{1, 0, 0}, {0, 0, -1}, {0, -1, 0}}),
189-
Matrix({{-1, 0, 0}, {0, 1, 0}, {0, 0, 1}}),
190-
Matrix({{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}})
191-
};
162+
using Matrix = std::array<std::array<double, 3>, 3>;
163+
164+
std::array<Matrix, 6> lfric_rotations_ = {{
165+
{{ {0, 1, 0}, {0, 0, -1}, {1, 0, 0} }},
166+
{{ {-1, 0, 0}, {0, 0, -1}, {0, 1, 0} }},
167+
{{ {0, -1, 0}, {0, 0, -1}, {-1, 0, 0} }},
168+
{{ {1, 0, 0}, {0, 0, -1}, {0, -1, 0} }},
169+
{{ {-1, 0, 0}, {0, 1, 0}, {0, 0, 1} }},
170+
{{ {-1, 0, 0}, {0, -1, 0}, {0, 0, -1} }}
171+
}};
172+
173+
std::array<Matrix, 6> lfric_rotations_transposed_ = {{
174+
{{ {0, 0, 1}, {1, 0, 0}, {0, -1, 0} }},
175+
{{ {-1, 0, 0}, {0, 0, 1}, {0, -1, 0} }},
176+
{{ {0, 0, -1}, {-1, 0, 0}, {0, -1, 0} }},
177+
{{ {1, 0, 0}, {0, 0, -1}, {0, -1, 0} }},
178+
{{ {-1, 0, 0}, {0, 1, 0}, {0, 0, 1} }},
179+
{{ {-1, 0, 0}, {0, -1, 0}, {0, 0, -1} }}
180+
}};
192181

193182
};
194183

0 commit comments

Comments
 (0)