Nektar++
SessionReader.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: SessionReader.h
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description:
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_LIB_UTILITIES_SESSIONREADER_H
36 #define NEKTAR_LIB_UTILITIES_SESSIONREADER_H
37 
38 #include <map>
39 #include <memory>
40 #include <string>
41 
46 
47 #include <boost/algorithm/string/case_conv.hpp>
48 #include <boost/program_options/variables_map.hpp>
49 
50 class TiXmlElement;
51 class TiXmlDocument;
52 class TiXmlHandle;
53 
54 namespace Nektar
55 {
56 namespace LibUtilities
57 {
58 typedef std::map<std::string, std::string> SolverInfoMap;
59 typedef std::map<std::string, NekDouble> ParameterMap;
60 typedef std::map<std::string, std::string> GeometricInfoMap;
61 typedef std::map<std::string, std::string> ExpressionMap;
62 typedef std::vector<std::string> VariableList;
63 typedef std::map<std::string, std::string> TagMap;
64 typedef std::map<std::string, std::string> FilterParams;
65 typedef std::vector<std::pair<std::string, FilterParams>> FilterMap;
66 
67 struct CmdLineArg
68 {
69  std::string shortName;
70  std::string description;
71  bool isFlag;
72 };
73 
74 typedef std::map<std::string, CmdLineArg> CmdLineArgMap;
75 
76 typedef std::map<std::string, int> EnumMap;
77 typedef std::map<std::string, EnumMap> EnumMapList;
78 
79 typedef std::map<std::string, std::string> GloSysInfoMap;
80 typedef std::map<std::string, GloSysInfoMap> GloSysSolnInfoList;
81 
82 typedef std::map<std::string, std::string> GloSysInfoMap;
83 typedef std::map<std::string, GloSysInfoMap> GloSysSolnInfoList;
84 
86 {
87  std::string method = "";
88  std::string variant = "";
89  unsigned int order = 1;
90  std::vector<NekDouble> freeParams;
91 };
92 
94 {
99 };
100 const char *const FunctionTypeMap[] = {"No Function type", "Expression",
101  "File"};
102 
104 {
105  enum FunctionType m_type;
106  std::string m_filename;
108  std::string m_fileVariable;
109 };
110 
111 typedef std::map<std::pair<std::string, int>, FunctionVariableDefinition>
113 typedef std::map<std::string, FunctionVariableMap> FunctionMap;
114 
115 class SessionReader;
116 typedef std::shared_ptr<SessionReader> SessionReaderSharedPtr;
117 
118 /// Reads and parses information from a Nektar++ XML session file.
120 {
121 public:
122  /// Support creation through MemoryManager.
123  friend class MemoryManager<SessionReader>;
124 
125  /**
126  * @brief Creates an instance of the SessionReader class.
127  *
128  * This function should be used by an application to instantiate the
129  * session reader. It should be called at the very beginning of the
130  * application before any other processing of command-line
131  * arguments. After instantiating the class and setting up any
132  * parallel communication, it also calls the main initialisation
133  * of the object.
134  */
136  int argc, char *argv[])
137  {
140  argv);
141  return p;
142  }
143 
144  /**
145  * @brief Creates an instance of the SessionReader class initialised
146  * using a separate list of XML documents.
147  *
148  * This function should be used by an application to instantiate the
149  * session reader. It may be called after processing of command-line
150  * arguments. After instantiating the class and setting up any
151  * parallel communication, it also calls the main initialisation
152  * of the object.
153  */
155  int argc, char *argv[], std::vector<std::string> &pFilenames,
156  const CommSharedPtr &pComm = CommSharedPtr())
157  {
160  argc, argv, pFilenames, pComm);
161  return p;
162  }
163 
165  int argc, char *argv[], const std::vector<std::string> &pFilenames,
166  const CommSharedPtr &pComm);
167 
168  /// Destructor
170 
172  const std::vector<std::string> &filenames = std::vector<std::string>());
173 
174  /// Provides direct access to the TiXmlDocument object.
175  LIB_UTILITIES_EXPORT TiXmlDocument &GetDocument();
176  /// Provides direct access to the TiXmlElement specified.
177  LIB_UTILITIES_EXPORT TiXmlElement *GetElement(const std::string &pPath);
178  /// Tests if a specified element is defined in the XML document.
179  LIB_UTILITIES_EXPORT bool DefinesElement(const std::string &pPath) const;
180  /// Returns the filename of the loaded XML document.
181  LIB_UTILITIES_EXPORT const std::vector<std::string> &GetFilenames() const;
182  /// Returns the session name of the loaded XML document.
183  LIB_UTILITIES_EXPORT const std::string &GetSessionName() const;
184  /// Returns the session name with process rank
185  LIB_UTILITIES_EXPORT const std::string GetSessionNameRank() const;
186  /// Returns the communication object.
188  /// Returns if file system shared
190  /// Finalises the session.
192 
193  /* ------ PARAMETERS --------*/
194  /// Checks if a parameter is specified in the XML document.
195  LIB_UTILITIES_EXPORT bool DefinesParameter(const std::string &name) const;
196  /// Returns the value of the specified parameter.
198  const std::string &pName) const;
199  /// Load an integer parameter
200  LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
201  int &var) const;
202  /// Load an size_t parameter
203  LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
204  size_t &var) const;
205  /// Check for and load an integer parameter.
206  LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name, int &var,
207  const int &def) const;
208  /// Check for and load an size_t parameter.
209  LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
210  size_t &var,
211  const size_t &def) const;
212  /// Load a double precision parameter
213  LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
214  NekDouble &var) const;
215  /// Check for and load a double-precision parameter.
216  LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
217  NekDouble &var,
218  const NekDouble &def) const;
219  /// Set an integer parameter
220  LIB_UTILITIES_EXPORT void SetParameter(const std::string &name, int &var);
221  /// Set an size_t parameter
222  LIB_UTILITIES_EXPORT void SetParameter(const std::string &name,
223  size_t &var);
224  /// Set a double precision parameter
225  LIB_UTILITIES_EXPORT void SetParameter(const std::string &name,
226  NekDouble &var);
227 
228  /* ------ SOLVER INFO ------ */
229  /// Checks if a solver info property is specified.
230  LIB_UTILITIES_EXPORT bool DefinesSolverInfo(const std::string &name) const;
231  /// Returns the value of the specified solver info property.
232  LIB_UTILITIES_EXPORT const std::string &GetSolverInfo(
233  const std::string &pProperty) const;
234  /// Sets the value of the specified solver info property.
235  LIB_UTILITIES_EXPORT void SetSolverInfo(const std::string &pProperty,
236  const std::string &pValue);
237  /// Returns the value of the specified solver info property as enum
238  template <typename T>
239  inline const T GetSolverInfoAsEnum(const std::string &pName) const;
240  /// Returns the value of the specified property and value as enum
241  template <typename T>
242  inline const T GetValueAsEnum(const std::string &pName,
243  const std::string &vValue) const;
244  /// Check for and load a solver info property.
245  LIB_UTILITIES_EXPORT void LoadSolverInfo(const std::string &name,
246  std::string &var,
247  const std::string &def = "") const;
248  /// Check if the value of a solver info property matches.
249  LIB_UTILITIES_EXPORT void MatchSolverInfo(const std::string &name,
250  const std::string &trueval,
251  bool &var,
252  const bool &def = false) const;
253  /// Check if the value of a solver info property matches.
254  LIB_UTILITIES_EXPORT bool MatchSolverInfo(const std::string &name,
255  const std::string &trueval) const;
256  /// Check if the value of a solver info property matches.
257  template <typename T>
258  inline bool MatchSolverInfoAsEnum(const std::string &name,
259  const T &trueval) const;
260  /// Registers an enumeration value.
261  LIB_UTILITIES_EXPORT inline static std::string RegisterEnumValue(
262  std::string pEnum, std::string pString, int pEnumValue);
263  /// Registers the default string value of a solver info property.
264  LIB_UTILITIES_EXPORT inline static std::string RegisterDefaultSolverInfo(
265  const std::string &pName, const std::string &pValue);
266  /// Returns the backups.
267  LIB_UTILITIES_EXPORT bool GetBackups() const;
268 
269  /* ----GlobalSysSolnInfo ----- */
270 
272  const std::string &variable, const std::string &property) const;
273 
274  LIB_UTILITIES_EXPORT const std::string &GetGlobalSysSolnInfo(
275  const std::string &variable, const std::string &property) const;
276 
277  /* ------ TIME INTEGRATION INFORMATION ----- */
280 
281  /* ------ GEOMETRIC INFO ------ */
282  LIB_UTILITIES_EXPORT std::string GetGeometryType() const;
283  /// Checks if a geometric info property is defined.
285  const std::string &name) const;
286  /// Checks for and load a geometric info string property.
288  const std::string &name, std::string &var,
289  const std::string &def = "") const;
290  /// Checks for and loads a geometric info boolean property.
291  LIB_UTILITIES_EXPORT void LoadGeometricInfo(const std::string &name,
292  bool &var,
293  const bool &def = false) const;
294  /// Checks for and loads a geometric info double-precision property.
296  const std::string &name, NekDouble &var,
297  const NekDouble &def = 0.0) const;
298  /// Check if the value of a geometric info string property matches.
299  LIB_UTILITIES_EXPORT void MatchGeometricInfo(const std::string &name,
300  const std::string &trueval,
301  bool &var,
302  const bool &def = false) const;
303 
304  /* ------ VARIABLES ------ */
305  /// Returns the name of the variable specified by the given index.
306  LIB_UTILITIES_EXPORT const std::string &GetVariable(
307  const unsigned int &idx) const;
308  LIB_UTILITIES_EXPORT void SetVariable(const unsigned int &idx,
309  std::string newname);
310 
311  /// Returns the names of all variables.
312  LIB_UTILITIES_EXPORT std::vector<std::string> GetVariables() const;
313 
314  /* ------ FUNCTIONS ------*/
315  /// Checks if a specified function is defined in the XML document.
316  LIB_UTILITIES_EXPORT bool DefinesFunction(const std::string &name) const;
317  /// Checks if a specified function has a given variable defined.
318  LIB_UTILITIES_EXPORT bool DefinesFunction(const std::string &name,
319  const std::string &variable,
320  const int pDomain = 0) const;
321  /// Returns an EquationSharedPtr to a given function variable.
323  GetFunction(const std::string &name, const std::string &variable,
324  const int pDomain = 0) const;
325  /// Returns an EquationSharedPtr to a given function variable index.
327  GetFunction(const std::string &name, const unsigned int &var,
328  const int pDomain = 0) const;
329  /// Returns the type of a given function variable.
331  const std::string &name, const std::string &variable,
332  const int pDomain = 0) const;
333  /// Returns the type of a given function variable index.
335  const std::string &pName, const unsigned int &pVar,
336  const int pDomain = 0) const;
337  /// Returns the filename to be loaded for a given variable.
339  const std::string &name, const std::string &variable,
340  const int pDomain = 0) const;
341  /// Returns the filename to be loaded for a given variable index.
343  const std::string &name, const unsigned int &var,
344  const int pDomain = 0) const;
345  /// Returns the filename variable to be loaded for a given variable
346  /// index.
348  const std::string &name, const std::string &variable,
349  const int pDomain = 0) const;
350 
351  /// Returns the instance of the Interpreter specific to this
352  /// session.
354 
355  /* ------ TAGS ------ */
356  /// Checks if a specified tag is defined.
357  LIB_UTILITIES_EXPORT bool DefinesTag(const std::string &pName) const;
358  /// Sets a specified tag.
359  LIB_UTILITIES_EXPORT void SetTag(const std::string &pName,
360  const std::string &pValue);
361  /// Returns the value of a specified tag.
362  LIB_UTILITIES_EXPORT const std::string &GetTag(
363  const std::string &pName) const;
364 
365  /* ------ FILTERS ------ */
367 
368  /* ------ CMDLINE ARGUMENTS ------- */
369  /// Checks if a specified cmdline argument has been given.
371  const std::string &pName) const;
372  /// Retrieves a command-line argument value.
373  template <typename T> T GetCmdLineArgument(const std::string &pName) const
374  {
375  return m_cmdLineOptions.find(pName)->second.as<T>();
376  }
377  /// Registers a command-line argument with the session reader.
378  LIB_UTILITIES_EXPORT inline static std::string RegisterCmdLineArgument(
379  const std::string &pName, const std::string &pShortName,
380  const std::string &pDescription);
381  /// Registers a command-line flag with the session reader.
382  LIB_UTILITIES_EXPORT inline static std::string RegisterCmdLineFlag(
383  const std::string &pName, const std::string &pShortName,
384  const std::string &pDescription);
385 
386  /// Substitutes expressions defined in the XML document.
387  LIB_UTILITIES_EXPORT void SubstituteExpressions(std::string &expr);
388 
389  /// Get bool to update optimisation file
391  {
392  return m_updateOptFile;
393  }
394 
395  /// Set bool to update optimisation file
397  {
398  m_updateOptFile = flag;
399  }
400 
401 private:
402  boost::program_options::variables_map m_cmdLineOptions;
403 
404  /// Communication object.
406  /// Filenames
407  std::vector<std::string> m_filenames;
408  /// Session name of the loaded XML document (filename minus ext).
409  std::string m_sessionName;
410  /// Pointer to the loaded XML document.
411  TiXmlDocument *m_xmlDoc;
412  /// Parameters.
414  /// Solver information properties.
416  /// Geometric information properties.
418  /// Expressions.
420  /// Interpreter instance.
422  /// Functions.
424  /// Variables.
426  /// Custom tags.
428  /// Filters map.
430  /// Time integration scheme information.
432  /// Be verbose
433  bool m_verbose;
434  /// Running on a shared filesystem
436  /// Backups
437  bool m_backups = true;
438  /// Update optimisation file
440  /// String to enumeration map for Solver Info parameters.
442  /// Default solver info options.
444  /// GlobalSysSoln Info map.
446  /// CmdLine argument map.
448 
449  /// Main constructor
450  LIB_UTILITIES_EXPORT SessionReader(int argc, char *argv[]);
451 
453 
454  /// Parse the program arguments and fill #m_cmdLineOptions
455  std::vector<std::string> ParseCommandLineArguments(int argc, char *argv[]);
456 
457  /// Parse the session name.
458  std::string ParseSessionName(std::vector<std::string> &filenames);
459 
460  /// Loads an xml file into a tinyxml doc and decompresses if needed
461  LIB_UTILITIES_EXPORT void LoadDoc(const std::string &pFilename,
462  TiXmlDocument *pDoc) const;
463  /// Creates an XML document from a list of input files.
464  LIB_UTILITIES_EXPORT TiXmlDocument *MergeDoc(
465  const std::vector<std::string> &pFilenames) const;
466  /// Loads and parses the specified file.
468  /// Loads the given XML document and instantiates an appropriate
469  /// communication object.
470  LIB_UTILITIES_EXPORT void CreateComm(int &argc, char *argv[]);
471 
472  /// Partitions the comm object based on session parameters.
474 
475  /// Reads the PARAMETERS section of the XML document.
476  LIB_UTILITIES_EXPORT void ReadParameters(TiXmlElement *conditions);
477  /// Reads the SOLVERINFO section of the XML document.
478  LIB_UTILITIES_EXPORT void ReadSolverInfo(TiXmlElement *conditions);
479  /// Reads the GLOBALSYSSOLNINFO section of the XML document.
480  LIB_UTILITIES_EXPORT void ReadGlobalSysSolnInfo(TiXmlElement *conditions);
481  /// Reads the TIMEINTEGRATIONSCHEME section of the XML document.
482  LIB_UTILITIES_EXPORT void ReadTimeIntScheme(TiXmlElement *conditions);
483  /// Reads the EXPRESSIONS section of the XML document.
484  LIB_UTILITIES_EXPORT void ReadExpressions(TiXmlElement *conditions);
485  /// Reads the VARIABLES section of the XML document.
486  LIB_UTILITIES_EXPORT void ReadVariables(TiXmlElement *conditions);
487  /// Reads the FUNCTIONS section of the XML document.
488  LIB_UTILITIES_EXPORT void ReadFunctions(TiXmlElement *conditions);
489  /// Reads the FILTERS section of the XML document.
490  LIB_UTILITIES_EXPORT void ReadFilters(TiXmlElement *filters);
491  /// Enforce parameters from command line arguments.
493  /// Check values of solver info options are valid.
495 
496  /// Parse a string in the form lhs = rhs.
497  LIB_UTILITIES_EXPORT void ParseEquals(const std::string &line,
498  std::string &lhs, std::string &rhs);
499 };
500 
501 /**
502  *
503  */
504 template <typename T>
505 inline bool SessionReader::MatchSolverInfoAsEnum(const std::string &name,
506  const T &trueval) const
507 {
508  return (GetSolverInfoAsEnum<T>(name) == trueval);
509 }
510 
511 /**
512  *
513  */
514 template <typename T>
516  const std::string &pName) const
517 {
518  std::string vName = boost::to_upper_copy(pName);
520  "Solver info '" + pName + "' not defined.");
521 
522  std::string vValue = GetSolverInfo(vName);
523  auto x = GetSolverInfoEnums().find(vName);
524  ASSERTL0(x != GetSolverInfoEnums().end(),
525  "Enum for SolverInfo property '" + pName + "' not found.");
526 
527  auto y = x->second.find(vValue);
528  ASSERTL0(y != x->second.end(),
529  "Value of SolverInfo property '" + pName + "' is invalid.");
530 
531  return T(y->second);
532 }
533 
534 /**
535  *
536  */
537 template <typename T>
538 inline const T SessionReader::GetValueAsEnum(const std::string &pName,
539  const std::string &pValue) const
540 {
541  std::string vName = boost::to_upper_copy(pName);
542 
543  auto x = GetSolverInfoEnums().find(vName);
544  ASSERTL0(x != GetSolverInfoEnums().end(),
545  "Enum for property '" + pName + "' not found.");
546 
547  auto y = x->second.find(pValue);
548  ASSERTL0(y != x->second.end(),
549  "Value of property '" + pValue + "' is invalid.");
550  return T(y->second);
551 }
552 
553 /**
554  * A set of valid values for a given solver info property may be
555  * registered using this function. It must be called statically during
556  * the initialisation of a static variable. For example:
557  *
558  * @code
559  * std::string GlobalLinSys::lookupIds[2] = {
560  * LibUtilities::SessionReader::RegisterEnumValue(
561  * "GlobalSysSoln",
562  * "DirectFull",
563  * MultiRegions::eDirectFullMatrix),
564  * LibUtilities::SessionReader::RegisterEnumValue(
565  * "GlobalSysSoln",
566  * "DirectStaticCond",
567  * MultiRegions::eDirectStaticCond)
568  * }
569  * @endcode
570  *
571  * @param pEnum The name of the property.
572  * @param pString A valid value for the property.
573  * @param pEnumValue An enumeration value corresponding to this
574  * value.
575  *
576  * @return The value for the property provided by #pString.
577  */
578 inline std::string SessionReader::RegisterEnumValue(std::string pEnum,
579  std::string pString,
580  int pEnumValue)
581 {
582  std::string vEnum = boost::to_upper_copy(pEnum);
583  auto x = GetSolverInfoEnums().find(vEnum);
584 
585  if (x == GetSolverInfoEnums().end())
586  {
587  GetSolverInfoEnums()[vEnum] = EnumMap();
588  x = GetSolverInfoEnums().find(vEnum);
589  }
590 
591  x->second[pString] = pEnumValue;
592  return pString;
593 }
594 
595 /**
596  * A default value for a given solver info property may be registered
597  * using this function. The property will take this value until it is
598  * overwritten by a value specified in the XML document, or specified
599  * as a command-line argument. Usage has the form:
600  *
601  * @code
602  * std::string GlobalLinSys::def
603  * = LibUtilities::SessionReader::RegisterDefaultSolverInfo(
604  * "GlobalSysSoln","DirectMultiLevelStaticCond");
605  * @endcode
606  *
607  * @param pName The name of the property.
608  * @param pValue The default value of the property.
609  *
610  * @return The default value of the property provided by #pValue.
611  */
613  const std::string &pName, const std::string &pValue)
614 {
615  std::string vName = boost::to_upper_copy(pName);
616  GetSolverInfoDefaults()[vName] = pValue;
617  return pValue;
618 }
619 
620 /**
621  *
622  */
624  const std::string &pName, const std::string &pShortName,
625  const std::string &pDescription)
626 {
627  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
628  CmdLineArg x;
629  x.shortName = pShortName;
630  x.description = pDescription;
631  x.isFlag = false;
632  GetCmdLineArgMap()[pName] = x;
633  return pName;
634 }
635 
636 /**
637  *
638  */
640  const std::string &pName, const std::string &pShortName,
641  const std::string &pDescription)
642 {
643  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
644  CmdLineArg x;
645  x.shortName = pShortName;
646  x.description = pDescription;
647  x.isFlag = true;
648  GetCmdLineArgMap()[pName] = x;
649  return pName;
650 }
651 
652 TiXmlElement *GetChildElementOrThrow(const std::string &filename,
653  std::string childElementName,
654  const TiXmlHandle &docHandle);
655 
656 } // namespace LibUtilities
657 } // namespace Nektar
658 
659 #endif
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#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.
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 InitSession(const std::vector< std::string > &filenames=std::vector< std::string >())
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.
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 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.
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.
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.
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
Definition: Interpreter.h:324
std::map< std::string, FunctionVariableMap > FunctionMap
std::map< std::string, std::string > FilterParams
Definition: SessionReader.h:64
std::map< std::string, std::string > SolverInfoMap
Definition: SessionReader.h:58
std::map< std::string, GloSysInfoMap > GloSysSolnInfoList
Definition: SessionReader.h:80
const char *const FunctionTypeMap[]
std::map< std::pair< std::string, int >, FunctionVariableDefinition > FunctionVariableMap
std::map< std::string, NekDouble > ParameterMap
Definition: SessionReader.h:59
std::map< std::string, int > EnumMap
Definition: SessionReader.h:76
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:129
std::vector< std::string > VariableList
Definition: SessionReader.h:62
std::map< std::string, std::string > GloSysInfoMap
Definition: SessionReader.h:79
TiXmlElement * GetChildElementOrThrow(const std::string &filename, std::string elementName, const TiXmlHandle &docHandle)
std::map< std::string, EnumMap > EnumMapList
Definition: SessionReader.h:77
std::vector< std::pair< std::string, FilterParams > > FilterMap
Definition: SessionReader.h:65
std::map< std::string, std::string > ExpressionMap
Definition: SessionReader.h:61
std::map< std::string, CmdLineArg > CmdLineArgMap
Definition: SessionReader.h:74
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
std::map< std::string, std::string > GeometricInfoMap
Definition: SessionReader.h:60
std::map< std::string, std::string > TagMap
Definition: SessionReader.h:63
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
std::vector< NekDouble > freeParams
Definition: SessionReader.h:90