Exemplo n.º 1
0
bool Level::LoadLevelInfo(const char *pszLevelName, IniReader *piniLoaded)
{
    IniReader *pini;

    if (piniLoaded == NULL) {
        pini = LoadIniFile(gpakr, pszLevelName);
        if (pini == NULL) {
            Assert(false);
            return false;
        }
    } else {
        pini = piniLoaded;
    }

    // Get level version

    if (pini->GetPropertyValue("General", "Version", "%d", &m_nVersion) == 0)
        m_nVersion = 0;

    // Get revision #

    if (pini->GetPropertyValue("General", "Revision", "%d", &m_dwRevision) == 0)
        m_dwRevision = 0;

    // Can't run if the level version is newer than what the game supports

    bool fSuccess = true;
    if (m_nVersion > knVersionLevelSupported) {
        fSuccess = false;
        HtMessageBox(kfMbWhiteBorder, "Error", "Newer version of Hostile Takeover required to run this mission.");
    } else {
        // Load General level data

        if (!pini->GetPropertyValue("General", "Title", m_szTitle, sizeof(m_szTitle)))
            strcpy(m_szTitle, "<untitled>");

        m_nPlayersMin = m_nPlayersMax = 0;
        pini->GetPropertyValue("General", "MinPlayers", "%d", &m_nPlayersMin);
        pini->GetPropertyValue("General", "MaxPlayers", "%d", &m_nPlayersMax);

        // Normalize
        if (pszLevelName[0] == 'm' && pszLevelName[1] == '_') {
            if (m_nPlayersMin < 2) {
                m_nPlayersMin = 2;
            }
            if (m_nPlayersMax > 4) {
                m_nPlayersMax = 4;
            }
            if (m_nPlayersMax < m_nPlayersMin) {
                m_nPlayersMax = m_nPlayersMin;
            }
        } else {
            m_nPlayersMin = 1;
            m_nPlayersMax = 1;
        }

        // Read in the side info for each side

        Side side;
        for (side = ksideNeutral; side < kcSides; side++) {
            if (side == ksideNeutral) {
                LoadSideInfo(pini, "sideNeutral", &m_asidi[side]);
            } else {
                char szSideName[] = "side1";
                szSideName[4] = '0' + side;
                LoadSideInfo(pini, szSideName, &m_asidi[side]);
            }
        }

        // If there is no human side, assume it is side 1
        // because gpplrLocal has to be set to something (because our code is intolerant)

        bool fHumanFound = false;
        for (side = ksideNeutral; side < kcSides; side++) {
            if (m_asidi[side].nIntelligence == knIntelligenceHuman)
                fHumanFound = true;
        }
        if (!fHumanFound)
            m_asidi[kside1].nIntelligence = knIntelligenceHuman;
    }

    if (piniLoaded == NULL)
        delete pini;

    return fSuccess;
}
Exemplo n.º 2
0
// Our program entry point
// This entry point is just a wrapper around the evolution routines.
// It sets up the input parameters as well as the output file, and otherwise just calls the routines to run the evolution.
int main(int argc, char* argv[]) {

    int result; // Just a number for return values

    //******************//
    // Input parameters //
    //******************//

	// Read the input parameters file, named "params.ini" by default.
	// If there is a command line argument, assume that it is the filename for the parameters file.
	IniReader inifile;
	if (argc > 1)
		inifile.read(argv[1]);
	else
		inifile.read("params.ini");

	// Values in the ini file can be set using the following command:
    // inifile.setparam("desiredh", "Cosmology", 1);
	// First parameter is the key name, the second is the section name, and the third is the value, either an integer, string or double

    // Set up the cosmological parameters
    Parameters myParams(inifile);

    // Figure out if we're going to postprocess or not
    bool dopostprocess = inifile.getiniBool("postprocess", false, "Single");

	// Turn off post-processing for now
	if(dopostprocess)
		dopostprocess = false;

    //**************//
    // Output class //
    //**************//

	/*

    // Set up the filenames to output
    string outputdir = inifile.getiniString("logdir", "logs", "Function");
    string basename = inifile.getiniString("runname", "run", "Function");
    string postname = inifile.getiniString("postname", "d", "Function"); // Only used if dopostprocess is true

    // Go and find our appropriate file name (using 4 digit numbers as the default)
    string outputname = getfilename(outputdir, basename, postname, inifile.getiniInt("numberpad", 4, "Function"), dopostprocess);

    // Set up the output class
    std::string parsestring = inifile.getiniString("outputclass", "BasicDump", "Single");
    Output *myOutput;
    if (parsestring == "BasicDump")
        myOutput = new BasicDump(dopostprocess, outputname, postname);
    else
        myOutput = new BasicDump(dopostprocess, outputname, postname);    // BasicDump is the default

    // Check that output is a go
    if (!myOutput->filesready()) {
        // End gracefully if not
        cout << "Unable to open files for output." << endl;
        delete myOutput;
        return -1;
    }
*/
	Print2Memory myOutput;
    // Load SN1a data
    // Not so much here in a single run, but when doing multiple runs, it makes sense to store the SN1a data in memory
    // rather than reading the file each time it's needed.
    // Here, we load up the SN1a data (if postprocessing is true)
    vector<vector<double> > SN1adata;
    if (dopostprocess) {
        string sn1afile = inifile.getiniString("union21", "SCPUnion2.1_mu_vs_z.txt", "Function");
        if (loadSN1adata(sn1afile, SN1adata) != 0) {
            // Could not find data file
            myOutput.printlog("Warning: cannot find Union2.1 SN1a data file.");
            cout << "Warning: cannot find Union2.1 SN1a data file." << endl;
        }
    }


    //*******************//
    // Do the evolution! //
    //*******************//

    // Print some stuff to the screen
    cout << "Beginning evolution." << endl;
    //cout << "Outputting to " << outputname << endl;

    // Start timing!
    boost::timer::cpu_timer myTimer;

	// parameter name to be dialed
	string paramname = "phi0"; 
	// Section name of dialed parameter
	string paramsection = "Cosmology"; 
	// Value of the parameter which will be returned as the sequestering-compatible parameter
	double param_seq;
	// Start value of the parameter to be dialed
	double paramstart = inifile.getiniDouble("paramstart", 0.0, "Seq");
	double paramend = inifile.getiniDouble("paramend", 2.5, "Seq");
	// Required accuracy of the sequestering constraint
	int maxSteps = inifile.getiniInt("maxSteps", 2000, "Seq");
	double DeltaParam = ( paramend - paramstart) / maxSteps;
	
	int Steps = 0;
	int NRflag = 0;
	double param = paramstart;
	double histIntRicciScalar;

	vector<double> results;
	/*
	ofstream dumpconv;
	dumpconv.open( inifile.getiniString("dumpdir", "testconv", "Seq") + "/" + inifile.getiniString("dumpfilename", "test.dat", "Seq") );
	string p1_name = "mass";
	string p1_section = "Quintessence";
	string p2_name = "Omegakh2";
	string p2_section = "Cosmology";
	double p1_min = inifile.getiniDouble("p1_min", 0.0, "Seq");
	double p1_max = inifile.getiniDouble("p1_max", 0.0, "Seq");
	double delta_p1 = (p1_max - p1_min)/inifile.getiniDouble("p1_n", 10.0, "Seq");
	double p2_min = inifile.getiniDouble("p2_min", 0.0, "Seq");
	double p2_max = inifile.getiniDouble("p2_max", 0.0, "Seq");
	double delta_p2 = (p2_max - p2_min)/inifile.getiniDouble("p2_n", 10.0, "Seq");		 
	std::cout << p1_name << " = " << p1_min << " " << p1_max << " " << delta_p1 << "(logspace)" << std::endl;
	std::cout << p2_name << " = " << p2_min << " " << p2_max << " " << delta_p2 << std::endl;
	
	for(double p1 = p1_min; p1 < p1_max; p1 += delta_p1){
		inifile.setparam(p1_name,p1_section,pow(10.0,p1));
		for(double p2 = p2_min; p2 < p2_max; p2 += delta_p2){
			inifile.setparam("evtoend","Seq",true);
			inifile.setparam(p2_name,p2_section,p2);
			Parameters myParams_1(inifile);
			results = doEvolution(inifile, myParams_1, myOutput, SN1adata, dopostprocess);
			// Now do a run to get the likelihood
			inifile.setparam("evtoend","Seq",false);
			Parameters myParams_2(inifile);
			doEvolution(inifile, myParams_2, myOutput, SN1adata, true);
			dumpconv << p1 << " " << p2 << " ";
			for(int n = 0; n < results.size(); n++)
				dumpconv << results[n] << " ";
			dumpconv << myOutput.getvalue("combinationchi", 0.0);
			dumpconv << std::endl;
		}
		dumpconv << std::endl;
	}
	*/
	
	
	// HOPEFULLY, A ROUTINE TO FIND A SEQUESTERING SOLUTION VIA SOME MCMC-ISH METHOD.
	
	
	
	ofstream dumpconv;
	dumpconv.open( inifile.getiniString("dumpdir", "testconv", "Seq") + "/" + inifile.getiniString("dumpfilename", "test.dat", "Seq") );
	
	double HIRl_p, HIRl_c = 1000, Omk_p, tmax, w0, amax;
	double HIRl_t = inifile.getiniDouble("HIRt", 0.1, "Seq");

	double p1_min = inifile.getiniDouble("p1_min", 0.0, "Seq");
	double p1_max = inifile.getiniDouble("p1_max", 0.0, "Seq");
	string p1_name = "mass";
	string p1_section = "Quintessence";
	double delta_p1 = (p1_max - p1_min)/inifile.getiniDouble("p1_n", 10.0, "Seq");
	double p2_min = inifile.getiniDouble("p2_min", 0.0, "Seq");
	double p2_max = inifile.getiniDouble("p2_max", 0.0, "Seq");
	double p2_sigma = (p2_max - p2_min) / 100.0;
	double Omk = p2_min;
	double tarmfrac, a_now;
	for(double p1 = p1_min; p1 < p1_max; p1 += delta_p1){
		
		inifile.setparam(p1_name,p1_section,pow(10.0,p1));
		Omk = p2_min + (p2_max - p2_min) * 0.5 + NormalRand() * p2_sigma;
		HIRl_c = 1000;
		while(true){
			
			// Pick a new Omk that is inside the prior range
			while(true){
				Omk_p = Omk + NormalRand() * p2_sigma;
				if(Omk_p <= p2_max && Omk_p >= p1_min)
					break;
			}

			// Now that we have a sensible choice of Omk,
			// run the evolver...
			inifile.setparam("evtoend","Seq",true);
			inifile.setparam("Omegakh2","Cosmology",Omk_p);
			Parameters myParams_1(inifile);
			results = doEvolution(inifile, myParams_1, myOutput, SN1adata, false);
			// ... and pull out the value of <R>
			HIRl_p = log10(abs(results[1]));
			
			// If <R> for this choice of Omk is smaller than the previous one,
			// then keep it.
			if(HIRl_p < HIRl_c){
				Omk = Omk_p;
				HIRl_c = HIRl_p;
			}
	
			// If <R> is smaller than te desired threshold "error",
			//	then we have found a sequestering solution.	
			if(HIRl_c < HIRl_t){
				amax = results[4];
				w0 = results[5];
				tmax = results[6];
				tarmfrac = results[7];
				a_now = results[8];
				break;
			}
		}
		inifile.setparam("evtoend","Seq",false);
		Parameters myParams_2(inifile);
		doEvolution(inifile, myParams_2, myOutput, SN1adata, true);
		dumpconv << p1 << " " <<  Omk << " " << HIRl_c << " ";
		dumpconv << exp(-0.5 * myOutput.getvalue("combinationchi", 0.0) ) << " ";
		dumpconv << amax << " " << tmax << " " << w0 << " " << tarmfrac << " " << a_now << endl;
		/*
		1: mass
		2: Omk
		3: <R>
		4: L
		5: amax
		6: tmax
		7: w0
		
		*/
	}
	
	
	
	dumpconv.close();
	if(NRflag == 0)
		std::cout << "histIntRicciScalar = " << histIntRicciScalar << endl;	
	
    // Stop timing
    myTimer.stop();
	result = (int)results[0];
	
    // Interpret the result of the evolution
    if (result == 0) {
        // Success! Print a nice message
        myOutput.printfinish(myTimer.elapsed().wall / 1e6);
        cout << setprecision(4) << "Evolution complete in " << myTimer.elapsed().wall / 1e6 << " milliseconds." << endl;
    }
    else if (result == -1) {
        // Initialization error
        cout << "Error initializing model; terminating." << endl;
    }
    else if (result == 1) {
        // Integration error
        cout << "Integration error; terminating." << endl;
    }
    else if (result == 2) {
        // NAN error
        cout << "NAN error; terminating." << endl;
    }
    else if (result == 3) {
        // Did not get t a = 1 error
        cout << "Did not evolve to a = 1 within appropriate conformal time; terminating." << endl;
    }
    else if (result == 4) {
        // Invalid state error
        cout << "Invalid state reached; terminating." << endl;
    }
    else if (result == 5) {
        // Invalid state error
        cout << "Error integrating distance measures; terminating." << endl;
    }


    //**********//
    // Clean up //
    //**********//

    // No memory leaks!
//    delete *myOutput;

	// Exit gracefully
	return 0;
}
Exemplo n.º 3
0
bool MissionList::GetMissionDescription(int i, MissionDescription *pmd) {
    PdbItem *ppdbi;
    LvlItem *plvli = FindLevelItem(i, &ppdbi);
    if (plvli == NULL) {
        return false;
    }
    if (!gppackm->Mount(gpakr, &ppdbi->packid)) {
        return false;
    }

    const char *pszName;
    switch (plvli->mt) {
    case kmtStory:
        pszName = "Story Missions";
        break;

    case kmtMultiplayerChallenge:
    case kmtChallenge:
        pszName = "Challenge Missions";
        break;

    case kmtDemo:
        pszName = "Demo Missions";
        break;

    case kmtMultiplayerAddOn:
    case kmtAddOn:
        pszName = ppdbi->pszTitle;
        if (strlen(pszName) == 0) {
            pszName = ExtractPackTitle(&ppdbi->packid);
            if (pszName == NULL) {
                pszName = "Add-On Mission Pack";
            }
        }
        break;

    default:
        pszName = "<untitled>";
        break;
    }
    strncpyz(pmd->szPackName, pszName, sizeof(pmd->szPackName));
    pmd->mt = plvli->mt;

    IniReader *pini = LoadIniFile(gpakr, plvli->pszFilename);
    if (pini == NULL) {
        gppackm->Unmount(gpakr, &ppdbi->packid);
        return false;
    }

    strncpyz(pmd->szLvlTitle, "<untitled>", sizeof(pmd->szLvlTitle));
    pini->GetPropertyValue("General", "Title", pmd->szLvlTitle,
            sizeof(pmd->szLvlTitle));

    if (IsMultiplayerMissionType(plvli->mt)) {
        pmd->cPlayersMin = 2;
        pini->GetPropertyValue("General", "MinPlayers", "%d",
                &pmd->cPlayersMin);
        if (pmd->cPlayersMin < 2) {
            pmd->cPlayersMin = 2;
        }
        pmd->cPlayersMax = 2;
        pini->GetPropertyValue("General", "MaxPlayers", "%d",
                &pmd->cPlayersMax);
        if (pmd->cPlayersMax > 4) {
            pmd->cPlayersMax = 4;
        }
    } else {
        pmd->cPlayersMin = 1;
        pmd->cPlayersMax = 1;
    }

    delete pini;
    gppackm->Unmount(gpakr, &ppdbi->packid);
    return true;
}
Exemplo n.º 4
0
// Our program entry point
int main(int argc, char* argv[]) {

	// Read the params.ini file
	// If there is a command line argument, assume that it is a different file than params.ini
	IniReader inifile;
	if (argc > 1)
		inifile.read(argv[1]);
	else
		inifile.read("params.ini");

	// Set up the integrator
	Integrator *myIntegrator = new Integrator;

	// Set up the equations of motion/model class
//	Model *myModel = new Quintessence();
	Model *myModel = new QuintessenceH();
//	Model *myModel = new LambdaCDM();

	// Set up the parameters - OmegaM, Tgamma, OmegaK, z_init, h (of H_0 = h * 100 km/s/Mpc) and the model
	Parameters *myParams = new Parameters(inifile.getiniDouble("Omegam", 0.3, "general"),
			                              inifile.getiniDouble("Tgamma", 2.72548, "general"), 0.01, 1.0e4, 0.7);

	// Load the model and parameters into a class to pass into the integration routine
	IntParams *myIntParams = new IntParams(*myParams, *myModel);

	// Set up the initial conditions
	// We use conformal time for our time coordinate. To make things easier, we start at tau = 0.
	double starttime = 0.0;
	// We don't want to integrate forever; specify an endtime in conformal time. I've chosen 100 here; this should
	// be chosen to correspond to about twice as long as you'd except the integration to take.
	// Note that we'll actually be checking to stop integration when the energy fraction of matter is roughly correct (a >= 1)
	double endtime = 10.0;
	// The initial conditions is specified by values for the initial a, \phi, and \dot{\phi}
	// where the overdot is a derivative with respect to conformal time.
	// Rather than setting a, it's simpler to set a redshift to begin at, and compute a from there, noting that 1 + z = a_{today}/a
	// and a_{today} = 1 by choice. This choice is specified in myParams.
	// \phi and \dot{\phi} will need to be set based on the model
	double phi0 = 0.01;
	double phidot0 = 0.0;

	// The data array stores a, \phi, and \dot{phi} through the evolution. The fourth parameter is an initial value of \dot{a}/a,
	// which may be necessary in some models.
	double data[4] = { 1.0 / (1.0 + myParams->z0()), phi0, phidot0, 0.0 };

	// Set up the filenames to output
	string outputdir = "logs";
	string basename = "run";
	// Go and find our appropriate file name (using 4 digit numbers)
	string outputname = getfilename(outputdir, basename, 4);

	// Set up the output class
	Output *myOutput = new BasicDump(outputname);
	// Check that output is a go
	if (!myOutput->filesready()) {
		cerr << "Unable to open files for output." << endl;
		return -1;
	}

	// Set up the consistency check class
	// Consistency *myChecker = new Consistency();
	Consistency *myChecker = new SimpleCheck();

	// Allow the model to initialize itself
	int initresult = myModel->init(data, starttime, *myParams);
	if (initresult != 0) {
		cerr << "Unable to initialize model." << endl;
		return -1;
	}

	// Get the output class to write out information on the run
	myOutput->printinfo(data, *myIntParams);

	// Allow the model class to write out any information on the run
	myOutput->printlog(myModel->description());

	// Start timing!
	boost::timer::cpu_timer myTimer;

	// Do the evolution!
	int result = BeginEvolution(*myIntegrator, *myIntParams, data, starttime, endtime, *myOutput, *myChecker);

	// Print a goodbye message, using time in milliseconds
	myTimer.stop();
	myOutput->printfinish(myTimer.elapsed().wall / 1e6);

	// Clean up
	delete myChecker;
	delete myOutput;
	delete myIntParams;
	delete myParams;
	delete myModel;
	delete myIntegrator;

	// Exit gracefully with result from integration
	return result;
}
Exemplo n.º 5
0
// Our program entry point
int main(int argc, char* argv[]) {

    // Start timing!
    boost::timer::cpu_timer myTimer;

    //******************//
    // Input parameters //
    //******************//

    // Read the input parameters file, named "params.ini" by default.
    // If there is a command line argument, assume that it is the filename for the parameters file.
    IniReader inifile;
    string paramsfile;
    if (argc > 1)
        paramsfile = argv[1];
    else
        paramsfile = "params.ini";
    inifile.read(paramsfile.c_str());

    //**************//
    // Declarations //
    //**************//

    // Print2Memory is used for MCMC outputting
    Print2Memory myOutput;

    // Seed random number generator
    RNGtool.seed(time(NULL));

    // Output directories and filenames
    string chaindir = inifile.getiniString("chaindir", "chains", "MCMC");
    string chainsubdir = inifile.getiniString("chainsubdir", "run1", "MCMC");
    string outputdir = chaindir + "/" + chainsubdir;
    string basename = inifile.getiniString("chainprefix", "chain", "MCMC");
    string priorsfile = inifile.getiniString("priorsfile", "priors.txt", "MCMC");

    // If the priors file doesn't exist, abort
    // Make sure that the directories exist
    if (!boost::filesystem::exists(priorsfile)) {
        cout << "Priors file (" << priorsfile << ") does not exist. Aborting." << endl;
        return -1;
    }

    // Make sure that the directories exist
    if (!boost::filesystem::exists(chaindir + "/")) {
        // Directory doesn't exist. Make it.
        boost::filesystem::create_directory(chaindir);
        std::cout << "Creating directory " << chaindir << "/" << std::endl;
    }
    if (!boost::filesystem::exists(outputdir + "/")) {
        // Directory doesn't exist. Make it.
        boost::filesystem::create_directory(outputdir);
        std::cout << "Creating directory " << outputdir << "/" << std::endl;
    }


    // Copy the params.ini and priors file being used into the subdir
    if (boost::filesystem::exists(paramsfile.c_str())) {
        boost::filesystem::copy_file(paramsfile, outputdir + "/params.ini", boost::filesystem::copy_option::overwrite_if_exists);
        boost::filesystem::copy_file(priorsfile, outputdir + "/priors.txt", boost::filesystem::copy_option::overwrite_if_exists);
    }

    // MCMC parameters
    // Number of MCMC steps to burn
    int MCMCburninsteps = inifile.getiniInt("MCMCburninsteps", 1000, "MCMC");
    // Number of MCMC steps to take
    int MCMCnumsteps = inifile.getiniInt("MCMCnumsteps", 40000, "MCMC");
    // Number of MCMC chains
    int MCMCnumchains = inifile.getiniInt("numchains", 5, "MCMC");

    // Various variables
    int MCMCstep, MCMCaccept_counter;
    double lower, upper;
    bool usingSN1a;

    // Variables for holding the current and proposed likelihoods, and their ratio
    double L_current, L_proposed, LikelihoodRatio;

    // Progressbar stuff
    bool showprogress = inifile.getiniBool("progress", true, "MCMC");
    float progress = 0.0;
    int barcount = 0;


    //****************//
    // Initialization //
    //****************//

    // Get the priors
	ifstream priorsin;
    string line;
	priorsin.open(priorsfile.c_str());
	vector<PARAMPRIORS> spriors;
	string dummy;
	if(priorsin){
		while(!priorsin.eof()){
		    // Extract the line
		    getline(priorsin, line);
		    // Check whether the line is a comment
		    if (line[0] != '#' && line.length() > 0) {
		        if (line[0] == 'L' && line[1] == ' ') {
		            // Log parameter
                    // Convert the string into a stringstream for extraction
                    stringstream stream(line);
                    PARAMPRIORS temp;
                    stream >> dummy >> temp.section >> temp.name >> temp.lower >> temp.upper >> temp.sigma;
                    temp.logparam = true;
                    // Make sure that the upper and lower bounds are positive
                    if (temp.upper < 0 or temp.lower < 0) {
                        cout << "Error: bounds for " << temp.name << " must be positive in order to investigate parameter in log space. Terminating." << endl;
                        return -1;
                    }
                    spriors.push_back(temp);
		        } else {
                    // Convert the string into a stringstream for extraction
                    stringstream stream(line);
                    PARAMPRIORS temp;
                    stream >> temp.section >> temp.name >> temp.lower >> temp.upper >> temp.sigma;
                    temp.logparam = false;
                    spriors.push_back(temp);
		        }
		    }
		}
Exemplo n.º 6
0
// This is the workhorse of the code.
// It takes in the input parameters and an output object, and runs everything from there.
// This modularization is set up so that anybody can call the evolution routines.
//
// Input parameters:
// inifile: the input parameters
// params: class containing cosmological parameters (somewhat degenerate with inifile, but these values won't be read from inifile)
// output: the outputting class
// postprocess: whether or not to perform postprocessing
//
// Return values:
// 0: success
// -1: error in initialization
// 1: Integration error
// 2: NAN error
// 3: Did not get to a = 1 in allotted time
// 4: Model reports invalid state
// 5: Error in postprocessing integration of distance measures
int doEvolution(IniReader& inifile, Parameters& params, Output& output, vector<vector<double> > &SN1adata, bool postprocess) {

    //****************//
    // Initialization //
    //****************//

    // Set up the integrator
    Integrator myIntegrator;

    // Set up the model class
    Model *myModel;
    std::string parsestring = inifile.getiniString("model", "LambdaCDM", "Cosmology");
    if (parsestring == "Quintessence")
        myModel = new Quintessence();
    else if (parsestring == "LinearW")
        myModel = new LinearW();
    else if (parsestring == "Kessence")
        myModel = new Kessence();
    else if (parsestring == "KGB")
        myModel = new KGB();
    else if (parsestring == "Fr")
        myModel = new Fr();
    else
        myModel = new LambdaCDM();    // LambdaCDM is the default

    // Load the model and parameters into a class to pass into the integration routine
    IntParams myIntParams(params, *myModel);

    // Set up the consistency check class
    parsestring = inifile.getiniString("consistencyclass", "None", "Function");
    Consistency *myChecker;
    if (parsestring == "SimpleCheck")
        myChecker = new SimpleCheck();
    else
        myChecker = new Consistency();  // Default option, which has no checking

    // Create vectors for redshift and hubble
    vector<double> redshift;
    vector<double> hubble;

    int result = 0; // For information coming back from functions


    //********************//
    // Initial Conditions //
    //********************//

    // The initial value of a is extracted from the starting redshift
    // The initial values of \phi and \dot{\phi} are read from the input parameters
    double phi0 = inifile.getiniDouble("phi0", 0.0, "Cosmology");
    double phidot0 = inifile.getiniDouble("phidot0", 0.0, "Cosmology");
    double data[4] = { 1.0 / (1.0 + params.z0()), phi0, phidot0, 0.0 };
    // The data array stores a, \phi, \dot{phi} and H through the evolution
    // H is calculated in the initialization of the model

    // Start and end times
    double starttime = inifile.getiniDouble("starttime", 0.0, "Function");
    double endtime = starttime + inifile.getiniDouble("maxtime", 10.0, "Function");

    // Get the output class to write out information on the run
    output.printinfo(data, params);

    // Allow the model to initialize itself
    result = myModel->init(data, starttime, params, inifile, output);
    if (result != 0) {
        delete myChecker;
        delete myModel;
        return -1;
    }

    // Check that the model has an internally consistent state with the initial data (it should have aborted already if so, but be safe)
    if (myModel->isvalidconfig(data) == false) {
        delete myChecker;
        delete myModel;
        return 4;
    }

    // Write the model name to the output log
    output.printvalue("Model", myModel->classname());
    output.printlog(""); // Whitespace for prettiness


    //***********//
    // Evolution //
    //***********//

    // Do the evolution!
    result = BeginEvolution(myIntegrator, myIntParams, data, starttime, endtime, output, *myChecker, hubble, redshift);


    //*********************************//
    // Clean up of Hubble and Redshift //
    //*********************************//

    if (result == 0) { // when the evolution was a success

        // We have H and z starting with high z going to z = 0. We want these reversed.
        reverse(hubble.begin(),hubble.end());
        reverse(redshift.begin(),redshift.end());

        // Update the parameters class with the new hubble value
        params.seth(hubble[0]);

        // Now go and report the actual density fractions and hubble parameter to the logs
        output.printlog("Values from evolution of model are as follows:");
        output.printvalue("modelh", params.geth());
        output.printvalue("modelOmegaR", params.getOmegaR());
        output.printvalue("modelOmegaM", params.getOmegaM());
        output.printvalue("modelOmegaB", params.getOmegaB());
        output.printvalue("modelOmegaK", params.getOmegaK());
        output.printvalue("modelOmegaLambda", 1 - params.getOmegaK() - params.getOmegaR() - params.getOmegaM());
        output.printlog("");

    }


    //*********************************//
    // Post-processing: initialization //
    //*********************************//

    // Construct vectors for distance measures
    int numrows = hubble.size();
    vector<double> DC;
    vector<double> DM;
    vector<double> DA;
    vector<double> DL;
    vector<double> mu;
    // Other distances that are computed
    double rs; // sound horizon at z_CMB
    double rd; // sound horizon at z_drag

    //*******************//
    // Distance measures //
    //*******************//

    if (result == 0 && postprocess) { // when the evolution was a success AND we're doing the postprocessing

        // Get the output class to print any headings for postprocessing
        output.postprintheading();

        // Allocate space for the vectors
        DC.reserve(numrows);
        DM.reserve(numrows);
        DA.reserve(numrows);
        DL.reserve(numrows);
        mu.reserve(numrows);

        // Calculate distance measurements
        result = PostProcessingDist(hubble, redshift, DC, DM, DA, DL, mu, rs, rd, params, output);

        // Flag any errors
        if (result == 1) result = 5;

    }


    //**************//
    // chi^2 values //
    //**************//

    if (result == 0 && postprocess) { // when the distance calculations were a success AND we're doing the postprocessing

        double BAOchi, BAOrchi, WMAPchi, Planckchi, Hubblechi, SNchi;

        // Put in some whitespace!
        output.printlog("");

        // First, do chi^2 of WMAP and Planck distance posteriors
        chi2CMB(redshift, DA, rs, output, params, WMAPchi, Planckchi);

        // Next, do chi^2 of SN1a
        SNchi = chi2SN1a(redshift, mu, output, inifile, SN1adata);

        // Do chi^2 for hubble value
        Hubblechi = chi2hubble(params, inifile.getiniDouble("desiredh", 0.7, "Cosmology"), inifile.getiniDouble("sigmah", 0.03, "Cosmology"), output);

        // Finally, do chi^2 of BAO measurements
        chi2BAO(rd, redshift, hubble, DA, params, output, BAOchi, BAOrchi);

        // Calculate the combination chi^2 from the bitmask
        double combination = 0;
        unsigned int bitmask = params.getbitmask();
        // 1 = SN1a
        // 2 = BAO (using SDSS)
        // 4 = BAO (using SDSSR)
        // 8 = Hubble
        // 16 = WMAP
        // 32 = Planck
        combination += (bitmask & 1) * SNchi;
        combination += ((bitmask & 2) >> 1) * BAOchi;
        combination += ((bitmask & 4) >> 2) * BAOrchi;
        combination += ((bitmask & 8) >> 3) * Hubblechi;
        combination += ((bitmask & 16) >> 4) * WMAPchi;
        combination += ((bitmask & 32) >> 5) * Planckchi;
        output.printvalue("combinationchi", combination);
        output.printvalue("chicombo", (int) bitmask);

    }
Exemplo n.º 7
0
void GetParams(int argc, char* argv[], struct DATA *params){

  	// Get the parameter file:
    IniReader inifile;
    // If the user specified a param file at runtime
    //  then use that, else, use the default, params.ini
    //   (User specifies via ./EXE my_param.par)
    
    if (argc > 1)
        inifile.read(argv[1]);
    else
        inifile.read("params.ini");


	// The numbers shown are the "default" values,
	// if nothing can be found in the params.ini file.
	
    params->h = inifile.getiniDouble("h",0.1);
    params->ht = inifile.getiniDouble("ht",0.01);
    params->derivsaccuracy = int(inifile.getiniDouble("derivsaccuracy",2));
    
    params->imax = int(inifile.getiniDouble("imax",10));
    params->cmax = int(inifile.getiniDouble("cmax",2));
    params->ntimsteps = int(inifile.getiniDouble("ntimsteps",100));
  
	params->pottype = int(inifile.getiniDouble("pottype",1));
	params->inittype = int(inifile.getiniDouble("inittype",1));
	params->evoltype = int(inifile.getiniDouble("evoltype",0));
	params->field_lap_type = int(inifile.getiniDouble("field_lap_type",0));
	params->eomtype = int(inifile.getiniDouble("eomtype",0));
	
	params->screenfreq = int(inifile.getiniDouble("screenfreq",10));
	params->filefreq = int(inifile.getiniDouble("filefreq",10));
	params->thistfreq = int(inifile.getiniDouble("thistfreq",1));
	params->potparam1 = inifile.getiniDouble("potparam1",0.0);
	params->initparam1 = inifile.getiniDouble("initparam1",0.0);
	
	params->OutDir = inifile.getiniString("OutDir","output/");
	params->RunID = inifile.getiniString("RunID","run_01");
	
	params->PoissSolnMethod = int(inifile.getiniDouble("PoissSolnMethod",1));
	params->PoissSolnRelaxMethod = int(inifile.getiniDouble("PoissSolnRelaxMethod",1));
	params->PoissSourceType = int(inifile.getiniDouble("PoissSourceType",1));
	params->PoissAccuracy =  inifile.getiniDouble("PoissAccuracy",1);
	params->PossSolveFreq =  inifile.getiniDouble("PossSolveFreq",1);
	
	params->H0 = inifile.getiniDouble("H0",1.0);
	params->hbar = inifile.getiniDouble("hbar",1.0);
	
	
	// Make sure output directory exists.
	// If it dosnt, this function will create it & tell you
	// it got created
    checkdirexists(params->OutDir);
	
	params->flag = 0;
	
	
} // END GetParams()