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

Use pyamrex in spacecraft charging example #4817

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

Conversation

RemiLehe
Copy link
Member

@RemiLehe RemiLehe commented Apr 2, 2024

No description provided.

@RemiLehe RemiLehe marked this pull request as draft April 2, 2024 21:10
@ax3l ax3l added component: tests Tests and CI component: Python Python layer labels Apr 3, 2024
@RemiLehe RemiLehe changed the title [WIP] Use pyamrex in spacecraft charging example Use pyamrex in spacecraft charging example Sep 23, 2024
@RemiLehe RemiLehe marked this pull request as ready for review September 23, 2024 23:06
@ax3l ax3l self-requested a review September 23, 2024 23:09
@ax3l ax3l self-assigned this Sep 23, 2024
Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Ran locally for me, minus checksum stability.

This still uses the global API from Dave (but now from pyAMReX); if we want to parallelize it further we could do another follow-up :)

Use the one that does not rely on naming conventions but has
named arguments. (The other one worked as well, but is deprecated.)
@ax3l ax3l enabled auto-merge (squash) January 26, 2025 01:15
@ax3l ax3l disabled auto-merge January 26, 2025 17:54
ax3l added a commit to AMReX-Codes/pyamrex that referenced this pull request Jan 29, 2025
We already have `.size` and we can iterate the `FabArray`, so we should
support `len(mf)`, too.

Seen in ECP-WarpX/WarpX#4817
2 * len(phi)
nr = phi.shape[0]
r = np.linspace(rmin, rmax, nr, endpoint=False) + (rmax - rmin) / (
2 * nr
) # shift of the r points because the derivaties are calculated in the middle
face_z0 = (
2 * np.pi * 1.0 / dz * ((phi[:, 0] - phi[:, 1]) * r).sum() * dr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct/as before: the : is without ghost cells, () is with ghost cells.
https://pyamrex.readthedocs.io/en/latest/usage/compute.html

Comment on lines +81 to +84
self.normalized_Er = warpx.multifab("Efield_fp", dir=self.dir_r, level=0).copy()
self.normalized_Er.mult(1 / q_v, 0)
self.normalized_Ez = warpx.multifab("Efield_fp", dir=self.dir_z, level=0).copy()
self.normalized_Ez.mult(1 / q_v, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now perfectly parallel in MPI contexts, no global comms.

phi = PhiFPWrapper(include_ghosts=True)
phi[...] += (q - q_v) * self.normalized_phi
Er = warpx.multifab("Efield_fp", dir=self.dir_r, level=0)
Er.saxpy(Er, (q - q_v), self.normalized_Er, 0, 0, 1, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now perfectly parallel in MPI contexts, no global comms.

Comment on lines +56 to +61
Er = warpx.multifab("Efield_fp", dir=self.dir_r, level=0)
Er.saxpy(Er, (q - q_v), self.normalized_Er, 0, 0, 1, 0)
Ez = warpx.multifab("Efield_fp", dir=self.dir_z, level=0)
Ez.saxpy(Ez, (q - q_v), self.normalized_Ez, 0, 0, 1, 0)
phi = warpx.multifab("phi_fp", level=0)
phi.saxpy(phi, (q - q_v), self.normalized_phi, 0, 0, 1, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: #5613 will change saxpy

Suggested change
Er = warpx.multifab("Efield_fp", dir=self.dir_r, level=0)
Er.saxpy(Er, (q - q_v), self.normalized_Er, 0, 0, 1, 0)
Ez = warpx.multifab("Efield_fp", dir=self.dir_z, level=0)
Ez.saxpy(Ez, (q - q_v), self.normalized_Ez, 0, 0, 1, 0)
phi = warpx.multifab("phi_fp", level=0)
phi.saxpy(phi, (q - q_v), self.normalized_phi, 0, 0, 1, 0)
Er = warpx.multifab("Efield_fp", dir=self.dir_r, level=0)
Er.saxpy(q - q_v, self.normalized_Er, 0, 0, 1, 0)
Ez = warpx.multifab("Efield_fp", dir=self.dir_z, level=0)
Ez.saxpy(q - q_v, self.normalized_Ez, 0, 0, 1, 0)
phi = warpx.multifab("phi_fp", level=0)
phi.saxpy(q - q_v, self.normalized_phi, 0, 0, 1, 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Python Python layer component: tests Tests and CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants