46 #include <boost/algorithm/string.hpp>
47 #include <boost/iostreams/copy.hpp>
48 #include <boost/iostreams/filter/gzip.hpp>
49 #include <boost/iostreams/filtering_streambuf.hpp>
61 #include <boost/format.hpp>
62 #include <boost/program_options.hpp>
64 #ifndef NEKTAR_VERSION
65 #define NEKTAR_VERSION "Unknown"
70 namespace po = boost::program_options;
71 namespace io = boost::iostreams;
75 namespace LibUtilities
131 return solverInfoEnums;
145 return solverInfoMap;
160 return gloSysSolnInfoList;
174 return cmdLineArguments;
185 SessionReader::SessionReader(
int argc,
char *argv[])
188 m_filenames = ParseCommandLineArguments(argc, argv);
190 ASSERTL0(m_filenames.size() > 0,
"No session file(s) given.");
192 m_sessionName = ParseSessionName(m_filenames);
195 CreateComm(argc, argv);
197 TestSharedFilesystem();
201 if (m_comm->GetSize() > 1)
203 GetSolverInfoDefaults()[
"GLOBALSYSSOLN"] =
"IterativeStaticCond";
207 m_interpreter->SetRandomSeed((m_comm->GetRank() + 1) *
208 (
unsigned int)time(NULL));
217 SessionReader::SessionReader(
int argc,
char *argv[],
218 const std::vector<std::string> &pFilenames,
221 ASSERTL0(pFilenames.size() > 0,
"No filenames specified.");
223 ParseCommandLineArguments(argc, argv);
225 m_filenames = pFilenames;
227 m_sessionName = ParseSessionName(m_filenames);
232 CreateComm(argc, argv);
239 TestSharedFilesystem();
243 if (m_comm->GetSize() > 1)
245 GetSolverInfoDefaults()[
"GLOBALSYSSOLN"] =
"IterativeStaticCond";
249 m_interpreter->SetRandomSeed((m_comm->GetRank() + 1) *
250 (
unsigned int)time(NULL));
259 SessionReader::~SessionReader()
273 void SessionReader::InitSession(
const std::vector<std::string> &filenames)
276 if (filenames.size() > 0)
278 m_filenames = filenames;
285 if (DefinesCmdLineArgument(
"useoptfile"))
287 optfile = m_cmdLineOptions.find(
"useoptfile")->second.as<std::string>();
288 exists = (bool)boost::filesystem::exists(optfile.c_str());
289 ASSERTL0(exists,
"A valid .opt file was not specified "
290 "with the --useoptfile command line option");
292 m_filenames.push_back(optfile);
295 std::rotate(m_filenames.rbegin(), m_filenames.rbegin() + 1,
301 optfile = m_sessionName +
".opt";
302 exists = (bool)boost::filesystem::exists(optfile.c_str());
305 m_filenames.push_back(optfile);
308 std::rotate(m_filenames.rbegin(), m_filenames.rbegin() + 1,
313 m_updateOptFile =
true;
323 m_xmlDoc = MergeDoc(m_filenames);
336 if (std::getenv(
"NEKTAR_DISABLE_BACKUPS") !=
nullptr)
342 if (m_verbose && m_comm)
344 if (m_comm->TreatAsRankZero() && m_parameters.size() > 0)
346 cout <<
"Parameters:" << endl;
347 for (
auto &x : m_parameters)
349 cout <<
"\t" << x.first <<
" = " << x.second << endl;
354 if (m_comm->TreatAsRankZero() && m_solverInfo.size() > 0)
356 cout <<
"Solver Info:" << endl;
357 for (
auto &x : m_solverInfo)
359 cout <<
"\t" << x.first <<
" = " << x.second << endl;
366 void SessionReader::TestSharedFilesystem()
368 m_sharedFilesystem =
false;
370 if (m_comm->GetSize() > 1)
372 if (m_comm->GetRank() == 0)
374 std::ofstream testfile(
"shared-fs-testfile");
375 testfile <<
"" << std::endl;
376 ASSERTL1(!testfile.fail(),
"Test file creation failed");
381 int exists = (bool)boost::filesystem::exists(
"shared-fs-testfile");
384 m_sharedFilesystem = (exists == m_comm->GetSize());
386 if ((m_sharedFilesystem && m_comm->GetRank() == 0) ||
389 std::remove(
"shared-fs-testfile");
394 m_sharedFilesystem =
false;
397 if (m_verbose && m_comm->GetRank() == 0 && m_sharedFilesystem)
399 cout <<
"Shared filesystem detected" << endl;
407 std::vector<std::string> SessionReader::ParseCommandLineArguments(
int argc,
411 po::options_description desc(
"Allowed options");
415 (
"verbose,v",
"be verbose")
416 (
"version,V",
"print version information")
417 (
"help,h",
"print this help message")
418 (
"solverinfo,I", po::value<vector<std::string> >(),
419 "override a SOLVERINFO property")
420 (
"parameter,P", po::value<vector<std::string> >(),
421 "override a parameter")
422 (
"npx", po::value<int>(),
423 "number of procs in X-dir")
424 (
"npy", po::value<int>(),
425 "number of procs in Y-dir")
426 (
"npz", po::value<int>(),
427 "number of procs in Z-dir")
428 (
"nsz", po::value<int>(),
429 "number of slices in Z-dir")
430 (
"npt", po::value<int>(),
431 "number of procs in T-dir (parareal)")
432 (
"part-only", po::value<int>(),
433 "only partition mesh into N partitions.")
434 (
"part-only-overlapping", po::value<int>(),
435 "only partition mesh into N overlapping partitions.")
436 (
"part-info",
"Output partition information")
437 (
"forceoutput,f",
"Disables backups files and forces output to be "
438 "written without any checks")
439 (
"writeoptfile",
"write an optimisation file")
440 (
"useoptfile", po::value<std::string>(),
441 "use an optimisation file");
443 #ifdef NEKTAR_USE_CWIPI
444 desc.add_options()(
"cwipi", po::value<std::string>(),
"set CWIPI name");
447 for (
auto &cmdIt : GetCmdLineArgMap())
449 std::string names = cmdIt.first;
450 if (cmdIt.second.shortName !=
"")
452 names +=
"," + cmdIt.second.shortName;
454 if (cmdIt.second.isFlag)
456 desc.add_options()(names.c_str(), cmdIt.second.description.c_str());
460 desc.add_options()(names.c_str(), po::value<std::string>(),
461 cmdIt.second.description.c_str());
467 po::options_description hidden(
"Hidden options");
469 hidden.add_options()(
"input-file", po::value<vector<string>>(),
473 po::options_description all(
"All options");
474 all.add(desc).add(hidden);
477 po::positional_options_description
p;
478 p.add(
"input-file", -1);
481 po::parsed_options parsed = po::command_line_parser(argc, argv)
484 .allow_unregistered()
488 po::store(parsed, m_cmdLineOptions);
489 po::notify(m_cmdLineOptions);
492 if (m_cmdLineOptions.count(
"help"))
499 if (m_cmdLineOptions.count(
"version"))
507 boost::replace_all(branch,
"refs/heads/",
"");
509 cout <<
" (git changeset " << sha1.substr(0, 8) <<
", ";
513 cout <<
"detached head";
517 cout <<
"head " << branch;
528 if (m_cmdLineOptions.count(
"verbose"))
538 if (m_cmdLineOptions.count(
"forceoutput"))
548 if (m_cmdLineOptions.count(
"writeoptfile"))
550 m_updateOptFile =
true;
554 m_updateOptFile =
false;
558 for (
auto &x : parsed.options)
562 cout <<
"Warning: Unknown option: " << x.string_key << endl;
567 if (m_cmdLineOptions.count(
"input-file"))
569 return m_cmdLineOptions[
"input-file"].as<std::vector<std::string>>();
573 return std::vector<std::string>();
580 std::string SessionReader::ParseSessionName(std::vector<std::string> &filenames)
582 ASSERTL0(!filenames.empty(),
"At least one filename expected.");
584 std::string retval =
"";
587 std::string fname = filenames[0];
590 if (fname.size() > 4 && fname.substr(fname.size() - 4, 4) ==
"_xml")
592 retval = fname.substr(0, fname.find_last_of(
"_"));
595 else if (fname.size() > 4 && fname.substr(fname.size() - 4, 4) ==
".xml")
597 retval = fname.substr(0, fname.find_last_of(
"."));
600 else if (fname.size() > 7 && fname.substr(fname.size() - 7, 7) ==
".xml.gz")
602 retval = fname.substr(0, fname.find_last_of(
"."));
603 retval = retval.substr(0, retval.find_last_of(
"."));
612 TiXmlDocument &SessionReader::GetDocument()
614 ASSERTL1(m_xmlDoc,
"XML Document not defined.");
640 TiXmlElement *SessionReader::GetElement(
const string &pPath)
642 std::string vPath = boost::to_upper_copy(pPath);
643 std::vector<std::string> st;
644 boost::split(st, vPath, boost::is_any_of(
"\\/ "));
645 ASSERTL0(st.size() > 0,
"No path given in XML element request.");
647 TiXmlElement *vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
649 std::string(
"Cannot find element '") + st[0] + std::string(
"'."));
650 for (
int i = 1; i < st.size(); ++i)
652 vReturn = vReturn->FirstChildElement(st[i].c_str());
653 ASSERTL0(vReturn, std::string(
"Cannot find element '") + st[i] +
662 bool SessionReader::DefinesElement(
const std::string &pPath)
const
664 std::string vPath = boost::to_upper_copy(pPath);
665 std::vector<std::string> st;
666 boost::split(st, vPath, boost::is_any_of(
"\\/ "));
667 ASSERTL0(st.size() > 0,
"No path given in XML element request.");
669 TiXmlElement *vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
671 std::string(
"Cannot find element '") + st[0] + std::string(
"'."));
672 for (
int i = 1; i < st.size(); ++i)
674 vReturn = vReturn->FirstChildElement(st[i].c_str());
684 const std::vector<std::string> &SessionReader::GetFilenames()
const
692 const std::string &SessionReader::GetSessionName()
const
694 return m_sessionName;
701 const std::string SessionReader::GetSessionNameRank()
const
703 std::string dirname = m_sessionName +
"_xml";
704 fs::path pdirname(dirname);
706 std::string vFilename =
707 "P" + boost::lexical_cast<std::string>(m_comm->GetRowComm()->GetRank());
708 fs::path pFilename(vFilename);
710 fs::path fullpath = pdirname / pFilename;
723 bool SessionReader::GetSharedFilesystem()
725 return m_sharedFilesystem;
742 bool SessionReader::DefinesParameter(
const std::string &pName)
const
744 std::string vName = boost::to_upper_copy(pName);
745 return m_parameters.find(vName) != m_parameters.end();
756 const NekDouble &SessionReader::GetParameter(
const std::string &pName)
const
758 std::string vName = boost::to_upper_copy(pName);
759 auto paramIter = m_parameters.find(vName);
761 ASSERTL0(paramIter != m_parameters.end(),
762 "Unable to find requested parameter: " + pName);
764 return paramIter->second;
770 void SessionReader::LoadParameter(
const std::string &pName,
int &pVar)
const
772 std::string vName = boost::to_upper_copy(pName);
773 auto paramIter = m_parameters.find(vName);
774 ASSERTL0(paramIter != m_parameters.end(),
775 "Required parameter '" + pName +
"' not specified in session.");
776 NekDouble param = round(paramIter->second);
777 pVar = checked_cast<int>(param);
783 void SessionReader::LoadParameter(
const std::string &pName,
int &pVar,
784 const int &pDefault)
const
786 std::string vName = boost::to_upper_copy(pName);
787 auto paramIter = m_parameters.find(vName);
788 if (paramIter != m_parameters.end())
790 NekDouble param = round(paramIter->second);
791 pVar = checked_cast<int>(param);
802 void SessionReader::LoadParameter(
const std::string &pName,
size_t &pVar)
const
804 std::string vName = boost::to_upper_copy(pName);
805 auto paramIter = m_parameters.find(vName);
806 ASSERTL0(paramIter != m_parameters.end(),
807 "Required parameter '" + pName +
"' not specified in session.");
808 NekDouble param = round(paramIter->second);
809 pVar = checked_cast<int>(param);
815 void SessionReader::LoadParameter(
const std::string &pName,
size_t &pVar,
816 const size_t &pDefault)
const
818 std::string vName = boost::to_upper_copy(pName);
819 auto paramIter = m_parameters.find(vName);
820 if (paramIter != m_parameters.end())
822 NekDouble param = round(paramIter->second);
823 pVar = checked_cast<int>(param);
834 void SessionReader::LoadParameter(
const std::string &pName,
837 std::string vName = boost::to_upper_copy(pName);
838 auto paramIter = m_parameters.find(vName);
839 ASSERTL0(paramIter != m_parameters.end(),
840 "Required parameter '" + pName +
"' not specified in session.");
841 pVar = paramIter->second;
847 void SessionReader::LoadParameter(
const std::string &pName,
NekDouble &pVar,
850 std::string vName = boost::to_upper_copy(pName);
851 auto paramIter = m_parameters.find(vName);
852 if (paramIter != m_parameters.end())
854 pVar = paramIter->second;
865 void SessionReader::SetParameter(
const std::string &pName,
int &pVar)
867 std::string vName = boost::to_upper_copy(pName);
868 m_parameters[vName] = pVar;
874 void SessionReader::SetParameter(
const std::string &pName,
size_t &pVar)
876 std::string vName = boost::to_upper_copy(pName);
877 m_parameters[vName] = pVar;
883 void SessionReader::SetParameter(
const std::string &pName,
NekDouble &pVar)
885 std::string vName = boost::to_upper_copy(pName);
886 m_parameters[vName] = pVar;
892 bool SessionReader::DefinesSolverInfo(
const std::string &pName)
const
894 std::string vName = boost::to_upper_copy(pName);
895 auto infoIter = m_solverInfo.find(vName);
896 return (infoIter != m_solverInfo.end());
902 const std::string &SessionReader::GetSolverInfo(
903 const std::string &pProperty)
const
905 std::string vProperty = boost::to_upper_copy(pProperty);
906 auto iter = m_solverInfo.find(vProperty);
908 ASSERTL1(iter != m_solverInfo.end(),
909 "Unable to find requested property: " + pProperty);
917 void SessionReader::SetSolverInfo(
const std::string &pProperty,
918 const std::string &pValue)
920 std::string vProperty = boost::to_upper_copy(pProperty);
921 auto iter = m_solverInfo.find(vProperty);
923 ASSERTL1(iter != m_solverInfo.end(),
924 "Unable to find requested property: " + pProperty);
926 iter->second = pValue;
932 void SessionReader::LoadSolverInfo(
const std::string &pName, std::string &pVar,
933 const std::string &pDefault)
const
935 std::string vName = boost::to_upper_copy(pName);
936 auto infoIter = m_solverInfo.find(vName);
937 if (infoIter != m_solverInfo.end())
939 pVar = infoIter->second;
950 void SessionReader::MatchSolverInfo(
const std::string &pName,
951 const std::string &pTrueVal,
bool &pVar,
952 const bool &pDefault)
const
954 std::string vName = boost::to_upper_copy(pName);
955 auto infoIter = m_solverInfo.find(vName);
956 if (infoIter != m_solverInfo.end())
958 pVar = boost::iequals(infoIter->second, pTrueVal);
969 bool SessionReader::MatchSolverInfo(
const std::string &pName,
970 const std::string &pTrueVal)
const
972 if (DefinesSolverInfo(pName))
974 std::string vName = boost::to_upper_copy(pName);
975 auto iter = m_solverInfo.find(vName);
976 if (iter != m_solverInfo.end())
978 return boost::iequals(iter->second, pTrueVal);
987 bool SessionReader::DefinesGlobalSysSolnInfo(
const std::string &pVariable,
988 const std::string &pProperty)
const
990 auto iter = GetGloSysSolnList().find(pVariable);
991 if (iter == GetGloSysSolnList().end())
996 std::string vProperty = boost::to_upper_copy(pProperty);
998 auto iter1 = iter->second.find(vProperty);
999 if (iter1 == iter->second.end())
1010 const std::string &SessionReader::GetGlobalSysSolnInfo(
1011 const std::string &pVariable,
const std::string &pProperty)
const
1013 auto iter = GetGloSysSolnList().find(pVariable);
1014 ASSERTL0(iter != GetGloSysSolnList().end(),
1015 "Failed to find variable in GlobalSysSolnInfoList");
1017 std::string vProperty = boost::to_upper_copy(pProperty);
1018 auto iter1 = iter->second.find(vProperty);
1020 ASSERTL0(iter1 != iter->second.end(),
1021 "Failed to find property: " + vProperty +
1022 " in GlobalSysSolnInfoList");
1024 return iter1->second;
1031 bool SessionReader::DefinesTimeIntScheme()
const
1033 return m_timeIntScheme.method !=
"";
1042 return m_timeIntScheme;
1045 std::string SessionReader::GetGeometryType()
const
1047 TiXmlElement *xmlGeom =
1048 m_xmlDoc->FirstChildElement(
"NEKTAR")->FirstChildElement(
"GEOMETRY");
1049 ASSERTL1(xmlGeom,
"Failed to find a GEOMETRY section in m_xmlDoc");
1051 TiXmlAttribute *attr = xmlGeom->FirstAttribute();
1054 std::string attrName(attr->Name());
1055 if (attrName ==
"HDF5FILE")
1061 attr = attr->Next();
1066 TiXmlElement *element = xmlGeom->FirstChildElement(
"VERTEX");
1067 string IsCompressed;
1068 element->QueryStringAttribute(
"COMPRESSED", &IsCompressed);
1070 if (IsCompressed.size() > 0)
1072 return "XmlCompressed";
1082 bool SessionReader::DefinesGeometricInfo(
const std::string &pName)
const
1084 std::string vName = boost::to_upper_copy(pName);
1085 return m_geometricInfo.find(vName) != m_geometricInfo.end();
1091 void SessionReader::LoadGeometricInfo(
const std::string &pName,
1093 const std::string &pDefault)
const
1095 std::string vName = boost::to_upper_copy(pName);
1096 auto iter = m_geometricInfo.find(vName);
1097 if (iter != m_geometricInfo.end())
1099 pVar = iter->second;
1110 void SessionReader::LoadGeometricInfo(
const std::string &pName,
bool &pVar,
1111 const bool &pDefault)
const
1113 std::string vName = boost::to_upper_copy(pName);
1114 auto iter = m_geometricInfo.find(vName);
1115 if (iter != m_geometricInfo.end())
1117 if (iter->second ==
"TRUE")
1135 void SessionReader::LoadGeometricInfo(
const std::string &pName,
NekDouble &pVar,
1138 std::string vName = boost::to_upper_copy(pName);
1139 auto iter = m_geometricInfo.find(vName);
1140 if (iter != m_geometricInfo.end())
1142 pVar = std::atoi(iter->second.c_str());
1153 void SessionReader::MatchGeometricInfo(
const std::string &pName,
1154 const std::string &pTrueVal,
bool &pVar,
1155 const bool &pDefault)
const
1157 std::string vName = boost::to_upper_copy(pName);
1158 auto iter = m_geometricInfo.find(vName);
1159 if (iter != m_geometricInfo.end())
1161 pVar = boost::iequals(iter->second, pTrueVal);
1172 const std::string &SessionReader::GetVariable(
const unsigned int &idx)
const
1174 ASSERTL0(idx < m_variables.size(),
"Variable index out of range.");
1175 return m_variables[idx];
1181 void SessionReader::SetVariable(
const unsigned int &idx, std::string newname)
1183 ASSERTL0(idx < m_variables.size(),
"Variable index out of range.");
1184 m_variables[idx] = newname;
1190 std::vector<std::string> SessionReader::GetVariables()
const
1198 bool SessionReader::GetBackups()
const
1206 bool SessionReader::DefinesFunction(
const std::string &pName)
const
1208 std::string vName = boost::to_upper_copy(pName);
1209 return m_functions.find(vName) != m_functions.end();
1215 bool SessionReader::DefinesFunction(
const std::string &pName,
1216 const std::string &pVariable,
1217 const int pDomain)
const
1219 std::string vName = boost::to_upper_copy(pName);
1222 auto it1 = m_functions.find(vName);
1223 if (it1 != m_functions.end())
1225 pair<std::string, int> key(pVariable, pDomain);
1226 pair<std::string, int> defkey(
"*", pDomain);
1227 bool varExists = it1->second.find(key) != it1->second.end() ||
1228 it1->second.find(defkey) != it1->second.end();
1238 const std::string &pVariable,
1239 const int pDomain)
const
1241 std::string vName = boost::to_upper_copy(pName);
1242 auto it1 = m_functions.find(vName);
1245 std::string(
"No such function '") + pName +
1246 std::string(
"' has been defined in the session file."));
1249 pair<std::string, int> key(pVariable, pDomain);
1250 pair<std::string, int> defkey(
"*", pDomain);
1252 auto it2 = it1->second.find(key);
1253 auto it3 = it1->second.find(defkey);
1254 bool specific = it2 != it1->second.end();
1255 bool wildcard = it3 != it1->second.end();
1259 "No such variable " + pVariable +
" in domain " +
1260 boost::lexical_cast<string>(pDomain) +
1261 " defined for function " + pName +
" in session file.");
1270 std::string(
"Function is defined by a file."));
1271 return it2->second.m_expression;
1278 const unsigned int &pVar,
1279 const int pDomain)
const
1281 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1282 return GetFunction(pName, m_variables[pVar], pDomain);
1288 enum FunctionType SessionReader::GetFunctionType(
const std::string &pName,
1289 const std::string &pVariable,
1290 const int pDomain)
const
1292 std::string vName = boost::to_upper_copy(pName);
1293 auto it1 = m_functions.find(vName);
1296 std::string(
"Function '") + pName + std::string(
"' not found."));
1299 pair<std::string, int> key(pVariable, pDomain);
1300 pair<std::string, int> defkey(
"*", pDomain);
1302 auto it2 = it1->second.find(key);
1303 auto it3 = it1->second.find(defkey);
1304 bool specific = it2 != it1->second.end();
1305 bool wildcard = it3 != it1->second.end();
1309 "No such variable " + pVariable +
" in domain " +
1310 boost::lexical_cast<string>(pDomain) +
1311 " defined for function " + pName +
" in session file.");
1319 return it2->second.m_type;
1325 enum FunctionType SessionReader::GetFunctionType(
const std::string &pName,
1326 const unsigned int &pVar,
1327 const int pDomain)
const
1329 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1330 return GetFunctionType(pName, m_variables[pVar], pDomain);
1336 std::string SessionReader::GetFunctionFilename(
const std::string &pName,
1337 const std::string &pVariable,
1338 const int pDomain)
const
1340 std::string vName = boost::to_upper_copy(pName);
1341 auto it1 = m_functions.find(vName);
1344 std::string(
"Function '") + pName + std::string(
"' not found."));
1347 pair<std::string, int> key(pVariable, pDomain);
1348 pair<std::string, int> defkey(
"*", pDomain);
1350 auto it2 = it1->second.find(key);
1351 auto it3 = it1->second.find(defkey);
1352 bool specific = it2 != it1->second.end();
1353 bool wildcard = it3 != it1->second.end();
1357 "No such variable " + pVariable +
" in domain " +
1358 boost::lexical_cast<string>(pDomain) +
1359 " defined for function " + pName +
" in session file.");
1367 return it2->second.m_filename;
1373 std::string SessionReader::GetFunctionFilename(
const std::string &pName,
1374 const unsigned int &pVar,
1375 const int pDomain)
const
1377 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1378 return GetFunctionFilename(pName, m_variables[pVar], pDomain);
1384 std::string SessionReader::GetFunctionFilenameVariable(
1385 const std::string &pName,
const std::string &pVariable,
1386 const int pDomain)
const
1388 std::string vName = boost::to_upper_copy(pName);
1389 auto it1 = m_functions.find(vName);
1392 std::string(
"Function '") + pName + std::string(
"' not found."));
1395 pair<std::string, int> key(pVariable, pDomain);
1396 pair<std::string, int> defkey(
"*", pDomain);
1398 auto it2 = it1->second.find(key);
1399 auto it3 = it1->second.find(defkey);
1400 bool specific = it2 != it1->second.end();
1401 bool wildcard = it3 != it1->second.end();
1405 "No such variable " + pVariable +
" in domain " +
1406 boost::lexical_cast<string>(pDomain) +
1407 " defined for function " + pName +
" in session file.");
1415 return it2->second.m_fileVariable;
1421 bool SessionReader::DefinesTag(
const std::string &pName)
const
1423 std::string vName = boost::to_upper_copy(pName);
1424 return m_tags.find(vName) != m_tags.end();
1430 void SessionReader::SetTag(
const std::string &pName,
const std::string &pValue)
1432 std::string vName = boost::to_upper_copy(pName);
1433 m_tags[vName] = pValue;
1439 const std::string &SessionReader::GetTag(
const std::string &pName)
const
1441 std::string vName = boost::to_upper_copy(pName);
1442 auto vTagIterator = m_tags.find(vName);
1443 ASSERTL0(vTagIterator != m_tags.end(),
"Requested tag does not exist.");
1444 return vTagIterator->second;
1458 bool SessionReader::DefinesCmdLineArgument(
const std::string &pName)
const
1460 return (m_cmdLineOptions.find(pName) != m_cmdLineOptions.end());
1466 void SessionReader::SubstituteExpressions(std::string &pExpr)
1468 for (
auto &exprIter : m_expressions)
1470 boost::replace_all(pExpr, exprIter.first, exprIter.second);
1477 void SessionReader::LoadDoc(
const std::string &pFilename,
1478 TiXmlDocument *pDoc)
const
1480 if (pFilename.size() > 3 &&
1481 pFilename.substr(pFilename.size() - 3, 3) ==
".gz")
1483 ifstream file(pFilename.c_str(), ios_base::in | ios_base::binary);
1484 ASSERTL0(file.good(),
"Unable to open file: " + pFilename);
1486 io::filtering_streambuf<io::input> in;
1487 in.push(io::gzip_decompressor());
1494 catch (io::gzip_error &)
1497 "Error: File '" + pFilename +
"' is corrupt.");
1500 else if (pFilename.size() > 4 &&
1501 pFilename.substr(pFilename.size() - 4, 4) ==
"_xml")
1503 fs::path pdirname(pFilename);
1505 pad % m_comm->GetSpaceComm()->GetRank();
1506 fs::path pRankFilename(pad.str());
1507 fs::path fullpath = pdirname / pRankFilename;
1510 ASSERTL0(file.good(),
"Unable to open file: " + fullpath.string());
1515 ifstream file(pFilename.c_str());
1516 ASSERTL0(file.good(),
"Unable to open file: " + pFilename);
1524 TiXmlDocument *SessionReader::MergeDoc(
1525 const std::vector<std::string> &pFilenames)
const
1527 ASSERTL0(pFilenames.size() > 0,
"No filenames for merging.");
1530 TiXmlDocument *vMainDoc =
new TiXmlDocument;
1531 LoadDoc(pFilenames[0], vMainDoc);
1533 TiXmlHandle vMainHandle(vMainDoc);
1534 TiXmlElement *vMainNektar =
1540 for (
int i = 1; i < pFilenames.size(); ++i)
1542 if ((pFilenames[i].compare(pFilenames[i].size() - 3, 3,
"xml") == 0) ||
1543 (pFilenames[i].compare(pFilenames[i].size() - 6, 6,
"xml.gz") ==
1545 (pFilenames[i].compare(pFilenames[i].size() - 3, 3,
"opt") == 0))
1547 TiXmlDocument *vTempDoc =
new TiXmlDocument;
1548 LoadDoc(pFilenames[i], vTempDoc);
1550 TiXmlHandle docHandle(vTempDoc);
1551 TiXmlElement *vTempNektar =
1553 TiXmlElement *
p = vTempNektar->FirstChildElement();
1557 TiXmlElement *vMainEntry =
1558 vMainNektar->FirstChildElement(
p->Value());
1563 if (!
p->FirstChild() && vMainEntry &&
1564 !boost::iequals(
p->Value(),
"COLLECTIONS"))
1566 std::string warningmsg =
1567 "File " + pFilenames[i] +
" contains " +
1568 "an empty XML element " + std::string(
p->Value()) +
1569 " which will be ignored.";
1570 NEKERROR(ErrorUtil::ewarning, warningmsg.c_str());
1576 vMainNektar->RemoveChild(vMainEntry);
1578 TiXmlElement *q =
new TiXmlElement(*
p);
1579 vMainNektar->LinkEndChild(q);
1581 p =
p->NextSiblingElement();
1593 void SessionReader::ParseDocument()
1596 ASSERTL0(m_xmlDoc,
"No XML document loaded.");
1599 TiXmlHandle docHandle(m_xmlDoc);
1601 e = docHandle.FirstChildElement(
"NEKTAR")
1602 .FirstChildElement(
"CONDITIONS")
1608 ReadGlobalSysSolnInfo(e);
1609 ReadTimeIntScheme(e);
1614 e = docHandle.FirstChildElement(
"NEKTAR")
1615 .FirstChildElement(
"FILTERS")
1624 void SessionReader::CreateComm(
int &argc,
char *argv[])
1632 string vCommModule(
"Serial");
1635 vCommModule =
"ParallelMPI";
1637 if (m_cmdLineOptions.count(
"cwipi") &&
1640 vCommModule =
"CWIPI";
1654 void SessionReader::PartitionComm()
1656 if (m_comm->GetSize() > 1)
1663 if (DefinesCmdLineArgument(
"npx"))
1665 nProcX = GetCmdLineArgument<int>(
"npx");
1667 if (DefinesCmdLineArgument(
"npy"))
1669 nProcY = GetCmdLineArgument<int>(
"npy");
1671 if (DefinesCmdLineArgument(
"npz"))
1673 nProcZ = GetCmdLineArgument<int>(
"npz");
1675 if (DefinesCmdLineArgument(
"nsz"))
1677 nStripZ = GetCmdLineArgument<int>(
"nsz");
1679 if (DefinesCmdLineArgument(
"npt"))
1681 nTime = GetCmdLineArgument<int>(
"npt");
1683 ASSERTL0(m_comm->GetSize() % nTime == 0,
1684 "Cannot exactly partition time using npt value.");
1685 ASSERTL0((m_comm->GetSize() / nTime) % (nProcZ * nProcY * nProcX) == 0,
1686 "Cannot exactly partition using PROC_Z value.");
1688 "Cannot exactly partition using PROC_Y value.");
1690 "Cannot exactly partition using PROC_X value.");
1693 int nProcSm = nProcZ * nProcY * nProcX;
1697 int nProcSem = m_comm->GetSize() / nTime / nProcSm;
1699 m_comm->SplitComm(nProcSm, nProcSem, nTime);
1700 m_comm->GetColumnComm()->SplitComm(nProcZ / nStripZ, nStripZ);
1701 m_comm->GetColumnComm()->GetColumnComm()->SplitComm((nProcY * nProcX),
1703 m_comm->GetColumnComm()->GetColumnComm()->GetColumnComm()->SplitComm(
1711 void SessionReader::ReadParameters(TiXmlElement *conditions)
1713 m_parameters.clear();
1720 TiXmlElement *parametersElement =
1721 conditions->FirstChildElement(
"PARAMETERS");
1725 if (parametersElement)
1727 TiXmlElement *parameter = parametersElement->FirstChildElement(
"P");
1735 stringstream tagcontent;
1736 tagcontent << *parameter;
1737 TiXmlNode *node = parameter->FirstChild();
1739 while (node && node->Type() != TiXmlNode::TINYXML_TEXT)
1741 node = node->NextSibling();
1747 std::string line = node->ToText()->Value(), lhs, rhs;
1751 ParseEquals(line, lhs, rhs);
1756 "Syntax error in parameter expression '" + line +
1757 "' in XML element: \n\t'" + tagcontent.str() +
1764 if (!lhs.empty() && !rhs.empty())
1772 catch (
const std::runtime_error &)
1775 "Error evaluating parameter expression"
1777 rhs +
"' in XML element: \n\t'" +
1778 tagcontent.str() +
"'");
1780 m_interpreter->SetParameter(lhs, value);
1781 caseSensitiveParameters[lhs] = value;
1782 boost::to_upper(lhs);
1783 m_parameters[lhs] = value;
1787 parameter = parameter->NextSiblingElement();
1795 void SessionReader::ReadSolverInfo(TiXmlElement *conditions)
1797 m_solverInfo.clear();
1798 m_solverInfo = GetSolverInfoDefaults();
1805 TiXmlElement *solverInfoElement =
1806 conditions->FirstChildElement(
"SOLVERINFO");
1808 if (solverInfoElement)
1810 TiXmlElement *solverInfo = solverInfoElement->FirstChildElement(
"I");
1814 std::stringstream tagcontent;
1815 tagcontent << *solverInfo;
1817 ASSERTL0(solverInfo->Attribute(
"PROPERTY"),
1818 "Missing PROPERTY attribute in solver info "
1819 "XML element: \n\t'" +
1820 tagcontent.str() +
"'");
1821 std::string solverProperty = solverInfo->Attribute(
"PROPERTY");
1823 "PROPERTY attribute must be non-empty in XML "
1825 tagcontent.str() +
"'");
1828 std::string solverPropertyUpper =
1829 boost::to_upper_copy(solverProperty);
1832 ASSERTL0(solverInfo->Attribute(
"VALUE"),
1833 "Missing VALUE attribute in solver info "
1834 "XML element: \n\t'" +
1835 tagcontent.str() +
"'");
1836 std::string solverValue = solverInfo->Attribute(
"VALUE");
1838 "VALUE attribute must be non-empty in XML "
1840 tagcontent.str() +
"'");
1843 m_solverInfo[solverPropertyUpper] = solverValue;
1844 solverInfo = solverInfo->NextSiblingElement(
"I");
1848 if (m_comm && m_comm->GetRowComm()->GetSize() > 1)
1851 m_solverInfo[
"GLOBALSYSSOLN"] ==
"IterativeFull" ||
1852 m_solverInfo[
"GLOBALSYSSOLN"] ==
"IterativeStaticCond" ||
1853 m_solverInfo[
"GLOBALSYSSOLN"] ==
1854 "IterativeMultiLevelStaticCond" ||
1855 m_solverInfo[
"GLOBALSYSSOLN"] ==
"XxtFull" ||
1856 m_solverInfo[
"GLOBALSYSSOLN"] ==
"XxtStaticCond" ||
1857 m_solverInfo[
"GLOBALSYSSOLN"] ==
"XxtMultiLevelStaticCond" ||
1858 m_solverInfo[
"GLOBALSYSSOLN"] ==
"PETScFull" ||
1859 m_solverInfo[
"GLOBALSYSSOLN"] ==
"PETScStaticCond" ||
1860 m_solverInfo[
"GLOBALSYSSOLN"] ==
"PETScMultiLevelStaticCond",
1861 "A parallel solver must be used when run in parallel.");
1868 void SessionReader::ReadGlobalSysSolnInfo(TiXmlElement *conditions)
1870 GetGloSysSolnList().clear();
1877 TiXmlElement *GlobalSys =
1878 conditions->FirstChildElement(
"GLOBALSYSSOLNINFO");
1885 TiXmlElement *VarInfo = GlobalSys->FirstChildElement(
"V");
1889 std::stringstream tagcontent;
1890 tagcontent << *VarInfo;
1891 ASSERTL0(VarInfo->Attribute(
"VAR"),
1892 "Missing VAR attribute in GobalSysSolnInfo XML "
1894 tagcontent.str() +
"'");
1896 std::string VarList = VarInfo->Attribute(
"VAR");
1898 "VAR attribute must be non-empty in XML element:\n\t'" +
1899 tagcontent.str() +
"'");
1902 std::vector<std::string> varStrings;
1903 bool valid = ParseUtils::GenerateVector(VarList, varStrings);
1905 ASSERTL0(valid,
"Unable to process list of variable in XML "
1907 tagcontent.str() +
"'");
1909 if (varStrings.size())
1911 TiXmlElement *SysSolnInfo = VarInfo->FirstChildElement(
"I");
1916 tagcontent << *SysSolnInfo;
1918 ASSERTL0(SysSolnInfo->Attribute(
"PROPERTY"),
1919 "Missing PROPERTY attribute in "
1920 "GlobalSysSolnInfo for variable(s) '" +
1921 VarList +
"' in XML element: \n\t'" +
1922 tagcontent.str() +
"'");
1924 std::string SysSolnProperty =
1925 SysSolnInfo->Attribute(
"PROPERTY");
1928 "GlobalSysSolnIno properties must have a "
1929 "non-empty name for variable(s) : '" +
1930 VarList +
"' in XML element: \n\t'" +
1931 tagcontent.str() +
"'");
1934 std::string SysSolnPropertyUpper =
1935 boost::to_upper_copy(SysSolnProperty);
1938 ASSERTL0(SysSolnInfo->Attribute(
"VALUE"),
1939 "Missing VALUE attribute in GlobalSysSolnInfo "
1940 "for variable(s) '" +
1941 VarList +
"' in XML element: \n\t" +
1942 tagcontent.str() +
"'");
1944 std::string SysSolnValue = SysSolnInfo->Attribute(
"VALUE");
1946 "GlobalSysSolnInfo properties must have a "
1947 "non-empty value for variable(s) '" +
1948 VarList +
"' in XML element: \n\t'" +
1949 tagcontent.str() +
"'");
1952 for (
int i = 0; i < varStrings.size(); ++i)
1954 auto x = GetGloSysSolnList().find(varStrings[i]);
1955 if (x == GetGloSysSolnList().end())
1957 (GetGloSysSolnList()[varStrings[i]])
1958 [SysSolnPropertyUpper] = SysSolnValue;
1962 x->second[SysSolnPropertyUpper] = SysSolnValue;
1966 SysSolnInfo = SysSolnInfo->NextSiblingElement(
"I");
1968 VarInfo = VarInfo->NextSiblingElement(
"V");
1972 if (m_verbose && GetGloSysSolnList().size() > 0 && m_comm)
1974 if (m_comm->GetRank() == 0)
1976 cout <<
"GlobalSysSoln Info:" << endl;
1978 for (
auto &x : GetGloSysSolnList())
1980 cout <<
"\t Variable: " << x.first << endl;
1982 for (
auto &y : x.second)
1984 cout <<
"\t\t " << y.first <<
" = " << y.second << endl;
1995 void SessionReader::ReadTimeIntScheme(TiXmlElement *conditions)
2002 TiXmlElement *timeInt =
2003 conditions->FirstChildElement(
"TIMEINTEGRATIONSCHEME");
2010 TiXmlElement *method = timeInt->FirstChildElement(
"METHOD");
2011 TiXmlElement *variant = timeInt->FirstChildElement(
"VARIANT");
2012 TiXmlElement *order = timeInt->FirstChildElement(
"ORDER");
2013 TiXmlElement *params = timeInt->FirstChildElement(
"FREEPARAMETERS");
2016 ASSERTL0(method,
"Missing METHOD tag inside "
2017 "TIMEINTEGRATIONSCHEME.");
2018 ASSERTL0(order,
"Missing ORDER tag inside "
2019 "TIMEINTEGRATIONSCHEME.");
2021 m_timeIntScheme.method = method->GetText();
2023 std::string orderStr = order->GetText();
2026 ASSERTL0(m_timeIntScheme.method.size() > 0,
2027 "Empty text inside METHOD tag in TIMEINTEGRATIONSCHEME.");
2029 "Empty text inside ORDER tag in TIMEINTEGRATIONSCHEME.");
2032 m_timeIntScheme.order = boost::lexical_cast<unsigned int>(orderStr);
2036 NEKERROR(ErrorUtil::efatal,
"In ORDER tag, unable to convert "
2038 orderStr +
"' to an unsigned integer.");
2043 m_timeIntScheme.variant = variant->GetText();
2048 std::string paramsStr = params->GetText();
2050 "Empty text inside FREEPARAMETERS tag in "
2051 "TIMEINTEGRATIONSCHEME.");
2053 std::vector<std::string> pSplit;
2054 boost::split(pSplit, paramsStr, boost::is_any_of(
" "));
2056 m_timeIntScheme.freeParams.resize(pSplit.size());
2057 for (
size_t i = 0; i < pSplit.size(); ++i)
2061 m_timeIntScheme.freeParams[i] =
2062 boost::lexical_cast<NekDouble>(pSplit[i]);
2066 NEKERROR(ErrorUtil::efatal,
"In FREEPARAMETERS tag, "
2067 "unable to convert string '" +
2070 "to a floating-point value.");
2075 if (m_verbose && m_comm)
2077 if (m_comm->GetRank() == 0)
2079 cout <<
"Trying to use time integration scheme:" << endl;
2080 cout <<
"\t Method : " << m_timeIntScheme.method << endl;
2081 cout <<
"\t Variant: " << m_timeIntScheme.variant << endl;
2082 cout <<
"\t Order : " << m_timeIntScheme.order << endl;
2084 if (m_timeIntScheme.freeParams.size() > 0)
2086 cout <<
"\t Params :";
2087 for (
auto &x : m_timeIntScheme.freeParams)
2100 void SessionReader::ReadExpressions(TiXmlElement *conditions)
2102 m_expressions.clear();
2109 TiXmlElement *expressionsElement =
2110 conditions->FirstChildElement(
"EXPRESSIONS");
2112 if (expressionsElement)
2114 TiXmlElement *expr = expressionsElement->FirstChildElement(
"E");
2118 stringstream tagcontent;
2119 tagcontent << *expr;
2121 "Missing NAME attribute in expression "
2122 "definition: \n\t'" +
2123 tagcontent.str() +
"'");
2124 std::string nameString = expr->Attribute(
"NAME");
2126 "Expressions must have a non-empty name: \n\t'" +
2127 tagcontent.str() +
"'");
2130 "Missing VALUE attribute in expression "
2131 "definition: \n\t'" +
2132 tagcontent.str() +
"'");
2133 std::string valString = expr->Attribute(
"VALUE");
2135 "Expressions must have a non-empty value: \n\t'" +
2136 tagcontent.str() +
"'");
2138 auto exprIter = m_expressions.find(nameString);
2139 ASSERTL0(exprIter == m_expressions.end(),
2140 std::string(
"Expression '") + nameString +
2141 std::string(
"' already specified."));
2143 m_expressions[nameString] = valString;
2144 expr = expr->NextSiblingElement(
"E");
2152 void SessionReader::ReadVariables(TiXmlElement *conditions)
2154 m_variables.clear();
2161 TiXmlElement *variablesElement = conditions->FirstChildElement(
"VARIABLES");
2165 if (variablesElement)
2167 TiXmlElement *varElement = variablesElement->FirstChildElement(
"V");
2170 int nextVariableNumber = -1;
2174 stringstream tagcontent;
2175 tagcontent << *varElement;
2179 nextVariableNumber++;
2182 int err = varElement->QueryIntAttribute(
"ID", &i);
2184 "Variables must have a unique ID number attribute "
2185 "in XML element: \n\t'" +
2186 tagcontent.str() +
"'");
2188 "ID numbers for variables must begin with zero and"
2189 " be sequential in XML element: \n\t'" +
2190 tagcontent.str() +
"'");
2192 TiXmlNode *varChild = varElement->FirstChild();
2197 while (varChild && varChild->Type() != TiXmlNode::TINYXML_TEXT)
2199 varChild = varChild->NextSibling();
2202 ASSERTL0(varChild,
"Unable to read variable definition body for "
2203 "variable with ID " +
2204 boost::lexical_cast<string>(i) +
2205 " in XML element: \n\t'" + tagcontent.str() +
2207 std::string variableName = varChild->ToText()->ValueStr();
2209 std::istringstream variableStrm(variableName);
2210 variableStrm >> variableName;
2213 variableName) == m_variables.end(),
2214 "Variable with ID " + boost::lexical_cast<string>(i) +
2215 " in XML element \n\t'" + tagcontent.str() +
2216 "'\nhas already been defined.");
2218 m_variables.push_back(variableName);
2220 varElement = varElement->NextSiblingElement(
"V");
2224 "Number of variables must be greater than zero.");
2231 void SessionReader::ReadFunctions(TiXmlElement *conditions)
2233 m_functions.clear();
2241 TiXmlElement *
function = conditions->FirstChildElement(
"FUNCTION");
2244 stringstream tagcontent;
2245 tagcontent << *
function;
2248 ASSERTL0(function->Attribute(
"NAME"),
2249 "Functions must have a NAME attribute defined in XML "
2251 tagcontent.str() +
"'");
2252 std::string functionStr =
function->Attribute(
"NAME");
2254 "Functions must have a non-empty name in XML "
2256 tagcontent.str() +
"'");
2259 boost::to_upper(functionStr);
2262 TiXmlElement *variable =
function->FirstChildElement();
2271 std::string conditionType = variable->Value();
2274 std::string variableStr;
2275 if (!variable->Attribute(
"VAR"))
2281 variableStr = variable->Attribute(
"VAR");
2285 std::vector<std::string> variableList;
2286 ParseUtils::GenerateVector(variableStr, variableList);
2289 std::string domainStr;
2290 if (!variable->Attribute(
"DOMAIN"))
2296 domainStr = variable->Attribute(
"DOMAIN");
2300 std::string evarsStr =
"x y z t";
2301 if (variable->Attribute(
"EVARS"))
2304 evarsStr + std::string(
" ") + variable->Attribute(
"EVARS");
2308 std::vector<std::string> varSplit;
2309 std::vector<unsigned int> domainList;
2310 ParseUtils::GenerateSeqVector(domainStr, domainList);
2313 if (conditionType ==
"E")
2318 ASSERTL0(variable->Attribute(
"VALUE"),
2319 "Attribute VALUE expected for function '" +
2320 functionStr +
"'.");
2321 std::string fcnStr = variable->Attribute(
"VALUE");
2324 (std::string(
"Expression for var: ") + variableStr +
2325 std::string(
" must be specified."))
2328 SubstituteExpressions(fcnStr);
2333 m_interpreter, fcnStr, evarsStr);
2337 else if (conditionType ==
"F")
2339 if (variable->Attribute(
"TIMEDEPENDENT") &&
2340 boost::lexical_cast<bool>(
2341 variable->Attribute(
"TIMEDEPENDENT")))
2351 ASSERTL0(variable->Attribute(
"FILE"),
2352 "Attribute FILE expected for function '" +
2353 functionStr +
"'.");
2354 std::string filenameStr = variable->Attribute(
"FILE");
2357 "A filename must be specified for the FILE "
2358 "attribute of function '" +
2359 functionStr +
"'.");
2361 std::vector<std::string> fSplit;
2362 boost::split(fSplit, filenameStr, boost::is_any_of(
":"));
2364 ASSERTL0(fSplit.size() == 1 || fSplit.size() == 2,
2365 "Incorrect filename specification in function " +
2368 "Specify variables inside file as: "
2369 "filename:var1,var2");
2372 fs::path fullpath = fSplit[0];
2373 fs::path ftype = fullpath.extension();
2374 if (fullpath.parent_path().extension() ==
".pit")
2376 string filename = fullpath.stem().string();
2377 fullpath = fullpath.parent_path();
2378 size_t start = filename.find_last_of(
"_") + 1;
2380 atoi(filename.substr(start, filename.size()).c_str());
2381 fullpath /= filename.substr(0, start) +
2383 index + m_comm->GetTimeComm()->GetRank()) +
2388 if (fSplit.size() == 2)
2391 "Filename variable mapping not valid "
2392 "when using * as a variable inside "
2394 functionStr +
"'.");
2396 boost::split(varSplit, fSplit[1], boost::is_any_of(
","));
2397 ASSERTL0(varSplit.size() == variableList.size(),
2398 "Filename variables should contain the "
2399 "same number of variables defined in "
2400 "VAR in function " +
2401 functionStr +
"'.");
2408 stringstream tagcontent;
2409 tagcontent << *variable;
2412 "Identifier " + conditionType +
" in function " +
2413 std::string(function->Attribute(
"NAME")) +
2414 " is not recognised in XML element: \n\t'" +
2415 tagcontent.str() +
"'");
2419 for (
unsigned int i = 0; i < variableList.size(); ++i)
2421 for (
unsigned int j = 0; j < domainList.size(); ++j)
2424 pair<std::string, int> key(variableList[i], domainList[j]);
2425 auto fcnsIter = functionVarMap.find(key);
2427 fcnsIter == functionVarMap.end(),
2428 "Error setting expression '" + variableList[i] +
2430 boost::lexical_cast<std::string>(domainList[j]) +
2431 "' in function '" + functionStr +
2433 "Expression has already been defined.");
2435 if (varSplit.size() > 0)
2439 functionVarMap[key] = funcDef2;
2443 functionVarMap[key] = funcDef;
2448 variable = variable->NextSiblingElement();
2451 m_functions[functionStr] = functionVarMap;
2452 function =
function->NextSiblingElement(
"FUNCTION");
2459 void SessionReader::ReadFilters(TiXmlElement *filters)
2468 TiXmlElement *filter = filters->FirstChildElement(
"FILTER");
2471 ASSERTL0(filter->Attribute(
"TYPE"),
2472 "Missing attribute 'TYPE' for filter.");
2473 std::string typeStr = filter->Attribute(
"TYPE");
2475 std::map<std::string, std::string> vParams;
2477 TiXmlElement *param = filter->FirstChildElement(
"PARAM");
2481 "Missing attribute 'NAME' for parameter in filter " +
2483 std::string nameStr = param->Attribute(
"NAME");
2485 ASSERTL0(param->GetText(),
"Empty value string for param.");
2486 std::string valueStr = param->GetText();
2488 vParams[nameStr] = valueStr;
2490 param = param->NextSiblingElement(
"PARAM");
2493 m_filters.push_back(
2494 std::pair<std::string, FilterParams>(typeStr, vParams));
2496 filter = filter->NextSiblingElement(
"FILTER");
2500 void SessionReader::ParseEquals(
const std::string &line, std::string &lhs,
2504 size_t beg = line.find_first_not_of(
" ");
2505 size_t end = line.find_first_of(
"=");
2510 if (end != line.find_last_of(
"="))
2513 if (end == std::string::npos)
2516 lhs = line.substr(line.find_first_not_of(
" "), end - beg);
2517 lhs = lhs.substr(0, lhs.find_last_not_of(
" ") + 1);
2518 rhs = line.substr(line.find_last_of(
"=") + 1);
2519 rhs = rhs.substr(rhs.find_first_not_of(
" "));
2520 rhs = rhs.substr(0, rhs.find_last_not_of(
" ") + 1);
2526 void SessionReader::CmdLineOverride()
2529 if (m_cmdLineOptions.count(
"solverinfo"))
2531 std::vector<std::string> solverInfoList =
2532 m_cmdLineOptions[
"solverinfo"].as<std::vector<std::string>>();
2534 for (
size_t i = 0; i < solverInfoList.size(); ++i)
2536 std::string lhs, rhs;
2540 ParseEquals(solverInfoList[i], lhs, rhs);
2544 NEKERROR(ErrorUtil::efatal,
"Parse error with command line "
2549 std::string lhsUpper = boost::to_upper_copy(lhs);
2550 m_solverInfo[lhsUpper] = rhs;
2554 if (m_cmdLineOptions.count(
"parameter"))
2556 std::vector<std::string> parametersList =
2557 m_cmdLineOptions[
"parameter"].as<std::vector<std::string>>();
2559 for (
size_t i = 0; i < parametersList.size(); ++i)
2561 std::string lhs, rhs;
2565 ParseEquals(parametersList[i], lhs, rhs);
2569 NEKERROR(ErrorUtil::efatal,
"Parse error with command line "
2574 std::string lhsUpper = boost::to_upper_copy(lhs);
2578 m_parameters[lhsUpper] = boost::lexical_cast<NekDouble>(rhs);
2582 NEKERROR(ErrorUtil::efatal,
"Unable to convert string: " + rhs +
2583 "to double value.");
2589 void SessionReader::VerifySolverInfo()
2591 for (
auto &x : m_solverInfo)
2593 std::string solverProperty = x.first;
2594 std::string solverValue = x.second;
2596 auto propIt = GetSolverInfoEnums().find(solverProperty);
2597 if (propIt != GetSolverInfoEnums().end())
2599 auto valIt = propIt->second.find(solverValue);
2600 ASSERTL0(valIt != propIt->second.end(),
"Value '" + solverValue +
2601 "' is not valid for "
2603 solverProperty +
"'");
2610 return m_interpreter;
2618 std::string elementName,
2619 const TiXmlHandle &docHandle)
2621 TiXmlElement *element = docHandle.FirstChildElement(elementName).Element();
2628 NEKERROR(ErrorUtil::efatal,
"Unable to find '" + elementName +
2629 "' XML node in " + filename);
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
NekDouble Evaluate() const
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static void Finalise(gs_data *pGsh)
Deallocates the GSLib mapping data.
std::shared_ptr< Interpreter > InterpreterSharedPtr
std::map< std::string, std::string > SolverInfoMap
std::map< std::string, GloSysInfoMap > GloSysSolnInfoList
std::map< std::pair< std::string, int >, FunctionVariableDefinition > FunctionVariableMap
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
std::map< std::string, NekDouble > ParameterMap
std::shared_ptr< Equation > EquationSharedPtr
TiXmlElement * GetChildElementOrThrow(const std::string &filename, std::string elementName, const TiXmlHandle &docHandle)
std::map< std::string, EnumMap > EnumMapList
std::vector< std::pair< std::string, FilterParams > > FilterMap
CommFactory & GetCommFactory()
std::map< std::string, CmdLineArg > CmdLineArgMap
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
@ eFunctionTypeExpression
@ eFunctionTypeTransientFile
const std::string kGitBranch
const std::string kGitSha1
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
The above copyright notice and this permission notice shall be included.
EquationSharedPtr m_expression
std::string m_fileVariable