35 #ifndef NEKTAR_LIB_UTILITIES_SESSIONREADER_H
36 #define NEKTAR_LIB_UTILITIES_SESSIONREADER_H
47 #include <boost/algorithm/string/case_conv.hpp>
48 #include <boost/program_options/variables_map.hpp>
55 namespace LibUtilities
62 typedef std::map<std::string, std::string>
TagMap;
76 typedef std::map<std::string, int>
EnumMap;
109 typedef std::map<std::string, FunctionVariableMap >
133 int argc,
char *argv[])
153 std::vector<std::string> &pFilenames,
158 ::AllocateSharedPtr(argc, argv, pFilenames, pComm);
165 const std::vector<std::string> &pFilenames,
172 const std::vector<std::string> &filenames =
173 std::vector<std::string>());
179 const std::string& pPath);
182 const std::string& pPath)
const;
200 const std::string &
name)
const;
203 const std::string &pName)
const;
206 const std::string &
name,
210 const std::string &
name,
212 const int &def)
const;
215 const std::string &
name,
219 const std::string &
name,
224 const std::string &
name,
228 const std::string &
name,
235 const std::string &
name)
const;
238 const std::string &pProperty)
const;
241 const std::string &pProperty,
const std::string &pValue);
248 const std::string &vValue)
const;
251 const std::string &
name,
253 const std::string &def =
"")
const;
256 const std::string &
name,
257 const std::string &trueval,
259 const bool &def =
false)
const;
262 const std::string &
name,
263 const std::string &trueval)
const;
267 const std::string &
name,
268 const T &trueval)
const;
277 const std::string &pName,
278 const std::string &pValue);
283 const std::string &variable,
284 const std::string &property)
const;
287 const std::string &variable,
288 const std::string &property)
const;
295 const std::string &
name)
const;
298 const std::string &
name,
300 const std::string &def =
"")
const;
303 const std::string &
name,
305 const bool &def =
false)
const;
308 const std::string &
name,
313 const std::string &
name,
314 const std::string &trueval,
316 const bool &def =
false)
const;
321 const unsigned int &idx)
const;
323 const unsigned int &idx,
324 std::string newname);
332 const std::string &
name)
const;
335 const std::string &
name,
336 const std::string &variable,
337 const int pDomain = 0)
const;
340 const std::string &
name,
341 const std::string &variable,
342 const int pDomain = 0)
const;
345 const std::string &
name,
346 const unsigned int &var,
347 const int pDomain = 0)
const;
350 const std::string &
name,
351 const std::string &variable,
352 const int pDomain = 0)
const;
355 const std::string &pName,
356 const unsigned int &pVar,
357 const int pDomain = 0)
const;
360 const std::string &
name,
361 const std::string &variable,
362 const int pDomain = 0)
const;
365 const std::string &
name,
366 const unsigned int &var,
367 const int pDomain = 0)
const;
371 const std::string &
name,
372 const std::string &variable,
373 const int pDomain = 0)
const;
382 const std::string& pName)
const;
385 const std::string& pName,
386 const std::string& pValue);
389 const std::string& pName)
const;
397 const std::string& pName)
const;
399 template <
typename T>
401 const std::string& pName)
const
408 const std::string &pName,
409 const std::string &pShortName,
410 const std::string &pDescription);
414 const std::string &pName,
415 const std::string &pShortName,
416 const std::string &pDescription);
474 int argc,
char *argv[]);
481 const std::string &pFilename,
482 TiXmlDocument* pDoc)
const;
485 const std::vector<std::string> &pFilenames)
const;
503 TiXmlElement *conditions);
519 const std::string &line,
530 const std::string &
name,
const T &trueval)
const
532 return (GetSolverInfoAsEnum<T>(
name) == trueval);
541 const std::string &pName)
const
543 std::string vName = boost::to_upper_copy(pName);
545 "Solver info '" + pName +
"' not defined.");
550 "Enum for SolverInfo property '" + pName +
"' not found.");
552 auto y = x->second.find(vValue);
554 "Value of SolverInfo property '" + pName +
567 const std::string &pName,
568 const std::string &pValue)
const
570 std::string vName = boost::to_upper_copy(pName);
574 "Enum for property '" + pName +
"' not found.");
576 auto y = x->second.find(pValue);
578 "Value of property '" + pValue +
"' is invalid.");
610 std::string pEnum, std::string pString,
int pEnumValue)
612 std::string vEnum = boost::to_upper_copy(pEnum);
621 x->second[pString] = pEnumValue;
644 const std::string &pName,
645 const std::string &pValue)
647 std::string vName = boost::to_upper_copy(pName);
657 const std::string &pName,
658 const std::string &pShortName,
659 const std::string &pDescription)
661 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
675 const std::string &pName,
676 const std::string &pShortName,
677 const std::string &pDescription)
679 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
#define ASSERTL0(condition, msg)
#define LIB_UTILITIES_EXPORT
Reads and parses information from a Nektar++ XML session file.
const std::string & GetGlobalSysSolnInfo(const std::string &variable, const std::string &property) const
void ReadSolverInfo(TiXmlElement *conditions)
Reads the SOLVERINFO section of the XML document.
GeometricInfoMap m_geometricInfo
Geometric information properties.
bool DefinesFunction(const std::string &name) const
Checks if a specified function is defined in the XML document.
std::string GetFunctionFilenameVariable(const std::string &name, const std::string &variable, const int pDomain=0) const
Returns the filename variable to be loaded for a given variable index.
bool DefinesGeometricInfo(const std::string &name) const
Checks if a geometric info property is defined.
std::vector< std::string > ParseCommandLineArguments(int argc, char *argv[])
Parse the program arguments and fill m_cmdLineOptions.
bool m_verbose
Be verbose.
static SolverInfoMap & GetSolverInfoDefaults()
Default solver info options.
static std::string RegisterCmdLineArgument(const std::string &pName, const std::string &pShortName, const std::string &pDescription)
Registers a command-line argument with the session reader.
InterpreterSharedPtr GetInterpreter()
Returns the instance of the Interpreter specific to this session.
TiXmlElement * GetElement(const std::string &pPath)
Provides direct access to the TiXmlElement specified.
void ReadVariables(TiXmlElement *conditions)
Reads the VARIABLES section of the XML document.
bool DefinesSolverInfo(const std::string &name) const
Checks if a solver info property is specified.
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.
const std::string & GetSessionName() const
Returns the session name of the loaded XML document.
void MatchGeometricInfo(const std::string &name, const std::string &trueval, bool &var, const bool &def=false) const
Check if the value of a geometric info string property matches.
void ReadFilters(TiXmlElement *filters)
Reads the FILTERS section of the XML document.
void ReadGlobalSysSolnInfo(TiXmlElement *conditions)
Reads the GLOBALSYSSOLNINFO section of the XML document.
void Finalise()
Finalises the session.
void InitSession(const std::vector< std::string > &filenames=std::vector< std::string >())
TagMap m_tags
Custom tags.
VariableList m_variables
Variables.
SolverInfoMap m_solverInfo
Solver information properties.
void SubstituteExpressions(std::string &expr)
Substitutes expressions defined in the XML document.
std::vector< std::string > GetVariables() const
Returns the names of all variables.
static CmdLineArgMap & GetCmdLineArgMap()
CmdLine argument map.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
TiXmlDocument * MergeDoc(const std::vector< std::string > &pFilenames) const
Creates an XML document from a list of input files.
void SetVariable(const unsigned int &idx, std::string newname)
T GetCmdLineArgument(const std::string &pName) const
Retrieves a command-line argument value.
~SessionReader()
Destructor.
void CmdLineOverride()
Enforce parameters from command line arguments.
void ParseDocument()
Loads and parses the specified file.
bool m_sharedFilesystem
Running on a shared filesystem.
static std::string RegisterDefaultSolverInfo(const std::string &pName, const std::string &pValue)
Registers the default string value of a solver info property.
std::string ParseSessionName(std::vector< std::string > &filenames)
Parse the session name.
std::string GetFunctionFilename(const std::string &name, const std::string &variable, const int pDomain=0) const
Returns the filename to be loaded for a given variable.
enum FunctionType GetFunctionType(const std::string &name, const std::string &variable, const int pDomain=0) const
Returns the type of a given function variable.
bool DefinesTag(const std::string &pName) const
Checks if a specified tag is defined.
void LoadParameter(const std::string &name, int &var) const
Load an integer parameter.
CommSharedPtr GetComm()
Returns the communication object.
const FilterMap & GetFilters() const
const NekDouble & GetParameter(const std::string &pName) const
Returns the value of the specified parameter.
const T GetSolverInfoAsEnum(const std::string &pName) const
Returns the value of the specified solver info property as enum.
ParameterMap m_parameters
Parameters.
void SetParameter(const std::string &name, int &var)
Set an integer parameter.
InterpreterSharedPtr m_interpreter
Interpreter instance.
static EnumMapList & GetSolverInfoEnums()
String to enumeration map for Solver Info parameters.
void VerifySolverInfo()
Check values of solver info options are valid.
void SetSolverInfo(const std::string &pProperty, const std::string &pValue)
Sets the value of the specified solver info property.
const std::string & GetVariable(const unsigned int &idx) const
Returns the name of the variable specified by the given index.
EquationSharedPtr GetFunction(const std::string &name, const std::string &variable, const int pDomain=0) const
Returns an EquationSharedPtr to a given function variable.
const std::string & GetTag(const std::string &pName) const
Returns the value of a specified tag.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[], std::vector< std::string > &pFilenames, const CommSharedPtr &pComm=CommSharedPtr())
Creates an instance of the SessionReader class initialised using a separate list of XML documents.
void TestSharedFilesystem()
ExpressionMap m_expressions
Expressions.
FunctionMap m_functions
Functions.
TiXmlDocument & GetDocument()
Provides direct access to the TiXmlDocument object.
bool DefinesElement(const std::string &pPath) const
Tests if a specified element is defined in the XML document.
std::vector< std::string > m_filenames
Filenames.
bool DefinesGlobalSysSolnInfo(const std::string &variable, const std::string &property) const
void ReadFunctions(TiXmlElement *conditions)
Reads the FUNCTIONS section of the XML document.
void LoadDoc(const std::string &pFilename, TiXmlDocument *pDoc) const
Loads an xml file into a tinyxml doc and decompresses if needed.
bool DefinesParameter(const std::string &name) const
Checks if a parameter is specified in the XML document.
SessionReader(int argc, char *argv[], const std::vector< std::string > &pFilenames, const CommSharedPtr &pComm)
const std::string GetSessionNameRank() const
Returns the session name with process rank.
bool MatchSolverInfoAsEnum(const std::string &name, const T &trueval) const
Check if the value of a solver info property matches.
void LoadGeometricInfo(const std::string &name, std::string &var, const std::string &def="") const
Checks for and load a geometric info string property.
FilterMap m_filters
Filters map.
void SetTag(const std::string &pName, const std::string &pValue)
Sets a specified tag.
boost::program_options::variables_map m_cmdLineOptions
std::string m_sessionName
Session name of the loaded XML document (filename minus ext).
CommSharedPtr m_comm
Communication object.
static std::string RegisterCmdLineFlag(const std::string &pName, const std::string &pShortName, const std::string &pDescription)
Registers a command-line flag with the session reader.
const T GetValueAsEnum(const std::string &pName, const std::string &vValue) const
Returns the value of the specified property and value as enum.
void MatchSolverInfo(const std::string &name, const std::string &trueval, bool &var, const bool &def=false) const
Check if the value of a solver info property matches.
void CreateComm(int &argc, char *argv[])
Loads the given XML document and instantiates an appropriate communication object.
const std::string & GetSolverInfo(const std::string &pProperty) const
Returns the value of the specified solver info property.
void ParseEquals(const std::string &line, std::string &lhs, std::string &rhs)
Parse a string in the form lhs = rhs.
const std::vector< std::string > & GetFilenames() const
Returns the filename of the loaded XML document.
bool GetSharedFilesystem()
Returns if file system shared.
static GloSysSolnInfoList & GetGloSysSolnList()
GlobalSysSoln Info map.
void PartitionComm()
Partitions the comm object based on session parameters.
bool DefinesCmdLineArgument(const std::string &pName) const
Checks if a specified cmdline argument has been given.
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.
void ReadParameters(TiXmlElement *conditions)
Reads the PARAMETERS section of the XML document.
void LoadSolverInfo(const std::string &name, std::string &var, const std::string &def="") const
Check for and load a solver info property.
std::string GetGeometryType() const
void ReadExpressions(TiXmlElement *conditions)
Reads the EXPRESSIONS section of the XML document.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< Interpreter > InterpreterSharedPtr
std::map< std::string, std::string > FilterParams
std::map< std::string, std::string > SolverInfoMap
std::map< std::string, GloSysInfoMap > GloSysSolnInfoList
std::map< std::string, FunctionVariableMap > FunctionMap
const char *const FunctionTypeMap[]
std::map< std::string, NekDouble > ParameterMap
std::map< std::string, int > EnumMap
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
std::vector< std::pair< std::string, FilterParams > > FilterMap
std::vector< std::string > VariableList
std::map< std::string, std::string > GloSysInfoMap
std::map< std::string, EnumMap > EnumMapList
std::map< std::string, std::string > ExpressionMap
std::map< std::string, CmdLineArg > CmdLineArgMap
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::map< std::string, std::string > GeometricInfoMap
@ eFunctionTypeExpression
@ eFunctionTypeTransientFile
std::map< std::pair< std::string, int >, FunctionVariableDefinition > FunctionVariableMap
std::map< std::string, std::string > TagMap
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
EquationSharedPtr m_expression
std::string m_fileVariable