testGravityDerivatives.c 45.9 KB
 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 /******************************************************************************* * This file is part of SWIFT. * Copyright (C) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * ******************************************************************************/ #include "../config.h" /* Some standard headers. */ #include #include #include #include #include /* Local headers. */ #include "swift.h" /*************************/ /* 0th order derivatives */ /*************************/ /** * @brief \f$\phi(r_x, r_y, r_z) \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 43 double D_000(double r_x, double r_y, double r_z, double r_inv) { return r_inv; }  44 45 46 47 48 49 50 51 52 53 54 55 56  /*************************/ /* 1st order derivatives */ /*************************/ /** * @brief \f$\frac{\partial\phi(r_x, r_y, r_z)}{\partial r_x} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 57 double D_100(double r_x, double r_y, double r_z, double r_inv) {  58 59 60 61 62 63 64 65 66 67 68 69  return -r_x * r_inv * r_inv * r_inv; } /** * @brief \f$\frac{\partial\phi(r_x, r_y, r_z)}{\partial r_x} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 70 double D_010(double r_x, double r_y, double r_z, double r_inv) {  71 72 73 74 75 76 77 78 79 80 81 82  return -r_y * r_inv * r_inv * r_inv; } /** * @brief \f$\frac{\partial\phi(r_x, r_y, r_z)}{\partial r_x} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 83 double D_001(double r_x, double r_y, double r_z, double r_inv) {  84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  return -r_z * r_inv * r_inv * r_inv; } /*************************/ /* 2nd order derivatives */ /*************************/ /** * @brief \f$\frac{\partial^2\phi(r_x, r_y, r_z)}{\partial r_x^2} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 100 double D_200(double r_x, double r_y, double r_z, double r_inv) {  101 102 103 104 105 106 107 108 109 110 111 112 113 114  const double r_inv2 = r_inv * r_inv; const double r_inv3 = r_inv * r_inv2; const double r_inv5 = r_inv3 * r_inv2; return 3. * r_x * r_x * r_inv5 - r_inv3; } /** * @brief \f$\frac{\partial^2\phi(r_x, r_y, r_z)}{\partial r_y^2} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 115 double D_020(double r_x, double r_y, double r_z, double r_inv) {  116 117 118 119 120 121 122 123 124 125 126 127 128 129  const double r_inv2 = r_inv * r_inv; const double r_inv3 = r_inv * r_inv2; const double r_inv5 = r_inv3 * r_inv2; return 3. * r_y * r_y * r_inv5 - r_inv3; } /** * @brief \f$\frac{\partial^2\phi(r_x, r_y, r_z)}{\partial r_z^2} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 130 double D_002(double r_x, double r_y, double r_z, double r_inv) {  131 132 133 134 135 136 137 138 139 140 141 142 143 144 145  const double r_inv2 = r_inv * r_inv; const double r_inv3 = r_inv * r_inv2; const double r_inv5 = r_inv3 * r_inv2; return 3. * r_z * r_z * r_inv5 - r_inv3; } /** * @brief \f$\frac{\partial^2\phi(r_x, r_y, r_z)}{\partial r_x\partial r_y} * \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 146 double D_110(double r_x, double r_y, double r_z, double r_inv) {  147 148 149 150 151 152 153 154 155 156 157 158 159 160  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; return 3. * r_x * r_y * r_inv5; } /** * @brief \f$\frac{\partial^2\phi(r_x, r_y, r_z)}{\partial r_x\partial r_z} * \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 161 double D_101(double r_x, double r_y, double r_z, double r_inv) {  162 163 164 165 166 167 168 169 170 171 172 173 174 175  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; return 3. * r_x * r_z * r_inv5; } /** * @brief \f$\frac{\partial^2\phi(r_x, r_y, r_z)}{\partial r_y\partial r_z} * \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 176 double D_011(double r_x, double r_y, double r_z, double r_inv) {  177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; return 3. * r_y * r_z * r_inv5; } /*************************/ /* 3rd order derivatives */ /*************************/ /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_x^3} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 194 double D_300(double r_x, double r_y, double r_z, double r_inv) {  195 196 197 198 199 200 201 202 203 204 205 206 207 208  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; const double r_inv7 = r_inv5 * r_inv2; return -15. * r_x * r_x * r_x * r_inv7 + 9. * r_x * r_inv5; } /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_y^3} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 209 double D_030(double r_x, double r_y, double r_z, double r_inv) {  210 211 212 213 214 215 216 217 218 219 220 221 222 223  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; const double r_inv7 = r_inv5 * r_inv2; return -15. * r_y * r_y * r_y * r_inv7 + 9. * r_y * r_inv5; } /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_z^3} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 224 double D_003(double r_x, double r_y, double r_z, double r_inv) {  225 226 227 228 229 230 231 232 233 234 235 236 237 238 239  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; const double r_inv7 = r_inv5 * r_inv2; return -15. * r_z * r_z * r_z * r_inv7 + 9. * r_z * r_inv5; } /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_x^2\partial r_y} * \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 240 double D_210(double r_x, double r_y, double r_z, double r_inv) {  241 242 243 244 245 246 247 248 249 250 251 252 253 254 255  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; const double r_inv7 = r_inv5 * r_inv2; return -15. * r_x * r_x * r_y * r_inv7 + 3. * r_y * r_inv5; } /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_x^2\partial r_z} * \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 256 double D_201(double r_x, double r_y, double r_z, double r_inv) {  257 258 259 260 261 262 263 264 265 266 267 268 269 270 271  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; const double r_inv7 = r_inv5 * r_inv2; return -15. * r_x * r_x * r_z * r_inv7 + 3. * r_z * r_inv5; } /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_x\partial r_y^2} * \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 272 double D_120(double r_x, double r_y, double r_z, double r_inv) {  273 274 275 276 277 278 279 280 281 282 283 284 285 286 287  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; const double r_inv7 = r_inv5 * r_inv2; return -15. * r_x * r_y * r_y * r_inv7 + 3. * r_x * r_inv5; } /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_y^2\partial r_z} * \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 288 double D_021(double r_x, double r_y, double r_z, double r_inv) {  289 290 291 292 293 294 295 296 297 298 299 300 301 302 303  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; const double r_inv7 = r_inv5 * r_inv2; return -15. * r_z * r_y * r_y * r_inv7 + 3. * r_z * r_inv5; } /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_x\partial r_z^2} * \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 304 double D_102(double r_x, double r_y, double r_z, double r_inv) {  305 306 307 308 309 310 311 312 313 314 315 316 317 318 319  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; const double r_inv7 = r_inv5 * r_inv2; return -15. * r_x * r_z * r_z * r_inv7 + 3. * r_x * r_inv5; } /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_y\partial r_z^2} * \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 320 double D_012(double r_x, double r_y, double r_z, double r_inv) {  321 322 323 324 325 326 327 328 329 330 331 332 333 334 335  const double r_inv2 = r_inv * r_inv; const double r_inv5 = r_inv2 * r_inv2 * r_inv; const double r_inv7 = r_inv5 * r_inv2; return -15. * r_y * r_z * r_z * r_inv7 + 3. * r_y * r_inv5; } /** * @brief \f$\frac{\partial^3\phi(r_x, r_y, r_z)}{\partial r_z\partial * r_y\partial r_z} \f$. * * @param r_x x-coordinate of the distance vector (\f$r_x \f$). * @param r_y y-coordinate of the distance vector (\f$r_y \f$). * @param r_z z-coordinate of the distance vector (\f$r_z \f$). * @param r_inv Inverse of the norm of the distance vector (\f$|r|^{-1} \f$) */  Matthieu Schaller committed Jul 03, 2018 336 double D_111(double r_x, double r_y, double r_z, double r_inv) {  337 338 339 340 341 342 343 344 345 346 347 348 349 350  const double r_inv3 = r_inv * r_inv * r_inv; const double r_inv7 = r_inv3 * r_inv3 * r_inv; return -15. * r_x * r_y * r_z * r_inv7; } /*********************************/ /* 4th order gravity derivatives */ /*********************************/ /** * @brief Compute \f$\frac{\partial^4}{ \partial_z^4 }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 351 double D_004(double r_x, double r_y, double r_z, double r_inv) {  352 353 354 355 356 357 358 359 360 361 362 363 364 365  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_z * r_z * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 6.0 * (r_z * r_z) + 3. * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0; /* 5 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_y^1 \partial_z^3 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 366 double D_013(double r_x, double r_y, double r_z, double r_inv) {  367 368 369 370 371 372 373 374 375 376 377 378 379  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_z * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_y * r_z); /* 11 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_y^2 \partial_z^2 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 380 double D_022(double r_x, double r_y, double r_z, double r_inv) {  381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_z * r_z) + 3. * r_inv * r_inv * r_inv * r_inv * r_inv; /* 11 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_y^3 \partial_z^1 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 397 double D_031(double r_x, double r_y, double r_z, double r_inv) {  398 399 400 401 402 403 404 405 406 407 408 409  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_y * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_y * r_z); /* 11 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_y^4 }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 410 double D_040(double r_x, double r_y, double r_z, double r_inv) {  411 412 413 414 415 416 417 418 419 420 421 422 423 424  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_y * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 6.0 * (r_y * r_y) + 3. * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0; /* 5 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^1 \partial_z^3 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 425 double D_103(double r_x, double r_y, double r_z, double r_inv) {  426 427 428 429 430 431 432 433 434 435 436 437 438  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_z * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_z); /* 11 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^1 \partial_y^1 \partial_z^2 * }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 439 double D_112(double r_x, double r_y, double r_z, double r_inv) {  440 441 442 443 444 445 446 447 448 449 450 451 452  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_y * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_y); /* 13 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^1 \partial_y^2 \partial_z^1 * }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 453 double D_121(double r_x, double r_y, double r_z, double r_inv) {  454 455 456 457 458 459 460 461 462 463 464 465 466  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_y * r_y * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_z); /* 13 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^1 \partial_y^3 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 467 double D_130(double r_x, double r_y, double r_z, double r_inv) {  468 469 470 471 472 473 474 475 476 477 478 479 480  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_y * r_y * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_y); /* 11 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^2 \partial_z^2 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 481 double D_202(double r_x, double r_y, double r_z, double r_inv) {  482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_z * r_z) + 3. * r_inv * r_inv * r_inv * r_inv * r_inv; /* 11 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^2 \partial_y^1 \partial_z^1 * }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 498 double D_211(double r_x, double r_y, double r_z, double r_inv) {  499 500 501 502 503 504 505 506 507 508 509 510 511  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_y * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_z); /* 13 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^2 \partial_y^2 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 512 double D_220(double r_x, double r_y, double r_z, double r_inv) {  513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_y * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y) + 3. * r_inv * r_inv * r_inv * r_inv * r_inv; /* 11 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^3 \partial_z^1 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 529 double D_301(double r_x, double r_y, double r_z, double r_inv) {  530 531 532 533 534 535 536 537 538 539 540 541 542  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_z); /* 11 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^3 \partial_y^1 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 543 double D_310(double r_x, double r_y, double r_z, double r_inv) {  544 545 546 547 548 549 550 551 552 553 554 555  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_y); /* 11 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^4}{ \partial_x^4 }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 556 double D_400(double r_x, double r_y, double r_z, double r_inv) {  557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573  return +105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x * r_x) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 6.0 * (r_x * r_x) + 3. * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0; /* 5 zero-valued terms not written out */ } /*********************************/ /* 5th order gravity derivatives */ /*********************************/ /** * @brief Compute \f$\frac{\partial^5}{ \partial_z^5 }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 574 double D_005(double r_x, double r_y, double r_z, double r_inv) {  575 576 577 578 579 580 581 582 583 584 585 586 587 588 589  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_z * r_z * r_z * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 10.0 * (r_z * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 15.0 * (r_z); /* 26 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_y^1 \partial_z^4 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 590 double D_014(double r_x, double r_y, double r_z, double r_inv) {  591 592 593 594 595 596 597 598 599 600 601 602 603 604 605  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_z * r_z * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 6.0 * (r_y * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_y); /* 42 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_y^2 \partial_z^3 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 606 double D_023(double r_x, double r_y, double r_z, double r_inv) {  607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_z * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_y * r_y * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_z * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_z); /* 44 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_y^3 \partial_z^2 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 624 double D_032(double r_x, double r_y, double r_z, double r_inv) {  625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_y * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_y) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_y * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_y); /* 44 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_y^4 \partial_z^1 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 642 double D_041(double r_x, double r_y, double r_z, double r_inv) {  643 644 645 646 647 648 649 650 651 652 653 654 655 656  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_y * r_y * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 6.0 * (r_y * r_y * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_z); /* 42 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_y^5 }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 657 double D_050(double r_x, double r_y, double r_z, double r_inv) {  658 659 660 661 662 663 664 665 666 667 668 669 670 671 672  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_y * r_y * r_y) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 10.0 * (r_y * r_y * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 15.0 * (r_y); /* 26 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^1 \partial_z^4 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 673 double D_104(double r_x, double r_y, double r_z, double r_inv) {  674 675 676 677 678 679 680 681 682 683 684 685 686 687 688  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_z * r_z * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 6.0 * (r_x * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x); /* 42 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^1 \partial_y^1 \partial_z^3 * }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 689 double D_113(double r_x, double r_y, double r_z, double r_inv) {  690 691 692 693 694 695 696 697 698 699 700 701 702  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_y * r_z * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_y * r_z); /* 48 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^1 \partial_y^2 \partial_z^2 * }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 703 double D_122(double r_x, double r_y, double r_z, double r_inv) {  704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_y * r_y * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_y * r_y) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x); /* 48 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^1 \partial_y^3 \partial_z^1 * }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 720 double D_131(double r_x, double r_y, double r_z, double r_inv) {  721 722 723 724 725 726 727 728 729 730 731 732 733  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_y * r_y * r_y * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_y * r_z); /* 48 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^1 \partial_y^4 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 734 double D_140(double r_x, double r_y, double r_z, double r_inv) {  735 736 737 738 739 740 741 742 743 744 745 746 747 748 749  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_y * r_y * r_y * r_y) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 6.0 * (r_x * r_y * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x); /* 42 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^2 \partial_z^3 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 750 double D_203(double r_x, double r_y, double r_z, double r_inv) {  751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_z * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_x * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_z * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_z); /* 44 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^2 \partial_y^1 \partial_z^2 * }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 768 double D_212(double r_x, double r_y, double r_z, double r_inv) {  769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_y * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_y) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y); /* 48 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^2 \partial_y^2 \partial_z^1 * }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 785 double D_221(double r_x, double r_y, double r_z, double r_inv) {  786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_y * r_y * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_z); /* 48 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^2 \partial_y^3 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 802 double D_230(double r_x, double r_y, double r_z, double r_inv) {  803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_y * r_y * r_y) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_x * r_y) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_y * r_y * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_y); /* 44 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^3 \partial_z^2 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 820 double D_302(double r_x, double r_y, double r_z, double r_inv) {  821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x * r_z * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_z * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x); /* 44 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^3 \partial_y^1 \partial_z^1 * }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 838 double D_311(double r_x, double r_y, double r_z, double r_inv) {  839 840 841 842 843 844 845 846 847 848 849 850 851  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x * r_y * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_y * r_z); /* 48 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^3 \partial_y^2 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 852 double D_320(double r_x, double r_y, double r_z, double r_inv) {  853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x * r_y * r_y) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x * r_y * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_x); /* 44 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^4 \partial_z^1 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 870 double D_401(double r_x, double r_y, double r_z, double r_inv) {  871 872 873 874 875 876 877 878 879 880 881 882 883 884 885  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x * r_x * r_z) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 6.0 * (r_x * r_x * r_z) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_z); /* 42 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^4 \partial_y^1 }\phi(x, y, * z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 886 double D_410(double r_x, double r_y, double r_z, double r_inv) {  887 888 889 890 891 892 893 894 895 896 897 898 899 900  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x * r_x * r_y) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 6.0 * (r_x * r_x * r_y) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 3.0 * (r_y); /* 42 zero-valued terms not written out */ } /** * @brief Compute \f$\frac{\partial^5}{ \partial_x^5 }\phi(x, y, z} \f$. * * Note that r_inv = 1./sqrt(r_x^2 + r_y^2 + r_z^2) */  Matthieu Schaller committed Jul 03, 2018 901 double D_500(double r_x, double r_y, double r_z, double r_inv) {  902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923  return -945. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * (r_x * r_x * r_x * r_x * r_x) + 105. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 10.0 * (r_x * r_x * r_x) - 15. * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * r_inv * 15.0 * (r_x); /* 26 zero-valued terms not written out */ } void test(double x, double y, double tol, double min, const char* name) { double diff = fabs(x - y); double norm = 0.5 * fabs(x + y); if (diff > norm * tol && norm > min) error( "Relative difference (%e) for '%s' (swift=%e) and (exact=%e) exceeds " "tolerance (%e)", diff / norm, name, x, y, tol); /* else */ /* message("'%s' (%e -- %e) OK!", name, x, y); */ }  924 int main(int argc, char* argv[]) {  925 926 927 928 929 930  /* Initialize CPU frequency, this also starts time. */ unsigned long long cpufreq = 0; clocks_set_cpufreq(cpufreq); /* Relative tolerance */  Matthieu Schaller committed Sep 12, 2017 931  double tol = 1e-4;  932 933 934 935 936 937  /* Get some randomness going */ const int seed = time(NULL); message("Seed = %d", seed); srand(seed);  Matthieu Schaller committed Sep 05, 2019 938  /* Start by testing M2L */  939 940 941 942 943 944  for (int i = 0; i < 100; ++i) { const double dx = 100. * ((double)rand() / (RAND_MAX)); const double dy = 100. * ((double)rand() / (RAND_MAX)); const double dz = 100. * ((double)rand() / (RAND_MAX));  Matthieu Schaller committed Sep 05, 2019 945  message("Testing M2L gravity for r=(%e %e %e)", dx, dy, dz);  946   Matthieu Schaller committed Aug 31, 2018 947 948 949 950 951 952 953  const double r_s = 100. * ((double)rand() / (RAND_MAX)); const double r_s_inv = 1. / r_s; const int periodic = 0; message("Mesh scale r_s=%e periodic=%d", r_s, periodic);  954 955 956  /* Compute distance */ const double r2 = dx * dx + dy * dy + dz * dz; const double r_inv = 1. / sqrt(r2);  957 958  const double r = r2 * r_inv; const double eps = r / 10.;  959 960  /* Compute all derivatives */  Matthieu Schaller committed Sep 11, 2017 961  struct potential_derivatives_M2L pot;  Matthieu Schaller committed Sep 05, 2019 962  bzero(&pot, sizeof(struct potential_derivatives_M2L));  963 964  potential_derivatives_compute_M2L(dx, dy, dz, r2, r_inv, eps, periodic, r_s_inv, &pot);  965 966 967 968 969 970 971  /* Minimal value we care about */ const double min = 1e-9; /* Now check everything... */ /* 0th order terms */  Matthieu Schaller committed Sep 05, 2019 972  test(pot.D_000, D_000(dx, dy, dz, r_inv), tol, min, "M2L D_000");  973 974 975 976  #if SELF_GRAVITY_MULTIPOLE_ORDER > 0 /* 1st order terms */  Matthieu Schaller committed Sep 05, 2019 977 978 979  test(pot.D_100, D_100(dx, dy, dz, r_inv), tol, min, "M2L D_100"); test(pot.D_010, D_010(dx, dy, dz, r_inv), tol, min, "M2L D_010"); test(pot.D_001, D_001(dx, dy, dz, r_inv), tol, min, "M2L D_001");  980 981 982 983 #endif #if SELF_GRAVITY_MULTIPOLE_ORDER > 1 /* 2nd order terms */  Matthieu Schaller committed Sep 05, 2019 984 985 986 987 988 989  test(pot.D_200, D_200(dx, dy, dz, r_inv), tol, min, "M2L D_200"); test(pot.D_020, D_020(dx, dy, dz, r_inv), tol, min, "M2L D_020"); test(pot.D_002, D_002(dx, dy, dz, r_inv), tol, min, "M2L D_002"); test(pot.D_110, D_110(dx, dy, dz, r_inv), tol, min, "M2L D_110"); test(pot.D_101, D_101(dx, dy, dz, r_inv), tol, min, "M2L D_101"); test(pot.D_011, D_011(dx, dy, dz, r_inv), tol, min, "M2L D_011");  990 991 992 #endif #if SELF_GRAVITY_MULTIPOLE_ORDER > 2  Matthieu Schaller committed Sep 28, 2017 993  tol *= 2.5;  Matthieu Schaller committed Sep 12, 2017 994   995  /* 3rd order terms */  Matthieu Schaller committed Sep 05, 2019 996 997 998 999 1000 1001 1002 1003 1004 1005  test(pot.D_300, D_300(dx, dy, dz, r_inv), tol, min, "M2L D_300"); test(pot.D_030, D_030(dx, dy, dz, r_inv), tol, min, "M2L D_030"); test(pot.D_003, D_003(dx, dy, dz, r_inv), tol, min, "M2L D_003"); test(pot.D_210, D_210(dx, dy, dz, r_inv), tol, min, "M2L D_210"); test(pot.D_201, D_201(dx, dy, dz, r_inv), tol, min, "M2L D_201"); test(pot.D_120, D_120(dx, dy, dz, r_inv), tol, min, "M2L D_120"); test(pot.D_021, D_021(dx, dy, dz, r_inv), tol, min, "M2L D_021"); test(pot.D_102, D_102(dx, dy, dz, r_inv), tol, min, "M2L D_102"); test(pot.D_012, D_012(dx, dy, dz, r_inv), tol, min, "M2L D_012"); test(pot.D_111, D_111(dx, dy, dz, r_inv), tol, min, "M2L D_111");  1006 1007 1008 1009 #endif #if SELF_GRAVITY_MULTIPOLE_ORDER > 3 /* 4th order terms */  Matthieu Schaller committed Sep 05, 2019 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024  test(pot.D_400, D_400(dx, dy, dz, r_inv), tol, min, "M2L D_400"); test(pot.D_040, D_040(dx, dy, dz, r_inv), tol, min, "M2L D_040"); test(pot.D_004, D_004(dx, dy, dz, r_inv), tol, min, "M2L D_004"); test(pot.D_310, D_310(dx, dy, dz, r_inv), tol, min, "M2L D_310"); test(pot.D_301, D_301(dx, dy, dz, r_inv), tol, min, "M2L D_301"); test(pot.D_130, D_130(dx, dy, dz, r_inv), tol, min, "M2L D_130"); test(pot.D_031, D_031(dx, dy, dz, r_inv), tol, min, "M2L D_031"); test(pot.D_103, D_103(dx, dy, dz, r_inv), tol, min, "M2L D_103"); test(pot.D_013, D_013(dx, dy, dz, r_inv), tol, min, "M2L D_013"); test(pot.D_220, D_220(dx, dy, dz, r_inv), tol, min, "M2L D_220"); test(pot.D_202, D_202(dx, dy, dz, r_inv), tol, min, "M2L D_202"); test(pot.D_022, D_022(dx, dy, dz, r_inv), tol, min, "M2L D_022"); test(pot.D_211, D_211(dx, dy, dz, r_inv), tol, min, "M2L D_211"); test(pot.D_121, D_121(dx, dy, dz, r_inv), tol, min, "M2L D_121"); test(pot.D_112, D_112(dx, dy, dz, r_inv), tol, min, "M2L D_112");  1025 #endif  Matthieu Schaller committed Aug 16, 2017 1026 1027 #if SELF_GRAVITY_MULTIPOLE_ORDER > 4  Matthieu Schaller committed Sep 28, 2017 1028  tol *= 2.5;  Matthieu Schaller committed Sep 12, 2017 1029   Matthieu Schaller committed Aug 16, 2017 1030  /* 5th order terms */  Matthieu Schaller committed Sep 05, 2019 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051  test(pot.D_500, D_500(dx, dy, dz, r_inv), tol, min, "M2L D_500"); test(pot.D_050, D_050(dx, dy, dz, r_inv), tol, min, "M2L D_050"); test(pot.D_005, D_005(dx, dy, dz, r_inv), tol, min, "M2L D_005"); test(pot.D_410, D_410(dx, dy, dz, r_inv), tol, min, "M2L D_410"); test(pot.D_401, D_401(dx, dy, dz, r_inv), tol, min, "M2L D_401"); test(pot.D_140, D_140(dx, dy, dz, r_inv), tol, min, "M2L D_140"); test(pot.D_041, D_041(dx, dy, dz, r_inv), tol, min, "M2L D_041"); test(pot.D_104, D_104(dx, dy, dz, r_inv), tol, min, "M2L D_104"); test(pot.D_014, D_014(dx, dy, dz, r_inv), tol, min, "M2L D_014"); test(pot.D_320, D_320(dx, dy, dz, r_inv), tol, min, "M2L D_320"); test(pot.D_302, D_302(dx, dy, dz, r_inv), tol, min, "M2L D_302"); test(pot.D_230, D_230(dx, dy, dz, r_inv), tol, min, "M2L D_230"); test(pot.D_032, D_032(dx, dy, dz, r_inv), tol, min, "M2L D_032"); test(pot.D_203, D_203(dx, dy, dz, r_inv), tol, min, "M2L D_203"); test(pot.D_023, D_023(dx, dy, dz, r_inv), tol, min, "M2L D_023"); test(pot.D_311, D_311(dx, dy, dz, r_inv), tol, min, "M2L D_311"); test(pot.D_131, D_131(dx, dy, dz, r_inv), tol, min, "M2L D_131"); test(pot.D_113, D_113(dx, dy, dz, r_inv), tol, min, "M2L D_113"); test(pot.D_122, D_122(dx, dy, dz, r_inv), tol, min, "M2L D_122"); test(pot.D_212, D_212(dx, dy, dz, r_inv), tol, min, "M2L D_212"); test(pot.D_221, D_221(dx, dy, dz, r_inv), tol, min, "M2L D_221");  Matthieu Schaller committed Aug 16, 2017 1052 1053  #endif  1054 1055  message("All good!"); }  Matthieu Schaller committed Sep 05, 2019 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080  /* And now the M2P terms */ for (int i = 0; i < 100; ++i) { const double dx = 100. * ((double)rand() / (RAND_MAX)); const double dy = 100. * ((double)rand() / (RAND_MAX)); const double dz = 100. * ((double)rand() / (RAND_MAX)); message("Testing M2P gravity for r=(%e %e %e)", dx, dy, dz); const double r_s = 100. * ((double)rand() / (RAND_MAX)); const double r_s_inv = 1. / r_s; const int periodic = 0; message("Mesh scale r_s=%e periodic=%d", r_s, periodic); /* Compute distance */ const double r2 = dx * dx + dy * dy + dz * dz; const double r_inv = 1. / sqrt(r2); const double r = r2 * r_inv; const double eps = r / 10.; /* Compute all derivatives */ struct potential_derivatives_M2P pot;  Matthieu Schaller committed Sep 05, 2019 1081  bzero(&pot, sizeof(struct potential_derivatives_M2P));  Matthieu Schaller committed Sep 05, 2019 1082 1083 1084 1085 1086 1087  potential_derivatives_compute_M2P(dx, dy, dz, r2, r_inv, eps, periodic, r_s_inv, &pot); /* Minimal value we care about */ const double min = 1e-9;  Matthieu Schaller committed Sep 05, 2019 1088 1089 1090 1091  /* Now check everything... * * Note that the M2P derivatives are computed to order * SELF_GRAVITY_MULTIPOLE_ORDER + 1 by the function above. */  Matthieu Schaller committed Sep 05, 2019 1092 1093 1094 1095 1096 1097 1098 1099  /* 0th order terms */ test(pot.D_000, D_000(dx, dy, dz, r_inv), tol, min, "M2P D_000"); /* 1st order terms */ test(pot.D_100, D_100(dx, dy, dz, r_inv), tol, min, "M2P D_100"); test(pot.D_010, D_010(dx, dy, dz, r_inv), tol, min, "M2P D_010"); test(pot.D_001, D_001(dx, dy, dz, r_inv), tol, min, "M2P D_001");  Matthieu Schaller committed Sep 05, 2019 1100 1101  #if SELF_GRAVITY_MULTIPOLE_ORDER > 0  Matthieu Schaller committed Sep 05, 2019 1102 1103 1104 1105 1106 1107 1108 1109 1110  /* 2nd order terms */ test(pot.D_200, D_200(dx, dy, dz, r_inv), tol, min, "M2P D_200"); test(pot.D_020, D_020(dx, dy, dz, r_inv), tol, min, "M2P D_020"); test(pot.D_002, D_002(dx, dy, dz, r_inv), tol, min, "M2P D_002"); test(pot.D_110, D_110(dx, dy, dz, r_inv), tol, min, "M2P D_110"); test(pot.D_101, D_101(dx, dy, dz, r_inv), tol, min, "M2P D_101"); test(pot.D_011, D_011(dx, dy, dz, r_inv), tol, min, "M2P D_011"); #endif  Matthieu Schaller committed Sep 05, 2019 1111 #if SELF_GRAVITY_MULTIPOLE_ORDER > 1  Matthieu Schaller committed Sep 05, 2019 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126  tol *= 2.5; /* 3rd order terms */ test(pot.D_300, D_300(dx, dy, dz, r_inv), tol, min, "M2P D_300"); test(pot.D_030, D_030(dx, dy, dz, r_inv), tol, min, "M2P D_030"); test(pot.D_003, D_003(dx, dy, dz, r_inv), tol, min, "M2P D_003"); test(pot.D_210, D_210(dx, dy, dz, r_inv), tol, min, "M2P D_210"); test(pot.D_201, D_201(dx, dy, dz, r_inv), tol, min, "M2P D_201"); test(pot.D_120, D_120(dx, dy, dz, r_inv), tol, min, "M2P D_120"); test(pot.D_021, D_021(dx, dy, dz, r_inv), tol, min, "M2P D_021"); test(pot.D_102, D_102(dx, dy, dz, r_inv), tol, min, "M2P D_102"); test(pot.D_012, D_012(dx, dy, dz, r_inv), tol, min, "M2P D_012"); test(pot.D_111, D_111(dx, dy, dz, r_inv), tol, min, "M2P D_111"); #endif  Matthieu Schaller committed Sep 05, 2019 1127 #if SELF_GRAVITY_MULTIPOLE_ORDER > 2  Matthieu Schaller committed Sep 05, 2019 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145  /* 4th order terms */ test(pot.D_400, D_400(dx, dy, dz, r_inv), tol, min, "M2P D_400"); test(pot.D_040, D_040(dx, dy, dz, r_inv), tol, min, "M2P D_040"); test(pot.D_004, D_004(dx, dy, dz, r_inv), tol, min, "M2P D_004"); test(pot.D_310, D_310(dx, dy, dz, r_inv), tol, min, "M2P D_310"); test(pot.D_301, D_301(dx, dy, dz, r_inv), tol, min, "M2P D_301"); test(pot.D_130, D_130(dx, dy, dz, r_inv), tol, min, "M2P D_130"); test(pot.D_031, D_031(dx, dy, dz, r_inv), tol, min, "M2P D_031"); test(pot.D_103, D_103(dx, dy, dz, r_inv), tol, min, "M2P D_103"); test(pot.D_013, D_013(dx, dy, dz, r_inv), tol, min, "M2P D_013"); test(pot.D_220, D_220(dx, dy, dz, r_inv), tol, min, "M2P D_220"); test(pot.D_202, D_202(dx, dy, dz, r_inv), tol, min, "M2P D_202"); test(pot.D_022, D_022(dx, dy, dz, r_inv), tol, min, "M2P D_022"); test(pot.D_211, D_211(dx, dy, dz, r_inv), tol, min, "M2P D_211"); test(pot.D_121, D_121(dx, dy, dz, r_inv), tol, min, "M2P D_121"); test(pot.D_112, D_112(dx, dy, dz, r_inv), tol, min, "M2P D_112"); #endif  Matthieu Schaller committed Sep 05, 2019 1146 #if SELF_GRAVITY_MULTIPOLE_ORDER > 3  Matthieu Schaller committed Sep 05, 2019 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177  tol *= 2.5; /* 5th order terms */ test(pot.D_500, D_500(dx, dy, dz, r_inv), tol, min, "M2P D_500"); test(pot.D_050, D_050(dx, dy, dz, r_inv), tol, min, "M2P D_050"); test(pot.D_005, D_005(dx, dy, dz, r_inv), tol, min, "M2P D_005"); test(pot.D_410, D_410(dx, dy, dz, r_inv), tol, min, "M2P D_410"); test(pot.D_401, D_401(dx, dy, dz, r_inv), tol, min, "M2P D_401"); test(pot.D_140, D_140(dx, dy, dz, r_inv), tol, min, "M2P D_140"); test(pot.D_041, D_041(dx, dy, dz, r_inv), tol, min, "M2P D_041"); test(pot.D_104, D_104(dx, dy, dz, r_inv), tol, min, "M2P D_104"); test(pot.D_014, D_014(dx, dy, dz, r_inv), tol, min, "M2P D_014"); test(pot.D_320, D_320(dx, dy, dz, r_inv), tol, min, "M2P D_320"); test(pot.D_302, D_302(dx, dy, dz, r_inv), tol, min, "M2P D_302"); test(pot.D_230, D_230(dx, dy, dz, r_inv), tol, min, "M2P D_230"); test(pot.D_032, D_032(dx, dy, dz, r_inv), tol, min, "M2P D_032"); test(pot.D_203, D_203(dx, dy, dz, r_inv), tol, min, "M2P D_203"); test(pot.D_023, D_023(dx, dy, dz, r_inv), tol, min, "M2P D_023"); test(pot.D_311, D_311(dx, dy, dz, r_inv), tol, min, "M2P D_311"); test(pot.D_131, D_131(dx, dy, dz, r_inv), tol, min, "M2P D_131"); test(pot.D_113, D_113(dx, dy, dz, r_inv), tol, min, "M2P D_113"); test(pot.D_122, D_122(dx, dy, dz, r_inv), tol, min, "M2P D_122"); test(pot.D_212, D_212(dx, dy, dz, r_inv), tol, min, "M2P D_212"); test(pot.D_221, D_221(dx, dy, dz, r_inv), tol, min, "M2P D_221"); #endif message("All good!"); } /* All happy */  1178 1179  return 0; }