/usr/lib/python2.7/dist-packages/PySPH-1.0a4.dev0-py2.7-linux-x86_64.egg/pysph/sph/integrator_step.py is in python-pysph 0~20160514.git91867dc-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | """Integrator steps for different schemes.
Implement as many stages as needed.
"""
###############################################################################
# `IntegratorStep` class
###############################################################################
class IntegratorStep(object):
"""Subclass this and implement the methods ``initialize``, ``stage1`` etc.
Use the same conventions as the equations.
"""
def __repr__(self):
return '%s()'%(self.__class__.__name__)
###############################################################################
# `EulerStep` class
###############################################################################
class EulerStep(IntegratorStep):
"""Fast but inaccurate integrator. Use this for testing"""
def stage1(self, d_idx, d_u, d_v, d_w, d_au, d_av, d_aw, d_x, d_y,
d_z, d_rho, d_arho, dt):
d_u[d_idx] += dt*d_au[d_idx]
d_v[d_idx] += dt*d_av[d_idx]
d_w[d_idx] += dt*d_aw[d_idx]
d_x[d_idx] += dt*d_u[d_idx]
d_y[d_idx] += dt*d_v[d_idx]
d_z[d_idx] += dt*d_w[d_idx]
d_rho[d_idx] += dt*d_arho[d_idx]
###############################################################################
# `WCSPHStep` class
###############################################################################
class WCSPHStep(IntegratorStep):
"""Standard Predictor Corrector integrator for the WCSPH formulation
Use this integrator for WCSPH formulations. In the predictor step,
the particles are advanced to `t + dt/2`. The particles are then
advanced with the new force computed at this position.
This integrator can be used in PEC or EPEC mode.
The same integrator can be used for other problems. Like for
example solid mechanics (see SolidMechStep)
"""
def initialize(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho):
d_x0[d_idx] = d_x[d_idx]
d_y0[d_idx] = d_y[d_idx]
d_z0[d_idx] = d_z[d_idx]
d_u0[d_idx] = d_u[d_idx]
d_v0[d_idx] = d_v[d_idx]
d_w0[d_idx] = d_w[d_idx]
d_rho0[d_idx] = d_rho[d_idx]
def stage1(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho, d_au, d_av,
d_aw, d_ax, d_ay, d_az, d_arho, dt):
dtb2 = 0.5*dt
d_u[d_idx] = d_u0[d_idx] + dtb2*d_au[d_idx]
d_v[d_idx] = d_v0[d_idx] + dtb2*d_av[d_idx]
d_w[d_idx] = d_w0[d_idx] + dtb2*d_aw[d_idx]
d_x[d_idx] = d_x0[d_idx] + dtb2 * d_ax[d_idx]
d_y[d_idx] = d_y0[d_idx] + dtb2 * d_ay[d_idx]
d_z[d_idx] = d_z0[d_idx] + dtb2 * d_az[d_idx]
# Update densities and smoothing lengths from the accelerations
d_rho[d_idx] = d_rho0[d_idx] + dtb2 * d_arho[d_idx]
def stage2(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho, d_au, d_av,
d_aw, d_ax, d_ay, d_az, d_arho, dt):
d_u[d_idx] = d_u0[d_idx] + dt*d_au[d_idx]
d_v[d_idx] = d_v0[d_idx] + dt*d_av[d_idx]
d_w[d_idx] = d_w0[d_idx] + dt*d_aw[d_idx]
d_x[d_idx] = d_x0[d_idx] + dt * d_ax[d_idx]
d_y[d_idx] = d_y0[d_idx] + dt * d_ay[d_idx]
d_z[d_idx] = d_z0[d_idx] + dt * d_az[d_idx]
# Update densities and smoothing lengths from the accelerations
d_rho[d_idx] = d_rho0[d_idx] + dt * d_arho[d_idx]
###############################################################################
# `WCSPHTVDRK3` Integrator
###############################################################################
class WCSPHTVDRK3Step(IntegratorStep):
r"""TVD RK3 stepper for WCSPH
This integrator requires :math:`2` stages for the storage of the
acceleration variables.
"""
def initialize(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho):
d_x0[d_idx] = d_x[d_idx]
d_y0[d_idx] = d_y[d_idx]
d_z0[d_idx] = d_z[d_idx]
d_u0[d_idx] = d_u[d_idx]
d_v0[d_idx] = d_v[d_idx]
d_w0[d_idx] = d_w[d_idx]
d_rho0[d_idx] = d_rho[d_idx]
def stage1(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho,
d_au, d_av, d_aw, d_ax, d_ay, d_az, d_arho,
dt):
# update velocities
d_u[d_idx] = d_u0[d_idx] + dt * d_au[d_idx]
d_v[d_idx] = d_v0[d_idx] + dt * d_av[d_idx]
d_w[d_idx] = d_w0[d_idx] + dt * d_aw[d_idx]
# update positions
d_x[d_idx] = d_x0[d_idx] + dt * d_ax[d_idx]
d_y[d_idx] = d_y0[d_idx] + dt * d_ay[d_idx]
d_z[d_idx] = d_z0[d_idx] + dt * d_az[d_idx]
# update density
d_rho[d_idx] = d_rho0[d_idx] + dt * d_arho[d_idx]
def stage2(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho, d_au, d_av,
d_aw, d_ax, d_ay, d_az, d_arho, dt):
# update velocities
d_u[d_idx] = 0.75*d_u0[d_idx] + 0.25*( d_u[d_idx] + dt * d_au[d_idx] )
d_v[d_idx] = 0.75*d_v0[d_idx] + 0.25*( d_v[d_idx] + dt * d_av[d_idx] )
d_w[d_idx] = 0.75*d_w0[d_idx] + 0.25*( d_w[d_idx] + dt * d_aw[d_idx] )
# update positions
d_x[d_idx] = 0.75*d_x0[d_idx] + 0.25*( d_x[d_idx] + dt * d_ax[d_idx] )
d_y[d_idx] = 0.75*d_y0[d_idx] + 0.25*( d_y[d_idx] + dt * d_ay[d_idx] )
d_z[d_idx] = 0.75*d_z0[d_idx] + 0.25*( d_z[d_idx] + dt * d_az[d_idx] )
# Update density
d_rho[d_idx] = 0.75*d_rho0[d_idx] + 0.25*( d_rho[d_idx] + dt * d_arho[d_idx] )
def stage3(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho, d_au, d_av,
d_aw, d_ax, d_ay, d_az, d_arho, dt):
oneby3 = 1./3.
twoby3 = 2./3.
# update velocities
d_u[d_idx] = oneby3*d_u0[d_idx] + twoby3*( d_u[d_idx] + dt * d_au[d_idx] )
d_v[d_idx] = oneby3*d_v0[d_idx] + twoby3*( d_v[d_idx] + dt * d_av[d_idx] )
d_w[d_idx] = oneby3*d_w0[d_idx] + twoby3*( d_w[d_idx] + dt * d_aw[d_idx] )
# update positions
d_x[d_idx] = oneby3*d_x0[d_idx] + twoby3*( d_x[d_idx] + dt * d_ax[d_idx] )
d_y[d_idx] = oneby3*d_y0[d_idx] + twoby3*( d_y[d_idx] + dt * d_ay[d_idx] )
d_z[d_idx] = oneby3*d_z0[d_idx] + twoby3*( d_z[d_idx] + dt * d_az[d_idx] )
# Update density
d_rho[d_idx] = oneby3*d_rho0[d_idx] + twoby3*( d_rho[d_idx] + dt * d_arho[d_idx] )
###############################################################################
# `SolidMechStep` class
###############################################################################
class SolidMechStep(IntegratorStep):
"""Predictor corrector Integrator for solid mechanics problems"""
def initialize(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho,
d_s00, d_s01, d_s02, d_s11, d_s12, d_s22,
d_s000, d_s010, d_s020, d_s110, d_s120, d_s220,
d_e0, d_e):
d_x0[d_idx] = d_x[d_idx]
d_y0[d_idx] = d_y[d_idx]
d_z0[d_idx] = d_z[d_idx]
d_u0[d_idx] = d_u[d_idx]
d_v0[d_idx] = d_v[d_idx]
d_w0[d_idx] = d_w[d_idx]
d_rho0[d_idx] = d_rho[d_idx]
d_e0[d_idx] = d_e[d_idx]
d_s000[d_idx] = d_s00[d_idx]
d_s010[d_idx] = d_s01[d_idx]
d_s020[d_idx] = d_s02[d_idx]
d_s110[d_idx] = d_s11[d_idx]
d_s120[d_idx] = d_s12[d_idx]
d_s220[d_idx] = d_s22[d_idx]
def stage1(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho, d_au, d_av,
d_aw, d_ax, d_ay, d_az, d_arho, d_e, d_e0, d_ae,
d_s00, d_s01, d_s02, d_s11, d_s12, d_s22,
d_s000, d_s010, d_s020, d_s110, d_s120, d_s220,
d_as00, d_as01, d_as02, d_as11, d_as12, d_as22,
dt):
dtb2 = 0.5*dt
d_u[d_idx] = d_u0[d_idx] + dtb2*d_au[d_idx]
d_v[d_idx] = d_v0[d_idx] + dtb2*d_av[d_idx]
d_w[d_idx] = d_w0[d_idx] + dtb2*d_aw[d_idx]
d_x[d_idx] = d_x0[d_idx] + dtb2 * d_ax[d_idx]
d_y[d_idx] = d_y0[d_idx] + dtb2 * d_ay[d_idx]
d_z[d_idx] = d_z0[d_idx] + dtb2 * d_az[d_idx]
# Update densities and smoothing lengths from the accelerations
d_rho[d_idx] = d_rho0[d_idx] + dtb2 * d_arho[d_idx]
d_e[d_idx] = d_e0[d_idx] + dtb2 * d_ae[d_idx]
# update deviatoric stress components
d_s00[d_idx] = d_s000[d_idx] + dtb2 * d_as00[d_idx]
d_s01[d_idx] = d_s010[d_idx] + dtb2 * d_as01[d_idx]
d_s02[d_idx] = d_s020[d_idx] + dtb2 * d_as02[d_idx]
d_s11[d_idx] = d_s110[d_idx] + dtb2 * d_as11[d_idx]
d_s12[d_idx] = d_s120[d_idx] + dtb2 * d_as12[d_idx]
d_s22[d_idx] = d_s220[d_idx] + dtb2 * d_as22[d_idx]
def stage2(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_rho0, d_rho, d_au, d_av,
d_aw, d_ax, d_ay, d_az, d_arho, d_e, d_ae, d_e0,
d_s00, d_s01, d_s02, d_s11, d_s12, d_s22,
d_s000, d_s010, d_s020, d_s110, d_s120, d_s220,
d_as00, d_as01, d_as02, d_as11, d_as12, d_as22,
dt):
d_u[d_idx] = d_u0[d_idx] + dt*d_au[d_idx]
d_v[d_idx] = d_v0[d_idx] + dt*d_av[d_idx]
d_w[d_idx] = d_w0[d_idx] + dt*d_aw[d_idx]
d_x[d_idx] = d_x0[d_idx] + dt * d_ax[d_idx]
d_y[d_idx] = d_y0[d_idx] + dt * d_ay[d_idx]
d_z[d_idx] = d_z0[d_idx] + dt * d_az[d_idx]
# Update densities and smoothing lengths from the accelerations
d_rho[d_idx] = d_rho0[d_idx] + dt * d_arho[d_idx]
d_e[d_idx] = d_e0[d_idx] + dt * d_ae[d_idx]
# update deviatoric stress components
d_s00[d_idx] = d_s000[d_idx] + dt * d_as00[d_idx]
d_s01[d_idx] = d_s010[d_idx] + dt * d_as01[d_idx]
d_s02[d_idx] = d_s020[d_idx] + dt * d_as02[d_idx]
d_s11[d_idx] = d_s110[d_idx] + dt * d_as11[d_idx]
d_s12[d_idx] = d_s120[d_idx] + dt * d_as12[d_idx]
d_s22[d_idx] = d_s220[d_idx] + dt * d_as22[d_idx]
###############################################################################
# `TransportVelocityStep` class
###############################################################################
class TransportVelocityStep(IntegratorStep):
"""Integrator defined in 'A transport velocity formulation for
smoothed particle hydrodynamics', 2013, JCP, 241, pp 292--307
For a predictor-corrector style of integrator, this integrator
should operate only in PEC mode.
"""
def initialize(self):
pass
def stage1(self, d_idx, d_u, d_v, d_w, d_au, d_av, d_aw, d_uhat, d_auhat, d_vhat,
d_avhat, d_what, d_awhat, d_x, d_y, d_z, dt):
dtb2 = 0.5*dt
# velocity update eqn (14)
d_u[d_idx] += dtb2*d_au[d_idx]
d_v[d_idx] += dtb2*d_av[d_idx]
d_w[d_idx] += dtb2*d_aw[d_idx]
# advection velocity update eqn (15)
d_uhat[d_idx] = d_u[d_idx] + dtb2*d_auhat[d_idx]
d_vhat[d_idx] = d_v[d_idx] + dtb2*d_avhat[d_idx]
d_what[d_idx] = d_w[d_idx] + dtb2*d_awhat[d_idx]
# position update eqn (16)
d_x[d_idx] += dt*d_uhat[d_idx]
d_y[d_idx] += dt*d_vhat[d_idx]
d_z[d_idx] += dt*d_what[d_idx]
def stage2(self, d_idx, d_u, d_v, d_w, d_au, d_av, d_aw, d_vmag2, dt):
dtb2 = 0.5*dt
# corrector update eqn (17)
d_u[d_idx] += dtb2*d_au[d_idx]
d_v[d_idx] += dtb2*d_av[d_idx]
d_w[d_idx] += dtb2*d_aw[d_idx]
# magnitude of velocity squared
d_vmag2[d_idx] = (d_u[d_idx]*d_u[d_idx] + d_v[d_idx]*d_v[d_idx] +
d_w[d_idx]*d_w[d_idx])
###############################################################################
# `AdamiVerletStep` class
###############################################################################
class AdamiVerletStep(IntegratorStep):
"""Verlet time integration described in `A generalized wall
boundary condition for smoothed particle hydrodynamics` 2012, JCP,
231, pp 7057--7075
This integrator can operate in either PEC mode or in EPEC mode as
described in the paper.
"""
def initialize(self):
pass
def stage1(self, d_idx, d_u, d_v, d_w, d_au, d_av, d_aw, d_x, d_y, d_z, dt):
dtb2 = 0.5*dt
# velocity predictor eqn (14)
d_u[d_idx] += dtb2*d_au[d_idx]
d_v[d_idx] += dtb2*d_av[d_idx]
d_w[d_idx] += dtb2*d_aw[d_idx]
# position predictor eqn (15)
d_x[d_idx] += dtb2*d_u[d_idx]
d_y[d_idx] += dtb2*d_v[d_idx]
d_z[d_idx] += dtb2*d_w[d_idx]
def stage2(self, d_idx, d_u, d_v, d_w, d_au, d_av, d_aw, d_x, d_y, d_z,
d_rho, d_arho, d_vmag2, dt):
dtb2 = 0.5*dt
# velocity corrector eqn (18)
d_u[d_idx] += dtb2*d_au[d_idx]
d_v[d_idx] += dtb2*d_av[d_idx]
d_w[d_idx] += dtb2*d_aw[d_idx]
# position corrector eqn (17)
d_x[d_idx] += dtb2*d_u[d_idx]
d_y[d_idx] += dtb2*d_v[d_idx]
d_z[d_idx] += dtb2*d_w[d_idx]
# density corrector eqn (16)
d_rho[d_idx] += dt * d_arho[d_idx]
# magnitude of velocity squared
d_vmag2[d_idx] = (d_u[d_idx]*d_u[d_idx] + d_v[d_idx]*d_v[d_idx] +
d_w[d_idx]*d_w[d_idx])
###############################################################################
# `GasDFluidStep` class
###############################################################################
class GasDFluidStep(IntegratorStep):
"""Predictor Corrector integrator for Gas-dynamics"""
def initialize(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z, d_h,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_e, d_e0, d_h0,
d_converged, d_omega, d_rho, d_rho0, d_alpha1, d_alpha2,
d_alpha10, d_alpha20):
d_x0[d_idx] = d_x[d_idx]
d_y0[d_idx] = d_y[d_idx]
d_z0[d_idx] = d_z[d_idx]
d_u0[d_idx] = d_u[d_idx]
d_v0[d_idx] = d_v[d_idx]
d_w0[d_idx] = d_w[d_idx]
d_e0[d_idx] = d_e[d_idx]
d_h0[d_idx] = d_h[d_idx]
d_rho0[d_idx] = d_rho[d_idx]
# set the converged attribute to 0 at the beginning of a Group
d_converged[d_idx] = 0
# likewise, we set the default omega (grad-h) terms to 1 at
# the beginning of this Group.
d_omega[d_idx] = 1.0
d_alpha10[d_idx] = d_alpha1[d_idx]
d_alpha20[d_idx] = d_alpha2[d_idx]
def stage1(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_e0, d_e, d_au, d_av,
d_aw, d_ae, d_rho, d_rho0, d_arho, d_h, d_h0, d_ah,
d_alpha1, d_aalpha1, d_alpha10,
d_alpha2, d_aalpha2, d_alpha20,
dt):
dtb2 = 0.5*dt
d_u[d_idx] = d_u0[d_idx] + dtb2 * d_au[d_idx]
d_v[d_idx] = d_v0[d_idx] + dtb2 * d_av[d_idx]
d_w[d_idx] = d_w0[d_idx] + dtb2 * d_aw[d_idx]
d_x[d_idx] = d_x0[d_idx] + dtb2 * d_u[d_idx]
d_y[d_idx] = d_y0[d_idx] + dtb2 * d_v[d_idx]
d_z[d_idx] = d_z0[d_idx] + dtb2 * d_w[d_idx]
# update thermal energy
d_e[d_idx] = d_e0[d_idx] + dtb2 * d_ae[d_idx]
# predict density and smoothing lengths for faster
# convergence. NNPS need not be explicitly updated since it
# will be called at the end of the predictor stage.
d_h[d_idx] = d_h0[d_idx] + dtb2 * d_ah[d_idx]
d_rho[d_idx] = d_rho0[d_idx] + dtb2 * d_arho[d_idx]
# update viscosity coefficients
d_alpha1[d_idx] = d_alpha10[d_idx] + dtb2*d_aalpha1[d_idx]
d_alpha2[d_idx] = d_alpha20[d_idx] + dtb2*d_aalpha2[d_idx]
def stage2(self, d_idx, d_x0, d_y0, d_z0, d_x, d_y, d_z,
d_u0, d_v0, d_w0, d_u, d_v, d_w, d_e0, d_e, d_au, d_av,
d_alpha1, d_aalpha1, d_alpha10,
d_alpha2, d_aalpha2, d_alpha20,
d_aw, d_ae, dt):
d_u[d_idx] = d_u0[d_idx] + dt * d_au[d_idx]
d_v[d_idx] = d_v0[d_idx] + dt * d_av[d_idx]
d_w[d_idx] = d_w0[d_idx] + dt * d_aw[d_idx]
d_x[d_idx] = d_x0[d_idx] + dt * d_u[d_idx]
d_y[d_idx] = d_y0[d_idx] + dt * d_v[d_idx]
d_z[d_idx] = d_z0[d_idx] + dt * d_w[d_idx]
# Update densities and smoothing lengths from the accelerations
d_e[d_idx] = d_e0[d_idx] + dt * d_ae[d_idx]
# update viscosity coefficients
d_alpha1[d_idx] = d_alpha10[d_idx] + dt*d_aalpha1[d_idx]
d_alpha2[d_idx] = d_alpha20[d_idx] + dt*d_aalpha2[d_idx]
###############################################################################
# `TwoStageRigidBodyStep` class
###############################################################################
class TwoStageRigidBodyStep(IntegratorStep):
"""Simple rigid-body motion
At each stage of the integrator, the prescribed velocity and
accelerations are incremented by dt/2.
Note that the time centered velocity is used for updating the
particle positions. This ensures exact motion for a constant
acceleration.
"""
def initialize(self, d_idx, d_x, d_y, d_z, d_x0, d_y0, d_z0,
d_u, d_v, d_w, d_u0, d_v0, d_w0):
d_u0[d_idx] = d_u[d_idx]
d_v0[d_idx] = d_v[d_idx]
d_w0[d_idx] = d_w[d_idx]
d_x0[d_idx] = d_x[d_idx]
d_y0[d_idx] = d_y[d_idx]
d_z0[d_idx] = d_z[d_idx]
def stage1(self, d_idx, d_x, d_y, d_z, d_x0, d_y0, d_z0,
d_u, d_v, d_w, d_u0, d_v0, d_w0, d_au, d_av, d_aw,
dt):
dtb2 = 0.5*dt
d_u[d_idx] = d_u0[d_idx] + dtb2 * d_au[d_idx]
d_v[d_idx] = d_v0[d_idx] + dtb2 * d_av[d_idx]
d_w[d_idx] = d_w0[d_idx] + dtb2 * d_aw[d_idx]
# positions are updated based on the time centered velocity
d_x[d_idx] = d_x0[d_idx] + dtb2 * 0.5 * (d_u[d_idx] + d_u0[d_idx])
d_y[d_idx] = d_y0[d_idx] + dtb2 * 0.5 * (d_v[d_idx] + d_v0[d_idx])
d_z[d_idx] = d_z0[d_idx] + dtb2 * 0.5 * (d_w[d_idx] + d_w0[d_idx])
def stage2(self, d_idx, d_x, d_y, d_z, d_x0, d_y0, d_z0,
d_u, d_v, d_w, d_u0, d_v0, d_w0, d_au, d_av, d_aw,
dt):
d_u[d_idx] = d_u0[d_idx] + dt * d_au[d_idx]
d_v[d_idx] = d_v0[d_idx] + dt * d_av[d_idx]
d_w[d_idx] = d_w0[d_idx] + dt * d_aw[d_idx]
# positions are updated based on the time centered velocity
d_x[d_idx] = d_x0[d_idx] + dt * 0.5 * (d_u[d_idx] + d_u0[d_idx])
d_y[d_idx] = d_y0[d_idx] + dt * 0.5 * (d_v[d_idx] + d_v0[d_idx])
d_z[d_idx] = d_z0[d_idx] + dt * 0.5 * (d_w[d_idx] + d_w0[d_idx])
###############################################################################
# `OneStageRigidBodyStep` class
###############################################################################
class OneStageRigidBodyStep(IntegratorStep):
"""Simple one stage rigid-body motion """
def initialize(self, d_idx, d_x, d_y, d_z, d_x0, d_y0, d_z0,
d_u, d_v, d_w, d_u0, d_v0, d_w0):
d_u0[d_idx] = d_u[d_idx]
d_v0[d_idx] = d_v[d_idx]
d_w0[d_idx] = d_w[d_idx]
d_x0[d_idx] = d_x[d_idx]
d_y0[d_idx] = d_y[d_idx]
d_z0[d_idx] = d_z[d_idx]
def stage1(self, d_idx, d_x, d_y, d_z, d_x0, d_y0, d_z0,
d_u, d_v, d_w, d_u0, d_v0, d_w0, d_au, d_av, d_aw,
dt):
pass
def stage2(self, d_idx, d_x, d_y, d_z, d_x0, d_y0, d_z0,
d_u, d_v, d_w, d_u0, d_v0, d_w0, d_au, d_av, d_aw,
dt):
# update velocities
d_u[d_idx] += dt * d_au[d_idx]
d_v[d_idx] += dt * d_av[d_idx]
d_w[d_idx] += dt * d_aw[d_idx]
# upadte positions using time-centered velocity
d_x[d_idx] += dt * 0.5 * (d_u[d_idx] + d_u0[d_idx])
d_y[d_idx] += dt * 0.5 * (d_v[d_idx] + d_v0[d_idx])
d_z[d_idx] += dt * 0.5 * (d_w[d_idx] + d_w0[d_idx])
###############################################################################
# `VerletSymplecticWCSPHStep` class
###############################################################################
class VerletSymplecticWCSPHStep(IntegratorStep):
"""Symplectic second order integrator described in the review
paper by Monaghan:
J. Monaghan, "Smoothed Particle Hydrodynamics", Reports on
Progress in Physics, 2005, 68, pp 1703--1759 [JM05]
Notes:
This integrator should run in PEC mode since in the first stage,
the positions are updated using the current velocity. The
accelerations are then computed to advance to the full time step
values.
This version of the integrator does not update the density. That
is, the summation density is used instead of the continuity
equation.
"""
def initialize(self):
pass
def stage1(self, d_idx, d_x, d_y, d_z, d_u, d_v, d_w, dt):
dtb2 = 0.5 * dt
# Eq. (5.39) in [JM05]
d_x[d_idx] += dtb2 * d_u[d_idx]
d_y[d_idx] += dtb2 * d_v[d_idx]
d_z[d_idx] += dtb2 * d_w[d_idx]
def stage2(self, d_idx, d_x, d_y, d_z, d_ax, d_ay, d_az,
d_u, d_v, d_w, d_au, d_av, d_aw, dt):
dtb2 = 0.5 * dt
# Eq. (5.40) in [JM05]
d_u[d_idx] += dt * d_au[d_idx]
d_v[d_idx] += dt * d_av[d_idx]
d_w[d_idx] += dt * d_aw[d_idx]
# Eq. (5.41) in [JM05] using XSPH velocity correction
d_x[d_idx] += dtb2 * d_ax[d_idx]
d_y[d_idx] += dtb2 * d_ay[d_idx]
d_z[d_idx] += dtb2 * d_az[d_idx]
###############################################################################
# `VelocityVerletSymplecticWCSPHStep` class
###############################################################################
class VelocityVerletSymplecticWCSPHStep(IntegratorStep):
"""Another symplectic second order integrator described in the
review paper by Monaghan:
J. Monaghan, "Smoothed Particle Hydrodynamics", Reports on
Progress in Physics, 2005, 68, pp 1703--1759 [JM05]
kick--drift--kick form of the verlet integrator
"""
def initialize(self):
pass
def stage1(self, d_idx, d_u, d_v, d_w, d_au, d_av, d_aw, dt):
dtb2 = 0.5 * dt
# Eq. (5.51) in [JM05]
d_u[d_idx] += dtb2 * d_au[d_idx]
d_v[d_idx] += dtb2 * d_av[d_idx]
d_w[d_idx] += dtb2 * d_aw[d_idx]
def stage2(self, d_idx, d_x, d_y, d_z, d_u, d_v, d_w,
d_au, d_av, d_aw, dt):
dtb2 = 0.5 * dt
# Eq. (5.52) in [JM05]
d_x[d_idx] += dt * d_u[d_idx]
d_y[d_idx] += dt * d_v[d_idx]
d_z[d_idx] += dt * d_w[d_idx]
# Eq. (5.53) in [JM05]
d_u[d_idx] += dtb2 * d_au[d_idx]
d_v[d_idx] += dtb2 * d_av[d_idx]
d_w[d_idx] += dtb2 * d_aw[d_idx]
###############################################################################
# `InletOutletStep` class
###############################################################################
class InletOutletStep(IntegratorStep):
"""A trivial integrator for the inlet/outlet particles
"""
def initialize(self):
pass
def stage1(self, d_idx, d_x, d_y, d_z, d_u, d_v, d_w, dt):
dtb2 = 0.5*dt
d_x[d_idx] += dtb2 * d_u[d_idx]
d_y[d_idx] += dtb2 * d_v[d_idx]
d_z[d_idx] += dtb2 * d_w[d_idx]
def stage2(self, d_idx, d_x, d_y, d_z, d_u, d_v, d_w, dt):
dtb2 = 0.5*dt
d_x[d_idx] += dtb2 * d_u[d_idx]
d_y[d_idx] += dtb2 * d_v[d_idx]
d_z[d_idx] += dtb2 * d_w[d_idx]
###############################################################################
class LeapFrogStep(IntegratorStep):
r"""Using this stepper with XSPH as implemented in
`pysph.base.basic_equations.XSPHCorrection` is not directly possible and
requires a nicer implementation where the correction alone is added to ``ax,
ay, az``.
"""
def stage1(self, d_idx, d_x, d_y, d_z, d_u, d_v, d_w, d_ax, d_ay, d_az,
dt):
d_x[d_idx] += 0.5 * dt * (d_u[d_idx] + d_ax[d_idx])
d_y[d_idx] += 0.5 * dt * (d_v[d_idx] + d_ay[d_idx])
d_z[d_idx] += 0.5 * dt * (d_w[d_idx] + d_az[d_idx])
def stage2(self, d_idx, d_x, d_y, d_z, d_u, d_au, d_v, d_av,
d_w, d_aw, d_ax, d_ay, d_az,
d_rho, d_arho, d_e, d_ae, dt):
d_u[d_idx] += dt * d_au[d_idx]
d_v[d_idx] += dt * d_av[d_idx]
d_w[d_idx] += dt * d_aw[d_idx]
d_rho[d_idx] += dt * d_arho[d_idx]
d_e[d_idx] += dt * d_ae[d_idx]
d_x[d_idx] += 0.5 * dt * (d_u[d_idx] + d_ax[d_idx])
d_y[d_idx] += 0.5 * dt * (d_v[d_idx] + d_ay[d_idx])
d_z[d_idx] += 0.5 * dt * (d_w[d_idx] + d_az[d_idx])
###############################################################################
class PEFRLStep(IntegratorStep):
r"""Using this stepper with XSPH as implemented in
`pysph.base.basic_equations.XSPHCorrection` is not directly possible and
requires a nicer implementation where the correction alone is added to ``ax,
ay, az``.
"""
def stage1(self, d_idx, d_x, d_y, d_z, d_u, d_v, d_w, d_ax, d_ay,
d_az, dt):
xi = 0.1786178958448091
d_x[d_idx] += xi * dt * (d_u[d_idx] + d_ax[d_idx])
d_y[d_idx] += xi * dt * (d_v[d_idx] + d_ay[d_idx])
d_z[d_idx] += xi * dt * (d_w[d_idx] + d_az[d_idx])
def stage2(self, d_idx, d_x, d_y, d_z, d_u, d_au, d_v, d_av,
d_w, d_aw, d_ax, d_ay, d_az,
d_rho, d_arho, d_e, d_ae, dt=0.0):
lamda = -0.2123418310626054
fac = (1. - 2.*lamda) / 2.
d_u[d_idx] += fac * dt * d_au[d_idx]
d_v[d_idx] += fac * dt * d_av[d_idx]
d_w[d_idx] += fac * dt * d_aw[d_idx]
d_rho[d_idx] += fac * dt * d_arho[d_idx]
d_e[d_idx] += fac * dt * d_ae[d_idx]
chi = -0.06626458266981849
d_x[d_idx] += chi * dt * (d_u[d_idx] + d_ax[d_idx])
d_y[d_idx] += chi * dt * (d_v[d_idx] + d_ay[d_idx])
d_z[d_idx] += chi * dt * (d_w[d_idx] + d_az[d_idx])
def stage3(self, d_idx, d_x, d_y, d_z, d_u, d_au, d_v, d_av,
d_w, d_aw, d_ax, d_ay, d_az,
d_rho, d_arho, d_e, d_ae, dt=0.0):
lamda = -0.2123418310626054
d_u[d_idx] += lamda * dt * d_au[d_idx]
d_v[d_idx] += lamda * dt * d_av[d_idx]
d_w[d_idx] += lamda * dt * d_aw[d_idx]
d_rho[d_idx] += lamda * dt * d_arho[d_idx]
d_e[d_idx] += lamda * dt * d_ae[d_idx]
xi = +0.1786178958448091
chi = -0.06626458266981849
fac = 1. - 2.*(xi + chi)
d_x[d_idx] += fac * dt * (d_u[d_idx] + d_ax[d_idx])
d_y[d_idx] += fac * dt * (d_v[d_idx] + d_ay[d_idx])
d_z[d_idx] += fac * dt * (d_w[d_idx] + d_az[d_idx])
def stage4(self, d_idx, d_x, d_y, d_z, d_u, d_au, d_v, d_av,
d_w, d_aw, d_ax, d_ay, d_az,
d_rho, d_arho, d_e, d_ae, dt=0.0):
lamda = -0.2123418310626054
d_u[d_idx] += lamda * dt * d_au[d_idx]
d_v[d_idx] += lamda * dt * d_av[d_idx]
d_w[d_idx] += lamda * dt * d_aw[d_idx]
d_rho[d_idx] += lamda * dt * d_arho[d_idx]
d_e[d_idx] += lamda * dt * d_ae[d_idx]
chi = -0.06626458266981849
d_x[d_idx] += chi * dt * (d_u[d_idx] + d_ax[d_idx])
d_y[d_idx] += chi * dt * (d_v[d_idx] + d_ay[d_idx])
d_z[d_idx] += chi * dt * (d_w[d_idx] + d_az[d_idx])
def stage5(self, d_idx, d_x, d_y, d_z, d_u, d_au, d_v, d_av,
d_w, d_aw, d_ax, d_ay, d_az,
d_rho, d_arho, d_e, d_ae, dt=0.0):
lamda = -0.2123418310626054
fac = (1. - 2.*lamda) / 2.
d_u[d_idx] += fac * dt * d_au[d_idx]
d_v[d_idx] += fac * dt * d_av[d_idx]
d_w[d_idx] += fac * dt * d_aw[d_idx]
d_rho[d_idx] += fac * dt * d_arho[d_idx]
d_e[d_idx] += fac * dt * d_ae[d_idx]
xi = +0.1786178958448091
d_x[d_idx] += xi * dt * (d_u[d_idx] + d_ax[d_idx])
d_y[d_idx] += xi * dt * (d_v[d_idx] + d_ay[d_idx])
d_z[d_idx] += xi * dt * (d_w[d_idx] + d_az[d_idx])
|