Skip to content
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

Open
wants to merge 33 commits into
base: development
Choose a base branch
from

Conversation

eebasso
Copy link
Member

@eebasso eebasso commented Nov 30, 2023

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 ratio r and for nodal-fields when r=1,2, but differs for larger r. The new weights reduce the magnitude of the highest-order error.

Additional Information

The Coarsen function is rewritten so that Interp avoids calculations that are independent of the staggering. The Python file check_interp_points_and_weights.py is rewritten to match the new formula. The functions of ablastr::coarsen::average now give the same results as ablastr::coarsen::sample for r=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

  • add a doc section in the theory manual

@eebasso eebasso marked this pull request as draft November 30, 2023 23:18
@eebasso eebasso requested a review from ax3l December 1, 2023 01:24
@eebasso eebasso marked this pull request as ready for review December 1, 2023 01:25
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

Local variable 'ii_min' may be used before it is initialized.
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

Local variable 'ii_max' may be used before it is initialized.
elif sf == 1: # nodal
iimin = 0
iimax = 8
return [iimin, iimax]

Check failure

Code scanning / CodeQL

Potentially uninitialized local variable Error

Local variable 'iimin' may be used before it is initialized.
elif sf == 1: # nodal
iimin = 0
iimax = 8
return [iimin, iimax]

Check failure

Code scanning / CodeQL

Potentially uninitialized local variable Error

Local variable 'iimax' may be used before it is initialized.
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

Local variable 'numpts' may be used before it is initialized.
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

Local variable 'idxmin' may be used before it is initialized.
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

Local variable 'numpts' may be used before it is initialized.
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

Local variable 'idxmin' may be used before it is initialized.
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

Local variable 'idxmin' may be used before it is initialized.
Comment on lines +94 to +104
# 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

This comment appears to contain commented-out code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants