Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description:
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILITIES_SESSIONREADER_H
37 #define NEKTAR_LIB_UTILITIES_SESSIONREADER_H
38 
39 #include <map>
40 #include <string>
41 
46 
47 #include <boost/algorithm/string.hpp>
48 #include <boost/enable_shared_from_this.hpp>
49 #include <boost/program_options/variables_map.hpp>
50 
51 class TiXmlElement;
52 class TiXmlDocument;
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<
66  std::pair<std::string, FilterParams> > FilterMap;
67 
68  struct CmdLineArg
69  {
70  std::string shortName;
71  std::string description;
72  bool isFlag;
73  };
74 
75  typedef std::map<std::string, CmdLineArg> CmdLineArgMap;
76 
77  typedef std::map<std::string, int> EnumMap;
78  typedef std::map<std::string, EnumMap> EnumMapList;
79 
80  typedef std::map<std::string, std::string> GloSysInfoMap;
81  typedef std::map<std::string, GloSysInfoMap> GloSysSolnInfoList;
82 
83  typedef std::map<std::string, std::string> GloSysInfoMap;
84  typedef std::map<std::string, GloSysInfoMap> GloSysSolnInfoList;
85 
87  {
92  };
93  const char* const FunctionTypeMap[] =
94  {
95  "No Function type",
96  "Expression",
97  "File"
98  };
99 
100  class Equation;
101  typedef boost::shared_ptr<Equation> EquationSharedPtr;
102 
103  typedef std::map<int, std::vector<unsigned int> > CompositeOrdering;
104  typedef std::map<int, std::vector<unsigned int> > BndRegionOrdering;
105 
107  {
109  std::string m_filename;
110  EquationSharedPtr m_expression;
111  std::string m_fileVariable;
112  };
113 
114  typedef std::map<std::pair<std::string,int>, FunctionVariableDefinition>
116  typedef std::map<std::string, FunctionVariableMap >
118 
119  class SessionReader;
120  typedef boost::shared_ptr<SessionReader> SessionReaderSharedPtr;
121 
122  /// Reads and parses information from a Nektar++ XML session file.
124  public boost::enable_shared_from_this<SessionReader>
125  {
126  public:
127  /// Support creation through MemoryManager.
129 
130  /**
131  * @brief Creates an instance of the SessionReader class.
132  *
133  * This function should be used by an application to instantiate the
134  * session reader. It should be called at the very beginning of the
135  * application before any other processing of command-line
136  * arguments. After instantiating the class and setting up any
137  * parallel communication, it also calls the main initialisation
138  * of the object.
139  */
140  LIB_UTILITIES_EXPORT static SessionReaderSharedPtr CreateInstance(
141  int argc, char *argv[])
142  {
143  SessionReaderSharedPtr p = MemoryManager<
144  LibUtilities::SessionReader>::AllocateSharedPtr(argc, argv);
145  p->InitSession();
146  return p;
147  }
148 
149  /**
150  * @brief Creates an instance of the SessionReader class initialised
151  * using a separate list of XML documents.
152  *
153  * This function should be used by an application to instantiate the
154  * session reader. It may be called after processing of command-line
155  * arguments. After instantiating the class and setting up any
156  * parallel communication, it also calls the main initialisation
157  * of the object.
158  */
159  LIB_UTILITIES_EXPORT static SessionReaderSharedPtr CreateInstance(
160  int argc,
161  char *argv[],
162  std::vector<std::string> &pFilenames,
163  const CommSharedPtr &pComm = CommSharedPtr())
164  {
165  SessionReaderSharedPtr p = MemoryManager<
167  ::AllocateSharedPtr(argc, argv, pFilenames, pComm);
168  p->InitSession();
169  return p;
170  }
171 
173  int argc,
174  char *argv[],
175  const std::vector<std::string> &pFilenames,
176  const CommSharedPtr &pComm);
177 
178  /// Destructor
180 
181  /// Provides direct access to the TiXmlDocument object.
182  LIB_UTILITIES_EXPORT TiXmlDocument &GetDocument();
183  /// Provides direct access to the TiXmlElement specified.
184  LIB_UTILITIES_EXPORT TiXmlElement *GetElement(
185  const std::string& pPath);
186  /// Tests if a specified element is defined in the XML document.
188  const std::string& pPath) const;
189  /// Returns the filename of the loaded XML document.
190  LIB_UTILITIES_EXPORT const std::vector<std::string>
191  &GetFilenames() const;
192  /// Returns the session name of the loaded XML document.
193  LIB_UTILITIES_EXPORT const std::string &GetSessionName() const;
194  /// Returns the session name with process rank
195  LIB_UTILITIES_EXPORT const std::string GetSessionNameRank() const;
196  /// Returns the communication object.
198  /// Returns the communication object.
200  /// Finalises the session.
202 
203  /* ------ PARAMETERS --------*/
204  /// Checks if a parameter is specified in the XML document.
206  const std::string &name) const;
207  /// Returns the value of the specified parameter.
209  const std::string &pName) const;
210  /// Load an integer parameter
212  const std::string &name,
213  int &var) const;
214  /// Check for and load an integer parameter.
216  const std::string &name,
217  int &var,
218  const int &def) const;
219  /// Load a double precision parameter
221  const std::string &name,
222  NekDouble &var) const;
223  /// Check for and load a double-precision parameter.
225  const std::string &name,
226  NekDouble &var,
227  const NekDouble &def) const;
228  /// Set an integer parameter
230  const std::string &name,
231  int &var);
232  /// Set a double precision parameter
234  const std::string &name,
235  NekDouble &var);
236 
237 
238  /* ------ SOLVER INFO ------ */
239  /// Checks if a solver info property is specified.
241  const std::string &name) const;
242  /// Returns the value of the specified solver info property.
243  LIB_UTILITIES_EXPORT const std::string& GetSolverInfo(
244  const std::string &pProperty) const;
245  /// Sets the value of the specified solver info property.
247  const std::string &pProperty, const std::string &pValue);
248  /// Returns the value of the specified solver info property as enum
249  template<typename T>
250  inline const T GetSolverInfoAsEnum(const std::string &pName) const;
251  /// Returns the value of the specified property and value as enum
252  template<typename T>
253  inline const T GetValueAsEnum(const std::string &pName,
254  const std::string &vValue) const;
255  /// Check for and load a solver info property.
257  const std::string &name,
258  std::string &var,
259  const std::string &def = "") const;
260  /// Check if the value of a solver info property matches.
262  const std::string &name,
263  const std::string &trueval,
264  bool &var,
265  const bool &def = false) const;
266  /// Check if the value of a solver info property matches.
268  const std::string &name,
269  const std::string &trueval) const;
270  /// Check if the value of a solver info property matches.
271  template<typename T>
272  inline bool MatchSolverInfoAsEnum(
273  const std::string &name,
274  const T &trueval) const;
275  /// Registers an enumeration value.
276  LIB_UTILITIES_EXPORT inline static std::string RegisterEnumValue(
277  std::string pEnum,
278  std::string pString,
279  int pEnumValue);
280  /// Registers the default string value of a solver info property.
281  LIB_UTILITIES_EXPORT inline static std::string
283  const std::string &pName,
284  const std::string &pValue);
285 
286  /* ----GlobalSysSolnInfo ----- */
287 
289  const std::string &variable,
290  const std::string &property) const;
291 
292  LIB_UTILITIES_EXPORT const std::string& GetGlobalSysSolnInfo(
293  const std::string &variable,
294  const std::string &property) const;
295 
296 
297  /* ------ GEOMETRIC INFO ------ */
298  /// Checks if a geometric info property is defined.
300  const std::string &name) const;
301  /// Checks for and load a geometric info string property.
303  const std::string &name,
304  std::string &var,
305  const std::string &def = "") const;
306  /// Checks for and loads a geometric info boolean property.
308  const std::string &name,
309  bool &var,
310  const bool &def = false) const;
311  /// Checks for and loads a geometric info double-precision property.
313  const std::string &name,
314  NekDouble &var,
315  const NekDouble &def = 0.0) const;
316  /// Check if the value of a geometric info string property matches.
318  const std::string &name,
319  const std::string &trueval,
320  bool &var,
321  const bool &def = false) const;
322 
323  /* ------ VARIABLES ------ */
324  /// Returns the name of the variable specified by the given index.
325  LIB_UTILITIES_EXPORT const std::string& GetVariable(
326  const unsigned int &idx) const;
328  const unsigned int &idx,
329  std::string newname);
330 
331  /// Returns the names of all variables.
332  LIB_UTILITIES_EXPORT std::vector<std::string> GetVariables() const;
333 
334  /* ------ FUNCTIONS ------*/
335  /// Checks if a specified function is defined in the XML document.
337  const std::string &name) const;
338  /// Checks if a specified function has a given variable defined.
340  const std::string &name,
341  const std::string &variable,
342  const int pDomain = 0) const;
343  /// Returns an EquationSharedPtr to a given function variable.
344  LIB_UTILITIES_EXPORT EquationSharedPtr GetFunction(
345  const std::string &name,
346  const std::string &variable,
347  const int pDomain = 0) const;
348  /// Returns an EquationSharedPtr to a given function variable index.
349  LIB_UTILITIES_EXPORT EquationSharedPtr GetFunction(
350  const std::string &name,
351  const unsigned int &var,
352  const int pDomain = 0) const;
353  /// Returns the type of a given function variable.
355  const std::string &name,
356  const std::string &variable,
357  const int pDomain = 0) const;
358  /// Returns the type of a given function variable index.
360  const std::string &pName,
361  const unsigned int &pVar,
362  const int pDomain = 0) const;
363  /// Returns the filename to be loaded for a given variable.
365  const std::string &name,
366  const std::string &variable,
367  const int pDomain = 0) const;
368  /// Returns the filename to be loaded for a given variable index.
370  const std::string &name,
371  const unsigned int &var,
372  const int pDomain = 0) const;
373  /// Returns the filename variable to be loaded for a given variable
374  /// index.
376  const std::string &name,
377  const std::string &variable,
378  const int pDomain = 0) const;
379 
380  /// Returns the instance of AnalyticExpressionEvaluator specific to
381  /// this session.
384 
385  /* ------ TAGS ------ */
386  /// Checks if a specified tag is defined.
388  const std::string& pName) const;
389  /// Sets a specified tag.
391  const std::string& pName,
392  const std::string& pValue);
393  /// Returns the value of a specified tag.
394  LIB_UTILITIES_EXPORT const std::string &GetTag(
395  const std::string& pName) const;
396 
397  /* ------ FILTERS ------ */
398  LIB_UTILITIES_EXPORT const FilterMap& GetFilters() const;
399 
400  /* ------ CMDLINE ARGUMENTS ------- */
401  /// Checks if a specified cmdline argument has been given.
403  const std::string& pName) const;
404  /// Retrieves a command-line argument value.
405  template <typename T>
407  const std::string& pName) const
408  {
409  return m_cmdLineOptions.find(pName)->second.as<T>();
410  }
411  /// Registers a command-line argument with the session reader.
412  LIB_UTILITIES_EXPORT inline static std::string
414  const std::string &pName,
415  const std::string &pShortName,
416  const std::string &pDescription);
417  /// Registers a command-line flag with the session reader.
418  LIB_UTILITIES_EXPORT inline static std::string
420  const std::string &pName,
421  const std::string &pShortName,
422  const std::string &pDescription);
423 
424  /// Substitutes expressions defined in the XML document.
425  LIB_UTILITIES_EXPORT void SubstituteExpressions(std::string &expr);
426  LIB_UTILITIES_EXPORT CompositeOrdering GetCompositeOrdering() const;
427  LIB_UTILITIES_EXPORT BndRegionOrdering GetBndRegionOrdering() const;
428 
430 
431  private:
432  boost::program_options::variables_map m_cmdLineOptions;
433 
434  /// Communication object.
436  /// Filenames
437  std::vector<std::string> m_filenames;
438  /// Session name of the loaded XML document (filename minus ext).
439  std::string m_sessionName;
440  /// Pointer to the loaded XML document.
441  TiXmlDocument* m_xmlDoc;
442  /// Parameters.
443  ParameterMap m_parameters;
444  /// Solver information properties.
445  SolverInfoMap m_solverInfo;
446  /// Geometric information properties.
447  GeometricInfoMap m_geometricInfo;
448  /// Expressions.
449  ExpressionMap m_expressions;
450  /// Analytic expression evaluator instance.
452  /// Functions.
454  /// Variables.
455  VariableList m_variables;
456  /// Custom tags.
457  TagMap m_tags;
458  /// Filters map.
459  FilterMap m_filters;
460  /// Be verbose
461  bool m_verbose;
462  /// Running on a shared filesystem
464  /// Map of original composite ordering for parallel periodic bcs.
465  CompositeOrdering m_compOrder;
466  /// Map of original boundary region ordering for parallel periodic
467  /// bcs.
468  BndRegionOrdering m_bndRegOrder;
469  /// String to enumeration map for Solver Info parameters.
470  LIB_UTILITIES_EXPORT static EnumMapList& GetSolverInfoEnums();
471  /// Default solver info options.
472  LIB_UTILITIES_EXPORT static SolverInfoMap& GetSolverInfoDefaults();
473  /// GlobalSysSoln Info map.
474  LIB_UTILITIES_EXPORT static GloSysSolnInfoList& GetGloSysSolnList();
475  /// CmdLine argument map.
476  LIB_UTILITIES_EXPORT static CmdLineArgMap& GetCmdLineArgMap();
477 
478  /// Main constructor
480  int argc,
481  char *argv[]);
482 
484 
485  /// Returns a shared pointer to the current object.
486  inline SessionReaderSharedPtr GetSharedThisPtr();
487 
489 
490  /// Parse the program arguments and fill #m_cmdLineOptions
491  std::vector<std::string> ParseCommandLineArguments(
492  int argc, char *argv[]);
493 
494  /// Parse the session name.
495  std::string ParseSessionName(std::vector<std::string> &filenames);
496 
497  /// Loads an xml file into a tinyxml doc and decompresses if needed
499  const std::string &pFilename,
500  TiXmlDocument* pDoc) const;
501  /// Creates an XML document from a list of input files.
502  LIB_UTILITIES_EXPORT TiXmlDocument *MergeDoc(
503  const std::vector<std::string> &pFilenames) const;
504  /// Loads and parses the specified file.
506  /// Loads the given XML document and instantiates an appropriate
507  /// communication object.
509  int &argc,
510  char* argv[]);
511 
512  /// Partitions the mesh when running in parallel.
514  /// Partitions the comm object based on session parameters.
516 
517  /// Reads the PARAMETERS section of the XML document.
518  LIB_UTILITIES_EXPORT void ReadParameters(TiXmlElement *conditions);
519  /// Reads the SOLVERINFO section of the XML document.
520  LIB_UTILITIES_EXPORT void ReadSolverInfo(TiXmlElement *conditions);
521  /// Reads the GLOBALSYSSOLNINFO section of the XML document.
523  TiXmlElement *conditions);
524  /// Reads the EXPRESSIONS section of the XML document.
525  LIB_UTILITIES_EXPORT void ReadExpressions(TiXmlElement *conditions);
526  /// Reads the VARIABLES section of the XML document.
527  LIB_UTILITIES_EXPORT void ReadVariables(TiXmlElement *conditions);
528  /// Reads the FUNCTIONS section of the XML document.
529  LIB_UTILITIES_EXPORT void ReadFunctions(TiXmlElement *conditions);
530  /// Reads the FILTERS section of the XML document.
531  LIB_UTILITIES_EXPORT void ReadFilters(TiXmlElement *filters);
532  /// Enforce parameters from command line arguments.
534  /// Check values of solver info options are valid.
536 
537  /// Parse a string in the form lhs = rhs.
539  const std::string &line,
540  std::string &lhs,
541  std::string &rhs);
542  };
543 
544 
545  /**
546  *
547  */
548  template<typename T>
550  const std::string &name, const T &trueval) const
551  {
552  return (GetSolverInfoAsEnum<T>(name) == trueval);
553  }
554 
555 
556  /**
557  *
558  */
559  template<typename T>
561  const std::string &pName) const
562  {
563  std::string vName = boost::to_upper_copy(pName);
565  "Solver info '" + pName + "' not defined.");
566 
567  std::string vValue = GetSolverInfo(vName);
569  ASSERTL0((x = GetSolverInfoEnums().find(vName)) !=
570  GetSolverInfoEnums().end(),
571  "Enum for SolverInfo property '" + pName + "' not found.");
572 
574  ASSERTL0((y = x->second.find(vValue)) != x->second.end(),
575  "Value of SolverInfo property '" + pName +
576  "' is invalid.");
577 
578  return T(y->second);
579  }
580 
581 
582 
583  /**
584  *
585  */
586  template<typename T>
588  const std::string &pName,
589  const std::string &pValue) const
590  {
591  std::string vName = boost::to_upper_copy(pName);
592 
594  ASSERTL0((x = GetSolverInfoEnums().find(vName)) !=
595  GetSolverInfoEnums().end(),
596  "Enum for property '" + pName + "' not found.");
597 
599  ASSERTL0((y = x->second.find(pValue)) != x->second.end(),
600  "Value of property '" + pValue + "' is invalid.");
601  return T(y->second);
602  }
603 
604 
605 
606  /**
607  * A set of valid values for a given solver info property may be
608  * registered using this function. It must be called statically during
609  * the initialisation of a static variable. For example:
610  *
611  * @code
612  * std::string GlobalLinSys::lookupIds[2] = {
613  * LibUtilities::SessionReader::RegisterEnumValue(
614  * "GlobalSysSoln",
615  * "DirectFull",
616  * MultiRegions::eDirectFullMatrix),
617  * LibUtilities::SessionReader::RegisterEnumValue(
618  * "GlobalSysSoln",
619  * "DirectStaticCond",
620  * MultiRegions::eDirectStaticCond)
621  * }
622  * @endcode
623  *
624  * @param pEnum The name of the property.
625  * @param pString A valid value for the property.
626  * @param pEnumValue An enumeration value corresponding to this
627  * value.
628  *
629  * @return The value for the property provided by #pString.
630  */
632  std::string pEnum, std::string pString, int pEnumValue)
633  {
634  std::string vEnum = boost::to_upper_copy(pEnum);
636  if ((x = GetSolverInfoEnums().find(vEnum)) ==
637  GetSolverInfoEnums().end())
638  {
639  GetSolverInfoEnums()[vEnum] = EnumMap();
640  x = GetSolverInfoEnums().find(vEnum);
641  }
642  x->second[pString] = pEnumValue;
643  return pString;
644  }
645 
646 
647  /**
648  * A default value for a given solver info property may be registered
649  * using this function. The property will take this value until it is
650  * overwritten by a value specified in the XML document, or specified
651  * as a command-line argument. Usage has the form:
652  *
653  * @code
654  * std::string GlobalLinSys::def
655  * = LibUtilities::SessionReader::RegisterDefaultSolverInfo(
656  * "GlobalSysSoln","DirectMultiLevelStaticCond");
657  * @endcode
658  *
659  * @param pName The name of the property.
660  * @param pValue The default value of the property.
661  *
662  * @return The default value of the property provided by #pValue.
663  */
665  const std::string &pName,
666  const std::string &pValue)
667  {
668  std::string vName = boost::to_upper_copy(pName);
669  GetSolverInfoDefaults()[vName] = pValue;
670  return pValue;
671  }
672 
673 
674  /**
675  *
676  */
678  const std::string &pName,
679  const std::string &pShortName,
680  const std::string &pDescription)
681  {
682  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
683  CmdLineArg x;
684  x.shortName = pShortName;
685  x.description = pDescription;
686  x.isFlag = false;
687  GetCmdLineArgMap()[pName] = x;
688  return pName;
689  }
690 
691 
692  /**
693  *
694  */
696  const std::string &pName,
697  const std::string &pShortName,
698  const std::string &pDescription)
699  {
700  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
701  CmdLineArg x;
702  x.shortName = pShortName;
703  x.description = pDescription;
704  x.isFlag = true;
705  GetCmdLineArgMap()[pName] = x;
706  return pName;
707  }
708 
709 
710  /**
711  * This allows a member function to pass a shared pointer to itself
712  * during a call to another function.
713  */
714  inline SessionReaderSharedPtr SessionReader::GetSharedThisPtr()
715  {
716  return shared_from_this();
717  }
718  }
719 }
720 
721 #endif
722 
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
Definition: SessionReader.h:58
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)
Definition: ErrorUtil.hpp:188
void CmdLineOverride()
Enforce parameters from command line arguments.
std::map< std::string, int > EnumMap
Definition: SessionReader.h:77
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.
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
Definition: SessionReader.h:63
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
Definition: MeshPartition.h:54
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
Definition: SessionReader.h:80
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
Definition: MeshPartition.h:53
CommSharedPtr m_comm
Communication object.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
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.
StandardMatrixTag & lhs
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[]
Definition: SessionReader.h:93
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.
Definition: Comm.h:53
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
Definition: SessionReader.h:60
std::map< std::string, std::string > FilterParams
Definition: SessionReader.h:64
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.
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
Definition: SessionReader.h:81
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
Definition: SessionReader.h:62
#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
Definition: SessionReader.h:66
CompositeOrdering GetCompositeOrdering() const
FunctionMap m_functions
Functions.
boost::program_options::variables_map m_cmdLineOptions
double NekDouble
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
Definition: SessionReader.h:61
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
Definition: SessionReader.h:59
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
Definition: SessionReader.h:78
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:315
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
Definition: SessionReader.h:75
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...
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.