Optimization of field at cathode with python wrapper and SPIFFE.
The two ANL codes used in this project are SPIFFE and SDDS Tools. SPIFFE is a 2.5-D particle in cell electromagnetic field solver. It can handle a wide range of problems and does a decent job of capturing particle dynamics. The interface is straightforward and it is moderately well documented. SPIFFE is ideal (in my opinion) for problems that cannot be solved analytically and are not yet mature enough for 3-D calculations. SDDS tools is an analysis package produced by Argonne to process and analyze data in the SDDS format.
The download for SPIFFE can be found here (https://www1.aps.anl.gov/accelerator-operations-physics/software) along with the other APS codes. To install SPIFFE download the .tar file, unzip, and then copy into your /opt/x11/bin folder.
The manual for SPIFFE can be found here (http://www.aps.anl.gov/Accelerator_Systems_Division/Accelerator_Operations_Physics/manuals/spiffe_V4.5/spiffe.html). The documentation is mostly there, however there have been a few areas where it is a little sparse. Most notably, in order to run an electrostatics problem you need to include the Poisson correction.
Because SPIFFE uses the SDDS format for output and input, some functions use functions in SDDS tools. I have written a function to bring data from SDDS into python that uses the sdds2stream function. This works well when wanting to do analysis in python.
You will need SDDS tools to run the optimizer and anything that calls the SDDSread function or some of the SPIFFE functions in the wrapper. The sdds toolkit can be downloaded here (https://www1.aps.anl.gov/accelerator-operations-physics/software). If you are using a mac you will need a version of x-quartz. To install sddstools download the binary files, unzip them, and copy them into your /opt/x11/bin folder.
The documentation for sddstools can be found here (http://www.aps.anl.gov/Accelerator_Systems_Division/Accelerator_Operations_Physics/manuals/SDDStoolkit/SDDStoolkit.html).
The python wrapper for SPIFFE builds a simulation file based on python commands. It is complete and has all the different elements included. Each function in the wrapper writes a string to the simulation file based on the format specified in the SPIFFE documentation. The python module is called "spiffe.py", a paper documenting the wrapper is included in the documents page (https://cdcvs.fnal.gov/redmine/attachments/download/43722/Python_Wrapper_Spiffe.pdf). The wrapper also includes a function to read SDDS files into a numpy array.
Electrostatic simulations (SPIFFE)¶
The geometry creation takes place in the geometry.py module. Here a points table for the McMillin shaped cathode is defined and written to a file that can be imported into SPIFFE. The module has a couple of general functions such as the creation of bends, but for the most part it is custom for that particular cathode geometry. There are two different geometries that can be created using this module, the simple geometry and the more complex geometry. Both the geometries are described in Figures 1 and 2 of the paper that describes the work done thus far (https://cdcvs.fnal.gov/redmine/attachments/download/43730/Field_Optimization_of_a_McMIllan_Electron_Gun.pdf)
The simulation setup file is where most of the effort to build an individual simulation goes. This begins with the geometry creation which is handled in geometry.py, then the rest of the simulation is constructed. Mostly this involves working with the SPIFFE manual to figure out which computations need to be done. For the electrostatic simulations we import the geometry, define the mesh intervals, enable solving of Poisson's Equation, turn on field saving and run the simulation.
The optimization is handled using shell.py, here the the simulation is called which has a flag for choosing between the two geometries. Then the post-processing is done on the simulation run to calculate the cost function for that particular run.