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