From 3f5b740fa78d0b4149a22fdb322571cf56380f7d Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Sat, 19 Oct 2024 17:47:15 +0200 Subject: [PATCH 1/2] reduce roundoff error when using coarsening --- src/fluid/coarsenFlow.hpp | 42 ++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/fluid/coarsenFlow.hpp b/src/fluid/coarsenFlow.hpp index 217c7711..b1bf79ea 100644 --- a/src/fluid/coarsenFlow.hpp +++ b/src/fluid/coarsenFlow.hpp @@ -290,28 +290,52 @@ void Fluid::CoarsenMagField(IdefixArray4D &Vsin) { // We reconstruct the parrallel field component with divB=0 int factor = 1 << (coarsening-1); + + if( (index-begDir)%factor == 0) { + real qt = 0; + real qb = 0; + + // Loop forward for(int shift = 0 ; shift < factor-1 ; shift++) { - real qt = Vsin(BXt,k+kt+shift*koffset, j+jt+shift*joffset, i+it+shift*ioffset) + qt += Vsin(BXt,k+kt+shift*koffset, j+jt+shift*joffset, i+it+shift*ioffset) * At(k+kt+shift*koffset, j+jt+shift*joffset, i+it+shift*ioffset) - Vsin(BXt,k+shift*koffset, j+shift*joffset, i+shift*ioffset) * At(k+shift*koffset, j+shift*joffset, i+shift*ioffset); #if DIMENSIONS == 3 - real qb = Vsin(BXb,k+kb+shift*koffset, j+jb+shift*joffset, i+ib+shift*ioffset) + qb += Vsin(BXb,k+kb+shift*koffset, j+jb+shift*joffset, i+ib+shift*ioffset) * Ab(k+kb+shift*koffset, j+jb+shift*joffset, i+ib+shift*ioffset) - Vsin(BXb,k+shift*koffset, j+shift*joffset, i+shift*ioffset) * Ab(k+shift*koffset, j+shift*joffset, i+shift*ioffset); - #else - real qb = 0.0; #endif Vsin(BXn, k+(shift+1)*koffset, j+(shift+1)*joffset, i+(shift+1)*ioffset) = + ((real) (factor-(shift+1))) / ((real)factor) * 1.0/An(k+(shift+1)*koffset, j+(shift+1)*joffset, i+(shift+1)*ioffset) * - ( - Vsin(BXn, k+shift*koffset, j+shift*joffset, i+shift*ioffset) * - An(k+shift*koffset, j+shift*joffset, i+shift*ioffset) - - qt - qb - ); + (Vsin(BXn, k, j, i) * An(k, j, i) - qt - qb); + } + // Loop backward + qt = 0; + qb = 0; + + // Loop forward + for(int shift = factor-1 ; shift >=1 ; shift--) { + qt += Vsin(BXt,k+kt+shift*koffset, j+jt+shift*joffset, i+it+shift*ioffset) + * At(k+kt+shift*koffset, j+jt+shift*joffset, i+it+shift*ioffset) + - Vsin(BXt,k+shift*koffset, j+shift*joffset, i+shift*ioffset) + * At(k+shift*koffset, j+shift*joffset, i+shift*ioffset); + #if DIMENSIONS == 3 + qb += Vsin(BXb,k+kb+shift*koffset, j+jb+shift*joffset, i+ib+shift*ioffset) + * Ab(k+kb+shift*koffset, j+jb+shift*joffset, i+ib+shift*ioffset) + - Vsin(BXb,k+shift*koffset, j+shift*joffset, i+shift*ioffset) + * Ab(k+shift*koffset, j+shift*joffset, i+shift*ioffset); + #endif + + Vsin(BXn, k+shift*koffset, j+shift*joffset, i+shift*ioffset) += + ((real) shift) / ((real)factor) * + 1.0/An(k+shift*koffset, j+shift*joffset, i+shift*ioffset) * + (Vsin(BXn, k+factor*koffset, j+factor*joffset, i+factor*ioffset) + * An( k+factor*koffset, j+factor*joffset, i+factor*ioffset) + qt + qb); } } } From f7fc679ea18b4db20956f3604746db14a430759d Mon Sep 17 00:00:00 2001 From: Geoffroy Lesur Date: Sat, 19 Oct 2024 18:43:56 +0200 Subject: [PATCH 2/2] update reference tag for new grid coarsening --- reference | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reference b/reference index 99f339c4..609a6016 160000 --- a/reference +++ b/reference @@ -1 +1 @@ -Subproject commit 99f339c43d98274a925282cc96252c5a0fa9374f +Subproject commit 609a60164461fb2d4fbeffa89ce148acf1191525