-
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
Introduce HandleSpacecharge
#842
Merged
ax3l
merged 2 commits into
BLAST-ImpactX:development
from
ax3l:topic-handle-spacecharge
Feb 12, 2025
+162
−81
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ target_sources(lib | |
PRIVATE | ||
ForceFromSelfFields.cpp | ||
GatherAndPush.cpp | ||
HandleSpacecharge.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
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,38 @@ | ||
/* Copyright 2022-2025 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, Chad Mitchell | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
#ifndef IMPACTX_HANDLE_SPACECHARGE_H | ||
#define IMPACTX_HANDLE_SPACECHARGE_H | ||
|
||
#include "initialization/AmrCoreData.H" | ||
|
||
#include <AMReX_REAL.H> | ||
|
||
#include <functional> | ||
#include <memory> | ||
|
||
|
||
namespace impactx::particles::spacecharge | ||
{ | ||
/** Function to handle space charge including charge deposition, Poisson solve, | ||
* field calculation, interpolation, and particle push. | ||
* | ||
* @param[in,out] amr_data AMR data like particle container and fields | ||
* @param[in] ResizeMesh function to call to resize the mesh | ||
* @param[in] slice_ds slice spacing along s | ||
*/ | ||
void HandleSpacecharge ( | ||
std::unique_ptr<initialization::AmrCoreData> & amr_data, | ||
std::function<void()> ResizeMesh, | ||
amrex::Real slice_ds | ||
); | ||
|
||
} // namespace impactx::particles::spacecharge | ||
|
||
#endif // IMPACTX_HANDLE_SPACECHARGE_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,108 @@ | ||
/* Copyright 2022-2025 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, Chad Mitchell | ||
* License: BSD-3-Clause-LBNL | ||
*/ | ||
#include "HandleSpacecharge.H" | ||
|
||
#include "initialization/AmrCoreData.H" | ||
#include "particles/ImpactXParticleContainer.H" | ||
#include "particles/spacecharge/ForceFromSelfFields.H" | ||
#include "particles/spacecharge/GatherAndPush.H" | ||
#include "particles/spacecharge/PoissonSolve.H" | ||
#include "particles/transformation/CoordinateTransformation.H" | ||
|
||
#include <AMReX_ParmParse.H> | ||
#include <AMReX_REAL.H> | ||
|
||
#include <memory> | ||
|
||
|
||
namespace impactx::particles::spacecharge | ||
{ | ||
void HandleSpacecharge ( | ||
std::unique_ptr<initialization::AmrCoreData> & amr_data, | ||
std::function<void()> ResizeMesh, | ||
amrex::Real slice_ds | ||
) | ||
{ | ||
BL_PROFILE("impactx::particles::wakefields::HandleSpacecharge") | ||
|
||
amrex::ParmParse const pp_algo("algo"); | ||
bool space_charge = false; | ||
pp_algo.query("space_charge", space_charge); | ||
|
||
// turn off if disabled by user | ||
if (!space_charge) { return; } | ||
|
||
// turn off if less than 2 particles | ||
if (amr_data->track_particles.m_particle_container->TotalNumberOfParticles(true, false) < 2) { return; } | ||
|
||
// transform from x',y',t to x,y,z | ||
transformation::CoordinateTransformation( | ||
*amr_data->track_particles.m_particle_container, | ||
CoordSystem::t | ||
); | ||
|
||
// Note: The following operation assume that | ||
// the particles are in x, y, z coordinates. | ||
|
||
// Resize the mesh, based on `amr_data->track_particles.m_particle_container` extent | ||
ResizeMesh(); | ||
|
||
// Redistribute particles in the new mesh in x, y, z | ||
amr_data->track_particles.m_particle_container->Redistribute(); | ||
|
||
// charge deposition | ||
amr_data->track_particles.m_particle_container->DepositCharge( | ||
amr_data->track_particles.m_rho, | ||
amr_data->refRatio() | ||
); | ||
|
||
// poisson solve in x,y,z | ||
spacecharge::PoissonSolve( | ||
*amr_data->track_particles.m_particle_container, | ||
amr_data->track_particles.m_rho, | ||
amr_data->track_particles.m_phi, | ||
amr_data->refRatio() | ||
); | ||
|
||
// calculate force in x,y,z | ||
spacecharge::ForceFromSelfFields( | ||
amr_data->track_particles.m_space_charge_field, | ||
amr_data->track_particles.m_phi, | ||
amr_data->Geom() | ||
); | ||
|
||
// gather and space-charge push in x,y,z , assuming the space-charge | ||
// field is the same before/after transformation | ||
// TODO: This is currently using linear order. | ||
spacecharge::GatherAndPush( | ||
*amr_data->track_particles.m_particle_container, | ||
amr_data->track_particles.m_space_charge_field, | ||
amr_data->Geom(), | ||
slice_ds | ||
); | ||
|
||
// transform from x,y,z to x',y',t | ||
transformation::CoordinateTransformation( | ||
*amr_data->track_particles.m_particle_container, | ||
CoordSystem::s | ||
); | ||
|
||
// for later: original Impact implementation as an option | ||
// Redistribute particles in x',y',t | ||
// TODO: only needed if we want to gather and push space charge | ||
// in x',y',t | ||
// TODO: change geometry beforehand according to transformation | ||
//m_amr_data->track_particles.m_particle_container->Redistribute(); | ||
// | ||
// in original Impact, we gather and space-charge push in x',y',t , | ||
// assuming that the distribution did not change | ||
} | ||
|
||
} // namespace impactx::particles::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
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
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.
This is the location that this PR cleans up :)