svenreiche / Genesis-1.3-Version4

Time-dependent, 3D Code to simulate the amplification process of a Free-electron Laser.
GNU General Public License v3.0
55 stars 27 forks source link

definition of undulator aw value using sequence as the lattice is parsed #127

Closed ZeugAusHH closed 10 months ago

ZeugAusHH commented 10 months ago

This patch adds the option to define the undulator aw value using a reference to an exisiting sequence as the lattice is being parsed. On the one hand, the result is a dramatic reduction of file size of lattice files describing tapered undulators. Furthermore, the taper can be adjusted using a single parameter in the main input file (no need to rewrite the .lat file).

In addition, this patch also introduces sequence_polynom. This sequence evaluates to s(n)=c0+c1*n+c2*n^2+c3*n^3+c4*n^4, with n being the number of values obtained from the sequence since its definition.

Here is an example with linear taper:

&sequence_polynom
   label=aw.sase2
   c0=1.696465
   c1=-1.000000e-04
&end

Then &setup etc., as usually (the &setup block triggers parsing of the lattice, so the sequence needs to be defined first).

In the example, the definition of the undulator in the lattice looks like:

SECT1_001UND: UNDULATOR = {lambdau = 0.04, nwig = 124.0, aw = @aw.sase2, helical = false};

One can then define the other components in the lattice as before and compose the beamline. I have also verified that it works as expected with lattices that first define the FODO cell, with the final beamline being defined in a second step using the n*FODO syntax.

Since I am working a lot on harmonic lasing at the moment, I also implemented this for the phaseshifter parameter phi. The design of the new code allows to readily implement this for further parameters, if needed.

svenreiche commented 10 months ago

Hi Christoph,

thanks for this feature. I just wanted to let you know that I was also working on that. I had the strategy to not fully parse the lattice in setup or alter_setup. Just to a point where I have each element identify and place in a map with its label containing the actual parameter still as string. The unrolling is then done in the tracking command, where then the sequence values can replace the reference to sequences. That way the same lattice can be modified differently for multiple tracks in the same input deck. I need this feature also for undulator errors etc.

svenreiche commented 10 months ago

Also the sequence feature hasn't been added yet in the manual. I can do that.

ZeugAusHH commented 10 months ago

Dear Sven,

thanks for merging, just a comment:

Deferred evaluation of the references only during &track execution is actually more elegant, but I guess also the implementation is more complex... But I assume the code that is in dev branch can be put together in several (different) ways... Per-period undulator errors need to be done in "your way", I could only do per-undulator detuning errors...

Actually I did also also implement a list sequence that reads the values from a text file, line by line. The underlying class takes a vector with the data and most likely can be also be used to complete the almost finished sequence_list. Once tested I would open a pull request for this.

Best Christoph

svenreiche commented 10 months ago

Hi Christoph,

look at SeriesParser::initList I have already started the implementation. Still need the evaluation of the sequence element but I can add it very soon (it is just storing the vector and once the element is out of range it should fall back to a default value. I need this functionality for a fast or simple way to interface with an optimizer, e.g. for optimizing taper profile.

You can build on top of it if you like.

I have also done the parser to just get the parsing down to the string level. For the evaluation and unrolling, I still need some time.

Best Sven


Paul Scherrer Institut

Sven Reiche WBGB/119 CH-5232 Villigen PSI

Telefon: +41 56 310 51 19 E-Mail: @.**@.>


From: Christoph Lechner @.> Sent: Wednesday, December 6, 2023 17:19 To: svenreiche/Genesis-1.3-Version4 @.> Cc: Reiche Sven @.>; State change @.> Subject: Re: [svenreiche/Genesis-1.3-Version4] definition of undulator aw value using sequence as the lattice is parsed (PR #127)

Dear Sven,

thanks for merging, just a comment:

Deferred evaluation of the references only during &track execution is actually more elegant, but I guess also the implementation is more complex... But I assume the code that is in dev branch can be put together in several (different) ways... Per-period undulator errors need to be done in "your way", I could only do per-undulator detuning errors...

Actually I did also also implement a list sequence that reads the values from a text file, line by line. The underlying class takes a vector with the data and most likely can be also be used to complete the almost finished sequence_list. Once tested I would open a pull request for this.

Best Christoph

— Reply to this email directly, view it on GitHubhttps://github.com/svenreiche/Genesis-1.3-Version4/pull/127#issuecomment-1843228692, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AK2LSE6AELHJPVZIPY55UXDYICLJ3AVCNFSM6AAAAABAIJEAWWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBTGIZDQNRZGI. You are receiving this because you modified the open/close state.Message ID: @.***>