From 87de672f8c2ddd4bf68c5aef14702a8f5f442def Mon Sep 17 00:00:00 2001 From: "P.M. Sutter" Date: Tue, 3 Jun 2014 00:33:11 -0400 Subject: [PATCH] added ramses loader --- c_tools/mock/generateMock.cpp | 2 +- c_tools/mock/loaders/ramses_loader.cpp | 92 ++++++++++++++++++- .../void_python_tools/backend/launchers.py | 20 +++- 3 files changed, 104 insertions(+), 10 deletions(-) diff --git a/c_tools/mock/generateMock.cpp b/c_tools/mock/generateMock.cpp index 6e26d7e..bbc0b86 100644 --- a/c_tools/mock/generateMock.cpp +++ b/c_tools/mock/generateMock.cpp @@ -684,7 +684,7 @@ int main(int argc, char **argv) if (args_info.ramsesBase_given && args_info.ramsesId_given) { loader = ramsesLoader(args_info.ramsesBase_arg, args_info.ramsesId_arg, - false, + true, // double precision with ramses... set this to false if you are dealing with single precision NEED_POSITION|NEED_VELOCITY|NEED_GADGET_ID, preselector); } else diff --git a/c_tools/mock/loaders/ramses_loader.cpp b/c_tools/mock/loaders/ramses_loader.cpp index 938ea77..ac4b7a4 100644 --- a/c_tools/mock/loaders/ramses_loader.cpp +++ b/c_tools/mock/loaders/ramses_loader.cpp @@ -25,6 +25,28 @@ #include #include "simulation_loader.hpp" +// ben edit + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// end ben edit + + using namespace std; using namespace CosmoTool; @@ -61,12 +83,24 @@ public: SimuData *loadFile(int id) { SimuData *d; + +// cludgy hack until I can get baseid working in this function... the problem is with SimuData *loadFile(int id) ... just need to learn a bit more C++ ~ Ben + + string baseidstr = snapshot_name.c_str(); + unsigned found = baseidstr.find_last_of("/"); + baseidstr = baseidstr.substr(found-5,found); + baseidstr = baseidstr.substr(0,5); // remove trailing slash + baseid = atoi(baseidstr.c_str()); + if (id >= _num_files) return 0; - d = loadRamsesSimu(snapshot_name.c_str(), baseid, id, double_precision, load_flags); + + d = loadRamsesSimu("/home/ben/phd/software/VIDE/vide_public/output_00091/", baseid, id, double_precision, load_flags); assert(d != 0); + cout << " Id " << id << "\n"; + if (d->Id != 0) { long *uniqueID = new long[d->NumPart]; @@ -87,18 +121,66 @@ public: SimulationLoader *ramsesLoader(const std::string& snapshot, int baseid, bool double_precision, int flags, SimulationPreprocessor *p) { SimuData *d, *header; - int num_files = 0; + int num_files = 0; // how many particle files are there? header = loadRamsesSimu(snapshot.c_str(), baseid, 0, double_precision, 0); + if (header == 0) return 0; - while ((d = loadRamsesSimu(snapshot.c_str(), baseid, num_files, double_precision, 0)) != 0) + +// count number of CPU's for this output... kinda copy/paste of loadRamses.cpp in cosmotool/src + + ostringstream ss_fname; + ss_fname << snapshot.c_str() << "/info_" << setfill('0') << setw(5) << baseid << ".txt"; + cout << "Opening info file " << ss_fname.str() << " to find cpu number" << endl; + ifstream infile(ss_fname.str().c_str()); + if (!infile) + return 0; + + + int err; + regex_t unit_l_rx; + + // const char *pattern = "^unit_l[ ]*=[ ]*([0-9\\.E+\\-]+)"; + const char *pattern = "^([A-Za-z_]+)[ ]*=[ ]*([0-9\\.E+\\-]+)"; + + err = regcomp (&unit_l_rx, pattern, REG_EXTENDED); + cout << unit_l_rx.re_nsub << endl; + if (err) { - num_files++; - delete d; + char errString[255]; + regerror(err, &unit_l_rx, errString, sizeof(errString)); + cout << errString << endl; + abort(); } + map infoMap; + string line; + while (getline(infile, line)) + { + regmatch_t allMatch[4]; + if (!regexec(&unit_l_rx, line.c_str(), 4, allMatch, 0)) + { + uint32_t start0 = allMatch[1].rm_so, end0 = allMatch[1].rm_eo; + uint32_t start1 = allMatch[2].rm_so, end1 = allMatch[2].rm_eo; + + string keyword = line.substr(start0, end0-start0); + istringstream iss(line.substr(start1, end1-start1)); + double unitLength; + + iss >> unitLength; + + infoMap[keyword] = unitLength; + } + } + + regfree(&unit_l_rx); + + + num_files = infoMap["ncpu"]; + + return new RamsesLoader(snapshot, baseid, double_precision, header, flags, num_files, p); } diff --git a/python_tools/void_python_tools/backend/launchers.py b/python_tools/void_python_tools/backend/launchers.py index 1110319..6804ba5 100644 --- a/python_tools/void_python_tools/backend/launchers.py +++ b/python_tools/void_python_tools/backend/launchers.py @@ -169,6 +169,8 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None, dataFileLine = "gadget " + datafile elif sample.dataFormat == "sdf": dataFileLine = "sdf " + datafile + elif sample.dataFormat == "ramses": + dataFileLine = "ramses " + os.path.split(datafile)[0] # just want the output directory else: raise ValueError("unknown dataFormat '%s'" % sample.dataFormat) @@ -183,13 +185,19 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None, reshiftFlag = "" if not sample.shiftSimZ: reshiftFlag = "preReShift" + if sample.dataFormat == "ramses": + ramsesId = int((os.path.split(datafile)[1])[5:10]) # picks out the particle file (should be the part_NNNNN.outXXXXX, then extracts the output id "NNNNN" as an integer) + ramsesIdLine = "ramsesId " + ramsesId + else: + ramsesIdLine = "" + conf=""" %s output %s outputParameter %s %s %s - gadgetUnit %g + %s rangeX_min %g rangeX_max %g rangeY_min %g @@ -200,11 +208,11 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None, %s %s %s - """ % (dataFileLine, outputFile, + """ % ((dataFileLine + "/"), outputFile, outputFile+".par", includePecVelString, useLightConeString, - sample.dataUnit, + ramsesIdLine, xMin, xMax, yMin, yMax, sample.zBoundaryMpc[0], sample.zBoundaryMpc[1], subSampleLine,resubSampleLine,inputParameterFlag,reshiftFlag) @@ -220,6 +228,8 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None, cmd = "%s --configFile=%s" % (binPath,parmFile) log = open(logFile, 'a') arg1 = "--configFile=%s" % parmFile + + subprocess.call(cmd, stdout=log, stderr=log, shell=True) log.close() @@ -230,7 +240,7 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None, doneLine = "Done! %5.2e\n" % keepFraction if not jobSuccessful(logFile, doneLine): - print "FAILED!" + print "FAILED!" ### dies here for now exit(-1) prevSubSample = thisSubSample @@ -312,6 +322,8 @@ def launchZobov(sample, binPath, zobovDir=None, logDir=None, continueRun=None, datafile = zobovDir+"zobov_slice_"+sampleName + print "zobovDir ", zobovDir + logFile = logDir+"/zobov_"+sampleName+".out" vozScript = "./scr_"+sampleName