47 #include <boost/iostreams/filtering_streambuf.hpp>
48 #include <boost/iostreams/copy.hpp>
49 #include <boost/iostreams/filter/gzip.hpp>
50 #include <boost/algorithm/string.hpp>
59 #include <boost/program_options.hpp>
60 #include <boost/format.hpp>
62 namespace po = boost::program_options;
63 namespace io = boost::iostreams;
67 namespace LibUtilities
123 return solverInfoEnums;
138 return solverInfoMap;
154 return gloSysSolnInfoList;
168 return cmdLineArguments;
180 SessionReader::SessionReader(
int argc,
char *argv[])
183 m_filenames = ParseCommandLineArguments(argc, argv);
185 ASSERTL0(m_filenames.size() > 0,
"No session file(s) given.");
187 m_filename = m_filenames[0];
188 m_sessionName = m_filename.substr(0, m_filename.find_last_of(
'.'));
189 if (m_filename.size() > 3 &&
190 m_filename.substr(m_filename.size() - 3, 3) ==
".gz")
193 m_sessionName.substr(0, m_sessionName.find_last_of(
'.'));
197 CreateComm(argc, argv);
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_filename = pFilenames[0];
225 m_sessionName = m_filename.substr(0, m_filename.find_last_of(
'.'));
226 if (m_filename.size() > 3 &&
227 m_filename.substr(m_filename.size() - 3, 3) ==
".gz")
230 m_sessionName.substr(0, m_sessionName.find_last_of(
'.'));
236 CreateComm(argc, argv);
242 if (m_comm->GetSize() > 1)
244 GetSolverInfoDefaults()[
"GLOBALSYSSOLN"] =
245 "IterativeStaticCond";
251 if (m_comm->GetSize() > 1)
253 GetSolverInfoDefaults()[
"GLOBALSYSSOLN"] =
254 "IterativeStaticCond";
262 SessionReader::~SessionReader()
274 void SessionReader::InitSession()
276 m_exprEvaluator.SetRandomSeed((m_comm->GetRank() + 1) * time(NULL));
292 if (m_verbose && m_comm)
294 if (m_comm->GetRank() == 0 && m_parameters.size() > 0)
296 cout <<
"Parameters:" << endl;
298 for (x = m_parameters.begin(); x != m_parameters.end(); ++x)
300 cout <<
"\t" << x->first <<
" = " << x->second << endl;
305 if (m_comm->GetRank() == 0 && m_solverInfo.size() > 0)
307 cout <<
"Solver Info:" << endl;
309 for (x = m_solverInfo.begin(); x != m_solverInfo.end(); ++x)
311 cout <<
"\t" << x->first <<
" = " << x->second << endl;
323 std::vector<std::string> SessionReader::ParseCommandLineArguments(
324 int argc,
char *argv[])
327 po::options_description desc(
"Allowed options");
329 (
"verbose,v",
"be verbose")
330 (
"help,h",
"print this help message")
331 (
"solverinfo,I", po::value<vector<std::string> >(),
332 "override a SOLVERINFO property")
333 (
"parameter,P", po::value<vector<std::string> >(),
334 "override a parameter")
335 (
"shared-filesystem,s",
"Using shared filesystem.")
336 (
"npx", po::value<int>(),
337 "number of procs in X-dir")
338 (
"npy", po::value<int>(),
339 "number of procs in Y-dir")
340 (
"npz", po::value<int>(),
341 "number of procs in Z-dir")
342 (
"part-info",
"Output partition information")
345 CmdLineArgMap::const_iterator cmdIt;
346 for (cmdIt = GetCmdLineArgMap().begin();
347 cmdIt != GetCmdLineArgMap().end(); ++cmdIt)
349 std::string names = cmdIt->first;
350 if (cmdIt->second.shortName !=
"")
352 names +=
"," + cmdIt->second.shortName;
354 if (cmdIt->second.isFlag)
357 (names.c_str(), cmdIt->second.description.c_str())
363 (names.c_str(), po::value<std::string>(),
364 cmdIt->second.description.c_str())
371 po::options_description hidden(
"Hidden options");
373 (
"input-file", po::value< vector<string> >(),
378 po::options_description all(
"All options");
379 all.add(desc).add(hidden);
382 po::positional_options_description p;
383 p.add(
"input-file", -1);
386 po::parsed_options parsed = po::command_line_parser(argc, argv).
389 allow_unregistered().
393 po::store(parsed, m_cmdLineOptions);
394 po::notify(m_cmdLineOptions);
397 if (m_cmdLineOptions.count(
"help"))
399 cout << desc << endl;
404 if (m_cmdLineOptions.count(
"verbose"))
414 std::vector< po::basic_option<char> >
::iterator x;
415 for (x = parsed.options.begin(); x != parsed.options.end(); ++x)
419 cout <<
"Warning: Unknown option: " << x->string_key
425 if (m_cmdLineOptions.count(
"input-file"))
427 return m_cmdLineOptions[
"input-file"].as<
428 std::vector<std::string> >();
432 return std::vector<std::string>();
440 TiXmlDocument& SessionReader::GetDocument()
442 ASSERTL1(m_xmlDoc,
"XML Document not defined.");
469 TiXmlElement* SessionReader::GetElement(
const string& pPath)
471 std::string vPath = boost::to_upper_copy(pPath);
472 std::vector<std::string> st;
473 boost::split(st, vPath, boost::is_any_of(
"\\/ "));
474 ASSERTL0(st.size() > 0,
"No path given in XML element request.");
476 TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
477 ASSERTL0(vReturn, std::string(
"Cannot find element '")
478 + st[0] + std::string(
"'."));
479 for (
int i = 1; i < st.size(); ++i)
481 vReturn = vReturn->FirstChildElement(st[i].c_str());
482 ASSERTL0(vReturn, std::string(
"Cannot find element '")
483 + st[i] + std::string(
"'."));
492 bool SessionReader::DefinesElement(
const std::string &pPath)
const
494 std::string vPath = boost::to_upper_copy(pPath);
495 std::vector<std::string> st;
496 boost::split(st, vPath, boost::is_any_of(
"\\/ "));
497 ASSERTL0(st.size() > 0,
"No path given in XML element request.");
499 TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
500 ASSERTL0(vReturn, std::string(
"Cannot find element '")
501 + st[0] + std::string(
"'."));
502 for (
int i = 1; i < st.size(); ++i)
504 vReturn = vReturn->FirstChildElement(st[i].c_str());
505 if (!vReturn)
return false;
514 const std::string& SessionReader::GetFilename()
const
523 const std::string& SessionReader::GetSessionName()
const
525 return m_sessionName;
533 const std::string SessionReader::GetSessionNameRank()
const
535 std::string dirname = m_sessionName +
"_xml";
536 fs::path pdirname(dirname);
538 std::string vFilename =
"P" + boost::lexical_cast<std::string>(m_comm->GetRowComm()->GetRank());
539 fs::path pFilename(vFilename);
541 fs::path fullpath = pdirname / pFilename;
570 bool SessionReader::DefinesParameter(
const std::string& pName)
const
572 std::string vName = boost::to_upper_copy(pName);
573 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
574 return (paramIter != m_parameters.end());
587 const std::string& pName)
const
589 std::string vName = boost::to_upper_copy(pName);
590 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
592 ASSERTL0(paramIter != m_parameters.end(),
593 "Unable to find requested parameter: " + pName);
595 return paramIter->second;
602 void SessionReader::LoadParameter(
603 const std::string &pName,
int &pVar)
const
605 std::string vName = boost::to_upper_copy(pName);
606 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
607 ASSERTL0(paramIter != m_parameters.end(),
"Required parameter '" +
608 pName +
"' not specified in session.");
609 pVar = (int)floor(paramIter->second);
616 void SessionReader::LoadParameter(
617 const std::string &pName,
int &pVar,
const int &pDefault)
const
619 std::string vName = boost::to_upper_copy(pName);
620 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
621 if(paramIter != m_parameters.end())
623 pVar = (int)floor(paramIter->second);
635 void SessionReader::LoadParameter(
636 const std::string &pName,
NekDouble& pVar)
const
638 std::string vName = boost::to_upper_copy(pName);
639 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
640 ASSERTL0(paramIter != m_parameters.end(),
"Required parameter '" +
641 pName +
"' not specified in session.");
642 pVar = paramIter->second;
649 void SessionReader::LoadParameter(
650 const std::string &pName,
654 std::string vName = boost::to_upper_copy(pName);
655 ParameterMap::const_iterator paramIter = m_parameters.find(vName);
656 if(paramIter != m_parameters.end())
658 pVar = paramIter->second;
671 void SessionReader::SetParameter(
const std::string &pName,
int &pVar)
673 std::string vName = boost::to_upper_copy(pName);
674 m_parameters[vName] = pVar;
681 void SessionReader::SetParameter(
682 const std::string &pName,
NekDouble& pVar)
684 std::string vName = boost::to_upper_copy(pName);
685 m_parameters[vName] = pVar;
693 bool SessionReader::DefinesSolverInfo(
const std::string &pName)
const
695 std::string vName = boost::to_upper_copy(pName);
696 SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
697 return (infoIter != m_solverInfo.end());
704 const std::string& SessionReader::GetSolverInfo(
705 const std::string &pProperty)
const
707 std::string vProperty = boost::to_upper_copy(pProperty);
708 SolverInfoMap::const_iterator iter = m_solverInfo.find(vProperty);
710 ASSERTL1(iter != m_solverInfo.end(),
711 "Unable to find requested property: " + pProperty);
719 void SessionReader::SetSolverInfo(
720 const std::string &pProperty,
const std::string &pValue)
722 std::string vProperty = boost::to_upper_copy(pProperty);
725 ASSERTL1(iter != m_solverInfo.end(),
726 "Unable to find requested property: " + pProperty);
728 iter->second = pValue;
734 void SessionReader::LoadSolverInfo(
735 const std::string &pName,
737 const std::string &pDefault)
const
739 std::string vName = boost::to_upper_copy(pName);
740 SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
741 if(infoIter != m_solverInfo.end())
743 pVar = infoIter->second;
755 void SessionReader::MatchSolverInfo(
756 const std::string &pName,
757 const std::string &pTrueVal,
759 const bool &pDefault)
const
761 std::string vName = boost::to_upper_copy(pName);
762 SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
763 if(infoIter != m_solverInfo.end())
765 pVar = boost::iequals(infoIter->second, pTrueVal);
777 bool SessionReader::MatchSolverInfo(
778 const std::string &pName,
779 const std::string &pTrueVal)
const
781 if (DefinesSolverInfo(pName))
783 std::string vName = boost::to_upper_copy(pName);
784 SolverInfoMap::const_iterator iter = m_solverInfo.find(vName);
785 if(iter != m_solverInfo.end())
797 bool SessionReader::DefinesGlobalSysSolnInfo(
const std::string &pVariable,
798 const std::string &pProperty)
const
801 GloSysSolnInfoList::const_iterator iter =
802 GetGloSysSolnList().find(pVariable);
803 if(iter == GetGloSysSolnList().end())
808 std::string vProperty = boost::to_upper_copy(pProperty);
810 GloSysInfoMap::const_iterator iter1 = iter->second.find(vProperty);
811 if(iter1 == iter->second.end())
823 const std::string &SessionReader::GetGlobalSysSolnInfo(
const std::string &pVariable,
const std::string &pProperty)
const
825 GloSysSolnInfoList::const_iterator iter;
827 ASSERTL0( (iter = GetGloSysSolnList().
find(pVariable)) !=
828 GetGloSysSolnList().end(),
829 "Failed to find variable in GlobalSysSolnInfoList");
831 std::string vProperty = boost::to_upper_copy(pProperty);
832 GloSysInfoMap::const_iterator iter1;
834 ASSERTL0( (iter1 = iter->second.find(vProperty)) != iter->second.end(),
835 "Failed to find property: " + vProperty +
" in GlobalSysSolnInfoList");
837 return iter1->second;
843 bool SessionReader::DefinesGeometricInfo(
const std::string &pName)
const
845 std::string vName = boost::to_upper_copy(pName);
846 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
847 return (iter != m_geometricInfo.end());
854 void SessionReader::LoadGeometricInfo(
855 const std::string &pName,
857 const std::string &pDefault)
const
859 std::string vName = boost::to_upper_copy(pName);
860 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
861 if(iter != m_geometricInfo.end())
875 void SessionReader::LoadGeometricInfo(
876 const std::string &pName,
878 const bool &pDefault)
const
880 std::string vName = boost::to_upper_copy(pName);
881 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
882 if(iter != m_geometricInfo.end())
884 if (iter->second ==
"TRUE")
903 void SessionReader::LoadGeometricInfo(
904 const std::string &pName,
908 std::string vName = boost::to_upper_copy(pName);
909 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
910 if(iter != m_geometricInfo.end())
912 pVar = std::atoi(iter->second.c_str());
924 void SessionReader::MatchGeometricInfo(
925 const std::string &pName,
926 const std::string &pTrueVal,
928 const bool &pDefault)
const
930 std::string vName = boost::to_upper_copy(pName);
931 GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
932 if(iter != m_geometricInfo.end())
934 pVar = boost::iequals(iter->second, pTrueVal);
946 const std::string& SessionReader::GetVariable(
947 const unsigned int &idx)
const
949 ASSERTL0(idx < m_variables.size(),
"Variable index out of range.");
950 return m_variables[idx];
958 void SessionReader::SetVariable(
const unsigned int &idx,
961 ASSERTL0(idx < m_variables.size(),
"Variable index out of range.");
962 m_variables[idx] = newname;
969 std::vector<std::string> SessionReader::GetVariables()
const
978 bool SessionReader::DefinesFunction(
const std::string &pName)
const
980 FunctionMap::const_iterator it1;
981 std::string vName = boost::to_upper_copy(pName);
983 if ((it1 = m_functions.find(vName)) != m_functions.end())
994 bool SessionReader::DefinesFunction(
995 const std::string &pName,
996 const std::string &pVariable,
997 const int pDomain)
const
999 FunctionMap::const_iterator it1;
1000 FunctionVariableMap::const_iterator it2;
1001 std::string vName = boost::to_upper_copy(pName);
1004 if ((it1 = m_functions.find(vName)) != m_functions.end())
1006 pair<std::string, int> key(pVariable,pDomain);
1007 pair<std::string, int> defkey(
"*",pDomain);
1009 (it2 = it1->second.find(key)) != it1->second.end() ||
1010 (it2 = it1->second.find(defkey)) != it1->second.end();
1021 const std::string &pName,
1022 const std::string &pVariable,
1023 const int pDomain)
const
1025 FunctionMap::const_iterator it1;
1026 FunctionVariableMap::const_iterator it2, it3;
1027 std::string vName = boost::to_upper_copy(pName);
1029 ASSERTL0((it1 = m_functions.find(vName)) != m_functions.end(),
1030 std::string(
"No such function '") + pName
1031 + std::string(
"' has been defined in the session file."));
1034 pair<std::string,int> key(pVariable,pDomain);
1035 pair<std::string,int> defkey(
"*",pDomain);
1036 bool specific = (it2 = it1->second.find(key)) !=
1038 bool wildcard = (it3 = it1->second.find(defkey)) !=
1043 "No such variable " + pVariable
1044 +
" in domain " + boost::lexical_cast<string>(pDomain)
1045 +
" defined for function " + pName
1046 +
" in session file.");
1055 std::string(
"Function is defined by a file."));
1056 return it2->second.m_expression;
1064 const std::string &pName,
1065 const unsigned int &pVar,
1066 const int pDomain)
const
1068 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1069 return GetFunction(pName, m_variables[pVar],pDomain);
1077 const std::string &pName,
1078 const std::string &pVariable,
1079 const int pDomain)
const
1081 FunctionMap::const_iterator it1;
1082 FunctionVariableMap::const_iterator it2, it3;
1083 std::string vName = boost::to_upper_copy(pName);
1085 it1 = m_functions.find(vName);
1086 ASSERTL0 (it1 != m_functions.end(),
1087 std::string(
"Function '") + pName
1088 + std::string(
"' not found."));
1091 pair<std::string,int> key(pVariable,pDomain);
1092 pair<std::string,int> defkey(
"*",pDomain);
1093 bool specific = (it2 = it1->second.find(key)) !=
1095 bool wildcard = (it3 = it1->second.find(defkey)) !=
1100 "No such variable " + pVariable
1101 +
" in domain " + boost::lexical_cast<string>(pDomain)
1102 +
" defined for function " + pName
1103 +
" in session file.");
1111 return it2->second.m_type;
1119 const std::string &pName,
1120 const unsigned int &pVar,
1121 const int pDomain)
const
1123 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1124 return GetFunctionType(pName, m_variables[pVar],pDomain);
1131 std::string SessionReader::GetFunctionFilename(
1132 const std::string &pName,
1133 const std::string &pVariable,
1134 const int pDomain)
const
1136 FunctionMap::const_iterator it1;
1137 FunctionVariableMap::const_iterator it2, it3;
1138 std::string vName = boost::to_upper_copy(pName);
1140 it1 = m_functions.find(vName);
1141 ASSERTL0 (it1 != m_functions.end(),
1142 std::string(
"Function '") + pName
1143 + std::string(
"' not found."));
1146 pair<std::string,int> key(pVariable,pDomain);
1147 pair<std::string,int> defkey(
"*",pDomain);
1148 bool specific = (it2 = it1->second.find(key)) !=
1150 bool wildcard = (it3 = it1->second.find(defkey)) !=
1155 "No such variable " + pVariable
1156 +
" in domain " + boost::lexical_cast<string>(pDomain)
1157 +
" defined for function " + pName
1158 +
" in session file.");
1166 return it2->second.m_filename;
1173 std::string SessionReader::GetFunctionFilename(
1174 const std::string &pName,
1175 const unsigned int &pVar,
1176 const int pDomain)
const
1178 ASSERTL0(pVar < m_variables.size(),
"Variable index out of range.");
1179 return GetFunctionFilename(pName, m_variables[pVar],pDomain);
1188 return m_exprEvaluator;
1195 bool SessionReader::DefinesTag(
const std::string &pName)
const
1197 std::string vName = boost::to_upper_copy(pName);
1198 TagMap::const_iterator vTagIterator = m_tags.find(vName);
1199 return (vTagIterator != m_tags.end());
1206 void SessionReader::SetTag(
1207 const std::string &pName,
1208 const std::string &pValue)
1210 std::string vName = boost::to_upper_copy(pName);
1211 m_tags[vName] = pValue;
1218 const std::string &SessionReader::GetTag(
const std::string& pName)
const
1220 std::string vName = boost::to_upper_copy(pName);
1221 TagMap::const_iterator vTagIterator = m_tags.find(vName);
1222 ASSERTL0(vTagIterator != m_tags.end(),
1223 "Requested tag does not exist.");
1224 return vTagIterator->second;
1240 bool SessionReader::DefinesCmdLineArgument(
1241 const std::string& pName)
const
1243 return (m_cmdLineOptions.find(pName) != m_cmdLineOptions.end());
1250 void SessionReader::SubstituteExpressions(std::string& pExpr)
1253 for (exprIter = m_expressions.begin();
1254 exprIter != m_expressions.end(); ++exprIter)
1256 boost::replace_all(pExpr, exprIter->first, exprIter->second);
1267 return m_bndRegOrder;
1273 void SessionReader::LoadDoc(
1274 const std::string &pFilename,
1275 TiXmlDocument* pDoc)
const
1277 if (pFilename.size() > 3 &&
1278 pFilename.substr(pFilename.size() - 3, 3) ==
".gz")
1280 ifstream file(pFilename.c_str(),
1281 ios_base::in | ios_base::binary);
1282 ASSERTL0(file.good(),
"Unable to open file: " + pFilename);
1284 io::filtering_streambuf<io::input> in;
1285 in.push(io::gzip_decompressor());
1292 catch (io::gzip_error& e)
1295 "Error: File '" + pFilename +
"' is corrupt.");
1300 ifstream file(pFilename.c_str());
1301 ASSERTL0(file.good(),
"Unable to open file: " + pFilename);
1309 TiXmlDocument *SessionReader::MergeDoc(
1310 const std::vector<std::string> &pFilenames)
const
1312 ASSERTL0(pFilenames.size() > 0,
"No filenames for merging.");
1315 TiXmlDocument *vMainDoc =
new TiXmlDocument;
1316 LoadDoc(pFilenames[0], vMainDoc);
1318 TiXmlHandle vMainHandle(vMainDoc);
1319 TiXmlElement* vMainNektar =
1320 vMainHandle.FirstChildElement(
"NEKTAR").Element();
1325 for (
int i = 1; i < pFilenames.size(); ++i)
1327 if((pFilenames[i].compare(pFilenames[i].size()-3,3,
"xml") == 0)
1328 ||(pFilenames[i].compare(pFilenames[i].size()-6,6,
"xml.gz") == 0))
1330 TiXmlDocument* vTempDoc =
new TiXmlDocument;
1331 LoadDoc(pFilenames[i], vTempDoc);
1333 TiXmlHandle docHandle(vTempDoc);
1334 TiXmlElement* vTempNektar;
1335 vTempNektar = docHandle.FirstChildElement(
"NEKTAR").Element();
1336 ASSERTL0(vTempNektar,
"Unable to find NEKTAR tag in file.");
1337 TiXmlElement* p = vTempNektar->FirstChildElement();
1341 TiXmlElement *vMainEntry =
1342 vMainNektar->FirstChildElement(p->Value());
1343 TiXmlElement *q =
new TiXmlElement(*p);
1346 vMainNektar->RemoveChild(vMainEntry);
1348 vMainNektar->LinkEndChild(q);
1349 p = p->NextSiblingElement();
1362 void SessionReader::ParseDocument()
1365 ASSERTL0(m_xmlDoc,
"No XML document loaded.");
1368 TiXmlHandle docHandle(m_xmlDoc);
1370 e = docHandle.FirstChildElement(
"NEKTAR").
1371 FirstChildElement(
"CONDITIONS").Element();
1376 ReadGlobalSysSolnInfo (e);
1377 ReadExpressions (e);
1381 e = docHandle.FirstChildElement(
"NEKTAR").
1382 FirstChildElement(
"GEOMETRY").Element();
1384 ReadGeometricInfo(e);
1386 e = docHandle.FirstChildElement(
"NEKTAR").
1387 FirstChildElement(
"FILTERS").Element();
1396 void SessionReader::CreateComm(
1406 string vCommModule(
"Serial");
1409 vCommModule =
"ParallelMPI";
1420 void SessionReader::PartitionMesh()
1422 ASSERTL0(m_comm.get(),
"Communication not initialised.");
1428 if (vCommMesh->GetSize() > 1)
1433 string vPartitionerName =
"Metis";
1436 vPartitionerName =
"Scotch";
1438 if (DefinesCmdLineArgument(
"use-metis"))
1440 vPartitionerName =
"Metis";
1442 if (DefinesCmdLineArgument(
"use-scotch"))
1444 vPartitionerName =
"Scotch";
1448 if (DefinesCmdLineArgument(
"shared-filesystem"))
1451 vector<unsigned int> keys, vals;
1454 if (vComm->GetRank() == 0)
1456 m_xmlDoc = MergeDoc(m_filenames);
1460 vPartitionerName, vSession);
1461 vPartitioner->PartitionMesh(
true);
1462 vPartitioner->WriteAllPartitions(vSession);
1463 vPartitioner->GetCompositeOrdering(m_compOrder);
1464 vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
1471 keys[0] = m_compOrder.size();
1472 keys[1] = m_bndRegOrder.size();
1474 for (i = 1; i < vComm->GetSize(); ++i)
1476 vComm->Send(i, keys);
1482 keys.resize(m_compOrder.size());
1483 vals.resize(m_compOrder.size());
1485 for (cIt = m_compOrder.begin(), i = 0;
1486 cIt != m_compOrder.end(); ++cIt, ++i)
1488 keys[i] = cIt->first;
1489 vals[i] = cIt->second.size();
1493 for (i = 1; i < vComm->GetSize(); ++i)
1495 vComm->Send(i, keys);
1496 vComm->Send(i, vals);
1498 for (cIt = m_compOrder.begin();
1499 cIt != m_compOrder.end(); ++cIt)
1501 vComm->Send(i, cIt->second);
1508 keys.resize(m_bndRegOrder.size());
1509 vals.resize(m_bndRegOrder.size());
1511 for (bIt = m_bndRegOrder.begin(), i = 0;
1512 bIt != m_bndRegOrder.end(); ++bIt, ++i)
1514 keys[i] = bIt->first;
1515 vals[i] = bIt->second.size();
1519 for (i = 1; i < vComm->GetSize(); ++i)
1521 vComm->Send(i, keys);
1522 vComm->Send(i, vals);
1524 for (bIt = m_bndRegOrder.begin();
1525 bIt != m_bndRegOrder.end(); ++bIt)
1527 vComm->Send(i, bIt->second);
1531 if (DefinesCmdLineArgument(
"part-info"))
1533 vPartitioner->PrintPartInfo(std::cout);
1539 vComm->Recv(0, keys);
1541 int cmpSize = keys[0];
1542 int bndSize = keys[1];
1544 keys.resize(cmpSize);
1545 vals.resize(cmpSize);
1546 vComm->Recv(0, keys);
1547 vComm->Recv(0, vals);
1549 for (
int i = 0; i < keys.size(); ++i)
1551 vector<unsigned int> tmp(vals[i]);
1552 vComm->Recv(0, tmp);
1553 m_compOrder[keys[i]] = tmp;
1556 keys.resize(bndSize);
1557 vals.resize(bndSize);
1558 vComm->Recv(0, keys);
1559 vComm->Recv(0, vals);
1561 for (
int i = 0; i < keys.size(); ++i)
1563 vector<unsigned int> tmp(vals[i]);
1564 vComm->Recv(0, tmp);
1565 m_bndRegOrder[keys[i]] = tmp;
1571 m_xmlDoc = MergeDoc(m_filenames);
1578 vPartitionerName, vSession);
1579 vPartitioner->PartitionMesh(
false);
1580 vPartitioner->WriteLocalPartition(vSession);
1581 vPartitioner->GetCompositeOrdering(m_compOrder);
1582 vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
1584 if (DefinesCmdLineArgument(
"part-info"))
1586 vPartitioner->PrintPartInfo(std::cout);
1591 std::string dirname = GetSessionName() +
"_xml";
1592 fs::path pdirname(dirname);
1593 boost::format pad(
"P%1$07d.xml");
1594 pad % m_comm->GetRank();
1595 fs::path pFilename(pad.str());
1596 fs::path fullpath = pdirname / pFilename;
1604 m_xmlDoc =
new TiXmlDocument(m_filename);
1606 ASSERTL0(m_xmlDoc,
"Failed to create XML document object.");
1608 bool loadOkay = m_xmlDoc->LoadFile(m_filename);
1609 ASSERTL0(loadOkay,
"Unable to load file: " + m_filename +
1610 ". Check XML standards compliance. Error on line: " +
1611 boost::lexical_cast<std::string>(m_xmlDoc->Row()));
1619 m_xmlDoc = MergeDoc(m_filenames);
1631 void SessionReader::PartitionComm()
1633 if (m_comm->GetSize() > 1)
1638 if (DefinesCmdLineArgument(
"npx")) {
1639 nProcX = GetCmdLineArgument<int>(
"npx");
1641 if (DefinesCmdLineArgument(
"npy")) {
1642 nProcY = GetCmdLineArgument<int>(
"npy");
1644 if (DefinesCmdLineArgument(
"npz")) {
1645 nProcZ = GetCmdLineArgument<int>(
"npz");
1648 ASSERTL0(m_comm->GetSize() % (nProcZ*nProcY*nProcX) == 0,
1649 "Cannot exactly partition using PROC_Z value.");
1651 "Cannot exactly partition using PROC_Y value.");
1653 "Cannot exactly partition using PROC_X value.");
1656 int nProcSm = nProcZ * nProcY * nProcX;
1660 int nProcSem = m_comm->GetSize() / nProcSm;
1662 m_comm->SplitComm(nProcSm,nProcSem);
1663 m_comm->GetColumnComm()->SplitComm((nProcY*nProcX),nProcZ);
1664 m_comm->GetColumnComm()->GetColumnComm()->SplitComm(
1673 void SessionReader::ReadParameters(TiXmlElement *conditions)
1675 m_parameters.clear();
1682 TiXmlElement *parametersElement = conditions->FirstChildElement(
1687 if (parametersElement)
1689 TiXmlElement *parameter =
1690 parametersElement->FirstChildElement(
"P");
1698 TiXmlNode *node = parameter->FirstChild();
1700 while (node && node->Type() != TiXmlNode::TEXT)
1702 node = node->NextSibling();
1708 std::string line = node->ToText()->Value(),
lhs, rhs;
1711 ParseEquals(line,
lhs, rhs);
1716 "File: '" + m_filename +
"', line: "
1717 + boost::lexical_cast<string>(node->Row()));
1723 if (!
lhs.empty() && !rhs.empty())
1729 GetSharedThisPtr(), rhs);
1732 catch (
const std::runtime_error &)
1735 "Error evaluating parameter expression"
1736 " '" + rhs +
"'." );
1738 m_exprEvaluator.SetParameter(
lhs, value);
1739 caseSensitiveParameters[
lhs] = value;
1740 boost::to_upper(
lhs);
1741 m_parameters[
lhs] = value;
1745 parameter = parameter->NextSiblingElement();
1754 void SessionReader::ReadSolverInfo(TiXmlElement *conditions)
1756 m_solverInfo.clear();
1757 m_solverInfo = GetSolverInfoDefaults();
1764 TiXmlElement *solverInfoElement =
1765 conditions->FirstChildElement(
"SOLVERINFO");
1767 if (solverInfoElement)
1769 TiXmlElement *solverInfo =
1770 solverInfoElement->FirstChildElement(
"I");
1775 ASSERTL0(solverInfo->Attribute(
"PROPERTY"),
1776 "Missing PROPERTY attribute in solver info "
1777 "section. File: '" + m_filename +
"', line: " +
1778 boost::lexical_cast<
string>(solverInfo->Row()));
1779 std::string solverProperty =
1780 solverInfo->Attribute(
"PROPERTY");
1782 "Solver info properties must have a non-empty "
1783 "name. File: '" + m_filename +
"', line: "
1784 + boost::lexical_cast<
string>(solverInfo->Row()));
1787 std::string solverPropertyUpper =
1788 boost::to_upper_copy(solverProperty);
1791 ASSERTL0(solverInfo->Attribute(
"VALUE"),
1792 "Missing VALUE attribute in solver info section. "
1793 "File: '" + m_filename +
"', line: "
1794 + boost::lexical_cast<
string>(solverInfo->Row()));
1795 std::string solverValue = solverInfo->Attribute(
"VALUE");
1797 "Solver info properties must have a non-empty "
1798 "value. File: '" + m_filename +
"', line: "
1799 + boost::lexical_cast<
string>(solverInfo->Row()));
1801 EnumMapList::const_iterator propIt =
1802 GetSolverInfoEnums().find(solverPropertyUpper);
1803 if (propIt != GetSolverInfoEnums().end())
1805 EnumMap::const_iterator valIt =
1806 propIt->second.find(solverValue);
1807 ASSERTL0(valIt != propIt->second.end(),
1808 "Value '" + solverValue +
"' is not valid for "
1809 "property '" + solverProperty +
"'. File: '" +
1810 m_filename +
"', line: " + boost::lexical_cast<
1811 string>(solverInfo->Row()));
1815 m_solverInfo[solverPropertyUpper] = solverValue;
1816 solverInfo = solverInfo->NextSiblingElement(
"I");
1820 if (m_comm && m_comm->GetRowComm()->GetSize() > 1)
1823 m_solverInfo[
"GLOBALSYSSOLN"] ==
"IterativeFull" ||
1824 m_solverInfo[
"GLOBALSYSSOLN"] ==
"IterativeStaticCond" ||
1825 m_solverInfo[
"GLOBALSYSSOLN"] ==
1826 "IterativeMultiLevelStaticCond" ||
1827 m_solverInfo[
"GLOBALSYSSOLN"] ==
"XxtFull" ||
1828 m_solverInfo[
"GLOBALSYSSOLN"] ==
"XxtStaticCond" ||
1829 m_solverInfo[
"GLOBALSYSSOLN"] ==
1830 "XxtMultiLevelStaticCond" ||
1831 m_solverInfo[
"GLOBALSYSSOLN"] ==
"PETScFull" ||
1832 m_solverInfo[
"GLOBALSYSSOLN"] ==
"PETScStaticCond" ||
1833 m_solverInfo[
"GLOBALSYSSOLN"] ==
1834 "PETScMultiLevelStaticCond",
1835 "A parallel solver must be used when run in parallel.");
1844 void SessionReader::ReadGlobalSysSolnInfo(TiXmlElement *conditions)
1846 GetGloSysSolnList().clear();
1853 TiXmlElement *GlobalSys =
1854 conditions->FirstChildElement(
"GLOBALSYSSOLNINFO");
1861 TiXmlElement *VarInfo = GlobalSys->FirstChildElement(
"V");
1865 ASSERTL0(VarInfo->Attribute(
"VAR"),
1866 "Missing VAR in attribute of GobalSysSolnInfo section."
1867 "File: '" + m_filename +
", line: " +
1868 boost::lexical_cast<
string>(GlobalSys->Row()));
1870 std::string VarList = VarInfo->Attribute(
"VAR");
1873 std::vector<std::string> varStrings;
1874 bool valid = ParseUtils::GenerateOrderedStringVector(
1875 VarList.c_str(),varStrings);
1877 ASSERTL0(valid,
"Unable to process list of variable in "
1878 "GlobalSysSolnInfo data, File '" + m_filename +
1880 boost::lexical_cast<string>(GlobalSys->Row()));
1882 if(varStrings.size())
1884 TiXmlElement *SysSolnInfo = VarInfo->FirstChildElement(
"I");
1889 ASSERTL0(SysSolnInfo->Attribute(
"PROPERTY"),
1890 "Missing PROPERTY attribute in "
1891 "GlobalSysSolnInfo section. File: '" +
1892 m_filename +
"', line: " +
1893 boost::lexical_cast<
string>(VarInfo->Row()));
1895 std::string SysSolnProperty =
1896 SysSolnInfo->Attribute(
"PROPERTY");
1899 "GlobalSysSolnIno properties must have a "
1900 "non-empty name for variable(s) : '" +
1901 VarList +
". File: '" + m_filename +
", line: "
1902 + boost::lexical_cast<
string>(VarInfo->Row()));
1905 std::string SysSolnPropertyUpper =
1906 boost::to_upper_copy(SysSolnProperty);
1909 ASSERTL0(SysSolnInfo->Attribute(
"VALUE"),
1910 "Missing VALUE attribute in GlobalSysSolnInfo "
1911 "section. File: '" + m_filename +
"', line: "
1912 + boost::lexical_cast<
string>(VarInfo->Row()));
1914 std::string SysSolnValue =
1915 SysSolnInfo->Attribute(
"VALUE");
1917 "GlobalSysSolnInfo properties must have a "
1918 "non-empty value. File: '" + m_filename +
1920 + boost::lexical_cast<
string>(VarInfo->Row()));
1923 for(
int i = 0; i < varStrings.size(); ++i)
1926 if ((x = GetGloSysSolnList().
find(varStrings[i])) ==
1927 GetGloSysSolnList().end())
1929 (GetGloSysSolnList()[varStrings[i]])[
1930 SysSolnPropertyUpper] = SysSolnValue;
1934 x->second[SysSolnPropertyUpper] = SysSolnValue;
1938 SysSolnInfo = SysSolnInfo->NextSiblingElement(
"I");
1940 VarInfo = VarInfo->NextSiblingElement(
"V");
1944 if (m_verbose && GetGloSysSolnList().size() > 0 && m_comm)
1946 if(m_comm->GetRank() == 0)
1948 cout <<
"GlobalSysSoln Info:" << endl;
1951 for (x = GetGloSysSolnList().begin();
1952 x != GetGloSysSolnList().end();
1955 cout <<
"\t Variable: " << x->first << endl;
1958 for (y = x->second.begin(); y != x->second.end(); ++y)
1960 cout <<
"\t\t " << y->first <<
" = " << y->second
1972 void SessionReader::ReadGeometricInfo(TiXmlElement *geometry)
1974 m_geometricInfo.clear();
1981 TiXmlElement *geometricInfoElement =
1982 geometry->FirstChildElement(
"GEOMINFO");
1984 if (geometricInfoElement)
1986 TiXmlElement *geometricInfo =
1987 geometricInfoElement->FirstChildElement(
"I");
1989 while (geometricInfo)
1991 ASSERTL0(geometricInfo->Attribute(
"PROPERTY"),
1992 "Missing PROPERTY attribute in geometric info "
1993 "section. File: '" + m_filename +
"', line: " +
1994 boost::lexical_cast<
string>(geometricInfo->Row()));
1995 std::string geometricProperty =
1996 geometricInfo->Attribute(
"PROPERTY");
1997 ASSERTL0(!geometricProperty.empty(),
1998 "Geometric info properties must have a non-empty "
1999 "name. File: '" + m_filename +
"', line: " +
2000 boost::lexical_cast<
string>(geometricInfo->Row()));
2003 boost::to_upper(geometricProperty);
2007 m_geometricInfo.find(geometricProperty);
2008 ASSERTL0(geometricInfoIter == m_geometricInfo.end(),
2009 "geometricInfo value: " + geometricProperty +
2010 " already specified.");
2013 ASSERTL0(geometricInfo->Attribute(
"VALUE"),
2014 "Missing VALUE attribute in geometric info section"
2015 ". File: '" + m_filename +
", line: " +
2016 boost::lexical_cast<
string>(geometricInfo->Row()));
2017 std::string geometricValue =
2018 geometricInfo->Attribute(
"VALUE");
2020 "Geometric info properties must have a non-empty "
2021 "value. File: '" + m_filename +
", line: " +
2022 boost::lexical_cast<
string>(geometricInfo->Row()));
2025 m_geometricInfo[geometricProperty] = geometricValue;
2026 geometricInfo = geometricInfo->NextSiblingElement(
"I");
2030 if (m_verbose && m_geometricInfo.size() > 0 && m_comm)
2032 if(m_comm->GetRank() == 0)
2034 cout <<
"Geometric Info:" << endl;
2036 for (x = m_geometricInfo.begin();
2037 x != m_geometricInfo.end(); ++x)
2039 cout <<
"\t" << x->first <<
" = " << x->second << endl;
2050 void SessionReader::ReadExpressions(TiXmlElement *conditions)
2052 m_expressions.clear();
2059 TiXmlElement *expressionsElement =
2060 conditions->FirstChildElement(
"EXPRESSIONS");
2062 if (expressionsElement)
2064 TiXmlElement *expr = expressionsElement->FirstChildElement(
"E");
2069 "Missing NAME attribute in expression definition. "
2070 "File: '" + m_filename +
"', line: "
2071 + boost::lexical_cast<std::string>(expr->Row()));
2072 std::string nameString = expr->Attribute(
"NAME");
2074 "Expressions must have a non-empty name. "
2075 "File: '" + m_filename +
"', line: "
2076 + boost::lexical_cast<std::string>(expr->Row()));
2079 "Missing VALUE attribute in expression definition."
2080 " File: '" + m_filename +
"', line: "
2081 + boost::lexical_cast<std::string>(expr->Row()));
2082 std::string valString = expr->Attribute(
"VALUE");
2084 "Expressions must have a non-empty value. "
2085 "File: '" + m_filename +
"', line: "
2086 + boost::lexical_cast<std::string>(expr->Row()));
2089 = m_expressions.find(nameString);
2090 ASSERTL0(exprIter == m_expressions.end(),
2091 std::string(
"Expression '") + nameString
2092 + std::string(
"' already specified."));
2094 m_expressions[nameString] = valString;
2095 expr = expr->NextSiblingElement(
"E");
2104 void SessionReader::ReadVariables(TiXmlElement *conditions)
2106 m_variables.clear();
2113 TiXmlElement *variablesElement =
2114 conditions->FirstChildElement(
"VARIABLES");
2118 if (variablesElement)
2120 TiXmlElement *varElement =
2121 variablesElement->FirstChildElement(
"V");
2124 int nextVariableNumber = -1;
2130 nextVariableNumber++;
2133 int err = varElement->QueryIntAttribute(
"ID", &i);
2135 "Variables must have a unique ID number attribute."
2136 " File: '" + m_filename +
"', line: " +
2137 boost::lexical_cast<string>(varElement->Row()));
2139 "ID numbers for variables must begin with zero and"
2140 " be sequential. File: '"+m_filename+
"', line: " +
2141 boost::lexical_cast<string>(varElement->Row()));
2143 TiXmlNode* varChild = varElement->FirstChild();
2148 while(varChild && varChild->Type() != TiXmlNode::TEXT)
2150 varChild = varChild->NextSibling();
2154 "Unable to read variable definition body for "
2156 + boost::lexical_cast<string>(i) +
". "
2157 " File: '" + m_filename +
"', line: "
2158 + boost::lexical_cast<string>(varElement->Row()));
2159 std::string variableName = varChild->ToText()->ValueStr();
2161 std::istringstream variableStrm(variableName);
2162 variableStrm >> variableName;
2165 variableName) == m_variables.end(),
2166 "Variable with ID "+boost::lexical_cast<
string>(i)
2167 +
" has already been defined. "
2168 " File: '" + m_filename +
"', line: "
2169 + boost::lexical_cast<string>(varElement->Row()));
2171 m_variables.push_back(variableName);
2173 varElement = varElement->NextSiblingElement(
"V");
2177 "Number of variables must be greater than zero.");
2185 void SessionReader::ReadFunctions(TiXmlElement *conditions)
2187 m_functions.clear();
2195 TiXmlElement *
function = conditions->FirstChildElement(
"FUNCTION");
2199 ASSERTL0(function->Attribute(
"NAME"),
2200 "Functions must have a NAME attribute defined. "
2201 "File: '" + m_filename +
"', line: "
2202 + boost::lexical_cast<std::string>(
function->Row()));
2203 std::string functionStr =
function->Attribute(
"NAME");
2205 "Functions must have a non-empty name. "
2206 "File: '" + m_filename +
"', line: "
2207 + boost::lexical_cast<
string>(
function->Row()));
2210 boost::to_upper(functionStr);
2213 TiXmlElement *variable =
function->FirstChildElement();
2222 std::string conditionType = variable->Value();
2225 std::string variableStr;
2226 if (!variable->Attribute(
"VAR"))
2232 variableStr = variable->Attribute(
"VAR");
2236 std::vector<std::string> variableList;
2237 ParseUtils::GenerateOrderedStringVector(variableStr.c_str(),
2241 std::string domainStr;
2242 if (!variable->Attribute(
"DOMAIN"))
2248 domainStr = variable->Attribute(
"DOMAIN");
2252 std::vector<unsigned int> domainList;
2253 ParseUtils::GenerateSeqVector(domainStr.c_str(), domainList);
2256 if (conditionType ==
"E")
2261 ASSERTL0(variable->Attribute(
"VALUE"),
2262 "Attribute VALUE expected for function '"
2263 + functionStr +
"'.");
2264 std::string fcnStr = variable->Attribute(
"VALUE");
2267 (std::string(
"Expression for var: ")
2269 + std::string(
" must be specified.")).c_str());
2271 SubstituteExpressions(fcnStr);
2279 else if (conditionType ==
"F")
2284 ASSERTL0(variable->Attribute(
"FILE"),
2285 "Attribute FILE expected for function '"
2286 + functionStr +
"'.");
2287 std::string filenameStr = variable->Attribute(
"FILE");
2290 "A filename must be specified for the FILE "
2291 "attribute of function '" + functionStr
2302 "Identifier " + conditionType +
" in function "
2303 + std::string(function->Attribute(
"NAME"))
2304 +
" is not recognised. "
2305 "File: '" + m_filename +
"', line: "
2306 + boost::lexical_cast<string>(variable->Row()));
2312 for (
unsigned int i = 0; i < variableList.size(); ++i)
2314 for(
unsigned int j = 0; j < domainList.size(); ++j)
2317 pair<std::string,int> key(variableList[i],domainList[j]);
2319 = functionVarMap.find(key);
2320 ASSERTL0(fcnsIter == functionVarMap.end(),
2321 "Error setting expression '" + variableList[i]
2323 + boost::lexical_cast<std::string>(domainList[j])
2324 +
"' in function '" + functionStr +
"'. "
2325 "Expression has already been defined.");
2327 functionVarMap[key] = funcDef;
2331 variable = variable->NextSiblingElement();
2334 m_functions[functionStr] = functionVarMap;
2335 function =
function->NextSiblingElement(
"FUNCTION");
2343 void SessionReader::ReadFilters(TiXmlElement *filters)
2352 TiXmlElement *filter = filters->FirstChildElement(
"FILTER");
2355 ASSERTL0(filter->Attribute(
"TYPE"),
2356 "Missing attribute 'TYPE' for filter.");
2357 std::string typeStr = filter->Attribute(
"TYPE");
2359 std::map<std::string, std::string> vParams;
2361 TiXmlElement *param = filter->FirstChildElement(
"PARAM");
2365 "Missing attribute 'NAME' for parameter in filter "
2367 std::string nameStr = param->Attribute(
"NAME");
2369 ASSERTL0(param->GetText(),
"Empty value string for param.");
2370 std::string valueStr = param->GetText();
2372 vParams[nameStr] = valueStr;
2374 param = param->NextSiblingElement(
"PARAM");
2377 m_filters.push_back(
2378 std::pair<std::string, FilterParams>(typeStr, vParams));
2380 filter = filter->NextSiblingElement(
"FILTER");
2384 void SessionReader::ParseEquals(
2385 const std::string &line,
2390 int beg = line.find_first_not_of(
" ");
2391 int end = line.find_first_of(
"=");
2393 if (beg == end)
throw 1;
2395 if (end != line.find_last_of(
"="))
throw 1;
2397 if (end == std::string::npos)
throw 1;
2399 lhs = line.substr(line.find_first_not_of(
" "),
2401 lhs = lhs .substr(0, lhs.find_last_not_of(
" ")+1);
2402 rhs = line.substr(line.find_last_of(
"=")+1);
2403 rhs = rhs .substr(rhs.find_first_not_of(
" "));
2404 rhs = rhs .substr(0, rhs.find_last_not_of(
" ")+1);
2410 void SessionReader::CmdLineOverride()
2413 if (m_cmdLineOptions.count(
"solverinfo"))
2415 std::vector<std::string> solverInfoList =
2416 m_cmdLineOptions[
"solverinfo"].as<
2417 std::vector<std::string> >();
2419 for (
int i = 0; i < solverInfoList.size(); ++i)
2421 std::string
lhs, rhs;
2425 ParseEquals(solverInfoList[i], lhs, rhs);
2429 ASSERTL0(
false,
"Parse error with command line "
2430 "option: "+solverInfoList[i]);
2433 std::string lhsUpper = boost::to_upper_copy(lhs);
2434 m_solverInfo[lhsUpper] = rhs;
2438 if (m_cmdLineOptions.count(
"parameter"))
2440 std::vector<std::string> parametersList =
2441 m_cmdLineOptions[
"parameter"].as<
2442 std::vector<std::string> >();
2444 for (
int i = 0; i < parametersList.size(); ++i)
2446 std::string
lhs, rhs;
2450 ParseEquals(parametersList[i], lhs, rhs);
2454 ASSERTL0(
false,
"Parse error with command line "
2455 "option: "+parametersList[i]);
2458 std::string lhsUpper = boost::to_upper_copy(lhs);
2462 m_parameters[lhsUpper] =
2467 ASSERTL0(
false,
"Unable to convert string: "+rhs+
2468 "to double value.");
2474 void SessionReader::SetUpXmlDoc(
void)
2476 m_xmlDoc = MergeDoc(m_filenames);