Skip to content

Add FEL simulation#555

Open
mbkkunze wants to merge 13 commits into
IPPL-framework:masterfrom
mbkkunze:FEL
Open

Add FEL simulation#555
mbkkunze wants to merge 13 commits into
IPPL-framework:masterfrom
mbkkunze:FEL

Conversation

@mbkkunze

Copy link
Copy Markdown
Contributor

Summary

  • Adds a free-electron laser simulation under fel/, built with -DIPPL_ENABLE_FEL=ON.
    It runs an FDTD/PIC simulation of a relativistic electron bunch through an
    undulator in a co-moving Lorentz frame and writes the forward radiated power to CSV
    (with an optional Poynting-flux video).

Build & run

cmake -S . -B build -DIPPL_ENABLE_FEL=ON -DCMAKE_CXX_STANDARD=20
cmake --build build --target FreeElectronLaser
cd build && mkdir -p ../renderdata
./fel/FreeElectronLaser ../fel/config.json --info 5

Notes

  • Bunch initialization and the resonance-power diagnostic are ported from
    MITHRA (A. Fallahi, GPL).
  • More detail in fel/README.md.

@mbkkunze

Copy link
Copy Markdown
Contributor Author

Please add @s-mayani as reviewer

@aaadelmann aaadelmann requested a review from s-mayani June 25, 2026 10:24
Comment thread fel/MithraBunch.h Outdated
Comment on lines +39 to +42
/* Type of the bunch which is one of the manual, ellipsoid, cylinder, cube, and 3D-crystal. If
* it is manual the charge at points of the position vector will be produced.
*/
// std::string bunchType_;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why is this commented? remove if not used

Comment thread fel/MithraBunch.h Outdated
FieldVector<scalar> initialDirection_;

/* Position of the center of the bunch in the unit of length scale. */
// std::vector<FieldVector<scalar> > position_;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove commented line

Comment thread fel/MithraBunch.h Outdated
FieldVector<scalar> betaVector_;

/* Initialize the parameters for the bunch initialization to some first values. */
// BunchInitialize ();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here

Comment thread fel/MithraBunch.h Outdated
*/
Double e;

// Charge();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove commented line

Comment thread fel/MithraBunch.h Outdated
Comment on lines +180 to +182
// printmessage(std::string(__FILE__), __LINE__, std::string("Warning: The number of
// particles in the bunch is not a multiple of four. ") +
// std::string("It is corrected to ") + std::to_string(bunchInit.numberOfParticles_) );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you could also print this in an IPPL inform message, and uncomment it

Comment thread fel/MithraBunch.h Outdated
Comment on lines +207 to +208
// printmessage(std::string(__FILE__), __LINE__, std::string("The bunching factor can not be
// larger than one or a negative value !!!") ); exit(1);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can uncomment this and turn it into an IpplException

Comment thread fel/MithraBunch.h Outdated
Comment on lines +230 to +235
// if ( bunchInit.generator_ == "random" )
return (randomNumbers.at(n * 2 * Np / ng + m));
// else
// return ( randomNumbers[ n * 2 * Np/ng + m ] );
// TODO: Return halton properly
// return ( halton(n,m) );

@s-mayani s-mayani Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove all the commented code here (do we really need halton rng? )

Comment thread fel/MithraBunch.h Outdated
}

/* If the longitudinal type of the bunch is uniform a tapered part needs to be added to remove
* the CSE from the tail of the bunch.

@s-mayani s-mayani Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

change the CSE to full form of the acronym

@s-mayani s-mayani left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Left some minor comments to be addressed

@aaadelmann

Copy link
Copy Markdown
Member

cscs-ci run cscs-ci-gh200, cscs-ci-mi300, cscs-ci-openmp

The deposition kernel applies a half-cell shift before computing CIC weights:

    gp = (mid - origin) / h - 0.5

This was introduced so current deposition uses the same centering convention as
the field gather on the cell-centered UniformCartesian grid. With that shift,
a particle segment whose midpoint is at the geometric cell center no longer
splits uniformly over the surrounding 2^Dim nodes. Instead, it lands exactly on
the shifted node location.

The exact-value unit test still used the older unshifted convention:

    gp = (mid - origin) / h

This made the test expect, for example, a 2D x-directed segment from 0.25 to
0.75 at y=0.5 to deposit

    Jx = 0.125

on each of four neighboring nodes. The current kernel correctly deposits the
full

    Jx = 0.5

on the shifted node and zero on the other three nodes. This mismatch caused
TestCurrentDeposition to fail for all 2D and 3D typed exact-value cases.

This change updates the expected tables and comments in
TestCurrentDeposition.cpp for the half-cell-shifted convention:

Verification:
- Built TestCurrentDeposition
- Ran TestCurrentDeposition via CTest: passed
- Ran full OpenMP unit_tests CTest tree: 35/35 passed
@aaadelmann

Copy link
Copy Markdown
Member

cscs-ci run cscs-ci-gh200, cscs-ci-mi300, cscs-ci-openmp

@aaadelmann

Copy link
Copy Markdown
Member

@s-mayani @mbkkunze please check carefully ccd6227

@aaadelmann

Copy link
Copy Markdown
Member

cscs-ci run cscs-ci-gh200, cscs-ci-mi300, cscs-ci-openmp

1 similar comment
@aaadelmann

Copy link
Copy Markdown
Member

cscs-ci run cscs-ci-gh200, cscs-ci-mi300, cscs-ci-openmp

@s-mayani

Copy link
Copy Markdown
Collaborator

@s-mayani @mbkkunze please check carefully ccd6227

I am confused, why do we need this? I thought the tests were already working correctly

@aaadelmann

Copy link
Copy Markdown
Member

This test was failing at CSCS and local on my laptop. Lets see if I can find earlier tests at CSCS that passed.

@aaadelmann

aaadelmann commented Jun 30, 2026

Copy link
Copy Markdown
Member

@s-mayani

Copy link
Copy Markdown
Collaborator

At cscs #555 did never pass all tests (https://my.cdash.org/queryTests.php?project=IPPL&date=2026-06-30&filtercount=2&showfilters=1&filtercombine=and&field1=status&compare1=62&value1=passed&field2=buildname&compare2=63&value2=555)

Bit still it could be a side effect of an other commit.

Okay I see, but I am still confused since the current projection was merged in a separate PR which did pass tests.

@mbkkunze

mbkkunze commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Pushed the cleanup from @s-mayani comments.

Thank you very much for fixing the tests numbers @aaadelmann! Looks all correct to me. A bit of explanation: At the time when the current deposition was merged previously, I was still thinking that the solver was using a staggered grid, so I wrote the deposition for that. Then it turned out that this was not the case, so I had to change to the colocated grid. When I later fixed a half-cell off bug, I forgot to update the tests accordingly.

Do we want to keep the staggered version for future use (If yes I will re-add it and its tests), or keep only the colocated one which is what the Maxwell solver uses?

@aaadelmann

Copy link
Copy Markdown
Member

Yes push the other test too!

@klappi-s klappi-s mentioned this pull request Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants