Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
6 changes: 3 additions & 3 deletions examples/expanding_beam/analysis_expanding_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def read_time_series(file_pattern):
assert np.allclose(
[sig_xf, sig_yf, sig_tf],
[
9.029112e-04,
9.029112e-04,
1.841402e-06,
8.94427191e-04,
Copy link
Member Author

Choose a reason for hiding this comment

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

Here the targets were tuned to analytically-determined values, instead of being set to coincide with a low-resolution run.

8.94427191e-04,
1.824483738e-06,
],
rtol=rtol,
atol=atol,
Expand Down
2 changes: 1 addition & 1 deletion examples/kurth/analysis_kurth_10nC_periodic_envelope.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def read_time_series(file_pattern):
)

atol = 0.0 # ignored
rtol = 2.0e-3 # from random sampling of a smooth distribution
rtol = 3.5e-3 # from random sampling of a smooth distribution
print(f" rtol={rtol} (ignored: atol~={atol})")
Copy link
Member Author

Choose a reason for hiding this comment

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

The original tolerance was too tight.


assert np.allclose(
Expand Down
1 change: 1 addition & 0 deletions src/initialization/InitElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace detail
int nslice = nslice_default;
pp_element.getWithParser("ds", ds);
pp_element.queryAddWithParser("nslice", nslice);
nslice = 2*nslice; // ensure nslice is even

AMREX_ALWAYS_ASSERT_WITH_MESSAGE(nslice > 0,
pp_element.getPrefix() + ".nslice must be > 0.");
Expand Down
20 changes: 17 additions & 3 deletions src/tracking/envelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ namespace impactx
}, element_variant);

// sub-steps for space charge within the element
for (int slice_step = 0; slice_step < nslice; ++slice_step)
int nsteps = std::floor(nslice/2.0);
for (int slice_step = 0; slice_step < nsteps; ++slice_step)
{
BL_PROFILE("ImpactX::track_envelope::slice_step");
step++;
Expand All @@ -147,14 +148,27 @@ namespace impactx
<< " slice_step=" << slice_step << "\n";
}

std::visit([&ref, &cm](auto&& element)
Copy link
Member

Choose a reason for hiding this comment

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

Is the reference particle pushed twice now? o.0

Happens again in line 176 below

Copy link
Member Author

@cemitch99 cemitch99 Jun 27, 2025

Choose a reason for hiding this comment

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

Clarified in person:

  • also includes envelope push
  • note the difference in weights (half step for push, full step for SC & CSR, another half step for push)

Copy link
Member Author

@cemitch99 cemitch99 Jun 27, 2025

Choose a reason for hiding this comment

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

We have to make sure that thin elements, which only go through this loop body once, are still only kicked once though.

{
// push reference particle in global coordinates
{
BL_PROFILE("impactx::Push::RefPart");
element(ref);
}

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

}, element_variant);

if (space_charge == SpaceChargeAlgo::True_2D)
{
// push Covariance Matrix in 2D space charge fields
envelope::spacecharge::space_charge2D_push(ref, cm, intensity, slice_ds);
envelope::spacecharge::space_charge2D_push(ref, cm, intensity, 2*slice_ds);
} else if (space_charge == SpaceChargeAlgo::True_3D)
{
// push Covariance Matrix in 3D space charge fields
envelope::spacecharge::space_charge3D_push(ref, cm, intensity, slice_ds);
envelope::spacecharge::space_charge3D_push(ref, cm, intensity, 2*slice_ds);
} else {
amrex::Print() << "Warning: Space charge is off by default." << "\n";
}
Expand Down
Loading