-
Notifications
You must be signed in to change notification settings - Fork 23
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
Space Charge Solver #162
Merged
+496
−13
Merged
Space Charge Solver #162
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a4bf171
New Fields: Phi & Force
ax3l d17600e
Poisson Solver
ax3l 8e4bd43
Fix Space Charge Force Constructor
ax3l 70c2177
Add ForceFromSelfFields
n01r 6766085
Phi & Force: Expose to Python
ax3l 8a843ea
rename: space_charge_field
ax3l 5c3631f
Implement: Nodal Gather and Push Momentum
ax3l 7260a08
Force Calc: Fix Stray Include
ax3l fb00f6f
Cleaning: Docs, Formatting, Constants, Constness
ax3l e482a60
Test: Analyze Expanding Beam
ax3l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
target_sources(ImpactX | ||
PRIVATE | ||
ForceFromSelfFields.cpp | ||
GatherAndPush.cpp | ||
PoissonSolve.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* Copyright 2022 The Regents of the University of California, through Lawrence | ||
* Berkeley National Laboratory (subject to receipt of any required | ||
* approvals from the U.S. Dept. of Energy). All rights reserved. | ||
* | ||
* This file is part of ImpactX. | ||
* | ||
* Authors: Marco Garten, Axel Huebl | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
#ifndef IMPACTX_FORCEFROMSELFFIELDS_H | ||
#define IMPACTX_FORCEFROMSELFFIELDS_H | ||
|
||
#include "particles/ImpactXParticleContainer.H" | ||
|
||
#include <AMReX_Geometry.H> | ||
#include <AMReX_MultiFab.H> | ||
#include <AMReX_Vector.H> | ||
|
||
#include <unordered_map> | ||
|
||
|
||
namespace impactx::spacecharge | ||
{ | ||
/** Calculate the space charge force field from the electric potential | ||
* | ||
* This resets the values in scf_<component> to zero and then calculates the space | ||
* charge force field. | ||
* | ||
* @param[inout] space_charge_field space charge force component in x,y,z per level | ||
* @param[in] phi scalar potential per level | ||
* @param[in] geom geometry object | ||
*/ | ||
void ForceFromSelfFields ( | ||
std::unordered_map<int, std::unordered_map<std::string, amrex::MultiFab> > & space_charge_field, | ||
std::unordered_map<int, amrex::MultiFab> const & phi, | ||
const amrex::Vector<amrex::Geometry>& geom | ||
); | ||
|
||
} // namespace impactx | ||
|
||
#endif // IMPACTX_FORCEFROMSELFFIELDS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* Copyright 2022 The Regents of the University of California, through Lawrence | ||
* Berkeley National Laboratory (subject to receipt of any required | ||
* approvals from the U.S. Dept. of Energy). All rights reserved. | ||
* | ||
* This file is part of ImpactX. | ||
* | ||
* Authors: Marco Garten, Axel Huebl | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
#include "ForceFromSelfFields.H" | ||
|
||
#include <AMReX_BLProfiler.H> | ||
#include <AMReX_REAL.H> // for Real | ||
#include <AMReX_SPACE.H> // for AMREX_D_DECL | ||
|
||
|
||
namespace impactx::spacecharge | ||
{ | ||
void ForceFromSelfFields ( | ||
std::unordered_map<int, std::unordered_map<std::string, amrex::MultiFab> > & space_charge_field, | ||
std::unordered_map<int, amrex::MultiFab> const & phi, | ||
amrex::Vector<amrex::Geometry> const & geom | ||
) | ||
{ | ||
BL_PROFILE("impactx::spacecharge::ForceFromSelfFields"); | ||
|
||
using namespace amrex::literals; | ||
|
||
// loop over refinement levels | ||
int const finest_level = phi.size() - 1u; | ||
for (int lev = 0; lev <= finest_level; ++lev) { | ||
|
||
// stencil coefficients: 0.5 * inverse cell size | ||
auto const &gm = geom[lev]; | ||
auto const dr = gm.CellSizeArray(); | ||
amrex::GpuArray<amrex::Real, 3> const inv2dr{AMREX_D_DECL(0.5_rt/dr[0], 0.5_rt/dr[1], 0.5_rt/dr[2])}; | ||
|
||
// reset the values in space_charge_field to zero | ||
space_charge_field.at(lev).at("x").setVal(0.); | ||
space_charge_field.at(lev).at("y").setVal(0.); | ||
space_charge_field.at(lev).at("z").setVal(0.); | ||
|
||
for (amrex::MFIter mfi(phi.at(lev)); mfi.isValid(); ++mfi) { | ||
|
||
amrex::Box bx = mfi.validbox(); | ||
auto const phi_arr = (phi.at(lev))[mfi].const_array(); | ||
|
||
auto scf_arr_x = space_charge_field[lev]["x"][mfi].array(); | ||
auto scf_arr_y = space_charge_field[lev]["y"][mfi].array(); | ||
auto scf_arr_z = space_charge_field[lev]["z"][mfi].array(); | ||
|
||
amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { | ||
scf_arr_x(i, j, k) = inv2dr[0] * (phi_arr(i-1, j, k) - phi_arr(i+1, j, k)); | ||
scf_arr_y(i, j, k) = inv2dr[1] * (phi_arr(i, j-1, k) - phi_arr(i, j+1, k)); | ||
scf_arr_z(i, j, k) = inv2dr[2] * (phi_arr(i, j, k-1) - phi_arr(i, j, k+1)); | ||
}); | ||
} | ||
} | ||
} | ||
} // namespace impactx::spacecharge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* Copyright 2022 The Regents of the University of California, through Lawrence | ||
* Berkeley National Laboratory (subject to receipt of any required | ||
* approvals from the U.S. Dept. of Energy). All rights reserved. | ||
* | ||
* This file is part of ImpactX. | ||
* | ||
* Authors: Axel Huebl, Remi Lehe | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
#ifndef IMPACTX_GATHER_AND_PUSH_H | ||
#define IMPACTX_GATHER_AND_PUSH_H | ||
|
||
#include "particles/ImpactXParticleContainer.H" | ||
|
||
#include <AMReX_Geometry.H> | ||
#include <AMReX_MultiFab.H> | ||
#include <AMReX_Vector.H> | ||
|
||
#include <unordered_map> | ||
#include <string> | ||
|
||
|
||
namespace impactx::spacecharge | ||
{ | ||
/** Gather force fields and push particles in x,y,z | ||
* | ||
* This gathers the space charge field with respect to particle position | ||
* and shape. The momentum of all particles is then pushed using a common | ||
* time step given by the reference particle speed and ds slice. The | ||
* position push is done in the lattice elements and not here. | ||
* | ||
* @param[inout] pc container of the particles that deposited rho | ||
* @param[in] space_charge_field space charge force component in x,y,z per level | ||
* @param[in] geom geometry object | ||
* @param[in] slice_ds segment length in meters | ||
*/ | ||
void GatherAndPush ( | ||
ImpactXParticleContainer & pc, | ||
std::unordered_map<int, std::unordered_map<std::string, amrex::MultiFab> > const & space_charge_field, | ||
const amrex::Vector<amrex::Geometry>& geom, | ||
amrex::ParticleReal const slice_ds | ||
); | ||
|
||
} // namespace impactx | ||
|
||
#endif // IMPACTX_GATHER_AND_PUSH_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RemiLehe let's discuss this again, this might currently be too large (can be performance-optimized in a follow-up PR as well)