11 #define BOOST_TEST_MODULE LFPTest
12 #include <boost/test/included/unit_test.hpp>
20 double integral(F f,
double a,
double b,
int n) {
21 double step = (b - a) / n;
23 for (
int i = 0;
i < n;
i++) {
24 area += f(a + (
i + 0.5) * step) * step;
34 double segment_length{1.0e-6};
35 double segment_start_val{1.0e-6};
36 std::array<double, 3> segment_start = std::array<double, 3>{0.0, 0.0, segment_start_val};
37 std::array<double, 3> segment_end =
38 paxpy(segment_start, 1.0, std::array<double, 3>{0.0, 0.0, segment_length});
42 std::array<double, 10> vals;
43 double circling_radius{1.0e-6};
44 std::array<double, 3> segment_middle{0.0, 0.0, 1.5e-6};
45 double medium_resistivity_fac{1.0};
46 for (
auto k = 0; k < 10; k++) {
47 std::array<double, 3> approaching_elec =
48 paxpy(segment_middle, 1.0, std::array<double, 3>{0.0, 1.0e-5 - k * 1.0e-6, 0.0});
49 std::array<double, 3> circling_elec =
52 std::array<double, 3>{0.0,
53 circling_radius * std::cos(2.0 *
pi * k / 10),
54 circling_radius * std::sin(2.0 *
pi * k / 10)});
57 approaching_elec, segment_start, segment_end, floor, medium_resistivity_fac);
59 circling_elec, segment_start, segment_end, floor, medium_resistivity_fac);
60 double numeric_circling_lfp =
integral(
62 return 1.0 / std::max(floor,
67 paxpy(segment_start, -1.0, segment_end)))));
73 std::clog <<
"ANALYTIC line source " << analytic_circling_lfp
74 <<
" vs NUMERIC line source LFP " << numeric_circling_lfp <<
"\n";
75 BOOST_REQUIRE_CLOSE(analytic_circling_lfp, numeric_circling_lfp, 1.0e-6);
77 BOOST_REQUIRE((approaching_elec[1] < 0.866e-6) ? analytic_approaching_lfp == 1.0e6 :
true);
78 vals[k] = analytic_circling_lfp;
81 for (
size_t k = 0; k < 5; k++) {
82 BOOST_REQUIRE(std::abs((vals[k] - vals[k + 5]) /
83 std::max(std::abs(vals[k]), std::abs(vals[k + 5]))) < 1.0e-12);
85 std::vector<std::array<double, 3>> segments_starts = {{0., 0., 1.},
89 std::vector<std::array<double, 3>> segments_ends = {{0., 0., 0.},
93 std::vector<double> radii{0.1, 0.1, 0.1, 0.1};
94 std::vector<std::array<double, 3>> electrodes = {{0.0, 0.3, 0.0}, {0.0, 0.7, 0.8}};
95 std::vector<int> indices = {0, 1, 2, 3};
97 lfp.template lfp<std::vector<double>>({0.0, 1.0, 2.0, 3.0});
98 std::vector<double> res_line_source = lfp.
lfp_values();
100 segments_starts, segments_ends, radii, indices, electrodes, 1.0);
101 lfpp.template lfp<std::vector<double>>({0.0, 1.0, 2.0, 3.0});
102 std::vector<double> res_point_source = lfpp.
lfp_values();
103 BOOST_REQUIRE_CLOSE(res_line_source[0], res_point_source[0], 1.0);
104 BOOST_REQUIRE_CLOSE(res_line_source[1], res_point_source[1], 1.0);