@@ -3905,26 +3905,35 @@ namespace BasisClasses
39053905 //
39063906 coef->rot = rot;
39073907
3908- std::vector<double > pp (3 ), vv (3 );
3908+ std::vector<double > p1 (3 ), v1 (3 );
3909+
3910+ // Map the vector rather than copy
3911+ //
3912+ Eigen::Map<Eigen::Vector3d> pp (p1.data (), 3 ), vv (v1.data (), 3 );
3913+ vv.setZero ();
39093914
39103915 reset_coefs ();
39113916 for (auto p=reader->firstParticle (); p!=0 ; p=reader->nextParticle ()) {
39123917
39133918 bool use = false ;
39143919
3920+ // Translate and rotate the position vector
3921+ //
3922+ for (int k=0 ; k<3 ; k++) p1[k] = p->pos [k];
3923+ pp = coefrot * (pp - coefctr);
3924+
39153925 if (ftor) {
3916- pp.assign (p->pos , p->pos +3 );
3917- vv.assign (p->vel , p->vel +3 );
3918- use = ftor (p->mass , pp, vv, p->indx );
3926+ // Rotate the velocity vector
3927+ //
3928+ for (int k=0 ; k<3 ; k++) v1[k] = p->vel [k];
3929+ vv = coefrot * vv;
3930+
3931+ use = ftor (p->mass , p1, v1, p->indx );
39193932 } else {
39203933 use = true ;
39213934 }
39223935
39233936 if (use) {
3924- Eigen::Vector3d pp;
3925- for (int k=0 ; k<3 ; k++) pp (k) = p->pos [k] - coefctr (k);
3926- pp = coefrot * pp;
3927-
39283937 accumulate (pp (0 ), pp (1 ), pp (2 ), p->mass );
39293938 }
39303939 }
@@ -3994,6 +4003,7 @@ namespace BasisClasses
39944003 int cols = p.cols ();
39954004
39964005 bool ambiguous = false ;
4006+ bool haveVel = false ;
39974007
39984008 if (cols==3 or cols==6 ) {
39994009 if (rows != 3 and rows != 6 ) PosVelRows = false ;
@@ -4014,7 +4024,11 @@ namespace BasisClasses
40144024 << " if this assumption is wrong." << std::endl;
40154025 }
40164026
4017- std::vector<double > p1 (3 ), v1 (3 , 0 );
4027+ // Map the vector rather than copy
4028+ //
4029+ std::vector<double > p1 (3 ), v1 (3 );
4030+ Eigen::Map<Eigen::Vector3d> pp (p1.data (), 3 ), vv (v1.data (), 3 );
4031+ vv.setZero ();
40184032
40194033 if (PosVelRows) {
40204034 if (p.rows ()<3 ) {
@@ -4024,21 +4038,30 @@ namespace BasisClasses
40244038 throw std::runtime_error (msg.str ());
40254039 }
40264040
4027- for ( int n= 0 ; n<p. cols (); n++) {
4041+ if (p. rows () == 6 ) haveVel = true ;
40284042
4043+ for (int n=0 ; n<p.cols (); n++) {
4044+
40294045 if (n % numprocs==myid or not RoundRobin) {
40304046
4047+ for (int k=0 ; k<3 ; k++) {
4048+ pp (k) = p (k, n);
4049+ if (haveVel) vv (k) = p (k+3 , n);
4050+ }
4051+
4052+ pp = coefrot * (pp - coefctr);
4053+
40314054 bool use = true ;
4055+
40324056 if (ftor) {
4033- for ( int k= 0 ; k< 3 ; k++) p1[k] = p (k, n) ;
4057+ if (haveVel) vv = coefrot * vv ;
40344058 use = ftor (m (n), p1, v1, coefindx);
40354059 } else {
40364060 use = true ;
40374061 }
40384062 coefindx++;
40394063
40404064 if (use) {
4041- auto pp = coefrot * (p.col (n) - coefctr);
40424065 accumulate (pp (0 ), pp (1 ), pp (2 ), m (n));
40434066 }
40444067 }
@@ -4053,21 +4076,30 @@ namespace BasisClasses
40534076 throw std::runtime_error (msg.str ());
40544077 }
40554078
4079+ if (p.cols () == 6 ) haveVel = true ;
4080+
4081+
40564082 for (int n=0 ; n<p.rows (); n++) {
40574083
40584084 if (n % numprocs==myid or not RoundRobin) {
40594085
4086+ for (int k=0 ; k<3 ; k++) {
4087+ pp (k) = p (n, k);
4088+ if (haveVel) vv (k) = p (n, k+3 );
4089+ }
4090+
4091+ pp = coefrot * (pp - coefctr);
4092+
40604093 bool use = true ;
40614094 if (ftor) {
4062- for ( int k= 0 ; k< 3 ; k++) p1[k] = p (n, k) ;
4095+ if (haveVel) vv = coefrot * vv ;
40634096 use = ftor (m (n), p1, v1, coefindx);
40644097 } else {
40654098 use = true ;
40664099 }
40674100 coefindx++;
40684101
40694102 if (use) {
4070- auto pp = coefrot * (p.row (n).transpose () - coefctr);
40714103 accumulate (pp (0 ), pp (1 ), pp (2 ), m (n));
40724104 }
40734105 }
0 commit comments