FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openmc/tests/cpp_unit_tests/test_interpolate.cpp at develop · openmc-dev/openmc · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
openmc-dev
/
openmc
Public
Notifications
You must be signed in to change notification settings
Fork
675
Star
1.1k
Code
Issues
342
Pull requests
124
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
openmc
/
tests
/
cpp_unit_tests
/
test_interpolate.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (41 loc) · 1.58 KB
Breadcrumbs
openmc
/
tests
/
cpp_unit_tests
/
test_interpolate.cpp
Copy path
File metadata and controls
51 lines (41 loc) · 1.58 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
include
<
iostream
>
#
include
<
map
>
#
include
<
catch2/catch_test_macros.hpp
>
#
include
<
catch2/matchers/catch_matchers_floating_point.hpp
>
#
include
"
openmc/interpolate.h
"
#
include
"
openmc/search.h
"
using
namespace
openmc
;
TEST_CASE
(
"
Test Lagranian Interpolation
"
)
{
std::vector<
double
> xs {
0.0
,
1.0
,
2.0
,
3.0
,
4.0
,
5.0
,
6.0
};
std::vector<
double
> ys {
0.0
,
1.0
,
1.0
,
2.0
,
3.0
,
3.0
,
5.0
};
//
ensure we get data points back at the x values
for
(
int
n =
1
; n <=
6
; n++) {
for
(
int
i =
0
; i < xs.
size
(); i++) {
double
x = xs[i];
double
y = ys[i];
size_t
idx =
lower_bound_index
(xs.
begin
(), xs.
end
(), x);
idx =
std::min
(idx, xs.
size
() - n -
1
);
double
out =
interpolate_lagrangian
(xs, ys, idx, x, n);
REQUIRE
(out == y);
}
}
//
spot checks based on an independent implementation of Lagrangian
//
interpolation
std::map<
int
, std::vector<std::pair<
double
,
double
>>> checks;
checks[
1
] = {{
0.5
,
0.5
}, {
4.5
,
3.0
}, {
2.5
,
1.5
}, {
5.5
,
4.0
}};
checks[
2
] = {{
2.5
,
1.5
}, {
4.5
,
2.75
}, {
4.9999
,
3.0
}, {
4.00001
,
3.0
}};
checks[
3
] = {{
2.5592
,
1.5
}, {
4.5
,
2.9375
}, {
4.9999
,
3.0
}, {
4.00001
,
3.0
}};
for
(
auto
check_set : checks) {
int
order = check_set.
first
;
auto
checks = check_set.
second
;
for
(
auto
check : checks) {
double
input = check.
first
;
double
exp_output = check.
second
;
size_t
idx =
lower_bound_index
(xs.
begin
(), xs.
end
(), input);
idx =
std::min
(idx, xs.
size
() - order -
1
);
double
out =
interpolate_lagrangian
(xs, ys, idx, input, order);
REQUIRE_THAT
(out,
Catch::Matchers::WithinAbs
(exp_output,
1e-04
));
}
}
}
Back
|
FazBrowse Home
|
New Git URL