Skip to content

Commit a8c0134

Browse files
author
mlund
committed
Fix json issues
1 parent aed612d commit a8c0134

File tree

7 files changed

+75
-71
lines changed

7 files changed

+75
-71
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ endif()
5858
# header paths
5959
string(TOLOWER ${PROJECT_NAME}/version.h VERSION_HEADER_LOCATION)
6060

61-
add_compile_definitions("NLOHMANN_JSON_HPP") # older versions used this macro. Now it's suffixed with "_"
62-
6361
packageProject(
6462
NAME ${PROJECT_NAME}
6563
VERSION ${PROJECT_VERSION}

include/coulombgalore/all.hpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,74 @@
3636
#include "wolf.hpp"
3737
#include "zahn.hpp"
3838
#include "zerodipole.hpp"
39+
40+
namespace CoulombGalore {
41+
#ifdef NLOHMANN_JSON_HPP
42+
inline std::shared_ptr<SchemeBase> createScheme(const nlohmann::json &j) {
43+
const std::map<std::string, Scheme> m = {{"plain", Scheme::plain},
44+
{"qpotential", Scheme::qpotential},
45+
{"wolf", Scheme::wolf},
46+
{"poisson", Scheme::poisson},
47+
{"reactionfield", Scheme::reactionfield},
48+
{"spline", Scheme::spline},
49+
{"fanourgakis", Scheme::fanourgakis},
50+
{"fennell", Scheme::fennell},
51+
{"zahn", Scheme::zahn},
52+
{"zerodipole", Scheme::zerodipole},
53+
{"ewald", Scheme::ewald},
54+
{"ewaldt", Scheme::ewaldt}}; // map string keyword to scheme type
55+
56+
std::string name = j.at("type").get<std::string>();
57+
auto it = m.find(name);
58+
if (it == m.end()) {
59+
throw std::runtime_error("unknown coulomb scheme " + name);
60+
}
61+
62+
std::shared_ptr<SchemeBase> scheme;
63+
switch (it->second) {
64+
case Scheme::plain:
65+
scheme = std::make_shared<Plain>(j);
66+
break;
67+
case Scheme::wolf:
68+
scheme = std::make_shared<Wolf>(j);
69+
break;
70+
case Scheme::zahn:
71+
scheme = std::make_shared<Zahn>(j);
72+
break;
73+
case Scheme::fennell:
74+
scheme = std::make_shared<Fennell>(j);
75+
break;
76+
case Scheme::zerodipole:
77+
scheme = std::make_shared<ZeroDipole>(j);
78+
break;
79+
case Scheme::fanourgakis:
80+
scheme = std::make_shared<Fanourgakis>(j);
81+
break;
82+
case Scheme::qpotential5:
83+
scheme = std::make_shared<qPotentialFixedOrder<5>>(j);
84+
break;
85+
case Scheme::qpotential:
86+
scheme = std::make_shared<qPotential>(j);
87+
break;
88+
case Scheme::ewald:
89+
scheme = std::make_shared<Ewald>(j);
90+
break;
91+
case Scheme::ewaldt:
92+
scheme = std::make_shared<EwaldTruncated>(j);
93+
break;
94+
case Scheme::poisson:
95+
scheme = std::make_shared<Poisson>(j);
96+
break;
97+
case Scheme::reactionfield:
98+
scheme = std::make_shared<ReactionField>(j);
99+
break;
100+
default:
101+
break;
102+
}
103+
return scheme;
104+
}
105+
#endif
106+
107+
108+
} // end of namespace
109+

include/coulombgalore/fanourgakis.hpp

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -68,70 +68,5 @@ class Fanourgakis : public EnergyImplementation<Fanourgakis> {
6868
#endif
6969
};
7070

71-
#ifdef NLOHMANN_JSON_HPP
72-
inline std::shared_ptr<SchemeBase> createScheme(const nlohmann::json &j) {
73-
const std::map<std::string, Scheme> m = {{"plain", Scheme::plain},
74-
{"qpotential", Scheme::qpotential},
75-
{"wolf", Scheme::wolf},
76-
{"poisson", Scheme::poisson},
77-
{"reactionfield", Scheme::reactionfield},
78-
{"spline", Scheme::spline},
79-
{"fanourgakis", Scheme::fanourgakis},
80-
{"fennell", Scheme::fennell},
81-
{"zahn", Scheme::zahn},
82-
{"zerodipole", Scheme::zerodipole},
83-
{"ewald", Scheme::ewald},
84-
{"ewaldt", Scheme::ewaldt}}; // map string keyword to scheme type
85-
86-
std::string name = j.at("type").get<std::string>();
87-
auto it = m.find(name);
88-
if (it == m.end()) {
89-
throw std::runtime_error("unknown coulomb scheme " + name);
90-
}
91-
92-
std::shared_ptr<SchemeBase> scheme;
93-
switch (it->second) {
94-
case Scheme::plain:
95-
scheme = std::make_shared<Plain>(j);
96-
break;
97-
case Scheme::wolf:
98-
scheme = std::make_shared<Wolf>(j);
99-
break;
100-
case Scheme::zahn:
101-
scheme = std::make_shared<Zahn>(j);
102-
break;
103-
case Scheme::fennell:
104-
scheme = std::make_shared<Fennell>(j);
105-
break;
106-
case Scheme::zerodipole:
107-
scheme = std::make_shared<ZeroDipole>(j);
108-
break;
109-
case Scheme::fanourgakis:
110-
scheme = std::make_shared<Fanourgakis>(j);
111-
break;
112-
case Scheme::qpotential5:
113-
scheme = std::make_shared<qPotentialFixedOrder<5>>(j);
114-
break;
115-
case Scheme::qpotential:
116-
scheme = std::make_shared<qPotential>(j);
117-
break;
118-
case Scheme::ewald:
119-
scheme = std::make_shared<Ewald>(j);
120-
break;
121-
case Scheme::ewaldt:
122-
scheme = std::make_shared<EwaldTruncated>(j);
123-
break;
124-
case Scheme::poisson:
125-
scheme = std::make_shared<Poisson>(j);
126-
break;
127-
case Scheme::reactionfield:
128-
scheme = std::make_shared<ReactionField>(j);
129-
break;
130-
default:
131-
break;
132-
}
133-
return scheme;
134-
}
135-
#endif
13671

13772
} // namespace CoulombGalore

include/coulombgalore/fennell.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Fennell : public EnergyImplementation<Fennell> {
7777
inline Fennell(const nlohmann::json &j) : Fennell(j.at("cutoff").get<double>(), j.at("alpha").get<double>()) {}
7878

7979
private:
80-
inline void _to_json(nlohmann::json &j) const override { j = {{"alpha", alpha}}; }
80+
inline void _to_json(nlohmann::json &j) const override { j = {{"alpha_red", alphaRed}}; }
8181
#endif
8282
};
8383

include/coulombgalore/wolf.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Wolf : public EnergyImplementation<Wolf> {
7575
inline Wolf(const nlohmann::json &j) : Wolf(j.at("cutoff").get<double>(), j.at("alpha").get<double>()) {}
7676

7777
private:
78-
inline void _to_json(nlohmann::json &j) const override { j = {{"alpha", alpha}}; }
78+
inline void _to_json(nlohmann::json &j) const override { j = {{"alpha", alphaRed}}; }
7979
#endif
8080
};
8181

include/coulombgalore/zahn.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class Zahn : public EnergyImplementation<Zahn> {
8080
inline Zahn(const nlohmann::json &j) : Zahn(j.at("cutoff").get<double>(), j.at("alpha").get<double>()) {}
8181

8282
private:
83-
inline void _to_json(nlohmann::json &j) const override { j = {{"alpha", alpha}}; }
83+
inline void _to_json(nlohmann::json &j) const override { j = {{"alpha", alphaRed}}; }
8484
#endif
8585
};
8686

include/coulombgalore/zerodipole.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ZeroDipole : public EnergyImplementation<ZeroDipole> {
8585
: ZeroDipole(j.at("cutoff").get<double>(), j.at("alpha").get<double>()) {}
8686

8787
private:
88-
inline void _to_json(nlohmann::json &j) const override { j = {{"alpha", alpha}}; }
88+
inline void _to_json(nlohmann::json &j) const override { j = {{"alpha", alphaRed}}; }
8989
#endif
9090
};
9191

0 commit comments

Comments
 (0)