-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomScheme.cpp
78 lines (72 loc) · 2.19 KB
/
CustomScheme.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
75
76
77
78
#include "CustomScheme.h"
// OddWeight
void to_json(json& j, const OddWeight& ow) {
j = json{{"level", ow.level}, {"type", ow.type}, {"value", ow.value}};
}
void from_json(const json& j, OddWeight& ow) {
j.at("level").get_to(ow.level);
j.at("type").get_to(ow.type);
j.at("value").get_to(ow.value);
}
std::ostream& operator<<(std::ostream& os, const OddWeight& ow) {
// write obj to stream
os << "[level:" << ow.level
<< ", type:" << std::to_string(ow.type)
<< ", value:" << std::to_string(ow.value) << "]";
return os;
}
// EvenWeights
void to_json(json& j, const EvenWeights& ew) {
j = json{{"alfa", ew.alfa}, {"beta", ew.beta}};
}
void from_json(const nlohmann::json& j, EvenWeights& ew) {
j.at("alfa").get_to(ew.alfa);
j.at("beta").get_to(ew.beta);
}
std::ostream& operator<<(std::ostream& os, const EvenWeights& ew) {
// write obj to stream
os << "[alfa:" << std::to_string(ew.alfa)
<< ", beta:" << std::to_string(ew.beta) << "]";
return os;
}
// Weights
void to_json(json& j, const Weights& w) {
j = json{{"odd", w.odd}, {"even", w.even}};
}
void from_json(const json& j, Weights& w) {
w.odd = j.at("odd");
w.even = j.at("even");
}
std::ostream& operator<<(std::ostream& os, const Weights& w) {
os << "[odd:[";
for (OddWeight ow : w.odd) {
os << ow;
}
os << "], even:" << w.even << "]";
return os;
}
// CustomScheme
void to_json(json& j, const CustomScheme& s) {
j = json{
{"name", s.name},
{"meshtype", s.mesh_type},
{"refinementtype", s.refinement_type},
{"neighbourlevel", s.neighbour_level},
{"weights", s.weights}
};
}
void from_json(const json& j, CustomScheme& s) {
s.name = j.at("name");
s.mesh_type = j.at("meshtype");
s.refinement_type = j.at("refinementtype");
s.neighbour_level = j.at("neighbourlevel");
s.weights = j.at("weights");
}
std::ostream& operator<<(std::ostream& os, const CustomScheme& s) {
os << "[name:" << s.name
<< ", mesh_type:" << s.mesh_type
<< ", refinement_type:" << s.refinement_type
<< ", neighbour_level:" << s.neighbour_level
<< ", weights:" << s.weights << "]";
return os;
}