Skip to content

Commit bef47e2

Browse files
ErwanH29rieder
andauthored
Include test particle calculations in Ph4 (#1161)
* Updates to ph4 * Implemented more massless algorithms --------- Co-authored-by: Steven Rieder <[email protected]>
1 parent 25edb9c commit bef47e2

File tree

2 files changed

+51
-37
lines changed

2 files changed

+51
-37
lines changed

src/amuse_ph4/interface.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -780,19 +780,22 @@ int get_center_of_mass_position(double * x, double * y, double * z)
780780
// (Could also use jdata::get_com.)
781781

782782
if (!jd || jd->nj <= 0) {
783-
*x = *y = *z = 0;
784-
return 0;
783+
*x = *y = *z = 0;
784+
return 0;
785785
}
786-
786+
787787
real mtot = 0;
788788
vec cmx(0,0,0);
789789
for (int j = 0; j < jd->nj; j++) {
790-
mtot += jd->mass[j];
791-
for (int k = 0; k < 3; k++) cmx[k] += jd->mass[j]*jd->pos[j][k];
790+
if (jd->mass[j] > _TINY_){
791+
mtot += jd->mass[j];
792+
for (int k = 0; k < 3; k++) cmx[k] += jd->mass[j]*jd->pos[j][k];
793+
}
792794
}
793795
*x = cmx[0]/mtot;
794796
*y = cmx[1]/mtot;
795797
*z = cmx[2]/mtot;
798+
796799
return 0;
797800
}
798801

@@ -808,12 +811,15 @@ int get_center_of_mass_velocity(double * vx, double * vy, double * vz)
808811
real mtot = 0;
809812
vec cmv(0,0,0);
810813
for (int j = 0; j < jd->nj; j++) {
811-
mtot += jd->mass[j];
812-
for (int k = 0; k < 3; k++) cmv[k] += jd->mass[j]*jd->vel[j][k];
814+
if (jd->mass[j] > _TINY_){
815+
mtot += jd->mass[j];
816+
for (int k = 0; k < 3; k++) cmv[k] += jd->mass[j]*jd->vel[j][k];
817+
}
813818
}
814819
*vx = cmv[0]/mtot;
815820
*vy = cmv[1]/mtot;
816821
*vz = cmv[2]/mtot;
822+
817823
return 0;
818824
}
819825

src/amuse_ph4/src/idata.cc

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -204,30 +204,33 @@ void idata::get_partial_acc_and_jerk()
204204
ldnn[i] = _INFINITY_;
205205
for (int k = 0; k < 3; k++) lacc[i][k] = ljerk[i][k] = 0;
206206
for (int j = j_start; j < j_end; j++) {
207-
r2 = xv = 0;
208-
for (int k = 0; k < 3; k++) {
209-
dx[k] = jdat->pred_pos[j][k] - ipos[i][k];
210-
dv[k] = jdat->pred_vel[j][k] - ivel[i][k];
211-
r2 += dx[k]*dx[k];
212-
xv += dx[k]*dv[k];
213-
}
214-
r2i = 1/(r2+eps2+_TINY_);
215-
ri = sqrt(r2i);
216-
mri = jdat->mass[j]*ri;
217-
mr3i = mri*r2i;
218-
a3 = -3*xv*r2i;
219-
// PRC(jdat->mpi_rank); PRC(ri); PRL(mri);
220-
if (r2 > _TINY_) {
221-
lpot[i] -= mri;
222-
if (r2 < ldnn[i]) {
223-
ldnn[i] = r2;
224-
lnn[i] = j;
207+
// Skip particles with zero mass.
208+
if (jdat->mass[j] > _TINY_){
209+
r2 = xv = 0;
210+
for (int k = 0; k < 3; k++) {
211+
dx[k] = jdat->pred_pos[j][k] - ipos[i][k];
212+
dv[k] = jdat->pred_vel[j][k] - ivel[i][k];
213+
r2 += dx[k]*dx[k];
214+
xv += dx[k]*dv[k];
215+
}
216+
r2i = 1/(r2+eps2+_TINY_);
217+
ri = sqrt(r2i);
218+
mri = jdat->mass[j]*ri;
219+
mr3i = mri*r2i;
220+
a3 = -3*xv*r2i;
221+
// PRC(jdat->mpi_rank); PRC(ri); PRL(mri);
222+
if (r2 > _TINY_) {
223+
lpot[i] -= mri;
224+
if (r2 < ldnn[i]) {
225+
ldnn[i] = r2;
226+
lnn[i] = j;
227+
}
228+
}
229+
for (int k = 0; k < 3; k++) {
230+
lacc[i][k] += mr3i*dx[k];
231+
ljerk[i][k] += mr3i*(dv[k]+a3*dx[k]);
232+
}
225233
}
226-
}
227-
for (int k = 0; k < 3; k++) {
228-
lacc[i][k] += mr3i*dx[k];
229-
ljerk[i][k] += mr3i*(dv[k]+a3*dx[k]);
230-
}
231234
}
232235
ldnn[i] = sqrt(ldnn[i]);
233236
}
@@ -523,8 +526,11 @@ real idata::get_pot()
523526
// and called get_acc_and_jerk() for the entire system.
524527

525528
real pot2 = 0;
526-
for (int i = 0; i < ni; i++)
527-
pot2 += jdat->mass[ilist[i]]*ipot[i];
529+
530+
// Ignore massless particles
531+
for (int i = 0; i < ni; i++){
532+
pot2 += jdat->mass[ilist[i]] * ipot[i];
533+
}
528534
return pot2/2;
529535
}
530536

@@ -538,9 +544,9 @@ real idata::get_kin()
538544

539545
real kin2 = 0;
540546
for (int i = 0; i < ni; i++) {
541-
real v2 = 0;
542-
for (int k = 0; k < 3; k++) v2 += pow(ivel[i][k],2);
543-
kin2 += jdat->mass[ilist[i]]*v2;
547+
real v2 = 0;
548+
for (int k = 0; k < 3; k++) v2 += pow(ivel[i][k],2);
549+
kin2 += jdat->mass[ilist[i]]*v2;
544550
}
545551
return kin2/2;
546552
}
@@ -636,12 +642,13 @@ void idata::check_encounters()
636642
for (int i = 0; i < ni; i++) {
637643

638644
int jnn = inn[i]; // j index, note
639-
if (jnn >= 0) { // valid neighbor
645+
if (jnn >= 0) { // valid neighbor
640646

647+
// Ignore collisions between two massless particles
648+
if ((jdat->mass[jnn] > _TINY_) || (imass[i] > _TINY_)) {
641649
// Note no dtmin test.
642650

643651
real r = rmin/idnn[i];
644-
645652
if (r > rmax_close) {
646653
rmax_close = r;
647654
imax_close = i;
@@ -658,6 +665,7 @@ void idata::check_encounters()
658665
imax_coll = i;
659666
}
660667
}
668+
}
661669
}
662670

663671
if (rmax_close >= 1) { // close criterion

0 commit comments

Comments
 (0)