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

Space charge 2D envelope push #841

Open
wants to merge 48 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a605081
Initial draft commit.
cemitch99 Feb 11, 2025
9b464c1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 11, 2025
862d53e
Update EnvelopeSpaceChargePush.H
cemitch99 Feb 11, 2025
5925584
Update EnvelopeSpaceChargePush.cpp
cemitch99 Feb 11, 2025
25f9185
Update EnvelopeSpaceChargePush.cpp
cemitch99 Feb 11, 2025
8130f43
Apply suggestions from code review
cemitch99 Feb 11, 2025
98a9fb1
[pre-commit.ci] pre-commit autoupdate (#839)
pre-commit-ci[bot] Feb 10, 2025
cd1d75c
Doc: How-To Update (#838)
ax3l Feb 10, 2025
f43668d
Fix `beam.units = static` (#840)
ax3l Feb 11, 2025
d37f810
openPMD Beam Input via `Source` Element (#820)
ax3l Feb 11, 2025
8f34ad6
Dashboard: Add tooltips (#843)
proy30 Feb 11, 2025
41cd4b0
Update Stub Files
ax3l Feb 11, 2025
99f69b7
Remove AMREX_FORCE_INLINE
cemitch99 Feb 11, 2025
1ea8528
Add calculation of beam perveance.
cemitch99 Feb 11, 2025
dbf41d4
Fix ParmParse.
cemitch99 Feb 11, 2025
0397587
Update EnvelopeSpaceChargePush.cpp
cemitch99 Feb 11, 2025
dd171b9
Update InitDistribution.cpp
cemitch99 Feb 11, 2025
6b1174e
Merge branch 'development' into add_spch2D_envelope
cemitch99 Feb 13, 2025
1878ab0
Input file for benchmark example.
cemitch99 Feb 14, 2025
7c39662
Correct perveance calculation. Hard-coded current for testing.
cemitch99 Feb 14, 2025
04ba2ba
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 14, 2025
7018335
Update benchmark example input files.
cemitch99 Feb 14, 2025
a7ee8b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 14, 2025
dc32c6d
Fix unused ParmParse variable error.
cemitch99 Feb 14, 2025
6effcc9
Remove unused drift3.
cemitch99 Feb 14, 2025
796f19d
Add support for current input, some refactoring.
cemitch99 Feb 14, 2025
4e7c288
Make Python current arg optional.
cemitch99 Feb 14, 2025
8fe40cf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 14, 2025
47a87a7
Fix Doxygen in CovarianceMatrix.H
cemitch99 Feb 15, 2025
e2b903e
Pass covariance matrix by reference.
cemitch99 Feb 15, 2025
c481250
Fix Doxygen error.
cemitch99 Feb 15, 2025
11fac54
Another Doxygen error.
cemitch99 Feb 15, 2025
8bb3f27
Try to fix Doxygen again.
cemitch99 Feb 15, 2025
810bdb7
Add space_charge_model input.
cemitch99 Feb 16, 2025
0df5bc4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 16, 2025
eee70e9
Move space charge envelope files.
cemitch99 Feb 18, 2025
9fc5601
Add basic documentation.
cemitch99 Feb 18, 2025
cfc02c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 18, 2025
bfa2cdd
Update how_to_run table.
cemitch99 Feb 20, 2025
0a6fd03
Verbatim
ax3l Feb 20, 2025
4692d4e
CMake: Rename Examples
ax3l Feb 20, 2025
cc17e57
CMake: Remove Empty Command
ax3l Feb 20, 2025
b17c29a
Readme Formatting & Link
ax3l Feb 20, 2025
b922ed4
Apply Changes from Review, Fix Tests
ax3l Feb 20, 2025
865cbd1
Update benchmark README.
cemitch99 Feb 21, 2025
0d04230
Python: `Envelope` Class
ax3l Feb 21, 2025
6e65816
Backwards Compatible `algo.space_charge` evolution
ax3l Feb 21, 2025
b23c9af
Update all Examples
ax3l Feb 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/particles/spacecharge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ target_sources(lib
ForceFromSelfFields.cpp
GatherAndPush.cpp
PoissonSolve.cpp
EnvelopeSpaceChargePush.cpp
)
41 changes: 41 additions & 0 deletions src/particles/spacecharge/EnvelopeSpaceChargePush.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Copyright 2022-2023 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: Chad Mitchell, Axel Huebl
* License: BSD-3-Clause-LBNL
*/
#ifndef IMPACTX_ENVELOPESPACECHARGEPUSH_H
#define IMPACTX_ENVELOPESPACECHARGEPUSH_H

#include "particles/ImpactXParticleContainer.H"
#include "particles/CovarianceMatrix.H"

#include <AMReX_REAL.H>


namespace impactx::spacecharge
{
/** This function pushes the 6x6 beam covariance matrix for a slice
* of length ds, using the linear space charge fields in an rms
* equivalent 2D ellipse, as determined from the beam covariance matrix.
* Note: This is a reduced model of 2D space charge.
*
* @param[in] refpart reference particle
* @param[inout] cm covariance matrix
* @param[in] current beam current [A]
* @param[in] ds step size [m]
*/
void
envelope_space_charge2D_push (
RefPart const & refpart,
Map6x6 & cm,
amrex::ParticleReal & current,
amrex::ParticleReal & ds
);

} // namespace impactx

#endif // IMPACTX_ENVELOPESPACECHARGEPUSH_H
68 changes: 68 additions & 0 deletions src/particles/spacecharge/EnvelopeSpaceChargePush.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* Copyright 2022-2023 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 "EnvelopeSpaceChargePush.H"

#include <AMReX_BLProfiler.H>
#include <AMReX_REAL.H> // for Real
#include <AMReX_SmallMatrix.H>

#include <cmath>

namespace impactx::spacecharge
{
/** This function returns the linear transport map associated with a
* reduced 2D space charge model, based on the beam covariance matrix.
*
* @param[in] refpart reference particle
* @param[in,out] cm covariance matrix
* @param[in] current beam current [A]
* @param[in] ds step size [m]
* @returns 6x6 transport matrix
*/
AMREX_GPU_HOST AMREX_FORCE_INLINE
void
envelope_space_charge2D_push (
RefPart const & refpart,
Map6x6 & cm,
amrex::ParticleReal & current,
amrex::ParticleReal & ds
)
{
using namespace amrex::literals;

// initialize the linear transport map
Map6x6 R = Map6x6::Identity();

// access reference particle values to find beta*gamma^2
amrex::ParticleReal const pt_ref = refpart.pt;
amrex::ParticleReal const betgam2 = std::pow(pt_ref, 2) - 1.0_prt;

// evaluate the beam space charge perveance from current
// TODO
amrex::ParticleReal const Kpv=0.0_prt;

// evaluate the linear transfer map
amrex::ParticleReal const sigma2 = cm(1,1)*cm(3,3)-cm(1,3)*cm(1,3);
amrex::ParticleReal const sigma = std::sqrt(sigma2);
amrex::ParticleReal const D = (sigma + cm(1,1)) * (sigma + cm(3,3)) - cm(1,3)*cm(1,3);
amrex::ParticleReal const coeff = Kpv*ds/(2.0_prt*D);

R(2,1) = coeff * (sigma + cm(3,3));
R(2,3) = coeff * (-cm(1,3));
R(4,1) = R(2,3);
R(4,3) = coeff * (sigma + cm(1,1));

// update the beam covariance matrix
cm = R * cm * R.transpose();

}


} // namespace impactx::spacecharge
14 changes: 11 additions & 3 deletions src/tracking/envelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "initialization/InitAmrCore.H"
#include "particles/ImpactXParticleContainer.H"
#include "particles/Push.H"
#include "particles/spacecharge/EnvelopeSpaceChargePush.H"
#include "diagnostics/DiagnosticOutput.H"

#include <AMReX.H>
Expand Down Expand Up @@ -77,7 +78,7 @@ namespace impactx
amrex::ParmParse const pp_algo("algo");
bool space_charge = false;
pp_algo.query("space_charge", space_charge);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(!space_charge, "Space charge not yet implemented for envelope tracking.");
//AMREX_ALWAYS_ASSERT_WITH_MESSAGE("2D space charge only is implemented for envelope tracking.");
if (verbose > 0)
{
amrex::Print() << " Space Charge effects: " << space_charge << "\n";
Expand Down Expand Up @@ -123,15 +124,22 @@ namespace impactx
<< " slice_step=" << slice_step << "\n";
}

std::visit([&ref, &cm](auto&& element)
std::visit([&ref, &cm, &slice_ds, &space_charge](auto&& element)
{
// push reference particle in global coordinates
{
BL_PROFILE("impactx::Push::RefPart");
element(ref);
}

// push Covariance Matrix
if (space_charge)
{
// push Covariance Matrix in 2D space charge fields
amrex::ParticleReal current=0.0; //TODO: This must be set.
spacecharge::envelope_space_charge2D_push(ref,cm,current,slice_ds);
}

// push Covariance Matrix in external fields
element(cm, ref);

}, element_variant);
Expand Down
Loading