This code comprises six different programs for working with LORASR:
runLORASR:
Run LORASR for a given input file.plotLORASR:
Copy data from LORASR output files to Excel plotting spreadsheet.collateLORASR:
Collect the transmission data from LORASR output files to a results file.tidyLORASR:
Tidy up files from a batch run of LORASR.sweepLORASR:
Sweep through sets of parameters and create individual input files for each set of values.batchLORASR:
Work through a batch of input files and Run LORASR for each one.
The programs can be run separately, or, for a batch run,
the program batchLORASR
will work through all the required
tasks for the simulation for all input files in the batch,
including the parameter sweep, running the simulation, plotting
and collating the results, and tidying up the generated files.
- Copy all the following files to a single folder:
runLORASR.exe
plotLORASR.exe
tidyLORASR.exe
- The master plot spreadsheet
Plots.xlsx
- The original LORASR program
LORASR.exe
- Your input file(s)
- Double-click
runLORASR
to start the process - Enter the name of the input file
- LORASR will run automatically
- Double-click
plotLORASR
to generate the plot spreadsheet - Repeat steps 2-5 for each input file
- Double-click
tidyLORASR
to clean up the output files
- Copy all the following files to a single folder:
batchLORASR.exe
- The master plot spreadsheet
Plots.xlsx
- The original LORASR program
LORASR.exe
- Your input files, named
*.in
- Double-click
batchLORASR
to automatically run the whole process for all input files
- Copy all the following files to a single folder:
batchLORASR.exe
- The master plot spreadsheet
Plots.xlsx
- The parameter sweep definition spreadsheet
Sweep.xls
- The original LORASR program
LORASR.exe
- Your input file
- Modify
Sweep.xls
to contain the parameters you want to sweep and the values to sweep through - Rename your input file as
Template.txt
- Modify the template file so that each parameter that should be swept
is listed as a variable instead of a value,
e.g.
POL.=1, DRIFTL.= 3.0, POLEL.= PARAM1, FIELDST.= PARAM2
- Double-click
batchLORASR
to automatically run the whole process for all swept values of all parameters
The executable programs:
runLORASR.exe
plotLORASR.exe
collateLORASR.exe
tidyLORASR.exe
sweepLORASR.exe
batchLORASR.exe
The settings file:
runLORASR.ini
Template files:
Plots.xlxs
Sweep.xlsx
Template.txt
Documentation:
- This Readme file
- Code documentation
Each of the programs can be run by double-clicking in Windows or from the command line by typing the program name. The programs can either be installed in the same folder as the LORASR program itself, or they can be run in any folder without requiring installation.
The settings used by the code are stored in the runLORASR.ini
settings file.
Most of these settings can be left as the default, and in fact, if the
settings file is not present, the default settings are loaded automatically.
The programs must be able to find the LORASR program (i.e. LORASR.exe
)
itself. There are two ways to do this: either copy LORASR.exe
to the same
folder that the runLORASR
programs are in, or modify runLORASR.ini
to
tell the code where the LORASR executable is installed.
To use the plotting function, you must have Microsoft Excel installed, and
the master plot file Plots.xlsx
should either be in the working folder for
the simulation, or in the same folder where the LORASR program is installed.
Work through a batch of input files and call RunLORASR
for each one.
It can use given input files or automatically build input files based on a parameter sweep definition file and a template input file. It produces a set of plots for each run, and saves batch results to a combined file for comparison.
This is the main program that users will interact with. The individual steps
can be run manually by running the other programs, but batchLORASR
runs all
of these steps automatically.
Double-clicking the program or running batchLORASR
from the command line will
run through the whole batch without requiring further input from the user.
All the program requires are the input file(s) and the location of the LORASR
executable. Either copy LORASR.exe
to the working folder, or modify the
runLORASR.ini
settings file with the correct installation location.
To set up a parametric sweep, see the usage notes for sweepLORASR
below.
Note that if the sweep files are present as well as input files, the program
will assume that you want to do a parametric sweep, and will ignore the other
input files. If you just want to use input files, move the Sweep.xlsx
file
out of the working folder.
If you want to generate output plot spreadsheets or each run, you must have
Microsoft Excel installed, and the master plot file Plots.xlsx
should
either be in the working folder for the simulation, or in the same folder
where the LORASR program is installed.
- Get working directory
- Copy input files to working directory if required
- Run sweep module to automatically produce input files if parameter sweep definition file is present
- Create a batch results output file to store the summarised results
- Get list of input files in working directory
- Run for each input file sequentially:
- Run LORASR
- Create plots spreadsheet for this run
- Write results to combined batch results file
- Tidy up input and output files for this run
- Next input file
- Tidy up batch files
Run LORASR for a given filename.
It handles the running of the LORASR file, using keyboard shortcuts and window controls to tell the program what to do. Intended to be used as part of a batch, but can run on its own, either from the command line with the input file as a parameter, or interactively where the user enters the input filename.
Double-clicking the program or running runLORASR
from the command line will
prompt the user to enter the input file name. The input file name can also be
given to the program as a command line parameter, e.g.
runLORASR dtl.in
All the program requires is the input file and the location of the LORASR
executable. Either copy LORASR.exe
to the working folder, or modify the
runLORASR.ini
settings file with the correct installation location.
- Get input file name
- Check input and program files exist
- Start the LORASR software
- Open the input file
- Run the calculation
- Wait for the calculation window to be complete
- Quit the program
Reads in the output data produced by LORASR in various text files and creates a results spreadsheet, based on a template with plots already defined. Produces all the same standard plots produced by LORASR.
This program can be run by itself in a folder where LORASR has been run manually, or can be called for each run of a batch process.
Note that running LORASR overwrites the output files, so in a batch run PlotLORASR must be called before starting the next run in the batch.
After running LORASR manually, or using the runLORASR.exe
program to run
LORASR automatically, there will be a number of output files in the working
directory, such as bucent
and transenv
.
Double-clicking the program or running plotLORASR
from the command line will
load all the data from these output files into a spreadsheet file.
You must have Microsoft Excel installed, and the master plot file Plots.xlsx
should either be in the working folder for the simulation, or in the same folder
where the LORASR program is installed.
- Find master spreadsheet
- Create plot spreadsheet from master
- Open Excel
- Open the spreadsheet
- For each type of data:
- Load data from file to array
- Write data to correct place in spreadsheet
- Next data type
- Save the spreadsheet
- Close Excel
Data type for step 5 are:
- Transverse envelope data
- Longitudinal envelope data
- Input x-emittance data
- Output x-emittance data
- Input y-emittance data
- Output y-emittance data
- Input z-emittance data
- Output z-emittance data
- Bunch centre data
- Emittance growth data
- Phase advance data
- Emittance values
Sweep through sets of parameters and create individual input files for each set of values.
By defining which parameters should be swept, what values should be used
for each sweep, and where these parameters fit into the overall simulation,
this code allows an arbitrary number of simulations to be run with various
different values of various parameters.
The parameters and their values are specified in a spreadsheet, which also
estimates the batch run time for the sweep.
The simulation is specified in a template file, where placeholders for the
parameters to be varied are automatically replaced by the code to create
a set of multiple input files from this template, one input file for each
combination of parameter values.
The resulting input files can be simulated manually, or automatically
using batchLORASR.exe
Double-clicking the program or running sweepLORASR
from the command line will
load all the parametric sweep definitions and create all the individual input
files for each combination of parameter values.
Normally sweepLORASR
wouldn't be run by itself, but rather run as part of a
batch. To process the batch, set up the template and parameter sweep spreadsheet
as below, then double-click batchLORASR.exe
or type batchLORASR
at the
command prompt.
The simulation must be specified in a template file. This is an input file
where the parameters you want to change have been replaced by variable names
such as PARAM1
, PARAM2
etc.
For example, to sweep through a number of possible values for the field length and field gradient of a quadrupole, you might modify one line in the input file from
POL.=1, DRIFTL.= 3.0, POLEL.= 7.3, FIELDST.= 5040
to
POL.=1, DRIFTL.= 3.0, POLEL.= PARAM1, FIELDST.= PARAM2
The default name for the template file is Template.txt
. This can be changed
in the runLORASR.ini
settings file.
Once the template file is ready, the parameters to sweep and the values to use
must be specified in a parameter sweep definition spreadsheet. The default name
for the definition file is Sweep.xlsx
, which can also be changed in the
runLORASR.ini
settings file.
In the first sheet in the spreadsheet, put in the name and units for each parameter that you want to sweep through. The number of parameters and number of values for each parameter will be calculated automatically, so these don't need to be manually entered.
In the second sheet, there will be a column for each parameter that you entered on the first sheet. Fill in the values to be simulated for each parameter.
- Get working directory
- Clear up existing input files in working directory
- Copy parameter sweep files to working directory if required
- Check whether parameter sweep files exists
- Get parameter details from sweep definition file
- Open Excel
- Open the spreadsheet
- Read in number of parameters
- Read in definition of each parameter from first sheet
- Read in parameter values from second sheet
- Close Excel
- Copy the template to one input file for each of the values of the
first parameter:
- Build filename
- Copy files
- Replace the dummy code for this first parameter with the value of the parameter
- Next value of first parameter
- For each successive parameter, copy all existing input files once for
each value of that parameter:
- Find existing files
- For each value of the current parameter:
- For each existing input file:
- Build new filename for this input file and this set of parameter values
- Copy to new input file
- Replace the dummy code for this current parameter with the value of the parameter
- Next file
- Next value of current parameter
- For each existing input file:
- Delete previous base files (as we are now a level deeper)
- Next parameter
- Prepare batch results file with headings based on parameter sweep definition
Collate transmission and beam core results from a batch run of LORASR into a batch results file.
This is normally handled automatically by batchLORASR
, but there may be cases
where a long batch was interrupted and the batch results are missing.
collateLORASR
works through a set of input and output files, and collates
all the results together.
The working folder should contain the various input files *.in
and
corresponding run files *.out
, either all together in one folder or with
separate input and run subfolders. The default names for the these subfolders
are Input\
and Runs\
, although these can be changed in the runLORASR.ini
settings file.
Double-clicking the program or running collateLORASR
from the command line
will sort through these files and produce a batch results output file. The
default name for the output file is Batch results.csv
, which can also be
changed in the runLORASR.ini
settings file.
- Get a list of all output files in the current folder or the Runs subfolder
- Create a blank output file
- For each unique run:
- Find the input file
*.in
- Find the latest run file
*.out
- Load the starting number of macroparticles from the input file
- Load the final number of macroparticles from the output file
- Calculate the transmission
- Load the final proportion of particles in core from the output file
- Save these results to the output file
- Find the input file
Tidy up files from a batch run of LORASR.
As batch files can produce a lot of input files, output files, results files, log files, and temporary data files, without some kind of handling of these files it is hard to find the information required. Also, leaving behind various output files can make re-running a batch more complicated. This program puts input files in an input folder, output files in an output folder, run data files in a run folder and also deletes old files that are no longer needed. If a run was unsuccessful, all related files are stored in a separate folder for incomplete runs, so they can be easily rerun by the user. Subfolders are created if they don't exist already.
Files that pertain to the whole batch are left in the parent folder: the parameter sweep definition spreadsheet and template input file (if using a parameter sweep), the overall log file, and the batch results summary file.
This part of a batch can be bypassed (i.e. don't tidy any files, keep them
where they are) by setting the option Cleanup
to FALSE
in the
runLORASR.ini
settings file.
Double-clicking the program or running tidyLORASR
from the command line will
move files into their correct subfolders and delete extraneous temporary files.
The subfolder names can be specified in the runLORASR.ini
settings file.
- For each run
(either called by the batch program or loop through all output files):
- Determine whether the run was successful or not
- Move the files for that run to the correct place:
- All files for unsuccessful runs go to the subfolder
defined by the
IncompleteFolder
setting - Input files for successful runs go to the subfolder
defined by the
InputFolder
setting - Run files for successful runs go to the subfolder
defined by the
RunFolder
setting - Output files for successful runs go to the subfolder
defined by the
OutputFolder
setting
- All files for unsuccessful runs go to the subfolder
defined by the
- Also tidy up batch-related files:
- Any files missed by the run-by-run tidying are tidied as above
- Master plot file goes to the subfolder defined by
$sInputFolder
- Data output files produced directly by LORASR are deleted, as they are no longer required
- LORASR executable file is deleted from the working directory (this shouldn't be the master version)
- Any files marked as "old" are also deleted
[Files and folders]
ProgramPath="C:\Program Files (x86)\LORASR"
SimulationProgram="LORASR.exe"
SweepFile="Sweep.xlsx"
TemplateFile="Template.txt"
ResultsFile="Batch results.csv"
PlotFile="Plots.xlsx"
LogFile="runLORASR.log"
InputFolder="Input"
OutputFolder="Output"
RunFolder="Runs"
IncompleteFolder="Incomplete"
[Options]
Cleanup=True
ConsoleVerbosity=5
LogFileVerbosity=3
MessageVerbosity=1
- Author: Matt Easton [email protected]
- Last modified: 2017-09-15
- Relates to runLORASR code version: v0.4