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