36 #ifndef NEKTAR_LIB_UTILITIES_SESSIONREADER_H
37 #define NEKTAR_LIB_UTILITIES_SESSIONREADER_H
47 #include <boost/algorithm/string.hpp>
48 #include <boost/enable_shared_from_this.hpp>
49 #include <boost/program_options/variables_map.hpp>
56 namespace LibUtilities
63 typedef std::map<std::string, std::string>
TagMap;
77 typedef std::map<std::string, int>
EnumMap;
116 typedef std::map<std::string, FunctionVariableMap >
124 public boost::enable_shared_from_this<SessionReader>
141 int argc,
char *argv[])
162 std::vector<std::string> &pFilenames,
167 ::AllocateSharedPtr(argc, argv, pFilenames, pComm);
175 const std::vector<std::string> &pFilenames,
185 const std::string& pPath);
188 const std::string& pPath)
const;
204 const std::string &name)
const;
207 const std::string &pName)
const;
210 const std::string &name,
214 const std::string &name,
216 const int &def)
const;
219 const std::string &name,
223 const std::string &name,
228 const std::string &name,
232 const std::string &name,
239 const std::string &name)
const;
242 const std::string &pProperty)
const;
245 const std::string &pProperty,
const std::string &pValue);
252 const std::string &vValue)
const;
255 const std::string &name,
257 const std::string &def =
"")
const;
260 const std::string &name,
261 const std::string &trueval,
263 const bool &def =
false)
const;
266 const std::string &name,
267 const std::string &trueval)
const;
271 const std::string &name,
272 const T &trueval)
const;
281 const std::string &pName,
282 const std::string &pValue);
287 const std::string &variable,
288 const std::string &property)
const;
291 const std::string &variable,
292 const std::string &property)
const;
298 const std::string &name)
const;
301 const std::string &name,
303 const std::string &def =
"")
const;
306 const std::string &name,
308 const bool &def =
false)
const;
311 const std::string &name,
316 const std::string &name,
317 const std::string &trueval,
319 const bool &def =
false)
const;
324 const unsigned int &idx)
const;
326 const unsigned int &idx,
327 std::string newname);
335 const std::string &name)
const;
338 const std::string &name,
339 const std::string &variable,
340 const int pDomain = 0)
const;
343 const std::string &name,
344 const std::string &variable,
345 const int pDomain = 0)
const;
348 const std::string &name,
349 const unsigned int &var,
350 const int pDomain = 0)
const;
353 const std::string &name,
354 const std::string &variable,
355 const int pDomain = 0)
const;
358 const std::string &pName,
359 const unsigned int &pVar,
360 const int pDomain = 0)
const;
363 const std::string &name,
364 const std::string &variable,
365 const int pDomain = 0)
const;
368 const std::string &name,
369 const unsigned int &var,
370 const int pDomain = 0)
const;
374 const std::string &name,
375 const std::string &variable,
376 const int pDomain = 0)
const;
386 const std::string& pName)
const;
389 const std::string& pName,
390 const std::string& pValue);
393 const std::string& pName)
const;
401 const std::string& pName)
const;
403 template <
typename T>
405 const std::string& pName)
const
412 const std::string &pName,
413 const std::string &pShortName,
414 const std::string &pDescription);
418 const std::string &pName,
419 const std::string &pShortName,
420 const std::string &pDescription);
486 int argc,
char *argv[]);
493 const std::string &pFilename,
494 TiXmlDocument* pDoc)
const;
497 const std::vector<std::string> &pFilenames)
const;
517 TiXmlElement *conditions);
533 const std::string &line,
544 const std::string &name,
const T &trueval)
const
546 return (GetSolverInfoAsEnum<T>(name) == trueval);
555 const std::string &pName)
const
557 std::string vName = boost::to_upper_copy(pName);
559 "Solver info '" + pName +
"' not defined.");
565 "Enum for SolverInfo property '" + pName +
"' not found.");
568 ASSERTL0((y = x->second.find(vValue)) != x->second.end(),
569 "Value of SolverInfo property '" + pName +
582 const std::string &pName,
583 const std::string &pValue)
const
585 std::string vName = boost::to_upper_copy(pName);
590 "Enum for property '" + pName +
"' not found.");
593 ASSERTL0((y = x->second.find(pValue)) != x->second.end(),
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);
636 x->second[pString] = pEnumValue;
659 const std::string &pName,
660 const std::string &pValue)
662 std::string vName = boost::to_upper_copy(pName);
672 const std::string &pName,
673 const std::string &pShortName,
674 const std::string &pDescription)
676 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
679 x.description = pDescription;
690 const std::string &pName,
691 const std::string &pShortName,
692 const std::string &pDescription)
694 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
697 x.description = pDescription;
710 return shared_from_this();
ParameterMap m_parameters
Parameters.
bool DefinesCmdLineArgument(const std::string &pName) const
Checks if a specified cmdline argument has been given.
void SetParameter(const std::string &name, int &var)
Set an integer parameter.
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.
TiXmlElement * GetElement(const std::string &pPath)
Provides direct access to the TiXmlElement specified.
std::map< std::string, std::string > SolverInfoMap
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.
TiXmlDocument * MergeDoc(const std::vector< std::string > &pFilenames) const
Creates an XML document from a list of input files.
#define ASSERTL0(condition, msg)
void CmdLineOverride()
Enforce parameters from command line arguments.
std::map< std::string, int > EnumMap
CommSharedPtr & GetComm()
Returns the communication object.
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.
std::map< std::string, FunctionVariableMap > FunctionMap
std::vector< std::string > ParseCommandLineArguments(int argc, char *argv[])
Parse the program arguments and fill m_cmdLineOptions.
void SetSolverInfo(const std::string &pProperty, const std::string &pValue)
Sets the value of the specified solver info property.
~SessionReader()
Destructor.
EquationSharedPtr GetFunction(const std::string &name, const std::string &variable, const int pDomain=0) const
Returns an EquationSharedPtr to a given function variable.
void SetVariable(const unsigned int &idx, std::string newname)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
bool MatchSolverInfoAsEnum(const std::string &name, const T &trueval) const
Check if the value of a solver info property matches.
std::map< std::pair< std::string, int >, FunctionVariableDefinition > FunctionVariableMap
static GloSysSolnInfoList & GetGloSysSolnList()
GlobalSysSoln Info map.
SolverInfoMap m_solverInfo
Solver information properties.
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.
AnalyticExpressionEvaluator m_exprEvaluator
Analytic expression evaluator instance.
ExpressionMap m_expressions
Expressions.
std::map< std::string, std::string > TagMap
TiXmlDocument & GetDocument()
Provides direct access to the TiXmlDocument object.
void SubstituteExpressions(std::string &expr)
Substitutes expressions defined in the XML document.
std::map< int, std::vector< unsigned int > > BndRegionOrdering
void LoadDoc(const std::string &pFilename, TiXmlDocument *pDoc) const
Loads an xml file into a tinyxml doc and decompresses if needed.
SessionReaderSharedPtr GetSharedThisPtr()
Returns a shared pointer to the current object.
std::map< std::string, std::string > GloSysInfoMap
void PartitionComm()
Partitions the comm object based on session parameters.
const std::string & GetVariable(const unsigned int &idx) const
Returns the name of the variable specified by the given index.
void ReadExpressions(TiXmlElement *conditions)
Reads the EXPRESSIONS section of the XML document.
std::map< int, std::vector< unsigned int > > CompositeOrdering
CommSharedPtr m_comm
Communication object.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
EquationSharedPtr m_expression
bool DefinesGlobalSysSolnInfo(const std::string &variable, const std::string &property) const
const T GetSolverInfoAsEnum(const std::string &pName) const
Returns the value of the specified solver info property as enum.
const std::string & GetGlobalSysSolnInfo(const std::string &variable, const std::string &property) const
const NekDouble & GetParameter(const std::string &pName) const
Returns the value of the specified parameter.
const std::vector< std::string > & GetFilenames() const
Returns the filename of the loaded XML document.
void ReadSolverInfo(TiXmlElement *conditions)
Reads the SOLVERINFO section of the XML document.
void ReadGlobalSysSolnInfo(TiXmlElement *conditions)
Reads the GLOBALSYSSOLNINFO section of the XML document.
const char *const FunctionTypeMap[]
void LoadGeometricInfo(const std::string &name, std::string &var, const std::string &def="") const
Checks for and load a geometric info string property.
void SetTag(const std::string &pName, const std::string &pValue)
Sets a specified tag.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
bool DefinesGeometricInfo(const std::string &name) const
Checks if a geometric info property is defined.
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
const T GetValueAsEnum(const std::string &pName, const std::string &vValue) const
Returns the value of the specified property and value as enum.
void Finalise()
Finalises the session.
std::map< std::string, std::string > GeometricInfoMap
std::map< std::string, std::string > FilterParams
const std::string & GetSessionName() const
Returns the session name of the loaded XML document.
const std::string & GetSolverInfo(const std::string &pProperty) const
Returns the value of the specified solver info property.
std::vector< std::string > m_filenames
Filenames.
VariableList m_variables
Variables.
bool m_verbose
Be verbose.
void ReadFunctions(TiXmlElement *conditions)
Reads the FUNCTIONS section of the XML document.
void ParseEquals(const std::string &line, std::string &lhs, std::string &rhs)
Parse a string in the form lhs = rhs.
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.
const std::string GetSessionNameRank() const
Returns the session name with process rank.
void CreateComm(int &argc, char *argv[])
Loads the given XML document and instantiates an appropriate communication object.
void LoadParameter(const std::string &name, int &var) const
Load an integer parameter.
std::map< std::string, GloSysInfoMap > GloSysSolnInfoList
AnalyticExpressionEvaluator & GetExpressionEvaluator()
Returns the instance of AnalyticExpressionEvaluator specific to this session.
T GetCmdLineArgument(const std::string &pName) const
Retrieves a command-line argument value.
const FilterMap & GetFilters() const
std::vector< std::string > VariableList
#define LIB_UTILITIES_EXPORT
bool DefinesParameter(const std::string &name) const
Checks if a parameter is specified in the XML document.
std::vector< std::pair< std::string, FilterParams > > FilterMap
CompositeOrdering GetCompositeOrdering() const
FunctionMap m_functions
Functions.
boost::program_options::variables_map m_cmdLineOptions
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.
std::map< std::string, std::string > ExpressionMap
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.
std::vector< std::string > GetVariables() const
Returns the names of all variables.
void ReadVariables(TiXmlElement *conditions)
Reads the VARIABLES section of the XML document.
FilterMap m_filters
Filters map.
boost::shared_ptr< Equation > EquationSharedPtr
This class defines evaluator of analytic (symbolic) mathematical expressions. Expressions are allowed...
bool DefinesSolverInfo(const std::string &name) const
Checks if a solver info property is specified.
BndRegionOrdering GetBndRegionOrdering() const
void ReadFilters(TiXmlElement *filters)
Reads the FILTERS section of the XML document.
void VerifySolverInfo()
Check values of solver info options are valid.
GeometricInfoMap m_geometricInfo
Geometric information properties.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::map< std::string, NekDouble > ParameterMap
std::string ParseSessionName(std::vector< std::string > &filenames)
Parse the session name.
void ParseDocument()
Loads and parses the specified file.
bool DefinesTag(const std::string &pName) const
Checks if a specified tag is defined.
Reads and parses information from a Nektar++ XML session file.
SessionReader(int argc, char *argv[], const std::vector< std::string > &pFilenames, const CommSharedPtr &pComm)
bool DefinesFunction(const std::string &name) const
Checks if a specified function is defined in the XML document.
const std::string & GetTag(const std::string &pName) const
Returns the value of a specified tag.
static EnumMapList & GetSolverInfoEnums()
String to enumeration map for Solver Info parameters.
void LoadSolverInfo(const std::string &name, std::string &var, const std::string &def="") const
Check for and load a solver info property.
std::map< std::string, EnumMap > EnumMapList
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
std::string m_fileVariable
enum FunctionType GetFunctionType(const std::string &name, const std::string &variable, const int pDomain=0) const
Returns the type of a given function variable.
static CmdLineArgMap & GetCmdLineArgMap()
CmdLine argument map.
static SolverInfoMap & GetSolverInfoDefaults()
Default solver info options.
std::map< std::string, CmdLineArg > CmdLineArgMap
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.
static std::string RegisterDefaultSolverInfo(const std::string &pName, const std::string &pValue)
Registers the default string value of a solver info property.
bool DefinesElement(const std::string &pPath) const
Tests if a specified element is defined in the XML document.
CompositeOrdering m_compOrder
Map of original composite ordering for parallel periodic bcs.
void PartitionMesh()
Partitions the mesh when running in parallel.
std::string m_sessionName
Session name of the loaded XML document (filename minus ext).
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...
TagMap m_tags
Custom tags.
BndRegionOrdering m_bndRegOrder
Map of original boundary region ordering for parallel periodic bcs.
void ReadParameters(TiXmlElement *conditions)
Reads the PARAMETERS section of the XML document.