@@ -517,15 +517,32 @@ void VelocityInterpolationRKPM_cir(
517517 Real& W,
518518 Vector<MAP_INFO> RKPM_MAP,
519519 Array4<Real const > const & E,
520+ GpuArray<Real, AMREX_SPACEDIM> const & plo,
521+ GpuArray<Real, AMREX_SPACEDIM> const & dx,
520522 int EulerVIndex)
521523{
524+ const Real lx = (p.pos (0 ) - plo[0 ]) / dx[0 ]; // x
525+ const Real ly = (p.pos (1 ) - plo[1 ]) / dx[1 ]; // y
526+ const Real lz = (p.pos (2 ) - plo[2 ]) / dx[2 ]; // z
527+
528+ const int i = static_cast <int >(Math::floor (lx)); // i
529+ const int j = static_cast <int >(Math::floor (ly)); // j
530+ const int k = static_cast <int >(Math::floor (lz)); // k
531+
522532 U = 0 ;
523533 V = 0 ;
524534 W = 0 ;
525- for (auto & l : RKPM_MAP) {
526- U += l.weight * l.Vcell * E (l.index .get <0 >(), l.index .get <1 >(), l.index .get <2 >(), EulerVIndex );
527- V += l.weight * l.Vcell * E (l.index .get <0 >(), l.index .get <1 >(), l.index .get <2 >(), EulerVIndex + 1 );
528- W += l.weight * l.Vcell * E (l.index .get <0 >(), l.index .get <1 >(), l.index .get <2 >(), EulerVIndex + 2 );
535+
536+ int cell_index = 0 ;
537+ for (int ii = -1 ; ii < 2 ; ii++){
538+ for (int jj = -1 ; jj < 2 ; jj++){
539+ for (int kk = -1 ; kk < 2 ; kk ++){
540+ auto RKPM = RKPM_MAP.at (cell_index++);
541+ U += RKPM.weight * RKPM.Vcell * E (i + ii, j + jj, k + kk, EulerVIndex );
542+ V += RKPM.weight * RKPM.Vcell * E (i + ii, j + jj, k + kk, EulerVIndex + 1 );
543+ W += RKPM.weight * RKPM.Vcell * E (i + ii, j + jj, k + kk, EulerVIndex + 2 );
544+ }
545+ }
529546 }
530547}
531548
@@ -562,8 +579,8 @@ void mParticle::VelocityInterpolation(MultiFab &EulerVel,
562579 if (do_RKPM) {
563580 ParallelFor (np,
564581 [=] AMREX_GPU_DEVICE (const int i) {
565- const auto id = p_ptr[i].id ();
566- VelocityInterpolationRKPM_cir (p_ptr[i], Up[i], Vp[i], Wp[i], RKPM_MAP[id], E, EulerVelocityIndex);
582+ const auto id = p_ptr[i].id () - 1 ;
583+ VelocityInterpolationRKPM_cir (p_ptr[i], Up[i], Vp[i], Wp[i], RKPM_MAP[id], E, plo, dx, EulerVelocityIndex);
567584 });
568585 }else {
569586 ParallelFor (np,
@@ -687,19 +704,36 @@ void ForceSpreadingRKPM_cir(
687704 Vector<MAP_INFO> RKPM_MAP,
688705 Real dv,
689706 Array4<Real> const &E,
707+ GpuArray<Real,AMREX_SPACEDIM> const & plo,
708+ GpuArray<Real,AMREX_SPACEDIM> const & dx,
690709 int EulerForceIndex)
691710{
711+ Real lx = (p.pos (0 ) - plo[0 ]) / dx[0 ];
712+ Real ly = (p.pos (1 ) - plo[1 ]) / dx[1 ];
713+ Real lz = (p.pos (2 ) - plo[2 ]) / dx[2 ];
714+
715+ int i = static_cast <int >(Math::floor (lx));
716+ int j = static_cast <int >(Math::floor (ly));
717+ int k = static_cast <int >(Math::floor (lz));
718+
692719 fxP *= dv;
693720 fyP *= dv;
694721 fzP *= dv;
695722 RealVect moment = RealVect (p.pos (0 ) - Px, p.pos (1 ) - Py, p.pos (2 ) - Pz).crossProduct (RealVect (fxP, fyP, fzP));
696723 mxP = moment[0 ];
697724 myP = moment[1 ];
698725 mzP = moment[2 ];
699- for (auto & rkpm : RKPM_MAP) {
700- Gpu::Atomic::AddNoRet (&E (rkpm.index .get <0 >(), rkpm.index .get <1 >(), rkpm.index .get <2 >(), EulerForceIndex ), rkpm.weight * fxP);
701- Gpu::Atomic::AddNoRet (&E (rkpm.index .get <0 >(), rkpm.index .get <1 >(), rkpm.index .get <2 >(), EulerForceIndex + 1 ), rkpm.weight * fyP);
702- Gpu::Atomic::AddNoRet (&E (rkpm.index .get <0 >(), rkpm.index .get <1 >(), rkpm.index .get <2 >(), EulerForceIndex + 2 ), rkpm.weight * fzP);
726+
727+ int cell_index = 0 ;
728+ for (int ii = -1 ; ii < 2 ; ii++){
729+ for (int jj = -1 ; jj < 2 ; jj++){
730+ for (int kk = -1 ; kk < 2 ; kk ++){
731+ auto RKPM = RKPM_MAP.at (cell_index++);
732+ Gpu::Atomic::AddNoRet (&E (i + ii, j + jj, k + kk, EulerForceIndex ), RKPM.weight * fxP);
733+ Gpu::Atomic::AddNoRet (&E (i + ii, j + jj, k + kk, EulerForceIndex + 1 ), RKPM.weight * fyP);
734+ Gpu::Atomic::AddNoRet (&E (i + ii, j + jj, k + kk, EulerForceIndex + 2 ), RKPM.weight * fzP);
735+ }
736+ }
703737 }
704738}
705739
@@ -732,14 +766,14 @@ void mParticle::ForceSpreading(MultiFab & EulerForce,
732766 if (do_RKPM) {
733767 ParallelFor (np,
734768 [=] AMREX_GPU_DEVICE (const int i) noexcept {
735- const auto p_id = p_ptr[i].id (); // lagrangian marker's id
769+ const auto p_id = p_ptr[i].id () - 1 ; // lagrangian marker's id
736770 const auto id = ids[i]; // particle's id
737771 auto loc_ptr = ps[id].location ;
738- auto dv = ps[id]. dv ;
772+ auto dv = RKPM_MAP[p_id][ 0 ]. eps ;
739773 ForceSpreadingRKPM_cir (p_ptr[i], loc_ptr[0 ], loc_ptr[1 ], loc_ptr[2 ],
740774 fxP_ptr[i], fyP_ptr[i], fzP_ptr[i],
741775 mxP_ptr[i], myP_ptr[i], mzP_ptr[i],
742- RKPM_MAP[p_id], dv, Uarray, force_index);
776+ RKPM_MAP[p_id], dv, Uarray, plo, dxi, force_index);
743777 });
744778 }else {
745779 ParallelFor (np,
0 commit comments