Skip to main content
1 of 3
Davislor
  • 8.3k
  • 17
  • 37

In addition to G. Sliepen’s idea, you could use the STL’s std::valarray<double>. This would let you replace something like

for (int d=0; d<DIM; d++) {
    p->x[d] += dt * (p->v[d] + a * p->F[d]);
    p->F_old[d] = p->F[d];
}

with something like

p->F_old = p->F;
p->x += dt * (p->v + a * p->F);

It would also be possible to lay out a structure of arrays rather than an array of structures. If there are more particles than dimensions, this could let you perform wider vector operations on all the x-coordinates, then all the y-coordinates and all the z-coordinates, rather than being limited to the width of the coordinate system.

Davislor
  • 8.3k
  • 17
  • 37