Installation and running <b>gadget</b>-2 «astrobites».

Error in deserializing body of reply message for operation 'Translate'. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 8872.
Error in deserializing body of reply message for operation 'Translate'. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 8664.

Today’s astrobite will be another in a series on career advice and useful astronomical tools.  So far, it looks like there’s been a dearth of posts on the tools of theoretical astrophysics, so I thought I’d take the opporunity to show how easy it is to run a simulation using Gadget-2, a smoothed particle hydrodynamics (or SPH) code.  Gadget-2 is open source and publically available, so anyone can run simulations with it.  In a future post, I’ll discuss how to set up and run a simple hydrodynamics test problem.

The instructions for installing Gadget-2 will be highly platform dependent.  If you’re running Linux or UNIX, you have all of the tools you will need to compile the codes already. If you’re on a Mac, you’ll need to install and update Xcode, which includes all of the compilers you will need.  On Windows, you’ll probably need to install cygwin which will give your Windows installation full UNIX support.

A simulation of cosmic structure formation run with Gadget-2 (Springel et al. 2005).

Since I have a Mac, I’m going to focus on getting these codes working on OS X Snow Leopard.  If you have a different system, it might not be possible to follow my instructions exactly.  I’ll be doing all of the simulations for this series of posts on my laptop, a Macbook Pro.

First, you will need to download a few software packages.

Gadget 2.0.7.Version 1.9 of the GNU scientific library (GSL).Version 2.1.5 of the FFTW fast Fourier transform library.A Message Passing Interface (MPI) library such as Open-MPI or MPICH

Open-MPI is included with OS X so if you have a Mac, do not install an MPI library. Don’t download version 3.x of the FFTW library since it doesn’t include multiprocessor support.

Once you have all of the software downloaded, you will need to extract the .tar.gz archives and install the software. I’m doing everything in terminal (found in your applications folder under Terminal.app). The installation process goes as follows:

1. Extract the software:

goldbaum@~/Documents/code: tar -xzf fftw-2.1.5.tar.gzgoldbaum@~/Documents/code: tar -xzf gadget-2.0.7.tar.gzgoldbaum@~/Documents/code: tar -xzf gsl-1.9.tar.gz

2. Install GSL:

goldbaum@~/Documents/code: cd gsl-1.9/goldbaum@~/Documents/code/gsl-1.9: ./configuresnip: lots of diagnostic ouputgoldbaum@~/Documents/code/gsl-1.9: makesnip: lots of compilation outputgoldbaum@~/Documents/code/gsl-1.9: sudo make installPassword:snip: lots of diagnostic outputgoldbaum@~/Documents/code/gsl-1.9: cd ..

I’ve gone with the default option of installing GSL to root system directories.  If you don’t have administrator privileges, you can install the software to your user directory by adding “–prefix=/folder/to/install/to” to the configure line. Leave out the quotes and change to your choice of folders when you do this for real.

3. Install FFTW:

goldbaum@~/Documents/code: cd fftw-2.1.5goldbaum@~/Documents/code/fftw-2.1.5: ./configure --enable-mpi --enable-type-prefix --enable-floatsnip: lots of diagnostic outputgoldbaum@~/Documents/code/gsl-1.9: makesnip: lots of compilation outputgoldbaum@~/Documents/code/gsl-1.9: sudo make installPassword:snip: lots of diagnostic outputgoldbaum@~/Documents/code/gsl-1.9: cd ..

4. Edit the Gadget makefile for your system

Gadget has a ton of compile-time parameters, which are extensively described in the User’s Guide. There are several changes to the default makefile that you need to make in order for Gadget to run correctly. Go to the directory you extracted Gadget to, then the Gadget-2 directory inside that folder. Open the makefile in a text editor (e.g. vim, emacs, textedit, notepad), and edit the compile time parameters so the beginning of your makefile looks like the following:

#--------------------------------------- Basic operation mode of code#OPT += -DPERIODICOPT += -DUNEQUALSOFTENINGS#--------------------------------------- Things that are always recommendedOPT += -DPEANOHILBERTOPT += -DWALLCLOCK#--------------------------------------- TreePM Options#OPT += -DPMGRID=128#OPT += -DPLACEHIGHRESREGION=3#OPT += -DENLARGEREGION=1.2#OPT += -DASMTH=1.25#OPT += -DRCUT=4.5#--------------------------------------- Single/Double Precision#OPT += -DDOUBLEPRECISION#OPT += -DDOUBLEPRECISION_FFTW#--------------------------------------- Time integration optionsOPT += -DSYNCHRONIZATION#OPT += -DFLEXSTEPS#OPT += -DPSEUDOSYMMETRIC#OPT += -DNOSTOP_WHEN_BELOW_MINTIMESTEP#OPT += -DNOPMSTEPADJUSTMENT#--------------------------------------- Output#OPT += -DHAVE_HDF5#OPT += -DOUTPUTPOTENTIAL#OPT += -DOUTPUTACCELERATION#OPT += -DOUTPUTCHANGEOFENTROPY#OPT += -DOUTPUTTIMESTEP#--------------------------------------- Things for special behaviour#OPT += -DNOGRAVITY#OPT += -DNOTREERND#OPT += -DNOTYPEPREFIX_FFTW#OPT += -DLONG_X=60#OPT += -DLONG_Y=5#OPT += -DLONG_Z=0.2#OPT += -DTWODIMS#OPT += -DSPH_BND_PARTICLES#OPT += -DNOVISCOSITYLIMITER#OPT += -DCOMPUTE_POTENTIAL_ENERGY#OPT += -DLONGIDS#OPT += -DISOTHERM_EQS#OPT += -DADAPTIVE_GRAVSOFT_FORGAS#OPT += -DSELECTIVE_NO_GRAVITY=2+4+8+16#--------------------------------------- Testing and Debugging options#OPT += -DFORCETEST=0.1#--------------------------------------- Glass making#OPT += -DMAKEGLASS=262144

The most important change is commenting out the HAVE_HDF5 line to avoid a compilation error.

Next, you’ll need to edit the makefile once more to tell it where you’ve installed GSL and FFTW. My makefile looks like this:

#----------------------------------------------------------------------# Here, select compile environment for the target machine. This may need# adjustment, depending on your local system. Follow the examples to add# additional target platforms, and to get things properly compiled.#----------------------------------------------------------------------#--------------------------------------- Select some defaultsCC = mpicc # sets the C-compilerOPTIMIZE = -O2 -Wall -g # sets optimization and warning flagsMPICHLIB = -lmpich#--------------------------------------- Select target computerSYSTYPE="Goldbaum"#--------------------------------------- Adjust settings for target computerifeq ($(SYSTYPE),"Goldbaum")CC = mpiccOPTIMIZE = -03 -WallGSL_INCL = -I/usr/local/includeGSL_LIBS = -L/usr/local/libFFTW_INCL= -I/usr/local/includeFFTW_LIBS= -L/usr/local/libMPICHLIB = -L/usr/libendif

You can define your own SYSTYPE and tell Gadget where you’ve installed GSL and FFTW. By default, they’re in /usr/local/. The MPI library that comes with OS X is in /usr/lib/.

Now you’re almost done! Just save the changes you’ve made, exit out of your editor and run “make” in the Gadget-2 code directory. That should produce an executable called Gadget2 that you can run simulations with.

There are a number of test cases that come with Gadget.  You might try running the galaxy collision test since it makes some nice looking outputs that can be readily visualized using IDL routines included with Gadget.  To run the galaxy collision test, first set up a folder with all of the needed executables and parameter files:

goldbaum@~/Documents/code/Gadget-2.0.7: mkdir galaxygoldbaum@~/Documents/code/Gadget-2.0.7: cp Gadget2/Gadget2 galaxy/goldbaum@~/Documents/code/Gadget-2.0.7: cp Gadget2/parameterfiles/galaxy.param galaxy/goldbaum@~/Documents/code/Gadget-2.0.7: cd galaxy/

Then edit galaxy.param so that the first two lines look like:

% Relevant filesInitCondFile /path/to/Gadget-2.0.7/ICs/galaxy_littleendian.datOutputDir /path/to/Gadget-2.0.7/galaxy/

You should change the path to the initial conditions directory and the output directory to reflect the directory structure on your computer. You’re now ready to run your first simulation! Invoke Gadget with the following command:

mpirun -np 2 ./Gadget2 galaxy.param

The command mpirun initializes an MPI program, in this case Gadget. The paramater -np 2 tells mpirun to run Gadget with two processors.  Gadget in turn looks in galaxy.param for parameters of the simulation. If you have more than two processors, feel free to change the 2 in “-np 2? to the number of processors on your system. You can check how many processors you have by running System Profiler.app which is included with OS X. You might want to try playing with increasing the number of outputs to make a simple movie of the galaxy collision:

Next time, we’ll setup and run a simple hydrodynamics test. Stay tuned!

0 komentar:

Posting Komentar