GCC Code Coverage Report


Directory: ./
File: include/potentials.hpp
Date: 2024-04-18 12:22:13
Exec Total Coverage
Lines: 7 13 53.8%
Functions: 1 3 33.3%
Branches: 8 10 80.0%

Line Branch Exec Source
1 #pragma once
2
3 #include <string>
4 #include <unordered_map>
5 #include <yaml-cpp/yaml.h>
6
7 #include "types.hpp"
8
9 class System;
10 struct Particle;
11
12 class External {
13 int props = 0;
14
15 public:
16 enum Props : int {
17 DOES_E = 1 << 0,
18 DOES_F = 1 << 1,
19 };
20 External(int props);
21 virtual ~External() = default;
22 bool doesE();
23 bool doesF();
24
25 virtual double operator()(Particle &p) = 0;
26 };
27
28 class TestExternal : public External {
29 public:
30 TestExternal(System *s, const YAML::Node &c);
31 double operator()(Particle &p);
32 };
33
34 class Const : public External {
35 public:
36 int d;
37 Real mag;
38 Const(System *s, const YAML::Node &c);
39 double operator()(Particle &p);
40 };
41
42 class PiecewiseLinear : public External {
43 public:
44 int d;
45 Real pos1;
46 Real pos2;
47 Real posDeltaInv;
48 Real E1;
49 Real E2;
50 Real F;
51 PiecewiseLinear(System *s, const YAML::Node &c);
52 double operator()(Particle &p);
53 };
54
55 class WallsHard : public External {
56 public:
57 Vec &L;
58 int d;
59 Real width;
60 WallsHard(System *s, const YAML::Node &c);
61 double operator()(Particle &p);
62 };
63
64 class WallLJ : public External {
65 public:
66 Vec &L;
67 int d;
68 Real cutoff;
69 Vec pos;
70 WallLJ(System *s, const YAML::Node &c);
71 double operator()(Particle &p);
72 };
73
74 class MovingInterface : public External {
75 public:
76 double &t;
77 int d;
78 Real B;
79 Real kappa;
80 Real v;
81 Real posStart;
82 MovingInterface(System *s, const YAML::Node &c);
83 double operator()(Particle &p);
84 };
85
86 class FixedLJ : public External {
87 public:
88 Vec &L;
89 Vec pos;
90 Real cutoff;
91 FixedLJ(System *s, const YAML::Node &c);
92 double operator()(Particle &p);
93 };
94
95 class HarmonicTrapPlanar : public External {
96 public:
97 int d;
98 Real A;
99 Real pos;
100 HarmonicTrapPlanar(System *s, const YAML::Node &c);
101 double operator()(Particle &p);
102 };
103
104 class Sine : public External {
105 public:
106 int dMod;
107 int dForce;
108 Real L;
109 Real A;
110 Real k;
111 Real phase;
112 Real Linv2pik;
113 Real ALby2pik;
114 Sine(System *s, const YAML::Node &c);
115 double operator()(Particle &p);
116 };
117
118 class ExternalTable : public External {
119 public:
120 ArrayI bins;
121 ArrayI stride;
122 Vec dr;
123 std::vector<Vec> Fext;
124
125 ExternalTable(System *s, const YAML::Node &c);
126 double operator()(Particle &p);
127 int index(const Vec &r);
128 };
129
130 107 class PairFunction {
131 public:
132 virtual ~PairFunction() = default;
133 virtual double operator()(Particle &p1, Particle &p2) = 0;
134 };
135
136 107 class TripleFunction {
137 public:
138 virtual ~TripleFunction() = default;
139 virtual double operator()(Particle &p1, Particle &p2, Particle &p3) = 0;
140 };
141
142 class Internal : public PairFunction, public TripleFunction {
143 int props = 0;
144
145 public:
146 enum Props : int {
147 DOES_E = 1 << 0,
148 DOES_F = 1 << 1,
149 THREEBODY = 1 << 2,
150 NEEDS_GATHER = 1 << 3,
151 };
152 double range;
153 bool newton3;
154 bool gather = false;
155 Vec &L;
156 Internal(int props, double range, bool newton3, System *s);
157 virtual ~Internal() = default;
158
159 107 inline bool doesE() { return props & DOES_E; }
160 107 inline bool doesF() { return props & DOES_F; }
161
5/6
✓ Branch 1 taken 83 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 662 times.
✓ Branch 4 taken 4149 times.
✓ Branch 5 taken 2977 times.
✓ Branch 6 taken 1969 times.
9840 inline bool threebody() { return props & THREEBODY; }
162
3/4
✓ Branch 0 taken 663 times.
✓ Branch 1 taken 4148 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4946 times.
9757 inline bool needsGather() { return props & NEEDS_GATHER; }
163
164 4148 virtual void reset() {}
165
166 virtual double operator()(Particle &p) { return 0.; }
167 virtual double operator()(Particle &p1, Particle &p2) = 0;
168 virtual double operator()(Particle &p1, Particle &p2, Particle &p3) { return 0.; }
169 };
170
171 class TestInternal : public Internal {
172 public:
173 bool doThreebody;
174 double rangesq;
175 TestInternal(System *s, const YAML::Node &c, bool newton3);
176 double operator()(Particle &p1, Particle &p2);
177 double operator()(Particle &p1, Particle &p2, Particle &p3);
178 };
179
180 class Ideal : public Internal {
181 public:
182 Ideal(System *s, const YAML::Node &c, bool newton3);
183 double operator()(Particle &p1, Particle &p2);
184 };
185
186 class Hard : public Internal {
187 public:
188 Hard(System *s, const YAML::Node &c, bool newton3);
189 double operator()(Particle &p1, Particle &p2);
190 };
191
192 class LJ : public Internal {
193 public:
194 double rangesq;
195 double Eshift;
196 LJ(System *s, const YAML::Node &c, bool newton3);
197 double operator()(Particle &p1, Particle &p2);
198 };
199
200 class WCA : public Internal {
201 public:
202 double rangesq;
203 WCA(System *s, const YAML::Node &c, bool newton3);
204 double operator()(Particle &p1, Particle &p2);
205 };
206
207 class Yukawa : public Internal {
208 public:
209 double kappa;
210 Yukawa(System *s, const YAML::Node &c, bool newton3);
211 double operator()(Particle &p1, Particle &p2);
212 };
213
214 class Stockmayer : public Internal {
215 public:
216 double mu;
217 double musq;
218 double epsilon6;
219 Stockmayer(System *s, const YAML::Node &c, bool newton3);
220 double operator()(Particle &p1, Particle &p2);
221 };
222
223 class GayBerne : public Internal {
224 public:
225 double rangesq;
226 double kappa;
227 double kappaprime;
228 double chi;
229 double chiprime;
230 GayBerne(System *s, const YAML::Node &c, bool newton3);
231 double operator()(Particle &p1, Particle &p2);
232 };
233
234 class SW : public Internal {
235 public:
236 Real a;
237 Real A;
238 Real B;
239 Real lambda;
240 Real gamma;
241 Real costheta0;
242 Real asq;
243 SW(System *s, const YAML::Node &c, bool newton3);
244 double operator()(Particle &p1, Particle &p2);
245 double operator()(Particle &p1, Particle &p2, Particle &p3);
246 double threebody(Particle &p1, Particle &p2, Particle &p3, int update = 0);
247 };
248
249 class SWOptimized : public Internal {
250 public:
251 std::vector<Particle> &particles;
252 std::vector<double> h;
253 std::vector<Vec> s;
254 std::vector<Eigen::Matrix<double, DIM, DIM>> T;
255 Real a;
256 Real A;
257 Real B;
258 Real lambda;
259 Real gamma;
260 Real costheta0;
261 Real asq;
262 SWOptimized(System *s, const YAML::Node &c, bool newton3);
263 void reset();
264 double operator()(Particle &p);
265 double operator()(Particle &p1, Particle &p2);
266 double accumulationPhase(Particle &p1, Particle &p2);
267 double gatherPhase(Particle &p1, Particle &p2);
268 };
269
270 class PotentialFactory {
271 public:
272 static std::map<std::string, External *(*)(System *s, const YAML::Node &c)> externalMap;
273 static std::map<std::string, Internal *(*)(System *s, const YAML::Node &c, bool newton3)>
274 internalMap;
275 static External *createExternal(System *s, const YAML::Node &externalConfig);
276 static std::vector<External *> createExternals(System *s, const YAML::Node &externalsConfig);
277 static Internal *createInternal(System *s, const YAML::Node &internalConfig, bool newton3);
278 };
279