48 #include <boost/iostreams/filtering_streambuf.hpp>
49 #include <boost/iostreams/copy.hpp>
50 #include <boost/iostreams/filter/gzip.hpp>
51 #include <boost/algorithm/string.hpp>
60 #include <boost/program_options.hpp>
61 #include <boost/format.hpp>
63 #ifndef NEKTAR_VERSION
64 #define NEKTAR_VERSION "Unknown"
67 namespace po = boost::program_options;
68 namespace io = boost::iostreams;
72 namespace LibUtilities
128 return solverInfoEnums;
143 return solverInfoMap;
159 return gloSysSolnInfoList;
173 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"] =
204 "IterativeStaticCond";
212 SessionReader::SessionReader(
215 const std::vector<std::string> &pFilenames,
218 ASSERTL0(pFilenames.size() > 0,
"No filenames specified.");
220 ParseCommandLineArguments(argc, argv);
222 m_filenames = pFilenames;
224 m_sessionName = ParseSessionName(m_filenames);
229 CreateComm(argc, argv);
235 if (m_comm->GetSize() > 1)
237 GetSolverInfoDefaults()[
"GLOBALSYSSOLN"] =
238 "IterativeStaticCond";
242 TestSharedFilesystem();
246 if (m_comm->GetSize() > 1)
248 GetSolverInfoDefaults()[
"GLOBALSYSSOLN"] =
249 "IterativeStaticCond";
257 SessionReader::~SessionReader()
269 void SessionReader::InitSession()
271 m_exprEvaluator.SetRandomSeed((m_comm->GetRank() + 1) * time(NULL));
290 if (m_verbose && m_comm)
292 if (m_comm->TreatAsRankZero() && m_parameters.size() > 0)
294 cout <<
"Parameters:" << endl;
296 for (x = m_parameters.begin(); x != m_parameters.end(); ++x)
298 cout <<
"\t" << x->first <<
" = " << x->second << endl;
303 if (m_comm->TreatAsRankZero() && m_solverInfo.size() > 0)
305 cout <<
"Solver Info:" << endl;
307 for (x = m_solverInfo.begin(); x != m_solverInfo.end(); ++x)
309 cout <<
"\t" << x->first <<
" = " << x->second << endl;
317 void SessionReader::TestSharedFilesystem()
319 m_sharedFilesystem =
false;
321 if (m_comm->GetSize() > 1)
323 if (m_comm->GetRank() == 0)
325 std::ofstream testfile(
"shared-fs-testfile");
326 testfile <<
"" << std::endl;
327 ASSERTL1(!testfile.fail(),
"Test file creation failed");
332 int exists = (bool)boost::filesystem::exists(
"shared-fs-testfile");
335 m_sharedFilesystem = (exists == m_comm->GetSize());
337 if ((m_sharedFilesystem && m_comm->GetRank() == 0) ||
340 std::remove(
"shared-fs-testfile");
345 m_sharedFilesystem =
false;
348 if (m_verbose && m_comm->GetRank() == 0 && m_sharedFilesystem)
350 cout <<
"Shared filesystem detected" << endl;
359 std::vector<std::string> SessionReader::ParseCommandLineArguments(
360 int argc,
char *argv[])
363 po::options_description desc(
"Allowed options");
365 (
"verbose,v",
"be verbose")
366 (
"version,V",
"print version information")
367 (
"help,h",
"print this help message")
368 (
"solverinfo,I", po::value<vector<std::string> >(),
369 "override a SOLVERINFO property")
370 (
"parameter,P", po::value<vector<std::string> >(),
371 "override a parameter")
372 (
"npx", po::value<int>(),
373 "number of procs in X-dir")
374 (
"npy", po::value<int>(),
375 "number of procs in Y-dir")
376 (
"npz", po::value<int>(),
377 "number of procs in Z-dir")
378 (
"nsz", po::value<int>(),
379 "number of slices in Z-dir")
380 (
"part-only", po::value<int>(),
381 "only partition mesh into N partitions.")
382 (
"part-only-overlapping", po::value<int>(),
383 "only partition mesh into N overlapping partitions.")
384 (
"part-info",
"Output partition information")
387 CmdLineArgMap::const_iterator cmdIt;
388 for (cmdIt = GetCmdLineArgMap().begin();
389 cmdIt != GetCmdLineArgMap().end(); ++cmdIt)
391 std::string names = cmdIt->first;
392 if (cmdIt->second.shortName !=
"")
394 names +=
"," + cmdIt->second.shortName;
396 if (cmdIt->second.isFlag)
399 (names.c_str(), cmdIt->second.description.c_str())
405 (names.c_str(), po::value<std::string>(),
406 cmdIt->second.description.c_str())
413 po::options_description hidden(
"Hidden options");
415 (
"input-file", po::value< vector<string> >(),
420 po::options_description all(
"All options");
421 all.add(desc).add(hidden);
424 po::positional_options_description
p;
425 p.add(
"input-file", -1);
428 po::parsed_options parsed = po::command_line_parser(argc, argv).
431 allow_unregistered().
435 po::store(parsed, m_cmdLineOptions);
436 po::notify(m_cmdLineOptions);
439 if (m_cmdLineOptions.count(
"help"))
446 if (m_cmdLineOptions.count(
"version"))
454 boost::replace_all(branch,
"refs/heads/",
"");
456 cout <<
" (git changeset " << sha1.substr(0, 8) <<
", ";
460 cout <<
"detached head";
464 cout <<
"head " << branch;
475 if (m_cmdLineOptions.count(
"verbose"))
485 std::vector< po::basic_option<char> >
::iterator x;
486 for (x = parsed.options.begin(); x != parsed.options.end(); ++x)
490 cout <<
"Warning: Unknown option: " << x->string_key
496 if (m_cmdLineOptions.count(
"input-file"))
498 return m_cmdLineOptions[
"input-file"].as<
499 std::vector<std::string> >();
503 return std::vector<std::string>();
511 std::string SessionReader::ParseSessionName(
512 std::vector<std::string> &filenames)
515 "At least one filename expected.");
517 std::string retval =
"";
520 std::string fname = filenames[0];
523 if (fname.size() > 4 &&
524 fname.substr(fname.size() - 4, 4) ==
"_xml")
526 retval = fname.substr(0, fname.find_last_of(
"_"));
529 else if (fname.size() > 4 &&
530 fname.substr(fname.size() - 4, 4) ==
".xml")
532 retval = fname.substr(0, fname.find_last_of(
"."));
535 else if (fname.size() > 7 &&
536 fname.substr(fname.size() - 7, 7) ==
".xml.gz")
538 retval = fname.substr(0, fname.find_last_of(
"."));
539 retval = retval.substr(0, retval.find_last_of(
"."));
549 TiXmlDocument& SessionReader::GetDocument()
551 ASSERTL1(m_xmlDoc,
"XML Document not defined.");
578 TiXmlElement* SessionReader::GetElement(
const string& pPath)
580 std::string vPath = boost::to_upper_copy(pPath);
581 std::vector<std::string> st;
582 boost::split(st, vPath, boost::is_any_of(
"\\/ "));
583 ASSERTL0(st.size() > 0,
"No path given in XML element request.");
585 TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
586 ASSERTL0(vReturn, std::string(
"Cannot find element '")
587 + st[0] + std::string(
"'."));
588 for (
int i = 1; i < st.size(); ++i)
590 vReturn = vReturn->FirstChildElement(st[i].c_str());
591 ASSERTL0(vReturn, std::string(
"Cannot find element '")
592 + st[i] + std::string(
"'."));
601 bool SessionReader::DefinesElement(
const std::string &pPath)
const
603 std::string vPath = boost::to_upper_copy(pPath);
604 std::vector<std::string> st;
605 boost::split(st, vPath, boost::is_any_of(
"\\/ "));
606 ASSERTL0(st.size() > 0,
"No path given in XML element request.");
608 TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
609 ASSERTL0(vReturn, std::string(
"Cannot find element '")
610 + st[0] + std::string(
"'."));
611 for (
int i = 1; i < st.size(); ++i)
613 vReturn = vReturn->FirstChildElement(st[i].c_str());
614 if (!vReturn)
return false;
623 const std::vector<std::string>& SessionReader::GetFilenames()
const
632 const std::string& SessionReader::GetSessionName()
const
634 return m_sessionName;
642 const std::string SessionReader::GetSessionNameRank()
const
644 std::string dirname = m_sessionName +
"_xml";
645 fs::path pdirname(dirname);
647 std::string vFilename =
"P" + boost::lexical_cast<std::string>(m_comm->GetRowComm()->GetRank());
648 fs::path pFilename(vFilename);
650 fs::path fullpath = pdirname / pFilename;
663 bool SessionReader::GetSharedFilesystem()
665 return m_sharedFilesystem;
683 bool SessionReader::DefinesParameter(
const std::string& pName)
const
685 std::string vName = boost::to_upper_copy(pName);
686 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
687 return (paramIter != m_parameters.end());
700 const std::string& pName)
const
702 std::string vName = boost::to_upper_copy(pName);
703 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
705 ASSERTL0(paramIter != m_parameters.end(),
706 "Unable to find requested parameter: " + pName);
708 return paramIter->second;
715 void SessionReader::LoadParameter(
716 const std::string &pName,
int &pVar)
const
718 std::string vName = boost::to_upper_copy(pName);
719 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
720 ASSERTL0(paramIter != m_parameters.end(),
"Required parameter '" +
721 pName +
"' not specified in session.");
722 pVar = (int)floor(paramIter->second);
729 void SessionReader::LoadParameter(
730 const std::string &pName,
int &pVar,
const int &pDefault)
const
732 std::string vName = boost::to_upper_copy(pName);
733 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
734 if(paramIter != m_parameters.end())
736 pVar = (int)floor(paramIter->second);
748 void SessionReader::LoadParameter(
749 const std::string &pName,
NekDouble& pVar)
const
751 std::string vName = boost::to_upper_copy(pName);
752 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
753 ASSERTL0(paramIter != m_parameters.end(),
"Required parameter '" +
754 pName +
"' not specified in session.");
755 pVar = paramIter->second;
762 void SessionReader::LoadParameter(
763 const std::string &pName,
767 std::string vName = boost::to_upper_copy(pName);
768 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
769 if(paramIter != m_parameters.end())
771 pVar = paramIter->second;
784 void SessionReader::SetParameter(
const std::string &pName,
int &pVar)
786 std::string vName = boost::to_upper_copy(pName);
787 m_parameters[vName] = pVar;
794 void SessionReader::SetParameter(
795 const std::string &pName,
NekDouble& pVar)
797 std::string vName = boost::to_upper_copy(pName);
798 m_parameters[vName] = pVar;
806 bool SessionReader::DefinesSolverInfo(
const std::string &pName)
const
808 std::string vName = boost::to_upper_copy(pName);
809 SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
810 return (infoIter != m_solverInfo.end());
817 const std::string& SessionReader::GetSolverInfo(
818 const std::string &pProperty)
const
820 std::string vProperty = boost::to_upper_copy(pProperty);
821 SolverInfoMap::const_iterator iter = m_solverInfo.find(vProperty);
823 ASSERTL1(iter != m_solverInfo.end(),
824 "Unable to find requested property: " + pProperty);
832 void SessionReader::SetSolverInfo(
833 const std::string &pProperty,
const std::string &pValue)
835 std::string vProperty = boost::to_upper_copy(pProperty);
838 ASSERTL1(iter != m_solverInfo.end(),
839 "Unable to find requested property: " + pProperty);
841 iter->second = pValue;
847 void SessionReader::LoadSolverInfo(
848 const std::string &pName,
850 const std::string &pDefault)
const
852 std::string vName = boost::to_upper_copy(pName);
853 SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
854 if(infoIter != m_solverInfo.end())
856 pVar = infoIter->second;
868 void SessionReader::MatchSolverInfo(
869 const std::string &pName,
870 const std::string &pTrueVal,
872 const bool &pDefault)
const
874 std::string vName = boost::to_upper_copy(pName);
875 SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
876 if(infoIter != m_solverInfo.end())
878 pVar = boost::iequals(infoIter->second, pTrueVal);
890 bool SessionReader::MatchSolverInfo(
891 const std::string &pName,
892 const std::string &pTrueVal)
const
894 if (DefinesSolverInfo(pName))
896 std::string vName = boost::to_upper_copy(pName);
897 SolverInfoMap::const_iterator iter = m_solverInfo.find(vName);
898 if(iter != m_solverInfo.end())
910 bool SessionReader::DefinesGlobalSysSolnInfo(
const std::string &pVariable,
911 const std::string &pProperty)
const
914 GloSysSolnInfoList::const_iterator iter =
915 GetGloSysSolnList().find(pVariable);
916 if(iter == GetGloSysSolnList().end())
921 std::string vProperty = boost::to_upper_copy(pProperty);
923 GloSysInfoMap::const_iterator iter1 = iter->second.find(vProperty);
924 if(iter1 == iter->second.end())
936 const std::string &SessionReader::GetGlobalSysSolnInfo(
const std::string &pVariable,
const std::string &pProperty)
const
938 GloSysSolnInfoList::const_iterator iter;
940 ASSERTL0( (iter = GetGloSysSolnList().
find(pVariable)) !=
941 GetGloSysSolnList().end(),
942 "Failed to find variable in GlobalSysSolnInfoList");
944 std::string vProperty = boost::to_upper_copy(pProperty);
945 GloSysInfoMap::const_iterator iter1;
947 ASSERTL0( (iter1 = iter->second.find(vProperty)) != iter->second.end(),
948 "Failed to find property: " + vProperty +
" in GlobalSysSolnInfoList");
950 return iter1->second;
956 bool SessionReader::DefinesGeometricInfo(
const std::string &pName)
const
958 std::string vName = boost::to_upper_copy(pName);
959 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
960 return (iter != m_geometricInfo.end());
967 void SessionReader::LoadGeometricInfo(
968 const std::string &pName,
970 const std::string &pDefault)
const
972 std::string vName = boost::to_upper_copy(pName);
973 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
974 if(iter != m_geometricInfo.end())
988 void SessionReader::LoadGeometricInfo(
989 const std::string &pName,
991 const bool &pDefault)
const
993 std::string vName = boost::to_upper_copy(pName);
994 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
995 if(iter != m_geometricInfo.end())
997 if (iter->second ==
"TRUE")
1016 void SessionReader::LoadGeometricInfo(
1017 const std::string &pName,
1021 std::string vName = boost::to_upper_copy(pName);
1022 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
1023 if(iter != m_geometricInfo.end())
1025 pVar = std::atoi(iter->second.c_str());
1037 void SessionReader::MatchGeometricInfo(
1038 const std::string &pName,
1039 const std::string &pTrueVal,
1041 const bool &pDefault)
const
1043 std::string vName = boost::to_upper_copy(pName);
1044 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
1045 if(iter != m_geometricInfo.end())
1047 pVar = boost::iequals(iter->second, pTrueVal);
1059 const std::string& SessionReader::GetVariable(
1060 const unsigned int &idx)
const
1062 ASSERTL0(idx < m_variables.size(),
"Variable index out of range.");
1063 return m_variables[idx];
1071 void SessionReader::SetVariable(
const unsigned int &idx,
1072 std::string newname)
1074 ASSERTL0(idx < m_variables.size(),
"Variable index out of range.");
1075 m_variables[idx] = newname;
1082 std::vector<std::string> SessionReader::GetVariables()
const
1091 bool SessionReader::DefinesFunction(
const std::string &pName)
const
1093 FunctionMap::const_iterator it1;
1094 std::string vName = boost::to_upper_copy(pName);
1096 if ((it1 = m_functions.find(vName)) != m_functions.end())
1107 bool SessionReader::DefinesFunction(
1108 const std::string &pName,
1109 const std::string &pVariable,
1110 const int pDomain)
const
1112 FunctionMap::const_iterator it1;
1113 FunctionVariableMap::const_iterator it2;
1114 std::string vName = boost::to_upper_copy(pName);
1117 if ((it1 = m_functions.find(vName)) != m_functions.end())
1119 pair<std::string, int> key(pVariable,pDomain);
1120 pair<std::string, int> defkey(
"*",pDomain);
1122 (it2 = it1->second.find(key)) != it1->second.end() ||
1123 (it2 = it1->second.find(defkey)) != it1->second.end();
1134 const std::string &pName,
1135 const std::string &pVariable,
1136 const int pDomain)
const
1138 FunctionMap::const_iterator it1;
1139 FunctionVariableMap::const_iterator it2, it3;
1140 std::string vName = boost::to_upper_copy(pName);
1142 ASSERTL0((it1 = m_functions.find(vName)) != m_functions.end(),
1143 std::string(
"No such function '") + pName
1144 + std::string(
"' has been defined in the session file."));
1147 pair<std::string,int> key(pVariable,pDomain);
1148 pair<std::string,int> defkey(
"*",pDomain);
1149 bool specific = (it2 = it1->second.find(key)) !=
1151 bool wildcard = (it3 = it1->second.find(defkey)) !=
1156 "No such variable " + pVariable
1157 +
" in domain " + boost::lexical_cast<string>(pDomain)
1158 +
" defined for function " + pName
1159 +
" in session file.");
1168 std::string(
"Function is defined by a file."));
1169 return it2->second.m_expression;
1177 const std::string &pName,
1178 const unsigned int &pVar,
1179 const int pDomain)
const
1181 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1182 return GetFunction(pName, m_variables[pVar],pDomain);
1190 const std::string &pName,
1191 const std::string &pVariable,
1192 const int pDomain)
const
1194 FunctionMap::const_iterator it1;
1195 FunctionVariableMap::const_iterator it2, it3;
1196 std::string vName = boost::to_upper_copy(pName);
1198 it1 = m_functions.find(vName);
1199 ASSERTL0 (it1 != m_functions.end(),
1200 std::string(
"Function '") + pName
1201 + std::string(
"' not found."));
1204 pair<std::string,int> key(pVariable,pDomain);
1205 pair<std::string,int> defkey(
"*",pDomain);
1206 bool specific = (it2 = it1->second.find(key)) !=
1208 bool wildcard = (it3 = it1->second.find(defkey)) !=
1213 "No such variable " + pVariable
1214 +
" in domain " + boost::lexical_cast<string>(pDomain)
1215 +
" defined for function " + pName
1216 +
" in session file.");
1224 return it2->second.m_type;
1232 const std::string &pName,
1233 const unsigned int &pVar,
1234 const int pDomain)
const
1236 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1237 return GetFunctionType(pName, m_variables[pVar],pDomain);
1244 std::string SessionReader::GetFunctionFilename(
1245 const std::string &pName,
1246 const std::string &pVariable,
1247 const int pDomain)
const
1249 FunctionMap::const_iterator it1;
1250 FunctionVariableMap::const_iterator it2, it3;
1251 std::string vName = boost::to_upper_copy(pName);
1253 it1 = m_functions.find(vName);
1254 ASSERTL0 (it1 != m_functions.end(),
1255 std::string(
"Function '") + pName
1256 + std::string(
"' not found."));
1259 pair<std::string,int> key(pVariable,pDomain);
1260 pair<std::string,int> defkey(
"*",pDomain);
1261 bool specific = (it2 = it1->second.find(key)) !=
1263 bool wildcard = (it3 = it1->second.find(defkey)) !=
1268 "No such variable " + pVariable
1269 +
" in domain " + boost::lexical_cast<string>(pDomain)
1270 +
" defined for function " + pName
1271 +
" in session file.");
1279 return it2->second.m_filename;
1286 std::string SessionReader::GetFunctionFilename(
1287 const std::string &pName,
1288 const unsigned int &pVar,
1289 const int pDomain)
const
1291 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1292 return GetFunctionFilename(pName, m_variables[pVar],pDomain);
1299 std::string SessionReader::GetFunctionFilenameVariable(
1300 const std::string &pName,
1301 const std::string &pVariable,
1302 const int pDomain)
const
1304 FunctionMap::const_iterator it1;
1305 FunctionVariableMap::const_iterator it2, it3;
1306 std::string vName = boost::to_upper_copy(pName);
1308 it1 = m_functions.find(vName);
1309 ASSERTL0 (it1 != m_functions.end(),
1310 std::string(
"Function '") + pName
1311 + std::string(
"' not found."));
1314 pair<std::string,int> key(pVariable,pDomain);
1315 pair<std::string,int> defkey(
"*",pDomain);
1316 bool specific = (it2 = it1->second.find(key)) !=
1318 bool wildcard = (it3 = it1->second.find(defkey)) !=
1323 "No such variable " + pVariable
1324 +
" in domain " + boost::lexical_cast<string>(pDomain)
1325 +
" defined for function " + pName
1326 +
" in session file.");
1334 return it2->second.m_fileVariable;
1343 return m_exprEvaluator;
1350 bool SessionReader::DefinesTag(
const std::string &pName)
const
1352 std::string vName = boost::to_upper_copy(pName);
1353 TagMap::const_iterator vTagIterator = m_tags.find(vName);
1354 return (vTagIterator != m_tags.end());
1361 void SessionReader::SetTag(
1362 const std::string &pName,
1363 const std::string &pValue)
1365 std::string vName = boost::to_upper_copy(pName);
1366 m_tags[vName] = pValue;
1373 const std::string &SessionReader::GetTag(
const std::string& pName)
const
1375 std::string vName = boost::to_upper_copy(pName);
1376 TagMap::const_iterator vTagIterator = m_tags.find(vName);
1377 ASSERTL0(vTagIterator != m_tags.end(),
1378 "Requested tag does not exist.");
1379 return vTagIterator->second;
1395 bool SessionReader::DefinesCmdLineArgument(
1396 const std::string& pName)
const
1398 return (m_cmdLineOptions.find(pName) != m_cmdLineOptions.end());
1405 void SessionReader::SubstituteExpressions(std::string& pExpr)
1408 for (exprIter = m_expressions.begin();
1409 exprIter != m_expressions.end(); ++exprIter)
1411 boost::replace_all(pExpr, exprIter->first, exprIter->second);
1422 return m_bndRegOrder;
1428 void SessionReader::LoadDoc(
1429 const std::string &pFilename,
1430 TiXmlDocument* pDoc)
const
1432 if (pFilename.size() > 3 &&
1433 pFilename.substr(pFilename.size() - 3, 3) ==
".gz")
1435 ifstream file(pFilename.c_str(),
1436 ios_base::in | ios_base::binary);
1437 ASSERTL0(file.good(),
"Unable to open file: " + pFilename);
1439 io::filtering_streambuf<io::input> in;
1440 in.push(io::gzip_decompressor());
1447 catch (io::gzip_error& e)
1450 "Error: File '" + pFilename +
"' is corrupt.");
1453 else if (pFilename.size() > 4 &&
1454 pFilename.substr(pFilename.size() - 4, 4) ==
"_xml")
1456 fs::path pdirname(pFilename);
1458 pad % m_comm->GetRank();
1459 fs::path pRankFilename(pad.str());
1460 fs::path fullpath = pdirname / pRankFilename;
1463 ASSERTL0(file.good(),
"Unable to open file: " + fullpath.string());
1468 ifstream file(pFilename.c_str());
1469 ASSERTL0(file.good(),
"Unable to open file: " + pFilename);
1477 TiXmlDocument *SessionReader::MergeDoc(
1478 const std::vector<std::string> &pFilenames)
const
1480 ASSERTL0(pFilenames.size() > 0,
"No filenames for merging.");
1483 TiXmlDocument *vMainDoc =
new TiXmlDocument;
1484 LoadDoc(pFilenames[0], vMainDoc);
1486 TiXmlHandle vMainHandle(vMainDoc);
1487 TiXmlElement* vMainNektar =
1488 vMainHandle.FirstChildElement(
"NEKTAR").Element();
1493 for (
int i = 1; i < pFilenames.size(); ++i)
1495 if((pFilenames[i].compare(pFilenames[i].size()-3,3,
"xml") == 0)
1496 ||(pFilenames[i].compare(pFilenames[i].size()-6,6,
"xml.gz") == 0))
1498 TiXmlDocument* vTempDoc =
new TiXmlDocument;
1499 LoadDoc(pFilenames[i], vTempDoc);
1501 TiXmlHandle docHandle(vTempDoc);
1502 TiXmlElement* vTempNektar;
1503 vTempNektar = docHandle.FirstChildElement(
"NEKTAR").Element();
1504 ASSERTL0(vTempNektar,
"Unable to find NEKTAR tag in file.");
1505 TiXmlElement*
p = vTempNektar->FirstChildElement();
1509 TiXmlElement *vMainEntry =
1510 vMainNektar->FirstChildElement(p->Value());
1513 if (!p->FirstChild() && vMainEntry)
1515 std::string warningmsg =
1516 "File " + pFilenames[i] +
" contains " +
1517 "an empty XML element " +
1518 std::string(p->Value()) +
1519 " which will be ignored.";
1526 vMainNektar->RemoveChild(vMainEntry);
1528 TiXmlElement *q =
new TiXmlElement(*p);
1529 vMainNektar->LinkEndChild(q);
1531 p = p->NextSiblingElement();
1544 void SessionReader::ParseDocument()
1547 ASSERTL0(m_xmlDoc,
"No XML document loaded.");
1550 TiXmlHandle docHandle(m_xmlDoc);
1552 e = docHandle.FirstChildElement(
"NEKTAR").
1553 FirstChildElement(
"CONDITIONS").Element();
1558 ReadGlobalSysSolnInfo (e);
1559 ReadExpressions (e);
1563 e = docHandle.FirstChildElement(
"NEKTAR").
1564 FirstChildElement(
"FILTERS").Element();
1573 void SessionReader::CreateComm(
1583 string vCommModule(
"Serial");
1586 vCommModule =
"ParallelMPI";
1597 void SessionReader::PartitionMesh()
1599 ASSERTL0(m_comm.get(),
"Communication not initialised.");
1603 const bool isRoot = m_comm->TreatAsRankZero();
1619 int isPartitioned = 0;
1622 m_xmlDoc = MergeDoc(m_filenames);
1623 if (DefinesElement(
"Nektar/Geometry"))
1625 if (GetElement(
"Nektar/Geometry")->Attribute(
"PARTITION"))
1627 cout <<
"Using pre-partitioned mesh." << endl;
1632 GetComm()->Bcast(isPartitioned, 0);
1640 m_xmlDoc = MergeDoc(m_filenames);
1648 string vPartitionerName =
"Metis";
1651 vPartitionerName =
"Scotch";
1653 if (DefinesCmdLineArgument(
"use-metis"))
1655 vPartitionerName =
"Metis";
1657 if (DefinesCmdLineArgument(
"use-scotch"))
1659 vPartitionerName =
"Scotch";
1665 if (DefinesCmdLineArgument(
"part-only")||
1666 DefinesCmdLineArgument(
"part-only-overlapping"))
1671 "The 'part-only' option should be used in serial.");
1678 vPartitionerName, vSession);
1679 if(DefinesCmdLineArgument(
"part-only"))
1681 nParts = GetCmdLineArgument<int>(
"part-only");
1682 vPartitioner->PartitionMesh(nParts,
true);
1686 nParts = GetCmdLineArgument<int>(
"part-only-overlapping");
1687 vPartitioner->PartitionMesh(nParts,
true,
true);
1689 vPartitioner->WriteAllPartitions(vSession);
1690 vPartitioner->GetCompositeOrdering(m_compOrder);
1691 vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
1693 if (isRoot && DefinesCmdLineArgument(
"part-info"))
1695 vPartitioner->PrintPartInfo(std::cout);
1701 else if (vCommMesh->GetSize() > 1)
1704 int nParts = vCommMesh->GetSize();
1705 if (m_sharedFilesystem)
1708 vector<unsigned int> keys, vals;
1713 m_xmlDoc = MergeDoc(m_filenames);
1717 vPartitionerName, vSession);
1718 vPartitioner->PartitionMesh(nParts,
true);
1719 vPartitioner->WriteAllPartitions(vSession);
1720 vPartitioner->GetCompositeOrdering(m_compOrder);
1721 vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
1728 keys[0] = m_compOrder.size();
1729 keys[1] = m_bndRegOrder.size();
1730 vComm->Bcast(keys, 0);
1735 keys.resize(m_compOrder.size());
1736 vals.resize(m_compOrder.size());
1738 for (cIt = m_compOrder.begin(), i = 0;
1739 cIt != m_compOrder.end(); ++cIt, ++i)
1741 keys[i] = cIt->first;
1742 vals[i] = cIt->second.size();
1746 vComm->Bcast(keys, 0);
1747 vComm->Bcast(vals, 0);
1748 for (cIt = m_compOrder.begin();
1749 cIt != m_compOrder.end(); ++cIt)
1751 vComm->Bcast(cIt->second, 0);
1757 keys.resize(m_bndRegOrder.size());
1758 vals.resize(m_bndRegOrder.size());
1760 for (bIt = m_bndRegOrder.begin(), i = 0;
1761 bIt != m_bndRegOrder.end(); ++bIt, ++i)
1763 keys[i] = bIt->first;
1764 vals[i] = bIt->second.size();
1768 vComm->Bcast(keys, 0);
1769 vComm->Bcast(vals, 0);
1770 for (bIt = m_bndRegOrder.begin();
1771 bIt != m_bndRegOrder.end(); ++bIt)
1773 vComm->Bcast(bIt->second, 0);
1776 if (DefinesCmdLineArgument(
"part-info"))
1778 vPartitioner->PrintPartInfo(std::cout);
1784 vComm->Bcast(keys, 0);
1786 int cmpSize = keys[0];
1787 int bndSize = keys[1];
1789 keys.resize(cmpSize);
1790 vals.resize(cmpSize);
1791 vComm->Bcast(keys, 0);
1792 vComm->Bcast(vals, 0);
1794 for (
int i = 0; i < keys.size(); ++i)
1796 vector<unsigned int> tmp(vals[i]);
1797 vComm->Bcast(tmp, 0);
1798 m_compOrder[keys[i]] = tmp;
1801 keys.resize(bndSize);
1802 vals.resize(bndSize);
1803 vComm->Bcast(keys, 0);
1804 vComm->Bcast(vals, 0);
1806 for (
int i = 0; i < keys.size(); ++i)
1808 vector<unsigned int> tmp(vals[i]);
1809 vComm->Bcast(tmp, 0);
1810 m_bndRegOrder[keys[i]] = tmp;
1819 m_xmlDoc = MergeDoc(m_filenames);
1827 vPartitionerName, vSession);
1828 vPartitioner->PartitionMesh(nParts,
false);
1829 vPartitioner->WriteLocalPartition(vSession);
1830 vPartitioner->GetCompositeOrdering(m_compOrder);
1831 vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
1833 if (DefinesCmdLineArgument(
"part-info") && isRoot)
1835 vPartitioner->PrintPartInfo(std::cout);
1840 std::string dirname = GetSessionName() +
"_xml";
1841 fs::path pdirname(dirname);
1843 pad % m_comm->GetRowComm()->GetRank();
1844 fs::path pFilename(pad.str());
1845 fs::path fullpath = pdirname / pFilename;
1853 m_xmlDoc =
new TiXmlDocument(vFilename);
1855 ASSERTL0(m_xmlDoc,
"Failed to create XML document object.");
1857 bool loadOkay = m_xmlDoc->LoadFile(vFilename);
1858 ASSERTL0(loadOkay,
"Unable to load file: " + vFilename +
1859 ". Check XML standards compliance. Error on line: " +
1860 boost::lexical_cast<std::string>(m_xmlDoc->Row()));
1864 m_xmlDoc = MergeDoc(m_filenames);
1876 void SessionReader::PartitionComm()
1878 if (m_comm->GetSize() > 1)
1884 if (DefinesCmdLineArgument(
"npx")) {
1885 nProcX = GetCmdLineArgument<int>(
"npx");
1887 if (DefinesCmdLineArgument(
"npy")) {
1888 nProcY = GetCmdLineArgument<int>(
"npy");
1890 if (DefinesCmdLineArgument(
"npz")) {
1891 nProcZ = GetCmdLineArgument<int>(
"npz");
1893 if (DefinesCmdLineArgument(
"nsz")) {
1894 nStripZ = GetCmdLineArgument<int>(
"nsz");
1896 ASSERTL0(m_comm->GetSize() % (nProcZ*nProcY*nProcX) == 0,
1897 "Cannot exactly partition using PROC_Z value.");
1899 "Cannot exactly partition using PROC_Y value.");
1901 "Cannot exactly partition using PROC_X value.");
1904 int nProcSm = nProcZ * nProcY * nProcX;
1908 int nProcSem = m_comm->GetSize() / nProcSm;
1910 m_comm->SplitComm(nProcSm,nProcSem);
1911 m_comm->GetColumnComm()->SplitComm(nProcZ/nStripZ,nStripZ);
1912 m_comm->GetColumnComm()->GetColumnComm()->SplitComm(
1913 (nProcY*nProcX),nProcZ/nStripZ);
1914 m_comm->GetColumnComm()->GetColumnComm()->GetColumnComm()
1915 ->SplitComm(nProcX,nProcY);
1923 void SessionReader::ReadParameters(TiXmlElement *conditions)
1925 m_parameters.clear();
1932 TiXmlElement *parametersElement = conditions->FirstChildElement(
1937 if (parametersElement)
1939 TiXmlElement *parameter =
1940 parametersElement->FirstChildElement(
"P");
1948 stringstream tagcontent;
1949 tagcontent << *parameter;
1950 TiXmlNode *node = parameter->FirstChild();
1952 while (node && node->Type() != TiXmlNode::TINYXML_TEXT)
1954 node = node->NextSibling();
1960 std::string line = node->ToText()->Value(),
lhs, rhs;
1963 ParseEquals(line,
lhs, rhs);
1967 ASSERTL0(
false,
"Syntax error in parameter "
1968 "expression '" + line
1969 +
"' in XML element: \n\t'"
1970 + tagcontent.str() +
"'");
1976 if (!
lhs.empty() && !rhs.empty())
1982 GetSharedThisPtr(), rhs);
1985 catch (
const std::runtime_error &)
1988 "Error evaluating parameter expression"
1989 " '" + rhs +
"' in XML element: \n\t'"
1990 + tagcontent.str() +
"'");
1992 m_exprEvaluator.SetParameter(
lhs, value);
1993 caseSensitiveParameters[
lhs] = value;
1994 boost::to_upper(
lhs);
1995 m_parameters[
lhs] = value;
1999 parameter = parameter->NextSiblingElement();
2008 void SessionReader::ReadSolverInfo(TiXmlElement *conditions)
2010 m_solverInfo.clear();
2011 m_solverInfo = GetSolverInfoDefaults();
2018 TiXmlElement *solverInfoElement =
2019 conditions->FirstChildElement(
"SOLVERINFO");
2021 if (solverInfoElement)
2023 TiXmlElement *solverInfo =
2024 solverInfoElement->FirstChildElement(
"I");
2028 std::stringstream tagcontent;
2029 tagcontent << *solverInfo;
2031 ASSERTL0(solverInfo->Attribute(
"PROPERTY"),
2032 "Missing PROPERTY attribute in solver info "
2033 "XML element: \n\t'" + tagcontent.str() +
"'");
2034 std::string solverProperty =
2035 solverInfo->Attribute(
"PROPERTY");
2037 "PROPERTY attribute must be non-empty in XML "
2038 "element: \n\t'" + tagcontent.str() +
"'");
2041 std::string solverPropertyUpper =
2042 boost::to_upper_copy(solverProperty);
2045 ASSERTL0(solverInfo->Attribute(
"VALUE"),
2046 "Missing VALUE attribute in solver info "
2047 "XML element: \n\t'" + tagcontent.str() +
"'");
2048 std::string solverValue = solverInfo->Attribute(
"VALUE");
2050 "VALUE attribute must be non-empty in XML "
2051 "element: \n\t'" + tagcontent.str() +
"'");
2054 m_solverInfo[solverPropertyUpper] = solverValue;
2055 solverInfo = solverInfo->NextSiblingElement(
"I");
2059 if (m_comm && m_comm->GetRowComm()->GetSize() > 1)
2062 m_solverInfo[
"GLOBALSYSSOLN"] ==
"IterativeFull" ||
2063 m_solverInfo[
"GLOBALSYSSOLN"] ==
"IterativeStaticCond" ||
2064 m_solverInfo[
"GLOBALSYSSOLN"] ==
2065 "IterativeMultiLevelStaticCond" ||
2066 m_solverInfo[
"GLOBALSYSSOLN"] ==
"XxtFull" ||
2067 m_solverInfo[
"GLOBALSYSSOLN"] ==
"XxtStaticCond" ||
2068 m_solverInfo[
"GLOBALSYSSOLN"] ==
2069 "XxtMultiLevelStaticCond" ||
2070 m_solverInfo[
"GLOBALSYSSOLN"] ==
"PETScFull" ||
2071 m_solverInfo[
"GLOBALSYSSOLN"] ==
"PETScStaticCond" ||
2072 m_solverInfo[
"GLOBALSYSSOLN"] ==
2073 "PETScMultiLevelStaticCond",
2074 "A parallel solver must be used when run in parallel.");
2083 void SessionReader::ReadGlobalSysSolnInfo(TiXmlElement *conditions)
2085 GetGloSysSolnList().clear();
2092 TiXmlElement *GlobalSys =
2093 conditions->FirstChildElement(
"GLOBALSYSSOLNINFO");
2100 TiXmlElement *VarInfo = GlobalSys->FirstChildElement(
"V");
2104 std::stringstream tagcontent;
2105 tagcontent << *VarInfo;
2106 ASSERTL0(VarInfo->Attribute(
"VAR"),
2107 "Missing VAR attribute in GobalSysSolnInfo XML "
2108 "element: \n\t'" + tagcontent.str() +
"'");
2110 std::string VarList = VarInfo->Attribute(
"VAR");
2112 "VAR attribute must be non-empty in XML element:\n\t'"
2113 + tagcontent.str() +
"'");
2116 std::vector<std::string> varStrings;
2117 bool valid = ParseUtils::GenerateOrderedStringVector(
2118 VarList.c_str(),varStrings);
2120 ASSERTL0(valid,
"Unable to process list of variable in XML "
2121 "element \n\t'" + tagcontent.str() +
"'");
2123 if(varStrings.size())
2125 TiXmlElement *SysSolnInfo = VarInfo->FirstChildElement(
"I");
2130 tagcontent << *SysSolnInfo;
2132 ASSERTL0(SysSolnInfo->Attribute(
"PROPERTY"),
2133 "Missing PROPERTY attribute in "
2134 "GlobalSysSolnInfo for variable(s) '"
2135 + VarList +
"' in XML element: \n\t'"
2136 + tagcontent.str() +
"'");
2138 std::string SysSolnProperty =
2139 SysSolnInfo->Attribute(
"PROPERTY");
2142 "GlobalSysSolnIno properties must have a "
2143 "non-empty name for variable(s) : '"
2144 + VarList +
"' in XML element: \n\t'"
2145 + tagcontent.str() +
"'");
2148 std::string SysSolnPropertyUpper =
2149 boost::to_upper_copy(SysSolnProperty);
2152 ASSERTL0(SysSolnInfo->Attribute(
"VALUE"),
2153 "Missing VALUE attribute in GlobalSysSolnInfo "
2154 "for variable(s) '" + VarList
2155 +
"' in XML element: \n\t"
2156 + tagcontent.str() +
"'");
2158 std::string SysSolnValue =
2159 SysSolnInfo->Attribute(
"VALUE");
2161 "GlobalSysSolnInfo properties must have a "
2162 "non-empty value for variable(s) '"
2163 + VarList +
"' in XML element: \n\t'"
2164 + tagcontent.str() +
"'");
2167 for(
int i = 0; i < varStrings.size(); ++i)
2170 if ((x = GetGloSysSolnList().
find(varStrings[i])) ==
2171 GetGloSysSolnList().end())
2173 (GetGloSysSolnList()[varStrings[i]])[
2174 SysSolnPropertyUpper] = SysSolnValue;
2178 x->second[SysSolnPropertyUpper] = SysSolnValue;
2182 SysSolnInfo = SysSolnInfo->NextSiblingElement(
"I");
2184 VarInfo = VarInfo->NextSiblingElement(
"V");
2188 if (m_verbose && GetGloSysSolnList().size() > 0 && m_comm)
2190 if(m_comm->GetRank() == 0)
2192 cout <<
"GlobalSysSoln Info:" << endl;
2195 for (x = GetGloSysSolnList().begin();
2196 x != GetGloSysSolnList().end();
2199 cout <<
"\t Variable: " << x->first << endl;
2202 for (y = x->second.begin(); y != x->second.end(); ++y)
2204 cout <<
"\t\t " << y->first <<
" = " << y->second
2217 void SessionReader::ReadExpressions(TiXmlElement *conditions)
2219 m_expressions.clear();
2226 TiXmlElement *expressionsElement =
2227 conditions->FirstChildElement(
"EXPRESSIONS");
2229 if (expressionsElement)
2231 TiXmlElement *expr = expressionsElement->FirstChildElement(
"E");
2235 stringstream tagcontent;
2236 tagcontent << *expr;
2238 "Missing NAME attribute in expression "
2239 "definition: \n\t'" + tagcontent.str() +
"'");
2240 std::string nameString = expr->Attribute(
"NAME");
2242 "Expressions must have a non-empty name: \n\t'"
2243 + tagcontent.str() +
"'");
2246 "Missing VALUE attribute in expression "
2247 "definition: \n\t'" + tagcontent.str() +
"'");
2248 std::string valString = expr->Attribute(
"VALUE");
2250 "Expressions must have a non-empty value: \n\t'"
2251 + tagcontent.str() +
"'");
2254 = m_expressions.find(nameString);
2255 ASSERTL0(exprIter == m_expressions.end(),
2256 std::string(
"Expression '") + nameString
2257 + std::string(
"' already specified."));
2259 m_expressions[nameString] = valString;
2260 expr = expr->NextSiblingElement(
"E");
2269 void SessionReader::ReadVariables(TiXmlElement *conditions)
2271 m_variables.clear();
2278 TiXmlElement *variablesElement =
2279 conditions->FirstChildElement(
"VARIABLES");
2283 if (variablesElement)
2285 TiXmlElement *varElement =
2286 variablesElement->FirstChildElement(
"V");
2289 int nextVariableNumber = -1;
2293 stringstream tagcontent;
2294 tagcontent << *varElement;
2298 nextVariableNumber++;
2301 int err = varElement->QueryIntAttribute(
"ID", &i);
2303 "Variables must have a unique ID number attribute "
2304 "in XML element: \n\t'" + tagcontent.str() +
"'");
2306 "ID numbers for variables must begin with zero and"
2307 " be sequential in XML element: \n\t'"
2308 + tagcontent.str() +
"'");
2310 TiXmlNode* varChild = varElement->FirstChild();
2315 while(varChild && varChild->Type() != TiXmlNode::TINYXML_TEXT)
2317 varChild = varChild->NextSibling();
2321 "Unable to read variable definition body for "
2323 + boost::lexical_cast<string>(i)
2324 +
" in XML element: \n\t'"
2325 + tagcontent.str() +
"'");
2326 std::string variableName = varChild->ToText()->ValueStr();
2328 std::istringstream variableStrm(variableName);
2329 variableStrm >> variableName;
2332 variableName) == m_variables.end(),
2334 + boost::lexical_cast<
string>(i)
2335 +
" in XML element \n\t'" + tagcontent.str()
2336 +
"'\nhas already been defined.");
2338 m_variables.push_back(variableName);
2340 varElement = varElement->NextSiblingElement(
"V");
2344 "Number of variables must be greater than zero.");
2352 void SessionReader::ReadFunctions(TiXmlElement *conditions)
2354 m_functions.clear();
2362 TiXmlElement *
function = conditions->FirstChildElement(
"FUNCTION");
2365 stringstream tagcontent;
2366 tagcontent << *
function;
2369 ASSERTL0(function->Attribute(
"NAME"),
2370 "Functions must have a NAME attribute defined in XML "
2371 "element: \n\t'" + tagcontent.str() +
"'");
2372 std::string functionStr =
function->Attribute(
"NAME");
2374 "Functions must have a non-empty name in XML "
2375 "element: \n\t'" + tagcontent.str() +
"'");
2378 boost::to_upper(functionStr);
2381 TiXmlElement *variable =
function->FirstChildElement();
2390 std::string conditionType = variable->Value();
2393 std::string variableStr;
2394 if (!variable->Attribute(
"VAR"))
2400 variableStr = variable->Attribute(
"VAR");
2404 std::vector<std::string> variableList;
2405 ParseUtils::GenerateOrderedStringVector(variableStr.c_str(),
2409 std::string domainStr;
2410 if (!variable->Attribute(
"DOMAIN"))
2416 domainStr = variable->Attribute(
"DOMAIN");
2420 std::vector<std::string> varSplit;
2421 std::vector<unsigned int> domainList;
2422 ParseUtils::GenerateSeqVector(domainStr.c_str(), domainList);
2425 if (conditionType ==
"E")
2430 ASSERTL0(variable->Attribute(
"VALUE"),
2431 "Attribute VALUE expected for function '"
2432 + functionStr +
"'.");
2433 std::string fcnStr = variable->Attribute(
"VALUE");
2436 (std::string(
"Expression for var: ")
2438 + std::string(
" must be specified.")).c_str());
2440 SubstituteExpressions(fcnStr);
2448 else if (conditionType ==
"F")
2450 if (variable->Attribute(
"TIMEDEPENDENT") &&
2451 boost::lexical_cast<
bool>(variable->Attribute(
"TIMEDEPENDENT")))
2461 ASSERTL0(variable->Attribute(
"FILE"),
2462 "Attribute FILE expected for function '"
2463 + functionStr +
"'.");
2464 std::string filenameStr = variable->Attribute(
"FILE");
2467 "A filename must be specified for the FILE "
2468 "attribute of function '" + functionStr
2471 std::vector<std::string> fSplit;
2472 boost::split(fSplit, filenameStr, boost::is_any_of(
":"));
2474 ASSERTL0(fSplit.size() == 1 || fSplit.size() == 2,
2475 "Incorrect filename specification in function "
2476 + functionStr +
"'. "
2477 "Specify variables inside file as: "
2478 "filename:var1,var2");
2483 if (fSplit.size() == 2)
2486 "Filename variable mapping not valid "
2487 "when using * as a variable inside "
2488 "function '" + functionStr +
"'.");
2491 varSplit, fSplit[1], boost::is_any_of(
","));
2492 ASSERTL0(varSplit.size() == variableList.size(),
2493 "Filename variables should contain the "
2494 "same number of variables defined in "
2495 "VAR in function " + functionStr +
"'.");
2502 stringstream tagcontent;
2503 tagcontent << *variable;
2506 "Identifier " + conditionType +
" in function "
2507 + std::string(function->Attribute(
"NAME"))
2508 +
" is not recognised in XML element: \n\t'"
2509 + tagcontent.str() +
"'");
2515 for (
unsigned int i = 0; i < variableList.size(); ++i)
2517 for(
unsigned int j = 0; j < domainList.size(); ++j)
2520 pair<std::string,int> key(variableList[i],domainList[j]);
2522 = functionVarMap.find(key);
2523 ASSERTL0(fcnsIter == functionVarMap.end(),
2524 "Error setting expression '" + variableList[i]
2526 + boost::lexical_cast<std::string>(domainList[j])
2527 +
"' in function '" + functionStr +
"'. "
2528 "Expression has already been defined.");
2530 if (varSplit.size() > 0)
2534 functionVarMap[key] = funcDef2;
2538 functionVarMap[key] = funcDef;
2543 variable = variable->NextSiblingElement();
2546 m_functions[functionStr] = functionVarMap;
2547 function =
function->NextSiblingElement(
"FUNCTION");
2555 void SessionReader::ReadFilters(TiXmlElement *filters)
2564 TiXmlElement *filter = filters->FirstChildElement(
"FILTER");
2567 ASSERTL0(filter->Attribute(
"TYPE"),
2568 "Missing attribute 'TYPE' for filter.");
2569 std::string typeStr = filter->Attribute(
"TYPE");
2571 std::map<std::string, std::string> vParams;
2573 TiXmlElement *param = filter->FirstChildElement(
"PARAM");
2577 "Missing attribute 'NAME' for parameter in filter "
2579 std::string nameStr = param->Attribute(
"NAME");
2581 ASSERTL0(param->GetText(),
"Empty value string for param.");
2582 std::string valueStr = param->GetText();
2584 vParams[nameStr] = valueStr;
2586 param = param->NextSiblingElement(
"PARAM");
2589 m_filters.push_back(
2590 std::pair<std::string, FilterParams>(typeStr, vParams));
2592 filter = filter->NextSiblingElement(
"FILTER");
2596 void SessionReader::ParseEquals(
2597 const std::string &line,
2602 int beg = line.find_first_not_of(
" ");
2603 int end = line.find_first_of(
"=");
2605 if (beg == end)
throw 1;
2607 if (end != line.find_last_of(
"="))
throw 1;
2609 if (end == std::string::npos)
throw 1;
2611 lhs = line.substr(line.find_first_not_of(
" "),
2613 lhs = lhs .substr(0, lhs.find_last_not_of(
" ")+1);
2614 rhs = line.substr(line.find_last_of(
"=")+1);
2615 rhs = rhs .substr(rhs.find_first_not_of(
" "));
2616 rhs = rhs .substr(0, rhs.find_last_not_of(
" ")+1);
2622 void SessionReader::CmdLineOverride()
2625 if (m_cmdLineOptions.count(
"solverinfo"))
2627 std::vector<std::string> solverInfoList =
2628 m_cmdLineOptions[
"solverinfo"].as<
2629 std::vector<std::string> >();
2631 for (
int i = 0; i < solverInfoList.size(); ++i)
2633 std::string
lhs, rhs;
2637 ParseEquals(solverInfoList[i], lhs, rhs);
2641 ASSERTL0(
false,
"Parse error with command line "
2642 "option: "+solverInfoList[i]);
2645 std::string lhsUpper = boost::to_upper_copy(lhs);
2646 m_solverInfo[lhsUpper] = rhs;
2650 if (m_cmdLineOptions.count(
"parameter"))
2652 std::vector<std::string> parametersList =
2653 m_cmdLineOptions[
"parameter"].as<
2654 std::vector<std::string> >();
2656 for (
int i = 0; i < parametersList.size(); ++i)
2658 std::string
lhs, rhs;
2662 ParseEquals(parametersList[i], lhs, rhs);
2666 ASSERTL0(
false,
"Parse error with command line "
2667 "option: "+parametersList[i]);
2670 std::string lhsUpper = boost::to_upper_copy(lhs);
2674 m_parameters[lhsUpper] =
2679 ASSERTL0(
false,
"Unable to convert string: "+rhs+
2680 "to double value.");
2686 void SessionReader::VerifySolverInfo()
2688 SolverInfoMap::const_iterator x;
2689 for (x = m_solverInfo.begin(); x != m_solverInfo.end(); ++x)
2691 std::string solverProperty = x->first;
2692 std::string solverValue = x->second;
2694 EnumMapList::const_iterator propIt =
2695 GetSolverInfoEnums().find(solverProperty);
2696 if (propIt != GetSolverInfoEnums().end())
2698 EnumMap::const_iterator valIt =
2699 propIt->second.find(solverValue);
2700 ASSERTL0(valIt != propIt->second.end(),
2701 "Value '" + solverValue +
"' is not valid for "
2702 "property '" + solverProperty +
"'");
2708 void SessionReader::SetUpXmlDoc(
void)
2710 m_xmlDoc = MergeDoc(m_filenames);
std::map< std::string, std::string > SolverInfoMap
#define ASSERTL0(condition, msg)
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
static void Finalise(gs_data *pGsh)
Deallocates the GSLib mapping data.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::map< std::pair< std::string, int >, FunctionVariableDefinition > FunctionVariableMap
boost::shared_ptr< MeshPartition > MeshPartitionSharedPtr
std::map< int, std::vector< unsigned int > > BndRegionOrdering
std::map< int, std::vector< unsigned int > > CompositeOrdering
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
CommFactory & GetCommFactory()
EquationSharedPtr m_expression
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
const std::string kGitSha1
std::map< std::string, GloSysInfoMap > GloSysSolnInfoList
NekDouble Evaluate() const
#define WARNINGL0(condition, msg)
std::vector< std::pair< std::string, FilterParams > > FilterMap
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
int GetSize(const ConstArray< OneD, NekDouble > &x)
const std::string kGitBranch
boost::shared_ptr< Equation > EquationSharedPtr
This class defines evaluator of analytic (symbolic) mathematical expressions. Expressions are allowed...
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::map< std::string, NekDouble > ParameterMap
std::map< std::string, EnumMap > EnumMapList
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
std::string m_fileVariable
std::map< std::string, CmdLineArg > CmdLineArgMap
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
MeshPartitionFactory & GetMeshPartitionFactory()