ChristopherMayes / lume-astra

Python wrapper for Astra (A Space Charge Tracking Algorithm, DESY) for eventual use in LUME https://christophermayes.github.io/lume-astra/
https://christophermayes.github.io/lume-astra/
Apache License 2.0
14 stars 9 forks source link

3D field maps in Cavity Namelist #14

Closed kathryn-baker closed 2 years ago

kathryn-baker commented 2 years ago

Hi there,

I'm new to ASTRA and lume-astra so I'm trying to get to know the software as it looks incredibly useful for a project I'll be completing.

To test lume-astra, I am trying to run it using a astra.in file which links to a number of files with predefined geometries/fields etc in each of the namelists.

This has caused an issue with the CAVITY namelist, where I am defining a 3D field map that links to three .ex, .ey and .ez files. In the .in file when I run Astra on my PC I am able to specify the path to these files using just the filename without the extensions e.g. filename.ex, filename.ey, filename.ez -> filename, but when I run the run_astra_with_generator function with this input, it tells me:

Path does not exist for symlink: filename

I presume this is because a file doesn't exist in the path with that filename as only the three files with the extension exist. Am I right in thinking that this is the case and if so, is there any way of specifying that it's those three files that I want to use in the run_astra_with_generator function?

Thanks for your help!

ChristopherMayes commented 2 years ago

@kathryn-baker could you attach a simple example that demonstrates the error?

kathryn-baker commented 2 years ago

I'm afraid I'm too new to both Astra and lume-astra to be able to produce a simple example different to the one that I've been provided so I've attached the information I think is relevant to what I'm trying to do and hopefully this helps.

I'm using python 3.9.5 and lume-astra version 0.4.5.

Using the following command:

from astra import run_astra_with_generator
settings0 = {} # empty as all of the settings should be defined in the astra.in file
A2 = run_astra_with_generator(settings0, 
                              astra_input_file=astra.in,
                              astra_bin=setup.astra_bin,
                              generator_bin=setup.generator_bin,
                              generator_input_file=generator.in, 
                              workdir='.',
                              verbose=True)

With the cavity settings defined in astra.in:

&CAVITY
 LEField=T,
 File_Efield(1)='QWR_efielddata.dat',  C_pos(1)=0.11650, Phi(1)=54.4,  Nue(1)=0.2025,   MaxE(1)=1.95,   !1.95 MV/m nominal, phi = 149.42 - 95
 File_Efield(2)='QWR_efielddata.dat',  C_pos(2)=0.65850, Phi(2)=148.7, Nue(2)=0.2025,   MaxE(2)=1.25,   !1.25 MV/m nominal, phi = 240.67 - 92
 File_Efield(3)='QWR_efielddata.dat',  C_pos(3)=1.24650, Phi(3)=-53.9, Nue(3)=0.2025,   MaxE(3)=0.70,   !0.70 MV/m nominal, phi =  36.10 - 90
 File_Efield(4)='QWR_efielddata.dat',  C_pos(4)=1.74850, Phi(4)=-60.9, Nue(4)=0.2025,   MaxE(4)=1.40,   !1.40 MV/m nominal, phi =  31.09 - 92
 File_Efield(5)='3D_7500Vchopmap', C_pos(5)=0.94250, Phi(5)=0.000, Nue(5)=0.0000,   MaxE(5)=0.75,
/

where QWR_efielddata.dat, 3D_7500Vchopmap.ex, 3D_7500Vchopmap.ey and 3D_7500Vchopmap.ez are all files within the current directory.

I get the following error:

Initial particles written to ./tmp10ln8jg6/astra.particles
./tmp10ln8jg6/astra.particles exists, will not symlink
Linked /src/app/QWR_efielddata.dat to ./tmp10ln8jg6/QWR_efielddata.dat
Linked /src/app/QWR_efielddata.dat to ./tmp10ln8jg6/QWR_efielddata.dat
Linked /src/app/QWR_efielddata.dat to ./tmp10ln8jg6/QWR_efielddata.dat
Linked /src/app/QWR_efielddata.dat to ./tmp10ln8jg6/QWR_efielddata.dat
Path does not exist for symlink: 3D_7500Vchopmap
Path does not exist for symlink: RAD
Path does not exist for symlink: RAD
Path does not exist for symlink: RAD
Path does not exist for symlink: RAD
Path does not exist for symlink: RAD
Path does not exist for symlink: Col_X
Path does not exist for symlink: Scr_X
Path does not exist for symlink: Scr_X
Path does not exist for symlink: Scr_X
Path does not exist for symlink: Scr_X
Path does not exist for symlink: Scr_X
Path does not exist for symlink: Scr_X
Path does not exist for symlink: Scr_X
Path does not exist for symlink: Scr_X
Path does not exist for symlink: Scr_X
Path does not exist for symlink: Scr_X
Linked /src/app/geometry.dat to ./tmp10ln8jg6/geometry.dat
Run Aborted Traceback (most recent call last):
  File "/opt/conda/lib/python3.9/site-packages/astra/astra.py", line 353, in run_astra
    self.load_output()
  File "/opt/conda/lib/python3.9/site-packages/astra/astra.py", line 256, in load_output
    assert len(nlist)==1, f'Stat keys do not all have the same length: { [len(stats[k]) for k in stats]}'
AssertionError: Stat keys do not all have the same length: []

{'start_time': 1636027472.44325, 'run_script': '/src/app/Astra ISISMEBT.in', 'why_error': 'Traceback (most recent call last):\n  File "/opt/conda/lib/python3.9/site-packages/astra/astra.py", line 353, in run_astra\n    self.load_output()\n  File "/opt/conda/lib/python3.9/site-packages/astra/astra.py", line 256, in load_output\n    assert len(nlist)==1, f\'Stat keys do not all have the same length: { [len(stats[k]) for k in stats]}\'\nAssertionError: Stat keys do not all have the same length: []\n', 'error': True, 'run_time': 0.84267258644104, 'run_error': True}
run_astra_with_generator finished
ChristopherMayes commented 2 years ago

@kathryn-baker just zip up all of your files and attach them here, by dragging into the text box.

kathryn-baker commented 2 years ago

Here are the files: lume-astra-example.zip Thank you for your help!

ChristopherMayes commented 2 years ago

@kathryn-baker Okay, I made some changes that should be able to handle your 3D fieldmaps.

However, Astra warns: ATTENTION: PROGRAM IS QUITTING EARLY ! and does not produce any output. Could you attach an example that runs with vanilla Astra?

kathryn-baker commented 2 years ago

Thank you! Yes I think there might be something wrong in the configuration that's preventing the program from completing as I had a similar issue with the Astra main program. I'll try to sort it out and can send you the updated example to test when I know it can be run through Astra itself.

kathryn-baker commented 2 years ago

It appears the error was in the cavity input anyway, it can be resolved by setting the last parameter in the CAVITY namelist in the input file to 0: File_Efield(5)='3D_7500Vchopmap', C_pos(5)=0.94250, Phi(5)=0.000, Nue(5)=0.0000, MaxE(5)=0.00,

(previously MaxE(5)=0.75).

I think this might actually remove the overall effect of the 3D field map but I have managed to run a simulation with the updated configuration and produced some output so it looks like your fix worked!

Thanks again for your help and for responding so quickly!