This post will serve as a guide to installing and running the simulation code GADGET 2 and the initial conditions generation code N-GenIC, moving on to using Gadgetreader for visualising snapshot files.

GADGET 2 is a parallel smoothed particle hydrodynamics code written by Volker Springel as a PhD student at the Max Planck Institute for Astrophysics at Garching. It uses a combination of a Tree algorithm for looking range forces and Particle-Mesh methods for short range forces.

It outputs snapshots at specified redshifts that are stored as binary files that store the positions and velocities of dark matter particles.

The first part of this post will deal with installing dependencies for running the initial conditions and simulation codes.

Dependencies for GADGET and N-GenIC

This is assuming you have standard C and FORTRAN compilers running on your Ubuntu system.

1. GNU Scientific Library (GSL), which includes required mathematical functions. Download the latest tarball, extract it, and then inside the GSL folder, type:

> ./configure

> make

> make install

2. MPICH, for parallel running of the GADGET 2 / N-GenIC code. Download, extract and follow the same procedure:

> ./configure

> make

> make install

3. Fastest Fourier Transform in the West (FFTW), for performing FFT on the simulation grid for the computation of force from potential. Installing this involves some options while configuring. Download fftw-2.1.5 (not 3) and extract it. In the folder, type:

> ./configure –enable-mpi –enable-type-prefix –enable-float

> make

> make install

This installs the FFTW library in single precision (–enable-float), enables MPI, and attaches a prefix to differentiate single and double precision files. Here, for the N-GenIC code, we need double precision files as well, so:

> make clean

> ./configure –enable-mpi –enable-type-prefix

> make

> make install

This installs these libraries in default locations on your system.

Making and Installing GADGET 2



Download GADGET 2 from the following link: http://wwwmpa.mpa-garching.mpg.de/gadget/gadget-2.0.7.tar.gz

Now, in the folder containing the tarball, type:

> tar -xzf gadget-2.0.7.tar.gz

> cd Gadget-2.0.7/Gadget2

This takes you inside the GADGET directory proper. Here we have the Makefile which needs to be modified.

Go into the folder parameterfiles from Gadget2:

> cd parameterfiles

This will contain the file lcdm_gas.Makefile. Copy this into the Gadget2 folder.



A typical N-body simulation makefile looks like this:

#---------------------------------------------------------------------- # From the list below, please activate/deactivate the options that # apply to your run. If you modify any of these options, make sure # that you recompile the whole code by typing "make clean; make". # # Look at end of file for a brief guide to the compile-time options. #---------------------------------------------------------------------- #--------------------------------------- Basic operation mode of code OPT += -DPERIODIC #OPT += -DUNEQUALSOFTENINGS #--------------------------------------- Things that are always recommended OPT += -DPEANOHILBERT OPT += -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 options OPT += -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 #---------------------------------------------------------------------- # 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 defaults CC = mpicc # sets the C-compiler OPTIMIZE = -O2 -Wall -g # sets optimization and warning flags MPICHLIB = #-lmpich #--------------------------------------- Select target computer SYSTYPE = "Dianas-MacBook" #SYSTYPE="MPA" #SYSTYPE="Mako" #SYSTYPE="Regatta" #SYSTYPE="RZG_LinuxCluster" #SYSTYPE="RZG_LinuxCluster-gcc" #SYSTYPE="OpteronMPA" #SYSTYPE="OPA-Cluster32" #SYSTYPE="OPA-Cluster64" #--------------------------------------- Adjust settings for target computer ifeq ($(SYSTYPE),"Dianas-MacBook") CC = mpicc OPTIMIZE = -O3 -Wall GSL_INCL = -I/usr/local/include GSL_LIBS = -L/usr/local/lib FFTW_INCL= -I/usr/local/include FFTW_LIBS= -L/usr/local/lib MPICHLIB = -L/usr/local/lib #HDF5INCL = /src/hdf5-1.8.4/hdf5/include #HDF5LIB = /src/hdf5-1.8.4/hdf5/lib #HDF5LIB = -lhdf5 -lz endif ifeq ($(SYSTYPE),"OpteronMPA") CC = mpicc OPTIMIZE = -O3 -Wall -m64 GSL_INCL = -L/usr/local/include GSL_LIBS = -L/usr/local/lib FFTW_INCL= FFTW_LIBS= MPICHLIB = HDF5INCL = -I/opt/hdf5/include HDF5LIB = -L/opt/hdf5/lib -lhdf5 -lz -Wl,"-R /opt/hdf5/lib" endif ifeq ($(SYSTYPE),"OPA-Cluster32") CC = mpicc OPTIMIZE = -O3 -Wall GSL_INCL = -I/afs/rzg/bc-b/vrs/opteron32/include GSL_LIBS = -L/afs/rzg/bc-b/vrs/opteron32/lib -Wl,"-R /afs/rzg/bc-b/vrs/opteron32/lib" FFTW_INCL= -I/afs/rzg/bc-b/vrs/opteron32/include FFTW_LIBS= -L/afs/rzg/bc-b/vrs/opteron32/lib MPICHLIB = HDF5INCL = HDF5LIB = -lhdf5 -lz endif ifeq ($(SYSTYPE),"OPA-Cluster64") CC = mpicc OPTIMIZE = -O3 -Wall -m64 GSL_INCL = -I/afs/rzg/bc-b/vrs/opteron64/include GSL_LIBS = -L/afs/rzg/bc-b/vrs/opteron64/lib -Wl,"-R /afs/rzg/bc-b/vrs/opteron64/lib" FFTW_INCL= -I/afs/rzg/bc-b/vrs/opteron64/include FFTW_LIBS= -L/afs/rzg/bc-b/vrs/opteron64/lib MPICHLIB = HDF5INCL = HDF5LIB = -lhdf5 -lz endif ifeq ($(SYSTYPE),"Mako") CC = mpicc # sets the C-compiler OPTIMIZE = -O3 -march=athlon-mp -mfpmath=sse GSL_INCL = GSL_LIBS = FFTW_INCL= FFTW_LIBS= MPICHLIB = HDF5INCL = HDF5LIB = -lhdf5 -lz endif ifeq ($(SYSTYPE),"Regatta") CC = mpcc_r OPTIMIZE = -O5 -qstrict -qipa -q64 GSL_INCL = -I/afs/rzg/u/vrs/gsl_psi64/include GSL_LIBS = -L/afs/rzg/u/vrs/gsl_psi64/lib FFTW_INCL= -I/afs/rzg/u/vrs/fftw_psi64/include FFTW_LIBS= -L/afs/rzg/u/vrs/fftw_psi64/lib -q64 -qipa MPICHLIB = HDF5INCL = -I/afs/rzg/u/vrs/hdf5_psi64/include HDF5LIB = -L/afs/rzg/u/vrs/hdf5_psi64/lib -lhdf5 -lz endif ifeq ($(SYSTYPE),"RZG_LinuxCluster") CC = mpicci OPTIMIZE = -O3 -ip # Note: Don't use the "-rcd" optimization of Intel's compiler! (causes code crashes) GSL_INCL = -I/afs/rzg/u/vrs/gsl_linux/include GSL_LIBS = -L/afs/rzg/u/vrs/gsl_linux/lib -Wl,"-R /afs/rzg/u/vrs/gsl_linux/lib" FFTW_INCL= -I/afs/rzg/u/vrs/fftw_linux/include FFTW_LIBS= -L/afs/rzg/u/vrs/fftw_linux/lib HDF5INCL = -I/afs/rzg/u/vrs/hdf5_linux/include HDF5LIB = -L/afs/rzg/u/vrs/hdf5_linux/lib -lhdf5 -lz -Wl,"-R /afs/rzg/u/vrs/hdf5_linux/lib" endif ifeq ($(SYSTYPE),"RZG_LinuxCluster-gcc") CC = mpiccg OPTIMIZE = -Wall -g -O3 -march=pentium4 GSL_INCL = -I/afs/rzg/u/vrs/gsl_linux_gcc3.2/include GSL_LIBS = -L/afs/rzg/u/vrs/gsl_linux_gcc3.2/lib -Wl,"-R /afs/rzg/u/vrs/gsl_linux_gcc3.2/lib" FFTW_INCL= -I/afs/rzg/u/vrs/fftw_linux_gcc3.2/include FFTW_LIBS= -L/afs/rzg/u/vrs/fftw_linux_gcc3.2/lib HDF5INCL = -I/afs/rzg/u/vrs/hdf5_linux/include HDF5LIB = -L/afs/rzg/u/vrs/hdf5_linux/lib -lhdf5 -lz -Wl,"-R /afs/rzg/u/vrs/hdf5_linux/lib" endif ifneq (HAVE_HDF5,$(findstring HAVE_HDF5,$(OPT))) HDF5INCL = HDF5LIB = endif OPTIONS = $(OPTIMIZE) $(OPT) EXEC = Gadget2 OBJS = main.o run.o predict.o begrun.o endrun.o global.o \ timestep.o init.o restart.o io.o \ accel.o read_ic.o ngb.o \ system.o allocate.o density.o \ gravtree.o hydra.o driftfac.o \ domain.o allvars.o potential.o \ forcetree.o peano.o gravtree_forcetest.o \ pm_periodic.o pm_nonperiodic.o longrange.o INCL = allvars.h proto.h tags.h Makefile CFLAGS = $(OPTIONS) $(GSL_INCL)# $(FFTW_INCL) $(HDF5INCL) ifeq (NOTYPEPREFIX_FFTW,$(findstring NOTYPEPREFIX_FFTW,$(OPT))) # fftw installed with type prefix? FFTW_LIB = $(FFTW_LIBS) -lrfftw_mpi -lfftw_mpi -lrfftw -lfftw else ifeq (DOUBLEPRECISION_FFTW,$(findstring DOUBLEPRECISION_FFTW,$(OPT))) FFTW_LIB = $(FFTW_LIBS) -ldrfftw_mpi -ldfftw_mpi -ldrfftw -ldfftw else FFTW_LIB = $(FFTW_LIBS) -lsrfftw_mpi -lsfftw_mpi -lsrfftw -lsfftw endif endif LIBS = -g $(GSL_LIBS) -lgsl -lgslcblas -lm $(EXEC): $(OBJS) $(CC) $(OBJS) $(LIBS) -o $(EXEC) $(OBJS): $(INCL) clean: rm -f $(OBJS) $(EXEC) #----------------------------------------------------------------------- # # Brief guide to compile-time options of the code. More information # can be found in the code documentation. # # - PERIODIC: # Set this if you want to have periodic boundary conditions. # # - UNEQUALSOFTENINGS: # Set this if you use particles with different gravitational # softening lengths. # # - PEANOHILBERT: # This is a tuning option. When set, the code will bring the # particles after each domain decomposition into Peano-Hilbert # order. This improves cache utilization and performance. # # - WALLCLOCK: # If set, a wallclock timer is used by the code to measure internal # time consumption (see cpu-log file). Otherwise, a timer that # measures consumed processor ticks is used. # # - PMGRID: # This enables the TreePM method, i.e. the long-range force is # computed with a PM-algorithm, and the short range force with the # tree. The parameter has to be set to the size of the mesh that # should be used, (e.g. 64, 96, 128, etc). The mesh dimensions need # not necessarily be a power of two. Note: If the simulation is # not in a periodic box, then a FFT method for vacuum boundaries is # employed, using an actual mesh with dimension twice(!) that # specified by PMGRID. # # - PLACEHIGHRESREGION: # If this option is set (will only work together with PMGRID), then # the long range force is computed in two stages: One Fourier-grid # is used to cover the whole simulation volume, allowing the # computation of the longe-range force. A second Fourier mesh is # placed on the region occupied by "high-resolution" particles, # allowing the computation of an intermediate scale force. Finally, # the force on short scales is computed with the tree. This # procedure can be useful for "zoom-simulations", provided the # majority of particles (the high-res particles) are occupying only # a small fraction of the volume. To activate this option, the # parameter needs to be set to an integer bit mask that encodes the # particle types that make up the high-res particles. # For example, if types 0, 1, and 4 form the high-res # particles, set the parameter to PLACEHIGHRESREGION=19, because # 2^0 + 2^1 + 2^4 = 19. The spatial region covered by the high-res # grid is determined automatically from the initial conditions. # Note: If a periodic box is used, the high-res zone may not intersect # the box boundaries. # # - ENLARGEREGION: # The spatial region covered by the high-res zone has a fixed size # during the simulation, which initially is set to the smallest # region that encompasses all high-res particles. Normally, the # simulation will be interrupted if high-res particles leave this # region in the course of the run. However, by setting this # parameter to a value larger than one, the size of the high-res # region can be expanded, providing a buffer region. For example, # setting it to 1.4 will enlarge its side-length by 40% (it remains # centered on the high-res particles). Hence, with this setting, the # high-res region may expand or move by a limited amount. # Note: If SYNCHRONIZATION is activated, the code will be able to # continue even if high-res particles leave the initial high-res # grid. In this case, the code will update the size and position of # the grid that is placed onto the high-resolution region # automatically. To prevent that this potentially happens every # single PM step, one should nevertheless assign a value slightly # larger than 1 to ENLARGEREGION. # # - ASMTH: # This can be used to override the value assumed for the scale that # defines the long-range/short-range force-split in the TreePM # algorithm. The default value is 1.25, in mesh-cells. # # - RCUT: # This can be used to override the maximum radius in which the # short-range tree-force is evaluated (in case the TreePM algorithm # is used). The default value is 4.5, given in mesh-cells. # # - DOUBLEPRECISION: # This makes the code store and compute internal particle data in # double precision. Note that output files are nevertheless written # by converting the particle data to single precision. # # - DDOUBLEPRECISION_FFTW: # If this is set, the code will use the double-precision version of # FTTW, provided the latter has been explicitly installed with a # "d" prefix, and NOTYPEPREFIX_FFTW is not set. Otherwise the # single precision version ("s" prefix) is used. # # - SYNCHRONIZATION: # When this is set, particles are kept in a binary hierarchy of # timesteps and may only increase their timestep if the new # timestep will put them into synchronization with the higher time # level. # # - FLEXSTEPS: # This is an alternative to SYNCHRONIZATION. Particle timesteps are # here allowed to be integer multiples of the minimum timestep that # occurs among the particles, which in turn is rounded down to the # nearest power-of-two devision of the total simulated # timespan. This option distributes particles more evenly over # individual system timesteps, particularly once a simulation has # run for a while, and may then result in a reduction of work-load # imbalance losses. # # - PSEUDOSYMMETRIC: # When this option is set, the code will try to "anticipate" # timestep changes by extrapolating the change of the acceleration # into the future. This can in certain idealized cases improve the # long-term integration behaviour of periodic orbits, but should # make little or no difference in most real-world applications. May # only be used together with SYNCHRONIZATION. # # - NOSTOP_WHEN_BELOW_MINTIMESTEP: # If this is activated, the code will not terminate when the # timestep falls below the value of MinSizeTimestep specified in # the parameterfile. This is useful for runs where one wants to # enforce a constant timestep for all particles. This can be done # by activating this option, and by setting MinSizeTimestep and # MaxSizeTimestep to an equal value. # # - NOPMSTEPADJUSTMENT: # When this is set, the long-range timestep for the PM-force # computation (when the TreePM algorithm is used) is always # determined by MaxSizeTimeStep. Otherwise, it is determined by # the MaxRMSDisplacement parameter, or MaxSizeTimeStep, whichever # gives the smaller step. # # - HAVE_HDF5: # If this is set, the code will be compiled with support for input # and output in the HDF5 format. You need to have the HDF5 # libraries and headers installed on your computer for this option # to work. The HDF5 format can then be selected as format "3" in # Gadget's parameterfile. # # - OUTPUTPOTENTIAL: # This will make the code compute gravitational potentials for # all particles each time a snapshot file is generated. The values # are then included in the snapshot file. Note that the computation # of the values of the gravitational potential costs additional CPU. # # - OUTPUTACCELERATION: # This will include the physical acceleration of each particle in # snapshot files. # # - OUTPUTCHANGEOFENTROPY: # This will include the rate of change of entropy of gas particles # in snapshot files. # # - OUTPUTTIMESTEP: # This will include the current timesteps of all particles in the # snapshot files. # # - NOGRAVITY # This switches off gravity. Useful only for pure SPH simulations # in non-expanding space. # # - NOTREERND: # If this is not set, the tree construction will succeed even when # there are a few particles at identical locations. This is done by # `rerouting' particles once the node-size has fallen below 1.0e-3 # of the softening length. When this option is activated, this will # be surpressed and the tree construction will always fail if there # are particles at extremely close coordinates. # # - NOTYPEPREFIX_FFTW: # This is an option that signals that FFTW has been compiled # without the type-prefix option, i.e. no leading "d" or "s" # characters are used to access the library. # # - LONG_X/Y/Z: # These options can be used together with PERIODIC and NOGRAVITY only. # When set, the options define numerical factors that can be used to # distorts the periodic simulation cube into a parallelepiped of # arbitrary aspect ratio. This can be useful for idealized SPH tests. # # - TWODIMS: # This effectively switches of one dimension in SPH, i.e. the code # follows only 2d hydrodynamics in the xy-, yz-, or xz-plane. This # only works with NOGRAVITY, and if all coordinates of the third # axis are exactly equal. Can be useful for idealized SPH tests. # # - SPH_BND_PARTICLES: # If this is set, particles with a particle-ID equal to zero do not # receive any SPH acceleration. This can be useful for idealized # SPH tests, where these particles represent fixed "walls". # # - NOVISCOSITYLIMITER: # If this is set, the code will not try to put an upper limit on # the viscous force in case an implausibly high pair-wise viscous # force (which may lead to a particle 'reflection' in case of poor # timestepping) should arise. Note: For proper settings of the # timestep parameters, this situation should not arise. # # - COMPUTE_POTENTIAL_ENERGY: # When this option is set, the code will compute the gravitational # potential energy each time a global statistics is computed. This # can be useful for testing global energy conservation. # # - LONGIDS: # If this is set, the code assumes that particle-IDs are stored as # 64-bit long integers. This is only really needed if you want to # go beyond ~2 billion particles. # # - ISOTHERM_EQS: # This special option makes the gas behave like an isothermal gas # with equation of state P = cs^2 * rho. The sound-speed cs is set by # the thermal energy per unit mass in the intial conditions, # i.e. cs^2=u. If the value for u is zero, then the initial gas # temperature in the parameter file is used to define the sound speed # according to cs^2 = 3/2 kT/mp, where mp is the proton mass. # # - ADAPTIVE_GRAVSOFT_FORGAS: # When this option is set, the gravitational softening lengths used for # gas particles is tied to their SPH smoothing length. This can be useful # for dissipative collapse simulations. The option requires the setting # of UNEQUALSOFTENINGS. # # - SELECTIVE_NO_GRAVITY: # This can be used for special computations where one wants to # exclude certain particle types from receiving gravitational # forces. The particle types that are excluded in this fashion are # specified by a bit mask, in the same as for the PLACEHIGHRESREGION # option. # # - FORCETEST: # This can be set to check the force accuracy of the code. The # option needs to be set to a number between 0 and 1 (e.g. 0.01), # which is taken to specify a random fraction of particles for # which at each timestep forces by direct summation are # computed. The normal tree-forces and the correct direct # summation forces are collected in a file. Note that the # simulation itself is unaffected by this option, but it will of # course run much(!) slower, especially if # FORCETEST*NumPart*NumPart >> NumPart. Note: Particle IDs must # be set to numbers >=1 for this to work. # # - MAKEGLASS # This option can be used to generate a glass-like particle # configuration. The value assigned gives the particle load, # which is initially generated as a Poisson sample and then # evolved towards a glass with the sign of gravity reversed. # #-----------------------------------------------------------------------

Here, the DPMGRID option is essential as it defines the size of the particle grid. DPERIODIC compiles the code with periodic boundary conditions.

SYSTYPE = "Dianas-MacBook" Also, the system options set after the parameters allow you to specify the paths of the various libraries installed. In the above example,

is un-commented, and underneath that, various library paths are defined. All of these are default paths for library installations.

(This makefile is courtesy Diana Juncher’s Blog , with a few modifications)

Rename the file to Makefile and after making all the above changes, save.

Once the makefile is set and saved, type in the command prompt,

> make

This should compile a program “Gadget2” in your folder. Constructing the program is now done.

Running the First Simulation

Now, exit the folder:

> cd ..

Create a new folder here.

> mkdir run1

Copy the Gadget2 executable into this folder. We will place our initial conditions file and parameter file for the run in the same folder, and snapshots and data will be stored in the same.

GADGET 2 comes with example IC files and parameter files that can be found in the following way:

> cd Gadget2

> cd parameterfiles

From here, copy the file lcdm_gas.param to the run1 folder.

Now, go back to the main GADGET folder and enter the ICs folder:

> cd ../ICs

From here, copy the file lcdm_gas_littleendian.dat to the run1 folder.

Here, in the run1 folder we have three things now: Gadget2 executable, parameter file, and IC file.

Looking At The Parameter File

The parameter file is fairly self-explanatory, with a few changes here and there.

Here is what a typical parameter file will look like:

% Relevant files InitCondFile /home/him/Documents/Gadget-2.0.7/run1/lcdm_gas_littleendian.dat

OutputDir /home/him/Documents/Gadget-2.0.7/run1/ EnergyFile energy.txt

InfoFile info.txt

TimingsFile timings.txt

CpuFile cpu.txt RestartFile restart

SnapshotFileBase snapshot OutputListFilename /home/him/Documents/Gadget-2.0.7/run1/outputs_lcdm_gas.txt % CPU time -limit TimeLimitCPU 36000 % = 10 hours

ResubmitOn 0

ResubmitCommand my-scriptfile % Code options ICFormat 1

SnapFormat 1

ComovingIntegrationOn 1 TypeOfTimestepCriterion 0

OutputListOn 1

PeriodicBoundariesOn 1 % Caracteristics of run TimeBegin 0.090909091 % z=10, Begin of the simulation

TimeMax 1.0 Omega0 0.3

OmegaLambda 0.7

OmegaBaryon 0.04

HubbleParam 0.7

BoxSize 50000.0 % Output frequency TimeBetSnapshot 0.5

TimeOfFirstSnapshot 0 CpuTimeBetRestartFile 36000.0 ; here in seconds

TimeBetStatistics 0.05 NumFilesPerSnapshot 1

NumFilesWrittenInParallel 1 % Accuracy of time integration ErrTolIntAccuracy 0.025 MaxRMSDisplacementFac 0.2 CourantFac 0.15 MaxSizeTimestep 0.03

MinSizeTimestep 0.0 % Tree algorithm, force accuracy, domain update frequency ErrTolTheta 0.5

TypeOfOpeningCriterion 1

ErrTolForceAcc 0.005 TreeDomainUpdateFrequency 0.1 % Further parameters of SPH DesNumNgb 33

MaxNumNgbDeviation 2

ArtBulkViscConst 0.8

InitGasTemp 1000.0 % always ignored if set to 0

MinGasTemp 50.0 % Memory allocation PartAllocFactor 1.6

TreeAllocFactor 0.8

BufferSize 30 % in MByte % System of units UnitLength_in_cm 3.085678e21 ; 1.0 kpc

UnitMass_in_g 1.989e43 ; 1.0e10 solar masses

UnitVelocity_in_cm_per_s 1e5 ; 1 km/sec

GravityConstantInternal 0

% Softening lengths MinGasHsmlFractional 0.25 SofteningGas 15.0

SofteningHalo 15.0

SofteningDisk 0

SofteningBulge 0

SofteningStars 0

SofteningBndry 0 SofteningGasMaxPhys 15.0

SofteningHaloMaxPhys 15.0

SofteningDiskMaxPhys 0

SofteningBulgeMaxPhys 0

SofteningStarsMaxPhys 0

SofteningBndryMaxPhys 0

An explanation of the various parameters in the file is given here









In the above, we changed the softening lengths to 15.0 (as opposed to 600.0 given in the example file, which is wrong).



Note that InitCondFile and OutputDir hold the paths for the IC file and the output directory, which, in our present case, is run1 .



Also, the parameter OutputListOn is set to 1, which means you can specify the times (scale factors) at which you want the snapshot files to be generated in a text file, with each value separated by a line break. You can specify the file path in the parameter OutputListFilename . An example list would look like:



0.25



0.33



0.5



0.75



This will take snapshots at a = 0.25, 0.33 and so on. A customary snapshot is taken at the end.



(Note that the internal measure of time in a GADGET 2 process is the scale factor. )



The run parameters of the example parameter file are set to match the IC example file.



Running the Program



Finally, while in the run1 folder, type:



> mpirun -np 2 ./Gadget2 lcdm_gas.param



Here, ‘2’ specifies the number of processors to be used.



Voila! GADGET 2 is now running. Looks something like this:

The proper running begins:

You can see the code evolving the system through timesteps.

Viewing Snapshots with Gadgetviewer

Gadgetviewer is an interactive visualization tool for GADGET snapshots, made by John Helly.

You can obtain the source code here

Installing Gadgetviewer involves installing the following dependencies:

1. GTK 2+, a GUI library:

> sudo apt-get install libgtk2.0-dev

2. HDF5, for reading snapshots:

> sudo apt-get install libhdf5-serial-dev

3. LibPNG, for printing out PNG files:

> sudo apt-get install libpng-dev

With these prerequisites installed, we can now extract the Gadgetviewer files. Enter the Gadgetviewer folder, and type:



> ./configure –prefix=some/path/



This will most probably show you that all dependencies are installed, and prepare for installation in a folder of your choosing. Now, specify the default library locations in the Makefile as we have done in the case of GADGET-2. Then,



> make



> make install



This should install Gadgetviewer at the location specified. Enter the bin folder in the Gadgetviewer install folder, and open gadgetviewer.



Now, open the “File” menu and choose the “Read Gadget Snapshot” option. Select your file and open it.

You can choose the colour of the component according to the density, and create internal energy and other plots if the snapshot has the information.

You can rotate the snapshot to look at it from different angles with your mouse.

In the above snapshot, you can see the clumps (halos) and filamentary structures of dark matter (highlighted in yellow) at z = 0.

If your snapshots are named consistently, you can use the “Snapshot” counter on the bottom right to browse through a sequence of snapshots from inside the program itself.

It also gives you the option to generate a PNG file or a sequence of them, to create a movie.

It has a wonderful readme file and accompanying documentation that you can browse for the plethora of options on offer.

Generating Initial Conditions using N-GenIC

So, now that you have gone through running a whole simulation and viewing its results in Gadgetviewer, you must also learn how to generate your own initial conditions files for actual simulations that you want to run.

N-GenIC is a companion code written by Volker Springel, available from his website. Download the tarball here

The initial conditions file is just a snapshot generated using statistics (the power spectrum) at a specified redshift value.

Once you extract the files, enter the folder to modify the makefile. This file is pretty straightforward, and just needs the library file locations specified as earlier.

Once the makefile is done, inside the folder, type the usual:

> make

> make install

Once done, open the ics.param file to take a look at the parameters for the initial conditions.

This is a sample makefile:

Nmesh 128 % This is the size of the FFT grid used to

% compute the displacement field. One

% should have Nmesh >= Nsample.

Nsample 128 % sets the maximum k that the code uses,

% i.e. this effectively determines the

% Nyquist frequency that the code assumes,

% k_Nyquist = 2*PI/Box * Nsample/2

% Normally, one chooses Nsample such that

% Ntot = Nsample^3, where Ntot is the

% total number of particles



Box 50000.0 % Periodic box size of simulation

FileBase ics % Base-filename of output files

OutputDir ./ICs/ % Directory for output

GlassFile dummy_glass.dat % File with unperturbed glass or

% Cartesian grid

TileFac 8 % Number of times the glass file is

% tiled in each dimension (must be

% an integer)

% Nsample / TileFac should be 16.

Omega 0.3 % Total matter density (at z=0)

OmegaLambda 0.7 % Cosmological constant (at z=0)

OmegaBaryon 0.0 % Baryon density (at z=0)

HubbleParam 0.7 % Hubble paramater (may be used for power spec parameterization)

Redshift 15 % Starting redshift

Sigma8 0.8 % power spectrum normalization

SphereMode 1 % if “1” only modes with |k| < k_Nyquist are

% used (i.e. a sphere in k-space), otherwise modes with

% |k_x|,|k_y|,|k_z| < k_Nyquist are used

% (i.e. a cube in k-space)



WhichSpectrum 1 % “1” selects Eisenstein & Hu spectrum,

% “2” selects a tabulated power spectrum in

% the file ‘FileWithInputSpectrum’

% otherwise, Efstathiou parametrization is used

FileWithInputSpectrum input_spectrum.txt % filename of tabulated input

% spectrum (if used)

InputSpectrum_UnitLength_in_cm 3.085678e24 % defines length unit of tabulated

% input spectrum in cm/h.

% Note: This can be chosen different from UnitLength_in_cm

ReNormalizeInputSpectrum 1 % if set to zero, the

% tabulated spectrum is

% assumed to be normalized

% already in its amplitude to

% the starting redshift,

% otherwise this is recomputed

% based on the specified sigma8

ShapeGamma 0.21 % only needed for Efstathiou power spectrum

PrimordialIndex 1.0 % may be used to tilt the primordial index,

% primordial spectrum is k^PrimordialIndex



Seed 123456 % seed for IC-generator

NumFilesWrittenInParallel 1 % limits the number of files that are

% written in parallel when outputting

UnitLength_in_cm 3.085678e21 % defines length unit of output (in cm/h)

UnitMass_in_g 1.989e43 % defines mass unit of output (in g/cm)

UnitVelocity_in_cm_per_s 1e5 % defines velocity unit of output (in cm/sec)

The fields in the file are mostly self-explanatory.

Do note that the ratio of the NSample and TileFac parameters should be 16.

You can choose to create the ICs using three different power spectrum generation methods: Hu-Eisenstein, Efstathiou, or a tabulated power spectrum that you might have generated using anotheer program like CAMB.

Through the NumFilesWrittenInParallel parameter, you can also choose to generate multiple files in parallel.

You can set the other usual parameters like Omega, OmegaBaryon, OmegaLambda, the Hubble Constant, the Sigma8 value, and the tilt (primordial index).

The above file generates an IC file with the base filename ics, in a folder IC in the same folder.

Once the parameter file is set and saved, in the prompt, run N-GenIC in the same folder:

> ./N-GenIC ics.param

Thus, you can now generate your own IC files.

This completes this short guide, that teaches you how to generate ICs, run simulations, and view snapshots. Hope this helps!