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>
62typedef std::map<std::string, std::string>
TagMap;
64typedef std::vector<std::pair<std::string, FilterParams>>
FilterMap;
75typedef std::map<std::string, int>
EnumMap;
135 int argc,
char *argv[])
154 int argc,
char *argv[], std::vector<std::string> &pFilenames,
159 argc, argv, pFilenames, pComm, timelevel);
164 int argc,
char *argv[],
const std::vector<std::string> &pFilenames,
171 const std::vector<std::string> &filenames = std::vector<std::string>());
197 const std::string &pName)
const;
206 const int &def)
const;
210 const size_t &def)
const;
232 const std::string &pProperty)
const;
235 const std::string &pValue);
237 template <
typename T>
240 template <
typename T>
242 const std::string &vValue)
const;
246 const std::string &def =
"")
const;
249 const std::string &trueval,
251 const bool &def =
false)
const;
254 const std::string &trueval)
const;
256 template <
typename T>
258 const T &trueval)
const;
261 std::string pEnum, std::string pString,
int pEnumValue);
264 const std::string &pName,
const std::string &pValue);
271 const std::string &variable,
const std::string &property)
const;
274 const std::string &variable,
const std::string &property)
const;
284 const std::string &
name)
const;
287 const std::string &
name, std::string &var,
288 const std::string &def =
"")
const;
292 const bool &def =
false)
const;
299 const std::string &trueval,
301 const bool &def =
false)
const;
306 const unsigned int &idx)
const;
308 std::string newname);
318 const std::string &variable,
319 const int pDomain = 0)
const;
323 const int pDomain = 0)
const;
327 const int pDomain = 0)
const;
330 const std::string &
name,
const std::string &variable,
331 const int pDomain = 0)
const;
334 const std::string &pName,
const unsigned int &pVar,
335 const int pDomain = 0)
const;
338 const std::string &
name,
const std::string &variable,
339 const int pDomain = 0)
const;
342 const std::string &
name,
const unsigned int &var,
343 const int pDomain = 0)
const;
347 const std::string &
name,
const std::string &variable,
348 const int pDomain = 0)
const;
359 const std::string &pValue);
362 const std::string &pName)
const;
370 const std::string &pName)
const;
378 const std::string &pName,
const std::string &pShortName,
379 const std::string &pDescription);
382 const std::string &pName,
const std::string &pShortName,
383 const std::string &pDescription);
405 TiXmlElement *&element,
const size_t timeLevel,
406 const bool disableCheck =
true);
469 TiXmlDocument *pDoc)
const;
472 const std::vector<std::string> &pFilenames)
const;
503 std::string &lhs, std::string &rhs);
511 const T &trueval)
const
513 return (GetSolverInfoAsEnum<T>(
name) == trueval);
521 const std::string &pName)
const
523 std::string vName = boost::to_upper_copy(pName);
525 "Solver info '" + pName +
"' not defined.");
530 "Enum for SolverInfo property '" + pName +
"' not found.");
532 auto y = x->second.find(vValue);
534 "Value of SolverInfo property '" + pName +
"' is invalid.");
544 const std::string &pValue)
const
546 std::string vName = boost::to_upper_copy(pName);
550 "Enum for property '" + pName +
"' not found.");
552 auto y = x->second.find(pValue);
554 "Value of property '" + pValue +
"' is invalid.");
587 std::string vEnum = boost::to_upper_copy(pEnum);
596 x->second[pString] = pEnumValue;
618 const std::string &pName,
const std::string &pValue)
620 std::string vName = boost::to_upper_copy(pName);
629 const std::string &pName,
const std::string &pShortName,
630 const std::string &pDescription)
632 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
645 const std::string &pName,
const std::string &pShortName,
646 const std::string &pDescription)
648 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
661 std::string childElementName,
662 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.
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.
static void GetXMLElementTimeLevel(TiXmlElement *&element, const size_t timeLevel, const bool disableCheck=true)
Get XML elment time level (Parallel-in-Time)
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.
SessionReader(int argc, char *argv[], const std::vector< std::string > &pFilenames, const CommSharedPtr &pComm, const int &timelevel)
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.
void TestSharedFilesystem()
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.
size_t m_timeLevel
Time level.
const std::string GetSessionNameRank() const
Returns the session name with process rank.
size_t GetTimeLevel(void) const
Get time level (Parallel-in-Time)
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
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[], std::vector< std::string > &pFilenames, const CommSharedPtr &pComm=CommSharedPtr(), const int &timelevel=0)
Creates an instance of the SessionReader class initialised using a separate list of XML documents.
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
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, 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