Medusa  1.1
Coordinate Free Mehless Method implementation
test/domains/discretization_helpers_test.cpp
#include "gtest/gtest.h"
namespace mm {
TEST(Domains, SphereDiscretization1d) {
std::mt19937 gen;
double r = 2.3;
const int dim = 1;
ASSERT_EQ(2, v.size());
std::sort(v.begin(), v.end());
EXPECT_EQ(-r, v[0][0]);
EXPECT_EQ(r, v[1][0]);
}
TEST(Domains, SphereDiscretization2d) {
double r = 2.3;
ASSERT_EQ(v.size(), 4);
std::sort(v.begin(), v.end());
double tol = 1e-15;
EXPECT_NEAR(v[0][0], -r, tol);
EXPECT_NEAR(v[0][1], 0, tol);
EXPECT_NEAR(v[1][0], 0, tol);
EXPECT_NEAR(v[1][1], -r, tol);
EXPECT_NEAR(v[2][0], 0, tol);
EXPECT_NEAR(v[2][1], r, tol);
EXPECT_NEAR(v[3][0], r, tol);
EXPECT_NEAR(v[3][1], 0, tol);
}
TEST(Domains, SphereDiscretization3d) {
double r = 2.3;
decltype(v) expected = {{-1.15, -1.99186, 2.43932e-16}, {-1.15, -0.995929, -1.725},
{-1.15, -0.995929, 1.725}, {-1.15, 0.995929, -1.725},
{-1.15, 0.995929, 1.725}, {-1.15, 1.99186, 0},
{1.15, -1.99186, 2.43932e-16}, {1.15, -0.995929, -1.725},
{1.15, -0.995929, 1.725}, {1.15, 0.995929, -1.725},
{1.15, 0.995929, 1.725}, {1.15, 1.99186, 0}};
std::sort(v.begin(), v.end());
double tol = 1e-5; // large due to low precision data above, but not really a problem
ASSERT_EQ(expected.size(), v.size());
int n = expected.size();
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 3; ++j) {
EXPECT_NEAR(expected[i][j], v[i][j], tol);
}
}
}
TEST(Domains, DiscretizeLineWithDensity) {
Vec2d p = 0.0, q = {1.0, 0.5};
auto fn = [](const Vec2d& p) { return 0.1*(1+p[0]); };
Range<Vec2d> expected = {{0.0894427, 0.0447214}, {0.186885, 0.0934427}, {0.293044, 0.146522},
{0.408697, 0.204349}, {0.534695, 0.267347}, {0.671962, 0.335981},
{0.821507, 0.410753}};
// plot the points: endpoints are not included, spacing is variable
double tol = 1e-6;
ASSERT_EQ(expected.size(), d.size());
int n = d.size();
for (int i = 0; i < n; ++i) {
EXPECT_NEAR(expected[i][0], d[i][0], tol);
EXPECT_NEAR(expected[i][1], d[i][1], tol);
}
}
} // namespace mm
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
Vec_fwd.hpp
mm::discretization_helpers::discretizeLineWithDensity
Range< vec_t > discretizeLineWithDensity(const vec_t &p, const vec_t &q, const func_t &delta_r)
Returns nodes lying on the line segment pq with approximate distances delta_r.
Definition: discretization_helpers.hpp:35
discretization_helpers.hpp
mm::discretization_helpers::SphereDiscretization::construct
static std::vector< Eigen::Matrix< scalar_t, dim, 1 >, Eigen::aligned_allocator< Eigen::Matrix< scalar_t, dim, 1 > > > construct(scalar_t radius, int num_samples, generator_t &generator)
Construct a randomized discretization.
Definition: discretization_helpers.hpp:85
mm::sort
container_t & sort(container_t &v)
Sorts a container inplace.
Definition: stdtypesutils.hpp:43
mm::Vec2d
Vec< double, 2 > Vec2d
Convenience typedef for 2d vector of doubles.
Definition: Vec_fwd.hpp:34