/** * @brief Moves particles forward based on 2nd order Runge-Kutta method * * @param[in] endTime Final time of the simulation **/ void Runge_Kutta2::moveParticles(const double endTime) { while (currentTime < endTime) { const double dt = modifyTimeStep(1.0e-4f, init_dt); // implement dynamic timstep (if necessary): const doubleV vdt = set1_pd(dt); // store timestep as vector const const cloud_index numParticles = cloud->n; operate1(currentTime); force1(currentTime); // compute net force1 BEGIN_PARALLEL_FOR(i, e, numParticles, DOUBLE_STRIDE, static) // calculate k1 and l1 for entire cloud const doubleV vmass = load_pd(cloud->mass + i); // load ith and (i+1)th mass into vector // assign force pointers for stylistic purposes: double * const pFx = cloud->forceX + i; double * const pFy = cloud->forceY + i; store_pd(cloud->k1 + i, div_pd(mul_pd(vdt, load_pd(pFx)), vmass)); // velocityX tidbit store_pd(cloud->l1 + i, mul_pd(vdt, cloud->getVx1_pd(i))); // positionX tidbit store_pd(cloud->m1 + i, div_pd(mul_pd(vdt, load_pd(pFy)), vmass)); // velocityY tidbit store_pd(cloud->n1 + i, mul_pd(vdt, cloud->getVy1_pd(i))); // positionY tidbit // reset forces to zero: store_pd(pFx, set0_pd()); store_pd(pFy, set0_pd()); END_PARALLEL_FOR operate2(currentTime + dt/2.0); force2(currentTime + dt/2.0); // compute net force2 BEGIN_PARALLEL_FOR(i, e, numParticles, DOUBLE_STRIDE, static) // calculate k2 and l for entire cloud const doubleV vmass = load_pd(cloud->mass + i); // assign force pointers: double * const pFx = cloud->forceX + i; double * const pFy = cloud->forceY + i; store_pd(cloud->k2 + i, div_pd(mul_pd(vdt, load_pd(pFx)), vmass)); // velocityX tidbit store_pd(cloud->l2 + i, mul_pd(vdt, cloud->getVx2_pd(i))); // positionX tidbit store_pd(cloud->m2 + i, div_pd(mul_pd(vdt, load_pd(pFy)), vmass)); // velocityY tidbit store_pd(cloud->n2 + i, mul_pd(vdt, cloud->getVy2_pd(i))); // positionY tidbit // reset forces to zero: store_pd(pFx, set0_pd()); store_pd(pFy, set0_pd()); END_PARALLEL_FOR // Calculate next position and next velocity for entire cloud. BEGIN_PARALLEL_FOR(i, e, numParticles, DOUBLE_STRIDE, static) plusEqual_pd(cloud->Vx + i, load_pd(cloud->k2 + i)); plusEqual_pd(cloud->x + i, load_pd(cloud->l2 + i)); plusEqual_pd(cloud->Vy + i, load_pd(cloud->m2 + i)); plusEqual_pd(cloud->y + i, load_pd(cloud->n2 + i)); END_PARALLEL_FOR currentTime += dt; } }
//------------------------------------------------------------------------------ PD_Particles load_pd(string loadPath, unordered_map<string, double> particleParameters) { PD_Particles particles = load_pd(loadPath); if(!particleParameters.empty()) { for(auto pm:particleParameters) { particles.registerParameter(pm.first, pm.second); } } return particles; }