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  /// Check for and load an integer parameter.
203  LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name, int &var,
204  const int &def) const;
205  /// Load a double precision parameter
206  LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
207  NekDouble &var) const;
208  /// Check for and load a double-precision parameter.
209  LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
210  NekDouble &var,
211  const NekDouble &def) const;
212  /// Set an integer parameter
213  LIB_UTILITIES_EXPORT void SetParameter(const std::string &name, int &var);
214  /// Set a double precision parameter
215  LIB_UTILITIES_EXPORT void SetParameter(const std::string &name,
216  NekDouble &var);
217 
218  /* ------ SOLVER INFO ------ */
219  /// Checks if a solver info property is specified.
220  LIB_UTILITIES_EXPORT bool DefinesSolverInfo(const std::string &name) const;
221  /// Returns the value of the specified solver info property.
222  LIB_UTILITIES_EXPORT const std::string &GetSolverInfo(
223  const std::string &pProperty) const;
224  /// Sets the value of the specified solver info property.
225  LIB_UTILITIES_EXPORT void SetSolverInfo(const std::string &pProperty,
226  const std::string &pValue);
227  /// Returns the value of the specified solver info property as enum
228  template <typename T>
229  inline const T GetSolverInfoAsEnum(const std::string &pName) const;
230  /// Returns the value of the specified property and value as enum
231  template <typename T>
232  inline const T GetValueAsEnum(const std::string &pName,
233  const std::string &vValue) const;
234  /// Check for and load a solver info property.
235  LIB_UTILITIES_EXPORT void LoadSolverInfo(const std::string &name,
236  std::string &var,
237  const std::string &def = "") const;
238  /// Check if the value of a solver info property matches.
239  LIB_UTILITIES_EXPORT void MatchSolverInfo(const std::string &name,
240  const std::string &trueval,
241  bool &var,
242  const bool &def = false) const;
243  /// Check if the value of a solver info property matches.
244  LIB_UTILITIES_EXPORT bool MatchSolverInfo(const std::string &name,
245  const std::string &trueval) const;
246  /// Check if the value of a solver info property matches.
247  template <typename T>
248  inline bool MatchSolverInfoAsEnum(const std::string &name,
249  const T &trueval) const;
250  /// Registers an enumeration value.
251  LIB_UTILITIES_EXPORT inline static std::string RegisterEnumValue(
252  std::string pEnum, std::string pString, int pEnumValue);
253  /// Registers the default string value of a solver info property.
254  LIB_UTILITIES_EXPORT inline static std::string RegisterDefaultSolverInfo(
255  const std::string &pName, const std::string &pValue);
256 
257  /* ----GlobalSysSolnInfo ----- */
258 
260  const std::string &variable, const std::string &property) const;
261 
262  LIB_UTILITIES_EXPORT const std::string &GetGlobalSysSolnInfo(
263  const std::string &variable, const std::string &property) const;
264 
265  /* ------ TIME INTEGRATION INFORMATION ----- */
268 
269  /* ------ GEOMETRIC INFO ------ */
270  LIB_UTILITIES_EXPORT std::string GetGeometryType() const;
271  /// Checks if a geometric info property is defined.
273  const std::string &name) const;
274  /// Checks for and load a geometric info string property.
276  const std::string &name, std::string &var,
277  const std::string &def = "") const;
278  /// Checks for and loads a geometric info boolean property.
279  LIB_UTILITIES_EXPORT void LoadGeometricInfo(const std::string &name,
280  bool &var,
281  const bool &def = false) const;
282  /// Checks for and loads a geometric info double-precision property.
284  const std::string &name, NekDouble &var,
285  const NekDouble &def = 0.0) const;
286  /// Check if the value of a geometric info string property matches.
287  LIB_UTILITIES_EXPORT void MatchGeometricInfo(const std::string &name,
288  const std::string &trueval,
289  bool &var,
290  const bool &def = false) const;
291 
292  /* ------ VARIABLES ------ */
293  /// Returns the name of the variable specified by the given index.
294  LIB_UTILITIES_EXPORT const std::string &GetVariable(
295  const unsigned int &idx) const;
296  LIB_UTILITIES_EXPORT void SetVariable(const unsigned int &idx,
297  std::string newname);
298 
299  /// Returns the names of all variables.
300  LIB_UTILITIES_EXPORT std::vector<std::string> GetVariables() const;
301 
302  /* ------ FUNCTIONS ------*/
303  /// Checks if a specified function is defined in the XML document.
304  LIB_UTILITIES_EXPORT bool DefinesFunction(const std::string &name) const;
305  /// Checks if a specified function has a given variable defined.
306  LIB_UTILITIES_EXPORT bool DefinesFunction(const std::string &name,
307  const std::string &variable,
308  const int pDomain = 0) const;
309  /// Returns an EquationSharedPtr to a given function variable.
311  GetFunction(const std::string &name, const std::string &variable,
312  const int pDomain = 0) const;
313  /// Returns an EquationSharedPtr to a given function variable index.
315  GetFunction(const std::string &name, const unsigned int &var,
316  const int pDomain = 0) const;
317  /// Returns the type of a given function variable.
319  const std::string &name, const std::string &variable,
320  const int pDomain = 0) const;
321  /// Returns the type of a given function variable index.
323  const std::string &pName, const unsigned int &pVar,
324  const int pDomain = 0) const;
325  /// Returns the filename to be loaded for a given variable.
327  const std::string &name, const std::string &variable,
328  const int pDomain = 0) const;
329  /// Returns the filename to be loaded for a given variable index.
331  const std::string &name, const unsigned int &var,
332  const int pDomain = 0) const;
333  /// Returns the filename variable to be loaded for a given variable
334  /// index.
336  const std::string &name, const std::string &variable,
337  const int pDomain = 0) const;
338 
339  /// Returns the instance of the Interpreter specific to this
340  /// session.
342 
343  /* ------ TAGS ------ */
344  /// Checks if a specified tag is defined.
345  LIB_UTILITIES_EXPORT bool DefinesTag(const std::string &pName) const;
346  /// Sets a specified tag.
347  LIB_UTILITIES_EXPORT void SetTag(const std::string &pName,
348  const std::string &pValue);
349  /// Returns the value of a specified tag.
350  LIB_UTILITIES_EXPORT const std::string &GetTag(
351  const std::string &pName) const;
352 
353  /* ------ FILTERS ------ */
355 
356  /* ------ CMDLINE ARGUMENTS ------- */
357  /// Checks if a specified cmdline argument has been given.
359  const std::string &pName) const;
360  /// Retrieves a command-line argument value.
361  template <typename T> T GetCmdLineArgument(const std::string &pName) const
362  {
363  return m_cmdLineOptions.find(pName)->second.as<T>();
364  }
365  /// Registers a command-line argument with the session reader.
366  LIB_UTILITIES_EXPORT inline static std::string RegisterCmdLineArgument(
367  const std::string &pName, const std::string &pShortName,
368  const std::string &pDescription);
369  /// Registers a command-line flag with the session reader.
370  LIB_UTILITIES_EXPORT inline static std::string RegisterCmdLineFlag(
371  const std::string &pName, const std::string &pShortName,
372  const std::string &pDescription);
373 
374  /// Substitutes expressions defined in the XML document.
375  LIB_UTILITIES_EXPORT void SubstituteExpressions(std::string &expr);
376 
378 
379  /// Get bool to update optimisation file
381  {
382  return m_updateOptFile;
383  }
384 
385  /// Set bool to update optimisation file
387  {
388  m_updateOptFile = flag;
389  }
390 
391 private:
392  boost::program_options::variables_map m_cmdLineOptions;
393 
394  /// Communication object.
396  /// Filenames
397  std::vector<std::string> m_filenames;
398  /// Session name of the loaded XML document (filename minus ext).
399  std::string m_sessionName;
400  /// Pointer to the loaded XML document.
401  TiXmlDocument *m_xmlDoc;
402  /// Parameters.
404  /// Solver information properties.
406  /// Geometric information properties.
408  /// Expressions.
410  /// Interpreter instance.
412  /// Functions.
414  /// Variables.
416  /// Custom tags.
418  /// Filters map.
420  /// Time integration scheme information.
422  /// Be verbose
423  bool m_verbose;
424  /// Running on a shared filesystem
426  /// Update optimisation file
428  /// String to enumeration map for Solver Info parameters.
430  /// Default solver info options.
432  /// GlobalSysSoln Info map.
434  /// CmdLine argument map.
436 
437  /// Main constructor
438  LIB_UTILITIES_EXPORT SessionReader(int argc, char *argv[]);
439 
441 
442  /// Parse the program arguments and fill #m_cmdLineOptions
443  std::vector<std::string> ParseCommandLineArguments(int argc, char *argv[]);
444 
445  /// Parse the session name.
446  std::string ParseSessionName(std::vector<std::string> &filenames);
447 
448  /// Loads an xml file into a tinyxml doc and decompresses if needed
449  LIB_UTILITIES_EXPORT void LoadDoc(const std::string &pFilename,
450  TiXmlDocument *pDoc) const;
451  /// Creates an XML document from a list of input files.
452  LIB_UTILITIES_EXPORT TiXmlDocument *MergeDoc(
453  const std::vector<std::string> &pFilenames) const;
454  /// Loads and parses the specified file.
456  /// Loads the given XML document and instantiates an appropriate
457  /// communication object.
458  LIB_UTILITIES_EXPORT void CreateComm(int &argc, char *argv[]);
459 
460  /// Partitions the comm object based on session parameters.
462 
463  /// Reads the PARAMETERS section of the XML document.
464  LIB_UTILITIES_EXPORT void ReadParameters(TiXmlElement *conditions);
465  /// Reads the SOLVERINFO section of the XML document.
466  LIB_UTILITIES_EXPORT void ReadSolverInfo(TiXmlElement *conditions);
467  /// Reads the GLOBALSYSSOLNINFO section of the XML document.
468  LIB_UTILITIES_EXPORT void ReadGlobalSysSolnInfo(TiXmlElement *conditions);
469  /// Reads the TIMEINTEGRATIONSCHEME section of the XML document.
470  LIB_UTILITIES_EXPORT void ReadTimeIntScheme(TiXmlElement *conditions);
471  /// Reads the EXPRESSIONS section of the XML document.
472  LIB_UTILITIES_EXPORT void ReadExpressions(TiXmlElement *conditions);
473  /// Reads the VARIABLES section of the XML document.
474  LIB_UTILITIES_EXPORT void ReadVariables(TiXmlElement *conditions);
475  /// Reads the FUNCTIONS section of the XML document.
476  LIB_UTILITIES_EXPORT void ReadFunctions(TiXmlElement *conditions);
477  /// Reads the FILTERS section of the XML document.
478  LIB_UTILITIES_EXPORT void ReadFilters(TiXmlElement *filters);
479  /// Enforce parameters from command line arguments.
481  /// Check values of solver info options are valid.
483 
484  /// Parse a string in the form lhs = rhs.
485  LIB_UTILITIES_EXPORT void ParseEquals(const std::string &line,
486  std::string &lhs, std::string &rhs);
487 };
488 
489 /**
490  *
491  */
492 template <typename T>
493 inline bool SessionReader::MatchSolverInfoAsEnum(const std::string &name,
494  const T &trueval) const
495 {
496  return (GetSolverInfoAsEnum<T>(name) == trueval);
497 }
498 
499 /**
500  *
501  */
502 template <typename T>
504  const std::string &pName) const
505 {
506  std::string vName = boost::to_upper_copy(pName);
508  "Solver info '" + pName + "' not defined.");
509 
510  std::string vValue = GetSolverInfo(vName);
511  auto x = GetSolverInfoEnums().find(vName);
512  ASSERTL0(x != GetSolverInfoEnums().end(),
513  "Enum for SolverInfo property '" + pName + "' not found.");
514 
515  auto y = x->second.find(vValue);
516  ASSERTL0(y != x->second.end(),
517  "Value of SolverInfo property '" + pName + "' is invalid.");
518 
519  return T(y->second);
520 }
521 
522 /**
523  *
524  */
525 template <typename T>
526 inline const T SessionReader::GetValueAsEnum(const std::string &pName,
527  const std::string &pValue) const
528 {
529  std::string vName = boost::to_upper_copy(pName);
530 
531  auto x = GetSolverInfoEnums().find(vName);
532  ASSERTL0(x != GetSolverInfoEnums().end(),
533  "Enum for property '" + pName + "' not found.");
534 
535  auto y = x->second.find(pValue);
536  ASSERTL0(y != x->second.end(),
537  "Value of property '" + pValue + "' is invalid.");
538  return T(y->second);
539 }
540 
541 /**
542  * A set of valid values for a given solver info property may be
543  * registered using this function. It must be called statically during
544  * the initialisation of a static variable. For example:
545  *
546  * @code
547  * std::string GlobalLinSys::lookupIds[2] = {
548  * LibUtilities::SessionReader::RegisterEnumValue(
549  * "GlobalSysSoln",
550  * "DirectFull",
551  * MultiRegions::eDirectFullMatrix),
552  * LibUtilities::SessionReader::RegisterEnumValue(
553  * "GlobalSysSoln",
554  * "DirectStaticCond",
555  * MultiRegions::eDirectStaticCond)
556  * }
557  * @endcode
558  *
559  * @param pEnum The name of the property.
560  * @param pString A valid value for the property.
561  * @param pEnumValue An enumeration value corresponding to this
562  * value.
563  *
564  * @return The value for the property provided by #pString.
565  */
566 inline std::string SessionReader::RegisterEnumValue(std::string pEnum,
567  std::string pString,
568  int pEnumValue)
569 {
570  std::string vEnum = boost::to_upper_copy(pEnum);
571  auto x = GetSolverInfoEnums().find(vEnum);
572 
573  if (x == GetSolverInfoEnums().end())
574  {
575  GetSolverInfoEnums()[vEnum] = EnumMap();
576  x = GetSolverInfoEnums().find(vEnum);
577  }
578 
579  x->second[pString] = pEnumValue;
580  return pString;
581 }
582 
583 /**
584  * A default value for a given solver info property may be registered
585  * using this function. The property will take this value until it is
586  * overwritten by a value specified in the XML document, or specified
587  * as a command-line argument. Usage has the form:
588  *
589  * @code
590  * std::string GlobalLinSys::def
591  * = LibUtilities::SessionReader::RegisterDefaultSolverInfo(
592  * "GlobalSysSoln","DirectMultiLevelStaticCond");
593  * @endcode
594  *
595  * @param pName The name of the property.
596  * @param pValue The default value of the property.
597  *
598  * @return The default value of the property provided by #pValue.
599  */
601  const std::string &pName, const std::string &pValue)
602 {
603  std::string vName = boost::to_upper_copy(pName);
604  GetSolverInfoDefaults()[vName] = pValue;
605  return pValue;
606 }
607 
608 /**
609  *
610  */
612  const std::string &pName, const std::string &pShortName,
613  const std::string &pDescription)
614 {
615  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
616  CmdLineArg x;
617  x.shortName = pShortName;
618  x.description = pDescription;
619  x.isFlag = false;
620  GetCmdLineArgMap()[pName] = x;
621  return pName;
622 }
623 
624 /**
625  *
626  */
628  const std::string &pName, const std::string &pShortName,
629  const std::string &pDescription)
630 {
631  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
632  CmdLineArg x;
633  x.shortName = pShortName;
634  x.description = pDescription;
635  x.isFlag = true;
636  GetCmdLineArgMap()[pName] = x;
637  return pName;
638 }
639 
640 TiXmlElement *GetChildElementOrThrow(const std::string &filename,
641  std::string childElementName,
642  const TiXmlHandle &docHandle);
643 
644 } // namespace LibUtilities
645 } // namespace Nektar
646 
647 #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.
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:130
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:1
double NekDouble
std::vector< NekDouble > freeParams
Definition: SessionReader.h:90