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
50class TiXmlElement;
51class TiXmlDocument;
52class TiXmlHandle;
53
55{
56typedef std::map<std::string, std::string> SolverInfoMap;
57typedef std::map<std::string, NekDouble> ParameterMap;
58typedef std::map<std::string, std::string> GeometricInfoMap;
59typedef std::vector<std::string> VariableList;
60typedef std::map<std::string, std::string> TagMap;
61typedef std::map<std::string, std::string> FilterParams;
62typedef std::vector<std::pair<std::string, FilterParams>> FilterMap;
63
65{
66 std::string shortName;
67 std::string description;
68 bool isFlag;
69};
70
71typedef std::map<std::string, CmdLineArg> CmdLineArgMap;
72
73typedef std::map<std::string, int> EnumMap;
74typedef std::map<std::string, EnumMap> EnumMapList;
75
76typedef std::map<std::string, std::string> GloSysInfoMap;
77typedef std::map<std::string, GloSysInfoMap> GloSysSolnInfoList;
78
79typedef std::map<std::string, std::string> GloSysInfoMap;
80typedef std::map<std::string, GloSysInfoMap> GloSysSolnInfoList;
81
83{
84 std::string method = "";
85 std::string variant = "";
86 unsigned int order = 1;
87 std::vector<NekDouble> freeParams;
88};
89
91{
96};
97const char *const FunctionTypeMap[] = {"No Function type", "Expression",
98 "File"};
99
101{
103 std::string m_filename;
105 std::string m_fileVariable;
106};
107
108typedef std::map<std::pair<std::string, int>, FunctionVariableDefinition>
110typedef std::map<std::string, FunctionVariableMap> FunctionMap;
111
112class SessionReader;
113typedef std::shared_ptr<SessionReader> SessionReaderSharedPtr;
114
115/// Reads and parses information from a Nektar++ XML session file.
117{
118public:
119 /// Support creation through MemoryManager.
120 friend class MemoryManager<SessionReader>;
121
122 /**
123 * @brief Creates an instance of the SessionReader class.
124 *
125 * This function should be used by an application to instantiate the
126 * session reader. It should be called at the very beginning of the
127 * application before any other processing of command-line
128 * arguments. After instantiating the class and setting up any
129 * parallel communication, it also calls the main initialisation
130 * of the object.
131 */
133 int argc, char *argv[])
134 {
137 argv);
138 return p;
139 }
140
141 /**
142 * @brief Creates an instance of the SessionReader class initialised
143 * using a separate list of XML documents.
144 *
145 * This function should be used by an application to instantiate the
146 * session reader. It may be called after processing of command-line
147 * arguments. After instantiating the class and setting up any
148 * parallel communication, it also calls the main initialisation
149 * of the object.
150 */
152 int argc, char *argv[], std::vector<std::string> &pFilenames,
153 const CommSharedPtr &pComm = CommSharedPtr(), const int &timelevel = 0)
154 {
157 argc, argv, pFilenames, pComm, timelevel);
158 return p;
159 }
160
162 int argc, char *argv[], const std::vector<std::string> &pFilenames,
163 const CommSharedPtr &pComm, const int &timelevel);
164
165 /// Destructor
167
169 const std::vector<std::string> &filenames = std::vector<std::string>());
170
171 /// Provides direct access to the TiXmlDocument object.
172 LIB_UTILITIES_EXPORT TiXmlDocument &GetDocument();
173 /// Provides direct access to the TiXmlElement specified.
174 LIB_UTILITIES_EXPORT TiXmlElement *GetElement(const std::string &pPath);
175 /// Tests if a specified element is defined in the XML document.
176 LIB_UTILITIES_EXPORT bool DefinesElement(const std::string &pPath) const;
177 /// Returns the filename of the loaded XML document.
178 LIB_UTILITIES_EXPORT const std::vector<std::string> &GetFilenames() const;
179 /// Returns the session name of the loaded XML document.
180 LIB_UTILITIES_EXPORT const std::string &GetSessionName() const;
181 /// Returns the communication object.
183 /// Returns if file system shared
185 /// Finalises the session.
187
188 /* ------ PARAMETERS --------*/
189 /// Checks if a parameter is specified in the XML document.
190 LIB_UTILITIES_EXPORT bool DefinesParameter(const std::string &name) const;
191 /// Returns the value of the specified parameter.
193 const std::string &pName) const;
195 /// Load an integer parameter
196 LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
197 int &var) const;
198 /// Load an size_t parameter
199 LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
200 size_t &var) const;
201 /// Check for and load an integer parameter.
202 LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name, int &var,
203 const int &def) const;
204 /// Check for and load an size_t parameter.
205 LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
206 size_t &var,
207 const size_t &def) const;
208 /// Load a double precision parameter
209 LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
210 NekDouble &var) const;
211 /// Check for and load a double-precision parameter.
212 LIB_UTILITIES_EXPORT void LoadParameter(const std::string &name,
213 NekDouble &var,
214 const NekDouble &def) const;
215 /// Set an integer parameter
216 LIB_UTILITIES_EXPORT void SetParameter(const std::string &name, int &var);
217 /// Set an size_t parameter
218 LIB_UTILITIES_EXPORT void SetParameter(const std::string &name,
219 size_t &var);
220 /// Set a double precision parameter
221 LIB_UTILITIES_EXPORT void SetParameter(const std::string &name,
222 NekDouble &var);
223
224 /* ------ SOLVER INFO ------ */
225 /// Checks if a solver info property is specified.
226 LIB_UTILITIES_EXPORT bool DefinesSolverInfo(const std::string &name) const;
227 /// Returns the value of the specified solver info property.
228 LIB_UTILITIES_EXPORT const std::string &GetSolverInfo(
229 const std::string &pProperty) const;
230 /// Sets the value of the specified solver info property.
231 LIB_UTILITIES_EXPORT void SetSolverInfo(const std::string &pProperty,
232 const std::string &pValue);
233 /// Returns the value of the specified solver info property as enum
234 template <typename T>
235 inline const T GetSolverInfoAsEnum(const std::string &pName) const;
236 /// Returns the value of the specified property and value as enum
237 template <typename T>
238 inline const T GetValueAsEnum(const std::string &pName,
239 const std::string &vValue) const;
240 /// Check for and load a solver info property.
241 LIB_UTILITIES_EXPORT void LoadSolverInfo(const std::string &name,
242 std::string &var,
243 const std::string &def = "") const;
244 /// Check if the value of a solver info property matches.
245 LIB_UTILITIES_EXPORT void MatchSolverInfo(const std::string &name,
246 const std::string &trueval,
247 bool &var,
248 const bool &def = false) const;
249 /// Check if the value of a solver info property matches.
250 LIB_UTILITIES_EXPORT bool MatchSolverInfo(const std::string &name,
251 const std::string &trueval) const;
252 /// Check if the value of a solver info property matches.
253 template <typename T>
254 inline bool MatchSolverInfoAsEnum(const std::string &name,
255 const T &trueval) const;
256 /// Registers an enumeration value.
257 LIB_UTILITIES_EXPORT inline static std::string RegisterEnumValue(
258 std::string pEnum, std::string pString, int pEnumValue);
259 /// Registers the default string value of a solver info property.
260 LIB_UTILITIES_EXPORT inline static std::string RegisterDefaultSolverInfo(
261 const std::string &pName, const std::string &pValue);
262 /// Returns the backups.
263 LIB_UTILITIES_EXPORT bool GetBackups() const;
264
265 /* ----GlobalSysSolnInfo ----- */
267 const std::string &variable, const std::string &property) const;
268
270 const std::string &variable, const std::string &property) const;
271
272 /* ------ TIME INTEGRATION INFORMATION ----- */
275
276 /* ------ GEOMETRIC INFO ------ */
277 LIB_UTILITIES_EXPORT std::string GetGeometryType() const;
278
279 /* ------ VARIABLES ------ */
280 /// Returns the name of the variable specified by the given index.
281 LIB_UTILITIES_EXPORT const std::string &GetVariable(
282 const unsigned int &idx) const;
283 LIB_UTILITIES_EXPORT void SetVariable(const unsigned int &idx,
284 std::string newname);
285
286 /// Returns the names of all variables.
287 LIB_UTILITIES_EXPORT std::vector<std::string> GetVariables() const;
288
289 /* ------ FUNCTIONS ------*/
290 /// Checks if a specified function is defined in the XML document.
291 LIB_UTILITIES_EXPORT bool DefinesFunction(const std::string &name) const;
292 /// Checks if a specified function has a given variable defined.
293 LIB_UTILITIES_EXPORT bool DefinesFunction(const std::string &name,
294 const std::string &variable,
295 const int pDomain = 0) const;
296 /// Returns an EquationSharedPtr to a given function variable.
298 GetFunction(const std::string &name, const std::string &variable,
299 const int pDomain = 0) const;
300 /// Returns an EquationSharedPtr to a given function variable index.
302 GetFunction(const std::string &name, const unsigned int &var,
303 const int pDomain = 0) const;
304 /// Returns the type of a given function variable.
306 const std::string &name, const std::string &variable,
307 const int pDomain = 0) const;
308 /// Returns the type of a given function variable index.
310 const std::string &pName, const unsigned int &pVar,
311 const int pDomain = 0) const;
312 /// Returns the filename to be loaded for a given variable.
314 const std::string &name, const std::string &variable,
315 const int pDomain = 0) const;
316 /// Returns the filename to be loaded for a given variable index.
318 const std::string &name, const unsigned int &var,
319 const int pDomain = 0) const;
320 /// Returns the filename variable to be loaded for a given variable
321 /// index.
323 const std::string &name, const std::string &variable,
324 const int pDomain = 0) const;
325
326 /// Returns the instance of the Interpreter specific to this
327 /// session.
329
330 /* ------ TAGS ------ */
331 /// Checks if a specified tag is defined.
332 LIB_UTILITIES_EXPORT bool DefinesTag(const std::string &pName) const;
333 /// Sets a specified tag.
334 LIB_UTILITIES_EXPORT void SetTag(const std::string &pName,
335 const std::string &pValue);
336 /// Returns the value of a specified tag.
337 LIB_UTILITIES_EXPORT const std::string &GetTag(
338 const std::string &pName) const;
339
340 /* ------ FILTERS ------ */
342
343 /* ------ CMDLINE ARGUMENTS ------- */
344 /// Checks if a specified cmdline argument has been given.
346 const std::string &pName) const;
347 /// Retrieves a command-line argument value.
348 template <typename T> T GetCmdLineArgument(const std::string &pName) const
349 {
350 return m_cmdLineOptions.find(pName)->second.as<T>();
351 }
352 /// Registers a command-line argument with the session reader.
353 LIB_UTILITIES_EXPORT inline static std::string RegisterCmdLineArgument(
354 const std::string &pName, const std::string &pShortName,
355 const std::string &pDescription);
356 /// Registers a command-line flag with the session reader.
357 LIB_UTILITIES_EXPORT inline static std::string RegisterCmdLineFlag(
358 const std::string &pName, const std::string &pShortName,
359 const std::string &pDescription);
360
361 /// Get bool to update optimisation file
363 {
364 return m_updateOptFile;
365 }
366
367 /// Set bool to update optimisation file
369 {
370 m_updateOptFile = flag;
371 }
372
373 /// Get time level (Parallel-in-Time)
375 {
376 return m_timeLevel;
377 }
378
379 /// Get XML elment time level (Parallel-in-Time)
381 TiXmlElement *&element, const size_t timeLevel,
382 const bool enableCheck = true);
383
384private:
385 boost::program_options::variables_map m_cmdLineOptions;
386
387 /// Communication object.
389 /// Filenames
390 std::vector<std::string> m_filenames;
391 /// Session name of the loaded XML document (filename minus ext).
392 std::string m_sessionName;
393 /// Pointer to the loaded XML document.
394 TiXmlDocument *m_xmlDoc;
395 /// Parameters.
397 /// Solver information properties.
399 /// Geometric information properties.
401 /// Interpreter instance.
403 /// Functions.
405 /// Variables.
407 /// Custom tags.
409 /// Filters map.
411 /// Time integration scheme information.
413 /// Time level.
414 size_t m_timeLevel = 0;
415 /// Be verbose
417 /// Running on a shared filesystem
419 /// Backups
420 bool m_backups = true;
421 /// Update optimisation file
423
424 /// String to enumeration map for Solver Info parameters.
426 /// Default solver info options.
428 /// GlobalSysSoln Info map.
430 /// CmdLine argument map.
432
433 /// Main constructor
434 LIB_UTILITIES_EXPORT SessionReader(int argc, char *argv[]);
435
437
438 /// Parse the program arguments and fill #m_cmdLineOptions
439 std::vector<std::string> ParseCommandLineArguments(int argc, char *argv[]);
440
441 /// Parse the session name.
442 std::string ParseSessionName(std::vector<std::string> &filenames);
443
444 /// Loads an xml file into a tinyxml doc and decompresses if needed
445 LIB_UTILITIES_EXPORT void LoadDoc(const std::string &pFilename,
446 TiXmlDocument *pDoc) const;
447 /// Creates an XML document from a list of input files.
448 LIB_UTILITIES_EXPORT TiXmlDocument *MergeDoc(
449 const std::vector<std::string> &pFilenames) const;
450 /// Loads and parses the specified file.
452
453 /// Loads the given XML document and instantiates an appropriate
454 /// communication object.
455 LIB_UTILITIES_EXPORT void CreateComm(int &argc, char *argv[]);
456 /// Partitions the comm object based on session parameters.
458
459 /// Reads the PARAMETERS section of the XML document.
460 LIB_UTILITIES_EXPORT void ReadParameters(TiXmlElement *conditions);
461 /// Reads the SOLVERINFO section of the XML document.
462 LIB_UTILITIES_EXPORT void ReadSolverInfo(TiXmlElement *conditions);
463 /// Reads the GLOBALSYSSOLNINFO section of the XML document.
464 LIB_UTILITIES_EXPORT void ReadGlobalSysSolnInfo(TiXmlElement *conditions);
465 /// Reads the TIMEINTEGRATIONSCHEME section of the XML document.
466 LIB_UTILITIES_EXPORT void ReadTimeIntScheme(TiXmlElement *conditions);
467 /// Reads the VARIABLES section of the XML document.
468 LIB_UTILITIES_EXPORT void ReadVariables(TiXmlElement *conditions);
469 /// Reads the FUNCTIONS section of the XML document.
470 LIB_UTILITIES_EXPORT void ReadFunctions(TiXmlElement *conditions);
471 /// Reads the FILTERS section of the XML document.
472 LIB_UTILITIES_EXPORT void ReadFilters(TiXmlElement *filters);
473 /// Enforce parameters from command line arguments.
475 /// Check values of solver info options are valid.
477
478 /// Parse a string in the form lhs = rhs.
479 LIB_UTILITIES_EXPORT void ParseEquals(const std::string &line,
480 std::string &lhs, std::string &rhs);
481};
482
483/**
484 *
485 */
486template <typename T>
487inline bool SessionReader::MatchSolverInfoAsEnum(const std::string &name,
488 const T &trueval) const
489{
490 return (GetSolverInfoAsEnum<T>(name) == trueval);
491}
492
493/**
494 *
495 */
496template <typename T>
498 const std::string &pName) const
499{
500 std::string vName = boost::to_upper_copy(pName);
502 "Solver info '" + pName + "' not defined.");
503
504 std::string vValue = GetSolverInfo(vName);
505 auto x = GetSolverInfoEnums().find(vName);
506 ASSERTL0(x != GetSolverInfoEnums().end(),
507 "Enum for SolverInfo property '" + pName + "' not found.");
508
509 auto y = x->second.find(vValue);
510 ASSERTL0(y != x->second.end(),
511 "Value of SolverInfo property '" + pName + "' is invalid.");
512
513 return T(y->second);
514}
515
516/**
517 *
518 */
519template <typename T>
520inline const T SessionReader::GetValueAsEnum(const std::string &pName,
521 const std::string &pValue) const
522{
523 std::string vName = boost::to_upper_copy(pName);
524
525 auto x = GetSolverInfoEnums().find(vName);
526 ASSERTL0(x != GetSolverInfoEnums().end(),
527 "Enum for property '" + pName + "' not found.");
528
529 auto y = x->second.find(pValue);
530 ASSERTL0(y != x->second.end(),
531 "Value of property '" + pValue + "' is invalid.");
532 return T(y->second);
533}
534
535/**
536 * A set of valid values for a given solver info property may be
537 * registered using this function. It must be called statically during
538 * the initialisation of a static variable. For example:
539 *
540 * @code
541 * std::string GlobalLinSys::lookupIds[2] = {
542 * LibUtilities::SessionReader::RegisterEnumValue(
543 * "GlobalSysSoln",
544 * "DirectFull",
545 * MultiRegions::eDirectFullMatrix),
546 * LibUtilities::SessionReader::RegisterEnumValue(
547 * "GlobalSysSoln",
548 * "DirectStaticCond",
549 * MultiRegions::eDirectStaticCond)
550 * }
551 * @endcode
552 *
553 * @param pEnum The name of the property.
554 * @param pString A valid value for the property.
555 * @param pEnumValue An enumeration value corresponding to this
556 * value.
557 *
558 * @return The value for the property provided by #pString.
559 */
560inline std::string SessionReader::RegisterEnumValue(std::string pEnum,
561 std::string pString,
562 int pEnumValue)
563{
564 std::string vEnum = boost::to_upper_copy(pEnum);
565 auto x = GetSolverInfoEnums().find(vEnum);
566
567 if (x == GetSolverInfoEnums().end())
568 {
569 GetSolverInfoEnums()[vEnum] = EnumMap();
570 x = GetSolverInfoEnums().find(vEnum);
571 }
572
573 x->second[pString] = pEnumValue;
574 return pString;
575}
576
577/**
578 * A default value for a given solver info property may be registered
579 * using this function. The property will take this value until it is
580 * overwritten by a value specified in the XML document, or specified
581 * as a command-line argument. Usage has the form:
582 *
583 * @code
584 * std::string GlobalLinSys::def
585 * = LibUtilities::SessionReader::RegisterDefaultSolverInfo(
586 * "GlobalSysSoln","DirectMultiLevelStaticCond");
587 * @endcode
588 *
589 * @param pName The name of the property.
590 * @param pValue The default value of the property.
591 *
592 * @return The default value of the property provided by #pValue.
593 */
595 const std::string &pName, const std::string &pValue)
596{
597 std::string vName = boost::to_upper_copy(pName);
598 GetSolverInfoDefaults()[vName] = pValue;
599 return pValue;
600}
601
602/**
603 *
604 */
606 const std::string &pName, const std::string &pShortName,
607 const std::string &pDescription)
608{
609 ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
610 CmdLineArg x;
611 x.shortName = pShortName;
612 x.description = pDescription;
613 x.isFlag = false;
614 GetCmdLineArgMap()[pName] = x;
615 return pName;
616}
617
618/**
619 *
620 */
622 const std::string &pName, const std::string &pShortName,
623 const std::string &pDescription)
624{
625 ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
626 CmdLineArg x;
627 x.shortName = pShortName;
628 x.description = pDescription;
629 x.isFlag = true;
630 GetCmdLineArgMap()[pName] = x;
631 return pName;
632}
633
634/**
635 *
636 */
637TiXmlElement *GetChildElementOrThrow(const std::string &filename,
638 std::string childElementName,
639 const TiXmlHandle &docHandle);
640
641} // namespace Nektar::LibUtilities
642
643#endif
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
#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.
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 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.
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.
static void GetXMLElementTimeLevel(TiXmlElement *&element, const size_t timeLevel, const bool enableCheck=true)
Get XML elment time level (Parallel-in-Time)
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.
SessionReader(int argc, char *argv[], const std::vector< std::string > &pFilenames, const CommSharedPtr &pComm, const int &timelevel)
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.
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.
size_t GetTimeLevel(void) const
Get time level (Parallel-in-Time)
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 SetTag(const std::string &pName, const std::string &pValue)
Sets a specified tag.
boost::program_options::variables_map m_cmdLineOptions
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[], std::vector< std::string > &pFilenames, const CommSharedPtr &pComm=CommSharedPtr(), const int &timelevel=0)
Creates an instance of the SessionReader class initialised using a separate list of XML documents.
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.
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:322
std::map< std::string, FunctionVariableMap > FunctionMap
std::map< std::string, std::string > FilterParams
Definition: SessionReader.h:61
std::map< std::string, std::string > SolverInfoMap
Definition: SessionReader.h:56
std::map< std::string, GloSysInfoMap > GloSysSolnInfoList
Definition: SessionReader.h:77
const char *const FunctionTypeMap[]
Definition: SessionReader.h:97
std::map< std::pair< std::string, int >, FunctionVariableDefinition > FunctionVariableMap
std::map< std::string, NekDouble > ParameterMap
Definition: SessionReader.h:57
std::map< std::string, int > EnumMap
Definition: SessionReader.h:73
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:125
std::vector< std::string > VariableList
Definition: SessionReader.h:59
std::map< std::string, std::string > GloSysInfoMap
Definition: SessionReader.h:76
TiXmlElement * GetChildElementOrThrow(const std::string &filename, std::string elementName, const TiXmlHandle &docHandle)
std::map< std::string, EnumMap > EnumMapList
Definition: SessionReader.h:74
std::vector< std::pair< std::string, FilterParams > > FilterMap
Definition: SessionReader.h:62
std::map< std::string, CmdLineArg > CmdLineArgMap
Definition: SessionReader.h:71
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
std::map< std::string, std::string > GeometricInfoMap
Definition: SessionReader.h:58
std::map< std::string, std::string > TagMap
Definition: SessionReader.h:60
double NekDouble
std::vector< NekDouble > freeParams
Definition: SessionReader.h:87