Nektar++
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
Nektar::LibUtilities::SessionReader Class Reference

Reads and parses information from a Nektar++ XML session file. More...

#include <SessionReader.h>

Public Member Functions

 SessionReader (int argc, char *argv[], const std::vector< std::string > &pFilenames, const CommSharedPtr &pComm)
 
 ~SessionReader ()
 Destructor. More...
 
void InitSession (const std::vector< std::string > &filenames=std::vector< std::string >())
 
TiXmlDocument & GetDocument ()
 Provides direct access to the TiXmlDocument object. More...
 
TiXmlElement * GetElement (const std::string &pPath)
 Provides direct access to the TiXmlElement specified. More...
 
bool DefinesElement (const std::string &pPath) const
 Tests if a specified element is defined in the XML document. More...
 
const std::vector< std::string > & GetFilenames () const
 Returns the filename of the loaded XML document. More...
 
const std::string & GetSessionName () const
 Returns the session name of the loaded XML document. More...
 
const std::string GetSessionNameRank () const
 Returns the session name with process rank. More...
 
CommSharedPtr GetComm ()
 Returns the communication object. More...
 
bool GetSharedFilesystem ()
 Returns if file system shared. More...
 
void Finalise ()
 Finalises the session. More...
 
bool DefinesParameter (const std::string &name) const
 Checks if a parameter is specified in the XML document. More...
 
const NekDoubleGetParameter (const std::string &pName) const
 Returns the value of the specified parameter. More...
 
void LoadParameter (const std::string &name, int &var) const
 Load an integer parameter. More...
 
void LoadParameter (const std::string &name, int &var, const int &def) const
 Check for and load an integer parameter. More...
 
void LoadParameter (const std::string &name, NekDouble &var) const
 Load a double precision parameter. More...
 
void LoadParameter (const std::string &name, NekDouble &var, const NekDouble &def) const
 Check for and load a double-precision parameter. More...
 
void SetParameter (const std::string &name, int &var)
 Set an integer parameter. More...
 
void SetParameter (const std::string &name, NekDouble &var)
 Set a double precision parameter. More...
 
bool DefinesSolverInfo (const std::string &name) const
 Checks if a solver info property is specified. More...
 
const std::string & GetSolverInfo (const std::string &pProperty) const
 Returns the value of the specified solver info property. More...
 
void SetSolverInfo (const std::string &pProperty, const std::string &pValue)
 Sets the value of the specified solver info property. More...
 
template<typename T >
const T GetSolverInfoAsEnum (const std::string &pName) const
 Returns the value of the specified solver info property as enum. More...
 
template<typename T >
const T GetValueAsEnum (const std::string &pName, const std::string &vValue) const
 Returns the value of the specified property and value as enum. More...
 
void LoadSolverInfo (const std::string &name, std::string &var, const std::string &def="") const
 Check for and load a solver info property. More...
 
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. More...
 
bool MatchSolverInfo (const std::string &name, const std::string &trueval) const
 Check if the value of a solver info property matches. More...
 
template<typename T >
bool MatchSolverInfoAsEnum (const std::string &name, const T &trueval) const
 Check if the value of a solver info property matches. More...
 
bool DefinesGlobalSysSolnInfo (const std::string &variable, const std::string &property) const
 
const std::string & GetGlobalSysSolnInfo (const std::string &variable, const std::string &property) const
 
std::string GetGeometryType () const
 
bool DefinesGeometricInfo (const std::string &name) const
 Checks if a geometric info property is defined. More...
 
void LoadGeometricInfo (const std::string &name, std::string &var, const std::string &def="") const
 Checks for and load a geometric info string property. More...
 
void LoadGeometricInfo (const std::string &name, bool &var, const bool &def=false) const
 Checks for and loads a geometric info boolean property. More...
 
void LoadGeometricInfo (const std::string &name, NekDouble &var, const NekDouble &def=0.0) const
 Checks for and loads a geometric info double-precision property. More...
 
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. More...
 
const std::string & GetVariable (const unsigned int &idx) const
 Returns the name of the variable specified by the given index. More...
 
void SetVariable (const unsigned int &idx, std::string newname)
 
std::vector< std::string > GetVariables () const
 Returns the names of all variables. More...
 
bool DefinesFunction (const std::string &name) const
 Checks if a specified function is defined in the XML document. More...
 
bool DefinesFunction (const std::string &name, const std::string &variable, const int pDomain=0) const
 Checks if a specified function has a given variable defined. More...
 
EquationSharedPtr GetFunction (const std::string &name, const std::string &variable, const int pDomain=0) const
 Returns an EquationSharedPtr to a given function variable. More...
 
EquationSharedPtr GetFunction (const std::string &name, const unsigned int &var, const int pDomain=0) const
 Returns an EquationSharedPtr to a given function variable index. More...
 
enum FunctionType GetFunctionType (const std::string &name, const std::string &variable, const int pDomain=0) const
 Returns the type of a given function variable. More...
 
enum FunctionType GetFunctionType (const std::string &pName, const unsigned int &pVar, const int pDomain=0) const
 Returns the type of a given function variable index. More...
 
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. More...
 
std::string GetFunctionFilename (const std::string &name, const unsigned int &var, const int pDomain=0) const
 Returns the filename to be loaded for a given variable index. More...
 
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. More...
 
InterpreterSharedPtr GetInterpreter ()
 Returns the instance of the Interpreter specific to this session. More...
 
bool DefinesTag (const std::string &pName) const
 Checks if a specified tag is defined. More...
 
void SetTag (const std::string &pName, const std::string &pValue)
 Sets a specified tag. More...
 
const std::string & GetTag (const std::string &pName) const
 Returns the value of a specified tag. More...
 
const FilterMapGetFilters () const
 
bool DefinesCmdLineArgument (const std::string &pName) const
 Checks if a specified cmdline argument has been given. More...
 
template<typename T >
GetCmdLineArgument (const std::string &pName) const
 Retrieves a command-line argument value. More...
 
void SubstituteExpressions (std::string &expr)
 Substitutes expressions defined in the XML document. More...
 
void SetUpXmlDoc ()
 

Static Public Member Functions

static SessionReaderSharedPtr CreateInstance (int argc, char *argv[])
 Creates an instance of the SessionReader class. More...
 
static SessionReaderSharedPtr CreateInstance (int argc, char *argv[], std::vector< std::string > &pFilenames, const CommSharedPtr &pComm=CommSharedPtr())
 Creates an instance of the SessionReader class initialised using a separate list of XML documents. More...
 
static std::string RegisterEnumValue (std::string pEnum, std::string pString, int pEnumValue)
 Registers an enumeration value. More...
 
static std::string RegisterDefaultSolverInfo (const std::string &pName, const std::string &pValue)
 Registers the default string value of a solver info property. More...
 
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. More...
 
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. More...
 

Private Member Functions

 SessionReader (int argc, char *argv[])
 Main constructor. More...
 
void TestSharedFilesystem ()
 
std::vector< std::string > ParseCommandLineArguments (int argc, char *argv[])
 Parse the program arguments and fill m_cmdLineOptions. More...
 
std::string ParseSessionName (std::vector< std::string > &filenames)
 Parse the session name. More...
 
void LoadDoc (const std::string &pFilename, TiXmlDocument *pDoc) const
 Loads an xml file into a tinyxml doc and decompresses if needed. More...
 
TiXmlDocument * MergeDoc (const std::vector< std::string > &pFilenames) const
 Creates an XML document from a list of input files. More...
 
void ParseDocument ()
 Loads and parses the specified file. More...
 
void CreateComm (int &argc, char *argv[])
 Loads the given XML document and instantiates an appropriate communication object. More...
 
void PartitionComm ()
 Partitions the comm object based on session parameters. More...
 
void ReadParameters (TiXmlElement *conditions)
 Reads the PARAMETERS section of the XML document. More...
 
void ReadSolverInfo (TiXmlElement *conditions)
 Reads the SOLVERINFO section of the XML document. More...
 
void ReadGlobalSysSolnInfo (TiXmlElement *conditions)
 Reads the GLOBALSYSSOLNINFO section of the XML document. More...
 
void ReadExpressions (TiXmlElement *conditions)
 Reads the EXPRESSIONS section of the XML document. More...
 
void ReadVariables (TiXmlElement *conditions)
 Reads the VARIABLES section of the XML document. More...
 
void ReadFunctions (TiXmlElement *conditions)
 Reads the FUNCTIONS section of the XML document. More...
 
void ReadFilters (TiXmlElement *filters)
 Reads the FILTERS section of the XML document. More...
 
void CmdLineOverride ()
 Enforce parameters from command line arguments. More...
 
void VerifySolverInfo ()
 Check values of solver info options are valid. More...
 
void ParseEquals (const std::string &line, std::string &lhs, std::string &rhs)
 Parse a string in the form lhs = rhs. More...
 

Static Private Member Functions

static EnumMapListGetSolverInfoEnums ()
 String to enumeration map for Solver Info parameters. More...
 
static SolverInfoMapGetSolverInfoDefaults ()
 Default solver info options. More...
 
static GloSysSolnInfoListGetGloSysSolnList ()
 GlobalSysSoln Info map. More...
 
static CmdLineArgMapGetCmdLineArgMap ()
 CmdLine argument map. More...
 

Private Attributes

boost::program_options::variables_map m_cmdLineOptions
 
CommSharedPtr m_comm
 Communication object. More...
 
std::vector< std::string > m_filenames
 Filenames. More...
 
std::string m_sessionName
 Session name of the loaded XML document (filename minus ext). More...
 
TiXmlDocument * m_xmlDoc
 Pointer to the loaded XML document. More...
 
ParameterMap m_parameters
 Parameters. More...
 
SolverInfoMap m_solverInfo
 Solver information properties. More...
 
GeometricInfoMap m_geometricInfo
 Geometric information properties. More...
 
ExpressionMap m_expressions
 Expressions. More...
 
InterpreterSharedPtr m_interpreter
 Interpreter instance. More...
 
FunctionMap m_functions
 Functions. More...
 
VariableList m_variables
 Variables. More...
 
TagMap m_tags
 Custom tags. More...
 
FilterMap m_filters
 Filters map. More...
 
bool m_verbose
 Be verbose. More...
 
bool m_sharedFilesystem
 Running on a shared filesystem. More...
 

Friends

class MemoryManager< SessionReader >
 Support creation through MemoryManager. More...
 

Detailed Description

Reads and parses information from a Nektar++ XML session file.

This class provides an interface to Nektar++-specific content in a supplied XML document. It also initialises a Nektar++ session including setting up communication for parallel execution and where necessary partitioning the supplied mesh for running across multiple processes.

A session should be initialised at the beginning of a user's application by passing the command-line arguments. This not only allows the SessionReader to extract the name of the XML document to load containing Nektar++ session information, but also supplies the MPI arguments necessary for setting up parallel communication. The SessionReader should be initialised using the CreateInstance function:

The instance vSession can now be passed to other key Nektar++ components during their construction.

Note
At the end of the user application, it is important to call the Finalise routine in order to finalise any MPI communication and correctly free resources.

The SessionReader class provides streamlined, validated access to session parameters, solver information and functions defined within a Nektar++ XML document. The available routines and their usage is documented below.

In the case of solver information properties, the classes to which these parameters are pertinent may register with the SessionReader class the set of valid values for a given property. Such values may also be associated with an enumeration value for more transparent use of the property values in code.

Definition at line 116 of file SessionReader.h.

Constructor & Destructor Documentation

◆ SessionReader() [1/2]

Nektar::LibUtilities::SessionReader::SessionReader ( int  argc,
char *  argv[],
const std::vector< std::string > &  pFilenames,
const CommSharedPtr pComm 
)

Definition at line 221 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

226  {
227  ASSERTL0(pFilenames.size() > 0, "No filenames specified.");
228 
229  ParseCommandLineArguments(argc, argv);
230  m_xmlDoc = 0;
231  m_filenames = pFilenames;
232 
234 
235  // Create communicator
236  if (!pComm.get())
237  {
238  CreateComm(argc, argv);
239  }
240  else
241  {
242  m_comm = pComm;
243  }
244 
246 
247  // If running in parallel change the default global sys solution
248  // type.
249  if (m_comm->GetSize() > 1)
250  {
251  GetSolverInfoDefaults()["GLOBALSYSSOLN"] =
252  "IterativeStaticCond";
253  }
254 
256  m_interpreter->SetRandomSeed((m_comm->GetRank() + 1)
257  * (unsigned int)time(NULL));
258 
259  // Split up the communicator
260  PartitionComm();
261  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::vector< std::string > ParseCommandLineArguments(int argc, char *argv[])
Parse the program arguments and fill m_cmdLineOptions.
InterpreterSharedPtr m_interpreter
Interpreter instance.
void PartitionComm()
Partitions the comm object based on session parameters.
CommSharedPtr m_comm
Communication object.
std::vector< std::string > m_filenames
Filenames.
void CreateComm(int &argc, char *argv[])
Loads the given XML document and instantiates an appropriate communication object.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::string ParseSessionName(std::vector< std::string > &filenames)
Parse the session name.
static SolverInfoMap & GetSolverInfoDefaults()
Default solver info options.
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.
std::string m_sessionName
Session name of the loaded XML document (filename minus ext).

◆ ~SessionReader()

Nektar::LibUtilities::SessionReader::~SessionReader ( )

Destructor.

Definition at line 267 of file BasicUtils/SessionReader.cpp.

268  {
269  if (m_xmlDoc)
270  {
271  delete m_xmlDoc;
272  }
273  }
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.

◆ SessionReader() [2/2]

Nektar::LibUtilities::SessionReader::SessionReader ( int  argc,
char *  argv[] 
)
private

Main constructor.

This constructor parses the command-line arguments given to the user application to set up any MPI communication, read supplied XML session files, and partition meshes where necessary.

Parameters
argcNumber of command-line arguments
argvArray of command-line arguments

Definition at line 187 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

188  {
189  m_xmlDoc = 0;
191 
192  ASSERTL0(m_filenames.size() > 0, "No session file(s) given.");
193 
195 
196  // Create communicator
197  CreateComm(argc, argv);
198 
200 
201  // If running in parallel change the default global sys solution
202  // type.
203  if (m_comm->GetSize() > 1)
204  {
205  GetSolverInfoDefaults()["GLOBALSYSSOLN"] =
206  "IterativeStaticCond";
207  }
208 
210  m_interpreter->SetRandomSeed((m_comm->GetRank() + 1)
211  * (unsigned int)time(NULL));
212 
213  // Split up the communicator
214  PartitionComm();
215  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::vector< std::string > ParseCommandLineArguments(int argc, char *argv[])
Parse the program arguments and fill m_cmdLineOptions.
InterpreterSharedPtr m_interpreter
Interpreter instance.
void PartitionComm()
Partitions the comm object based on session parameters.
CommSharedPtr m_comm
Communication object.
std::vector< std::string > m_filenames
Filenames.
void CreateComm(int &argc, char *argv[])
Loads the given XML document and instantiates an appropriate communication object.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::string ParseSessionName(std::vector< std::string > &filenames)
Parse the session name.
static SolverInfoMap & GetSolverInfoDefaults()
Default solver info options.
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.
std::string m_sessionName
Session name of the loaded XML document (filename minus ext).

Member Function Documentation

◆ CmdLineOverride()

void Nektar::LibUtilities::SessionReader::CmdLineOverride ( )
private

Enforce parameters from command line arguments.

Definition at line 2360 of file BasicUtils/SessionReader.cpp.

References Nektar::lhs, NEKERROR, and Nektar::rhs.

2361  {
2362  // Parse solver info overrides
2363  if (m_cmdLineOptions.count("solverinfo"))
2364  {
2365  std::vector<std::string> solverInfoList =
2366  m_cmdLineOptions["solverinfo"].as<
2367  std::vector<std::string> >();
2368 
2369  for (size_t i = 0; i < solverInfoList.size(); ++i)
2370  {
2371  std::string lhs, rhs;
2372 
2373  try
2374  {
2375  ParseEquals(solverInfoList[i], lhs, rhs);
2376  }
2377  catch (...)
2378  {
2380  "Parse error with command line "
2381  "option: "+solverInfoList[i]);
2382  }
2383 
2384  std::string lhsUpper = boost::to_upper_copy(lhs);
2385  m_solverInfo[lhsUpper] = rhs;
2386  }
2387  }
2388 
2389  if (m_cmdLineOptions.count("parameter"))
2390  {
2391  std::vector<std::string> parametersList =
2392  m_cmdLineOptions["parameter"].as<
2393  std::vector<std::string> >();
2394 
2395  for (size_t i = 0; i < parametersList.size(); ++i)
2396  {
2397  std::string lhs, rhs;
2398 
2399  try
2400  {
2401  ParseEquals(parametersList[i], lhs, rhs);
2402  }
2403  catch (...)
2404  {
2406  "Parse error with command line "
2407  "option: "+parametersList[i]);
2408  }
2409 
2410  std::string lhsUpper = boost::to_upper_copy(lhs);
2411 
2412  try
2413  {
2414  m_parameters[lhsUpper] =
2415  boost::lexical_cast<NekDouble>(rhs);
2416  }
2417  catch (...)
2418  {
2420  "Unable to convert string: "+rhs+
2421  "to double value.");
2422  }
2423  }
2424  }
2425  }
ParameterMap m_parameters
Parameters.
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
SolverInfoMap m_solverInfo
Solver information properties.
StandardMatrixTag & lhs
void ParseEquals(const std::string &line, std::string &lhs, std::string &rhs)
Parse a string in the form lhs = rhs.
boost::program_options::variables_map m_cmdLineOptions
double NekDouble
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs

◆ CreateComm()

void Nektar::LibUtilities::SessionReader::CreateComm ( int &  argc,
char *  argv[] 
)
private

Loads the given XML document and instantiates an appropriate communication object.

Definition at line 1585 of file BasicUtils/SessionReader.cpp.

References Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), Nektar::LibUtilities::GetCommFactory(), and Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::ModuleExists().

1588  {
1589  if (argc == 0)
1590  {
1591  m_comm = GetCommFactory().CreateInstance("Serial", 0, 0);
1592  }
1593  else
1594  {
1595  string vCommModule("Serial");
1596  if (GetCommFactory().ModuleExists("ParallelMPI"))
1597  {
1598  vCommModule = "ParallelMPI";
1599  }
1600  if (m_cmdLineOptions.count("cwipi") && GetCommFactory().ModuleExists("CWIPI"))
1601  {
1602  vCommModule = "CWIPI";
1603  }
1604 
1605  m_comm = GetCommFactory().CreateInstance(vCommModule, argc, argv);
1606  }
1607  }
CommSharedPtr m_comm
Communication object.
CommFactory & GetCommFactory()
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
bool ModuleExists(tKey idKey)
Checks if a particular module is available.
Definition: NekFactory.hpp:215
boost::program_options::variables_map m_cmdLineOptions

◆ CreateInstance() [1/2]

static SessionReaderSharedPtr Nektar::LibUtilities::SessionReader::CreateInstance ( int  argc,
char *  argv[] 
)
inlinestatic

Creates an instance of the SessionReader class.

This function should be used by an application to instantiate the session reader. It should be called at the very beginning of the application before any other processing of command-line arguments. After instantiating the class and setting up any parallel communication, it also calls the main initialisation of the object.

Definition at line 132 of file SessionReader.h.

References CellMLToNektar.cellml_metadata::p.

Referenced by main(), Nektar::Utilities::InputMCF::ParseFile(), Nektar::FieldUtils::InputXml::Process(), Nektar::Utilities::InputNekpp::Process(), Nektar::FieldUtils::ProcessDisplacement::Process(), Nektar::Utilities::OutputNekpp::Process(), Nektar::FieldUtils::ProcessInterpField::Process(), Nektar::FieldUtils::ProcessHomogeneousPlane::Process(), Nektar::FieldUtils::ProcessInterpPoints::Process(), SessionReader_CreateInstance(), Nektar::SolverUtils::Driver::v_InitObject(), and Nektar::VortexWaveInteraction::VortexWaveInteraction().

134  {
135  SessionReaderSharedPtr p = MemoryManager<
136  LibUtilities::SessionReader>::AllocateSharedPtr(argc, argv);
137  return p;
138  }
std::shared_ptr< SessionReader > SessionReaderSharedPtr

◆ CreateInstance() [2/2]

static SessionReaderSharedPtr Nektar::LibUtilities::SessionReader::CreateInstance ( int  argc,
char *  argv[],
std::vector< std::string > &  pFilenames,
const CommSharedPtr pComm = CommSharedPtr() 
)
inlinestatic

Creates an instance of the SessionReader class initialised using a separate list of XML documents.

This function should be used by an application to instantiate the session reader. It may be called after processing of command-line arguments. After instantiating the class and setting up any parallel communication, it also calls the main initialisation of the object.

Definition at line 150 of file SessionReader.h.

References Gs::Finalise(), LIB_UTILITIES_EXPORT, CellMLToNektar.pycml::name, and CellMLToNektar.cellml_metadata::p.

155  {
156  SessionReaderSharedPtr p = MemoryManager<
157  LibUtilities::SessionReader>
158  ::AllocateSharedPtr(argc, argv, pFilenames, pComm);
159  return p;
160  }
std::shared_ptr< SessionReader > SessionReaderSharedPtr

◆ DefinesCmdLineArgument()

bool Nektar::LibUtilities::SessionReader::DefinesCmdLineArgument ( const std::string &  pName) const

Checks if a specified cmdline argument has been given.

Definition at line 1419 of file BasicUtils/SessionReader.cpp.

1421  {
1422  return (m_cmdLineOptions.find(pName) != m_cmdLineOptions.end());
1423  }
boost::program_options::variables_map m_cmdLineOptions

◆ DefinesElement()

bool Nektar::LibUtilities::SessionReader::DefinesElement ( const std::string &  pPath) const

Tests if a specified element is defined in the XML document.

Definition at line 619 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

620  {
621  std::string vPath = boost::to_upper_copy(pPath);
622  std::vector<std::string> st;
623  boost::split(st, vPath, boost::is_any_of("\\/ "));
624  ASSERTL0(st.size() > 0, "No path given in XML element request.");
625 
626  TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
627  ASSERTL0(vReturn, std::string("Cannot find element '")
628  + st[0] + std::string("'."));
629  for (int i = 1; i < st.size(); ++i)
630  {
631  vReturn = vReturn->FirstChildElement(st[i].c_str());
632  if (!vReturn) return false;
633  }
634  return true;
635  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.

◆ DefinesFunction() [1/2]

bool Nektar::LibUtilities::SessionReader::DefinesFunction ( const std::string &  name) const

Checks if a specified function is defined in the XML document.

Definition at line 1135 of file BasicUtils/SessionReader.cpp.

1136  {
1137  std::string vName = boost::to_upper_copy(pName);
1138  return m_functions.find(vName) != m_functions.end();
1139  }
FunctionMap m_functions
Functions.

◆ DefinesFunction() [2/2]

bool Nektar::LibUtilities::SessionReader::DefinesFunction ( const std::string &  name,
const std::string &  variable,
const int  pDomain = 0 
) const

Checks if a specified function has a given variable defined.

Definition at line 1145 of file BasicUtils/SessionReader.cpp.

1149  {
1150  std::string vName = boost::to_upper_copy(pName);
1151 
1152  // Check function exists
1153  auto it1 = m_functions.find(vName);
1154  if (it1 != m_functions.end())
1155  {
1156  pair<std::string, int> key(pVariable,pDomain);
1157  pair<std::string, int> defkey("*",pDomain);
1158  bool varExists =
1159  it1->second.find(key) != it1->second.end() ||
1160  it1->second.find(defkey) != it1->second.end();
1161  return varExists;
1162  }
1163  return false;
1164  }
FunctionMap m_functions
Functions.

◆ DefinesGeometricInfo()

bool Nektar::LibUtilities::SessionReader::DefinesGeometricInfo ( const std::string &  name) const

Checks if a geometric info property is defined.

Definition at line 1001 of file BasicUtils/SessionReader.cpp.

1002  {
1003  std::string vName = boost::to_upper_copy(pName);
1004  return m_geometricInfo.find(vName) != m_geometricInfo.end();
1005  }
GeometricInfoMap m_geometricInfo
Geometric information properties.

◆ DefinesGlobalSysSolnInfo()

bool Nektar::LibUtilities::SessionReader::DefinesGlobalSysSolnInfo ( const std::string &  variable,
const std::string &  property 
) const

Definition at line 927 of file BasicUtils/SessionReader.cpp.

929  {
930  auto iter = GetGloSysSolnList().find(pVariable);
931  if(iter == GetGloSysSolnList().end())
932  {
933  return false;
934  }
935 
936  std::string vProperty = boost::to_upper_copy(pProperty);
937 
938  auto iter1 = iter->second.find(vProperty);
939  if(iter1 == iter->second.end())
940  {
941  return false;
942  }
943 
944  return true;
945  }
static GloSysSolnInfoList & GetGloSysSolnList()
GlobalSysSoln Info map.

◆ DefinesParameter()

bool Nektar::LibUtilities::SessionReader::DefinesParameter ( const std::string &  name) const

Checks if a parameter is specified in the XML document.

Definition at line 701 of file BasicUtils/SessionReader.cpp.

Referenced by export_SessionReader().

702  {
703  std::string vName = boost::to_upper_copy(pName);
704  return m_parameters.find(vName) != m_parameters.end();
705  }
ParameterMap m_parameters
Parameters.

◆ DefinesSolverInfo()

bool Nektar::LibUtilities::SessionReader::DefinesSolverInfo ( const std::string &  name) const

Checks if a solver info property is specified.

Definition at line 823 of file BasicUtils/SessionReader.cpp.

824  {
825  std::string vName = boost::to_upper_copy(pName);
826  auto infoIter = m_solverInfo.find(vName);
827  return (infoIter != m_solverInfo.end());
828  }
SolverInfoMap m_solverInfo
Solver information properties.

◆ DefinesTag()

bool Nektar::LibUtilities::SessionReader::DefinesTag ( const std::string &  pName) const

Checks if a specified tag is defined.

Definition at line 1375 of file BasicUtils/SessionReader.cpp.

1376  {
1377  std::string vName = boost::to_upper_copy(pName);
1378  return m_tags.find(vName) != m_tags.end();
1379  }

◆ Finalise()

void Nektar::LibUtilities::SessionReader::Finalise ( )

Finalises the session.

This routine finalises any parallel communication.

Note
This routine should be called at the very end of a users application.

Definition at line 692 of file BasicUtils/SessionReader.cpp.

Referenced by export_SessionReader().

693  {
694  m_comm->Finalise();
695  }
CommSharedPtr m_comm
Communication object.

◆ GetCmdLineArgMap()

CmdLineArgMap & Nektar::LibUtilities::SessionReader::GetCmdLineArgMap ( )
staticprivate

CmdLine argument map.

Lists the possible command-line argument which can be specified for this executable.

This list is populated through the RegisterCmdLineArgument static member function which is called statically from various classes to register command-line arguments they need.

Definition at line 172 of file BasicUtils/SessionReader.cpp.

173  {
174  static CmdLineArgMap cmdLineArguments;
175  return cmdLineArguments;
176  }
std::map< std::string, CmdLineArg > CmdLineArgMap
Definition: SessionReader.h:74

◆ GetCmdLineArgument()

template<typename T >
T Nektar::LibUtilities::SessionReader::GetCmdLineArgument ( const std::string &  pName) const
inline

Retrieves a command-line argument value.

Definition at line 400 of file SessionReader.h.

References LIB_UTILITIES_EXPORT.

402  {
403  return m_cmdLineOptions.find(pName)->second.as<T>();
404  }
boost::program_options::variables_map m_cmdLineOptions

◆ GetComm()

CommSharedPtr Nektar::LibUtilities::SessionReader::GetComm ( )

Returns the communication object.

Definition at line 676 of file BasicUtils/SessionReader.cpp.

Referenced by export_SessionReader().

677  {
678  return m_comm;
679  }
CommSharedPtr m_comm
Communication object.

◆ GetDocument()

TiXmlDocument & Nektar::LibUtilities::SessionReader::GetDocument ( )

Provides direct access to the TiXmlDocument object.

Definition at line 567 of file BasicUtils/SessionReader.cpp.

References ASSERTL1.

568  {
569  ASSERTL1(m_xmlDoc, "XML Document not defined.");
570  return *m_xmlDoc;
571  }
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250

◆ GetElement()

TiXmlElement * Nektar::LibUtilities::SessionReader::GetElement ( const std::string &  pPath)

Provides direct access to the TiXmlElement specified.

The single parameter specifies a path to the requested element in a similar format to the filesystem path. Given the following XML:

<NEKTAR>
<CONDITIONS>
<PARAMETERS>
...
</PARAMETERS>
</CONDITIONS>
</NEKTAR>

the PARAMETERS element would be retrieved by requesting the path:

Nektar/Conditions/Parameters
Note
Paths are case-insensitive.
Parameters
pPathPath to requested element.
Returns
Direct pointer to requested XML Element.

Definition at line 596 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

597  {
598  std::string vPath = boost::to_upper_copy(pPath);
599  std::vector<std::string> st;
600  boost::split(st, vPath, boost::is_any_of("\\/ "));
601  ASSERTL0(st.size() > 0, "No path given in XML element request.");
602 
603  TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
604  ASSERTL0(vReturn, std::string("Cannot find element '")
605  + st[0] + std::string("'."));
606  for (int i = 1; i < st.size(); ++i)
607  {
608  vReturn = vReturn->FirstChildElement(st[i].c_str());
609  ASSERTL0(vReturn, std::string("Cannot find element '")
610  + st[i] + std::string("'."));
611  }
612  return vReturn;
613  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.

◆ GetFilenames()

const std::vector< std::string > & Nektar::LibUtilities::SessionReader::GetFilenames ( ) const

Returns the filename of the loaded XML document.

Definition at line 641 of file BasicUtils/SessionReader.cpp.

642  {
643  return m_filenames;
644  }
std::vector< std::string > m_filenames
Filenames.

◆ GetFilters()

const FilterMap & Nektar::LibUtilities::SessionReader::GetFilters ( ) const

Definition at line 1410 of file BasicUtils/SessionReader.cpp.

1411  {
1412  return m_filters;
1413  }
FilterMap m_filters
Filters map.

◆ GetFunction() [1/2]

EquationSharedPtr Nektar::LibUtilities::SessionReader::GetFunction ( const std::string &  name,
const std::string &  variable,
const int  pDomain = 0 
) const

Returns an EquationSharedPtr to a given function variable.

Definition at line 1170 of file BasicUtils/SessionReader.cpp.

References ASSERTL0, and Nektar::LibUtilities::eFunctionTypeExpression.

1174  {
1175  std::string vName = boost::to_upper_copy(pName);
1176  auto it1 = m_functions.find(vName);
1177 
1178  ASSERTL0(it1 != m_functions.end(),
1179  std::string("No such function '") + pName
1180  + std::string("' has been defined in the session file."));
1181 
1182  // Check for specific and wildcard definitions
1183  pair<std::string,int> key(pVariable,pDomain);
1184  pair<std::string,int> defkey("*",pDomain);
1185 
1186  auto it2 = it1->second.find(key);
1187  auto it3 = it1->second.find(defkey);
1188  bool specific = it2 != it1->second.end();
1189  bool wildcard = it3 != it1->second.end();
1190 
1191  // Check function is defined somewhere
1192  ASSERTL0(specific || wildcard,
1193  "No such variable " + pVariable
1194  + " in domain " + boost::lexical_cast<string>(pDomain)
1195  + " defined for function " + pName
1196  + " in session file.");
1197 
1198  // If not specific, must be wildcard
1199  if (!specific)
1200  {
1201  it2 = it3;
1202  }
1203 
1204  ASSERTL0((it2->second.m_type == eFunctionTypeExpression),
1205  std::string("Function is defined by a file."));
1206  return it2->second.m_expression;
1207  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FunctionMap m_functions
Functions.

◆ GetFunction() [2/2]

EquationSharedPtr Nektar::LibUtilities::SessionReader::GetFunction ( const std::string &  name,
const unsigned int &  var,
const int  pDomain = 0 
) const

Returns an EquationSharedPtr to a given function variable index.

Definition at line 1213 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1217  {
1218  ASSERTL0(pVar < m_variables.size(), "Variable index out of range.");
1219  return GetFunction(pName, m_variables[pVar],pDomain);
1220  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
VariableList m_variables
Variables.
EquationSharedPtr GetFunction(const std::string &name, const std::string &variable, const int pDomain=0) const
Returns an EquationSharedPtr to a given function variable.

◆ GetFunctionFilename() [1/2]

std::string Nektar::LibUtilities::SessionReader::GetFunctionFilename ( const std::string &  name,
const std::string &  variable,
const int  pDomain = 0 
) const

Returns the filename to be loaded for a given variable.

Definition at line 1280 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1284  {
1285  std::string vName = boost::to_upper_copy(pName);
1286  auto it1 = m_functions.find(vName);
1287 
1288  ASSERTL0 (it1 != m_functions.end(),
1289  std::string("Function '") + pName
1290  + std::string("' not found."));
1291 
1292  // Check for specific and wildcard definitions
1293  pair<std::string,int> key(pVariable,pDomain);
1294  pair<std::string,int> defkey("*",pDomain);
1295 
1296  auto it2 = it1->second.find(key);
1297  auto it3 = it1->second.find(defkey);
1298  bool specific = it2 != it1->second.end();
1299  bool wildcard = it3 != it1->second.end();
1300 
1301  // Check function is defined somewhere
1302  ASSERTL0(specific || wildcard,
1303  "No such variable " + pVariable
1304  + " in domain " + boost::lexical_cast<string>(pDomain)
1305  + " defined for function " + pName
1306  + " in session file.");
1307 
1308  // If not specific, must be wildcard
1309  if (!specific)
1310  {
1311  it2 = it3;
1312  }
1313 
1314  return it2->second.m_filename;
1315  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FunctionMap m_functions
Functions.

◆ GetFunctionFilename() [2/2]

std::string Nektar::LibUtilities::SessionReader::GetFunctionFilename ( const std::string &  name,
const unsigned int &  var,
const int  pDomain = 0 
) const

Returns the filename to be loaded for a given variable index.

Definition at line 1321 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1325  {
1326  ASSERTL0(pVar < m_variables.size(), "Variable index out of range.");
1327  return GetFunctionFilename(pName, m_variables[pVar],pDomain);
1328  }
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.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
VariableList m_variables
Variables.

◆ GetFunctionFilenameVariable()

std::string Nektar::LibUtilities::SessionReader::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.

Definition at line 1334 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1338  {
1339  std::string vName = boost::to_upper_copy(pName);
1340  auto it1 = m_functions.find(vName);
1341 
1342  ASSERTL0 (it1 != m_functions.end(),
1343  std::string("Function '") + pName
1344  + std::string("' not found."));
1345 
1346  // Check for specific and wildcard definitions
1347  pair<std::string,int> key(pVariable,pDomain);
1348  pair<std::string,int> defkey("*",pDomain);
1349 
1350  auto it2 = it1->second.find(key);
1351  auto it3 = it1->second.find(defkey);
1352  bool specific = it2 != it1->second.end();
1353  bool wildcard = it3 != it1->second.end();
1354 
1355  // Check function is defined somewhere
1356  ASSERTL0(specific || wildcard,
1357  "No such variable " + pVariable
1358  + " in domain " + boost::lexical_cast<string>(pDomain)
1359  + " defined for function " + pName
1360  + " in session file.");
1361 
1362  // If not specific, must be wildcard
1363  if (!specific)
1364  {
1365  it2 = it3;
1366  }
1367 
1368  return it2->second.m_fileVariable;
1369  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FunctionMap m_functions
Functions.

◆ GetFunctionType() [1/2]

enum FunctionType Nektar::LibUtilities::SessionReader::GetFunctionType ( const std::string &  name,
const std::string &  variable,
const int  pDomain = 0 
) const

Returns the type of a given function variable.

Definition at line 1226 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1230  {
1231  std::string vName = boost::to_upper_copy(pName);
1232  auto it1 = m_functions.find(vName);
1233 
1234  ASSERTL0 (it1 != m_functions.end(),
1235  std::string("Function '") + pName
1236  + std::string("' not found."));
1237 
1238  // Check for specific and wildcard definitions
1239  pair<std::string,int> key(pVariable,pDomain);
1240  pair<std::string,int> defkey("*",pDomain);
1241 
1242  auto it2 = it1->second.find(key);
1243  auto it3 = it1->second.find(defkey);
1244  bool specific = it2 != it1->second.end();
1245  bool wildcard = it3 != it1->second.end();
1246 
1247  // Check function is defined somewhere
1248  ASSERTL0(specific || wildcard,
1249  "No such variable " + pVariable
1250  + " in domain " + boost::lexical_cast<string>(pDomain)
1251  + " defined for function " + pName
1252  + " in session file.");
1253 
1254  // If not specific, must be wildcard
1255  if (!specific)
1256  {
1257  it2 = it3;
1258  }
1259 
1260  return it2->second.m_type;
1261  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FunctionMap m_functions
Functions.

◆ GetFunctionType() [2/2]

enum FunctionType Nektar::LibUtilities::SessionReader::GetFunctionType ( const std::string &  pName,
const unsigned int &  pVar,
const int  pDomain = 0 
) const

Returns the type of a given function variable index.

Definition at line 1267 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1271  {
1272  ASSERTL0(pVar < m_variables.size(), "Variable index out of range.");
1273  return GetFunctionType(pName, m_variables[pVar],pDomain);
1274  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
VariableList m_variables
Variables.
enum FunctionType GetFunctionType(const std::string &name, const std::string &variable, const int pDomain=0) const
Returns the type of a given function variable.

◆ GetGeometryType()

std::string Nektar::LibUtilities::SessionReader::GetGeometryType ( ) const

Definition at line 966 of file BasicUtils/SessionReader.cpp.

967  {
968  TiXmlElement *xmlGeom = m_xmlDoc->FirstChildElement("NEKTAR")
969  ->FirstChildElement("GEOMETRY");
970  TiXmlAttribute *attr = xmlGeom->FirstAttribute();
971  while (attr)
972  {
973  std::string attrName(attr->Name());
974  if (attrName == "HDF5FILE")
975  {
976  // there is a file pointer, therefore is HDF5
977  return "HDF5";
978  }
979  // Get the next attribute.
980  attr = attr->Next();
981  }
982 
983  // Check the VERTEX block. If this is compressed, assume the file is
984  // compressed, otherwise assume uncompressed.
985  TiXmlElement *element = xmlGeom->FirstChildElement("VERTEX");
986  string IsCompressed;
987  element->QueryStringAttribute("COMPRESSED", &IsCompressed);
988 
989  if (IsCompressed.size() > 0)
990  {
991  return "XmlCompressed";
992  }
993 
994  // no file pointer or compressed, just standard xml
995  return "Xml";
996  }
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.

◆ GetGlobalSysSolnInfo()

const std::string & Nektar::LibUtilities::SessionReader::GetGlobalSysSolnInfo ( const std::string &  variable,
const std::string &  property 
) const

Definition at line 951 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

952  {
953  auto iter = GetGloSysSolnList().find(pVariable);
954  ASSERTL0(iter != GetGloSysSolnList().end(),
955  "Failed to find variable in GlobalSysSolnInfoList");
956 
957  std::string vProperty = boost::to_upper_copy(pProperty);
958  auto iter1 = iter->second.find(vProperty);
959 
960  ASSERTL0(iter1 != iter->second.end(),
961  "Failed to find property: " + vProperty + " in GlobalSysSolnInfoList");
962 
963  return iter1->second;
964  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
static GloSysSolnInfoList & GetGloSysSolnList()
GlobalSysSoln Info map.

◆ GetGloSysSolnList()

GloSysSolnInfoList & Nektar::LibUtilities::SessionReader::GetGloSysSolnList ( )
staticprivate

GlobalSysSoln Info map.

List of values for GlobalSysSoln parameters to be used to override details given in SolverInfo

This list is populated by ReadGlobalSysSoln if the GLOBALSYSSOLNINFO section is defined in the input file. This List allows for details to define for the Global Sys solver for each variable.

Definition at line 158 of file BasicUtils/SessionReader.cpp.

159  {
160  static GloSysSolnInfoList gloSysSolnInfoList;
161  return gloSysSolnInfoList;
162  }
std::map< std::string, GloSysInfoMap > GloSysSolnInfoList
Definition: SessionReader.h:80

◆ GetInterpreter()

InterpreterSharedPtr Nektar::LibUtilities::SessionReader::GetInterpreter ( )

Returns the instance of the Interpreter specific to this session.

Definition at line 2451 of file BasicUtils/SessionReader.cpp.

2452  {
2453  return m_interpreter;
2454  }
InterpreterSharedPtr m_interpreter
Interpreter instance.

◆ GetParameter()

const NekDouble & Nektar::LibUtilities::SessionReader::GetParameter ( const std::string &  pName) const

Returns the value of the specified parameter.

If the parameter is not defined, termination occurs. Therefore, the parameters existence should be tested for using DefinesParameter before calling this function.

Parameters
pNameThe name of a floating-point parameter.
Returns
The value of the floating-point parameter.

Definition at line 716 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

Referenced by export_SessionReader().

718  {
719  std::string vName = boost::to_upper_copy(pName);
720  auto paramIter = m_parameters.find(vName);
721 
722  ASSERTL0(paramIter != m_parameters.end(),
723  "Unable to find requested parameter: " + pName);
724 
725  return paramIter->second;
726  }
ParameterMap m_parameters
Parameters.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216

◆ GetSessionName()

const std::string & Nektar::LibUtilities::SessionReader::GetSessionName ( ) const

Returns the session name of the loaded XML document.

Definition at line 650 of file BasicUtils/SessionReader.cpp.

Referenced by export_SessionReader().

651  {
652  return m_sessionName;
653  }
std::string m_sessionName
Session name of the loaded XML document (filename minus ext).

◆ GetSessionNameRank()

const std::string Nektar::LibUtilities::SessionReader::GetSessionNameRank ( ) const

Returns the session name with process rank.

Output is of the form [sessionName]_P[idx] where idx is the rank of the process.

Definition at line 660 of file BasicUtils/SessionReader.cpp.

References Nektar::LibUtilities::PortablePath().

661  {
662  std::string dirname = m_sessionName + "_xml";
663  fs::path pdirname(dirname);
664 
665  std::string vFilename = "P" + boost::lexical_cast<std::string>(m_comm->GetRowComm()->GetRank());
666  fs::path pFilename(vFilename);
667 
668  fs::path fullpath = pdirname / pFilename;
669 
670  return PortablePath(fullpath);
671  }
CommSharedPtr m_comm
Communication object.
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
Definition: FileSystem.cpp:41
std::string m_sessionName
Session name of the loaded XML document (filename minus ext).

◆ GetSharedFilesystem()

bool Nektar::LibUtilities::SessionReader::GetSharedFilesystem ( )

Returns if file system shared.

Definition at line 681 of file BasicUtils/SessionReader.cpp.

682  {
683  return m_sharedFilesystem;
684  }
bool m_sharedFilesystem
Running on a shared filesystem.

◆ GetSolverInfo()

const std::string & Nektar::LibUtilities::SessionReader::GetSolverInfo ( const std::string &  pProperty) const

Returns the value of the specified solver info property.

Definition at line 834 of file BasicUtils/SessionReader.cpp.

References ASSERTL1.

836  {
837  std::string vProperty = boost::to_upper_copy(pProperty);
838  auto iter = m_solverInfo.find(vProperty);
839 
840  ASSERTL1(iter != m_solverInfo.end(),
841  "Unable to find requested property: " + pProperty);
842 
843  return iter->second;
844  }
SolverInfoMap m_solverInfo
Solver information properties.
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250

◆ GetSolverInfoAsEnum()

template<typename T >
const T Nektar::LibUtilities::SessionReader::GetSolverInfoAsEnum ( const std::string &  pName) const
inline

Returns the value of the specified solver info property as enum.

Definition at line 540 of file SessionReader.h.

References ASSERTL0.

542  {
543  std::string vName = boost::to_upper_copy(pName);
545  "Solver info '" + pName + "' not defined.");
546 
547  std::string vValue = GetSolverInfo(vName);
548  auto x = GetSolverInfoEnums().find(vName);
549  ASSERTL0(x != GetSolverInfoEnums().end(),
550  "Enum for SolverInfo property '" + pName + "' not found.");
551 
552  auto y = x->second.find(vValue);
553  ASSERTL0(y != x->second.end(),
554  "Value of SolverInfo property '" + pName +
555  "' is invalid.");
556 
557  return T(y->second);
558  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
bool DefinesSolverInfo(const std::string &name) const
Checks if a solver info property is specified.
const std::string & GetSolverInfo(const std::string &pProperty) const
Returns the value of the specified solver info property.
static EnumMapList & GetSolverInfoEnums()
String to enumeration map for Solver Info parameters.

◆ GetSolverInfoDefaults()

SolverInfoMap & Nektar::LibUtilities::SessionReader::GetSolverInfoDefaults ( )
staticprivate

Default solver info options.

List of default values for solver information parameters to be used in the case of them not being provided.

This list is populated through the RegisterDefaultSolverInfo static member variable which is called statically from various classes to register the default value for a given parameter.

Definition at line 142 of file BasicUtils/SessionReader.cpp.

143  {
144  static SolverInfoMap solverInfoMap;
145  return solverInfoMap;
146  }
std::map< std::string, std::string > SolverInfoMap
Definition: SessionReader.h:57

◆ GetSolverInfoEnums()

EnumMapList & Nektar::LibUtilities::SessionReader::GetSolverInfoEnums ( )
staticprivate

String to enumeration map for Solver Info parameters.

This map of maps stores the list of valid string values for a number of solver information parameters. The top level map connects different parameter names to their list of possible values. The list of possible values is also a map, mapping a valid string to a corresponding enum value.

This list is populated through the RegisterEnumValue static member function which is called statically from various classes to register the valid values for solver info parameters associated with them. The map is therefore fully populated before the SessionReader class is instantiated and a file is read in and parsed.

Definition at line 127 of file BasicUtils/SessionReader.cpp.

128  {
129  static EnumMapList solverInfoEnums;
130  return solverInfoEnums;
131  }
std::map< std::string, EnumMap > EnumMapList
Definition: SessionReader.h:77

◆ GetTag()

const std::string & Nektar::LibUtilities::SessionReader::GetTag ( const std::string &  pName) const

Returns the value of a specified tag.

Definition at line 1397 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1398  {
1399  std::string vName = boost::to_upper_copy(pName);
1400  auto vTagIterator = m_tags.find(vName);
1401  ASSERTL0(vTagIterator != m_tags.end(),
1402  "Requested tag does not exist.");
1403  return vTagIterator->second;
1404  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216

◆ GetValueAsEnum()

template<typename T >
const T Nektar::LibUtilities::SessionReader::GetValueAsEnum ( const std::string &  pName,
const std::string &  vValue 
) const
inline

Returns the value of the specified property and value as enum.

Definition at line 566 of file SessionReader.h.

References ASSERTL0.

569  {
570  std::string vName = boost::to_upper_copy(pName);
571 
572  auto x = GetSolverInfoEnums().find(vName);
573  ASSERTL0(x != GetSolverInfoEnums().end(),
574  "Enum for property '" + pName + "' not found.");
575 
576  auto y = x->second.find(pValue);
577  ASSERTL0(y != x->second.end(),
578  "Value of property '" + pValue + "' is invalid.");
579  return T(y->second);
580  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
static EnumMapList & GetSolverInfoEnums()
String to enumeration map for Solver Info parameters.

◆ GetVariable()

const std::string & Nektar::LibUtilities::SessionReader::GetVariable ( const unsigned int &  idx) const

Returns the name of the variable specified by the given index.

Definition at line 1103 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

Referenced by export_SessionReader().

1105  {
1106  ASSERTL0(idx < m_variables.size(), "Variable index out of range.");
1107  return m_variables[idx];
1108  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
VariableList m_variables
Variables.

◆ GetVariables()

std::vector< std::string > Nektar::LibUtilities::SessionReader::GetVariables ( ) const

Returns the names of all variables.

Definition at line 1126 of file BasicUtils/SessionReader.cpp.

1127  {
1128  return m_variables;
1129  }
VariableList m_variables
Variables.

◆ InitSession()

void Nektar::LibUtilities::SessionReader::InitSession ( const std::vector< std::string > &  filenames = std::vector<std::string>())

Performs the main initialisation of the object. The XML file provided on the command-line is loaded and any mesh partitioning is done. The resulting process-specific XML file (containing the process's geometry partition) is then reloaded and parsed.

Definition at line 282 of file BasicUtils/SessionReader.cpp.

284  {
285  // Re-load filenames for session if required.
286  if (filenames.size() > 0)
287  {
288  m_filenames = filenames;
289  }
290 
291  // Merge document if required.
292  if (m_xmlDoc)
293  {
294  delete m_xmlDoc;
295  }
296 
298 
299  // Parse the XML data in #m_xmlDoc
300  ParseDocument();
301 
302  // Override SOLVERINFO and parameters with any specified on the
303  // command line.
304  CmdLineOverride();
305 
306  // Verify SOLVERINFO values
308 
309  // In verbose mode, print out parameters and solver info sections
310  if (m_verbose && m_comm)
311  {
312  if (m_comm->TreatAsRankZero() && m_parameters.size() > 0)
313  {
314  cout << "Parameters:" << endl;
315  for (auto &x : m_parameters)
316  {
317  cout << "\t" << x.first << " = " << x.second << endl;
318  }
319  cout << endl;
320  }
321 
322  if (m_comm->TreatAsRankZero() && m_solverInfo.size() > 0)
323  {
324  cout << "Solver Info:" << endl;
325  for (auto &x : m_solverInfo)
326  {
327  cout << "\t" << x.first << " = " << x.second << endl;
328  }
329  cout << endl;
330  }
331  }
332  }
ParameterMap m_parameters
Parameters.
void CmdLineOverride()
Enforce parameters from command line arguments.
SolverInfoMap m_solverInfo
Solver information properties.
CommSharedPtr m_comm
Communication object.
TiXmlDocument * MergeDoc(const std::vector< std::string > &pFilenames) const
Creates an XML document from a list of input files.
std::vector< std::string > m_filenames
Filenames.
void VerifySolverInfo()
Check values of solver info options are valid.
void ParseDocument()
Loads and parses the specified file.
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.

◆ LoadDoc()

void Nektar::LibUtilities::SessionReader::LoadDoc ( const std::string &  pFilename,
TiXmlDocument *  pDoc 
) const
private

Loads an xml file into a tinyxml doc and decompresses if needed.

Definition at line 1440 of file BasicUtils/SessionReader.cpp.

References ASSERTL0, CellMLToNektar.pycml::copy(), CellMLToNektar.pycml::format, NEKERROR, and Nektar::LibUtilities::PortablePath().

1443  {
1444  if (pFilename.size() > 3 &&
1445  pFilename.substr(pFilename.size() - 3, 3) == ".gz")
1446  {
1447  ifstream file(pFilename.c_str(),
1448  ios_base::in | ios_base::binary);
1449  ASSERTL0(file.good(), "Unable to open file: " + pFilename);
1450  stringstream ss;
1451  io::filtering_streambuf<io::input> in;
1452  in.push(io::gzip_decompressor());
1453  in.push(file);
1454  try
1455  {
1456  io::copy(in, ss);
1457  ss >> (*pDoc);
1458  }
1459  catch (io::gzip_error&)
1460  {
1462  "Error: File '" + pFilename + "' is corrupt.");
1463  }
1464  }
1465  else if (pFilename.size() > 4 &&
1466  pFilename.substr(pFilename.size() - 4, 4) == "_xml")
1467  {
1468  fs::path pdirname(pFilename);
1469  boost::format pad("P%1$07d.xml");
1470  pad % m_comm->GetRank();
1471  fs::path pRankFilename(pad.str());
1472  fs::path fullpath = pdirname / pRankFilename;
1473 
1474  ifstream file(PortablePath(fullpath).c_str());
1475  ASSERTL0(file.good(), "Unable to open file: " + fullpath.string());
1476  file >> (*pDoc);
1477  }
1478  else
1479  {
1480  ifstream file(pFilename.c_str());
1481  ASSERTL0(file.good(), "Unable to open file: " + pFilename);
1482  file >> (*pDoc);
1483  }
1484  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
CommSharedPtr m_comm
Communication object.
def copy(self)
Definition: pycml.py:2663
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
Definition: FileSystem.cpp:41

◆ LoadGeometricInfo() [1/3]

void Nektar::LibUtilities::SessionReader::LoadGeometricInfo ( const std::string &  name,
std::string &  var,
const std::string &  def = "" 
) const

Checks for and load a geometric info string property.

Definition at line 1011 of file BasicUtils/SessionReader.cpp.

1015  {
1016  std::string vName = boost::to_upper_copy(pName);
1017  auto iter = m_geometricInfo.find(vName);
1018  if(iter != m_geometricInfo.end())
1019  {
1020  pVar = iter->second;
1021  }
1022  else
1023  {
1024  pVar = pDefault;
1025  }
1026  }
GeometricInfoMap m_geometricInfo
Geometric information properties.

◆ LoadGeometricInfo() [2/3]

void Nektar::LibUtilities::SessionReader::LoadGeometricInfo ( const std::string &  name,
bool &  var,
const bool &  def = false 
) const

Checks for and loads a geometric info boolean property.

Definition at line 1032 of file BasicUtils/SessionReader.cpp.

1036  {
1037  std::string vName = boost::to_upper_copy(pName);
1038  auto iter = m_geometricInfo.find(vName);
1039  if(iter != m_geometricInfo.end())
1040  {
1041  if (iter->second == "TRUE")
1042  {
1043  pVar = true;
1044  }
1045  else
1046  {
1047  pVar = false;
1048  }
1049  }
1050  else
1051  {
1052  pVar = pDefault;
1053  }
1054  }
GeometricInfoMap m_geometricInfo
Geometric information properties.

◆ LoadGeometricInfo() [3/3]

void Nektar::LibUtilities::SessionReader::LoadGeometricInfo ( const std::string &  name,
NekDouble var,
const NekDouble def = 0.0 
) const

Checks for and loads a geometric info double-precision property.

Definition at line 1060 of file BasicUtils/SessionReader.cpp.

1064  {
1065  std::string vName = boost::to_upper_copy(pName);
1066  auto iter = m_geometricInfo.find(vName);
1067  if(iter != m_geometricInfo.end())
1068  {
1069  pVar = std::atoi(iter->second.c_str());
1070  }
1071  else
1072  {
1073  pVar = pDefault;
1074  }
1075  }
GeometricInfoMap m_geometricInfo
Geometric information properties.

◆ LoadParameter() [1/4]

void Nektar::LibUtilities::SessionReader::LoadParameter ( const std::string &  name,
int &  var 
) const

Load an integer parameter.

Definition at line 732 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

734  {
735  std::string vName = boost::to_upper_copy(pName);
736  auto paramIter = m_parameters.find(vName);
737  ASSERTL0(paramIter != m_parameters.end(), "Required parameter '" +
738  pName + "' not specified in session.");
739  pVar = (int)round(paramIter->second);
740  }
ParameterMap m_parameters
Parameters.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216

◆ LoadParameter() [2/4]

void Nektar::LibUtilities::SessionReader::LoadParameter ( const std::string &  name,
int &  var,
const int &  def 
) const

Check for and load an integer parameter.

Definition at line 746 of file BasicUtils/SessionReader.cpp.

748  {
749  std::string vName = boost::to_upper_copy(pName);
750  auto paramIter = m_parameters.find(vName);
751  if(paramIter != m_parameters.end())
752  {
753  pVar = (int)round(paramIter->second);
754  }
755  else
756  {
757  pVar = pDefault;
758  }
759  }
ParameterMap m_parameters
Parameters.

◆ LoadParameter() [3/4]

void Nektar::LibUtilities::SessionReader::LoadParameter ( const std::string &  name,
NekDouble var 
) const

Load a double precision parameter.

Definition at line 765 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

767  {
768  std::string vName = boost::to_upper_copy(pName);
769  auto paramIter = m_parameters.find(vName);
770  ASSERTL0(paramIter != m_parameters.end(), "Required parameter '" +
771  pName + "' not specified in session.");
772  pVar = paramIter->second;
773  }
ParameterMap m_parameters
Parameters.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216

◆ LoadParameter() [4/4]

void Nektar::LibUtilities::SessionReader::LoadParameter ( const std::string &  name,
NekDouble var,
const NekDouble def 
) const

Check for and load a double-precision parameter.

Definition at line 779 of file BasicUtils/SessionReader.cpp.

783  {
784  std::string vName = boost::to_upper_copy(pName);
785  auto paramIter = m_parameters.find(vName);
786  if(paramIter != m_parameters.end())
787  {
788  pVar = paramIter->second;
789  }
790  else
791  {
792  pVar = pDefault;
793  }
794  }
ParameterMap m_parameters
Parameters.

◆ LoadSolverInfo()

void Nektar::LibUtilities::SessionReader::LoadSolverInfo ( const std::string &  name,
std::string &  var,
const std::string &  def = "" 
) const

Check for and load a solver info property.

Definition at line 864 of file BasicUtils/SessionReader.cpp.

868  {
869  std::string vName = boost::to_upper_copy(pName);
870  auto infoIter = m_solverInfo.find(vName);
871  if(infoIter != m_solverInfo.end())
872  {
873  pVar = infoIter->second;
874  }
875  else
876  {
877  pVar = pDefault;
878  }
879  }
SolverInfoMap m_solverInfo
Solver information properties.

◆ MatchGeometricInfo()

void Nektar::LibUtilities::SessionReader::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.

Definition at line 1081 of file BasicUtils/SessionReader.cpp.

1086  {
1087  std::string vName = boost::to_upper_copy(pName);
1088  auto iter = m_geometricInfo.find(vName);
1089  if(iter != m_geometricInfo.end())
1090  {
1091  pVar = boost::iequals(iter->second, pTrueVal);
1092  }
1093  else
1094  {
1095  pVar = pDefault;
1096  }
1097  }
GeometricInfoMap m_geometricInfo
Geometric information properties.

◆ MatchSolverInfo() [1/2]

void Nektar::LibUtilities::SessionReader::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.

Definition at line 885 of file BasicUtils/SessionReader.cpp.

890  {
891  std::string vName = boost::to_upper_copy(pName);
892  auto infoIter = m_solverInfo.find(vName);
893  if(infoIter != m_solverInfo.end())
894  {
895  pVar = boost::iequals(infoIter->second, pTrueVal);
896  }
897  else
898  {
899  pVar = pDefault;
900  }
901  }
SolverInfoMap m_solverInfo
Solver information properties.

◆ MatchSolverInfo() [2/2]

bool Nektar::LibUtilities::SessionReader::MatchSolverInfo ( const std::string &  name,
const std::string &  trueval 
) const

Check if the value of a solver info property matches.

Definition at line 907 of file BasicUtils/SessionReader.cpp.

910  {
911  if (DefinesSolverInfo(pName))
912  {
913  std::string vName = boost::to_upper_copy(pName);
914  auto iter = m_solverInfo.find(vName);
915  if(iter != m_solverInfo.end())
916  {
917  return boost::iequals(iter->second, pTrueVal);
918  }
919  }
920  return false;
921  }
SolverInfoMap m_solverInfo
Solver information properties.
bool DefinesSolverInfo(const std::string &name) const
Checks if a solver info property is specified.

◆ MatchSolverInfoAsEnum()

template<typename T >
bool Nektar::LibUtilities::SessionReader::MatchSolverInfoAsEnum ( const std::string &  name,
const T &  trueval 
) const
inline

Check if the value of a solver info property matches.

Definition at line 529 of file SessionReader.h.

531  {
532  return (GetSolverInfoAsEnum<T>(name) == trueval);
533  }

◆ MergeDoc()

TiXmlDocument * Nektar::LibUtilities::SessionReader::MergeDoc ( const std::vector< std::string > &  pFilenames) const
private

Creates an XML document from a list of input files.

Definition at line 1489 of file BasicUtils/SessionReader.cpp.

References ASSERTL0, NEKERROR, and CellMLToNektar.cellml_metadata::p.

1491  {
1492  ASSERTL0(pFilenames.size() > 0, "No filenames for merging.");
1493 
1494  // Read the first document
1495  TiXmlDocument *vMainDoc = new TiXmlDocument;
1496  LoadDoc(pFilenames[0], vMainDoc);
1497 
1498  TiXmlHandle vMainHandle(vMainDoc);
1499  TiXmlElement* vMainNektar =
1500  vMainHandle.FirstChildElement("NEKTAR").Element();
1501 
1502  // Read all subsequent XML documents.
1503  // For each element within the NEKTAR tag, use it to replace the
1504  // version already present in the loaded XML data.
1505  for (int i = 1; i < pFilenames.size(); ++i)
1506  {
1507  if((pFilenames[i].compare(pFilenames[i].size()-3,3,"xml") == 0)
1508  ||(pFilenames[i].compare(pFilenames[i].size()-6,6,"xml.gz") == 0))
1509  {
1510  TiXmlDocument* vTempDoc = new TiXmlDocument;
1511  LoadDoc(pFilenames[i], vTempDoc);
1512 
1513  TiXmlHandle docHandle(vTempDoc);
1514  TiXmlElement* vTempNektar;
1515  vTempNektar = docHandle.FirstChildElement("NEKTAR").Element();
1516  ASSERTL0(vTempNektar, "Unable to find NEKTAR tag in file.");
1517  TiXmlElement* p = vTempNektar->FirstChildElement();
1518 
1519  while (p)
1520  {
1521  TiXmlElement *vMainEntry =
1522  vMainNektar->FirstChildElement(p->Value());
1523 
1524  // First check if the new item is in fact blank
1525  if (!p->FirstChild() && vMainEntry)
1526  {
1527  std::string warningmsg =
1528  "File " + pFilenames[i] + " contains " +
1529  "an empty XML element " +
1530  std::string(p->Value()) +
1531  " which will be ignored.";
1532  NEKERROR(ErrorUtil::ewarning, warningmsg.c_str());
1533  }
1534  else
1535  {
1536  if (vMainEntry)
1537  {
1538  vMainNektar->RemoveChild(vMainEntry);
1539  }
1540  TiXmlElement *q = new TiXmlElement(*p);
1541  vMainNektar->LinkEndChild(q);
1542  }
1543  p = p->NextSiblingElement();
1544  }
1545 
1546  delete vTempDoc;
1547  }
1548  }
1549  return vMainDoc;
1550  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
void LoadDoc(const std::string &pFilename, TiXmlDocument *pDoc) const
Loads an xml file into a tinyxml doc and decompresses if needed.

◆ ParseCommandLineArguments()

std::vector< std::string > Nektar::LibUtilities::SessionReader::ParseCommandLineArguments ( int  argc,
char *  argv[] 
)
private

Parse the program arguments and fill m_cmdLineOptions.

Parses the command-line arguments for known options and filenames.

Definition at line 376 of file BasicUtils/SessionReader.cpp.

References Nektar::NekConstants::kGitBranch, Nektar::NekConstants::kGitSha1, NEKTAR_VERSION, CellMLToNektar.cellml_metadata::p, and CellMLToNektar.translators::run().

378  {
379  // List the publically visible options (listed using --help)
380  po::options_description desc("Allowed options");
381  desc.add_options()
382  ("verbose,v", "be verbose")
383  ("version,V", "print version information")
384  ("help,h", "print this help message")
385  ("solverinfo,I", po::value<vector<std::string> >(),
386  "override a SOLVERINFO property")
387  ("parameter,P", po::value<vector<std::string> >(),
388  "override a parameter")
389  ("npx", po::value<int>(),
390  "number of procs in X-dir")
391  ("npy", po::value<int>(),
392  "number of procs in Y-dir")
393  ("npz", po::value<int>(),
394  "number of procs in Z-dir")
395  ("nsz", po::value<int>(),
396  "number of slices in Z-dir")
397  ("part-only", po::value<int>(),
398  "only partition mesh into N partitions.")
399  ("part-only-overlapping", po::value<int>(),
400  "only partition mesh into N overlapping partitions.")
401  ("part-info", "Output partition information")
402 #ifdef NEKTAR_USE_CWIPI
403  ("cwipi", po::value<std::string>(),
404  "set CWIPI name")
405 #endif
406  ;
407 
408  for (auto &cmdIt : GetCmdLineArgMap())
409  {
410  std::string names = cmdIt.first;
411  if (cmdIt.second.shortName != "")
412  {
413  names += "," + cmdIt.second.shortName;
414  }
415  if (cmdIt.second.isFlag)
416  {
417  desc.add_options()
418  (names.c_str(), cmdIt.second.description.c_str())
419  ;
420  }
421  else
422  {
423  desc.add_options()
424  (names.c_str(), po::value<std::string>(),
425  cmdIt.second.description.c_str())
426  ;
427  }
428  }
429 
430  // List hidden options (e.g. session file arguments are not actually
431  // specified using the input-file option by the user).
432  po::options_description hidden("Hidden options");
433  hidden.add_options()
434  ("input-file", po::value< vector<string> >(),
435  "input filename")
436  ;
437 
438  // Combine all options for the parser
439  po::options_description all("All options");
440  all.add(desc).add(hidden);
441 
442  // Session file is a positional option
443  po::positional_options_description p;
444  p.add("input-file", -1);
445 
446  // Parse the command-line options
447  po::parsed_options parsed = po::command_line_parser(argc, argv).
448  options(all).
449  positional(p).
450  allow_unregistered().
451  run();
452 
453  // Extract known options to map and update
454  po::store(parsed, m_cmdLineOptions);
455  po::notify(m_cmdLineOptions);
456 
457  // Help message
458  if (m_cmdLineOptions.count("help"))
459  {
460  cout << desc;
461  exit(0);
462  }
463 
464  // Version information
465  if (m_cmdLineOptions.count("version"))
466  {
467  cout << "Nektar++ version " << NEKTAR_VERSION;
468 
469  if (NekConstants::kGitSha1 != "GITDIR-NOTFOUND")
470  {
471  string sha1(NekConstants::kGitSha1);
472  string branch(NekConstants::kGitBranch);
473  boost::replace_all(branch, "refs/heads/", "");
474 
475  cout << " (git changeset " << sha1.substr(0, 8) << ", ";
476 
477  if (branch == "")
478  {
479  cout << "detached head";
480  }
481  else
482  {
483  cout << "head " << branch;
484  }
485 
486  cout << ")";
487  }
488 
489  cout << endl;
490  exit(0);
491  }
492 
493  // Enable verbose mode
494  if (m_cmdLineOptions.count("verbose"))
495  {
496  m_verbose = true;
497  }
498  else
499  {
500  m_verbose = false;
501  }
502 
503  // Print a warning for unknown options
504  for (auto &x : parsed.options)
505  {
506  if (x.unregistered)
507  {
508  cout << "Warning: Unknown option: " << x.string_key
509  << endl;
510  }
511  }
512 
513  // Return the vector of filename(s) given as positional options
514  if (m_cmdLineOptions.count("input-file"))
515  {
516  return m_cmdLineOptions["input-file"].as<
517  std::vector<std::string> >();
518  }
519  else
520  {
521  return std::vector<std::string>();
522  }
523  }
#define NEKTAR_VERSION
const std::string kGitSha1
boost::program_options::variables_map m_cmdLineOptions
const std::string kGitBranch
static CmdLineArgMap & GetCmdLineArgMap()
CmdLine argument map.

◆ ParseDocument()

void Nektar::LibUtilities::SessionReader::ParseDocument ( )
private

Loads and parses the specified file.

Definition at line 1556 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1557  {
1558  // Check we actually have a document loaded.
1559  ASSERTL0(m_xmlDoc, "No XML document loaded.");
1560 
1561  // Look for all data in CONDITIONS block.
1562  TiXmlHandle docHandle(m_xmlDoc);
1563  TiXmlElement* e;
1564  e = docHandle.FirstChildElement("NEKTAR").
1565  FirstChildElement("CONDITIONS").Element();
1566 
1567  // Read the various sections of the CONDITIONS block
1568  ReadParameters (e);
1569  ReadSolverInfo (e);
1571  ReadExpressions (e);
1572  ReadVariables (e);
1573  ReadFunctions (e);
1574 
1575  e = docHandle.FirstChildElement("NEKTAR").
1576  FirstChildElement("FILTERS").Element();
1577 
1578  ReadFilters(e);
1579  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
void ReadExpressions(TiXmlElement *conditions)
Reads the EXPRESSIONS section of the XML document.
void ReadSolverInfo(TiXmlElement *conditions)
Reads the SOLVERINFO section of the XML document.
void ReadGlobalSysSolnInfo(TiXmlElement *conditions)
Reads the GLOBALSYSSOLNINFO section of the XML document.
void ReadFunctions(TiXmlElement *conditions)
Reads the FUNCTIONS section of the XML document.
void ReadVariables(TiXmlElement *conditions)
Reads the VARIABLES section of the XML document.
void ReadFilters(TiXmlElement *filters)
Reads the FILTERS section of the XML document.
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.
void ReadParameters(TiXmlElement *conditions)
Reads the PARAMETERS section of the XML document.

◆ ParseEquals()

void Nektar::LibUtilities::SessionReader::ParseEquals ( const std::string &  line,
std::string &  lhs,
std::string &  rhs 
)
private

Parse a string in the form lhs = rhs.

Pull out lhs and rhs and eliminate any spaces.

Definition at line 2334 of file BasicUtils/SessionReader.cpp.

2338  {
2339  /// Pull out lhs and rhs and eliminate any spaces.
2340  size_t beg = line.find_first_not_of(" ");
2341  size_t end = line.find_first_of("=");
2342  // Check for no parameter name
2343  if (beg == end) throw 1;
2344  // Check for no parameter value
2345  if (end != line.find_last_of("=")) throw 1;
2346  // Check for no equals sign
2347  if (end == std::string::npos) throw 1;
2348 
2349  lhs = line.substr(line.find_first_not_of(" "),
2350  end-beg);
2351  lhs = lhs .substr(0, lhs.find_last_not_of(" ")+1);
2352  rhs = line.substr(line.find_last_of("=")+1);
2353  rhs = rhs .substr(rhs.find_first_not_of(" "));
2354  rhs = rhs .substr(0, rhs.find_last_not_of(" ")+1);
2355  }
StandardMatrixTag & lhs
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs

◆ ParseSessionName()

std::string Nektar::LibUtilities::SessionReader::ParseSessionName ( std::vector< std::string > &  filenames)
private

Parse the session name.

Definition at line 529 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

531  {
532  ASSERTL0(!filenames.empty(),
533  "At least one filename expected.");
534 
535  std::string retval = "";
536 
537  // First input file defines the session name
538  std::string fname = filenames[0];
539 
540  // If loading a pre-partitioned mesh, remove _xml extension
541  if (fname.size() > 4 &&
542  fname.substr(fname.size() - 4, 4) == "_xml")
543  {
544  retval = fname.substr(0, fname.find_last_of("_"));
545  }
546  // otherwise remove the .xml extension
547  else if (fname.size() > 4 &&
548  fname.substr(fname.size() - 4, 4) == ".xml")
549  {
550  retval = fname.substr(0, fname.find_last_of("."));
551  }
552  // If compressed .xml.gz, remove both extensions
553  else if (fname.size() > 7 &&
554  fname.substr(fname.size() - 7, 7) == ".xml.gz")
555  {
556  retval = fname.substr(0, fname.find_last_of("."));
557  retval = retval.substr(0, retval.find_last_of("."));
558  }
559 
560  return retval;
561  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216

◆ PartitionComm()

void Nektar::LibUtilities::SessionReader::PartitionComm ( )
private

Partitions the comm object based on session parameters.

Splits the processes into a cartesian grid and creates communicators for each row and column of the grid. The grid is defined by the PROC_X parameter which, if specified, gives the number of processes spanned by the Fourier direction. PROC_X must exactly divide the total number of processes or an error is thrown.

Definition at line 1616 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1617  {
1618  if (m_comm->GetSize() > 1)
1619  {
1620  int nProcZ = 1;
1621  int nProcY = 1;
1622  int nProcX = 1;
1623  int nStripZ = 1;
1624  if (DefinesCmdLineArgument("npx")) {
1625  nProcX = GetCmdLineArgument<int>("npx");
1626  }
1627  if (DefinesCmdLineArgument("npy")) {
1628  nProcY = GetCmdLineArgument<int>("npy");
1629  }
1630  if (DefinesCmdLineArgument("npz")) {
1631  nProcZ = GetCmdLineArgument<int>("npz");
1632  }
1633  if (DefinesCmdLineArgument("nsz")) {
1634  nStripZ = GetCmdLineArgument<int>("nsz");
1635  }
1636  ASSERTL0(m_comm->GetSize() % (nProcZ*nProcY*nProcX) == 0,
1637  "Cannot exactly partition using PROC_Z value.");
1638  ASSERTL0(nProcZ % nProcY == 0,
1639  "Cannot exactly partition using PROC_Y value.");
1640  ASSERTL0(nProcY % nProcX == 0,
1641  "Cannot exactly partition using PROC_X value.");
1642 
1643  // Number of processes associated with the spectral method
1644  int nProcSm = nProcZ * nProcY * nProcX;
1645 
1646  // Number of processes associated with the spectral element
1647  // method.
1648  int nProcSem = m_comm->GetSize() / nProcSm;
1649 
1650  m_comm->SplitComm(nProcSm,nProcSem);
1651  m_comm->GetColumnComm()->SplitComm(nProcZ/nStripZ,nStripZ);
1652  m_comm->GetColumnComm()->GetColumnComm()->SplitComm(
1653  (nProcY*nProcX),nProcZ/nStripZ);
1654  m_comm->GetColumnComm()->GetColumnComm()->GetColumnComm()
1655  ->SplitComm(nProcX,nProcY);
1656  }
1657  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
CommSharedPtr m_comm
Communication object.
bool DefinesCmdLineArgument(const std::string &pName) const
Checks if a specified cmdline argument has been given.

◆ ReadExpressions()

void Nektar::LibUtilities::SessionReader::ReadExpressions ( TiXmlElement *  conditions)
private

Reads the EXPRESSIONS section of the XML document.

Definition at line 1951 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1952  {
1953  m_expressions.clear();
1954 
1955  if (!conditions)
1956  {
1957  return;
1958  }
1959 
1960  TiXmlElement *expressionsElement =
1961  conditions->FirstChildElement("EXPRESSIONS");
1962 
1963  if (expressionsElement)
1964  {
1965  TiXmlElement *expr = expressionsElement->FirstChildElement("E");
1966 
1967  while (expr)
1968  {
1969  stringstream tagcontent;
1970  tagcontent << *expr;
1971  ASSERTL0(expr->Attribute("NAME"),
1972  "Missing NAME attribute in expression "
1973  "definition: \n\t'" + tagcontent.str() + "'");
1974  std::string nameString = expr->Attribute("NAME");
1975  ASSERTL0(!nameString.empty(),
1976  "Expressions must have a non-empty name: \n\t'"
1977  + tagcontent.str() + "'");
1978 
1979  ASSERTL0(expr->Attribute("VALUE"),
1980  "Missing VALUE attribute in expression "
1981  "definition: \n\t'" + tagcontent.str() + "'");
1982  std::string valString = expr->Attribute("VALUE");
1983  ASSERTL0(!valString.empty(),
1984  "Expressions must have a non-empty value: \n\t'"
1985  + tagcontent.str() + "'");
1986 
1987  auto exprIter = m_expressions.find(nameString);
1988  ASSERTL0(exprIter == m_expressions.end(),
1989  std::string("Expression '") + nameString
1990  + std::string("' already specified."));
1991 
1992  m_expressions[nameString] = valString;
1993  expr = expr->NextSiblingElement("E");
1994  }
1995  }
1996  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
ExpressionMap m_expressions
Expressions.

◆ ReadFilters()

void Nektar::LibUtilities::SessionReader::ReadFilters ( TiXmlElement *  filters)
private

Reads the FILTERS section of the XML document.

Definition at line 2293 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

2294  {
2295  if (!filters)
2296  {
2297  return;
2298  }
2299 
2300  m_filters.clear();
2301 
2302  TiXmlElement *filter = filters->FirstChildElement("FILTER");
2303  while (filter)
2304  {
2305  ASSERTL0(filter->Attribute("TYPE"),
2306  "Missing attribute 'TYPE' for filter.");
2307  std::string typeStr = filter->Attribute("TYPE");
2308 
2309  std::map<std::string, std::string> vParams;
2310 
2311  TiXmlElement *param = filter->FirstChildElement("PARAM");
2312  while (param)
2313  {
2314  ASSERTL0(param->Attribute("NAME"),
2315  "Missing attribute 'NAME' for parameter in filter "
2316  + typeStr + "'.");
2317  std::string nameStr = param->Attribute("NAME");
2318 
2319  ASSERTL0(param->GetText(), "Empty value string for param.");
2320  std::string valueStr = param->GetText();
2321 
2322  vParams[nameStr] = valueStr;
2323 
2324  param = param->NextSiblingElement("PARAM");
2325  }
2326 
2327  m_filters.push_back(
2328  std::pair<std::string, FilterParams>(typeStr, vParams));
2329 
2330  filter = filter->NextSiblingElement("FILTER");
2331  }
2332  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
FilterMap m_filters
Filters map.

◆ ReadFunctions()

void Nektar::LibUtilities::SessionReader::ReadFunctions ( TiXmlElement *  conditions)
private

Reads the FUNCTIONS section of the XML document.

Definition at line 2085 of file BasicUtils/SessionReader.cpp.

References ASSERTL0, Nektar::LibUtilities::eFunctionTypeExpression, Nektar::LibUtilities::eFunctionTypeFile, Nektar::LibUtilities::eFunctionTypeTransientFile, Nektar::LibUtilities::FunctionVariableDefinition::m_expression, Nektar::LibUtilities::FunctionVariableDefinition::m_filename, Nektar::LibUtilities::FunctionVariableDefinition::m_fileVariable, Nektar::LibUtilities::FunctionVariableDefinition::m_type, and NEKERROR.

2086  {
2087  m_functions.clear();
2088 
2089  if (!conditions)
2090  {
2091  return;
2092  }
2093 
2094  // Scan through conditions section looking for functions.
2095  TiXmlElement *function = conditions->FirstChildElement("FUNCTION");
2096  while (function)
2097  {
2098  stringstream tagcontent;
2099  tagcontent << *function;
2100 
2101  // Every function must have a NAME attribute
2102  ASSERTL0(function->Attribute("NAME"),
2103  "Functions must have a NAME attribute defined in XML "
2104  "element: \n\t'" + tagcontent.str() + "'");
2105  std::string functionStr = function->Attribute("NAME");
2106  ASSERTL0(!functionStr.empty(),
2107  "Functions must have a non-empty name in XML "
2108  "element: \n\t'" + tagcontent.str() + "'");
2109 
2110  // Store function names in uppercase to remain case-insensitive.
2111  boost::to_upper(functionStr);
2112 
2113  // Retrieve first entry (variable, or file)
2114  TiXmlElement *variable = function->FirstChildElement();
2115 
2116  // Create new function structure with default type of none.
2117  FunctionVariableMap functionVarMap;
2118 
2119  // Process all entries in the function block
2120  while (variable)
2121  {
2122  FunctionVariableDefinition funcDef;
2123  std::string conditionType = variable->Value();
2124 
2125  // If no var is specified, assume wildcard
2126  std::string variableStr;
2127  if (!variable->Attribute("VAR"))
2128  {
2129  variableStr = "*";
2130  }
2131  else
2132  {
2133  variableStr = variable->Attribute("VAR");
2134  }
2135 
2136  // Parse list of variables
2137  std::vector<std::string> variableList;
2138  ParseUtils::GenerateVector(variableStr, variableList);
2139 
2140  // If no domain string put to 0
2141  std::string domainStr;
2142  if (!variable->Attribute("DOMAIN"))
2143  {
2144  domainStr = "0";
2145  }
2146  else
2147  {
2148  domainStr = variable->Attribute("DOMAIN");
2149  }
2150 
2151  // If no domain string put to 0
2152  std::string evarsStr = "x y z t";
2153  if (variable->Attribute("EVARS"))
2154  {
2155  evarsStr = evarsStr + std::string(" ") + variable->Attribute("EVARS");
2156  }
2157 
2158  // Parse list of variables
2159  std::vector<std::string> varSplit;
2160  std::vector<unsigned int> domainList;
2161  ParseUtils::GenerateSeqVector(domainStr, domainList);
2162 
2163  // Expressions are denoted by E
2164  if (conditionType == "E")
2165  {
2166  funcDef.m_type = eFunctionTypeExpression;
2167 
2168  // Expression must have a VALUE.
2169  ASSERTL0(variable->Attribute("VALUE"),
2170  "Attribute VALUE expected for function '"
2171  + functionStr + "'.");
2172  std::string fcnStr = variable->Attribute("VALUE");
2173 
2174  ASSERTL0(!fcnStr.empty(),
2175  (std::string("Expression for var: ")
2176  + variableStr
2177  + std::string(" must be specified.")).c_str());
2178 
2179  SubstituteExpressions(fcnStr);
2180 
2181  // set expression
2182  funcDef.m_expression = MemoryManager<Equation>
2183  ::AllocateSharedPtr(m_interpreter, fcnStr, evarsStr);
2184  }
2185 
2186  // Files are denoted by F
2187  else if (conditionType == "F")
2188  {
2189  if (variable->Attribute("TIMEDEPENDENT") &&
2190  boost::lexical_cast<bool>(variable->Attribute("TIMEDEPENDENT")))
2191  {
2192  funcDef.m_type = eFunctionTypeTransientFile;
2193  }
2194  else
2195  {
2196  funcDef.m_type = eFunctionTypeFile;
2197  }
2198 
2199  // File must have a FILE.
2200  ASSERTL0(variable->Attribute("FILE"),
2201  "Attribute FILE expected for function '"
2202  + functionStr + "'.");
2203  std::string filenameStr = variable->Attribute("FILE");
2204 
2205  ASSERTL0(!filenameStr.empty(),
2206  "A filename must be specified for the FILE "
2207  "attribute of function '" + functionStr
2208  + "'.");
2209 
2210  std::vector<std::string> fSplit;
2211  boost::split(fSplit, filenameStr, boost::is_any_of(":"));
2212 
2213  ASSERTL0(fSplit.size() == 1 || fSplit.size() == 2,
2214  "Incorrect filename specification in function "
2215  + functionStr + "'. "
2216  "Specify variables inside file as: "
2217  "filename:var1,var2");
2218 
2219  // set the filename
2220  funcDef.m_filename = fSplit[0];
2221 
2222  if (fSplit.size() == 2)
2223  {
2224  ASSERTL0(variableList[0] != "*",
2225  "Filename variable mapping not valid "
2226  "when using * as a variable inside "
2227  "function '" + functionStr + "'.");
2228 
2229  boost::split(
2230  varSplit, fSplit[1], boost::is_any_of(","));
2231  ASSERTL0(varSplit.size() == variableList.size(),
2232  "Filename variables should contain the "
2233  "same number of variables defined in "
2234  "VAR in function " + functionStr + "'.");
2235  }
2236  }
2237 
2238  // Nothing else supported so throw an error
2239  else
2240  {
2241  stringstream tagcontent;
2242  tagcontent << *variable;
2243 
2245  "Identifier " + conditionType + " in function "
2246  + std::string(function->Attribute("NAME"))
2247  + " is not recognised in XML element: \n\t'"
2248  + tagcontent.str() + "'");
2249  }
2250 
2251 
2252 
2253  // Add variables to function
2254  for (unsigned int i = 0; i < variableList.size(); ++i)
2255  {
2256  for(unsigned int j = 0; j < domainList.size(); ++j)
2257  {
2258  // Check it has not already been defined
2259  pair<std::string,int> key(variableList[i],domainList[j]);
2260  auto fcnsIter = functionVarMap.find(key);
2261  ASSERTL0(fcnsIter == functionVarMap.end(),
2262  "Error setting expression '" + variableList[i]
2263  + " in domain "
2264  + boost::lexical_cast<std::string>(domainList[j])
2265  + "' in function '" + functionStr + "'. "
2266  "Expression has already been defined.");
2267 
2268  if (varSplit.size() > 0)
2269  {
2270  FunctionVariableDefinition funcDef2 = funcDef;
2271  funcDef2.m_fileVariable = varSplit[i];
2272  functionVarMap[key] = funcDef2;
2273  }
2274  else
2275  {
2276  functionVarMap[key] = funcDef;
2277  }
2278  }
2279  }
2280 
2281  variable = variable->NextSiblingElement();
2282  }
2283  // Add function definition to map
2284  m_functions[functionStr] = functionVarMap;
2285  function = function->NextSiblingElement("FUNCTION");
2286  }
2287  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
InterpreterSharedPtr m_interpreter
Interpreter instance.
std::map< std::pair< std::string, int >, FunctionVariableDefinition > FunctionVariableMap
void SubstituteExpressions(std::string &expr)
Substitutes expressions defined in the XML document.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
FunctionMap m_functions
Functions.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:135
static bool GenerateSeqVector(const std::string &str, std::vector< unsigned int > &out)
Takes a comma-separated compressed string and converts it to entries in a vector. ...
Definition: ParseUtils.cpp:108

◆ ReadGlobalSysSolnInfo()

void Nektar::LibUtilities::SessionReader::ReadGlobalSysSolnInfo ( TiXmlElement *  conditions)
private

Reads the GLOBALSYSSOLNINFO section of the XML document.

Definition at line 1823 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1824  {
1825  GetGloSysSolnList().clear();
1826 
1827  if (!conditions)
1828  {
1829  return;
1830  }
1831 
1832  TiXmlElement *GlobalSys =
1833  conditions->FirstChildElement("GLOBALSYSSOLNINFO");
1834 
1835  if(!GlobalSys)
1836  {
1837  return;
1838  }
1839 
1840  TiXmlElement *VarInfo = GlobalSys->FirstChildElement("V");
1841 
1842  while (VarInfo)
1843  {
1844  std::stringstream tagcontent;
1845  tagcontent << *VarInfo;
1846  ASSERTL0(VarInfo->Attribute("VAR"),
1847  "Missing VAR attribute in GobalSysSolnInfo XML "
1848  "element: \n\t'" + tagcontent.str() + "'");
1849 
1850  std::string VarList = VarInfo->Attribute("VAR");
1851  ASSERTL0(!VarList.empty(),
1852  "VAR attribute must be non-empty in XML element:\n\t'"
1853  + tagcontent.str() + "'");
1854 
1855  // generate a list of variables.
1856  std::vector<std::string> varStrings;
1857  bool valid = ParseUtils::GenerateVector(VarList, varStrings);
1858 
1859  ASSERTL0(valid,"Unable to process list of variable in XML "
1860  "element \n\t'" + tagcontent.str() + "'");
1861 
1862  if(varStrings.size())
1863  {
1864  TiXmlElement *SysSolnInfo = VarInfo->FirstChildElement("I");
1865 
1866  while (SysSolnInfo)
1867  {
1868  tagcontent.clear();
1869  tagcontent << *SysSolnInfo;
1870  // read the property name
1871  ASSERTL0(SysSolnInfo->Attribute("PROPERTY"),
1872  "Missing PROPERTY attribute in "
1873  "GlobalSysSolnInfo for variable(s) '"
1874  + VarList + "' in XML element: \n\t'"
1875  + tagcontent.str() + "'");
1876 
1877  std::string SysSolnProperty =
1878  SysSolnInfo->Attribute("PROPERTY");
1879 
1880  ASSERTL0(!SysSolnProperty.empty(),
1881  "GlobalSysSolnIno properties must have a "
1882  "non-empty name for variable(s) : '"
1883  + VarList + "' in XML element: \n\t'"
1884  + tagcontent.str() + "'");
1885 
1886  // make sure that solver property is capitalised
1887  std::string SysSolnPropertyUpper =
1888  boost::to_upper_copy(SysSolnProperty);
1889 
1890  // read the value
1891  ASSERTL0(SysSolnInfo->Attribute("VALUE"),
1892  "Missing VALUE attribute in GlobalSysSolnInfo "
1893  "for variable(s) '" + VarList
1894  + "' in XML element: \n\t"
1895  + tagcontent.str() + "'");
1896 
1897  std::string SysSolnValue =
1898  SysSolnInfo->Attribute("VALUE");
1899  ASSERTL0(!SysSolnValue.empty(),
1900  "GlobalSysSolnInfo properties must have a "
1901  "non-empty value for variable(s) '"
1902  + VarList + "' in XML element: \n\t'"
1903  + tagcontent.str() + "'");
1904 
1905  // Store values under variable map.
1906  for(int i = 0; i < varStrings.size(); ++i)
1907  {
1908  auto x = GetGloSysSolnList().find(varStrings[i]);
1909  if (x == GetGloSysSolnList().end())
1910  {
1911  (GetGloSysSolnList()[varStrings[i]])[
1912  SysSolnPropertyUpper] = SysSolnValue;
1913  }
1914  else
1915  {
1916  x->second[SysSolnPropertyUpper] = SysSolnValue;
1917  }
1918  }
1919 
1920  SysSolnInfo = SysSolnInfo->NextSiblingElement("I");
1921  }
1922  VarInfo = VarInfo->NextSiblingElement("V");
1923  }
1924  }
1925 
1926  if (m_verbose && GetGloSysSolnList().size() > 0 && m_comm)
1927  {
1928  if(m_comm->GetRank() == 0)
1929  {
1930  cout << "GlobalSysSoln Info:" << endl;
1931 
1932  for (auto &x : GetGloSysSolnList())
1933  {
1934  cout << "\t Variable: " << x.first << endl;
1935 
1936  for (auto &y : x.second)
1937  {
1938  cout << "\t\t " << y.first << " = " << y.second
1939  << endl;
1940  }
1941  }
1942  cout << endl;
1943  }
1944  }
1945  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
static GloSysSolnInfoList & GetGloSysSolnList()
GlobalSysSoln Info map.
CommSharedPtr m_comm
Communication object.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:135

◆ ReadParameters()

void Nektar::LibUtilities::SessionReader::ReadParameters ( TiXmlElement *  conditions)
private

Reads the PARAMETERS section of the XML document.

Definition at line 1663 of file BasicUtils/SessionReader.cpp.

References Nektar::LibUtilities::Equation::Evaluate(), Nektar::lhs, NEKERROR, and Nektar::rhs.

1664  {
1665  m_parameters.clear();
1666 
1667  if (!conditions)
1668  {
1669  return;
1670  }
1671 
1672  TiXmlElement *parametersElement = conditions->FirstChildElement(
1673  "PARAMETERS");
1674 
1675  // See if we have parameters defined. They are optional so we go on
1676  // if not.
1677  if (parametersElement)
1678  {
1679  TiXmlElement *parameter =
1680  parametersElement->FirstChildElement("P");
1681 
1682  ParameterMap caseSensitiveParameters;
1683 
1684  // Multiple nodes will only occur if there is a comment in
1685  // between definitions.
1686  while (parameter)
1687  {
1688  stringstream tagcontent;
1689  tagcontent << *parameter;
1690  TiXmlNode *node = parameter->FirstChild();
1691 
1692  while (node && node->Type() != TiXmlNode::TINYXML_TEXT)
1693  {
1694  node = node->NextSibling();
1695  }
1696 
1697  if (node)
1698  {
1699  // Format is "paramName = value"
1700  std::string line = node->ToText()->Value(), lhs, rhs;
1701 
1702  try {
1703  ParseEquals(line, lhs, rhs);
1704  }
1705  catch (...)
1706  {
1708  "Syntax error in parameter expression '"
1709  + line + "' in XML element: \n\t'"
1710  + tagcontent.str() + "'");
1711  }
1712 
1713  // We want the list of parameters to have their RHS
1714  // evaluated, so we use the expression evaluator to do
1715  // the dirty work.
1716  if (!lhs.empty() && !rhs.empty())
1717  {
1718  NekDouble value=0.0;
1719  try
1720  {
1721  LibUtilities::Equation expession(
1722  m_interpreter, rhs);
1723  value = expession.Evaluate();
1724  }
1725  catch (const std::runtime_error &)
1726  {
1728  "Error evaluating parameter expression"
1729  " '" + rhs + "' in XML element: \n\t'"
1730  + tagcontent.str() + "'");
1731  }
1732  m_interpreter->SetParameter(lhs, value);
1733  caseSensitiveParameters[lhs] = value;
1734  boost::to_upper(lhs);
1735  m_parameters[lhs] = value;
1736  }
1737  }
1738 
1739  parameter = parameter->NextSiblingElement();
1740  }
1741  }
1742  }
ParameterMap m_parameters
Parameters.
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
InterpreterSharedPtr m_interpreter
Interpreter instance.
StandardMatrixTag & lhs
void ParseEquals(const std::string &line, std::string &lhs, std::string &rhs)
Parse a string in the form lhs = rhs.
double NekDouble
std::map< std::string, NekDouble > ParameterMap
Definition: SessionReader.h:58
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs

◆ ReadSolverInfo()

void Nektar::LibUtilities::SessionReader::ReadSolverInfo ( TiXmlElement *  conditions)
private

Reads the SOLVERINFO section of the XML document.

Definition at line 1748 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1749  {
1750  m_solverInfo.clear();
1752 
1753  if (!conditions)
1754  {
1755  return;
1756  }
1757 
1758  TiXmlElement *solverInfoElement =
1759  conditions->FirstChildElement("SOLVERINFO");
1760 
1761  if (solverInfoElement)
1762  {
1763  TiXmlElement *solverInfo =
1764  solverInfoElement->FirstChildElement("I");
1765 
1766  while (solverInfo)
1767  {
1768  std::stringstream tagcontent;
1769  tagcontent << *solverInfo;
1770  // read the property name
1771  ASSERTL0(solverInfo->Attribute("PROPERTY"),
1772  "Missing PROPERTY attribute in solver info "
1773  "XML element: \n\t'" + tagcontent.str() + "'");
1774  std::string solverProperty =
1775  solverInfo->Attribute("PROPERTY");
1776  ASSERTL0(!solverProperty.empty(),
1777  "PROPERTY attribute must be non-empty in XML "
1778  "element: \n\t'" + tagcontent.str() + "'");
1779 
1780  // make sure that solver property is capitalised
1781  std::string solverPropertyUpper =
1782  boost::to_upper_copy(solverProperty);
1783 
1784  // read the value
1785  ASSERTL0(solverInfo->Attribute("VALUE"),
1786  "Missing VALUE attribute in solver info "
1787  "XML element: \n\t'" + tagcontent.str() + "'");
1788  std::string solverValue = solverInfo->Attribute("VALUE");
1789  ASSERTL0(!solverValue.empty(),
1790  "VALUE attribute must be non-empty in XML "
1791  "element: \n\t'" + tagcontent.str() + "'");
1792 
1793  // Set Variable
1794  m_solverInfo[solverPropertyUpper] = solverValue;
1795  solverInfo = solverInfo->NextSiblingElement("I");
1796  }
1797  }
1798 
1799  if (m_comm && m_comm->GetRowComm()->GetSize() > 1)
1800  {
1801  ASSERTL0(
1802  m_solverInfo["GLOBALSYSSOLN"] == "IterativeFull" ||
1803  m_solverInfo["GLOBALSYSSOLN"] == "IterativeStaticCond" ||
1804  m_solverInfo["GLOBALSYSSOLN"] ==
1805  "IterativeMultiLevelStaticCond" ||
1806  m_solverInfo["GLOBALSYSSOLN"] == "XxtFull" ||
1807  m_solverInfo["GLOBALSYSSOLN"] == "XxtStaticCond" ||
1808  m_solverInfo["GLOBALSYSSOLN"] ==
1809  "XxtMultiLevelStaticCond" ||
1810  m_solverInfo["GLOBALSYSSOLN"] == "PETScFull" ||
1811  m_solverInfo["GLOBALSYSSOLN"] == "PETScStaticCond" ||
1812  m_solverInfo["GLOBALSYSSOLN"] ==
1813  "PETScMultiLevelStaticCond",
1814  "A parallel solver must be used when run in parallel.");
1815  }
1816  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
SolverInfoMap m_solverInfo
Solver information properties.
CommSharedPtr m_comm
Communication object.
static SolverInfoMap & GetSolverInfoDefaults()
Default solver info options.

◆ ReadVariables()

void Nektar::LibUtilities::SessionReader::ReadVariables ( TiXmlElement *  conditions)
private

Reads the VARIABLES section of the XML document.

All elements are of the form: "<V ID="#"> name = value </V>", with ? being the element type.

Definition at line 2002 of file BasicUtils/SessionReader.cpp.

References ASSERTL0, and Nektar::StdRegions::find().

2003  {
2004  m_variables.clear();
2005 
2006  if (!conditions)
2007  {
2008  return;
2009  }
2010 
2011  TiXmlElement *variablesElement =
2012  conditions->FirstChildElement("VARIABLES");
2013 
2014  // See if we have parameters defined. They are optional so we go on
2015  // if not.
2016  if (variablesElement)
2017  {
2018  TiXmlElement *varElement =
2019  variablesElement->FirstChildElement("V");
2020 
2021  // Sequential counter for the composite numbers.
2022  int nextVariableNumber = -1;
2023 
2024  while (varElement)
2025  {
2026  stringstream tagcontent;
2027  tagcontent << *varElement;
2028 
2029  /// All elements are of the form: "<V ID="#"> name = value
2030  /// </V>", with ? being the element type.
2031  nextVariableNumber++;
2032 
2033  int i;
2034  int err = varElement->QueryIntAttribute("ID", &i);
2035  ASSERTL0(err == TIXML_SUCCESS,
2036  "Variables must have a unique ID number attribute "
2037  "in XML element: \n\t'" + tagcontent.str() + "'");
2038  ASSERTL0(i == nextVariableNumber,
2039  "ID numbers for variables must begin with zero and"
2040  " be sequential in XML element: \n\t'"
2041  + tagcontent.str() + "'");
2042 
2043  TiXmlNode* varChild = varElement->FirstChild();
2044  // This is primarily to skip comments that may be present.
2045  // Comments appear as nodes just like elements. We are
2046  // specifically looking for text in the body of the
2047  // definition.
2048  while(varChild && varChild->Type() != TiXmlNode::TINYXML_TEXT)
2049  {
2050  varChild = varChild->NextSibling();
2051  }
2052 
2053  ASSERTL0(varChild,
2054  "Unable to read variable definition body for "
2055  "variable with ID "
2056  + boost::lexical_cast<string>(i)
2057  + " in XML element: \n\t'"
2058  + tagcontent.str() + "'");
2059  std::string variableName = varChild->ToText()->ValueStr();
2060 
2061  std::istringstream variableStrm(variableName);
2062  variableStrm >> variableName;
2063 
2064  ASSERTL0(std::find(m_variables.begin(), m_variables.end(),
2065  variableName) == m_variables.end(),
2066  "Variable with ID "
2067  + boost::lexical_cast<string>(i)
2068  + " in XML element \n\t'" + tagcontent.str()
2069  + "'\nhas already been defined.");
2070 
2071  m_variables.push_back(variableName);
2072 
2073  varElement = varElement->NextSiblingElement("V");
2074  }
2075 
2076  ASSERTL0(nextVariableNumber > -1,
2077  "Number of variables must be greater than zero.");
2078  }
2079  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
VariableList m_variables
Variables.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:358

◆ RegisterCmdLineArgument()

std::string Nektar::LibUtilities::SessionReader::RegisterCmdLineArgument ( const std::string &  pName,
const std::string &  pShortName,
const std::string &  pDescription 
)
inlinestatic

Registers a command-line argument with the session reader.

Definition at line 656 of file SessionReader.h.

References ASSERTL0, and Nektar::LibUtilities::CmdLineArg::shortName.

660  {
661  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
662  CmdLineArg x;
663  x.shortName = pShortName;
664  x.description = pDescription;
665  x.isFlag = false;
666  GetCmdLineArgMap()[pName] = x;
667  return pName;
668  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
static CmdLineArgMap & GetCmdLineArgMap()
CmdLine argument map.

◆ RegisterCmdLineFlag()

std::string Nektar::LibUtilities::SessionReader::RegisterCmdLineFlag ( const std::string &  pName,
const std::string &  pShortName,
const std::string &  pDescription 
)
inlinestatic

Registers a command-line flag with the session reader.

Definition at line 674 of file SessionReader.h.

References ASSERTL0, and Nektar::LibUtilities::CmdLineArg::shortName.

678  {
679  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
680  CmdLineArg x;
681  x.shortName = pShortName;
682  x.description = pDescription;
683  x.isFlag = true;
684  GetCmdLineArgMap()[pName] = x;
685  return pName;
686  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
static CmdLineArgMap & GetCmdLineArgMap()
CmdLine argument map.

◆ RegisterDefaultSolverInfo()

std::string Nektar::LibUtilities::SessionReader::RegisterDefaultSolverInfo ( const std::string &  pName,
const std::string &  pValue 
)
inlinestatic

Registers the default string value of a solver info property.

A default value for a given solver info property may be registered using this function. The property will take this value until it is overwritten by a value specified in the XML document, or specified as a command-line argument. Usage has the form:

std::string GlobalLinSys::def
"GlobalSysSoln","DirectMultiLevelStaticCond");
Parameters
pNameThe name of the property.
pValueThe default value of the property.
Returns
The default value of the property provided by #pValue.

Definition at line 643 of file SessionReader.h.

Referenced by Nektar::Extrapolate::~Extrapolate().

646  {
647  std::string vName = boost::to_upper_copy(pName);
648  GetSolverInfoDefaults()[vName] = pValue;
649  return pValue;
650  }
static SolverInfoMap & GetSolverInfoDefaults()
Default solver info options.

◆ RegisterEnumValue()

std::string Nektar::LibUtilities::SessionReader::RegisterEnumValue ( std::string  pEnum,
std::string  pString,
int  pEnumValue 
)
inlinestatic

Registers an enumeration value.

A set of valid values for a given solver info property may be registered using this function. It must be called statically during the initialisation of a static variable. For example:

Parameters
pEnumThe name of the property.
pStringA valid value for the property.
pEnumValueAn enumeration value corresponding to this value.
Returns
The value for the property provided by #pString.

Definition at line 609 of file SessionReader.h.

611  {
612  std::string vEnum = boost::to_upper_copy(pEnum);
613  auto x = GetSolverInfoEnums().find(vEnum);
614 
615  if (x == GetSolverInfoEnums().end())
616  {
617  GetSolverInfoEnums()[vEnum] = EnumMap();
618  x = GetSolverInfoEnums().find(vEnum);
619  }
620 
621  x->second[pString] = pEnumValue;
622  return pString;
623  }
std::map< std::string, int > EnumMap
Definition: SessionReader.h:76
static EnumMapList & GetSolverInfoEnums()
String to enumeration map for Solver Info parameters.

◆ SetParameter() [1/2]

void Nektar::LibUtilities::SessionReader::SetParameter ( const std::string &  name,
int &  var 
)

Set an integer parameter.

Definition at line 801 of file BasicUtils/SessionReader.cpp.

802  {
803  std::string vName = boost::to_upper_copy(pName);
804  m_parameters[vName] = pVar;
805  }
ParameterMap m_parameters
Parameters.

◆ SetParameter() [2/2]

void Nektar::LibUtilities::SessionReader::SetParameter ( const std::string &  name,
NekDouble var 
)

Set a double precision parameter.

Definition at line 811 of file BasicUtils/SessionReader.cpp.

813  {
814  std::string vName = boost::to_upper_copy(pName);
815  m_parameters[vName] = pVar;
816  }
ParameterMap m_parameters
Parameters.

◆ SetSolverInfo()

void Nektar::LibUtilities::SessionReader::SetSolverInfo ( const std::string &  pProperty,
const std::string &  pValue 
)

Sets the value of the specified solver info property.

Definition at line 849 of file BasicUtils/SessionReader.cpp.

References ASSERTL1.

851  {
852  std::string vProperty = boost::to_upper_copy(pProperty);
853  auto iter = m_solverInfo.find(vProperty);
854 
855  ASSERTL1(iter != m_solverInfo.end(),
856  "Unable to find requested property: " + pProperty);
857 
858  iter->second = pValue;
859  }
SolverInfoMap m_solverInfo
Solver information properties.
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250

◆ SetTag()

void Nektar::LibUtilities::SessionReader::SetTag ( const std::string &  pName,
const std::string &  pValue 
)

Sets a specified tag.

Definition at line 1385 of file BasicUtils/SessionReader.cpp.

1388  {
1389  std::string vName = boost::to_upper_copy(pName);
1390  m_tags[vName] = pValue;
1391  }

◆ SetUpXmlDoc()

void Nektar::LibUtilities::SessionReader::SetUpXmlDoc ( void  )

Definition at line 2446 of file BasicUtils/SessionReader.cpp.

2447  {
2449  }
TiXmlDocument * MergeDoc(const std::vector< std::string > &pFilenames) const
Creates an XML document from a list of input files.
std::vector< std::string > m_filenames
Filenames.
TiXmlDocument * m_xmlDoc
Pointer to the loaded XML document.

◆ SetVariable()

void Nektar::LibUtilities::SessionReader::SetVariable ( const unsigned int &  idx,
std::string  newname 
)

Definition at line 1115 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

1117  {
1118  ASSERTL0(idx < m_variables.size(), "Variable index out of range.");
1119  m_variables[idx] = newname;
1120  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
VariableList m_variables
Variables.

◆ SubstituteExpressions()

void Nektar::LibUtilities::SessionReader::SubstituteExpressions ( std::string &  expr)

Substitutes expressions defined in the XML document.

Definition at line 1429 of file BasicUtils/SessionReader.cpp.

1430  {
1431  for (auto &exprIter : m_expressions)
1432  {
1433  boost::replace_all(pExpr, exprIter.first, exprIter.second);
1434  }
1435  }
ExpressionMap m_expressions
Expressions.

◆ TestSharedFilesystem()

void Nektar::LibUtilities::SessionReader::TestSharedFilesystem ( )
private

Definition at line 334 of file BasicUtils/SessionReader.cpp.

References ASSERTL1, and Nektar::LibUtilities::ReduceSum.

335  {
336  m_sharedFilesystem = false;
337 
338  if (m_comm->GetSize() > 1)
339  {
340  if (m_comm->GetRank() == 0)
341  {
342  std::ofstream testfile("shared-fs-testfile");
343  testfile << "" << std::endl;
344  ASSERTL1(!testfile.fail(), "Test file creation failed");
345  testfile.close();
346  }
347  m_comm->Block();
348 
349  int exists = (bool)boost::filesystem::exists("shared-fs-testfile");
350  m_comm->AllReduce(exists, LibUtilities::ReduceSum);
351 
352  m_sharedFilesystem = (exists == m_comm->GetSize());
353 
354  if ((m_sharedFilesystem && m_comm->GetRank() == 0) ||
356  {
357  std::remove("shared-fs-testfile");
358  }
359  }
360  else
361  {
362  m_sharedFilesystem = false;
363  }
364 
365  if (m_verbose && m_comm->GetRank() == 0 && m_sharedFilesystem)
366  {
367  cout << "Shared filesystem detected" << endl;
368  }
369  }
CommSharedPtr m_comm
Communication object.
bool m_sharedFilesystem
Running on a shared filesystem.
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250

◆ VerifySolverInfo()

void Nektar::LibUtilities::SessionReader::VerifySolverInfo ( )
private

Check values of solver info options are valid.

Definition at line 2427 of file BasicUtils/SessionReader.cpp.

References ASSERTL0.

2428  {
2429  for (auto &x : m_solverInfo)
2430  {
2431  std::string solverProperty = x.first;
2432  std::string solverValue = x.second;
2433 
2434  auto propIt = GetSolverInfoEnums().find(solverProperty);
2435  if (propIt != GetSolverInfoEnums().end())
2436  {
2437  auto valIt = propIt->second.find(solverValue);
2438  ASSERTL0(valIt != propIt->second.end(),
2439  "Value '" + solverValue + "' is not valid for "
2440  "property '" + solverProperty + "'");
2441  }
2442  }
2443  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
SolverInfoMap m_solverInfo
Solver information properties.
static EnumMapList & GetSolverInfoEnums()
String to enumeration map for Solver Info parameters.

Friends And Related Function Documentation

◆ MemoryManager< SessionReader >

friend class MemoryManager< SessionReader >
friend

Support creation through MemoryManager.

Definition at line 120 of file SessionReader.h.

Member Data Documentation

◆ m_cmdLineOptions

boost::program_options::variables_map Nektar::LibUtilities::SessionReader::m_cmdLineOptions
private

Definition at line 424 of file SessionReader.h.

◆ m_comm

CommSharedPtr Nektar::LibUtilities::SessionReader::m_comm
private

Communication object.

Definition at line 427 of file SessionReader.h.

◆ m_expressions

ExpressionMap Nektar::LibUtilities::SessionReader::m_expressions
private

Expressions.

Definition at line 441 of file SessionReader.h.

◆ m_filenames

std::vector<std::string> Nektar::LibUtilities::SessionReader::m_filenames
private

Filenames.

Definition at line 429 of file SessionReader.h.

◆ m_filters

FilterMap Nektar::LibUtilities::SessionReader::m_filters
private

Filters map.

Definition at line 451 of file SessionReader.h.

◆ m_functions

FunctionMap Nektar::LibUtilities::SessionReader::m_functions
private

Functions.

Definition at line 445 of file SessionReader.h.

◆ m_geometricInfo

GeometricInfoMap Nektar::LibUtilities::SessionReader::m_geometricInfo
private

Geometric information properties.

Definition at line 439 of file SessionReader.h.

◆ m_interpreter

InterpreterSharedPtr Nektar::LibUtilities::SessionReader::m_interpreter
private

Interpreter instance.

Definition at line 443 of file SessionReader.h.

◆ m_parameters

ParameterMap Nektar::LibUtilities::SessionReader::m_parameters
private

Parameters.

Definition at line 435 of file SessionReader.h.

◆ m_sessionName

std::string Nektar::LibUtilities::SessionReader::m_sessionName
private

Session name of the loaded XML document (filename minus ext).

Definition at line 431 of file SessionReader.h.

◆ m_sharedFilesystem

bool Nektar::LibUtilities::SessionReader::m_sharedFilesystem
private

Running on a shared filesystem.

Definition at line 455 of file SessionReader.h.

◆ m_solverInfo

SolverInfoMap Nektar::LibUtilities::SessionReader::m_solverInfo
private

Solver information properties.

Definition at line 437 of file SessionReader.h.

◆ m_tags

TagMap Nektar::LibUtilities::SessionReader::m_tags
private

Custom tags.

Definition at line 449 of file SessionReader.h.

◆ m_variables

VariableList Nektar::LibUtilities::SessionReader::m_variables
private

Variables.

Definition at line 447 of file SessionReader.h.

◆ m_verbose

bool Nektar::LibUtilities::SessionReader::m_verbose
private

Be verbose.

Definition at line 453 of file SessionReader.h.

◆ m_xmlDoc

TiXmlDocument* Nektar::LibUtilities::SessionReader::m_xmlDoc
private

Pointer to the loaded XML document.

Definition at line 433 of file SessionReader.h.