Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

begrun.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <math.h>
00005 #include <mpi.h>
00006 #include <sys/types.h>
00007 #include <unistd.h>
00008 #include <gsl/gsl_rng.h>
00009 
00010 #include "allvars.h"
00011 #include "proto.h"
00012 
00013 
00028 void begrun(void)
00029 {
00030   struct global_data_all_processes all;
00031 
00032   if(ThisTask == 0)
00033     {
00034       printf("\nThis is Gadget, version `%s'.\n", GADGETVERSION);
00035       printf("\nRunning on %d processors.\n", NTask);
00036     }
00037 
00038   read_parameter_file(ParameterFile);   /* ... read in parameters for this run */
00039 
00040   allocate_commbuffers();       /* ... allocate buffer-memory for particle 
00041                                    exchange during force computation */
00042   set_units();
00043 
00044 #if defined(PERIODIC) && (!defined(PMGRID) || defined(FORCETEST))
00045   ewald_init();
00046 #endif
00047 
00048   open_outputfiles();
00049 
00050   random_generator = gsl_rng_alloc(gsl_rng_ranlxd1);
00051   gsl_rng_set(random_generator, 42);    /* start-up seed */
00052 
00053 #ifdef PMGRID
00054   long_range_init();
00055 #endif
00056 
00057   All.TimeLastRestartFile = CPUThisRun;
00058 
00059   if(RestartFlag == 0 || RestartFlag == 2)
00060     {
00061       set_random_numbers();
00062 
00063       init();                   /* ... read in initial model */
00064     }
00065   else
00066     {
00067       all = All;                /* save global variables. (will be read from restart file) */
00068 
00069       restart(RestartFlag);     /* ... read restart file. Note: This also resets 
00070                                    all variables in the struct `All'. 
00071                                    However, during the run, some variables in the parameter
00072                                    file are allowed to be changed, if desired. These need to 
00073                                    copied in the way below.
00074                                    Note:  All.PartAllocFactor is treated in restart() separately.  
00075                                  */
00076 
00077       All.MinSizeTimestep = all.MinSizeTimestep;
00078       All.MaxSizeTimestep = all.MaxSizeTimestep;
00079       All.BufferSize = all.BufferSize;
00080       All.BunchSizeForce = all.BunchSizeForce;
00081       All.BunchSizeDensity = all.BunchSizeDensity;
00082       All.BunchSizeHydro = all.BunchSizeHydro;
00083       All.BunchSizeDomain = all.BunchSizeDomain;
00084 
00085       All.TimeLimitCPU = all.TimeLimitCPU;
00086       All.ResubmitOn = all.ResubmitOn;
00087       All.TimeBetSnapshot = all.TimeBetSnapshot;
00088       All.TimeBetStatistics = all.TimeBetStatistics;
00089       All.CpuTimeBetRestartFile = all.CpuTimeBetRestartFile;
00090       All.ErrTolIntAccuracy = all.ErrTolIntAccuracy;
00091       All.MaxRMSDisplacementFac = all.MaxRMSDisplacementFac;
00092 
00093       All.ErrTolForceAcc = all.ErrTolForceAcc;
00094 
00095       All.TypeOfTimestepCriterion = all.TypeOfTimestepCriterion;
00096       All.TypeOfOpeningCriterion = all.TypeOfOpeningCriterion;
00097       All.NumFilesWrittenInParallel = all.NumFilesWrittenInParallel;
00098       All.TreeDomainUpdateFrequency = all.TreeDomainUpdateFrequency;
00099 
00100       All.SnapFormat = all.SnapFormat;
00101       All.NumFilesPerSnapshot = all.NumFilesPerSnapshot;
00102       All.MaxNumNgbDeviation = all.MaxNumNgbDeviation;
00103       All.ArtBulkViscConst = all.ArtBulkViscConst;
00104 
00105 
00106       All.OutputListOn = all.OutputListOn;
00107       All.CourantFac = all.CourantFac;
00108 
00109       All.OutputListLength = all.OutputListLength;
00110       memcpy(All.OutputListTimes, all.OutputListTimes, sizeof(double) * All.OutputListLength);
00111 
00112 
00113       strcpy(All.ResubmitCommand, all.ResubmitCommand);
00114       strcpy(All.OutputListFilename, all.OutputListFilename);
00115       strcpy(All.OutputDir, all.OutputDir);
00116       strcpy(All.RestartFile, all.RestartFile);
00117       strcpy(All.EnergyFile, all.EnergyFile);
00118       strcpy(All.InfoFile, all.InfoFile);
00119       strcpy(All.CpuFile, all.CpuFile);
00120       strcpy(All.TimingsFile, all.TimingsFile);
00121       strcpy(All.SnapshotFileBase, all.SnapshotFileBase);
00122 
00123       if(All.TimeMax != all.TimeMax)
00124         readjust_timebase(All.TimeMax, all.TimeMax);
00125     }
00126 
00127 #ifdef PMGRID
00128   long_range_init_regionsize();
00129 #endif
00130 
00131   if(All.ComovingIntegrationOn)
00132     init_drift_table();
00133 
00134   if(RestartFlag == 2)
00135     All.Ti_nextoutput = find_next_outputtime(All.Ti_Current + 1);
00136   else
00137     All.Ti_nextoutput = find_next_outputtime(All.Ti_Current);
00138 
00139 
00140   All.TimeLastRestartFile = CPUThisRun;
00141 }
00142 
00143 
00144 
00145 
00149 void set_units(void)
00150 {
00151   double meanweight;
00152 
00153   All.UnitTime_in_s = All.UnitLength_in_cm / All.UnitVelocity_in_cm_per_s;
00154   All.UnitTime_in_Megayears = All.UnitTime_in_s / SEC_PER_MEGAYEAR;
00155 
00156   if(All.GravityConstantInternal == 0)
00157     All.G = GRAVITY / pow(All.UnitLength_in_cm, 3) * All.UnitMass_in_g * pow(All.UnitTime_in_s, 2);
00158   else
00159     All.G = All.GravityConstantInternal;
00160 
00161   All.UnitDensity_in_cgs = All.UnitMass_in_g / pow(All.UnitLength_in_cm, 3);
00162   All.UnitPressure_in_cgs = All.UnitMass_in_g / All.UnitLength_in_cm / pow(All.UnitTime_in_s, 2);
00163   All.UnitCoolingRate_in_cgs = All.UnitPressure_in_cgs / All.UnitTime_in_s;
00164   All.UnitEnergy_in_cgs = All.UnitMass_in_g * pow(All.UnitLength_in_cm, 2) / pow(All.UnitTime_in_s, 2);
00165 
00166   /* convert some physical input parameters to internal units */
00167 
00168   All.Hubble = HUBBLE * All.UnitTime_in_s;
00169 
00170   if(ThisTask == 0)
00171     {
00172       printf("\nHubble (internal units) = %g\n", All.Hubble);
00173       printf("G (internal units) = %g\n", All.G);
00174       printf("UnitMass_in_g = %g \n", All.UnitMass_in_g);
00175       printf("UnitTime_in_s = %g \n", All.UnitTime_in_s);
00176       printf("UnitVelocity_in_cm_per_s = %g \n", All.UnitVelocity_in_cm_per_s);
00177       printf("UnitDensity_in_cgs = %g \n", All.UnitDensity_in_cgs);
00178       printf("UnitEnergy_in_cgs = %g \n", All.UnitEnergy_in_cgs);
00179       printf("\n");
00180     }
00181 
00182   meanweight = 4.0 / (1 + 3 * HYDROGEN_MASSFRAC);       /* note: we assume neutral gas here */
00183 
00184 #ifdef ISOTHERM_EQS
00185   All.MinEgySpec = 0;
00186 #else
00187   All.MinEgySpec = 1 / meanweight * (1.0 / GAMMA_MINUS1) * (BOLTZMANN / PROTONMASS) * All.MinGasTemp;
00188   All.MinEgySpec *= All.UnitMass_in_g / All.UnitEnergy_in_cgs;
00189 #endif
00190 
00191 }
00192 
00193 
00194 
00199 void open_outputfiles(void)
00200 {
00201   char mode[2], buf[200];
00202 
00203   if(ThisTask != 0)             /* only the root processor writes to the log files */
00204     return;
00205 
00206   if(RestartFlag == 0)
00207     strcpy(mode, "w");
00208   else
00209     strcpy(mode, "a");
00210 
00211 
00212   sprintf(buf, "%s%s", All.OutputDir, All.CpuFile);
00213   if(!(FdCPU = fopen(buf, mode)))
00214     {
00215       printf("error in opening file '%s'\n", buf);
00216       endrun(1);
00217     }
00218 
00219   sprintf(buf, "%s%s", All.OutputDir, All.InfoFile);
00220   if(!(FdInfo = fopen(buf, mode)))
00221     {
00222       printf("error in opening file '%s'\n", buf);
00223       endrun(1);
00224     }
00225 
00226   sprintf(buf, "%s%s", All.OutputDir, All.EnergyFile);
00227   if(!(FdEnergy = fopen(buf, mode)))
00228     {
00229       printf("error in opening file '%s'\n", buf);
00230       endrun(1);
00231     }
00232 
00233   sprintf(buf, "%s%s", All.OutputDir, All.TimingsFile);
00234   if(!(FdTimings = fopen(buf, mode)))
00235     {
00236       printf("error in opening file '%s'\n", buf);
00237       endrun(1);
00238     }
00239 
00240 #ifdef FORCETEST
00241   if(RestartFlag == 0)
00242     {
00243       sprintf(buf, "%s%s", All.OutputDir, "forcetest.txt");
00244       if(!(FdForceTest = fopen(buf, "w")))
00245         {
00246           printf("error in opening file '%s'\n", buf);
00247           endrun(1);
00248         }
00249       fclose(FdForceTest);
00250     }
00251 #endif
00252 }
00253 
00254 
00257 void close_outputfiles(void)
00258 {
00259   if(ThisTask != 0)             /* only the root processor writes to the log files */
00260     return;
00261 
00262   fclose(FdCPU);
00263   fclose(FdInfo);
00264   fclose(FdEnergy);
00265   fclose(FdTimings);
00266 #ifdef FORCETEST
00267   fclose(FdForceTest);
00268 #endif
00269 }
00270 
00271 
00272 
00273 
00280 void read_parameter_file(char *fname)
00281 {
00282 #define DOUBLE 1
00283 #define STRING 2
00284 #define INT 3
00285 #define MAXTAGS 300
00286 
00287   FILE *fd, *fdout;
00288   char buf[200], buf1[200], buf2[200], buf3[400];
00289   int i, j, nt;
00290   int id[MAXTAGS];
00291   void *addr[MAXTAGS];
00292   char tag[MAXTAGS][50];
00293   int  errorFlag = 0;
00294 
00295 
00296   if(sizeof(long long) != 8)
00297     {
00298       if(ThisTask == 0)
00299         printf("\nType `long long' is not 64 bit on this platform. Stopping.\n\n");
00300       endrun(0);
00301     }
00302 
00303   if(sizeof(int) != 4)
00304     {
00305       if(ThisTask == 0)
00306         printf("\nType `int' is not 32 bit on this platform. Stopping.\n\n");
00307       endrun(0);
00308     }
00309 
00310   if(sizeof(float) != 4)
00311     {
00312       if(ThisTask == 0)
00313         printf("\nType `float' is not 32 bit on this platform. Stopping.\n\n");
00314       endrun(0);
00315     }
00316 
00317   if(sizeof(double) != 8)
00318     {
00319       if(ThisTask == 0)
00320         printf("\nType `double' is not 64 bit on this platform. Stopping.\n\n");
00321       endrun(0);
00322     }
00323 
00324 
00325   if(ThisTask == 0)             /* read parameter file on process 0 */
00326     {
00327       nt = 0;
00328 
00329       strcpy(tag[nt], "InitCondFile");
00330       addr[nt] = All.InitCondFile;
00331       id[nt++] = STRING;
00332 
00333       strcpy(tag[nt], "OutputDir");
00334       addr[nt] = All.OutputDir;
00335       id[nt++] = STRING;
00336 
00337       strcpy(tag[nt], "SnapshotFileBase");
00338       addr[nt] = All.SnapshotFileBase;
00339       id[nt++] = STRING;
00340 
00341       strcpy(tag[nt], "EnergyFile");
00342       addr[nt] = All.EnergyFile;
00343       id[nt++] = STRING;
00344 
00345       strcpy(tag[nt], "CpuFile");
00346       addr[nt] = All.CpuFile;
00347       id[nt++] = STRING;
00348 
00349       strcpy(tag[nt], "InfoFile");
00350       addr[nt] = All.InfoFile;
00351       id[nt++] = STRING;
00352 
00353       strcpy(tag[nt], "TimingsFile");
00354       addr[nt] = All.TimingsFile;
00355       id[nt++] = STRING;
00356 
00357       strcpy(tag[nt], "RestartFile");
00358       addr[nt] = All.RestartFile;
00359       id[nt++] = STRING;
00360 
00361       strcpy(tag[nt], "ResubmitCommand");
00362       addr[nt] = All.ResubmitCommand;
00363       id[nt++] = STRING;
00364 
00365       strcpy(tag[nt], "OutputListFilename");
00366       addr[nt] = All.OutputListFilename;
00367       id[nt++] = STRING;
00368 
00369       strcpy(tag[nt], "OutputListOn");
00370       addr[nt] = &All.OutputListOn;
00371       id[nt++] = INT;
00372 
00373       strcpy(tag[nt], "Omega0");
00374       addr[nt] = &All.Omega0;
00375       id[nt++] = DOUBLE;
00376 
00377       strcpy(tag[nt], "OmegaBaryon");
00378       addr[nt] = &All.OmegaBaryon;
00379       id[nt++] = DOUBLE;
00380 
00381       strcpy(tag[nt], "OmegaLambda");
00382       addr[nt] = &All.OmegaLambda;
00383       id[nt++] = DOUBLE;
00384 
00385       strcpy(tag[nt], "HubbleParam");
00386       addr[nt] = &All.HubbleParam;
00387       id[nt++] = DOUBLE;
00388 
00389       strcpy(tag[nt], "BoxSize");
00390       addr[nt] = &All.BoxSize;
00391       id[nt++] = DOUBLE;
00392 
00393       strcpy(tag[nt], "PeriodicBoundariesOn");
00394       addr[nt] = &All.PeriodicBoundariesOn;
00395       id[nt++] = INT;
00396 
00397       strcpy(tag[nt], "TimeOfFirstSnapshot");
00398       addr[nt] = &All.TimeOfFirstSnapshot;
00399       id[nt++] = DOUBLE;
00400 
00401       strcpy(tag[nt], "CpuTimeBetRestartFile");
00402       addr[nt] = &All.CpuTimeBetRestartFile;
00403       id[nt++] = DOUBLE;
00404 
00405       strcpy(tag[nt], "TimeBetStatistics");
00406       addr[nt] = &All.TimeBetStatistics;
00407       id[nt++] = DOUBLE;
00408 
00409       strcpy(tag[nt], "TimeBegin");
00410       addr[nt] = &All.TimeBegin;
00411       id[nt++] = DOUBLE;
00412 
00413       strcpy(tag[nt], "TimeMax");
00414       addr[nt] = &All.TimeMax;
00415       id[nt++] = DOUBLE;
00416 
00417       strcpy(tag[nt], "TimeBetSnapshot");
00418       addr[nt] = &All.TimeBetSnapshot;
00419       id[nt++] = DOUBLE;
00420 
00421       strcpy(tag[nt], "UnitVelocity_in_cm_per_s");
00422       addr[nt] = &All.UnitVelocity_in_cm_per_s;
00423       id[nt++] = DOUBLE;
00424 
00425       strcpy(tag[nt], "UnitLength_in_cm");
00426       addr[nt] = &All.UnitLength_in_cm;
00427       id[nt++] = DOUBLE;
00428 
00429       strcpy(tag[nt], "UnitMass_in_g");
00430       addr[nt] = &All.UnitMass_in_g;
00431       id[nt++] = DOUBLE;
00432 
00433       strcpy(tag[nt], "TreeDomainUpdateFrequency");
00434       addr[nt] = &All.TreeDomainUpdateFrequency;
00435       id[nt++] = DOUBLE;
00436 
00437       strcpy(tag[nt], "ErrTolIntAccuracy");
00438       addr[nt] = &All.ErrTolIntAccuracy;
00439       id[nt++] = DOUBLE;
00440 
00441       strcpy(tag[nt], "ErrTolTheta");
00442       addr[nt] = &All.ErrTolTheta;
00443       id[nt++] = DOUBLE;
00444 
00445       strcpy(tag[nt], "ErrTolForceAcc");
00446       addr[nt] = &All.ErrTolForceAcc;
00447       id[nt++] = DOUBLE;
00448 
00449       strcpy(tag[nt], "MinGasHsmlFractional");
00450       addr[nt] = &All.MinGasHsmlFractional;
00451       id[nt++] = DOUBLE;
00452 
00453       strcpy(tag[nt], "MaxSizeTimestep");
00454       addr[nt] = &All.MaxSizeTimestep;
00455       id[nt++] = DOUBLE;
00456 
00457       strcpy(tag[nt], "MinSizeTimestep");
00458       addr[nt] = &All.MinSizeTimestep;
00459       id[nt++] = DOUBLE;
00460 
00461       strcpy(tag[nt], "MaxRMSDisplacementFac");
00462       addr[nt] = &All.MaxRMSDisplacementFac;
00463       id[nt++] = DOUBLE;
00464 
00465       strcpy(tag[nt], "ArtBulkViscConst");
00466       addr[nt] = &All.ArtBulkViscConst;
00467       id[nt++] = DOUBLE;
00468 
00469       strcpy(tag[nt], "CourantFac");
00470       addr[nt] = &All.CourantFac;
00471       id[nt++] = DOUBLE;
00472 
00473       strcpy(tag[nt], "DesNumNgb");
00474       addr[nt] = &All.DesNumNgb;
00475       id[nt++] = DOUBLE;
00476 
00477       strcpy(tag[nt], "MaxNumNgbDeviation");
00478       addr[nt] = &All.MaxNumNgbDeviation;
00479       id[nt++] = DOUBLE;
00480 
00481       strcpy(tag[nt], "ComovingIntegrationOn");
00482       addr[nt] = &All.ComovingIntegrationOn;
00483       id[nt++] = INT;
00484 
00485       strcpy(tag[nt], "ICFormat");
00486       addr[nt] = &All.ICFormat;
00487       id[nt++] = INT;
00488 
00489       strcpy(tag[nt], "SnapFormat");
00490       addr[nt] = &All.SnapFormat;
00491       id[nt++] = INT;
00492 
00493       strcpy(tag[nt], "NumFilesPerSnapshot");
00494       addr[nt] = &All.NumFilesPerSnapshot;
00495       id[nt++] = INT;
00496 
00497       strcpy(tag[nt], "NumFilesWrittenInParallel");
00498       addr[nt] = &All.NumFilesWrittenInParallel;
00499       id[nt++] = INT;
00500 
00501       strcpy(tag[nt], "ResubmitOn");
00502       addr[nt] = &All.ResubmitOn;
00503       id[nt++] = INT;
00504 
00505       strcpy(tag[nt], "TypeOfTimestepCriterion");
00506       addr[nt] = &All.TypeOfTimestepCriterion;
00507       id[nt++] = INT;
00508 
00509       strcpy(tag[nt], "TypeOfOpeningCriterion");
00510       addr[nt] = &All.TypeOfOpeningCriterion;
00511       id[nt++] = INT;
00512 
00513       strcpy(tag[nt], "TimeLimitCPU");
00514       addr[nt] = &All.TimeLimitCPU;
00515       id[nt++] = DOUBLE;
00516 
00517       strcpy(tag[nt], "SofteningHalo");
00518       addr[nt] = &All.SofteningHalo;
00519       id[nt++] = DOUBLE;
00520 
00521       strcpy(tag[nt], "SofteningDisk");
00522       addr[nt] = &All.SofteningDisk;
00523       id[nt++] = DOUBLE;
00524 
00525       strcpy(tag[nt], "SofteningBulge");
00526       addr[nt] = &All.SofteningBulge;
00527       id[nt++] = DOUBLE;
00528 
00529       strcpy(tag[nt], "SofteningGas");
00530       addr[nt] = &All.SofteningGas;
00531       id[nt++] = DOUBLE;
00532 
00533       strcpy(tag[nt], "SofteningStars");
00534       addr[nt] = &All.SofteningStars;
00535       id[nt++] = DOUBLE;
00536 
00537       strcpy(tag[nt], "SofteningBndry");
00538       addr[nt] = &All.SofteningBndry;
00539       id[nt++] = DOUBLE;
00540 
00541       strcpy(tag[nt], "SofteningHaloMaxPhys");
00542       addr[nt] = &All.SofteningHaloMaxPhys;
00543       id[nt++] = DOUBLE;
00544 
00545       strcpy(tag[nt], "SofteningDiskMaxPhys");
00546       addr[nt] = &All.SofteningDiskMaxPhys;
00547       id[nt++] = DOUBLE;
00548 
00549       strcpy(tag[nt], "SofteningBulgeMaxPhys");
00550       addr[nt] = &All.SofteningBulgeMaxPhys;
00551       id[nt++] = DOUBLE;
00552 
00553       strcpy(tag[nt], "SofteningGasMaxPhys");
00554       addr[nt] = &All.SofteningGasMaxPhys;
00555       id[nt++] = DOUBLE;
00556 
00557       strcpy(tag[nt], "SofteningStarsMaxPhys");
00558       addr[nt] = &All.SofteningStarsMaxPhys;
00559       id[nt++] = DOUBLE;
00560 
00561       strcpy(tag[nt], "SofteningBndryMaxPhys");
00562       addr[nt] = &All.SofteningBndryMaxPhys;
00563       id[nt++] = DOUBLE;
00564 
00565       strcpy(tag[nt], "BufferSize");
00566       addr[nt] = &All.BufferSize;
00567       id[nt++] = INT;
00568 
00569       strcpy(tag[nt], "PartAllocFactor");
00570       addr[nt] = &All.PartAllocFactor;
00571       id[nt++] = DOUBLE;
00572 
00573       strcpy(tag[nt], "TreeAllocFactor");
00574       addr[nt] = &All.TreeAllocFactor;
00575       id[nt++] = DOUBLE;
00576 
00577       strcpy(tag[nt], "GravityConstantInternal");
00578       addr[nt] = &All.GravityConstantInternal;
00579       id[nt++] = DOUBLE;
00580 
00581       strcpy(tag[nt], "InitGasTemp");
00582       addr[nt] = &All.InitGasTemp;
00583       id[nt++] = DOUBLE;
00584 
00585       strcpy(tag[nt], "MinGasTemp");
00586       addr[nt] = &All.MinGasTemp;
00587       id[nt++] = DOUBLE;
00588 
00589       if((fd = fopen(fname, "r")))
00590         {
00591           sprintf(buf, "%s%s", fname, "-usedvalues");
00592           if(!(fdout = fopen(buf, "w")))
00593             {
00594               printf("error opening file '%s' \n", buf);
00595               errorFlag = 1;
00596             }
00597           else
00598             {
00599               while(!feof(fd))
00600                 {
00601                   *buf = 0;
00602                   fgets(buf, 200, fd);
00603                   if(sscanf(buf, "%s%s%s", buf1, buf2, buf3) < 2)
00604                     continue;
00605 
00606                   if(buf1[0] == '%')
00607                     continue;
00608 
00609                   for(i = 0, j = -1; i < nt; i++)
00610                     if(strcmp(buf1, tag[i]) == 0)
00611                       {
00612                         j = i;
00613                         tag[i][0] = 0;
00614                         break;
00615                       }
00616 
00617                   if(j >= 0)
00618                     {
00619                       switch (id[j])
00620                         {
00621                         case DOUBLE:
00622                           *((double *) addr[j]) = atof(buf2);
00623                           fprintf(fdout, "%-35s%g\n", buf1, *((double *) addr[j]));
00624                           break;
00625                         case STRING:
00626                           strcpy(addr[j], buf2);
00627                           fprintf(fdout, "%-35s%s\n", buf1, buf2);
00628                           break;
00629                         case INT:
00630                           *((int *) addr[j]) = atoi(buf2);
00631                           fprintf(fdout, "%-35s%d\n", buf1, *((int *) addr[j]));
00632                           break;
00633                         }
00634                     }
00635                   else
00636                     {
00637                       fprintf(stdout, "Error in file %s:   Tag '%s' not allowed or multiple defined.\n",
00638                               fname, buf1);
00639                       errorFlag = 1;
00640                     }
00641                 }
00642               fclose(fd);
00643               fclose(fdout);
00644 
00645               i = strlen(All.OutputDir);
00646               if(i > 0)
00647                 if(All.OutputDir[i - 1] != '/')
00648                   strcat(All.OutputDir, "/");
00649 
00650               sprintf(buf1, "%s%s", fname, "-usedvalues");
00651               sprintf(buf2, "%s%s", All.OutputDir, "parameters-usedvalues");
00652               sprintf(buf3, "cp %s %s", buf1, buf2);
00653               system(buf3);
00654             }
00655         }
00656       else
00657         {
00658           printf("\nParameter file %s not found.\n\n", fname);
00659           errorFlag = 2;
00660         }
00661 
00662       if(errorFlag != 2)
00663         for(i = 0; i < nt; i++)
00664           {
00665             if(*tag[i])
00666               {
00667                 printf("Error. I miss a value for tag '%s' in parameter file '%s'.\n", tag[i], fname);
00668                 errorFlag = 1;
00669               }
00670           }
00671 
00672       if(All.OutputListOn && errorFlag == 0)
00673         errorFlag += read_outputlist(All.OutputListFilename);
00674       else
00675         All.OutputListLength = 0;
00676     }
00677 
00678   MPI_Bcast(&errorFlag, 1, MPI_INT, 0, MPI_COMM_WORLD);
00679 
00680   if(errorFlag)
00681     {
00682       MPI_Finalize();
00683       exit(0);
00684     }
00685 
00686   /* now communicate the relevant parameters to the other processes */
00687   MPI_Bcast(&All, sizeof(struct global_data_all_processes), MPI_BYTE, 0, MPI_COMM_WORLD);
00688 
00689 
00690   if(All.NumFilesWrittenInParallel < 1)
00691     {
00692       if(ThisTask == 0)
00693         printf("NumFilesWrittenInParallel MUST be at least 1\n");
00694       endrun(0);
00695     }
00696 
00697   if(All.NumFilesWrittenInParallel > NTask)
00698     {
00699       if(ThisTask == 0)
00700         printf("NumFilesWrittenInParallel MUST be smaller than number of processors\n");
00701       endrun(0);
00702     }
00703 
00704 #ifdef PERIODIC
00705   if(All.PeriodicBoundariesOn == 0)
00706     {
00707       if(ThisTask == 0)
00708         {
00709           printf("Code was compiled with periodic boundary conditions switched on.\n");
00710           printf("You must set `PeriodicBoundariesOn=1', or recompile the code.\n");
00711         }
00712       endrun(0);
00713     }
00714 #else
00715   if(All.PeriodicBoundariesOn == 1)
00716     {
00717       if(ThisTask == 0)
00718         {
00719           printf("Code was compiled with periodic boundary conditions switched off.\n");
00720           printf("You must set `PeriodicBoundariesOn=0', or recompile the code.\n");
00721         }
00722       endrun(0);
00723     }
00724 #endif
00725 
00726 
00727   if(All.TypeOfTimestepCriterion >= 1)
00728     {
00729       if(ThisTask == 0)
00730         {
00731           printf("The specified timestep criterion\n");
00732           printf("is not valid\n");
00733         }
00734       endrun(0);
00735     }
00736 
00737 #if defined(LONG_X) ||  defined(LONG_Y) || defined(LONG_Z)
00738 #ifndef NOGRAVITY
00739   if(ThisTask == 0)
00740     {
00741       printf("Code was compiled with LONG_X/Y/Z, but not with NOGRAVITY.\n");
00742       printf("Stretched periodic boxes are not implemented for gravity yet.\n");
00743     }
00744   endrun(0);
00745 #endif
00746 #endif
00747 
00748 #undef DOUBLE
00749 #undef STRING
00750 #undef INT
00751 #undef MAXTAGS
00752 }
00753 
00754 
00759 int read_outputlist(char *fname)
00760 {
00761   FILE *fd;
00762 
00763   if(!(fd = fopen(fname, "r")))
00764     {
00765       printf("can't read output list in file '%s'\n", fname);
00766       return 1;
00767     }
00768 
00769   All.OutputListLength = 0;
00770   do
00771     {
00772       if(fscanf(fd, " %lg ", &All.OutputListTimes[All.OutputListLength]) == 1)
00773         All.OutputListLength++;
00774       else
00775         break;
00776     }
00777   while(All.OutputListLength < MAXLEN_OUTPUTLIST);
00778 
00779   fclose(fd);
00780 
00781   printf("\nfound %d times in output-list.\n", All.OutputListLength);
00782 
00783   return 0;
00784 }
00785 
00786 
00793 void readjust_timebase(double TimeMax_old, double TimeMax_new)
00794 {
00795   int i;
00796   long long ti_end;
00797 
00798   if(ThisTask == 0)
00799     {
00800       printf("\nAll.TimeMax has been changed in the parameterfile\n");
00801       printf("Need to adjust integer timeline\n\n\n");
00802     }
00803 
00804   if(TimeMax_new < TimeMax_old)
00805     {
00806       if(ThisTask == 0)
00807         printf("\nIt is not allowed to reduce All.TimeMax\n\n");
00808       endrun(556);
00809     }
00810 
00811   if(All.ComovingIntegrationOn)
00812     ti_end = log(TimeMax_new / All.TimeBegin) / All.Timebase_interval;
00813   else
00814     ti_end = (TimeMax_new - All.TimeBegin) / All.Timebase_interval;
00815 
00816   while(ti_end > TIMEBASE)
00817     {
00818       All.Timebase_interval *= 2.0;
00819 
00820       ti_end /= 2;
00821       All.Ti_Current /= 2;
00822 
00823 #ifdef PMGRID
00824       All.PM_Ti_begstep /= 2;
00825       All.PM_Ti_endstep /= 2;
00826 #endif
00827 
00828       for(i = 0; i < NumPart; i++)
00829         {
00830           P[i].Ti_begstep /= 2;
00831           P[i].Ti_endstep /= 2;
00832         }
00833     }
00834 
00835   All.TimeMax = TimeMax_new;
00836 }
00837 

Generated on Sun May 22 17:33:28 2005 for GADGET-2 by  doxygen 1.3.9.1