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