-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generalize ablastr::coarsen::average
to any staggering
#4458
base: development
Are you sure you want to change the base?
Generalize ablastr::coarsen::average
to any staggering
#4458
Conversation
… coarsen-average-Interp-any-staggering
… coarsen-average-Interp-any-staggering
… coarsen-average-Interp-any-staggering
… coarsen-average-Interp-any-staggering
for more information, see https://pre-commit.ci
… coarsen-average-Interp-any-staggering
… coarsen-average-Interp-any-staggering
… coarsen-average-Interp-any-staggering
for more information, see https://pre-commit.ci
return [iimin, iimax] | ||
ii_min = 0 | ||
ii_max = 4 * cr | ||
return [ii_min, ii_max] |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
return [iimin, iimax] | ||
ii_min = 0 | ||
ii_max = 4 * cr | ||
return [ii_min, ii_max] |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
elif sf == 1: # nodal | ||
iimin = 0 | ||
iimax = 8 | ||
return [iimin, iimax] |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
elif sf == 1: # nodal | ||
iimin = 0 | ||
iimax = 8 | ||
return [iimin, iimax] |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
elif cr >= 2: | ||
numpts = cr * (1 - sf) * (1 - sc) + (2 * (cr - 1) + 1) * sf * sc | ||
idxmin = i * cr * (1 - sf) * (1 - sc) + (i * cr - cr + 1) * sf * sc | ||
weights = np.zeros(numpts) |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
weights[ir] = (1 / cr) * (1 - sf) * (1 - sc) + ( | ||
(abs(cr - abs(ii - i * cr))) / (cr * cr) | ||
) * sf * sc | ||
return [numpts, idxmin, weights] |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
elif ii % cr != 0: | ||
numpts = (1 - sf) * (1 - sc) + 2 * sf * sc | ||
idxmin = (ii // cr) * (1 - sf) * (1 - sc) + (ii // cr) * sf * sc | ||
weights = np.zeros(numpts) |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
idxmin = (ii // cr) * (1 - sf) * (1 - sc) + (ii // cr) * sf * sc | ||
weights = np.zeros(numpts) | ||
for ir in range(numpts): | ||
i = idxmin + ir |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
weights[ir] = (1 - sf) * (1 - sc) + ( | ||
(abs(cr - abs(ii - i * cr))) / (cr) | ||
) * sf * sc | ||
return [numpts, idxmin, weights] |
Check failure
Code scanning / CodeQL
Potentially uninitialized local variable Error
# def coarsening_points_and_weights_for_IO( i, sf, sc, cr ): | ||
# if ( cr==1 ): | ||
# numpts = 1+abs(sf-sc) | ||
# idxmin = i-sc*(1-sf) | ||
# elif ( cr>=2 ): | ||
# numpts = 2-sf | ||
# idxmin = i*cr+cr//2*(1-sc)-(1-sf) | ||
# weights = np.zeros( numpts ) | ||
# for ir in range( numpts ): | ||
# weights[ir] = (1/numpts)*(1-sf)*(1-sc)+(1/numpts)*sf*sc | ||
# return [ numpts, idxmin, weights ] |
Check notice
Code scanning / CodeQL
Commented-out code Note
Summary
This PR rewrites
ablastr::coarsen::average
to handle any staggering while maintaining the desired property of charge conservation. The results are the same for cell-centered for any coarsening ratior
and for nodal-fields whenr=1,2
, but differs for largerr
. The new weights reduce the magnitude of the highest-order error.Additional Information
The
Coarsen
function is rewritten so thatInterp
avoids calculations that are independent of the staggering. The Python filecheck_interp_points_and_weights.py
is rewritten to match the new formula. The functions ofablastr::coarsen::average
now give the same results asablastr::coarsen::sample
forr=1
, perhaps making the latter obsolete.A rough draft of the derivation of the weights can be found here:
coarsen-average-generalization-derivation.pdf
Prior Docs
2020 PDF by @EZoni : https://github.com/ECP-WarpX/WarpX/files/9904632/Slides-Interpolation-IO-MR.pdf
To Do