-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New Fields: Phi & Force Add new fields (MultiFabs) for the scalar potential and the space charge force. * Poisson Solver * Fix Space Charge Force Constructor * Add ForceFromSelfFields Add function ForceFromSelfFields to calculate space charge self fields and their force. * Phi & Force: Expose to Python * rename: space_charge_field * Implement: Nodal Gather and Push Momentum * Force Calc: Fix Stray Include * Cleaning: Docs, Formatting, Constants, Constness * Test: Analyze Expanding Beam Co-authored-by: Marco Garten <mgarten@lbl.gov>
- Loading branch information
Showing
13 changed files
with
496 additions
and
13 deletions.
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.