2D simulations

Asked by Robert Sarracino

I plan to start a number of 2D simulations. Is there a tutorial or document which outlines how to do this?

Initially I have to create a number of mesh walls (mesh lines) -- what are the commands for that?

Question information

Language:
English Edit question
Status:
Answered
For:
ESyS-Particle Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Dion Weatherley (d-weatherley) said :
#1

Hi Robert,

There are no features in ESyS-Particle itself that assist with executing multiple simulations (e.g. for a parameter sweep). Consequently we haven't written any documentation on how to do this. Having said that, a number of users will be interested in some possible solutions. I'll describe how I resolved this problem.

1) I create a text file that lists all the important model parameters. It has the following format:
minRadius real 0.3
maxRadius real 1.0
numTimeSteps integer 1
geofile text sample.geo
....
#Sweep Parameters:
minRadius 0.2 0.1 5 add

2) I then wrote a python class called SimParameters that reads files of this format and stores the parameter values in a python dictionary called params. The parameter name is the key used in the dictionary. The parameter type (real/integer/text) is used whilst reading the file to cast the value into the correct type when storing it in the dictionary.

3) Import the SimParameters class into your simulation python script and supply it with a parameter filename via a commandline argument when running ESyS-Particle. Then with your script, you can access the parameter values like this:
Rmin = simparams.params['minRadius']

I find this to be a handy way to keep track of model parameters and make it easy to change them whilst testing your simulations.

4) Now to running a parameter sweep:
4A) I wrote a second python script called SetupParameterSweep.py. This one reads a supplied parameter file and stores the read parameter values in a SimParameters object. It then reads the last line of the parameter file (after the '#Sweep Parameters:' line).
4B) This last line instructs my script to vary the value of 'minRadius' starting with a value of 0.2, incrementing by 0.1 for a total of 5 values (i.e. minRadius will take values {0.2,0.3,0.4,0.5,0.6}. The word 'add' at the end specifies how to increment the value (I also have a 'multiply' option for sweeping over a very large range of values)
4C) The SetupParameterSweep script then enters a for loop and, for each value of the sweep parameter it does the following:
* create a subdirectory called parameter_i (e.g. minRadius_0, minRadius_1, ... , minRadius_4)
* write out a parameter file in that subdirectory after setting the value of minRadius to the desired value. One can augment the SimParameters class with a write(..) subroutine to do this part
4D) Finally, after creating a series of subdirectories and populating these with parameter files, my script writes a little shell script called runSweep.sh which looks something like this:
for (( i = 0 ; i < 5 ; i++ ))
do
   cd minRadius_$i
   mpirun -np 2 esysparticle ../simulation.py ./paramfile.txt
   cd ..
done

5) Now all the simulations can be run one-after-another simply by typing the following at the terminal command prompt:
sh runSweep.sh

There are of course a number of other ways to achieve the same result, many of which are far simpler to code. The advantage of this approach is that I can re-use my SimParameters class and SetupParameterSweep.py script for any/all the different simulation models I write, regardless of the actual model parameters and those that I wish to sweep over.

> Initially I have to create a number of mesh walls (mesh lines) -- what are the commands for that?

You will need to write your own script to generate the mesh wall files. It could be easily appended to step 4C described above.

I hope this helps and have fun!

Cheers,

Dion

Can you help with this problem?

Provide an answer of your own, or ask Robert Sarracino for more information if necessary.

To post a message you must log in.