diff --git a/src/begrun.c b/src/begrun.c index ea05baa..eec686c 100644 --- a/src/begrun.c +++ b/src/begrun.c @@ -1,2748 +1,2748 @@ #include #include #include #include #include #include #include #include #include "allvars.h" #include "proto.h" /*! \file begrun.c * \brief initial set-up of a simulation run * * This file contains various functions to initialize a simulation run. In * particular, the parameterfile is read in and parsed, the initial * conditions or restart files are read, and global variables are * initialized to their proper values. */ /*! This function performs the initial set-up of the simulation. First, the * parameterfile is set, then routines for setting units, reading * ICs/restart-files are called, auxialiary memory is allocated, etc. */ void begrun(void) { struct global_data_all_processes all; #ifdef DETAILED_CPU double tstart,tend; tstart = second(); #endif if(ThisTask == 0) { - printf("\nThis is Gadget, version `%s'.\n", GADGETVERSION); + printf("\nThis is Gear, version `%s'.\n", GADGETVERSION); printf("\nRunning on %d processors.\n", NTask); } read_parameter_file(ParameterFile); /* ... read in parameters for this run */ allocate_commbuffers(); /* ... allocate buffer-memory for particle exchange during force computation */ set_units(); #if defined(PERIODIC) && (!defined(PMGRID) || defined(FORCETEST)) ewald_init(); #endif open_outputfiles(); random_generator = gsl_rng_alloc(gsl_rng_ranlxd1); #ifdef RANDOMSEED_AS_PARAMETER if(ThisTask == 0) printf("Using %d as initial random seed\n",All.RandomSeed); gsl_rng_set(random_generator, All.RandomSeed); /* start-up seed */ #else if(ThisTask == 0) printf("Using %d as initial random seed\n",42); gsl_rng_set(random_generator, 42); /* start-up seed */ #endif #ifdef PMGRID long_range_init(); #endif All.TimeLastRestartFile = CPUThisRun; #ifdef MULTIPHASE All.StickyLastCollisionTime = All.TimeBegin; #endif #ifdef COSMICTIME if(All.ComovingIntegrationOn) { if (ThisTask==0) printf("Initialize cosmic table\n"); init_cosmictime_table(); if (ThisTask==0) printf("Initialize cosmic table done.\n"); } if (ThisTask==0) printf("Initialize full cosmic table\n"); init_full_cosmictime_table(); if (ThisTask==0) printf("Initialize full cosmic table done.\n"); #endif /* other physics initialization */ #ifdef COOLING if (All.CoolingType==0) /* sutherland */ { if(ThisTask == 0) printf("Initialize cooling function...\n"); init_cooling(0); if(ThisTask == 0) printf("Initialize cooling function done.\n"); } if (All.CoolingType==2) /* cooling with metals */ { if(ThisTask == 0) printf("Initialize cooling function...\n"); #ifdef COOLING_WIERSMA //InitWiersmaCooling("/home/epfl/revaz/code/gear/PyCool/tables_wiersma/coolingtables/"); InitWiersmaCooling(All.CoolingDirectory); //SetRedshiftInterpolationOff(); #else #ifdef COOLING_GRACKLE init_cooling_GRACKLE(); #else init_cooling_with_metals(); #endif #endif if(ThisTask == 0) printf("Initialize cooling function done.\n"); } #endif #ifdef CHIMIE int i; if(ThisTask == 0) printf("Initialize chimie...\n"); init_chimie(); check_chimie(); if(ThisTask == 0) { for (i=0;i 0.1/All.MaxSizeTimestep)&&(ThisTask==0)) // { // printf("\nStickyLambda is to big and you may experiment numerical problems !\n"); // printf("You should either decrease StickyLambda or decrease MaxSizeTimestep.\n"); // printf("(StickyLambda=%g,maxStickyLambda=%g)\n",All.StickyLambda,0.01/All.MaxSizeTimestep); // printf("try \n"); // printf("StickyLambda <= %g or MaxSizeTimestep <= %g \n",(0.01/All.MaxSizeTimestep),(0.01/All.StickyLambda)); // fflush(stdout); // endrun(121212); // } #ifdef COLDGAS_CYCLE All.ColdGasCycleTransitionTime *= 3.1536e+13*All.HubbleParam/All.UnitTime_in_s; /* Myr to code unit */ #endif #endif #ifdef SFR All.StarFormationTime = All.StarFormationTime/All.UnitTime_in_s * 3.1536e16*All.HubbleParam; All.StarFormationDensity = All.StarFormationDensity/All.UnitDensity_in_cgs/(All.HubbleParam*All.HubbleParam); #endif #ifdef FOF All.FoF_Density = All.FoF_Density/All.UnitDensity_in_cgs/(All.HubbleParam*All.HubbleParam); All.FoF_ThresholdDensity = All.FoF_ThresholdDensityFactor*All.FoF_Density; All.FoF_MinHeadDensity = All.FoF_MinHeadDensityFactor *All.FoF_Density; All.FoF_MinGroupMass *=SOLAR_MASS/All.UnitMass_in_g*All.HubbleParam; /* to CMU */ #endif #if defined (HEATING_PE) || defined (STELLAR_FLUX) All.HeatingPeLMRatio[0] = All.HeatingPeLMRatioGas; All.HeatingPeLMRatio[1] = All.HeatingPeLMRatioHalo; All.HeatingPeLMRatio[2] = All.HeatingPeLMRatioDisk; All.HeatingPeLMRatio[3] = All.HeatingPeLMRatioBulge; All.HeatingPeLMRatio[4] = All.HeatingPeLMRatioStars; All.HeatingPeLMRatio[5] = All.HeatingPeLMRatioBndry; int k; for (k=0;k<6;k++) { All.HeatingPeLMRatio[k] *= 1./SOLAR_MASS; /* erg/s/Msol to erg/s/g */ All.HeatingPeLMRatio[k] *= All.UnitMass_in_g*All.UnitTime_in_s / All.UnitEnergy_in_cgs / All.HubbleParam; /* erg/s/g to code unit */ } #endif #ifdef FEEDBACK All.SupernovaEgySpecPerMassUnit *= All.UnitMass_in_g / All.UnitEnergy_in_cgs; All.SupernovaTime *= 3.1536e+13*All.HubbleParam/All.UnitTime_in_s; /* Myr to code unit */ #endif #ifdef FEEDBACK_WIND All.SupernovaWindEgySpecPerMassUnit *= All.UnitMass_in_g / All.UnitEnergy_in_cgs; All.SupernovaWindSpeed = sqrt( 2*All.SupernovaWindFractionInEgyKin * All.SupernovaWindEgySpecPerMassUnit / All.SupernovaWindParameter ); #endif #if defined (AGN_ACCRETION) || defined (BONDI_ACCRETION) All.LightSpeed = C/All.UnitVelocity_in_cm_per_s; #endif #ifdef CHIMIE All.ChimieSupernovaEnergy = All.ChimieSupernovaEnergy/All.UnitMass_in_g/pow(All.UnitVelocity_in_cm_per_s,2)*All.HubbleParam; All.ChimieWindSpeed = All.ChimieWindSpeed*1e5/All.UnitVelocity_in_cm_per_s; All.ChimieWindTime = All.ChimieWindTime*3.1536e13/All.UnitTime_in_s*All.HubbleParam; All.ChimieSNIaThermalTime = All.ChimieSNIaThermalTime*3.1536e13/All.UnitTime_in_s*All.HubbleParam; All.ChimieSNIIThermalTime = All.ChimieSNIIThermalTime*3.1536e13/All.UnitTime_in_s*All.HubbleParam; All.ChimieMaxSizeTimestep = All.ChimieMaxSizeTimestep*3.1536e13/All.UnitTime_in_s*All.HubbleParam; #ifdef CHIMIE_TIMEBET All.ChimieTimeBetChimie = All.ChimieTimeBetChimie*3.1536e13/All.UnitTime_in_s*All.HubbleParam; #endif #endif #if defined(CHIMIE) || defined(FOF) All.CMUtoMsol = All.UnitMass_in_g/SOLAR_MASS/All.HubbleParam; /* convertion factor from Code Mass Unit to Solar Mass */ All.MsoltoCMU = 1/All.CMUtoMsol; /* convertion factor from Solar Mass to Code Mass Unit */ #endif #ifdef CHIMIE #ifdef CHIMIE_ONE_SN_ONLY All.ChimieOneSNMass = All.ChimieOneSNMass*All.MsoltoCMU; #endif #if CHIMIE_EJECTA_RADIUS == 1 All.ChimieEjectaRadius = All.ChimieEjectaRadius * KPC_IN_CM/All.UnitLength_in_cm * All.HubbleParam; /* kpc to code length units */ #endif #endif #ifdef JEANS_PRESSURE_FLOOR All.JeansMassFactor = pow(All.JeansMassFactor,2/3.); #endif #ifdef COOLING_GRACKLE #ifdef COOLING_GRACKLE_H_SSHIELDING All.GrackleHSShieldingDensityThreshold = All.GrackleHSShieldingDensityThreshold*1.6726e-24/All.UnitDensity_in_cgs/(All.HubbleParam*All.HubbleParam); /* atom/cm3 to density code unit */ #endif #endif #ifdef FOF All.FoF_TimeBetFoF = All.FoF_TimeBetFoF*3.1536e13/All.UnitTime_in_s*All.HubbleParam; #endif #ifdef COMPUTE_PHYSICAL_UNITS // density to atom per CC (we assume the density is already corrected from hubbpleparam and scaling factor) All.CDUtoAtomPerCC = All.UnitMass_in_g / pow(All.UnitLength_in_cm,3) / PROTONMASS ; #endif if(ThisTask == 0) { printf("\nHubble (internal units) = %g\n", All.Hubble); printf("G (internal units) = %g\n", All.G); printf("Boltzmann = %g \n", All.Boltzmann); printf("ProtonMass = %g \n", All.ProtonMass); printf("mumh = %g \n", All.mumh); printf("UnitMass_in_g = %g \n", All.UnitMass_in_g); printf("UnitTime_in_s = %g \n", All.UnitTime_in_s); printf("UnitVelocity_in_cm_per_s = %g \n", All.UnitVelocity_in_cm_per_s); printf("UnitDensity_in_cgs = %g \n", All.UnitDensity_in_cgs); printf("UnitEnergy_in_cgs = %g \n", All.UnitEnergy_in_cgs); printf("\n"); #ifdef SFR printf("StarFormationDensity (internal units) = %g \n", All.StarFormationDensity); printf("StarFormationTime (internal units) = %g \n", All.StarFormationTime); #endif #ifdef FEEDBACK printf("SupernovaTime (internal units) = %g \n", All.SupernovaTime); printf("SupernovaEgySpecPerMassUnit (internal units) = %g \n", All.SupernovaEgySpecPerMassUnit); #endif #ifdef FEEDBACK_WIND printf("SupernovaWindEgySpecPerMassUnit (internal units) = %g \n", All.SupernovaWindEgySpecPerMassUnit); printf("SupernovaWindSpeed (internal units) = %g \n", All.SupernovaWindSpeed); #endif #ifdef MULTIPHASE printf("CriticalEgySpec (internal units) = %g \n", All.CriticalEgySpec); printf("CriticalNonCollisionalEgySpec (internal units) = %g \n", All.CriticalNonCollisionalEgySpec); printf("StickyCollisionTime (internal units) = %g \n", All.StickyCollisionTime); printf("StickyIdleTime (internal units) = %g \n", All.StickyIdleTime); printf("StickyDensity (internal units) = %g \n", All.StickyDensity); printf("StickyTime (internal units) = %g \n", All.StickyTime); printf("StickyMinVelocity (internal units) = %g \n", All.StickyMinVelocity); printf("StickyMaxVelocity (internal units) = %g \n", All.StickyMaxVelocity); #endif #ifdef COLDGAS_CYCLE printf("ColdGasCycleTransitionTime (internal units) = %g \n", All.ColdGasCycleTransitionTime); #endif #ifdef CHIMIE printf("ChimieSupernovaEnergy (internal units) = %g \n", All.ChimieSupernovaEnergy); printf("ChimieWindSpeed (internal units) = %g \n", All.ChimieWindSpeed); printf("ChimieWindTime (internal units) = %g \n", All.ChimieWindTime); printf("ChimieSNIaThermalTime (internal units) = %g \n", All.ChimieSNIaThermalTime); printf("ChimieSNIIThermalTime (internal units) = %g \n", All.ChimieSNIIThermalTime); printf("ChimieMaxSizeTimestep (internal units) = %g \n", All.ChimieMaxSizeTimestep); #ifdef CHIMIE_TIMEBET printf("ChimieTimeBetChimie (internal units) = %g \n", All.ChimieTimeBetChimie); #endif #endif #ifdef FOF printf("FoF_Density (internal units) = %g \n",All.FoF_Density); printf("FoF_ThresholdDensity (internal units) = %g \n",All.FoF_ThresholdDensity); printf("FoF_MinHeadDensity (internal units) = %g \n",All.FoF_MinHeadDensity); printf("FoF_MinGroupMass (internal units) = %g \n",All.FoF_MinGroupMass); printf("FoF_VirialFractionThreshold (internal units) = %g \n",All.FoF_VirialFractionThreshold); printf("FoF_HsmlSearchRadiusFactor (internal units) = %g \n",All.FoF_HsmlSearchRadiusFactor); printf("FoF_TimeBetFoF (internal units) = %g \n",All.FoF_TimeBetFoF); #endif #ifdef JEANS_PRESSURE_FLOOR printf("JeansMassFactor^(2/3) = %g \n",All.JeansMassFactor); #endif #ifdef COOLING_GRACKLE #ifdef COOLING_GRACKLE_H_SSHIELDING printf("GrackleHSShieldingDensityThreshold(internal units)= %g \n",All.GrackleHSShieldingDensityThreshold); #endif #endif #ifdef COMPUTE_PHYSICAL_UNITS printf("CDUtoAtomPerCC = %g \n",All.CDUtoAtomPerCC); #endif printf("\n"); } #ifdef ISOTHERM_EQS All.MinEgySpec = 0; #else All.MinEgySpec = 1 / meanweight * (1.0 / GAMMA_MINUS1) * (BOLTZMANN / PROTONMASS) * All.MinGasTemp; All.MinEgySpec *= All.UnitMass_in_g / All.UnitEnergy_in_cgs; #endif } /*! Initialize local system state variables */ void init_local_sys_state(void) { #ifdef SFR LocalSysState.StarEnergyInt = 0.; #ifdef COOLING LocalSysState.RadiatedEnergy = 0.; #endif #endif #ifdef CHIMIE_THERMAL_FEEDBACK LocalSysState.EnergyThermalFeedback = 0.; #endif #ifdef CHIMIE_KINETIC_FEEDBACK LocalSysState.EnergyKineticFeedback = 0.; #endif #ifdef MULTIPHASE LocalSysState.EnergyRadSticky = 0.; #endif #ifdef FEEDBACK_WIND LocalSysState.EnergyFeedbackWind = 0.; #endif #ifdef INTEGRAL_CONSERVING_DISSIPATION LocalSysState.EnergyICDissipation = 0.; #endif } /*! This function opens various log-files that report on the status and * performance of the simulstion. On restart from restart-files * (start-option 1), the code will append to these files. */ void open_outputfiles(void) { char mode[2], buf[200]; #ifdef ADVANCEDSTATISTICS int i=0; #endif if(RestartFlag == 0 || RestartFlag == 2) strcpy(mode, "w"); else strcpy(mode, "a"); /* for this kind of log, all tasks write its own file */ #ifdef CHIMIE #ifdef CHIMIE_STATS sprintf(buf, "%s%s_%s.%d", All.OutputDir, All.ChimieFile,"SNs",ThisTask); if(!(FdChimieStatsSNs = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } sprintf(buf, "%s%s_%s.%d", All.OutputDir, All.ChimieFile,"Gas",ThisTask); if(!(FdChimieStatsGas = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif #ifdef FOF sprintf(buf, "%s%s.%d", All.OutputDir, All.FoF_ChimieFile,ThisTask); if(!(FdFOF_Chimie = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif // FOF #endif if(ThisTask != 0) /* only the root processor writes to the log files */ return; sprintf(buf, "%s%s", All.OutputDir, All.CpuFile); if(!(FdCPU = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #ifdef ADVANCEDCPUSTATISTICS else { if(RestartFlag == 0 || RestartFlag == 2) /* write the header */ { fprintf(FdCPU,"# Step "); fprintf(FdCPU,"Time "); fprintf(FdCPU,"nCPUs "); fprintf(FdCPU,"CPU_Total "); #ifdef DETAILED_CPU fprintf(FdCPU,"CPU_Leapfrog "); fprintf(FdCPU,"CPU_Physics "); fprintf(FdCPU,"CPU_Residual "); fprintf(FdCPU,"CPU_Accel "); fprintf(FdCPU,"CPU_Begrun "); #endif fprintf(FdCPU,"CPU_Gravity "); fprintf(FdCPU,"CPU_Hydro "); #ifdef COOLING fprintf(FdCPU,"CPU_Cooling "); #endif #ifdef SFR fprintf(FdCPU,"CPU_StarFormation "); #endif #ifdef CHIMIE fprintf(FdCPU,"CPU_Chimie "); #endif #ifdef MULTIPHASE fprintf(FdCPU,"CPU_Sticky "); #endif fprintf(FdCPU,"CPU_Domain "); fprintf(FdCPU,"CPU_Potential "); fprintf(FdCPU,"CPU_Predict "); fprintf(FdCPU,"CPU_TimeLine "); fprintf(FdCPU,"CPU_Snapshot "); fprintf(FdCPU,"CPU_TreeWalk "); fprintf(FdCPU,"CPU_TreeConstruction "); fprintf(FdCPU,"CPU_CommSum "); fprintf(FdCPU,"CPU_Imbalance "); fprintf(FdCPU,"CPU_HydCompWalk "); fprintf(FdCPU,"CPU_HydCommSumm "); fprintf(FdCPU,"CPU_HydImbalance "); fprintf(FdCPU,"CPU_EnsureNgb "); fprintf(FdCPU,"CPU_PM "); fprintf(FdCPU,"CPU_Peano "); #ifdef DETAILED_CPU_DOMAIN fprintf(FdCPU,"CPU_Domain_findExtend "); fprintf(FdCPU,"CPU_Domain_determineTopTree "); fprintf(FdCPU,"CPU_Domain_sumCost "); fprintf(FdCPU,"CPU_Domain_findSplit "); fprintf(FdCPU,"CPU_Domain_shiftSplit "); fprintf(FdCPU,"CPU_Domain_countToGo "); fprintf(FdCPU,"CPU_Domain_exchange "); #endif #ifdef DETAILED_CPU_GRAVITY fprintf(FdCPU,"CPU_Gravity_TreeWalk1 "); fprintf(FdCPU,"CPU_Gravity_TreeWalk2 "); fprintf(FdCPU,"CPU_Gravity_CommSum1 "); fprintf(FdCPU,"CPU_Gravity_CommSum2 "); fprintf(FdCPU,"CPU_Gravity_Imbalance1 "); fprintf(FdCPU,"CPU_Gravity_Imbalance2 "); #endif /* return */ fprintf(FdCPU,"\n"); fflush(FdCPU); } } #endif sprintf(buf, "%s%s", All.OutputDir, All.InfoFile); if(!(FdInfo = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } sprintf(buf, "%s%s", All.OutputDir, All.LogFile); if(!(FdLog = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } sprintf(buf, "%s%s", All.OutputDir, All.EnergyFile); if(!(FdEnergy = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #ifdef ADVANCEDSTATISTICS else { if(RestartFlag == 0 || RestartFlag == 2 ) /* write the header */ { fprintf(FdEnergy,"# Time EnergyInt EnergyPot EnergyKin "); #ifdef COOLING fprintf(FdEnergy,"EnergyRadSph "); #endif #ifdef AGN_HEATING fprintf(FdEnergy,"EnergyAGNHeat "); #endif #ifdef DISSIPATION_FORCES fprintf(FdEnergy,"EnergyDissipationForces "); #endif #ifdef INTEGRAL_CONSERVING_DISSIPATION fprintf(FdEnergy,"EnergyICDissipation "); #endif #ifdef MULTIPHASE fprintf(FdEnergy,"EnergyRadSticky "); #endif #ifdef FEEDBACK_WIND fprintf(FdEnergy,"EnergyFeedbackWind "); #endif #ifdef BUBBLES fprintf(FdEnergy,"EnergyBubbles "); #endif #ifdef CHIMIE_THERMAL_FEEDBACK fprintf(FdEnergy,"EnergyThermalFeedback "); #endif #ifdef CHIMIE_KINETIC_FEEDBACK fprintf(FdEnergy,"EnergyKineticFeedback "); #endif for (i=0;i<6;i++) { fprintf(FdEnergy,"EnergyIntComp%d EnergyPotComp%d EnergyKinComp%d ",i+1,i+1,i+1); #ifdef COOLING fprintf(FdEnergy,"EnergyRadSphComp%d ",i+1); #endif #ifdef MULTIPHASE fprintf(FdEnergy,"EnergyRadStickyComp%d ",i+1); #endif #ifdef FEEDBACK_WIND fprintf(FdEnergy,"EnergyFeedbackWindComp%d ",i+1); #endif #ifdef BUBBLES fprintf(FdEnergy,"EnergyBubblesComp%d ",i+1); #endif #ifdef CHIMIE_THERMAL_FEEDBACK fprintf(FdEnergy,"EnergyThermalFeedbackComp%d ",i+1); #endif #ifdef CHIMIE_KINETIC_FEEDBACK fprintf(FdEnergy,"EnergyKineticFeedbackComp%d ",i+1); #endif } for (i=0;i<6;i++) fprintf(FdEnergy,"MassComp%d ",i+1); /* return */ fprintf(FdEnergy,"\n"); fflush(FdEnergy); } } #endif #ifdef SYSTEMSTATISTICS sprintf(buf, "%s%s", All.OutputDir, All.SystemFile); if(!(FdSystem = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif sprintf(buf, "%s%s", All.OutputDir, All.TimingsFile); if(!(FdTimings = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #ifdef FORCETEST if(RestartFlag == 0 || RestartFlag == 2) { sprintf(buf, "%s%s", All.OutputDir, "forcetest.txt"); if(!(FdForceTest = fopen(buf, "w"))) { printf("error in opening file '%s'\n", buf); endrun(1); } fclose(FdForceTest); } #endif #ifdef SFR sprintf(buf, "%s%s", All.OutputDir, All.SfrFile); if(!(FdSfr = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif #ifdef CHIMIE sprintf(buf, "%s%s", All.OutputDir, All.ChimieFile); if(!(FdChimie = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif #ifdef MULTIPHASE sprintf(buf, "%s%s", All.OutputDir, All.PhaseFile); if(!(FdPhase = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } sprintf(buf, "%s%s", All.OutputDir, All.StickyFile); if(!(FdSticky = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif #ifdef AGN_ACCRETION sprintf(buf, "%s%s", All.OutputDir, All.AccretionFile); if(!(FdAccretion = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif #ifdef BONDI_ACCRETION sprintf(buf, "%s%s", All.OutputDir, All.BondiFile); if(!(FdBondi = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif #ifdef BUBBLES sprintf(buf, "%s%s", All.OutputDir, All.BubbleFile); if(!(FdBubble = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif #ifdef GAS_ACCRETION sprintf(buf, "%s%s", All.OutputDir, All.GasAccretionFile); if(!(FdGasAccretion = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif #ifdef PERIODICOUTER sprintf(buf, "%s%s", All.OutputDir, All.TraceFile); if(!(FdTrace = fopen(buf, mode))) { printf("error in opening file '%s'\n", buf); endrun(1); } #endif } /*! This function closes the global log-files. */ void close_outputfiles(void) { /* for this kind of log, all tasks write its own file */ #ifdef CHIMIE #ifdef CHIMIE_STATS fclose(FdChimieStatsSNs); fclose(FdChimieStatsGas); #endif #ifdef FOF fclose(FdFOF_Chimie); #endif #endif if(ThisTask != 0) /* only the root processor writes to the log files */ return; fclose(FdCPU); fclose(FdInfo); fclose(FdLog); fclose(FdEnergy); #ifdef SYSTEMSTATISTICS fclose(FdSystem); #endif fclose(FdTimings); #ifdef FORCETEST fclose(FdForceTest); #endif #ifdef SFR fclose(FdSfr); #endif #ifdef CHIMIE fclose(FdChimie); #endif #ifdef MULTIPHASE fclose(FdPhase); fclose(FdSticky); #endif #ifdef AGN_ACCRETION fclose(FdAccretion); #endif #ifdef BONDI_ACCRETION fclose(FdBondi); #endif #ifdef BUBBLES fclose(FdBubble); #endif #ifdef GAS_ACCRETION fclose(FdGasAccretion); #endif } /*! This function parses the parameterfile in a simple way. Each paramater * is defined by a keyword (`tag'), and can be either of type double, int, * or character string. The routine makes sure that each parameter * appears exactly once in the parameterfile, otherwise error messages are * produced that complain about the missing parameters. */ void read_parameter_file(char *fname) { #define DOUBLE 1 #define STRING 2 #define INT 3 #define MAXTAGS 300 FILE *fd, *fdout; char buf[200], buf1[200], buf2[200], buf3[400]; int i, j, nt; int id[MAXTAGS]; void *addr[MAXTAGS]; char tag[MAXTAGS][50]; int errorFlag = 0; if(sizeof(long long) != 8) { if(ThisTask == 0) printf("\nType `long long' is not 64 bit on this platform. Stopping.\n\n"); endrun(0); } if(sizeof(int) != 4) { if(ThisTask == 0) printf("\nType `int' is not 32 bit on this platform. Stopping.\n\n"); endrun(0); } if(sizeof(float) != 4) { if(ThisTask == 0) printf("\nType `float' is not 32 bit on this platform. Stopping.\n\n"); endrun(0); } if(sizeof(double) != 8) { if(ThisTask == 0) printf("\nType `double' is not 64 bit on this platform. Stopping.\n\n"); endrun(0); } if(ThisTask == 0) /* read parameter file on process 0 */ { nt = 0; strcpy(tag[nt], "InitCondFile"); addr[nt] = All.InitCondFile; id[nt++] = STRING; strcpy(tag[nt], "OutputDir"); addr[nt] = All.OutputDir; id[nt++] = STRING; strcpy(tag[nt], "SnapshotFileBase"); addr[nt] = All.SnapshotFileBase; id[nt++] = STRING; strcpy(tag[nt], "EnergyFile"); addr[nt] = All.EnergyFile; id[nt++] = STRING; #ifdef SYSTEMSTATISTICS strcpy(tag[nt], "SystemFile"); addr[nt] = All.SystemFile; id[nt++] = STRING; #endif strcpy(tag[nt], "CpuFile"); addr[nt] = All.CpuFile; id[nt++] = STRING; #ifdef SFR strcpy(tag[nt], "SfrFile"); addr[nt] = All.SfrFile; id[nt++] = STRING; #endif #ifdef CHIMIE strcpy(tag[nt], "ChimieFile"); addr[nt] = All.ChimieFile; id[nt++] = STRING; #endif #ifdef MULTIPHASE strcpy(tag[nt], "PhaseFile"); addr[nt] = All.PhaseFile; id[nt++] = STRING; strcpy(tag[nt], "StickyFile"); addr[nt] = All.StickyFile; id[nt++] = STRING; #endif #ifdef AGN_ACCRETION strcpy(tag[nt], "AccretionFile"); addr[nt] = All.AccretionFile; id[nt++] = STRING; #endif #ifdef BONDI_ACCRETION strcpy(tag[nt], "BondiFile"); addr[nt] = All.BondiFile; id[nt++] = STRING; #endif #ifdef BUBBLES strcpy(tag[nt], "BubbleFile"); addr[nt] = All.BubbleFile; id[nt++] = STRING; #endif #ifdef GAS_ACCRETION strcpy(tag[nt], "GasAccretionFile"); addr[nt] = All.GasAccretionFile; id[nt++] = STRING; #endif strcpy(tag[nt], "InfoFile"); addr[nt] = All.InfoFile; id[nt++] = STRING; strcpy(tag[nt], "LogFile"); addr[nt] = All.LogFile; id[nt++] = STRING; strcpy(tag[nt], "TimingsFile"); addr[nt] = All.TimingsFile; id[nt++] = STRING; strcpy(tag[nt], "RestartFile"); addr[nt] = All.RestartFile; id[nt++] = STRING; strcpy(tag[nt], "ResubmitCommand"); addr[nt] = All.ResubmitCommand; id[nt++] = STRING; strcpy(tag[nt], "OutputListFilename"); addr[nt] = All.OutputListFilename; id[nt++] = STRING; strcpy(tag[nt], "OutputListOn"); addr[nt] = &All.OutputListOn; id[nt++] = INT; strcpy(tag[nt], "Omega0"); addr[nt] = &All.Omega0; id[nt++] = DOUBLE; strcpy(tag[nt], "OmegaBaryon"); addr[nt] = &All.OmegaBaryon; id[nt++] = DOUBLE; strcpy(tag[nt], "OmegaLambda"); addr[nt] = &All.OmegaLambda; id[nt++] = DOUBLE; strcpy(tag[nt], "HubbleParam"); addr[nt] = &All.HubbleParam; id[nt++] = DOUBLE; #ifdef HUBBLE_PARAM_WHEN_NOT_IN_UNITS strcpy(tag[nt], "HubbleParamNIU"); addr[nt] = &All.HubbleParamNIU; id[nt++] = DOUBLE; #endif strcpy(tag[nt], "BoxSize"); addr[nt] = &All.BoxSize; id[nt++] = DOUBLE; strcpy(tag[nt], "PeriodicBoundariesOn"); addr[nt] = &All.PeriodicBoundariesOn; id[nt++] = INT; strcpy(tag[nt], "TimeOfFirstSnapshot"); addr[nt] = &All.TimeOfFirstSnapshot; id[nt++] = DOUBLE; strcpy(tag[nt], "CpuTimeBetRestartFile"); addr[nt] = &All.CpuTimeBetRestartFile; id[nt++] = DOUBLE; strcpy(tag[nt], "TimeBetStatistics"); addr[nt] = &All.TimeBetStatistics; id[nt++] = DOUBLE; strcpy(tag[nt], "TimeBegin"); addr[nt] = &All.TimeBegin; id[nt++] = DOUBLE; strcpy(tag[nt], "TimeMax"); addr[nt] = &All.TimeMax; id[nt++] = DOUBLE; strcpy(tag[nt], "TimeBetSnapshot"); addr[nt] = &All.TimeBetSnapshot; id[nt++] = DOUBLE; #ifdef SET_SNAPSHOT_FILE_COUNT strcpy(tag[nt], "SnapshotFileCount"); addr[nt] = &All.SnapshotFileCount; id[nt++] = INT; #endif strcpy(tag[nt], "UnitVelocity_in_cm_per_s"); addr[nt] = &All.UnitVelocity_in_cm_per_s; id[nt++] = DOUBLE; strcpy(tag[nt], "UnitLength_in_cm"); addr[nt] = &All.UnitLength_in_cm; id[nt++] = DOUBLE; strcpy(tag[nt], "UnitMass_in_g"); addr[nt] = &All.UnitMass_in_g; id[nt++] = DOUBLE; strcpy(tag[nt], "TreeDomainUpdateFrequency"); addr[nt] = &All.TreeDomainUpdateFrequency; id[nt++] = DOUBLE; strcpy(tag[nt], "ErrTolIntAccuracy"); addr[nt] = &All.ErrTolIntAccuracy; id[nt++] = DOUBLE; strcpy(tag[nt], "ErrTolTheta"); addr[nt] = &All.ErrTolTheta; id[nt++] = DOUBLE; strcpy(tag[nt], "ErrTolForceAcc"); addr[nt] = &All.ErrTolForceAcc; id[nt++] = DOUBLE; strcpy(tag[nt], "MinGasHsmlFractional"); addr[nt] = &All.MinGasHsmlFractional; id[nt++] = DOUBLE; strcpy(tag[nt], "MaxSizeTimestep"); addr[nt] = &All.MaxSizeTimestep; id[nt++] = DOUBLE; strcpy(tag[nt], "MinSizeTimestep"); addr[nt] = &All.MinSizeTimestep; id[nt++] = DOUBLE; strcpy(tag[nt], "MaxRMSDisplacementFac"); addr[nt] = &All.MaxRMSDisplacementFac; id[nt++] = DOUBLE; strcpy(tag[nt], "ArtBulkViscConst"); addr[nt] = &All.ArtBulkViscConst; id[nt++] = DOUBLE; #ifdef ART_CONDUCTIVITY strcpy(tag[nt], "ArtCondConst"); addr[nt] = &All.ArtCondConst; id[nt++] = DOUBLE; strcpy(tag[nt], "ArtCondThreshold"); addr[nt] = &All.ArtCondThreshold; id[nt++] = DOUBLE; #endif #if defined(ART_VISCO_MM)|| defined(ART_VISCO_RO) || defined(ART_VISCO_CD) strcpy(tag[nt], "ArtBulkViscConstMin"); addr[nt] = &All.ArtBulkViscConstMin; id[nt++] = DOUBLE; strcpy(tag[nt], "ArtBulkViscConstMax"); addr[nt] = &All.ArtBulkViscConstMax; id[nt++] = DOUBLE; strcpy(tag[nt], "ArtBulkViscConstL"); addr[nt] = &All.ArtBulkViscConstL; id[nt++] = DOUBLE; #endif #if METAL_DIFFUSION strcpy(tag[nt], "MetalDiffusionConst"); addr[nt] = &All.MetalDiffusionConst; id[nt++] = DOUBLE; #endif #ifdef AB_TURB strcpy(tag[nt], "ST_decay"); addr[nt] = &All.StDecay; id[nt++] = DOUBLE; strcpy(tag[nt], "ST_energy"); addr[nt] = &All.StEnergy; id[nt++] = DOUBLE; strcpy(tag[nt], "ST_DtFreq"); addr[nt] = &All.StDtFreq; id[nt++] = DOUBLE; strcpy(tag[nt], "ST_Kmin"); addr[nt] = &All.StKmin; id[nt++] = DOUBLE; strcpy(tag[nt], "ST_Kmax"); addr[nt] = &All.StKmax; id[nt++] = DOUBLE; strcpy(tag[nt], "ST_SolWeight"); addr[nt] = &All.StSolWeight; id[nt++] = DOUBLE; strcpy(tag[nt], "ST_AmplFac"); addr[nt] = &All.StAmplFac; id[nt++] = DOUBLE; strcpy(tag[nt], "ST_SpectForm"); addr[nt] = &All.StSpectForm; id[nt++] = INT; strcpy(tag[nt], "ST_Seed"); addr[nt] = &All.StSeed; id[nt++] = INT; #endif #ifdef SYNCHRONIZE_NGB_TIMESTEP strcpy(tag[nt], "NgbFactorTimestep"); addr[nt] = &All.NgbFactorTimestep; id[nt++] = INT; #endif strcpy(tag[nt], "CourantFac"); addr[nt] = &All.CourantFac; id[nt++] = DOUBLE; strcpy(tag[nt], "DesNumNgb"); addr[nt] = &All.DesNumNgb; id[nt++] = DOUBLE; strcpy(tag[nt], "MaxNumNgbDeviation"); addr[nt] = &All.MaxNumNgbDeviation; id[nt++] = DOUBLE; strcpy(tag[nt], "ComovingIntegrationOn"); addr[nt] = &All.ComovingIntegrationOn; id[nt++] = INT; strcpy(tag[nt], "ICFormat"); addr[nt] = &All.ICFormat; id[nt++] = INT; strcpy(tag[nt], "SnapFormat"); addr[nt] = &All.SnapFormat; id[nt++] = INT; strcpy(tag[nt], "NumFilesPerSnapshot"); addr[nt] = &All.NumFilesPerSnapshot; id[nt++] = INT; strcpy(tag[nt], "NumFilesWrittenInParallel"); addr[nt] = &All.NumFilesWrittenInParallel; id[nt++] = INT; strcpy(tag[nt], "ResubmitOn"); addr[nt] = &All.ResubmitOn; id[nt++] = INT; strcpy(tag[nt], "TypeOfTimestepCriterion"); addr[nt] = &All.TypeOfTimestepCriterion; id[nt++] = INT; strcpy(tag[nt], "TypeOfOpeningCriterion"); addr[nt] = &All.TypeOfOpeningCriterion; id[nt++] = INT; strcpy(tag[nt], "TimeLimitCPU"); addr[nt] = &All.TimeLimitCPU; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningHalo"); addr[nt] = &All.SofteningHalo; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningDisk"); addr[nt] = &All.SofteningDisk; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningBulge"); addr[nt] = &All.SofteningBulge; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningGas"); addr[nt] = &All.SofteningGas; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningStars"); addr[nt] = &All.SofteningStars; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningBndry"); addr[nt] = &All.SofteningBndry; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningHaloMaxPhys"); addr[nt] = &All.SofteningHaloMaxPhys; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningDiskMaxPhys"); addr[nt] = &All.SofteningDiskMaxPhys; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningBulgeMaxPhys"); addr[nt] = &All.SofteningBulgeMaxPhys; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningGasMaxPhys"); addr[nt] = &All.SofteningGasMaxPhys; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningStarsMaxPhys"); addr[nt] = &All.SofteningStarsMaxPhys; id[nt++] = DOUBLE; strcpy(tag[nt], "SofteningBndryMaxPhys"); addr[nt] = &All.SofteningBndryMaxPhys; id[nt++] = DOUBLE; strcpy(tag[nt], "BufferSize"); addr[nt] = &All.BufferSize; id[nt++] = INT; strcpy(tag[nt], "PartAllocFactor"); addr[nt] = &All.PartAllocFactor; id[nt++] = DOUBLE; strcpy(tag[nt], "TreeAllocFactor"); addr[nt] = &All.TreeAllocFactor; id[nt++] = DOUBLE; #ifdef SFR strcpy(tag[nt], "StarsAllocFactor"); addr[nt] = &All.StarsAllocFactor; id[nt++] = DOUBLE; #endif strcpy(tag[nt], "GravityConstantInternal"); addr[nt] = &All.GravityConstantInternal; id[nt++] = DOUBLE; strcpy(tag[nt], "InitGasTemp"); addr[nt] = &All.InitGasTemp; id[nt++] = DOUBLE; strcpy(tag[nt], "MinGasTemp"); addr[nt] = &All.MinGasTemp; id[nt++] = DOUBLE; #ifdef RANDOMSEED_AS_PARAMETER strcpy(tag[nt], "RandomSeed"); addr[nt] = &All.RandomSeed; id[nt++] = INT; #endif #ifdef COOLING strcpy(tag[nt], "CoolingFile"); addr[nt] = All.CoolingFile; id[nt++] = STRING; #ifdef COOLING_WIERSMA strcpy(tag[nt], "CoolingDirectory"); addr[nt] = All.CoolingDirectory; id[nt++] = STRING; #endif #ifdef COOLING_GRACKLE strcpy(tag[nt], "GrackleCloudyTable"); addr[nt] = All.GrackleCloudyTable; id[nt++] = STRING; strcpy(tag[nt], "GrackleUVbackground"); addr[nt] = &All.GrackleUVbackground; id[nt++] = INT; strcpy(tag[nt], "GrackleRedshift"); addr[nt] = &All.GrackleRedshift; id[nt++] = DOUBLE; #ifdef COOLING_GRACKLE_H_SSHIELDING strcpy(tag[nt], "GrackleHSShieldingDensityThreshold"); addr[nt] = &All.GrackleHSShieldingDensityThreshold; id[nt++] = DOUBLE; #endif #endif strcpy(tag[nt], "CutofCoolingTemperature"); addr[nt] = &All.CutofCoolingTemperature; id[nt++] = DOUBLE; strcpy(tag[nt], "InitGasMetallicity"); addr[nt] = &All.InitGasMetallicity; id[nt++] = DOUBLE; strcpy(tag[nt], "CoolingType"); addr[nt] = &All.CoolingType; id[nt++] = DOUBLE; #endif #ifdef CHIMIE strcpy(tag[nt], "ChimieNumberOfParameterFiles"); addr[nt] = &All.ChimieNumberOfParameterFiles; id[nt++] = INT; strcpy(tag[nt], "ChimieParameterFile"); addr[nt] = All.ChimieParameterFile; id[nt++] = STRING; strcpy(tag[nt], "ChimieDesNumNgb"); addr[nt] = &All.ChimieDesNumNgb; id[nt++] = DOUBLE; strcpy(tag[nt], "ChimieMaxNumNgbDeviation"); addr[nt] = &All.ChimieMaxNumNgbDeviation; id[nt++] = DOUBLE; strcpy(tag[nt], "ChimieSupernovaEnergy"); addr[nt] = &All.ChimieSupernovaEnergy; id[nt++] = DOUBLE; strcpy(tag[nt], "ChimieKineticFeedbackFraction"); addr[nt] = &All.ChimieKineticFeedbackFraction; id[nt++] = DOUBLE; strcpy(tag[nt], "ChimieWindSpeed"); addr[nt] = &All.ChimieWindSpeed; id[nt++] = DOUBLE; strcpy(tag[nt], "ChimieWindTime"); addr[nt] = &All.ChimieWindTime; id[nt++] = DOUBLE; strcpy(tag[nt], "ChimieSNIaThermalTime"); addr[nt] = &All.ChimieSNIaThermalTime; id[nt++] = DOUBLE; strcpy(tag[nt], "ChimieSNIIThermalTime"); addr[nt] = &All.ChimieSNIIThermalTime; id[nt++] = DOUBLE; strcpy(tag[nt], "ChimieMaxSizeTimestep"); addr[nt] = &All.ChimieMaxSizeTimestep; id[nt++] = DOUBLE; #ifdef CHIMIE_TIMEBET strcpy(tag[nt], "ChimieTimeBetChimie"); addr[nt] = &All.ChimieTimeBetChimie; id[nt++] = DOUBLE; #endif #ifdef CHIMIE_ONE_SN_ONLY strcpy(tag[nt], "ChimieOneSNMass"); addr[nt] = &All.ChimieOneSNMass; id[nt++] = DOUBLE; #endif #if CHIMIE_EJECTA_RADIUS == 1 strcpy(tag[nt], "ChimieEjectaRadius"); addr[nt] = &All.ChimieEjectaRadius; id[nt++] = DOUBLE; #endif #endif #if defined (HEATING_PE) strcpy(tag[nt], "HeatingPeElectronFraction"); addr[nt] = &All.HeatingPeElectronFraction; id[nt++] = DOUBLE; #endif #if defined (HEATING_PE) || defined (STELLAR_FLUX) || defined (EXTERNAL_FLUX) strcpy(tag[nt], "HeatingPeSolarEnergyDensity"); addr[nt] = &All.HeatingPeSolarEnergyDensity; id[nt++] = DOUBLE; #endif #if defined (HEATING_PE) || defined (STELLAR_FLUX) strcpy(tag[nt], "HeatingPeLMRatioGas"); addr[nt] = &All.HeatingPeLMRatioGas; id[nt++] = DOUBLE; strcpy(tag[nt], "HeatingPeLMRatioHalo"); addr[nt] = &All.HeatingPeLMRatioHalo; id[nt++] = DOUBLE; strcpy(tag[nt], "HeatingPeLMRatioDisk"); addr[nt] = &All.HeatingPeLMRatioDisk; id[nt++] = DOUBLE; strcpy(tag[nt], "HeatingPeLMRatioBulge"); addr[nt] = &All.HeatingPeLMRatioBulge; id[nt++] = DOUBLE; strcpy(tag[nt], "HeatingPeLMRatioStars"); addr[nt] = &All.HeatingPeLMRatioStars; id[nt++] = DOUBLE; strcpy(tag[nt], "HeatingPeLMRatioBndry"); addr[nt] = &All.HeatingPeLMRatioBndry; id[nt++] = DOUBLE; #endif #ifdef EXTERNAL_FLUX strcpy(tag[nt], "HeatingExternalFLuxEnergyDensity"); addr[nt] = &All.HeatingExternalFLuxEnergyDensity; id[nt++] = DOUBLE; #endif #ifdef MULTIPHASE strcpy(tag[nt], "CriticalTemperature"); addr[nt] = &All.CriticalTemperature; id[nt++] = DOUBLE; strcpy(tag[nt], "CriticalNonCollisionalTemperature"); addr[nt] = &All.CriticalNonCollisionalTemperature; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyUseGridForCollisions"); addr[nt] = &All.StickyUseGridForCollisions; id[nt++] = INT; strcpy(tag[nt], "StickyTime"); addr[nt] = &All.StickyTime; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyCollisionTime"); addr[nt] = &All.StickyCollisionTime; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyIdleTime"); addr[nt] = &All.StickyIdleTime; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyMinVelocity"); addr[nt] = &All.StickyMinVelocity; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyMaxVelocity"); addr[nt] = &All.StickyMaxVelocity; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyBetaR"); addr[nt] = &All.StickyBetaR; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyBetaT"); addr[nt] = &All.StickyBetaT; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyGridNx"); addr[nt] = &All.StickyGridNx; id[nt++] = INT; strcpy(tag[nt], "StickyGridNy"); addr[nt] = &All.StickyGridNy; id[nt++] = INT; strcpy(tag[nt], "StickyGridNz"); addr[nt] = &All.StickyGridNz; id[nt++] = INT; strcpy(tag[nt], "StickyGridXmin"); addr[nt] = &All.StickyGridXmin; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyGridXmax"); addr[nt] = &All.StickyGridXmax; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyGridYmin"); addr[nt] = &All.StickyGridYmin; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyGridYmax"); addr[nt] = &All.StickyGridYmax; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyGridZmin"); addr[nt] = &All.StickyGridZmin; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyGridZmax"); addr[nt] = &All.StickyGridZmax; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyDensity"); addr[nt] = &All.StickyDensity; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyDensityPower"); addr[nt] = &All.StickyDensityPower; id[nt++] = DOUBLE; strcpy(tag[nt], "StickyRsphFact"); addr[nt] = &All.StickyRsphFact; id[nt++] = DOUBLE; #ifdef COLDGAS_CYCLE strcpy(tag[nt], "ColdGasCycleTransitionTime"); addr[nt] = &All.ColdGasCycleTransitionTime; id[nt++] = DOUBLE; strcpy(tag[nt], "ColdGasCycleTransitionParameter"); addr[nt] = &All.ColdGasCycleTransitionParameter; id[nt++] = DOUBLE; #endif #endif #ifdef JEANS_PRESSURE_FLOOR strcpy(tag[nt], "JeansMassFactor"); addr[nt] = &All.JeansMassFactor; id[nt++] = DOUBLE; #endif #ifdef OUTERPOTENTIAL #ifdef NFW strcpy(tag[nt], "HaloConcentration"); addr[nt] = &All.HaloConcentration; id[nt++] = DOUBLE; strcpy(tag[nt], "HaloMass"); addr[nt] = &All.HaloMass; id[nt++] = DOUBLE; strcpy(tag[nt], "GasMassFraction"); addr[nt] = &All.GasMassFraction; id[nt++] = DOUBLE; #endif #ifdef PLUMMER strcpy(tag[nt], "PlummerMass"); addr[nt] = &All.PlummerMass; id[nt++] = DOUBLE; strcpy(tag[nt], "PlummerSoftenning"); addr[nt] = &All.PlummerSoftenning; id[nt++] = DOUBLE; #endif #ifdef HOMOSPHERE strcpy(tag[nt], "HomosphereMass"); addr[nt] = &All.HomosphereMass; id[nt++] = DOUBLE; strcpy(tag[nt], "HomosphereMaxRadius"); addr[nt] = &All.HomosphereMaxRadius; id[nt++] = DOUBLE; #endif #ifdef MIYAMOTONAGAI strcpy(tag[nt], "MiyamotoNagaiMass"); addr[nt] = &All.MiyamotoNagaiMass; id[nt++] = DOUBLE; strcpy(tag[nt], "MiyamotoNagaiHr"); addr[nt] = &All.MiyamotoNagaiHr; id[nt++] = DOUBLE; strcpy(tag[nt], "MiyamotoNagaiHz"); addr[nt] = &All.MiyamotoNagaiHz; id[nt++] = DOUBLE; #endif #ifdef PISOTHERM strcpy(tag[nt], "Rho0"); addr[nt] = &All.Rho0; id[nt++] = DOUBLE; strcpy(tag[nt], "Rc"); addr[nt] = &All.Rc; id[nt++] = DOUBLE; strcpy(tag[nt], "GasMassFraction"); addr[nt] = &All.GasMassFraction; id[nt++] = DOUBLE; #endif #ifdef CORIOLIS strcpy(tag[nt], "CoriolisOmegaX0"); addr[nt] = &All.CoriolisOmegaX0; id[nt++] = DOUBLE; strcpy(tag[nt], "CoriolisOmegaY0"); addr[nt] = &All.CoriolisOmegaY0; id[nt++] = DOUBLE; strcpy(tag[nt], "CoriolisOmegaZ0"); addr[nt] = &All.CoriolisOmegaZ0; id[nt++] = DOUBLE; #endif #endif #ifdef SFR strcpy(tag[nt], "StarFormationNStarsFromGas"); addr[nt] = &All.StarFormationNStarsFromGas; id[nt++] = INT; strcpy(tag[nt], "StarFormationMgMsFraction"); addr[nt] = &All.StarFormationMgMsFraction; id[nt++] = DOUBLE; strcpy(tag[nt], "StarFormationStarMass"); addr[nt] = &All.StarFormationStarMass; id[nt++] = DOUBLE; strcpy(tag[nt], "StarFormationType"); addr[nt] = &All.StarFormationType; id[nt++] = INT; strcpy(tag[nt], "StarFormationCstar"); addr[nt] = &All.StarFormationCstar; id[nt++] = DOUBLE; strcpy(tag[nt], "StarFormationTime"); addr[nt] = &All.StarFormationTime; id[nt++] = DOUBLE; strcpy(tag[nt], "StarFormationDensity"); addr[nt] = &All.StarFormationDensity; id[nt++] = DOUBLE; strcpy(tag[nt], "StarFormationTemperature"); addr[nt] = &All.StarFormationTemperature; id[nt++] = DOUBLE; #ifdef SFR_USE_JEANS strcpy(tag[nt], "StarformationJeansMassFactor"); addr[nt] = &All.StarformationJeansMassFactor; id[nt++] = DOUBLE; strcpy(tag[nt], "StarformationSofteningMaxPhys"); addr[nt] = &All.StarformationSofteningMaxPhys; id[nt++] = DOUBLE; strcpy(tag[nt], "StarformationSoftening"); addr[nt] = &All.StarformationSoftening; id[nt++] = DOUBLE; #endif #endif #ifdef FOF strcpy(tag[nt], "FoF_Density"); addr[nt] = &All.FoF_Density; id[nt++] = DOUBLE; strcpy(tag[nt], "FoF_ThresholdDensityFactor"); addr[nt] = &All.FoF_ThresholdDensityFactor; id[nt++] = DOUBLE; strcpy(tag[nt], "FoF_MinHeadDensityFactor"); addr[nt] = &All.FoF_MinHeadDensityFactor; id[nt++] = DOUBLE; strcpy(tag[nt], "FoF_MinGroupMembers"); addr[nt] = &All.FoF_MinGroupMembers; id[nt++] = INT; strcpy(tag[nt], "FoF_MinGroupMass"); addr[nt] = &All.FoF_MinGroupMass; id[nt++] = DOUBLE; strcpy(tag[nt], "FoF_VirialFractionThreshold"); addr[nt] = &All.FoF_VirialFractionThreshold; id[nt++] = DOUBLE; strcpy(tag[nt], "FoF_HsmlSearchRadiusFactor"); addr[nt] = &All.FoF_HsmlSearchRadiusFactor; id[nt++] = DOUBLE; strcpy(tag[nt], "FoF_HsmlMaxDistFactor"); addr[nt] = &All.FoF_HsmlMaxDistFactor; id[nt++] = DOUBLE; strcpy(tag[nt], "FoF_TimeBetFoF"); addr[nt] = &All.FoF_TimeBetFoF; id[nt++] = DOUBLE; strcpy(tag[nt], "FoF_SnapshotFileBase"); addr[nt] = All.FoF_SnapshotFileBase; id[nt++] = STRING; strcpy(tag[nt], "FoF_IMFSnapshotFileBase"); addr[nt] = All.FoF_IMFSnapshotFileBase; id[nt++] = STRING; strcpy(tag[nt], "FoF_StarFormationType"); addr[nt] = &All.FoF_StarFormationType; id[nt++] = INT; #ifdef CHIMIE strcpy(tag[nt], "FoF_ChimieFile"); addr[nt] = All.FoF_ChimieFile; id[nt++] = STRING; #endif #endif #ifdef FEEDBACK strcpy(tag[nt], "SupernovaEgySpecPerMassUnit"); addr[nt] = &All.SupernovaEgySpecPerMassUnit; id[nt++] = DOUBLE; strcpy(tag[nt], "SupernovaFractionInEgyKin"); addr[nt] = &All.SupernovaFractionInEgyKin; id[nt++] = DOUBLE; strcpy(tag[nt], "SupernovaTime"); addr[nt] = &All.SupernovaTime; id[nt++] = DOUBLE; #endif #ifdef FEEDBACK_WIND strcpy(tag[nt], "SupernovaWindEgySpecPerMassUnit"); addr[nt] = &All.SupernovaWindEgySpecPerMassUnit; id[nt++] = DOUBLE; strcpy(tag[nt], "SupernovaWindFractionInEgyKin"); addr[nt] = &All.SupernovaWindFractionInEgyKin; id[nt++] = DOUBLE; strcpy(tag[nt], "SupernovaWindParameter"); addr[nt] = &All.SupernovaWindParameter; id[nt++] = DOUBLE; strcpy(tag[nt], "SupernovaWindIntAccuracy"); addr[nt] = &All.SupernovaWindIntAccuracy; id[nt++] = DOUBLE; #endif #ifdef AGN_ACCRETION strcpy(tag[nt], "TimeBetAccretion"); addr[nt] = &All.TimeBetAccretion; id[nt++] = DOUBLE; strcpy(tag[nt], "AccretionRadius"); addr[nt] = &All.AccretionRadius; id[nt++] = DOUBLE; strcpy(tag[nt], "AGNFactor"); addr[nt] = &All.AGNFactor; id[nt++] = DOUBLE; strcpy(tag[nt], "MinMTotInRa"); addr[nt] = &All.MinMTotInRa; id[nt++] = DOUBLE; #endif #ifdef BUBBLES strcpy(tag[nt], "BubblesDelta"); addr[nt] = &All.BubblesDelta; id[nt++] = DOUBLE; strcpy(tag[nt], "BubblesAlpha"); addr[nt] = &All.BubblesAlpha; id[nt++] = DOUBLE; strcpy(tag[nt], "BubblesRadiusFactor"); addr[nt] = &All.BubblesRadiusFactor; id[nt++] = DOUBLE; strcpy(tag[nt], "BubblesInitFile"); addr[nt] = All.BubblesInitFile; id[nt++] = STRING; #endif #ifdef AGN_HEATING strcpy(tag[nt], "AGNHeatingPower"); addr[nt] = &All.AGNHeatingPower; id[nt++] = DOUBLE; strcpy(tag[nt], "AGNHeatingRmax"); addr[nt] = &All.AGNHeatingRmax; id[nt++] = DOUBLE; #endif #ifdef BONDI_ACCRETION strcpy(tag[nt], "BondiEfficiency"); addr[nt] = &All.BondiEfficiency; id[nt++] = DOUBLE; strcpy(tag[nt], "BondiBlackHoleMass"); addr[nt] = &All.BondiBlackHoleMass; id[nt++] = DOUBLE; strcpy(tag[nt], "BondiHsmlFactor"); addr[nt] = &All.BondiHsmlFactor; id[nt++] = DOUBLE; strcpy(tag[nt], "BondiTimeBet"); addr[nt] = &All.BondiTimeBet; id[nt++] = DOUBLE; #endif #ifdef PERIODICOUTER /*Trace Output file*/ strcpy(tag[nt], "TraceFile"); addr[nt] = All.TraceFile; id[nt++] = STRING; /*External position */ strcpy(tag[nt],"TracePosX"); addr[nt] = &All.TracePos[0]; id[nt++] = DOUBLE; strcpy(tag[nt],"TracePosY"); addr[nt] = &All.TracePos[1]; id[nt++] = DOUBLE; strcpy(tag[nt],"TracePosZ"); addr[nt] = &All.TracePos[2]; id[nt++] = DOUBLE; /*Box Velocity*/ strcpy(tag[nt],"TraceVelX"); addr[nt] = &All.TraceVel[0]; id[nt++] = DOUBLE; strcpy(tag[nt],"TraceVelY"); addr[nt] = &All.TraceVel[1]; id[nt++] = DOUBLE; strcpy(tag[nt],"TraceVelZ"); addr[nt] = &All.TraceVel[2]; id[nt++] = DOUBLE; /*Inertial Frame*/ strcpy(tag[nt],"InertialV"); addr[nt] = &All.InertialV; id[nt++] = INT; #ifndef TRACE_ACC /*Internal trace particle position*/ strcpy(tag[nt],"TracePeriodX"); addr[nt] = &All.TracePeriodPos[0]; id[nt++] = DOUBLE; strcpy(tag[nt],"TracePeriodY"); addr[nt] = &All.TracePeriodPos[1]; id[nt++] = DOUBLE; strcpy(tag[nt],"TracePeriodZ"); addr[nt] = &All.TracePeriodPos[2]; id[nt++] = DOUBLE; #endif #endif #ifdef HOT_HALO strcpy(tag[nt],"HaloT"); addr[nt] = &All.HaloT; id[nt++] = DOUBLE; strcpy(tag[nt],"HaloPMass"); addr[nt] = &All.HaloPartMass; id[nt++] = DOUBLE; strcpy(tag[nt],"HaloScale"); addr[nt] = &All.HaloScaleFactor; id[nt++] = DOUBLE; #endif if((fd = fopen(fname, "r"))) { sprintf(buf, "%s%s", fname, "-usedvalues"); if(!(fdout = fopen(buf, "w"))) { printf("error opening file '%s' \n", buf); errorFlag = 1; } else { while(!feof(fd)) { *buf = 0; fgets(buf, 200, fd); if(sscanf(buf, "%s%s%s", buf1, buf2, buf3) < 2) continue; if(buf1[0] == '%') continue; for(i = 0, j = -1; i < nt; i++) if(strcmp(buf1, tag[i]) == 0) { j = i; tag[i][0] = 0; break; } if(j >= 0) { switch (id[j]) { case DOUBLE: *((double *) addr[j]) = atof(buf2); fprintf(fdout, "%-35s%g\n", buf1, *((double *) addr[j])); break; case STRING: strcpy(addr[j], buf2); fprintf(fdout, "%-35s%s\n", buf1, buf2); break; case INT: *((int *) addr[j]) = atoi(buf2); fprintf(fdout, "%-35s%d\n", buf1, *((int *) addr[j])); break; } } else { fprintf(stdout, "Error in file %s: Tag '%s' not allowed or multiple defined.\n", fname, buf1); errorFlag = 1; } } fclose(fd); fclose(fdout); i = strlen(All.OutputDir); if(i > 0) if(All.OutputDir[i - 1] != '/') strcat(All.OutputDir, "/"); /* copy parameters-usedvalues file*/ sprintf(buf1, "%s%s", fname, "-usedvalues"); sprintf(buf2, "%s%s", All.OutputDir, "parameters-usedvalues"); fd = fopen(buf1,"r"); fdout = fopen(buf2,"w"); while(1) { fgets(buf, 200, fd); if (feof(fd)) break; fprintf(fdout, buf, 200); } fclose(fd); fclose(fdout); } } else { printf("\nParameter file %s not found.\n\n", fname); errorFlag = 2; } if(errorFlag != 2) for(i = 0; i < nt; i++) { if(*tag[i]) { printf("Error. I miss a value for tag '%s' in parameter file '%s'.\n", tag[i], fname); errorFlag = 1; } } if(All.OutputListOn && errorFlag == 0) errorFlag += read_outputlist(All.OutputListFilename); else All.OutputListLength = 0; } MPI_Bcast(&errorFlag, 1, MPI_INT, 0, MPI_COMM_WORLD); if(errorFlag) { MPI_Finalize(); exit(0); } /* now communicate the relevant parameters to the other processes */ MPI_Bcast(&All, sizeof(struct global_data_all_processes), MPI_BYTE, 0, MPI_COMM_WORLD); if(All.NumFilesWrittenInParallel < 1) { if(ThisTask == 0) printf("NumFilesWrittenInParallel MUST be at least 1\n"); endrun(0); } if(All.NumFilesWrittenInParallel > NTask) { if(ThisTask == 0) printf("NumFilesWrittenInParallel MUST be smaller than number of processors\n"); endrun(0); } #ifdef PERIODIC if(All.PeriodicBoundariesOn == 0) { if(ThisTask == 0) { printf("Code was compiled with periodic boundary conditions switched on.\n"); printf("You must set `PeriodicBoundariesOn=1', or recompile the code.\n"); } endrun(0); } #else if(All.PeriodicBoundariesOn == 1) { if(ThisTask == 0) { printf("Code was compiled with periodic boundary conditions switched off.\n"); printf("You must set `PeriodicBoundariesOn=0', or recompile the code.\n"); } endrun(0); } #endif if(All.TypeOfTimestepCriterion >= 1) { if(ThisTask == 0) { printf("The specified timestep criterion\n"); printf("is not valid\n"); } endrun(0); } #if defined(LONG_X) || defined(LONG_Y) || defined(LONG_Z) #ifndef NOGRAVITY if(ThisTask == 0) { printf("Code was compiled with LONG_X/Y/Z, but not with NOGRAVITY.\n"); printf("Stretched periodic boxes are not implemented for gravity yet.\n"); } endrun(0); #endif #endif #ifdef SYNCHRONIZE_NGB_TIMESTEP int ti = 1; while((ti != All.NgbFactorTimestep) && (ti!=TIMEBASE)) ti <<= 1; if (ti==TIMEBASE) { if(ThisTask == 0) { printf("\nThe parameter NgbFactorTimestep must be a power of two\n"); printf("NgbFactorTimestep=%d is not valid\n\n",All.NgbFactorTimestep); endrun(7); } } #endif #undef DOUBLE #undef STRING #undef INT #undef MAXTAGS } /*! this function reads a table with a list of desired output times. The * table does not have to be ordered in any way, but may not contain more * than MAXLEN_OUTPUTLIST entries. */ int read_outputlist(char *fname) { FILE *fd; if(!(fd = fopen(fname, "r"))) { printf("can't read output list in file '%s'\n", fname); return 1; } All.OutputListLength = 0; do { if(fscanf(fd, " %lg ", &All.OutputListTimes[All.OutputListLength]) == 1) All.OutputListLength++; else break; } while(All.OutputListLength < MAXLEN_OUTPUTLIST); fclose(fd); printf("\nfound %d times in output-list.\n", All.OutputListLength); return 0; } /*! If a restart from restart-files is carried out where the TimeMax * variable is increased, then the integer timeline needs to be * adjusted. The approach taken here is to reduce the resolution of the * integer timeline by factors of 2 until the new final time can be * reached within TIMEBASE. */ void readjust_timebase(double TimeMax_old, double TimeMax_new) { int i; long long ti_end; if(ThisTask == 0) { printf("\nAll.TimeMax has been changed in the parameterfile\n"); printf("Need to adjust integer timeline\n\n\n"); } if(TimeMax_new < TimeMax_old) { if(ThisTask == 0) printf("\nIt is not allowed to reduce All.TimeMax\n\n"); endrun(556); } if(All.ComovingIntegrationOn) ti_end = log(TimeMax_new / All.TimeBegin) / All.Timebase_interval; else ti_end = (TimeMax_new - All.TimeBegin) / All.Timebase_interval; while(ti_end > TIMEBASE) { All.Timebase_interval *= 2.0; ti_end /= 2; All.Ti_Current /= 2; #ifdef PMGRID All.PM_Ti_begstep /= 2; All.PM_Ti_endstep /= 2; #endif for(i = 0; i < NumPart; i++) { P[i].Ti_begstep /= 2; P[i].Ti_endstep /= 2; } } All.TimeMax = TimeMax_new; }