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