#######################################################################
#  Look at end of file for a brief guide to the compile-time options. #
#######################################################################

#OPT   +=  -DPERIODIC 
OPT   +=  -DCOOLING    
OPT   +=  -DSFR         
#OPT   +=  -DMETALS       
OPT   +=  -DSTELLARAGE   
#OPT   +=  -DWINDS
OPT   +=  -DSOFTEREQS
OPT   +=  -DMOREPARAMS    

#OPT   +=  -DPMGRID=100

OPT   +=  -DSYNCHRONIZATION
OPT   +=  -DPEANOHILBERT
OPT   +=  -DWALLCLOCK   

#OPT   +=  -DFOF                 # enable FoF output 
#OPT   +=  -DBLACK_HOLES          # enable Black-Holes
#OPT   +=  -DBH_THERMALFEEDBACK   # enable Black-Hole feedback
#OPT   +=  -DSWALLOWGAS           # enable swallowing of gas by Black-Hole 
#OPT   +=  -DREPOSITION_ON_POTMIN # Reposition BH on the minimum potential
#OPT   +=  -DBH_DRAG             # Black-Hole drag force 


#OPT    +=  -DQUICK_LYALPHA 
#OPT   +=  -DISOTROPICWINDS
#OPT   +=  -DNOGRAVITY     
#OPT   +=  -DLONGBOX=60    
#OPT   +=  -DNOFIXEDMASSINKERNEL  
#OPT   +=  -DNOGRADHSML  
#OPT   +=  -DNOVISCOSITYLIMITER
#OPT   +=  -DENLARGEREGION=1.2
#OPT   +=  -DPLACEHIGHRESREGION=3
OPT   +=  -DDOUBLEPRECISION      
OPT   +=  -DDOUBLEPRECISION_FFTW      
#OPT   +=  -DNOTREERND 
#OPT   +=  -DNOSTOP_WHEN_BELOW_MINTIMESTEP
#OPT   +=  -DPSEUDOSYMMETRIC

#OPT   +=  -DNOPMSTEPADJUSTMENT
#OPT   +=  -DT3E    
#OPT   +=  -DNOTYPEPREFIX_FFTW        
OPT   +=  -DOUTPUTPOTENTIAL
#OPT   +=  -DOUTPUTACCELERATION
OPT   +=  -DOUTPUTPRESSURE
OPT   +=  -DOUTPUTCHANGEOFENTROPY
OPT   +=  -DOUTPUTCHANGEOFINTERNALENERGY
#OPT   +=  -DOUTPUTTIMESTEP
#OPT   +=  -DFORCETEST=0.1
#OPT   +=  -DISOTHERM=200
#OPT   +=  -DSTATICNFW
#OPT   +=  -DNFW_C=20
#OPT   +=  -DNFW_M200=1.0
#OPT   +=  -DNFW_Eps=0.025
#OPT   +=  -DNFW_DARKFRACTION=0.9
#OPT   +=  -DASMTH=1.25
#OPT   +=  -DRCUT=4.5
#OPT   +=  -DCONDUCTION 
#OPT   +=  -DCONDUCTION_CONSTANT 
#OPT   +=  -DCONDUCTION_SATURATION 
#OPT   +=  -DNOACCEL 
#OPT   +=  -DSOD
#OPT   +=  -DALLOWEXTRAPARAMS
#OPT   +=  -DREDUCEVISC             #  Enables time dependend viscosity
#OPT   +=  -DSAVEVISCOSITY          #  Saves alpha into snapshots
#OPT   +=  -DDARKENERGY            # Enables Dark Energy
#OPT   +=  -DTIMEDEPDE             # read w(z) from a file
#OPT   +=  -DRESCALEVINI           # rescale v_ini in read_ic_cluster
#OPT   +=  -DDEBUG    # enables core-dumps and FPU exceptions
#OPT   +=  -DPARTICLE_DEBUG      # Allows to trace particle by comunicating the Particle ID in hydra
#OPT   +=  -DOUTPUTCOOLRATE       # outputs cooling rate, and conduction rate if enabled
OPT   +=  -DUNEQUALSOFTENINGS
# Magnetic Field options
#OPT   +=  -DMAGNETIC
#OPT   +=  -DMAGFORCE
#OPT   +=  -DBRIOWU
#OPT   +=  -DARTBPRES
#OPT   +=  -DDIVBFORCE
#OPT   +=  -DTRACEDIVB
#OPT   +=  -DDBOUTPUT
#OPT   +=  -DCORRECTDB
#OPT   +=  -DCORRECTBFRC
#OPT   +=  -DXXLINFO
#OPT   +=  -DBINISET
#OPT   +=  -DBSMOOTH
#OPT   +=  -DOUTPUTBSMOOTH
#OPT   +=  -DOUTPUTDENSNORM
#OPT   +=  -DFLEXSTEPS
#OPT   +=  -DSTATICHQ
#OPT   +=  -DHQ_M200=1.0
#OPT   +=  -DHQ_C=10
#OPT   +=  -DHQ_DARKFRACTION=0.9
#OPT   +=  -DNOISMPRESSURE
#OPT   +=  -DMAKEGLASS
#OPT   +=  -DNO_TREEDATA_IN_RESTART
#OPT   +=  -DCOMPUTE_POTENTIAL_ENERGY

#### Cecilia 's model

#OPT   +=  -DSFR_METALS      # Cecilia's model. (All SFR_* options belong to it)
#OPT   +=  -DSFR_FEEDBACK
#OPT   +=  -DSFR_SNI
#OPT   +=  -DSFR_SNII
#OPT   +=  -DSFR_ENRICH
#OPT   +=  -DSFR_DECOUPLING  # Marri-like decoupling
#OPT   +=  -DSFR_DIFFUSION


#OPT   +=  -DHAVE_HDF5  # needs to be set to compile with HDF5 I/O support (selected with file-format 3)


SYSTYPE="TRAPEZIUM"
#SYSTYPE="ALTIX"
#SYSTYPE="Mako"
#SYSTYPE="MPA"
#SYSTYPE="Regatta"
#SYSTYPE="cosmos"
#SYSTYPE="RZG_LinuxCluster-gcc"
#SYSTYPE="CINECA32"
#SYSTYPE="CINECA64"
#SYSTYPE="DEI32"


CC       =   icc        # sets the C-compiler (default)
OPTIMIZE =   -O2 -fno-fnalias -convertlittle_endian  # optimization and warning flags (default)

MPICHLIB =   -L/opt/modules/cmplrs/c_8.1.023/lib -lm -lscs -lmpi -ldl


ifeq ($(SYSTYPE),"TRAPEZIUM")
CC       =   icc   # sets the C-compiler
OPTIMIZE = #-fast -mcpu=itanium2 -ftz -IPF-fma -IPF-fp-relaxed \
           #-IPF-fp-speculationfast -prefetch -fno-fnalias 
#-convertbig_endian
GSL_INCL = -I/data/e3/users/projects/TRAPEZIUM/libs/GSL/include
GSL_LIBS = -L/data/e3/users/projects/TRAPEZIUM/libs/GSL/lib
FFTW_INCL= -I/data/e3/users/projects/TRAPEZIUM/libs/FFTW2/include
FFTW_LIBS= -L/data/e3/users/projects/TRAPEZIUM/libs/FFTW2/lib
MPI_INCL = -I/usr/lib64/mpi/gcc/openmpi/include/
MPICHLIB = -lm  -lmpi -ldl /usr/lib64/libdat.so.1 -L/usr/lib64/mpi/gcc/openmpi/lib64/ #-L/opt/modules/cmplrs/c_8.1.023/lib -lscs	
HDF5INCL = 
HDF5LIB  = 
endif


ifeq ($(SYSTYPE),"ALTIX")
CC       =   icc   # sets the C-compiler
OPTIMIZE = -fast -mcpu=itanium2 -ftz -IPF-fma -IPF-fp-relaxed \
           -IPF-fp-speculationfast -prefetch -fno-fnalias #-convertbig_endian
GSL_INCL = -I/data/e0/users/skarl/CODES/P-Gadget2/GSL/include
GSL_LIBS = -L/data/e0/users/skarl/CODES/P-Gadget2/GSL/lib
FFTW_INCL= -I/data/e0/users/skarl/CODES/P-Gadget2/FFTW2/include
FFTW_LIBS= -L/data/e0/users/skarl/CODES/P-Gadget2/FFTW2/lib
MPICHLIB = -L/opt/modules/cmplrs/c_8.1.023/lib -lm -lscs -lmpi -ldl
HDF5INCL = 
HDF5LIB  = 
endif


ifeq ($(SYSTYPE),"MPA")
CC       =   mpicc   # sets the C-compiler
OPTIMIZE =   -O3 -Wall
GSL_INCL = -I/usr/common/pdsoft/include
GSL_LIBS = -L/usr/common/pdsoft/lib
FFTW_INCL= 
FFTW_LIBS= 
MPICHLIB =
HDF5INCL = -I/opt/hdf5/include
HDF5LIB  = -L/opt/hdf5/lib -static -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 =
endif


ifeq ($(SYSTYPE),"Regatta")
CC       =   mpcc_r   # sets the C-compiler
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),"CINECA32")
CC       =   mpcc_r   # sets the C-compiler
OPTIMIZE =   -O5 -qstrict -qipa -bmaxdata=500000000
GSL_INCL = -I/u/inapd006/include
GSL_LIBS = -L/u/inapd006/lib32                
FFTW_INCL= -I/u/inapd006/include
FFTW_LIBS= -L/u/inapd006/lib32  -qbmaxdata=500000000 -qipa
MPICHLIB =
endif

ifeq ($(SYSTYPE),"CINECA64")
CC       =   mpcc_r   # sets the C-compiler
OPTIMIZE =   -O5 -qstrict -qipa -q64
GSL_INCL = -I/u/inats004/include
GSL_LIBS = -L/u/inats004/lib                
FFTW_INCL= -I/u/inats004/include
FFTW_LIBS= -L/u/inats004/lib -q64 -qipa
MPICHLIB =
endif


ifeq ($(SYSTYPE),"DEI32")
CC       =   mpcc   # sets the C-compiler
OPTIMIZE =   -O3 -qarch=pwr3 -qtune=pwr3 -qstrict -bmaxdata:1000000000
GSL_INCL = -I/home/kdolag/include
GSL_LIBS = -L/home/kdolag/lib
FFTW_INCL= -I/home/kdolag/include
FFTW_LIBS= -L/home/kdolag/lib  -bmaxdata:1000000000
MPICHLIB =
endif


ifeq ($(SYSTYPE),"RZG_LinuxCluster")
CC       =   mpicci   # sets the C-compiler
OPTIMIZE =   -O3 -ip 
# Don't use the "-rcd" optimization of Intel's compiler! Makes the code crash at times! 
GSL_INCL = -I/afs/rzg/u/vrs/gsl_linux/include
GSL_LIBS = -L/afs/rzg/u/vrs/gsl_linux/lib                -static
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 
endif


ifeq ($(SYSTYPE),"RZG_LinuxCluster-gcc")
CC       =   /afs/rzg/u/vrs/bin/mpiccf   # sets the gcc C-compiler
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
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 
endif

ifneq ($(OPT91),"HAVE_HDF5")
HDF5INCL =
HDF5LIB  =
endif

ifeq ($(SYSTYPE),"cosmos")
CC       =   icc   # sets the gcc C-compiler
OPTIMIZE =  -O2 -w -lmpi -lscs
GSL_LIBS = -L/home/cosmos/share-ia64/lib
GSL_INCL = -I/home/cosmos/share-ia64/include
FFTW_INCL= -I/home/cosmos/share-ia64/include
FFTW_LIBS= -L/home/cosmos/share-ia64/lib
HDF5INCL = 
HDF5LIB  = 
endif


OPTIONS =  $(OPTIMIZE) $(OPT)

EXEC   = P-Gadget2

OBJS   = main.o fof.o blackhole.o run.o  predict.o begrun.o endrun.o global.o  \
	 timestep.o  init.o restart.o  io.o  sfr_eff.o  \
	 accel.o   read_ic.o  cooling.o ngb.o \
	 system.o  allocate.o  density.o  bsmooth.o\
	 gravtree.o hydra.o  driftfac.o darkenergy.o \
	 domain.o  allvars.o potential.o read_ic_cluster_gas.o \
         forcetree.o  read_ic_cluster.o peano.o gravtree_forcetest.o \
	 pm_periodic.o pm_nonperiodic.o longrange.o \


INCL   = allvars.h  proto.h  forcetree.h tags.h cooling.h domain.h  


CFLAGS =   $(OPTIONS)  $(GSL_INCL) $(FFTW_INCL)  $(HDF5INCL) $(MPI_INCL)

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   =   $(HDF5LIB) -g $(MPICHLIB)  $(GSL_LIBS) -lgsl -lgslcblas -lm $(FFTW_LIB) 


$(EXEC): $(OBJS) 
	$(CC) $(OBJS) $(LIBS)   -o  $(EXEC)  

$(OBJS): $(INCL) 


.PHONY : clean
clean:
	rm -f $(OBJS) $(EXEC)




###############################################################################
#
# at compile-time. 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".
#
# Main code options:
#
#     These affect the physical model that is simulated.
#
#     - PERIODIC:   Set this if you want to have periodic boundary conditions.
#     - COOLING:    This enables radiative cooling and heating. It also enables
#                   an external UV background which is read from a file.
#     - SFR:        This enables star formation using an effective multiphase
#                   models. This option requires cooling.
#     - METALS:     This model activates the tracking of enrichment in gas and
#                   stars. Note that metal-line cooling is not included yet.
#     - STELLARAGE: This stores the formation redshift of each star particle.
#     - WINDS:      This activates galactic winds. Requires star formation. 
#     - ISOTROPICWINDS: This makes the wind isotropic. If not set the wind is
#                       spawned in an axial way. Requires winds to be activated.
#     - NOGRAVITY:  This switches off gravity. Makes only sense for pure
#                   SPH simulations in non-expanding space.
#     - LONGBOX:    This can be used only together with PERIODIC and NOGRAVITY.
#                   It needs to be set to an integer > 1. The size of the
#                   computational box in the x-direction is multiplied by
#                   this factor.
# 
# Options for SPH:
#  
#     - NOFIXEDMASSINKERNEL:  If set, the number of SPH particles in the kernel
#                             is kept constant instead of the mass.
#     - NOGRADHSML:           If actived, an equation of motion without grad(h)
#                             terms is used. 
#            Note: To have the default "entropy"-formulation of SPH (Springel & 
#                  Hernquist), the switches NOFIXEDMASSINKERNEL and NOGRADHSML 
#                  should *not* be set.
#     - NOVISCOSITYLIMITER:   If this is set, there is no explicit upper limit 
#                             on the viscosity that tries to prevent particle 
#                             'reflection' in case of poor timestepping.
#
# Numerical options:
#
#     - PMGRID:     This enables the TreePM method, i.e. the long-range force 
#                   is computed with a PM-algoritthm, 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 a 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 large-scale 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 very small
#                   scales is supplemented by the tree. This procedure can be useful
#                   for "zoom-simulations", where 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 that encodes the particle types that represent the
#                   high-res particles in the form of a bit mask. For example, if
#                   types 0, 1, and 4 form the high-res particles, set the parameter
#                   to PLACEHIGHRESREGION=1+2+16. 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 high-res region can be expanded.
#                   For example, setting it to 1.4 will enlarge its side-length by 
#                   40% (it remains centered on the high-res particles). Hence, with 
#                   such a setting, the high-res region may expand or move by a
#                   limited amount. If in addition SYNCHRONIZATION is activated, then 
#                   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.
#     - DOUBLEPRECISION: This makes the code store and compute internal 
#                        particle data in double precision. Note that output
#                        files are nevertheless written by converting to single
#                        precision.
#     - 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.
#     - 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 Min- and
#                        MaxSizeTimestep to an equal value.
#     - 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 in general improves the
#                        long-term integration behaviour of periodic orbits.
#     - SYNCHRONIZATION: When this is set, particles may only increase their 
#                        timestep if the new timestep will put them into 
#                        synchronization with the higher time level. This typically
#                        means that only on half of the timesteps of a particle
#                        an increase of the step may occur.
#     - NOPMSTEPADJUSTMENT: When this is set, the long-range timestep for the
#                        PM force computation is always determined by MaxSizeTimeStep.
#                        Otherwise, it is set to the minimum of MaxSizeTimeStep and
#                        the timestep obtained for the maximum long-range force with
#                        an effective softening scale equal to the PM smoothing-scale.
# Architecture options:
#
#     - T3E:       The code assumes that sizeof(int)=4 holds. A few machines
#                  (like Cray T3E) have sizeof(int)=8. In this case, set the
#                  T3E flag.
#     - NOTYPEPREFIX_FFTW: If this is set, the fftw-header/libraries are accessed
#                  without type prefix (adopting whatever was chosen as default at compile
#                  of fftw). Otherwise, the type prefix 'd' for double is used.
# 
# Input options:
# 
#     - MOREPARAMS:  Activate this to allow a set of additional parameters in
#                    the parameterfile which control the star formation and 
#                    feedback sector. This option must be activated when star
#                    formation is switched on.
#
# Output options:
#
#     - OUTPUTPOTENTIAL: This will force the code to compute gravitational
#                        potentials for all particles each time a snapshot file
#                        is generated. This values are then included in the
#                        snapshot file. Note that the computation of the
#                        values of the potential costs additional time.
#     - 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 an output of the timesteps actually
#                        taken by each particle.
# 
# Miscellaneous options:
#
#     - 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.
#
# Debugging/testing options:
#
#     - 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
#                        if FORCETEST*NumPart*NumPart >> NumPart. Note: Particle
#                        IDs must be set to numbers >=1 for this to work.
#
###############################################################################




#     - QUICK_LYALPHA:   This only works for cosmological simulations in periodic boxes
#                        with COOLING & SFR. (WINDS, METALS should be deselected).
#                        It will simply convert all gas particles above overdensity
#                        CritPhysOverdensity and with Temperature below 10^5 K to stars.
#                        This should still leave the Ly-Alpha forest largely unaffected,
#                        but should be faster. It is recommended to set GENERATIONS equal
#                        to 1 for maximum speed-up.