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>
56 namespace LibUtilities
63 typedef std::map<std::string, std::string>
TagMap;
65 typedef std::vector<std::pair<std::string, FilterParams>>
FilterMap;
76 typedef std::map<std::string, int>
EnumMap;
136 int argc,
char *argv[])
155 int argc,
char *argv[], std::vector<std::string> &pFilenames,
160 argc, argv, pFilenames, pComm);
165 int argc,
char *argv[],
const std::vector<std::string> &pFilenames,
172 const std::vector<std::string> &filenames = std::vector<std::string>());
198 const std::string &pName)
const;
207 const int &def)
const;
211 const size_t &def)
const;
233 const std::string &pProperty)
const;
236 const std::string &pValue);
238 template <
typename T>
241 template <
typename T>
243 const std::string &vValue)
const;
247 const std::string &def =
"")
const;
250 const std::string &trueval,
252 const bool &def =
false)
const;
255 const std::string &trueval)
const;
257 template <
typename T>
259 const T &trueval)
const;
262 std::string pEnum, std::string pString,
int pEnumValue);
265 const std::string &pName,
const std::string &pValue);
272 const std::string &variable,
const std::string &property)
const;
275 const std::string &variable,
const std::string &property)
const;
285 const std::string &
name)
const;
288 const std::string &
name, std::string &var,
289 const std::string &def =
"")
const;
293 const bool &def =
false)
const;
300 const std::string &trueval,
302 const bool &def =
false)
const;
307 const unsigned int &idx)
const;
309 std::string newname);
319 const std::string &variable,
320 const int pDomain = 0)
const;
324 const int pDomain = 0)
const;
328 const int pDomain = 0)
const;
331 const std::string &
name,
const std::string &variable,
332 const int pDomain = 0)
const;
335 const std::string &pName,
const unsigned int &pVar,
336 const int pDomain = 0)
const;
339 const std::string &
name,
const std::string &variable,
340 const int pDomain = 0)
const;
343 const std::string &
name,
const unsigned int &var,
344 const int pDomain = 0)
const;
348 const std::string &
name,
const std::string &variable,
349 const int pDomain = 0)
const;
360 const std::string &pValue);
363 const std::string &pName)
const;
371 const std::string &pName)
const;
379 const std::string &pName,
const std::string &pShortName,
380 const std::string &pDescription);
383 const std::string &pName,
const std::string &pShortName,
384 const std::string &pDescription);
462 TiXmlDocument *pDoc)
const;
465 const std::vector<std::string> &pFilenames)
const;
498 std::string &lhs, std::string &rhs);
504 template <
typename T>
506 const T &trueval)
const
508 return (GetSolverInfoAsEnum<T>(
name) == trueval);
514 template <
typename T>
516 const std::string &pName)
const
518 std::string vName = boost::to_upper_copy(pName);
520 "Solver info '" + pName +
"' not defined.");
525 "Enum for SolverInfo property '" + pName +
"' not found.");
527 auto y = x->second.find(vValue);
529 "Value of SolverInfo property '" + pName +
"' is invalid.");
537 template <
typename T>
539 const std::string &pValue)
const
541 std::string vName = boost::to_upper_copy(pName);
545 "Enum for property '" + pName +
"' not found.");
547 auto y = x->second.find(pValue);
549 "Value of property '" + pValue +
"' is invalid.");
582 std::string vEnum = boost::to_upper_copy(pEnum);
591 x->second[pString] = pEnumValue;
613 const std::string &pName,
const std::string &pValue)
615 std::string vName = boost::to_upper_copy(pName);
624 const std::string &pName,
const std::string &pShortName,
625 const std::string &pDescription)
627 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
640 const std::string &pName,
const std::string &pShortName,
641 const std::string &pDescription)
643 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
653 std::string childElementName,
654 const TiXmlHandle &docHandle);
#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.
void SetUpdateOptFile(bool flag)
Set bool to update optimisation file.
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.
bool GetBackups() const
Returns the backups.
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.
bool GetUpdateOptFile() const
Get bool to update optimisation file.
bool m_updateOptFile
Update optimisation file.
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...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Interpreter > InterpreterSharedPtr
std::map< std::string, FunctionVariableMap > FunctionMap
std::map< std::string, std::string > FilterParams
std::map< std::string, std::string > SolverInfoMap
std::map< std::string, GloSysInfoMap > GloSysSolnInfoList
const char *const FunctionTypeMap[]
std::map< std::pair< std::string, int >, FunctionVariableDefinition > FunctionVariableMap
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::string > VariableList
std::map< std::string, std::string > GloSysInfoMap
TiXmlElement * GetChildElementOrThrow(const std::string &filename, std::string elementName, const TiXmlHandle &docHandle)
std::map< std::string, EnumMap > EnumMapList
std::vector< std::pair< std::string, FilterParams > > FilterMap
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::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