Debian Codegraph @

examples/simulations/gray-scott/simulation/settings.cpp

raw
1 /*
2 * SPDX-FileCopyrightText: 2026 Oak Ridge National Laboratory and Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "settings.h"
8
9 #include <fstream>
10
11 #include "json.hpp"
12
13 void to_json(nlohmann::json &j, const Settings &s)
14 {
15 j = nlohmann::json{{"L", s.L},
16 {"steps", s.steps},
17 {"plotgap", s.plotgap},
18 {"F", s.F},
19 {"k", s.k},
20 {"dt", s.dt},
21 {"Du", s.Du},
22 {"Dv", s.Dv},
23 {"noise", s.noise},
24 {"output", s.output},
25 {"checkpoint", s.checkpoint},
26 {"checkpoint_freq", s.checkpoint_freq},
27 {"checkpoint_output", s.checkpoint_output},
28 {"restart", s.restart},
29 {"restart_input", s.restart_input},
30 {"adios_config", s.adios_config},
31 {"adios_span", s.adios_span},
32 {"adios_memory_selection", s.adios_memory_selection},
33 {"mesh_type", s.mesh_type}};
34 }
35
36 void from_json(const nlohmann::json &j, Settings &s)
37 {
38 j.at("L").get_to(s.L);
39 j.at("steps").get_to(s.steps);
40 j.at("plotgap").get_to(s.plotgap);
41 j.at("F").get_to(s.F);
42 j.at("k").get_to(s.k);
43 j.at("dt").get_to(s.dt);
44 j.at("Du").get_to(s.Du);
45 j.at("Dv").get_to(s.Dv);
46 j.at("noise").get_to(s.noise);
47 j.at("output").get_to(s.output);
48 j.at("checkpoint").get_to(s.checkpoint);
49 j.at("checkpoint_freq").get_to(s.checkpoint_freq);
50 j.at("checkpoint_output").get_to(s.checkpoint_output);
51 j.at("restart").get_to(s.restart);
52 j.at("restart_input").get_to(s.restart_input);
53 j.at("adios_config").get_to(s.adios_config);
54 j.at("adios_span").get_to(s.adios_span);
55 j.at("adios_memory_selection").get_to(s.adios_memory_selection);
56 j.at("mesh_type").get_to(s.mesh_type);
57 }
58
59 Settings::Settings()
60 {
61 L = 128;
62 steps = 20000;
63 plotgap = 200;
64 F = 0.04;
65 k = 0.06075;
66 dt = 0.2;
67 Du = 0.05;
68 Dv = 0.1;
69 noise = 0.0;
70 output = "foo.bp";
71 checkpoint = false;
72 checkpoint_freq = 2000;
73 checkpoint_output = "ckpt.bp";
74 restart = false;
75 restart_input = "ckpt.bp";
76 adios_config = "adios2.xml";
77 adios_span = false;
78 adios_memory_selection = false;
79 mesh_type = "image";
80 }
81
82 Settings Settings::from_json(const std::string &fname)
83 {
84 std::ifstream ifs(fname);
85 nlohmann::json j;
86
87 ifs >> j;
88
89 return j.get<Settings>();
90 }