Skip to content

Commit 324b09f

Browse files
committed
Add regression test for Aluminum model
1 parent 506b4d6 commit 324b09f

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

apps/aluminumNew/aluminumTest.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#include "Aluminum.hpp"
2+
#include "SeedGridFCC.hpp"
3+
#include <catch2/catch_test_macros.hpp>
4+
#include <catch2/matchers/catch_matchers_floating_point.hpp>
5+
#include <openpfc/openpfc.hpp>
6+
7+
using namespace pfc;
8+
using namespace Catch::Matchers;
9+
10+
/* Parameters from aluminumNew.json:
11+
{
12+
"n0": -0.0060,
13+
"alpha": 0.20,
14+
"n_sol": -0.036,
15+
"n_vap": -1.297,
16+
"T_const": 980,
17+
"T_min": 780,
18+
"T_max": 1280,
19+
"T0": 89285.0,
20+
"Bx": 0.817900686921996,
21+
"G_grid": 0,
22+
"V_grid": 0,
23+
"x_initial": 130,
24+
"alpha_farTol": 0.001,
25+
"alpha_highOrd": 0,
26+
"lambda": 0.22,
27+
"stabP": 0.0,
28+
"shift_u": 1.0,
29+
"shift_s": 0.0,
30+
"p2_bar": 0.8286531831,
31+
"p3_bar": -0.04204863,
32+
"p4_bar": 0.007533,
33+
"q20_bar": 0.016531729105214,
34+
"q21_bar": 5.467,
35+
"q30_bar": 1.7152418049986,
36+
"q31_bar": 0.45,
37+
"q40_bar": 0.787482
38+
}
39+
*/
40+
41+
TEST_CASE("Aluminum functionality", "[Aluminum]") {
42+
SECTION("Step model and calculate norm of the result") {
43+
MPI_Worker worker(0, nullptr);
44+
World world({32, 32, 32});
45+
Decomposition decomp(world);
46+
FFT fft(decomp);
47+
48+
Aluminum aluminum;
49+
aluminum.set_n0(-0.0060);
50+
aluminum.set_alpha(0.20);
51+
aluminum.set_n_sol(-0.036);
52+
aluminum.set_n_vap(-1.297);
53+
aluminum.set_T_const(980);
54+
aluminum.set_T_min(780);
55+
aluminum.set_T_max(1280);
56+
aluminum.set_T0(89285.0);
57+
aluminum.set_Bx(0.817900686921996);
58+
aluminum.set_G_grid(0);
59+
aluminum.set_V_grid(0);
60+
aluminum.set_x_initial(130);
61+
aluminum.set_alpha_farTol(0.001);
62+
aluminum.set_alpha_highOrd(0);
63+
aluminum.set_lambda(0.22);
64+
aluminum.set_stabP(0.0);
65+
aluminum.set_shift_u(1.0);
66+
aluminum.set_shift_s(0.0);
67+
aluminum.set_p2_bar(0.8286531831);
68+
aluminum.set_p3_bar(-0.04204863);
69+
aluminum.set_p4_bar(0.007533);
70+
aluminum.set_q20_bar(0.016531729105214);
71+
aluminum.set_q21_bar(5.467);
72+
aluminum.set_q30_bar(1.7152418049986);
73+
aluminum.set_q31_bar(0.45);
74+
aluminum.set_q40_bar(0.787482);
75+
aluminum.set_fft(fft);
76+
double dt = 1.0e-2;
77+
aluminum.initialize(dt);
78+
79+
SeedGridFCC ic;
80+
ic.set_Nx(1);
81+
ic.set_Ny(2);
82+
ic.set_Nz(2);
83+
ic.set_X0(8.0);
84+
ic.set_radius(4.0);
85+
ic.set_amplitude(0.4);
86+
ic.set_rho(-0.036);
87+
ic.set_rseed(42);
88+
89+
std::vector<double> &psi = aluminum.get_real_field("psi");
90+
std::fill(psi.begin(), psi.end(), -0.0060);
91+
ic.apply(aluminum, 0.0);
92+
93+
std::array<double, 5> expected_norms{1297.08, 1250.21, 1209.28, 1173.19, 1141.09};
94+
for (int i = 0; i < 5; ++i) {
95+
double norm2 = 0.0;
96+
for (auto &x : psi) norm2 += x * x;
97+
std::cout << "norm: " << norm2 << std::endl;
98+
REQUIRE_THAT(norm2, WithinAbs(expected_norms[i], 0.1));
99+
aluminum.step(1.0);
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)