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

Multibunch wakefieldpass #493

Merged
merged 23 commits into from
Sep 29, 2022
Merged

Multibunch wakefieldpass #493

merged 23 commits into from
Sep 29, 2022

Conversation

swhite2401
Copy link
Contributor

This PR implements multibunch wakefield computation making use of the fill pattern information introduced in #452

The particles are distributed into bunches using particle_number % number of bunches and this on each MPI process. The advantage is that the bunch structure is entirely independent of the number of CPUs which is a strong limitation in some existing codes where number of bunches = number of CPUs was required.
The drawback is that each process has to fulfill number of particle >= number of bunches which is the case for a vast majority of potential usage.

Changes associated to this branch:

  • adaptation of WakeFieldPass.c and atimplib.c for multibunch
  • simplification of wake_elements.py to use the fillpattern information and minor tweaks to related functions in lattice_object.py
  • python function to access bunch information (mean and std) are provided in at.tracking.utils, these are very basic and should be extended based on user's experience

Mutlibunch wake calculation is activated by setting the fillpattern using:

ring.set_fillpattern(nbunch)
ring.beam_current  = current

Besides these the syntax is identical to single bunch calculations.

@lcarver
Copy link
Contributor

lcarver commented Sep 21, 2022

I start with the longitudinal. I have simulated the LCBI with the simple longitudinal resonator and can make a comparison of the growth rate with the well known analytical theory.

Longitudinal resonator parameters:
fres = frf - f0 -fs
Q = 1e4
Rs = 2e6 Ohm

Simulated with 992 bunches over 64 cores with 640 particles per bunch (this value is low, further convergence is needed).

The figure shows the growth of the mode 1 (extracted by doing an SVD of the full 992 bunches vs 10000 turns).
image

Analytical growth rate of mode 1: 272.59s^-1
Simulated growth rate of mode 1: 255.08s^-1

I will clean up the LCBI script and add it to the Examples/CollectiveEffects folder in the pyat Repo. I think it is a useful case for users to add. Transverse RW benchmarking is ongoing.

Copy link
Contributor

@lfarv lfarv left a comment

Choose a reason for hiding this comment

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

WakefieldPass.c does not compile in Matlab:

WakeFieldPass.c:148:29: error: use of undeclared identifier 'PyExc_ValueError'

All files in atintegrators are compiled, even if they are not used. So you must provide the mex entry points (mexFunction and trackFunction, possibly just throwing an error if it cannot be used in Matlab), and provide a compatible way to throw exceptions: for instance see AtGetLong in the included atelem.c file.

If you want, I can modify atelem.c to provide a function to throw arbitrary errors.

@swhite2401
Copy link
Contributor Author

WakefieldPass.c does not compile in Matlab:

WakeFieldPass.c:148:29: error: use of undeclared identifier 'PyExc_ValueError'

All files in atintegrators are compiled, even if they are not used. So you must provide the mex entry points (mexFunction and trackFunction, possibly just throwing an error if it cannot be used in Matlab), and provide a compatible way to throw exceptions: for instance see AtGetLong in the included atelem.c file.

If you want, I can modify atelem.c to provide a function to throw arbitrary errors.

Ok I will change this, I thought the mexfunction was optional.
A function to throw warning and errors would be useful yes.

@lfarv
Copy link
Contributor

lfarv commented Sep 26, 2022

Added the atError(const char *format,...) and atWarning(const char *format,...) functions. See the modified WakefieldPass.c for an example. However, it still blocks in Matlab:

Could not compile /Users/famille/dev/libraries/at/atintegrators/WakeFieldPass.c: Undefined symbols for architecture x86_64:
  "_mexFunction", referenced from:
     -exported_symbol[s_list] command line option
  "_passFunction", referenced from:
     -exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Now, we need the 2 entry points !

@lcarver
Copy link
Contributor

lcarver commented Sep 26, 2022

Simulation of Transverse Resistive Wall for Q'=0. The formula (eq 31 of https://journals.iucr.org/s/issues/2014/05/00/xe5009/xe5009.pdf ) expects a mode -1 with a given growth rate.

Ib = 200mA
M=992
b=15mm
sigma_c = 1e8

Simulating a case in uniform filling with similar un-converged parameters as above gives the following:

image

As before, the data was acquired by doing an SVD of the 992xNturn data set. As before, I will soon put an example file in the directory as this is a fundamental test.

@swhite2401
Copy link
Contributor Author

Now, we need the 2 entry points !

Thanks! Very useful, I have added the mexfunction, it just prints an error message.

@swhite2401
Copy link
Contributor Author

Simulation of Transverse Resistive Wall for Q'=0. The formula (eq 31 of https://journals.iucr.org/s/issues/2014/05/00/xe5009/xe5009.pdf ) expects a mode -1 with a given growth rate.

Ib = 200mA M=992 b=15mm sigma_c = 1e8

Simulating a case in uniform filling with similar un-converged parameters as above gives the following:

image

As before, the data was acquired by doing an SVD of the 992xNturn data set. As before, I will soon put an example file in the directory as this is a fundamental test.

Very nice! thanks @lcarver is it just an impression or the rise time seems systematically lower than theory?

@lfarv
Copy link
Contributor

lfarv commented Sep 27, 2022

Thanks! Very useful, I have added the mexfunction, it just prints an error message.

OK, it now compiles correctly. But why not make it work ? At least the case nrhs == 0 to get the list of required and optional fields…

@lfarv lfarv self-requested a review September 27, 2022 08:57
Copy link
Contributor

@lfarv lfarv left a comment

Choose a reason for hiding this comment

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

No compilation problem in Matlab any more, so it's ok !

@swhite2401
Copy link
Contributor Author

OK, it now compiles correctly. But why not make it work ? At least the case nrhs == 0 to get the list of required and optional fields…

Ok to print out the required fields, but the full implementation does not make much sense does it?

@lfarv
Copy link
Contributor

lfarv commented Sep 27, 2022

You're right, it does not look realistic to run this on a single core in Matlab. But trackFunction, the entry point used in tracking a lattice, works, so why mexFunction would not ? Anyway, keep it as it is, it's ok for me !

@swhite2401
Copy link
Contributor Author

You're right, it does not look realistic to run this on a single core in Matlab. But trackFunction, the entry point used in tracking a lattice, works, so why mexFunction would not ? Anyway, keep it as it is, it's ok for me !

I have restored the mexfunction, still I think it is meaningless as the ring parameters cannot be passed...anyway it is done now, could be of some use for debugging...

Copy link
Contributor

@lcarver lcarver left a comment

Choose a reason for hiding this comment

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

Added example files for LCBI and TRW which can be found in pyat/examples/CollectiveEffects

For me, it has passed the 2 fundamental tests for longitudinal and transverse, some more detailed benchmarking will of course take place but for me this implementation is working well and is correct.

@lfarv lfarv added the Python For python AT code label Sep 28, 2022
@swhite2401 swhite2401 merged commit d6b2ccc into master Sep 29, 2022
@swhite2401 swhite2401 deleted the multibunch_wake branch September 29, 2022 15:14
@lfarv lfarv mentioned this pull request Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python For python AT code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants