# Running a Parameter Sweep in VSim/Vorpal

One can run a parameter sweep by creating a script (.bat file for Windows or .sh file for Linux/Mac).

After following the instructions in Running Vorpal from the Command Line, you should be able to run on the command line. The argument -iargs can be used to pass a parameter value to your input file for running.

vorpalser -i myFile.pre -iargs FREQUENCY=1.e9


If you are content with running one file at a time (eg for relatively quick simulations, or where all simulations scale perfectly onto all the cores you have available), the quickest way to scan through a set of frequencies, for instance, might be to write a script (.bat or .sh) to loop over the values.

## Linux/Mac

A basic example to loop through a number of wavelengths (2-10 by steps of 1) in the emPlaneWave example is as follows:

for number in seq 2 1 10 ; do
vorpalser -i emPlaneWaveT.pre -iargs WAVELENGTHS=$number -o emPlaneWaveT_${number} \
> emPlaneWaveT_\${number}.log
done


## Windows

A basic example to loop through a number of wavelengths (2-10 by steps of 1) in the emPlaneWave example is as follows:

FOR /L %n IN (2,1,10) DO vorpalser.exe -i emPlaneWaveT.pre -iargs WAVELENGTHS=%n \
-o emPlaneWaveT_%n > emPlaneWaveT_%n.log


In a batch file, use %%n in the above command.

Additionally you may want to use VSimComposer for visualisation after the simulation is complete, which requires you to have the .pre file in the run directory, and one directory per simulation. The script below was written for a cygwin machine with four cores. One core was kept clear so that the machine did not slow too much. The wc ... | cut -f2 -d" " approach will not work for larger core counts as the format of wc will change if there are more characters. The awk command is pretty standard and would be better. This is principally to provide inspiration if you wish to do something more complex. If you have comments and suggestions please email technical support.