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;
206 const std::string &name)
const;
209 const std::string &pName)
const;
212 const std::string &name,
216 const std::string &name,
218 const int &def)
const;
221 const std::string &name,
225 const std::string &name,
230 const std::string &name,
234 const std::string &name,
241 const std::string &name)
const;
244 const std::string &pProperty)
const;
247 const std::string &pProperty,
const std::string &pValue);
254 const std::string &vValue)
const;
257 const std::string &name,
259 const std::string &def =
"")
const;
262 const std::string &name,
263 const std::string &trueval,
265 const bool &def =
false)
const;
268 const std::string &name,
269 const std::string &trueval)
const;
273 const std::string &name,
274 const T &trueval)
const;
283 const std::string &pName,
284 const std::string &pValue);
289 const std::string &variable,
290 const std::string &property)
const;
293 const std::string &variable,
294 const std::string &property)
const;
300 const std::string &name)
const;
303 const std::string &name,
305 const std::string &def =
"")
const;
308 const std::string &name,
310 const bool &def =
false)
const;
313 const std::string &name,
318 const std::string &name,
319 const std::string &trueval,
321 const bool &def =
false)
const;
326 const unsigned int &idx)
const;
328 const unsigned int &idx,
329 std::string newname);
337 const std::string &name)
const;
340 const std::string &name,
341 const std::string &variable,
342 const int pDomain = 0)
const;
345 const std::string &name,
346 const std::string &variable,
347 const int pDomain = 0)
const;
350 const std::string &name,
351 const unsigned int &var,
352 const int pDomain = 0)
const;
355 const std::string &name,
356 const std::string &variable,
357 const int pDomain = 0)
const;
360 const std::string &pName,
361 const unsigned int &pVar,
362 const int pDomain = 0)
const;
365 const std::string &name,
366 const std::string &variable,
367 const int pDomain = 0)
const;
370 const std::string &name,
371 const unsigned int &var,
372 const int pDomain = 0)
const;
376 const std::string &name,
377 const std::string &variable,
378 const int pDomain = 0)
const;
388 const std::string& pName)
const;
391 const std::string& pName,
392 const std::string& pValue);
395 const std::string& pName)
const;
403 const std::string& pName)
const;
405 template <
typename T>
407 const std::string& pName)
const
414 const std::string &pName,
415 const std::string &pShortName,
416 const std::string &pDescription);
420 const std::string &pName,
421 const std::string &pShortName,
422 const std::string &pDescription);
492 int argc,
char *argv[]);
499 const std::string &pFilename,
500 TiXmlDocument* pDoc)
const;
503 const std::vector<std::string> &pFilenames)
const;
523 TiXmlElement *conditions);
539 const std::string &line,
550 const std::string &name,
const T &trueval)
const
552 return (GetSolverInfoAsEnum<T>(name) == trueval);
561 const std::string &pName)
const
563 std::string vName = boost::to_upper_copy(pName);
565 "Solver info '" + pName +
"' not defined.");
571 "Enum for SolverInfo property '" + pName +
"' not found.");
574 ASSERTL0((y = x->second.find(vValue)) != x->second.end(),
575 "Value of SolverInfo property '" + pName +
588 const std::string &pName,
589 const std::string &pValue)
const
591 std::string vName = boost::to_upper_copy(pName);
596 "Enum for property '" + pName +
"' not found.");
599 ASSERTL0((y = x->second.find(pValue)) != x->second.end(),
600 "Value of property '" + pValue +
"' is invalid.");
632 std::string pEnum, std::string pString,
int pEnumValue)
634 std::string vEnum = boost::to_upper_copy(pEnum);
642 x->second[pString] = pEnumValue;
665 const std::string &pName,
666 const std::string &pValue)
668 std::string vName = boost::to_upper_copy(pName);
678 const std::string &pName,
679 const std::string &pShortName,
680 const std::string &pDescription)
682 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
685 x.description = pDescription;
696 const std::string &pName,
697 const std::string &pShortName,
698 const std::string &pDescription)
700 ASSERTL0(!pName.empty(),
"Empty name for cmdline argument.");
703 x.description = pDescription;
716 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
bool GetSharedFilesystem()
Returns the communication object.
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.
void TestSharedFilesystem()
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.
bool m_sharedFilesystem
Running on a shared filesystem.
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.