forked from GridTools/gtbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvergence_tests.cpp
74 lines (63 loc) · 2.62 KB
/
convergence_tests.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* gtbench
*
* Copyright (c) 2014-2020, ETH Zurich
* All rights reserved.
*
* Please, refer to the LICENSE file in the root directory.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <iostream>
#include "./numerics/solver.hpp"
#include "./runtime/run.hpp"
#include "./verification/analytical.hpp"
#include "./verification/convergence.hpp"
int main(int argc, char **argv) {
constexpr auto rt_tag = runtime::GTBENCH_RUNTIME();
options opts;
runtime::register_options(rt_tag, opts);
auto args = opts.parse(argc, argv);
auto rt = runtime::init(rt_tag, args);
auto run_tests = [&rt](std::string const &title, auto const &exact,
auto const &stepper) {
std::size_t max_resolution = std::is_same<real_t, float>() ? 16 : 32;
std::cout << "=== " << title << " ===" << std::endl;
std::cout << "Spatial convergence:" << std::endl;
auto spatial_error_f = [&](std::size_t n) {
return runtime::solve(rt, exact, stepper, {n, n, n}, 1e-2,
std::is_same<real_t, float>() ? 1e-3 : 1e-5)
.error;
};
verification::print_order_verification_result(
verification::order_verification(spatial_error_f, 8, max_resolution));
std::cout << "Temporal convergence:" << std::endl;
auto spacetime_error_f = [&](std::size_t n) {
return runtime::solve(rt, exact, stepper, {128, 128, 128}, 1e-1, 1e-1 / n)
.error;
};
verification::print_order_verification_result(
verification::order_verification(spacetime_error_f, 8, max_resolution));
};
const real_t diffusion_coeff = 0.05;
run_tests("HORIZONTAL DIFFUSION",
verification::analytical::horizontal_diffusion{diffusion_coeff},
numerics::hdiff_stepper(diffusion_coeff));
run_tests("VERTICAL DIFFUSION",
verification::analytical::vertical_diffusion{diffusion_coeff},
numerics::vdiff_stepper(diffusion_coeff));
run_tests("FULL DIFFUSION",
verification::analytical::full_diffusion{diffusion_coeff},
numerics::diff_stepper(diffusion_coeff));
run_tests("HORIZONTAL ADVECTION",
verification::analytical::horizontal_advection{},
numerics::hadv_stepper());
run_tests("VERTICAL ADVECTION",
verification::analytical::vertical_advection{},
numerics::vadv_stepper());
run_tests("RUNGE-KUTTA ADVECTION", verification::analytical::full_advection{},
numerics::rkadv_stepper());
run_tests("ADVECTION-DIFFUSION",
verification::analytical::advection_diffusion{diffusion_coeff},
numerics::advdiff_stepper(diffusion_coeff));
return 0;
}