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);
199 if (m_comm->GetSize() > 1)
201 GetSolverInfoDefaults()[
"GLOBALSYSSOLN"] =
202 "IterativeStaticCond";
210 SessionReader::SessionReader(
213 const std::vector<std::string> &pFilenames,
216 ASSERTL0(pFilenames.size() > 0,
"No filenames specified.");
218 ParseCommandLineArguments(argc, argv);
220 m_filenames = pFilenames;
222 m_sessionName = ParseSessionName(m_filenames);
227 CreateComm(argc, argv);
233 if (m_comm->GetSize() > 1)
235 GetSolverInfoDefaults()[
"GLOBALSYSSOLN"] =
236 "IterativeStaticCond";
242 if (m_comm->GetSize() > 1)
244 GetSolverInfoDefaults()[
"GLOBALSYSSOLN"] =
245 "IterativeStaticCond";
253 SessionReader::~SessionReader()
265 void SessionReader::InitSession()
267 m_exprEvaluator.SetRandomSeed((m_comm->GetRank() + 1) * time(NULL));
286 if (m_verbose && m_comm)
288 if (m_comm->GetRank() == 0 && m_parameters.size() > 0)
290 cout <<
"Parameters:" << endl;
292 for (x = m_parameters.begin(); x != m_parameters.end(); ++x)
294 cout <<
"\t" << x->first <<
" = " << x->second << endl;
299 if (m_comm->GetRank() == 0 && m_solverInfo.size() > 0)
301 cout <<
"Solver Info:" << endl;
303 for (x = m_solverInfo.begin(); x != m_solverInfo.end(); ++x)
305 cout <<
"\t" << x->first <<
" = " << x->second << endl;
317 std::vector<std::string> SessionReader::ParseCommandLineArguments(
318 int argc,
char *argv[])
321 po::options_description desc(
"Allowed options");
323 (
"verbose,v",
"be verbose")
324 (
"version,V",
"print version information")
325 (
"help,h",
"print this help message")
326 (
"solverinfo,I", po::value<vector<std::string> >(),
327 "override a SOLVERINFO property")
328 (
"parameter,P", po::value<vector<std::string> >(),
329 "override a parameter")
330 (
"shared-filesystem,s",
"Using shared filesystem.")
331 (
"npx", po::value<int>(),
332 "number of procs in X-dir")
333 (
"npy", po::value<int>(),
334 "number of procs in Y-dir")
335 (
"npz", po::value<int>(),
336 "number of procs in Z-dir")
337 (
"nsz", po::value<int>(),
338 "number of slices in Z-dir")
339 (
"part-only", po::value<int>(),
340 "only partition mesh into N partitions.")
341 (
"part-only-overlapping", po::value<int>(),
342 "only partition mesh into N overlapping partitions.")
343 (
"part-info",
"Output partition information")
346 CmdLineArgMap::const_iterator cmdIt;
347 for (cmdIt = GetCmdLineArgMap().begin();
348 cmdIt != GetCmdLineArgMap().end(); ++cmdIt)
350 std::string names = cmdIt->first;
351 if (cmdIt->second.shortName !=
"")
353 names +=
"," + cmdIt->second.shortName;
355 if (cmdIt->second.isFlag)
358 (names.c_str(), cmdIt->second.description.c_str())
364 (names.c_str(), po::value<std::string>(),
365 cmdIt->second.description.c_str())
372 po::options_description hidden(
"Hidden options");
374 (
"input-file", po::value< vector<string> >(),
379 po::options_description all(
"All options");
380 all.add(desc).add(hidden);
383 po::positional_options_description p;
384 p.add(
"input-file", -1);
387 po::parsed_options parsed = po::command_line_parser(argc, argv).
390 allow_unregistered().
394 po::store(parsed, m_cmdLineOptions);
395 po::notify(m_cmdLineOptions);
398 if (m_cmdLineOptions.count(
"help"))
405 if (m_cmdLineOptions.count(
"version"))
413 boost::replace_all(branch,
"refs/heads/",
"");
415 cout <<
" (git changeset " << sha1.substr(0, 8) <<
", ";
419 cout <<
"detached head";
423 cout <<
"head " << branch;
434 if (m_cmdLineOptions.count(
"verbose"))
444 std::vector< po::basic_option<char> >
::iterator x;
445 for (x = parsed.options.begin(); x != parsed.options.end(); ++x)
449 cout <<
"Warning: Unknown option: " << x->string_key
455 if (m_cmdLineOptions.count(
"input-file"))
457 return m_cmdLineOptions[
"input-file"].as<
458 std::vector<std::string> >();
462 return std::vector<std::string>();
470 std::string SessionReader::ParseSessionName(
471 std::vector<std::string> &filenames)
474 "At least one filename expected.");
476 std::string retval =
"";
479 std::string fname = filenames[0];
482 if (fname.size() > 4 &&
483 fname.substr(fname.size() - 4, 4) ==
"_xml")
485 retval = fname.substr(0, fname.find_last_of(
"_"));
488 else if (fname.size() > 4 &&
489 fname.substr(fname.size() - 4, 4) ==
".xml")
491 retval = fname.substr(0, fname.find_last_of(
"."));
494 else if (fname.size() > 7 &&
495 fname.substr(fname.size() - 7, 7) ==
".xml.gz")
497 retval = fname.substr(0, fname.find_last_of(
"."));
498 retval = retval.substr(0, retval.find_last_of(
"."));
508 TiXmlDocument& SessionReader::GetDocument()
510 ASSERTL1(m_xmlDoc,
"XML Document not defined.");
537 TiXmlElement* SessionReader::GetElement(
const string& pPath)
539 std::string vPath = boost::to_upper_copy(pPath);
540 std::vector<std::string> st;
541 boost::split(st, vPath, boost::is_any_of(
"\\/ "));
542 ASSERTL0(st.size() > 0,
"No path given in XML element request.");
544 TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
545 ASSERTL0(vReturn, std::string(
"Cannot find element '")
546 + st[0] + std::string(
"'."));
547 for (
int i = 1; i < st.size(); ++i)
549 vReturn = vReturn->FirstChildElement(st[i].c_str());
550 ASSERTL0(vReturn, std::string(
"Cannot find element '")
551 + st[i] + std::string(
"'."));
560 bool SessionReader::DefinesElement(
const std::string &pPath)
const
562 std::string vPath = boost::to_upper_copy(pPath);
563 std::vector<std::string> st;
564 boost::split(st, vPath, boost::is_any_of(
"\\/ "));
565 ASSERTL0(st.size() > 0,
"No path given in XML element request.");
567 TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
568 ASSERTL0(vReturn, std::string(
"Cannot find element '")
569 + st[0] + std::string(
"'."));
570 for (
int i = 1; i < st.size(); ++i)
572 vReturn = vReturn->FirstChildElement(st[i].c_str());
573 if (!vReturn)
return false;
582 const std::vector<std::string>& SessionReader::GetFilenames()
const
591 const std::string& SessionReader::GetSessionName()
const
593 return m_sessionName;
601 const std::string SessionReader::GetSessionNameRank()
const
603 std::string dirname = m_sessionName +
"_xml";
604 fs::path pdirname(dirname);
606 std::string vFilename =
"P" + boost::lexical_cast<std::string>(m_comm->GetRowComm()->GetRank());
607 fs::path pFilename(vFilename);
609 fs::path fullpath = pdirname / pFilename;
638 bool SessionReader::DefinesParameter(
const std::string& pName)
const
640 std::string vName = boost::to_upper_copy(pName);
641 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
642 return (paramIter != m_parameters.end());
655 const std::string& pName)
const
657 std::string vName = boost::to_upper_copy(pName);
658 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
660 ASSERTL0(paramIter != m_parameters.end(),
661 "Unable to find requested parameter: " + pName);
663 return paramIter->second;
670 void SessionReader::LoadParameter(
671 const std::string &pName,
int &pVar)
const
673 std::string vName = boost::to_upper_copy(pName);
674 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
675 ASSERTL0(paramIter != m_parameters.end(),
"Required parameter '" +
676 pName +
"' not specified in session.");
677 pVar = (int)floor(paramIter->second);
684 void SessionReader::LoadParameter(
685 const std::string &pName,
int &pVar,
const int &pDefault)
const
687 std::string vName = boost::to_upper_copy(pName);
688 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
689 if(paramIter != m_parameters.end())
691 pVar = (int)floor(paramIter->second);
703 void SessionReader::LoadParameter(
704 const std::string &pName,
NekDouble& pVar)
const
706 std::string vName = boost::to_upper_copy(pName);
707 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
708 ASSERTL0(paramIter != m_parameters.end(),
"Required parameter '" +
709 pName +
"' not specified in session.");
710 pVar = paramIter->second;
717 void SessionReader::LoadParameter(
718 const std::string &pName,
722 std::string vName = boost::to_upper_copy(pName);
723 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
724 if(paramIter != m_parameters.end())
726 pVar = paramIter->second;
739 void SessionReader::SetParameter(
const std::string &pName,
int &pVar)
741 std::string vName = boost::to_upper_copy(pName);
742 m_parameters[vName] = pVar;
749 void SessionReader::SetParameter(
750 const std::string &pName,
NekDouble& pVar)
752 std::string vName = boost::to_upper_copy(pName);
753 m_parameters[vName] = pVar;
761 bool SessionReader::DefinesSolverInfo(
const std::string &pName)
const
763 std::string vName = boost::to_upper_copy(pName);
764 SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
765 return (infoIter != m_solverInfo.end());
772 const std::string& SessionReader::GetSolverInfo(
773 const std::string &pProperty)
const
775 std::string vProperty = boost::to_upper_copy(pProperty);
776 SolverInfoMap::const_iterator iter = m_solverInfo.find(vProperty);
778 ASSERTL1(iter != m_solverInfo.end(),
779 "Unable to find requested property: " + pProperty);
787 void SessionReader::SetSolverInfo(
788 const std::string &pProperty,
const std::string &pValue)
790 std::string vProperty = boost::to_upper_copy(pProperty);
793 ASSERTL1(iter != m_solverInfo.end(),
794 "Unable to find requested property: " + pProperty);
796 iter->second = pValue;
802 void SessionReader::LoadSolverInfo(
803 const std::string &pName,
805 const std::string &pDefault)
const
807 std::string vName = boost::to_upper_copy(pName);
808 SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
809 if(infoIter != m_solverInfo.end())
811 pVar = infoIter->second;
823 void SessionReader::MatchSolverInfo(
824 const std::string &pName,
825 const std::string &pTrueVal,
827 const bool &pDefault)
const
829 std::string vName = boost::to_upper_copy(pName);
830 SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
831 if(infoIter != m_solverInfo.end())
833 pVar = boost::iequals(infoIter->second, pTrueVal);
845 bool SessionReader::MatchSolverInfo(
846 const std::string &pName,
847 const std::string &pTrueVal)
const
849 if (DefinesSolverInfo(pName))
851 std::string vName = boost::to_upper_copy(pName);
852 SolverInfoMap::const_iterator iter = m_solverInfo.find(vName);
853 if(iter != m_solverInfo.end())
865 bool SessionReader::DefinesGlobalSysSolnInfo(
const std::string &pVariable,
866 const std::string &pProperty)
const
869 GloSysSolnInfoList::const_iterator iter =
870 GetGloSysSolnList().find(pVariable);
871 if(iter == GetGloSysSolnList().end())
876 std::string vProperty = boost::to_upper_copy(pProperty);
878 GloSysInfoMap::const_iterator iter1 = iter->second.find(vProperty);
879 if(iter1 == iter->second.end())
891 const std::string &SessionReader::GetGlobalSysSolnInfo(
const std::string &pVariable,
const std::string &pProperty)
const
893 GloSysSolnInfoList::const_iterator iter;
895 ASSERTL0( (iter = GetGloSysSolnList().
find(pVariable)) !=
896 GetGloSysSolnList().end(),
897 "Failed to find variable in GlobalSysSolnInfoList");
899 std::string vProperty = boost::to_upper_copy(pProperty);
900 GloSysInfoMap::const_iterator iter1;
902 ASSERTL0( (iter1 = iter->second.find(vProperty)) != iter->second.end(),
903 "Failed to find property: " + vProperty +
" in GlobalSysSolnInfoList");
905 return iter1->second;
911 bool SessionReader::DefinesGeometricInfo(
const std::string &pName)
const
913 std::string vName = boost::to_upper_copy(pName);
914 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
915 return (iter != m_geometricInfo.end());
922 void SessionReader::LoadGeometricInfo(
923 const std::string &pName,
925 const std::string &pDefault)
const
927 std::string vName = boost::to_upper_copy(pName);
928 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
929 if(iter != m_geometricInfo.end())
943 void SessionReader::LoadGeometricInfo(
944 const std::string &pName,
946 const bool &pDefault)
const
948 std::string vName = boost::to_upper_copy(pName);
949 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
950 if(iter != m_geometricInfo.end())
952 if (iter->second ==
"TRUE")
971 void SessionReader::LoadGeometricInfo(
972 const std::string &pName,
976 std::string vName = boost::to_upper_copy(pName);
977 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
978 if(iter != m_geometricInfo.end())
980 pVar = std::atoi(iter->second.c_str());
992 void SessionReader::MatchGeometricInfo(
993 const std::string &pName,
994 const std::string &pTrueVal,
996 const bool &pDefault)
const
998 std::string vName = boost::to_upper_copy(pName);
999 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
1000 if(iter != m_geometricInfo.end())
1002 pVar = boost::iequals(iter->second, pTrueVal);
1014 const std::string& SessionReader::GetVariable(
1015 const unsigned int &idx)
const
1017 ASSERTL0(idx < m_variables.size(),
"Variable index out of range.");
1018 return m_variables[idx];
1026 void SessionReader::SetVariable(
const unsigned int &idx,
1027 std::string newname)
1029 ASSERTL0(idx < m_variables.size(),
"Variable index out of range.");
1030 m_variables[idx] = newname;
1037 std::vector<std::string> SessionReader::GetVariables()
const
1046 bool SessionReader::DefinesFunction(
const std::string &pName)
const
1048 FunctionMap::const_iterator it1;
1049 std::string vName = boost::to_upper_copy(pName);
1051 if ((it1 = m_functions.find(vName)) != m_functions.end())
1062 bool SessionReader::DefinesFunction(
1063 const std::string &pName,
1064 const std::string &pVariable,
1065 const int pDomain)
const
1067 FunctionMap::const_iterator it1;
1068 FunctionVariableMap::const_iterator it2;
1069 std::string vName = boost::to_upper_copy(pName);
1072 if ((it1 = m_functions.find(vName)) != m_functions.end())
1074 pair<std::string, int> key(pVariable,pDomain);
1075 pair<std::string, int> defkey(
"*",pDomain);
1077 (it2 = it1->second.find(key)) != it1->second.end() ||
1078 (it2 = it1->second.find(defkey)) != it1->second.end();
1089 const std::string &pName,
1090 const std::string &pVariable,
1091 const int pDomain)
const
1093 FunctionMap::const_iterator it1;
1094 FunctionVariableMap::const_iterator it2, it3;
1095 std::string vName = boost::to_upper_copy(pName);
1097 ASSERTL0((it1 = m_functions.find(vName)) != m_functions.end(),
1098 std::string(
"No such function '") + pName
1099 + std::string(
"' has been defined in the session file."));
1102 pair<std::string,int> key(pVariable,pDomain);
1103 pair<std::string,int> defkey(
"*",pDomain);
1104 bool specific = (it2 = it1->second.find(key)) !=
1106 bool wildcard = (it3 = it1->second.find(defkey)) !=
1111 "No such variable " + pVariable
1112 +
" in domain " + boost::lexical_cast<string>(pDomain)
1113 +
" defined for function " + pName
1114 +
" in session file.");
1123 std::string(
"Function is defined by a file."));
1124 return it2->second.m_expression;
1132 const std::string &pName,
1133 const unsigned int &pVar,
1134 const int pDomain)
const
1136 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1137 return GetFunction(pName, m_variables[pVar],pDomain);
1145 const std::string &pName,
1146 const std::string &pVariable,
1147 const int pDomain)
const
1149 FunctionMap::const_iterator it1;
1150 FunctionVariableMap::const_iterator it2, it3;
1151 std::string vName = boost::to_upper_copy(pName);
1153 it1 = m_functions.find(vName);
1154 ASSERTL0 (it1 != m_functions.end(),
1155 std::string(
"Function '") + pName
1156 + std::string(
"' not found."));
1159 pair<std::string,int> key(pVariable,pDomain);
1160 pair<std::string,int> defkey(
"*",pDomain);
1161 bool specific = (it2 = it1->second.find(key)) !=
1163 bool wildcard = (it3 = it1->second.find(defkey)) !=
1168 "No such variable " + pVariable
1169 +
" in domain " + boost::lexical_cast<string>(pDomain)
1170 +
" defined for function " + pName
1171 +
" in session file.");
1179 return it2->second.m_type;
1187 const std::string &pName,
1188 const unsigned int &pVar,
1189 const int pDomain)
const
1191 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1192 return GetFunctionType(pName, m_variables[pVar],pDomain);
1199 std::string SessionReader::GetFunctionFilename(
1200 const std::string &pName,
1201 const std::string &pVariable,
1202 const int pDomain)
const
1204 FunctionMap::const_iterator it1;
1205 FunctionVariableMap::const_iterator it2, it3;
1206 std::string vName = boost::to_upper_copy(pName);
1208 it1 = m_functions.find(vName);
1209 ASSERTL0 (it1 != m_functions.end(),
1210 std::string(
"Function '") + pName
1211 + std::string(
"' not found."));
1214 pair<std::string,int> key(pVariable,pDomain);
1215 pair<std::string,int> defkey(
"*",pDomain);
1216 bool specific = (it2 = it1->second.find(key)) !=
1218 bool wildcard = (it3 = it1->second.find(defkey)) !=
1223 "No such variable " + pVariable
1224 +
" in domain " + boost::lexical_cast<string>(pDomain)
1225 +
" defined for function " + pName
1226 +
" in session file.");
1234 return it2->second.m_filename;
1241 std::string SessionReader::GetFunctionFilename(
1242 const std::string &pName,
1243 const unsigned int &pVar,
1244 const int pDomain)
const
1246 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1247 return GetFunctionFilename(pName, m_variables[pVar],pDomain);
1254 std::string SessionReader::GetFunctionFilenameVariable(
1255 const std::string &pName,
1256 const std::string &pVariable,
1257 const int pDomain)
const
1259 FunctionMap::const_iterator it1;
1260 FunctionVariableMap::const_iterator it2, it3;
1261 std::string vName = boost::to_upper_copy(pName);
1263 it1 = m_functions.find(vName);
1264 ASSERTL0 (it1 != m_functions.end(),
1265 std::string(
"Function '") + pName
1266 + std::string(
"' not found."));
1269 pair<std::string,int> key(pVariable,pDomain);
1270 pair<std::string,int> defkey(
"*",pDomain);
1271 bool specific = (it2 = it1->second.find(key)) !=
1273 bool wildcard = (it3 = it1->second.find(defkey)) !=
1278 "No such variable " + pVariable
1279 +
" in domain " + boost::lexical_cast<string>(pDomain)
1280 +
" defined for function " + pName
1281 +
" in session file.");
1289 return it2->second.m_fileVariable;
1298 return m_exprEvaluator;
1305 bool SessionReader::DefinesTag(
const std::string &pName)
const
1307 std::string vName = boost::to_upper_copy(pName);
1308 TagMap::const_iterator vTagIterator = m_tags.find(vName);
1309 return (vTagIterator != m_tags.end());
1316 void SessionReader::SetTag(
1317 const std::string &pName,
1318 const std::string &pValue)
1320 std::string vName = boost::to_upper_copy(pName);
1321 m_tags[vName] = pValue;
1328 const std::string &SessionReader::GetTag(
const std::string& pName)
const
1330 std::string vName = boost::to_upper_copy(pName);
1331 TagMap::const_iterator vTagIterator = m_tags.find(vName);
1332 ASSERTL0(vTagIterator != m_tags.end(),
1333 "Requested tag does not exist.");
1334 return vTagIterator->second;
1350 bool SessionReader::DefinesCmdLineArgument(
1351 const std::string& pName)
const
1353 return (m_cmdLineOptions.find(pName) != m_cmdLineOptions.end());
1360 void SessionReader::SubstituteExpressions(std::string& pExpr)
1363 for (exprIter = m_expressions.begin();
1364 exprIter != m_expressions.end(); ++exprIter)
1366 boost::replace_all(pExpr, exprIter->first, exprIter->second);
1377 return m_bndRegOrder;
1383 void SessionReader::LoadDoc(
1384 const std::string &pFilename,
1385 TiXmlDocument* pDoc)
const
1387 if (pFilename.size() > 3 &&
1388 pFilename.substr(pFilename.size() - 3, 3) ==
".gz")
1390 ifstream file(pFilename.c_str(),
1391 ios_base::in | ios_base::binary);
1392 ASSERTL0(file.good(),
"Unable to open file: " + pFilename);
1394 io::filtering_streambuf<io::input> in;
1395 in.push(io::gzip_decompressor());
1402 catch (io::gzip_error& e)
1405 "Error: File '" + pFilename +
"' is corrupt.");
1408 else if (pFilename.size() > 4 &&
1409 pFilename.substr(pFilename.size() - 4, 4) ==
"_xml")
1411 fs::path pdirname(pFilename);
1412 boost::format pad(
"P%1$07d.xml");
1413 pad % m_comm->GetRank();
1414 fs::path pRankFilename(pad.str());
1415 fs::path fullpath = pdirname / pRankFilename;
1418 ASSERTL0(file.good(),
"Unable to open file: " + fullpath.string());
1423 ifstream file(pFilename.c_str());
1424 ASSERTL0(file.good(),
"Unable to open file: " + pFilename);
1432 TiXmlDocument *SessionReader::MergeDoc(
1433 const std::vector<std::string> &pFilenames)
const
1435 ASSERTL0(pFilenames.size() > 0,
"No filenames for merging.");
1438 TiXmlDocument *vMainDoc =
new TiXmlDocument;
1439 LoadDoc(pFilenames[0], vMainDoc);
1441 TiXmlHandle vMainHandle(vMainDoc);
1442 TiXmlElement* vMainNektar =
1443 vMainHandle.FirstChildElement(
"NEKTAR").Element();
1448 for (
int i = 1; i < pFilenames.size(); ++i)
1450 if((pFilenames[i].compare(pFilenames[i].size()-3,3,
"xml") == 0)
1451 ||(pFilenames[i].compare(pFilenames[i].size()-6,6,
"xml.gz") == 0))
1453 TiXmlDocument* vTempDoc =
new TiXmlDocument;
1454 LoadDoc(pFilenames[i], vTempDoc);
1456 TiXmlHandle docHandle(vTempDoc);
1457 TiXmlElement* vTempNektar;
1458 vTempNektar = docHandle.FirstChildElement(
"NEKTAR").Element();
1459 ASSERTL0(vTempNektar,
"Unable to find NEKTAR tag in file.");
1460 TiXmlElement* p = vTempNektar->FirstChildElement();
1464 TiXmlElement *vMainEntry =
1465 vMainNektar->FirstChildElement(p->Value());
1468 if (!p->FirstChild() && vMainEntry)
1470 std::string warningmsg =
1471 "File " + pFilenames[i] +
" contains " +
1472 "an empty XML element " +
1473 std::string(p->Value()) +
1474 " which will be ignored.";
1481 vMainNektar->RemoveChild(vMainEntry);
1483 TiXmlElement *q =
new TiXmlElement(*p);
1484 vMainNektar->LinkEndChild(q);
1486 p = p->NextSiblingElement();
1499 void SessionReader::ParseDocument()
1502 ASSERTL0(m_xmlDoc,
"No XML document loaded.");
1505 TiXmlHandle docHandle(m_xmlDoc);
1507 e = docHandle.FirstChildElement(
"NEKTAR").
1508 FirstChildElement(
"CONDITIONS").Element();
1513 ReadGlobalSysSolnInfo (e);
1514 ReadExpressions (e);
1518 e = docHandle.FirstChildElement(
"NEKTAR").
1519 FirstChildElement(
"FILTERS").Element();
1528 void SessionReader::CreateComm(
1538 string vCommModule(
"Serial");
1541 vCommModule =
"ParallelMPI";
1552 void SessionReader::PartitionMesh()
1554 ASSERTL0(m_comm.get(),
"Communication not initialised.");
1558 const bool isRoot = (m_comm->GetRank() == 0);
1574 int isPartitioned = 0;
1577 m_xmlDoc = MergeDoc(m_filenames);
1578 if (DefinesElement(
"Nektar/Geometry"))
1580 if (GetElement(
"Nektar/Geometry")->Attribute(
"PARTITION"))
1582 cout <<
"Using pre-partitioned mesh." << endl;
1591 if (isPartitioned) {
1594 m_xmlDoc = MergeDoc(m_filenames);
1602 string vPartitionerName =
"Metis";
1605 vPartitionerName =
"Scotch";
1607 if (DefinesCmdLineArgument(
"use-metis"))
1609 vPartitionerName =
"Metis";
1611 if (DefinesCmdLineArgument(
"use-scotch"))
1613 vPartitionerName =
"Scotch";
1619 if (DefinesCmdLineArgument(
"part-only")||
1620 DefinesCmdLineArgument(
"part-only-overlapping"))
1625 "The 'part-only' option should be used in serial.");
1632 vPartitionerName, vSession);
1633 if(DefinesCmdLineArgument(
"part-only"))
1635 nParts = GetCmdLineArgument<int>(
"part-only");
1636 vPartitioner->PartitionMesh(nParts,
true);
1640 nParts = GetCmdLineArgument<int>(
"part-only-overlapping");
1641 vPartitioner->PartitionMesh(nParts,
true,
true);
1643 vPartitioner->WriteAllPartitions(vSession);
1644 vPartitioner->GetCompositeOrdering(m_compOrder);
1645 vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
1647 if (isRoot && DefinesCmdLineArgument(
"part-info"))
1649 vPartitioner->PrintPartInfo(std::cout);
1655 else if (vCommMesh->GetSize() > 1)
1658 int nParts = vCommMesh->GetSize();
1659 if (DefinesCmdLineArgument(
"shared-filesystem"))
1662 vector<unsigned int> keys, vals;
1665 if (vComm->GetRank() == 0)
1667 m_xmlDoc = MergeDoc(m_filenames);
1671 vPartitionerName, vSession);
1672 vPartitioner->PartitionMesh(nParts,
true);
1673 vPartitioner->WriteAllPartitions(vSession);
1674 vPartitioner->GetCompositeOrdering(m_compOrder);
1675 vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
1682 keys[0] = m_compOrder.size();
1683 keys[1] = m_bndRegOrder.size();
1685 for (i = 1; i < vComm->GetSize(); ++i)
1687 vComm->Send(i, keys);
1693 keys.resize(m_compOrder.size());
1694 vals.resize(m_compOrder.size());
1696 for (cIt = m_compOrder.begin(), i = 0;
1697 cIt != m_compOrder.end(); ++cIt, ++i)
1699 keys[i] = cIt->first;
1700 vals[i] = cIt->second.size();
1704 for (i = 1; i < vComm->GetSize(); ++i)
1706 vComm->Send(i, keys);
1707 vComm->Send(i, vals);
1709 for (cIt = m_compOrder.begin();
1710 cIt != m_compOrder.end(); ++cIt)
1712 vComm->Send(i, cIt->second);
1719 keys.resize(m_bndRegOrder.size());
1720 vals.resize(m_bndRegOrder.size());
1722 for (bIt = m_bndRegOrder.begin(), i = 0;
1723 bIt != m_bndRegOrder.end(); ++bIt, ++i)
1725 keys[i] = bIt->first;
1726 vals[i] = bIt->second.size();
1730 for (i = 1; i < vComm->GetSize(); ++i)
1732 vComm->Send(i, keys);
1733 vComm->Send(i, vals);
1735 for (bIt = m_bndRegOrder.begin();
1736 bIt != m_bndRegOrder.end(); ++bIt)
1738 vComm->Send(i, bIt->second);
1742 if (DefinesCmdLineArgument(
"part-info"))
1744 vPartitioner->PrintPartInfo(std::cout);
1750 vComm->Recv(0, keys);
1752 int cmpSize = keys[0];
1753 int bndSize = keys[1];
1755 keys.resize(cmpSize);
1756 vals.resize(cmpSize);
1757 vComm->Recv(0, keys);
1758 vComm->Recv(0, vals);
1760 for (
int i = 0; i < keys.size(); ++i)
1762 vector<unsigned int> tmp(vals[i]);
1763 vComm->Recv(0, tmp);
1764 m_compOrder[keys[i]] = tmp;
1767 keys.resize(bndSize);
1768 vals.resize(bndSize);
1769 vComm->Recv(0, keys);
1770 vComm->Recv(0, vals);
1772 for (
int i = 0; i < keys.size(); ++i)
1774 vector<unsigned int> tmp(vals[i]);
1775 vComm->Recv(0, tmp);
1776 m_bndRegOrder[keys[i]] = tmp;
1785 m_xmlDoc = MergeDoc(m_filenames);
1793 vPartitionerName, vSession);
1794 vPartitioner->PartitionMesh(nParts,
false);
1795 vPartitioner->WriteLocalPartition(vSession);
1796 vPartitioner->GetCompositeOrdering(m_compOrder);
1797 vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
1799 if (DefinesCmdLineArgument(
"part-info") && isRoot)
1801 vPartitioner->PrintPartInfo(std::cout);
1806 std::string dirname = GetSessionName() +
"_xml";
1807 fs::path pdirname(dirname);
1808 boost::format pad(
"P%1$07d.xml");
1809 pad % m_comm->GetRowComm()->GetRank();
1810 fs::path pFilename(pad.str());
1811 fs::path fullpath = pdirname / pFilename;
1819 m_xmlDoc =
new TiXmlDocument(vFilename);
1821 ASSERTL0(m_xmlDoc,
"Failed to create XML document object.");
1823 bool loadOkay = m_xmlDoc->LoadFile(vFilename);
1824 ASSERTL0(loadOkay,
"Unable to load file: " + vFilename +
1825 ". Check XML standards compliance. Error on line: " +
1826 boost::lexical_cast<std::string>(m_xmlDoc->Row()));
1830 m_xmlDoc = MergeDoc(m_filenames);
1842 void SessionReader::PartitionComm()
1844 if (m_comm->GetSize() > 1)
1850 if (DefinesCmdLineArgument(
"npx")) {
1851 nProcX = GetCmdLineArgument<int>(
"npx");
1853 if (DefinesCmdLineArgument(
"npy")) {
1854 nProcY = GetCmdLineArgument<int>(
"npy");
1856 if (DefinesCmdLineArgument(
"npz")) {
1857 nProcZ = GetCmdLineArgument<int>(
"npz");
1859 if (DefinesCmdLineArgument(
"nsz")) {
1860 nStripZ = GetCmdLineArgument<int>(
"nsz");
1862 ASSERTL0(m_comm->GetSize() % (nProcZ*nProcY*nProcX) == 0,
1863 "Cannot exactly partition using PROC_Z value.");
1865 "Cannot exactly partition using PROC_Y value.");
1867 "Cannot exactly partition using PROC_X value.");
1870 int nProcSm = nProcZ * nProcY * nProcX;
1874 int nProcSem = m_comm->GetSize() / nProcSm;
1876 m_comm->SplitComm(nProcSm,nProcSem);
1877 m_comm->GetColumnComm()->SplitComm(nProcZ/nStripZ,nStripZ);
1878 m_comm->GetColumnComm()->GetColumnComm()->SplitComm(
1879 (nProcY*nProcX),nProcZ/nStripZ);
1880 m_comm->GetColumnComm()->GetColumnComm()->GetColumnComm()
1881 ->SplitComm(nProcX,nProcY);
1889 void SessionReader::ReadParameters(TiXmlElement *conditions)
1891 m_parameters.clear();
1898 TiXmlElement *parametersElement = conditions->FirstChildElement(
1903 if (parametersElement)
1905 TiXmlElement *parameter =
1906 parametersElement->FirstChildElement(
"P");
1914 stringstream tagcontent;
1915 tagcontent << *parameter;
1916 TiXmlNode *node = parameter->FirstChild();
1918 while (node && node->Type() != TiXmlNode::TINYXML_TEXT)
1920 node = node->NextSibling();
1926 std::string line = node->ToText()->Value(),
lhs, rhs;
1929 ParseEquals(line,
lhs, rhs);
1933 ASSERTL0(
false,
"Syntax error in parameter "
1934 "expression '" + line
1935 +
"' in XML element: \n\t'"
1936 + tagcontent.str() +
"'");
1942 if (!
lhs.empty() && !rhs.empty())
1948 GetSharedThisPtr(), rhs);
1951 catch (
const std::runtime_error &)
1954 "Error evaluating parameter expression"
1955 " '" + rhs +
"' in XML element: \n\t'"
1956 + tagcontent.str() +
"'");
1958 m_exprEvaluator.SetParameter(
lhs, value);
1959 caseSensitiveParameters[
lhs] = value;
1960 boost::to_upper(
lhs);
1961 m_parameters[
lhs] = value;
1965 parameter = parameter->NextSiblingElement();
1974 void SessionReader::ReadSolverInfo(TiXmlElement *conditions)
1976 m_solverInfo.clear();
1977 m_solverInfo = GetSolverInfoDefaults();
1984 TiXmlElement *solverInfoElement =
1985 conditions->FirstChildElement(
"SOLVERINFO");
1987 if (solverInfoElement)
1989 TiXmlElement *solverInfo =
1990 solverInfoElement->FirstChildElement(
"I");
1994 std::stringstream tagcontent;
1995 tagcontent << *solverInfo;
1997 ASSERTL0(solverInfo->Attribute(
"PROPERTY"),
1998 "Missing PROPERTY attribute in solver info "
1999 "XML element: \n\t'" + tagcontent.str() +
"'");
2000 std::string solverProperty =
2001 solverInfo->Attribute(
"PROPERTY");
2003 "PROPERTY attribute must be non-empty in XML "
2004 "element: \n\t'" + tagcontent.str() +
"'");
2007 std::string solverPropertyUpper =
2008 boost::to_upper_copy(solverProperty);
2011 ASSERTL0(solverInfo->Attribute(
"VALUE"),
2012 "Missing VALUE attribute in solver info "
2013 "XML element: \n\t'" + tagcontent.str() +
"'");
2014 std::string solverValue = solverInfo->Attribute(
"VALUE");
2016 "VALUE attribute must be non-empty in XML "
2017 "element: \n\t'" + tagcontent.str() +
"'");
2020 m_solverInfo[solverPropertyUpper] = solverValue;
2021 solverInfo = solverInfo->NextSiblingElement(
"I");
2025 if (m_comm && m_comm->GetRowComm()->GetSize() > 1)
2028 m_solverInfo[
"GLOBALSYSSOLN"] ==
"IterativeFull" ||
2029 m_solverInfo[
"GLOBALSYSSOLN"] ==
"IterativeStaticCond" ||
2030 m_solverInfo[
"GLOBALSYSSOLN"] ==
2031 "IterativeMultiLevelStaticCond" ||
2032 m_solverInfo[
"GLOBALSYSSOLN"] ==
"XxtFull" ||
2033 m_solverInfo[
"GLOBALSYSSOLN"] ==
"XxtStaticCond" ||
2034 m_solverInfo[
"GLOBALSYSSOLN"] ==
2035 "XxtMultiLevelStaticCond" ||
2036 m_solverInfo[
"GLOBALSYSSOLN"] ==
"PETScFull" ||
2037 m_solverInfo[
"GLOBALSYSSOLN"] ==
"PETScStaticCond" ||
2038 m_solverInfo[
"GLOBALSYSSOLN"] ==
2039 "PETScMultiLevelStaticCond",
2040 "A parallel solver must be used when run in parallel.");
2049 void SessionReader::ReadGlobalSysSolnInfo(TiXmlElement *conditions)
2051 GetGloSysSolnList().clear();
2058 TiXmlElement *GlobalSys =
2059 conditions->FirstChildElement(
"GLOBALSYSSOLNINFO");
2066 TiXmlElement *VarInfo = GlobalSys->FirstChildElement(
"V");
2070 std::stringstream tagcontent;
2071 tagcontent << *VarInfo;
2072 ASSERTL0(VarInfo->Attribute(
"VAR"),
2073 "Missing VAR attribute in GobalSysSolnInfo XML "
2074 "element: \n\t'" + tagcontent.str() +
"'");
2076 std::string VarList = VarInfo->Attribute(
"VAR");
2078 "VAR attribute must be non-empty in XML element:\n\t'"
2079 + tagcontent.str() +
"'");
2082 std::vector<std::string> varStrings;
2083 bool valid = ParseUtils::GenerateOrderedStringVector(
2084 VarList.c_str(),varStrings);
2086 ASSERTL0(valid,
"Unable to process list of variable in XML "
2087 "element \n\t'" + tagcontent.str() +
"'");
2089 if(varStrings.size())
2091 TiXmlElement *SysSolnInfo = VarInfo->FirstChildElement(
"I");
2096 tagcontent << *SysSolnInfo;
2098 ASSERTL0(SysSolnInfo->Attribute(
"PROPERTY"),
2099 "Missing PROPERTY attribute in "
2100 "GlobalSysSolnInfo for variable(s) '"
2101 + VarList +
"' in XML element: \n\t'"
2102 + tagcontent.str() +
"'");
2104 std::string SysSolnProperty =
2105 SysSolnInfo->Attribute(
"PROPERTY");
2108 "GlobalSysSolnIno properties must have a "
2109 "non-empty name for variable(s) : '"
2110 + VarList +
"' in XML element: \n\t'"
2111 + tagcontent.str() +
"'");
2114 std::string SysSolnPropertyUpper =
2115 boost::to_upper_copy(SysSolnProperty);
2118 ASSERTL0(SysSolnInfo->Attribute(
"VALUE"),
2119 "Missing VALUE attribute in GlobalSysSolnInfo "
2120 "for variable(s) '" + VarList
2121 +
"' in XML element: \n\t"
2122 + tagcontent.str() +
"'");
2124 std::string SysSolnValue =
2125 SysSolnInfo->Attribute(
"VALUE");
2127 "GlobalSysSolnInfo properties must have a "
2128 "non-empty value for variable(s) '"
2129 + VarList +
"' in XML element: \n\t'"
2130 + tagcontent.str() +
"'");
2133 for(
int i = 0; i < varStrings.size(); ++i)
2136 if ((x = GetGloSysSolnList().
find(varStrings[i])) ==
2137 GetGloSysSolnList().end())
2139 (GetGloSysSolnList()[varStrings[i]])[
2140 SysSolnPropertyUpper] = SysSolnValue;
2144 x->second[SysSolnPropertyUpper] = SysSolnValue;
2148 SysSolnInfo = SysSolnInfo->NextSiblingElement(
"I");
2150 VarInfo = VarInfo->NextSiblingElement(
"V");
2154 if (m_verbose && GetGloSysSolnList().size() > 0 && m_comm)
2156 if(m_comm->GetRank() == 0)
2158 cout <<
"GlobalSysSoln Info:" << endl;
2161 for (x = GetGloSysSolnList().begin();
2162 x != GetGloSysSolnList().end();
2165 cout <<
"\t Variable: " << x->first << endl;
2168 for (y = x->second.begin(); y != x->second.end(); ++y)
2170 cout <<
"\t\t " << y->first <<
" = " << y->second
2183 void SessionReader::ReadExpressions(TiXmlElement *conditions)
2185 m_expressions.clear();
2192 TiXmlElement *expressionsElement =
2193 conditions->FirstChildElement(
"EXPRESSIONS");
2195 if (expressionsElement)
2197 TiXmlElement *expr = expressionsElement->FirstChildElement(
"E");
2201 stringstream tagcontent;
2202 tagcontent << *expr;
2204 "Missing NAME attribute in expression "
2205 "definition: \n\t'" + tagcontent.str() +
"'");
2206 std::string nameString = expr->Attribute(
"NAME");
2208 "Expressions must have a non-empty name: \n\t'"
2209 + tagcontent.str() +
"'");
2212 "Missing VALUE attribute in expression "
2213 "definition: \n\t'" + tagcontent.str() +
"'");
2214 std::string valString = expr->Attribute(
"VALUE");
2216 "Expressions must have a non-empty value: \n\t'"
2217 + tagcontent.str() +
"'");
2220 = m_expressions.find(nameString);
2221 ASSERTL0(exprIter == m_expressions.end(),
2222 std::string(
"Expression '") + nameString
2223 + std::string(
"' already specified."));
2225 m_expressions[nameString] = valString;
2226 expr = expr->NextSiblingElement(
"E");
2235 void SessionReader::ReadVariables(TiXmlElement *conditions)
2237 m_variables.clear();
2244 TiXmlElement *variablesElement =
2245 conditions->FirstChildElement(
"VARIABLES");
2249 if (variablesElement)
2251 TiXmlElement *varElement =
2252 variablesElement->FirstChildElement(
"V");
2255 int nextVariableNumber = -1;
2259 stringstream tagcontent;
2260 tagcontent << *varElement;
2264 nextVariableNumber++;
2267 int err = varElement->QueryIntAttribute(
"ID", &i);
2269 "Variables must have a unique ID number attribute "
2270 "in XML element: \n\t'" + tagcontent.str() +
"'");
2272 "ID numbers for variables must begin with zero and"
2273 " be sequential in XML element: \n\t'"
2274 + tagcontent.str() +
"'");
2276 TiXmlNode* varChild = varElement->FirstChild();
2281 while(varChild && varChild->Type() != TiXmlNode::TINYXML_TEXT)
2283 varChild = varChild->NextSibling();
2287 "Unable to read variable definition body for "
2289 + boost::lexical_cast<string>(i)
2290 +
" in XML element: \n\t'"
2291 + tagcontent.str() +
"'");
2292 std::string variableName = varChild->ToText()->ValueStr();
2294 std::istringstream variableStrm(variableName);
2295 variableStrm >> variableName;
2298 variableName) == m_variables.end(),
2300 + boost::lexical_cast<
string>(i)
2301 +
" in XML element \n\t'" + tagcontent.str()
2302 +
"'\nhas already been defined.");
2304 m_variables.push_back(variableName);
2306 varElement = varElement->NextSiblingElement(
"V");
2310 "Number of variables must be greater than zero.");
2318 void SessionReader::ReadFunctions(TiXmlElement *conditions)
2320 m_functions.clear();
2328 TiXmlElement *
function = conditions->FirstChildElement(
"FUNCTION");
2331 stringstream tagcontent;
2332 tagcontent << *
function;
2335 ASSERTL0(function->Attribute(
"NAME"),
2336 "Functions must have a NAME attribute defined in XML "
2337 "element: \n\t'" + tagcontent.str() +
"'");
2338 std::string functionStr =
function->Attribute(
"NAME");
2340 "Functions must have a non-empty name in XML "
2341 "element: \n\t'" + tagcontent.str() +
"'");
2344 boost::to_upper(functionStr);
2347 TiXmlElement *variable =
function->FirstChildElement();
2356 std::string conditionType = variable->Value();
2359 std::string variableStr;
2360 if (!variable->Attribute(
"VAR"))
2366 variableStr = variable->Attribute(
"VAR");
2370 std::vector<std::string> variableList;
2371 ParseUtils::GenerateOrderedStringVector(variableStr.c_str(),
2375 std::string domainStr;
2376 if (!variable->Attribute(
"DOMAIN"))
2382 domainStr = variable->Attribute(
"DOMAIN");
2386 std::vector<std::string> varSplit;
2387 std::vector<unsigned int> domainList;
2388 ParseUtils::GenerateSeqVector(domainStr.c_str(), domainList);
2391 if (conditionType ==
"E")
2396 ASSERTL0(variable->Attribute(
"VALUE"),
2397 "Attribute VALUE expected for function '"
2398 + functionStr +
"'.");
2399 std::string fcnStr = variable->Attribute(
"VALUE");
2402 (std::string(
"Expression for var: ")
2404 + std::string(
" must be specified.")).c_str());
2406 SubstituteExpressions(fcnStr);
2414 else if (conditionType ==
"F")
2416 if (variable->Attribute(
"TIMEDEPENDENT") &&
2417 boost::lexical_cast<
bool>(variable->Attribute(
"TIMEDEPENDENT")))
2427 ASSERTL0(variable->Attribute(
"FILE"),
2428 "Attribute FILE expected for function '"
2429 + functionStr +
"'.");
2430 std::string filenameStr = variable->Attribute(
"FILE");
2433 "A filename must be specified for the FILE "
2434 "attribute of function '" + functionStr
2437 std::vector<std::string> fSplit;
2438 boost::split(fSplit, filenameStr, boost::is_any_of(
":"));
2440 ASSERTL0(fSplit.size() == 1 || fSplit.size() == 2,
2441 "Incorrect filename specification in function "
2442 + functionStr +
"'. "
2443 "Specify variables inside file as: "
2444 "filename:var1,var2");
2449 if (fSplit.size() == 2)
2452 "Filename variable mapping not valid "
2453 "when using * as a variable inside "
2454 "function '" + functionStr +
"'.");
2457 varSplit, fSplit[1], boost::is_any_of(
","));
2458 ASSERTL0(varSplit.size() == variableList.size(),
2459 "Filename variables should contain the "
2460 "same number of variables defined in "
2461 "VAR in function " + functionStr +
"'.");
2468 stringstream tagcontent;
2469 tagcontent << *variable;
2472 "Identifier " + conditionType +
" in function "
2473 + std::string(function->Attribute(
"NAME"))
2474 +
" is not recognised in XML element: \n\t'"
2475 + tagcontent.str() +
"'");
2481 for (
unsigned int i = 0; i < variableList.size(); ++i)
2483 for(
unsigned int j = 0; j < domainList.size(); ++j)
2486 pair<std::string,int> key(variableList[i],domainList[j]);
2488 = functionVarMap.find(key);
2489 ASSERTL0(fcnsIter == functionVarMap.end(),
2490 "Error setting expression '" + variableList[i]
2492 + boost::lexical_cast<std::string>(domainList[j])
2493 +
"' in function '" + functionStr +
"'. "
2494 "Expression has already been defined.");
2496 if (varSplit.size() > 0)
2500 functionVarMap[key] = funcDef2;
2504 functionVarMap[key] = funcDef;
2509 variable = variable->NextSiblingElement();
2512 m_functions[functionStr] = functionVarMap;
2513 function =
function->NextSiblingElement(
"FUNCTION");
2521 void SessionReader::ReadFilters(TiXmlElement *filters)
2530 TiXmlElement *filter = filters->FirstChildElement(
"FILTER");
2533 ASSERTL0(filter->Attribute(
"TYPE"),
2534 "Missing attribute 'TYPE' for filter.");
2535 std::string typeStr = filter->Attribute(
"TYPE");
2537 std::map<std::string, std::string> vParams;
2539 TiXmlElement *param = filter->FirstChildElement(
"PARAM");
2543 "Missing attribute 'NAME' for parameter in filter "
2545 std::string nameStr = param->Attribute(
"NAME");
2547 ASSERTL0(param->GetText(),
"Empty value string for param.");
2548 std::string valueStr = param->GetText();
2550 vParams[nameStr] = valueStr;
2552 param = param->NextSiblingElement(
"PARAM");
2555 m_filters.push_back(
2556 std::pair<std::string, FilterParams>(typeStr, vParams));
2558 filter = filter->NextSiblingElement(
"FILTER");
2562 void SessionReader::ParseEquals(
2563 const std::string &line,
2568 int beg = line.find_first_not_of(
" ");
2569 int end = line.find_first_of(
"=");
2571 if (beg == end)
throw 1;
2573 if (end != line.find_last_of(
"="))
throw 1;
2575 if (end == std::string::npos)
throw 1;
2577 lhs = line.substr(line.find_first_not_of(
" "),
2579 lhs = lhs .substr(0, lhs.find_last_not_of(
" ")+1);
2580 rhs = line.substr(line.find_last_of(
"=")+1);
2581 rhs = rhs .substr(rhs.find_first_not_of(
" "));
2582 rhs = rhs .substr(0, rhs.find_last_not_of(
" ")+1);
2588 void SessionReader::CmdLineOverride()
2591 if (m_cmdLineOptions.count(
"solverinfo"))
2593 std::vector<std::string> solverInfoList =
2594 m_cmdLineOptions[
"solverinfo"].as<
2595 std::vector<std::string> >();
2597 for (
int i = 0; i < solverInfoList.size(); ++i)
2599 std::string
lhs, rhs;
2603 ParseEquals(solverInfoList[i], lhs, rhs);
2607 ASSERTL0(
false,
"Parse error with command line "
2608 "option: "+solverInfoList[i]);
2611 std::string lhsUpper = boost::to_upper_copy(lhs);
2612 m_solverInfo[lhsUpper] = rhs;
2616 if (m_cmdLineOptions.count(
"parameter"))
2618 std::vector<std::string> parametersList =
2619 m_cmdLineOptions[
"parameter"].as<
2620 std::vector<std::string> >();
2622 for (
int i = 0; i < parametersList.size(); ++i)
2624 std::string
lhs, rhs;
2628 ParseEquals(parametersList[i], lhs, rhs);
2632 ASSERTL0(
false,
"Parse error with command line "
2633 "option: "+parametersList[i]);
2636 std::string lhsUpper = boost::to_upper_copy(lhs);
2640 m_parameters[lhsUpper] =
2645 ASSERTL0(
false,
"Unable to convert string: "+rhs+
2646 "to double value.");
2652 void SessionReader::VerifySolverInfo()
2654 SolverInfoMap::const_iterator x;
2655 for (x = m_solverInfo.begin(); x != m_solverInfo.end(); ++x)
2657 std::string solverProperty = x->first;
2658 std::string solverValue = x->second;
2660 EnumMapList::const_iterator propIt =
2661 GetSolverInfoEnums().find(solverProperty);
2662 if (propIt != GetSolverInfoEnums().end())
2664 EnumMap::const_iterator valIt =
2665 propIt->second.find(solverValue);
2666 ASSERTL0(valIt != propIt->second.end(),
2667 "Value '" + solverValue +
"' is not valid for "
2668 "property '" + solverProperty +
"'");
2674 void SessionReader::SetUpXmlDoc(
void)
2676 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
int GetSize(const Array< OneD, const NekDouble > &x)
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
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()