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;
117 typedef std::map<std::string, FunctionVariableMap >
141 int argc,
char *argv[])
161 std::vector<std::string> &pFilenames,
166 ::AllocateSharedPtr(argc, argv, pFilenames, pComm);
173 const std::vector<std::string> &pFilenames,
180 const std::vector<std::string> &filenames =
181 std::vector<std::string>());
187 const std::string& pPath);
190 const std::string& pPath)
const;
208 const std::string &
name)
const;
211 const std::string &pName)
const;
214 const std::string &
name,
218 const std::string &
name,
220 const int &def)
const;
223 const std::string &
name,
227 const std::string &
name,
232 const std::string &
name,
236 const std::string &
name,
243 const std::string &
name)
const;
246 const std::string &pProperty)
const;
249 const std::string &pProperty,
const std::string &pValue);
256 const std::string &vValue)
const;
259 const std::string &
name,
261 const std::string &def =
"")
const;
264 const std::string &
name,
265 const std::string &trueval,
267 const bool &def =
false)
const;
270 const std::string &
name,
271 const std::string &trueval)
const;
275 const std::string &
name,
276 const T &trueval)
const;
285 const std::string &pName,
286 const std::string &pValue);
291 const std::string &variable,
292 const std::string &property)
const;
295 const std::string &variable,
296 const std::string &property)
const;
306 const std::string &
name)
const;
309 const std::string &
name,
311 const std::string &def =
"")
const;
314 const std::string &
name,
316 const bool &def =
false)
const;
319 const std::string &
name,
324 const std::string &
name,
325 const std::string &trueval,
327 const bool &def =
false)
const;
332 const unsigned int &idx)
const;
334 const unsigned int &idx,
335 std::string newname);
343 const std::string &
name)
const;
346 const std::string &
name,
347 const std::string &variable,
348 const int pDomain = 0)
const;
351 const std::string &
name,
352 const std::string &variable,
353 const int pDomain = 0)
const;
356 const std::string &
name,
357 const unsigned int &var,
358 const int pDomain = 0)
const;
361 const std::string &
name,
362 const std::string &variable,
363 const int pDomain = 0)
const;
366 const std::string &pName,
367 const unsigned int &pVar,
368 const int pDomain = 0)
const;
371 const std::string &
name,
372 const std::string &variable,
373 const int pDomain = 0)
const;
376 const std::string &
name,
377 const unsigned int &var,
378 const int pDomain = 0)
const;
382 const std::string &
name,
383 const std::string &variable,
384 const int pDomain = 0)
const;
393 const std::string& pName)
const;
396 const std::string& pName,
397 const std::string& pValue);
400 const std::string& pName)
const;
408 const std::string& pName)
const;
410 template <
typename T>
412 const std::string& pName)
const
419 const std::string &pName,
420 const std::string &pShortName,
421 const std::string &pDescription);
425 const std::string &pName,
426 const std::string &pShortName,
427 const std::string &pDescription);
487 int argc,
char *argv[]);
494 const std::string &pFilename,
495 TiXmlDocument* pDoc)
const;
498 const std::vector<std::string> &pFilenames)
const;
516 TiXmlElement *conditions);
519 TiXmlElement *conditions);
535 const std::string &line,
546 const std::string &
name,
const T &trueval)
const
548 return (GetSolverInfoAsEnum<T>(
name) == trueval);
557 const std::string &pName)
const
559 std::string vName = boost::to_upper_copy(pName);
561 "Solver info '" + pName +
"' not defined.");
566 "Enum for SolverInfo property '" + pName +
"' not found.");
568 auto y = x->second.find(vValue);
570 "Value of SolverInfo property '" + pName +
583 const std::string &pName,
584 const std::string &pValue)
const
586 std::string vName = boost::to_upper_copy(pName);
590 "Enum for property '" + pName +
"' not found.");
592 auto y = x->second.find(pValue);
594 "Value of property '" + pValue +
"' is invalid.");
626 std::string pEnum, std::string pString,
int pEnumValue)
628 std::string vEnum = boost::to_upper_copy(pEnum);
637 x->second[pString] = pEnumValue;
660 const std::string &pName,
661 const std::string &pValue)
663 std::string vName = boost::to_upper_copy(pName);
673 const std::string &pName,
674 const std::string &pShortName,
675 const std::string &pDescription)
677 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
691 const std::string &pName,
692 const std::string &pShortName,
693 const std::string &pDescription)
695 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.
TimeIntScheme m_timeIntScheme
Time integration scheme information.
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 ReadTimeIntScheme(TiXmlElement *conditions)
Reads the TIMEINTEGRATIONSCHEME section of the 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.
const TimeIntScheme & GetTimeIntScheme() const
Returns the time integration scheme structure m_timeIntScheme from the session file.
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.
bool DefinesTimeIntScheme() const
Returns true if the TIMEINTEGRATIONSCHEME section is defined in the session file.
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
The above copyright notice and this permission notice shall be included.
EquationSharedPtr m_expression
std::string m_fileVariable
std::vector< NekDouble > freeParams