Nektar++
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
 
bool DefinesTimeIntScheme () const
 Returns true if the TIMEINTEGRATIONSCHEME section is defined in the session file. More...
 
const TimeIntSchemeGetTimeIntScheme () const
 Returns the time integration scheme structure m_timeIntScheme from the session file. More...
 
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 ReadTimeIntScheme (TiXmlElement *conditions)
 Reads the TIMEINTEGRATIONSCHEME 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...
 
TimeIntScheme m_timeIntScheme
 Time integration scheme information. 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:

static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
std::shared_ptr< SessionReader > SessionReaderSharedPtr

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 124 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 222 of file BasicUtils/SessionReader.cpp.

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

References ASSERTL0.

◆ ~SessionReader()

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

Destructor.

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

269  {
270  if (m_xmlDoc)
271  {
272  delete m_xmlDoc;
273  }
274  }

◆ 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 188 of file BasicUtils/SessionReader.cpp.

189  {
190  m_xmlDoc = 0;
192 
193  ASSERTL0(m_filenames.size() > 0, "No session file(s) given.");
194 
196 
197  // Create communicator
198  CreateComm(argc, argv);
199 
201 
202  // If running in parallel change the default global sys solution
203  // type.
204  if (m_comm->GetSize() > 1)
205  {
206  GetSolverInfoDefaults()["GLOBALSYSSOLN"] =
207  "IterativeStaticCond";
208  }
209 
211  m_interpreter->SetRandomSeed((m_comm->GetRank() + 1)
212  * (unsigned int)time(NULL));
213 
214  // Split up the communicator
215  PartitionComm();
216  }

References ASSERTL0.

Member Function Documentation

◆ CmdLineOverride()

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

Enforce parameters from command line arguments.

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

2485  {
2486  // Parse solver info overrides
2487  if (m_cmdLineOptions.count("solverinfo"))
2488  {
2489  std::vector<std::string> solverInfoList =
2490  m_cmdLineOptions["solverinfo"].as<
2491  std::vector<std::string> >();
2492 
2493  for (size_t i = 0; i < solverInfoList.size(); ++i)
2494  {
2495  std::string lhs, rhs;
2496 
2497  try
2498  {
2499  ParseEquals(solverInfoList[i], lhs, rhs);
2500  }
2501  catch (...)
2502  {
2504  "Parse error with command line "
2505  "option: "+solverInfoList[i]);
2506  }
2507 
2508  std::string lhsUpper = boost::to_upper_copy(lhs);
2509  m_solverInfo[lhsUpper] = rhs;
2510  }
2511  }
2512 
2513  if (m_cmdLineOptions.count("parameter"))
2514  {
2515  std::vector<std::string> parametersList =
2516  m_cmdLineOptions["parameter"].as<
2517  std::vector<std::string> >();
2518 
2519  for (size_t i = 0; i < parametersList.size(); ++i)
2520  {
2521  std::string lhs, rhs;
2522 
2523  try
2524  {
2525  ParseEquals(parametersList[i], lhs, rhs);
2526  }
2527  catch (...)
2528  {
2530  "Parse error with command line "
2531  "option: "+parametersList[i]);
2532  }
2533 
2534  std::string lhsUpper = boost::to_upper_copy(lhs);
2535 
2536  try
2537  {
2538  m_parameters[lhsUpper] =
2539  boost::lexical_cast<NekDouble>(rhs);
2540  }
2541  catch (...)
2542  {
2544  "Unable to convert string: "+rhs+
2545  "to double value.");
2546  }
2547  }
2548  }
2549  }
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
SolverInfoMap m_solverInfo
Solver information properties.
ParameterMap m_parameters
Parameters.
boost::program_options::variables_map m_cmdLineOptions
void ParseEquals(const std::string &line, std::string &lhs, std::string &rhs)
Parse a string in the form lhs = rhs.

References NEKERROR.

◆ 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 1607 of file BasicUtils/SessionReader.cpp.

1610  {
1611  if (argc == 0)
1612  {
1613  m_comm = GetCommFactory().CreateInstance("Serial", 0, 0);
1614  }
1615  else
1616  {
1617  string vCommModule("Serial");
1618  if (GetCommFactory().ModuleExists("ParallelMPI"))
1619  {
1620  vCommModule = "ParallelMPI";
1621  }
1622  if (m_cmdLineOptions.count("cwipi") && GetCommFactory().ModuleExists("CWIPI"))
1623  {
1624  vCommModule = "CWIPI";
1625  }
1626 
1627  m_comm = GetCommFactory().CreateInstance(vCommModule, argc, argv);
1628  }
1629  }
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:145
CommFactory & GetCommFactory()

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

◆ 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 140 of file SessionReader.h.

142  {
143  SessionReaderSharedPtr p = MemoryManager<
144  LibUtilities::SessionReader>::AllocateSharedPtr(argc, argv);
145  return p;
146  }

References CellMLToNektar.cellml_metadata::p.

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

◆ 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 158 of file SessionReader.h.

163  {
164  SessionReaderSharedPtr p = MemoryManager<
165  LibUtilities::SessionReader>
166  ::AllocateSharedPtr(argc, argv, pFilenames, pComm);
167  return p;
168  }

References CellMLToNektar.cellml_metadata::p.

◆ DefinesCmdLineArgument()

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

Checks if a specified cmdline argument has been given.

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

1442  {
1443  return (m_cmdLineOptions.find(pName) != m_cmdLineOptions.end());
1444  }

◆ 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 620 of file BasicUtils/SessionReader.cpp.

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

References ASSERTL0.

◆ 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 1156 of file BasicUtils/SessionReader.cpp.

1157  {
1158  std::string vName = boost::to_upper_copy(pName);
1159  return m_functions.find(vName) != m_functions.end();
1160  }
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 1166 of file BasicUtils/SessionReader.cpp.

1170  {
1171  std::string vName = boost::to_upper_copy(pName);
1172 
1173  // Check function exists
1174  auto it1 = m_functions.find(vName);
1175  if (it1 != m_functions.end())
1176  {
1177  pair<std::string, int> key(pVariable,pDomain);
1178  pair<std::string, int> defkey("*",pDomain);
1179  bool varExists =
1180  it1->second.find(key) != it1->second.end() ||
1181  it1->second.find(defkey) != it1->second.end();
1182  return varExists;
1183  }
1184  return false;
1185  }

◆ DefinesGeometricInfo()

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

Checks if a geometric info property is defined.

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

1023  {
1024  std::string vName = boost::to_upper_copy(pName);
1025  return m_geometricInfo.find(vName) != m_geometricInfo.end();
1026  }
GeometricInfoMap m_geometricInfo
Geometric information properties.

◆ DefinesGlobalSysSolnInfo()

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

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

932  {
933  auto iter = GetGloSysSolnList().find(pVariable);
934  if(iter == GetGloSysSolnList().end())
935  {
936  return false;
937  }
938 
939  std::string vProperty = boost::to_upper_copy(pProperty);
940 
941  auto iter1 = iter->second.find(vProperty);
942  if(iter1 == iter->second.end())
943  {
944  return false;
945  }
946 
947  return true;
948  }
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 702 of file BasicUtils/SessionReader.cpp.

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

Referenced by export_SessionReader().

◆ DefinesSolverInfo()

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

Checks if a solver info property is specified.

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

827  {
828  std::string vName = boost::to_upper_copy(pName);
829  auto infoIter = m_solverInfo.find(vName);
830  return (infoIter != m_solverInfo.end());
831  }

Referenced by GetSolverInfoAsEnum().

◆ DefinesTag()

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

Checks if a specified tag is defined.

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

1397  {
1398  std::string vName = boost::to_upper_copy(pName);
1399  return m_tags.find(vName) != m_tags.end();
1400  }

◆ DefinesTimeIntScheme()

bool Nektar::LibUtilities::SessionReader::DefinesTimeIntScheme ( ) const

Returns true if the TIMEINTEGRATIONSCHEME section is defined in the session file.

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

974  {
975  return m_timeIntScheme.method != "";
976  }
TimeIntScheme m_timeIntScheme
Time integration scheme information.

◆ 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 693 of file BasicUtils/SessionReader.cpp.

694  {
695  m_comm->Finalise();
696  }

Referenced by export_SessionReader().

◆ 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 173 of file BasicUtils/SessionReader.cpp.

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

Referenced by RegisterCmdLineArgument(), and RegisterCmdLineFlag().

◆ GetCmdLineArgument()

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

Retrieves a command-line argument value.

Definition at line 411 of file SessionReader.h.

413  {
414  return m_cmdLineOptions.find(pName)->second.as<T>();
415  }

References m_cmdLineOptions.

◆ GetComm()

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

Returns the communication object.

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

678  {
679  return m_comm;
680  }

Referenced by export_SessionReader().

◆ GetDocument()

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

Provides direct access to the TiXmlDocument object.

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

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

References ASSERTL1.

◆ 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
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
Note
Paths are case-insensitive.
Parameters
pPathPath to requested element.
Returns
Direct pointer to requested XML Element.

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

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

References ASSERTL0.

◆ GetFilenames()

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

Returns the filename of the loaded XML document.

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

643  {
644  return m_filenames;
645  }

◆ GetFilters()

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

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

1432  {
1433  return m_filters;
1434  }

◆ 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 1191 of file BasicUtils/SessionReader.cpp.

1195  {
1196  std::string vName = boost::to_upper_copy(pName);
1197  auto it1 = m_functions.find(vName);
1198 
1199  ASSERTL0(it1 != m_functions.end(),
1200  std::string("No such function '") + pName
1201  + std::string("' has been defined in the session file."));
1202 
1203  // Check for specific and wildcard definitions
1204  pair<std::string,int> key(pVariable,pDomain);
1205  pair<std::string,int> defkey("*",pDomain);
1206 
1207  auto it2 = it1->second.find(key);
1208  auto it3 = it1->second.find(defkey);
1209  bool specific = it2 != it1->second.end();
1210  bool wildcard = it3 != it1->second.end();
1211 
1212  // Check function is defined somewhere
1213  ASSERTL0(specific || wildcard,
1214  "No such variable " + pVariable
1215  + " in domain " + boost::lexical_cast<string>(pDomain)
1216  + " defined for function " + pName
1217  + " in session file.");
1218 
1219  // If not specific, must be wildcard
1220  if (!specific)
1221  {
1222  it2 = it3;
1223  }
1224 
1225  ASSERTL0((it2->second.m_type == eFunctionTypeExpression),
1226  std::string("Function is defined by a file."));
1227  return it2->second.m_expression;
1228  }

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

◆ 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 1234 of file BasicUtils/SessionReader.cpp.

1238  {
1239  ASSERTL0(pVar < m_variables.size(), "Variable index out of range.");
1240  return GetFunction(pName, m_variables[pVar],pDomain);
1241  }
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.

References ASSERTL0.

◆ 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 1301 of file BasicUtils/SessionReader.cpp.

1305  {
1306  std::string vName = boost::to_upper_copy(pName);
1307  auto it1 = m_functions.find(vName);
1308 
1309  ASSERTL0 (it1 != m_functions.end(),
1310  std::string("Function '") + pName
1311  + std::string("' not found."));
1312 
1313  // Check for specific and wildcard definitions
1314  pair<std::string,int> key(pVariable,pDomain);
1315  pair<std::string,int> defkey("*",pDomain);
1316 
1317  auto it2 = it1->second.find(key);
1318  auto it3 = it1->second.find(defkey);
1319  bool specific = it2 != it1->second.end();
1320  bool wildcard = it3 != it1->second.end();
1321 
1322  // Check function is defined somewhere
1323  ASSERTL0(specific || wildcard,
1324  "No such variable " + pVariable
1325  + " in domain " + boost::lexical_cast<string>(pDomain)
1326  + " defined for function " + pName
1327  + " in session file.");
1328 
1329  // If not specific, must be wildcard
1330  if (!specific)
1331  {
1332  it2 = it3;
1333  }
1334 
1335  return it2->second.m_filename;
1336  }

References ASSERTL0.

◆ 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 1342 of file BasicUtils/SessionReader.cpp.

1346  {
1347  ASSERTL0(pVar < m_variables.size(), "Variable index out of range.");
1348  return GetFunctionFilename(pName, m_variables[pVar],pDomain);
1349  }
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.

References ASSERTL0.

◆ 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 1355 of file BasicUtils/SessionReader.cpp.

1359  {
1360  std::string vName = boost::to_upper_copy(pName);
1361  auto it1 = m_functions.find(vName);
1362 
1363  ASSERTL0 (it1 != m_functions.end(),
1364  std::string("Function '") + pName
1365  + std::string("' not found."));
1366 
1367  // Check for specific and wildcard definitions
1368  pair<std::string,int> key(pVariable,pDomain);
1369  pair<std::string,int> defkey("*",pDomain);
1370 
1371  auto it2 = it1->second.find(key);
1372  auto it3 = it1->second.find(defkey);
1373  bool specific = it2 != it1->second.end();
1374  bool wildcard = it3 != it1->second.end();
1375 
1376  // Check function is defined somewhere
1377  ASSERTL0(specific || wildcard,
1378  "No such variable " + pVariable
1379  + " in domain " + boost::lexical_cast<string>(pDomain)
1380  + " defined for function " + pName
1381  + " in session file.");
1382 
1383  // If not specific, must be wildcard
1384  if (!specific)
1385  {
1386  it2 = it3;
1387  }
1388 
1389  return it2->second.m_fileVariable;
1390  }

References ASSERTL0.

◆ 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 1234 of file BasicUtils/SessionReader.cpp.

1251  {
1252  std::string vName = boost::to_upper_copy(pName);
1253  auto it1 = m_functions.find(vName);
1254 
1255  ASSERTL0 (it1 != m_functions.end(),
1256  std::string("Function '") + pName
1257  + std::string("' not found."));
1258 
1259  // Check for specific and wildcard definitions
1260  pair<std::string,int> key(pVariable,pDomain);
1261  pair<std::string,int> defkey("*",pDomain);
1262 
1263  auto it2 = it1->second.find(key);
1264  auto it3 = it1->second.find(defkey);
1265  bool specific = it2 != it1->second.end();
1266  bool wildcard = it3 != it1->second.end();
1267 
1268  // Check function is defined somewhere
1269  ASSERTL0(specific || wildcard,
1270  "No such variable " + pVariable
1271  + " in domain " + boost::lexical_cast<string>(pDomain)
1272  + " defined for function " + pName
1273  + " in session file.");
1274 
1275  // If not specific, must be wildcard
1276  if (!specific)
1277  {
1278  it2 = it3;
1279  }
1280 
1281  return it2->second.m_type;
1282  }

◆ 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 1234 of file BasicUtils/SessionReader.cpp.

1292  {
1293  ASSERTL0(pVar < m_variables.size(), "Variable index out of range.");
1294  return GetFunctionType(pName, m_variables[pVar],pDomain);
1295  }
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 987 of file BasicUtils/SessionReader.cpp.

988  {
989  TiXmlElement *xmlGeom = m_xmlDoc->FirstChildElement("NEKTAR")
990  ->FirstChildElement("GEOMETRY");
991  TiXmlAttribute *attr = xmlGeom->FirstAttribute();
992  while (attr)
993  {
994  std::string attrName(attr->Name());
995  if (attrName == "HDF5FILE")
996  {
997  // there is a file pointer, therefore is HDF5
998  return "HDF5";
999  }
1000  // Get the next attribute.
1001  attr = attr->Next();
1002  }
1003 
1004  // Check the VERTEX block. If this is compressed, assume the file is
1005  // compressed, otherwise assume uncompressed.
1006  TiXmlElement *element = xmlGeom->FirstChildElement("VERTEX");
1007  string IsCompressed;
1008  element->QueryStringAttribute("COMPRESSED", &IsCompressed);
1009 
1010  if (IsCompressed.size() > 0)
1011  {
1012  return "XmlCompressed";
1013  }
1014 
1015  // no file pointer or compressed, just standard xml
1016  return "Xml";
1017  }

◆ GetGlobalSysSolnInfo()

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

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

955  {
956  auto iter = GetGloSysSolnList().find(pVariable);
957  ASSERTL0(iter != GetGloSysSolnList().end(),
958  "Failed to find variable in GlobalSysSolnInfoList");
959 
960  std::string vProperty = boost::to_upper_copy(pProperty);
961  auto iter1 = iter->second.find(vProperty);
962 
963  ASSERTL0(iter1 != iter->second.end(),
964  "Failed to find property: " + vProperty + " in GlobalSysSolnInfoList");
965 
966  return iter1->second;
967  }

References ASSERTL0.

◆ 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 159 of file BasicUtils/SessionReader.cpp.

160  {
161  static GloSysSolnInfoList gloSysSolnInfoList;
162  return gloSysSolnInfoList;
163  }
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 2575 of file BasicUtils/SessionReader.cpp.

2576  {
2577  return m_interpreter;
2578  }

◆ 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 717 of file BasicUtils/SessionReader.cpp.

719  {
720  std::string vName = boost::to_upper_copy(pName);
721  auto paramIter = m_parameters.find(vName);
722 
723  ASSERTL0(paramIter != m_parameters.end(),
724  "Unable to find requested parameter: " + pName);
725 
726  return paramIter->second;
727  }

References ASSERTL0.

Referenced by export_SessionReader().

◆ GetSessionName()

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

Returns the session name of the loaded XML document.

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

652  {
653  return m_sessionName;
654  }

Referenced by export_SessionReader().

◆ 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 661 of file BasicUtils/SessionReader.cpp.

662  {
663  std::string dirname = m_sessionName + "_xml";
664  fs::path pdirname(dirname);
665 
666  std::string vFilename = "P" + boost::lexical_cast<std::string>(m_comm->GetRowComm()->GetRank());
667  fs::path pFilename(vFilename);
668 
669  fs::path fullpath = pdirname / pFilename;
670 
671  return PortablePath(fullpath);
672  }
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
Definition: FileSystem.cpp:41

References Nektar::LibUtilities::PortablePath().

◆ GetSharedFilesystem()

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

Returns if file system shared.

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

683  {
684  return m_sharedFilesystem;
685  }
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 837 of file BasicUtils/SessionReader.cpp.

839  {
840  std::string vProperty = boost::to_upper_copy(pProperty);
841  auto iter = m_solverInfo.find(vProperty);
842 
843  ASSERTL1(iter != m_solverInfo.end(),
844  "Unable to find requested property: " + pProperty);
845 
846  return iter->second;
847  }

References ASSERTL1.

Referenced by GetSolverInfoAsEnum().

◆ 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 556 of file SessionReader.h.

558  {
559  std::string vName = boost::to_upper_copy(pName);
561  "Solver info '" + pName + "' not defined.");
562 
563  std::string vValue = GetSolverInfo(vName);
564  auto x = GetSolverInfoEnums().find(vName);
565  ASSERTL0(x != GetSolverInfoEnums().end(),
566  "Enum for SolverInfo property '" + pName + "' not found.");
567 
568  auto y = x->second.find(vValue);
569  ASSERTL0(y != x->second.end(),
570  "Value of SolverInfo property '" + pName +
571  "' is invalid.");
572 
573  return T(y->second);
574  }
bool DefinesSolverInfo(const std::string &name) const
Checks if a solver info property is specified.
static EnumMapList & GetSolverInfoEnums()
String to enumeration map for Solver Info parameters.
const std::string & GetSolverInfo(const std::string &pProperty) const
Returns the value of the specified solver info property.

References ASSERTL0, DefinesSolverInfo(), GetSolverInfo(), and GetSolverInfoEnums().

◆ 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 143 of file BasicUtils/SessionReader.cpp.

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

Referenced by RegisterDefaultSolverInfo().

◆ 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 128 of file BasicUtils/SessionReader.cpp.

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

Referenced by GetSolverInfoAsEnum(), GetValueAsEnum(), and RegisterEnumValue().

◆ GetTag()

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

Returns the value of a specified tag.

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

1419  {
1420  std::string vName = boost::to_upper_copy(pName);
1421  auto vTagIterator = m_tags.find(vName);
1422  ASSERTL0(vTagIterator != m_tags.end(),
1423  "Requested tag does not exist.");
1424  return vTagIterator->second;
1425  }

References ASSERTL0.

◆ GetTimeIntScheme()

const TimeIntScheme & Nektar::LibUtilities::SessionReader::GetTimeIntScheme ( ) const

Returns the time integration scheme structure m_timeIntScheme from the session file.

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

983  {
984  return m_timeIntScheme;
985  }

◆ 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 582 of file SessionReader.h.

585  {
586  std::string vName = boost::to_upper_copy(pName);
587 
588  auto x = GetSolverInfoEnums().find(vName);
589  ASSERTL0(x != GetSolverInfoEnums().end(),
590  "Enum for property '" + pName + "' not found.");
591 
592  auto y = x->second.find(pValue);
593  ASSERTL0(y != x->second.end(),
594  "Value of property '" + pValue + "' is invalid.");
595  return T(y->second);
596  }

References ASSERTL0, and GetSolverInfoEnums().

◆ 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 1124 of file BasicUtils/SessionReader.cpp.

1126  {
1127  ASSERTL0(idx < m_variables.size(), "Variable index out of range.");
1128  return m_variables[idx];
1129  }

References ASSERTL0.

Referenced by export_SessionReader().

◆ GetVariables()

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

Returns the names of all variables.

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

1148  {
1149  return m_variables;
1150  }

◆ 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 283 of file BasicUtils/SessionReader.cpp.

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

◆ 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 1461 of file BasicUtils/SessionReader.cpp.

1464  {
1465  if (pFilename.size() > 3 &&
1466  pFilename.substr(pFilename.size() - 3, 3) == ".gz")
1467  {
1468  ifstream file(pFilename.c_str(),
1469  ios_base::in | ios_base::binary);
1470  ASSERTL0(file.good(), "Unable to open file: " + pFilename);
1471  stringstream ss;
1472  io::filtering_streambuf<io::input> in;
1473  in.push(io::gzip_decompressor());
1474  in.push(file);
1475  try
1476  {
1477  io::copy(in, ss);
1478  ss >> (*pDoc);
1479  }
1480  catch (io::gzip_error&)
1481  {
1483  "Error: File '" + pFilename + "' is corrupt.");
1484  }
1485  }
1486  else if (pFilename.size() > 4 &&
1487  pFilename.substr(pFilename.size() - 4, 4) == "_xml")
1488  {
1489  fs::path pdirname(pFilename);
1490  boost::format pad("P%1$07d.xml");
1491  pad % m_comm->GetRank();
1492  fs::path pRankFilename(pad.str());
1493  fs::path fullpath = pdirname / pRankFilename;
1494 
1495  ifstream file(PortablePath(fullpath).c_str());
1496  ASSERTL0(file.good(), "Unable to open file: " + fullpath.string());
1497  file >> (*pDoc);
1498  }
1499  else
1500  {
1501  ifstream file(pFilename.c_str());
1502  ASSERTL0(file.good(), "Unable to open file: " + pFilename);
1503  file >> (*pDoc);
1504  }
1505  }
def copy(self)
Definition: pycml.py:2663

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

◆ LoadGeometricInfo() [1/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 1053 of file BasicUtils/SessionReader.cpp.

1057  {
1058  std::string vName = boost::to_upper_copy(pName);
1059  auto iter = m_geometricInfo.find(vName);
1060  if(iter != m_geometricInfo.end())
1061  {
1062  if (iter->second == "TRUE")
1063  {
1064  pVar = true;
1065  }
1066  else
1067  {
1068  pVar = false;
1069  }
1070  }
1071  else
1072  {
1073  pVar = pDefault;
1074  }
1075  }

◆ LoadGeometricInfo() [2/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 1081 of file BasicUtils/SessionReader.cpp.

1085  {
1086  std::string vName = boost::to_upper_copy(pName);
1087  auto iter = m_geometricInfo.find(vName);
1088  if(iter != m_geometricInfo.end())
1089  {
1090  pVar = std::atoi(iter->second.c_str());
1091  }
1092  else
1093  {
1094  pVar = pDefault;
1095  }
1096  }

◆ LoadGeometricInfo() [3/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 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  pVar = iter->second;
1042  }
1043  else
1044  {
1045  pVar = pDefault;
1046  }
1047  }

◆ LoadParameter() [1/4]

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

Load an integer parameter.

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

735  {
736  std::string vName = boost::to_upper_copy(pName);
737  auto paramIter = m_parameters.find(vName);
738  ASSERTL0(paramIter != m_parameters.end(), "Required parameter '" +
739  pName + "' not specified in session.");
740  NekDouble param = round(paramIter->second);
741  pVar = checked_cast<int>(param);
742  }
double NekDouble

References ASSERTL0.

◆ 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 748 of file BasicUtils/SessionReader.cpp.

750  {
751  std::string vName = boost::to_upper_copy(pName);
752  auto paramIter = m_parameters.find(vName);
753  if(paramIter != m_parameters.end())
754  {
755  NekDouble param = round(paramIter->second);
756  pVar = checked_cast<int>(param);
757  }
758  else
759  {
760  pVar = pDefault;
761  }
762  }

◆ LoadParameter() [3/4]

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

Load a double precision parameter.

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

770  {
771  std::string vName = boost::to_upper_copy(pName);
772  auto paramIter = m_parameters.find(vName);
773  ASSERTL0(paramIter != m_parameters.end(), "Required parameter '" +
774  pName + "' not specified in session.");
775  pVar = paramIter->second;
776  }

References ASSERTL0.

◆ 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 782 of file BasicUtils/SessionReader.cpp.

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

◆ 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 867 of file BasicUtils/SessionReader.cpp.

871  {
872  std::string vName = boost::to_upper_copy(pName);
873  auto infoIter = m_solverInfo.find(vName);
874  if(infoIter != m_solverInfo.end())
875  {
876  pVar = infoIter->second;
877  }
878  else
879  {
880  pVar = pDefault;
881  }
882  }

◆ 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 1102 of file BasicUtils/SessionReader.cpp.

1107  {
1108  std::string vName = boost::to_upper_copy(pName);
1109  auto iter = m_geometricInfo.find(vName);
1110  if(iter != m_geometricInfo.end())
1111  {
1112  pVar = boost::iequals(iter->second, pTrueVal);
1113  }
1114  else
1115  {
1116  pVar = pDefault;
1117  }
1118  }

◆ MatchSolverInfo() [1/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 910 of file BasicUtils/SessionReader.cpp.

913  {
914  if (DefinesSolverInfo(pName))
915  {
916  std::string vName = boost::to_upper_copy(pName);
917  auto iter = m_solverInfo.find(vName);
918  if(iter != m_solverInfo.end())
919  {
920  return boost::iequals(iter->second, pTrueVal);
921  }
922  }
923  return false;
924  }

◆ MatchSolverInfo() [2/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 888 of file BasicUtils/SessionReader.cpp.

893  {
894  std::string vName = boost::to_upper_copy(pName);
895  auto infoIter = m_solverInfo.find(vName);
896  if(infoIter != m_solverInfo.end())
897  {
898  pVar = boost::iequals(infoIter->second, pTrueVal);
899  }
900  else
901  {
902  pVar = pDefault;
903  }
904  }

◆ 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 545 of file SessionReader.h.

547  {
548  return (GetSolverInfoAsEnum<T>(name) == trueval);
549  }

References CellMLToNektar.pycml::name.

◆ 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 1510 of file BasicUtils/SessionReader.cpp.

1512  {
1513  ASSERTL0(pFilenames.size() > 0, "No filenames for merging.");
1514 
1515  // Read the first document
1516  TiXmlDocument *vMainDoc = new TiXmlDocument;
1517  LoadDoc(pFilenames[0], vMainDoc);
1518 
1519  TiXmlHandle vMainHandle(vMainDoc);
1520  TiXmlElement* vMainNektar =
1521  vMainHandle.FirstChildElement("NEKTAR").Element();
1522 
1523  // Read all subsequent XML documents.
1524  // For each element within the NEKTAR tag, use it to replace the
1525  // version already present in the loaded XML data.
1526  for (int i = 1; i < pFilenames.size(); ++i)
1527  {
1528  if((pFilenames[i].compare(pFilenames[i].size()-3,3,"xml") == 0)
1529  ||(pFilenames[i].compare(pFilenames[i].size()-6,6,"xml.gz") == 0))
1530  {
1531  TiXmlDocument* vTempDoc = new TiXmlDocument;
1532  LoadDoc(pFilenames[i], vTempDoc);
1533 
1534  TiXmlHandle docHandle(vTempDoc);
1535  TiXmlElement* vTempNektar;
1536  vTempNektar = docHandle.FirstChildElement("NEKTAR").Element();
1537  ASSERTL0(vTempNektar, "Unable to find NEKTAR tag in file.");
1538  TiXmlElement* p = vTempNektar->FirstChildElement();
1539 
1540  while (p)
1541  {
1542  TiXmlElement *vMainEntry =
1543  vMainNektar->FirstChildElement(p->Value());
1544 
1545  // First check if the new item is in fact blank
1546  if (!p->FirstChild() && vMainEntry)
1547  {
1548  std::string warningmsg =
1549  "File " + pFilenames[i] + " contains " +
1550  "an empty XML element " +
1551  std::string(p->Value()) +
1552  " which will be ignored.";
1553  NEKERROR(ErrorUtil::ewarning, warningmsg.c_str());
1554  }
1555  else
1556  {
1557  if (vMainEntry)
1558  {
1559  vMainNektar->RemoveChild(vMainEntry);
1560  }
1561  TiXmlElement *q = new TiXmlElement(*p);
1562  vMainNektar->LinkEndChild(q);
1563  }
1564  p = p->NextSiblingElement();
1565  }
1566 
1567  delete vTempDoc;
1568  }
1569  }
1570  return vMainDoc;
1571  }
void LoadDoc(const std::string &pFilename, TiXmlDocument *pDoc) const
Loads an xml file into a tinyxml doc and decompresses if needed.

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

◆ 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 377 of file BasicUtils/SessionReader.cpp.

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

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

◆ ParseDocument()

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

Loads and parses the specified file.

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

1578  {
1579  // Check we actually have a document loaded.
1580  ASSERTL0(m_xmlDoc, "No XML document loaded.");
1581 
1582  // Look for all data in CONDITIONS block.
1583  TiXmlHandle docHandle(m_xmlDoc);
1584  TiXmlElement* e;
1585  e = docHandle.FirstChildElement("NEKTAR").
1586  FirstChildElement("CONDITIONS").Element();
1587 
1588  // Read the various sections of the CONDITIONS block
1589  ReadParameters (e);
1590  ReadSolverInfo (e);
1592  ReadTimeIntScheme (e);
1593  ReadExpressions (e);
1594  ReadVariables (e);
1595  ReadFunctions (e);
1596 
1597  e = docHandle.FirstChildElement("NEKTAR").
1598  FirstChildElement("FILTERS").Element();
1599 
1600  ReadFilters(e);
1601  }
void ReadSolverInfo(TiXmlElement *conditions)
Reads the SOLVERINFO section of the XML document.
void ReadVariables(TiXmlElement *conditions)
Reads the VARIABLES section of the XML document.
void ReadTimeIntScheme(TiXmlElement *conditions)
Reads the TIMEINTEGRATIONSCHEME section of the XML document.
void ReadFilters(TiXmlElement *filters)
Reads the FILTERS section of the XML document.
void ReadGlobalSysSolnInfo(TiXmlElement *conditions)
Reads the GLOBALSYSSOLNINFO section of the XML document.
void ReadFunctions(TiXmlElement *conditions)
Reads the FUNCTIONS section of the XML document.
void ReadParameters(TiXmlElement *conditions)
Reads the PARAMETERS section of the XML document.
void ReadExpressions(TiXmlElement *conditions)
Reads the EXPRESSIONS section of the XML document.

References ASSERTL0.

◆ 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 2458 of file BasicUtils/SessionReader.cpp.

2462  {
2463  /// Pull out lhs and rhs and eliminate any spaces.
2464  size_t beg = line.find_first_not_of(" ");
2465  size_t end = line.find_first_of("=");
2466  // Check for no parameter name
2467  if (beg == end) throw 1;
2468  // Check for no parameter value
2469  if (end != line.find_last_of("=")) throw 1;
2470  // Check for no equals sign
2471  if (end == std::string::npos) throw 1;
2472 
2473  lhs = line.substr(line.find_first_not_of(" "),
2474  end-beg);
2475  lhs = lhs .substr(0, lhs.find_last_not_of(" ")+1);
2476  rhs = line.substr(line.find_last_of("=")+1);
2477  rhs = rhs .substr(rhs.find_first_not_of(" "));
2478  rhs = rhs .substr(0, rhs.find_last_not_of(" ")+1);
2479  }

◆ ParseSessionName()

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

Parse the session name.

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

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

References ASSERTL0.

◆ 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 1638 of file BasicUtils/SessionReader.cpp.

1639  {
1640  if (m_comm->GetSize() > 1)
1641  {
1642  int nProcZ = 1;
1643  int nProcY = 1;
1644  int nProcX = 1;
1645  int nStripZ = 1;
1646  if (DefinesCmdLineArgument("npx")) {
1647  nProcX = GetCmdLineArgument<int>("npx");
1648  }
1649  if (DefinesCmdLineArgument("npy")) {
1650  nProcY = GetCmdLineArgument<int>("npy");
1651  }
1652  if (DefinesCmdLineArgument("npz")) {
1653  nProcZ = GetCmdLineArgument<int>("npz");
1654  }
1655  if (DefinesCmdLineArgument("nsz")) {
1656  nStripZ = GetCmdLineArgument<int>("nsz");
1657  }
1658  ASSERTL0(m_comm->GetSize() % (nProcZ*nProcY*nProcX) == 0,
1659  "Cannot exactly partition using PROC_Z value.");
1660  ASSERTL0(nProcZ % nProcY == 0,
1661  "Cannot exactly partition using PROC_Y value.");
1662  ASSERTL0(nProcY % nProcX == 0,
1663  "Cannot exactly partition using PROC_X value.");
1664 
1665  // Number of processes associated with the spectral method
1666  int nProcSm = nProcZ * nProcY * nProcX;
1667 
1668  // Number of processes associated with the spectral element
1669  // method.
1670  int nProcSem = m_comm->GetSize() / nProcSm;
1671 
1672  m_comm->SplitComm(nProcSm,nProcSem);
1673  m_comm->GetColumnComm()->SplitComm(nProcZ/nStripZ,nStripZ);
1674  m_comm->GetColumnComm()->GetColumnComm()->SplitComm(
1675  (nProcY*nProcX),nProcZ/nStripZ);
1676  m_comm->GetColumnComm()->GetColumnComm()->GetColumnComm()
1677  ->SplitComm(nProcX,nProcY);
1678  }
1679  }
bool DefinesCmdLineArgument(const std::string &pName) const
Checks if a specified cmdline argument has been given.

References ASSERTL0.

◆ ReadExpressions()

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

Reads the EXPRESSIONS section of the XML document.

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

2076  {
2077  m_expressions.clear();
2078 
2079  if (!conditions)
2080  {
2081  return;
2082  }
2083 
2084  TiXmlElement *expressionsElement =
2085  conditions->FirstChildElement("EXPRESSIONS");
2086 
2087  if (expressionsElement)
2088  {
2089  TiXmlElement *expr = expressionsElement->FirstChildElement("E");
2090 
2091  while (expr)
2092  {
2093  stringstream tagcontent;
2094  tagcontent << *expr;
2095  ASSERTL0(expr->Attribute("NAME"),
2096  "Missing NAME attribute in expression "
2097  "definition: \n\t'" + tagcontent.str() + "'");
2098  std::string nameString = expr->Attribute("NAME");
2099  ASSERTL0(!nameString.empty(),
2100  "Expressions must have a non-empty name: \n\t'"
2101  + tagcontent.str() + "'");
2102 
2103  ASSERTL0(expr->Attribute("VALUE"),
2104  "Missing VALUE attribute in expression "
2105  "definition: \n\t'" + tagcontent.str() + "'");
2106  std::string valString = expr->Attribute("VALUE");
2107  ASSERTL0(!valString.empty(),
2108  "Expressions must have a non-empty value: \n\t'"
2109  + tagcontent.str() + "'");
2110 
2111  auto exprIter = m_expressions.find(nameString);
2112  ASSERTL0(exprIter == m_expressions.end(),
2113  std::string("Expression '") + nameString
2114  + std::string("' already specified."));
2115 
2116  m_expressions[nameString] = valString;
2117  expr = expr->NextSiblingElement("E");
2118  }
2119  }
2120  }
ExpressionMap m_expressions
Expressions.

References ASSERTL0.

◆ ReadFilters()

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

Reads the FILTERS section of the XML document.

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

2418  {
2419  if (!filters)
2420  {
2421  return;
2422  }
2423 
2424  m_filters.clear();
2425 
2426  TiXmlElement *filter = filters->FirstChildElement("FILTER");
2427  while (filter)
2428  {
2429  ASSERTL0(filter->Attribute("TYPE"),
2430  "Missing attribute 'TYPE' for filter.");
2431  std::string typeStr = filter->Attribute("TYPE");
2432 
2433  std::map<std::string, std::string> vParams;
2434 
2435  TiXmlElement *param = filter->FirstChildElement("PARAM");
2436  while (param)
2437  {
2438  ASSERTL0(param->Attribute("NAME"),
2439  "Missing attribute 'NAME' for parameter in filter "
2440  + typeStr + "'.");
2441  std::string nameStr = param->Attribute("NAME");
2442 
2443  ASSERTL0(param->GetText(), "Empty value string for param.");
2444  std::string valueStr = param->GetText();
2445 
2446  vParams[nameStr] = valueStr;
2447 
2448  param = param->NextSiblingElement("PARAM");
2449  }
2450 
2451  m_filters.push_back(
2452  std::pair<std::string, FilterParams>(typeStr, vParams));
2453 
2454  filter = filter->NextSiblingElement("FILTER");
2455  }
2456  }

References ASSERTL0.

◆ ReadFunctions()

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

Reads the FUNCTIONS section of the XML document.

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

2210  {
2211  m_functions.clear();
2212 
2213  if (!conditions)
2214  {
2215  return;
2216  }
2217 
2218  // Scan through conditions section looking for functions.
2219  TiXmlElement *function = conditions->FirstChildElement("FUNCTION");
2220  while (function)
2221  {
2222  stringstream tagcontent;
2223  tagcontent << *function;
2224 
2225  // Every function must have a NAME attribute
2226  ASSERTL0(function->Attribute("NAME"),
2227  "Functions must have a NAME attribute defined in XML "
2228  "element: \n\t'" + tagcontent.str() + "'");
2229  std::string functionStr = function->Attribute("NAME");
2230  ASSERTL0(!functionStr.empty(),
2231  "Functions must have a non-empty name in XML "
2232  "element: \n\t'" + tagcontent.str() + "'");
2233 
2234  // Store function names in uppercase to remain case-insensitive.
2235  boost::to_upper(functionStr);
2236 
2237  // Retrieve first entry (variable, or file)
2238  TiXmlElement *variable = function->FirstChildElement();
2239 
2240  // Create new function structure with default type of none.
2241  FunctionVariableMap functionVarMap;
2242 
2243  // Process all entries in the function block
2244  while (variable)
2245  {
2246  FunctionVariableDefinition funcDef;
2247  std::string conditionType = variable->Value();
2248 
2249  // If no var is specified, assume wildcard
2250  std::string variableStr;
2251  if (!variable->Attribute("VAR"))
2252  {
2253  variableStr = "*";
2254  }
2255  else
2256  {
2257  variableStr = variable->Attribute("VAR");
2258  }
2259 
2260  // Parse list of variables
2261  std::vector<std::string> variableList;
2262  ParseUtils::GenerateVector(variableStr, variableList);
2263 
2264  // If no domain string put to 0
2265  std::string domainStr;
2266  if (!variable->Attribute("DOMAIN"))
2267  {
2268  domainStr = "0";
2269  }
2270  else
2271  {
2272  domainStr = variable->Attribute("DOMAIN");
2273  }
2274 
2275  // If no domain string put to 0
2276  std::string evarsStr = "x y z t";
2277  if (variable->Attribute("EVARS"))
2278  {
2279  evarsStr = evarsStr + std::string(" ") + variable->Attribute("EVARS");
2280  }
2281 
2282  // Parse list of variables
2283  std::vector<std::string> varSplit;
2284  std::vector<unsigned int> domainList;
2285  ParseUtils::GenerateSeqVector(domainStr, domainList);
2286 
2287  // Expressions are denoted by E
2288  if (conditionType == "E")
2289  {
2290  funcDef.m_type = eFunctionTypeExpression;
2291 
2292  // Expression must have a VALUE.
2293  ASSERTL0(variable->Attribute("VALUE"),
2294  "Attribute VALUE expected for function '"
2295  + functionStr + "'.");
2296  std::string fcnStr = variable->Attribute("VALUE");
2297 
2298  ASSERTL0(!fcnStr.empty(),
2299  (std::string("Expression for var: ")
2300  + variableStr
2301  + std::string(" must be specified.")).c_str());
2302 
2303  SubstituteExpressions(fcnStr);
2304 
2305  // set expression
2306  funcDef.m_expression = MemoryManager<Equation>
2307  ::AllocateSharedPtr(m_interpreter, fcnStr, evarsStr);
2308  }
2309 
2310  // Files are denoted by F
2311  else if (conditionType == "F")
2312  {
2313  if (variable->Attribute("TIMEDEPENDENT") &&
2314  boost::lexical_cast<bool>(variable->Attribute("TIMEDEPENDENT")))
2315  {
2316  funcDef.m_type = eFunctionTypeTransientFile;
2317  }
2318  else
2319  {
2320  funcDef.m_type = eFunctionTypeFile;
2321  }
2322 
2323  // File must have a FILE.
2324  ASSERTL0(variable->Attribute("FILE"),
2325  "Attribute FILE expected for function '"
2326  + functionStr + "'.");
2327  std::string filenameStr = variable->Attribute("FILE");
2328 
2329  ASSERTL0(!filenameStr.empty(),
2330  "A filename must be specified for the FILE "
2331  "attribute of function '" + functionStr
2332  + "'.");
2333 
2334  std::vector<std::string> fSplit;
2335  boost::split(fSplit, filenameStr, boost::is_any_of(":"));
2336 
2337  ASSERTL0(fSplit.size() == 1 || fSplit.size() == 2,
2338  "Incorrect filename specification in function "
2339  + functionStr + "'. "
2340  "Specify variables inside file as: "
2341  "filename:var1,var2");
2342 
2343  // set the filename
2344  funcDef.m_filename = fSplit[0];
2345 
2346  if (fSplit.size() == 2)
2347  {
2348  ASSERTL0(variableList[0] != "*",
2349  "Filename variable mapping not valid "
2350  "when using * as a variable inside "
2351  "function '" + functionStr + "'.");
2352 
2353  boost::split(
2354  varSplit, fSplit[1], boost::is_any_of(","));
2355  ASSERTL0(varSplit.size() == variableList.size(),
2356  "Filename variables should contain the "
2357  "same number of variables defined in "
2358  "VAR in function " + functionStr + "'.");
2359  }
2360  }
2361 
2362  // Nothing else supported so throw an error
2363  else
2364  {
2365  stringstream tagcontent;
2366  tagcontent << *variable;
2367 
2369  "Identifier " + conditionType + " in function "
2370  + std::string(function->Attribute("NAME"))
2371  + " is not recognised in XML element: \n\t'"
2372  + tagcontent.str() + "'");
2373  }
2374 
2375 
2376 
2377  // Add variables to function
2378  for (unsigned int i = 0; i < variableList.size(); ++i)
2379  {
2380  for(unsigned int j = 0; j < domainList.size(); ++j)
2381  {
2382  // Check it has not already been defined
2383  pair<std::string,int> key(variableList[i],domainList[j]);
2384  auto fcnsIter = functionVarMap.find(key);
2385  ASSERTL0(fcnsIter == functionVarMap.end(),
2386  "Error setting expression '" + variableList[i]
2387  + " in domain "
2388  + boost::lexical_cast<std::string>(domainList[j])
2389  + "' in function '" + functionStr + "'. "
2390  "Expression has already been defined.");
2391 
2392  if (varSplit.size() > 0)
2393  {
2394  FunctionVariableDefinition funcDef2 = funcDef;
2395  funcDef2.m_fileVariable = varSplit[i];
2396  functionVarMap[key] = funcDef2;
2397  }
2398  else
2399  {
2400  functionVarMap[key] = funcDef;
2401  }
2402  }
2403  }
2404 
2405  variable = variable->NextSiblingElement();
2406  }
2407  // Add function definition to map
2408  m_functions[functionStr] = functionVarMap;
2409  function = function->NextSiblingElement("FUNCTION");
2410  }
2411  }
void SubstituteExpressions(std::string &expr)
Substitutes expressions defined in the XML document.
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
std::map< std::pair< std::string, int >, FunctionVariableDefinition > FunctionVariableMap

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.

◆ ReadGlobalSysSolnInfo()

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

Reads the GLOBALSYSSOLNINFO section of the XML document.

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

1846  {
1847  GetGloSysSolnList().clear();
1848 
1849  if (!conditions)
1850  {
1851  return;
1852  }
1853 
1854  TiXmlElement *GlobalSys =
1855  conditions->FirstChildElement("GLOBALSYSSOLNINFO");
1856 
1857  if(!GlobalSys)
1858  {
1859  return;
1860  }
1861 
1862  TiXmlElement *VarInfo = GlobalSys->FirstChildElement("V");
1863 
1864  while (VarInfo)
1865  {
1866  std::stringstream tagcontent;
1867  tagcontent << *VarInfo;
1868  ASSERTL0(VarInfo->Attribute("VAR"),
1869  "Missing VAR attribute in GobalSysSolnInfo XML "
1870  "element: \n\t'" + tagcontent.str() + "'");
1871 
1872  std::string VarList = VarInfo->Attribute("VAR");
1873  ASSERTL0(!VarList.empty(),
1874  "VAR attribute must be non-empty in XML element:\n\t'"
1875  + tagcontent.str() + "'");
1876 
1877  // generate a list of variables.
1878  std::vector<std::string> varStrings;
1879  bool valid = ParseUtils::GenerateVector(VarList, varStrings);
1880 
1881  ASSERTL0(valid,"Unable to process list of variable in XML "
1882  "element \n\t'" + tagcontent.str() + "'");
1883 
1884  if(varStrings.size())
1885  {
1886  TiXmlElement *SysSolnInfo = VarInfo->FirstChildElement("I");
1887 
1888  while (SysSolnInfo)
1889  {
1890  tagcontent.clear();
1891  tagcontent << *SysSolnInfo;
1892  // read the property name
1893  ASSERTL0(SysSolnInfo->Attribute("PROPERTY"),
1894  "Missing PROPERTY attribute in "
1895  "GlobalSysSolnInfo for variable(s) '"
1896  + VarList + "' in XML element: \n\t'"
1897  + tagcontent.str() + "'");
1898 
1899  std::string SysSolnProperty =
1900  SysSolnInfo->Attribute("PROPERTY");
1901 
1902  ASSERTL0(!SysSolnProperty.empty(),
1903  "GlobalSysSolnIno properties must have a "
1904  "non-empty name for variable(s) : '"
1905  + VarList + "' in XML element: \n\t'"
1906  + tagcontent.str() + "'");
1907 
1908  // make sure that solver property is capitalised
1909  std::string SysSolnPropertyUpper =
1910  boost::to_upper_copy(SysSolnProperty);
1911 
1912  // read the value
1913  ASSERTL0(SysSolnInfo->Attribute("VALUE"),
1914  "Missing VALUE attribute in GlobalSysSolnInfo "
1915  "for variable(s) '" + VarList
1916  + "' in XML element: \n\t"
1917  + tagcontent.str() + "'");
1918 
1919  std::string SysSolnValue =
1920  SysSolnInfo->Attribute("VALUE");
1921  ASSERTL0(!SysSolnValue.empty(),
1922  "GlobalSysSolnInfo properties must have a "
1923  "non-empty value for variable(s) '"
1924  + VarList + "' in XML element: \n\t'"
1925  + tagcontent.str() + "'");
1926 
1927  // Store values under variable map.
1928  for(int i = 0; i < varStrings.size(); ++i)
1929  {
1930  auto x = GetGloSysSolnList().find(varStrings[i]);
1931  if (x == GetGloSysSolnList().end())
1932  {
1933  (GetGloSysSolnList()[varStrings[i]])[
1934  SysSolnPropertyUpper] = SysSolnValue;
1935  }
1936  else
1937  {
1938  x->second[SysSolnPropertyUpper] = SysSolnValue;
1939  }
1940  }
1941 
1942  SysSolnInfo = SysSolnInfo->NextSiblingElement("I");
1943  }
1944  VarInfo = VarInfo->NextSiblingElement("V");
1945  }
1946  }
1947 
1948  if (m_verbose && GetGloSysSolnList().size() > 0 && m_comm)
1949  {
1950  if(m_comm->GetRank() == 0)
1951  {
1952  cout << "GlobalSysSoln Info:" << endl;
1953 
1954  for (auto &x : GetGloSysSolnList())
1955  {
1956  cout << "\t Variable: " << x.first << endl;
1957 
1958  for (auto &y : x.second)
1959  {
1960  cout << "\t\t " << y.first << " = " << y.second
1961  << endl;
1962  }
1963  }
1964  cout << endl;
1965  }
1966  }
1967  }

References ASSERTL0.

◆ ReadParameters()

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

Reads the PARAMETERS section of the XML document.

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

1686  {
1687  m_parameters.clear();
1688 
1689  if (!conditions)
1690  {
1691  return;
1692  }
1693 
1694  TiXmlElement *parametersElement = conditions->FirstChildElement(
1695  "PARAMETERS");
1696 
1697  // See if we have parameters defined. They are optional so we go on
1698  // if not.
1699  if (parametersElement)
1700  {
1701  TiXmlElement *parameter =
1702  parametersElement->FirstChildElement("P");
1703 
1704  ParameterMap caseSensitiveParameters;
1705 
1706  // Multiple nodes will only occur if there is a comment in
1707  // between definitions.
1708  while (parameter)
1709  {
1710  stringstream tagcontent;
1711  tagcontent << *parameter;
1712  TiXmlNode *node = parameter->FirstChild();
1713 
1714  while (node && node->Type() != TiXmlNode::TINYXML_TEXT)
1715  {
1716  node = node->NextSibling();
1717  }
1718 
1719  if (node)
1720  {
1721  // Format is "paramName = value"
1722  std::string line = node->ToText()->Value(), lhs, rhs;
1723 
1724  try {
1725  ParseEquals(line, lhs, rhs);
1726  }
1727  catch (...)
1728  {
1730  "Syntax error in parameter expression '"
1731  + line + "' in XML element: \n\t'"
1732  + tagcontent.str() + "'");
1733  }
1734 
1735  // We want the list of parameters to have their RHS
1736  // evaluated, so we use the expression evaluator to do
1737  // the dirty work.
1738  if (!lhs.empty() && !rhs.empty())
1739  {
1740  NekDouble value=0.0;
1741  try
1742  {
1743  LibUtilities::Equation expession(
1744  m_interpreter, rhs);
1745  value = expession.Evaluate();
1746  }
1747  catch (const std::runtime_error &)
1748  {
1750  "Error evaluating parameter expression"
1751  " '" + rhs + "' in XML element: \n\t'"
1752  + tagcontent.str() + "'");
1753  }
1754  m_interpreter->SetParameter(lhs, value);
1755  caseSensitiveParameters[lhs] = value;
1756  boost::to_upper(lhs);
1757  m_parameters[lhs] = value;
1758  }
1759  }
1760 
1761  parameter = parameter->NextSiblingElement();
1762  }
1763  }
1764  }
std::map< std::string, NekDouble > ParameterMap
Definition: SessionReader.h:58

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

◆ ReadSolverInfo()

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

Reads the SOLVERINFO section of the XML document.

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

1771  {
1772  m_solverInfo.clear();
1774 
1775  if (!conditions)
1776  {
1777  return;
1778  }
1779 
1780  TiXmlElement *solverInfoElement =
1781  conditions->FirstChildElement("SOLVERINFO");
1782 
1783  if (solverInfoElement)
1784  {
1785  TiXmlElement *solverInfo =
1786  solverInfoElement->FirstChildElement("I");
1787 
1788  while (solverInfo)
1789  {
1790  std::stringstream tagcontent;
1791  tagcontent << *solverInfo;
1792  // read the property name
1793  ASSERTL0(solverInfo->Attribute("PROPERTY"),
1794  "Missing PROPERTY attribute in solver info "
1795  "XML element: \n\t'" + tagcontent.str() + "'");
1796  std::string solverProperty =
1797  solverInfo->Attribute("PROPERTY");
1798  ASSERTL0(!solverProperty.empty(),
1799  "PROPERTY attribute must be non-empty in XML "
1800  "element: \n\t'" + tagcontent.str() + "'");
1801 
1802  // make sure that solver property is capitalised
1803  std::string solverPropertyUpper =
1804  boost::to_upper_copy(solverProperty);
1805 
1806  // read the value
1807  ASSERTL0(solverInfo->Attribute("VALUE"),
1808  "Missing VALUE attribute in solver info "
1809  "XML element: \n\t'" + tagcontent.str() + "'");
1810  std::string solverValue = solverInfo->Attribute("VALUE");
1811  ASSERTL0(!solverValue.empty(),
1812  "VALUE attribute must be non-empty in XML "
1813  "element: \n\t'" + tagcontent.str() + "'");
1814 
1815  // Set Variable
1816  m_solverInfo[solverPropertyUpper] = solverValue;
1817  solverInfo = solverInfo->NextSiblingElement("I");
1818  }
1819  }
1820 
1821  if (m_comm && m_comm->GetRowComm()->GetSize() > 1)
1822  {
1823  ASSERTL0(
1824  m_solverInfo["GLOBALSYSSOLN"] == "IterativeFull" ||
1825  m_solverInfo["GLOBALSYSSOLN"] == "IterativeStaticCond" ||
1826  m_solverInfo["GLOBALSYSSOLN"] ==
1827  "IterativeMultiLevelStaticCond" ||
1828  m_solverInfo["GLOBALSYSSOLN"] == "XxtFull" ||
1829  m_solverInfo["GLOBALSYSSOLN"] == "XxtStaticCond" ||
1830  m_solverInfo["GLOBALSYSSOLN"] ==
1831  "XxtMultiLevelStaticCond" ||
1832  m_solverInfo["GLOBALSYSSOLN"] == "PETScFull" ||
1833  m_solverInfo["GLOBALSYSSOLN"] == "PETScStaticCond" ||
1834  m_solverInfo["GLOBALSYSSOLN"] ==
1835  "PETScMultiLevelStaticCond",
1836  "A parallel solver must be used when run in parallel.");
1837  }
1838  }

References ASSERTL0.

◆ ReadTimeIntScheme()

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

Reads the TIMEINTEGRATIONSCHEME section of the XML document.

Read the time-integration scheme structure, if present.

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

1973  {
1974  if (!conditions)
1975  {
1976  return;
1977  }
1978 
1979  TiXmlElement *timeInt = conditions->FirstChildElement(
1980  "TIMEINTEGRATIONSCHEME");
1981 
1982  if (!timeInt)
1983  {
1984  return;
1985  }
1986 
1987  TiXmlElement *method = timeInt->FirstChildElement("METHOD");
1988  TiXmlElement *variant = timeInt->FirstChildElement("VARIANT");
1989  TiXmlElement *order = timeInt->FirstChildElement("ORDER");
1990  TiXmlElement *params = timeInt->FirstChildElement("FREEPARAMETERS");
1991 
1992  // Only the method and order are required.
1993  ASSERTL0(method, "Missing METHOD tag inside "
1994  "TIMEINTEGRATIONSCHEME.");
1995  ASSERTL0(order, "Missing ORDER tag inside "
1996  "TIMEINTEGRATIONSCHEME.");
1997 
1998  m_timeIntScheme.method = method->GetText();
1999 
2000  std::string orderStr = order->GetText();
2001 
2002  // Only the method and order are required.
2003  ASSERTL0(m_timeIntScheme.method.size() > 0,
2004  "Empty text inside METHOD tag in TIMEINTEGRATIONSCHEME.");
2005  ASSERTL0(orderStr.size() > 0,
2006  "Empty text inside ORDER tag in TIMEINTEGRATIONSCHEME.");
2007  try
2008  {
2009  m_timeIntScheme.order = boost::lexical_cast<unsigned int>(
2010  orderStr);
2011  }
2012  catch(...)
2013  {
2014  NEKERROR(ErrorUtil::efatal, "In ORDER tag, unable to convert "
2015  "string '" + orderStr + "' to an unsigned integer.");
2016  }
2017 
2018  if (variant)
2019  {
2020  m_timeIntScheme.variant = variant->GetText();
2021  }
2022 
2023  if (params)
2024  {
2025  std::string paramsStr = params->GetText();
2026  ASSERTL0(paramsStr.size() > 0,
2027  "Empty text inside FREEPARAMETERS tag in "
2028  "TIMEINTEGRATIONSCHEME.");
2029 
2030  std::vector<std::string> pSplit;
2031  boost::split(pSplit, paramsStr, boost::is_any_of(" "));
2032 
2033  m_timeIntScheme.freeParams.resize(pSplit.size());
2034  for (size_t i = 0; i < pSplit.size(); ++i)
2035  {
2036  try
2037  {
2038  m_timeIntScheme.freeParams[i] = boost::lexical_cast<
2039  NekDouble>(pSplit[i]);
2040  }
2041  catch (...)
2042  {
2043  NEKERROR(ErrorUtil::efatal, "In FREEPARAMETERS tag, "
2044  "unable to convert string '" + pSplit[i] + "' "
2045  "to a floating-point value.");
2046  }
2047  }
2048  }
2049 
2050  if (m_verbose && m_comm)
2051  {
2052  if (m_comm->GetRank() == 0)
2053  {
2054  cout << "Trying to use time integration scheme:" << endl;
2055  cout << "\t Method : " << m_timeIntScheme.method << endl;
2056  cout << "\t Variant: " << m_timeIntScheme.variant << endl;
2057  cout << "\t Order : " << m_timeIntScheme.order << endl;
2058 
2059  if (m_timeIntScheme.freeParams.size() > 0)
2060  {
2061  cout << "\t Params :";
2062  for (auto &x : m_timeIntScheme.freeParams)
2063  {
2064  cout << " " << x;
2065  }
2066  cout << endl;
2067  }
2068  }
2069  }
2070  }
std::vector< NekDouble > freeParams
Definition: SessionReader.h:90

References ASSERTL0, and NEKERROR.

◆ 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 2126 of file BasicUtils/SessionReader.cpp.

2127  {
2128  m_variables.clear();
2129 
2130  if (!conditions)
2131  {
2132  return;
2133  }
2134 
2135  TiXmlElement *variablesElement =
2136  conditions->FirstChildElement("VARIABLES");
2137 
2138  // See if we have parameters defined. They are optional so we go on
2139  // if not.
2140  if (variablesElement)
2141  {
2142  TiXmlElement *varElement =
2143  variablesElement->FirstChildElement("V");
2144 
2145  // Sequential counter for the composite numbers.
2146  int nextVariableNumber = -1;
2147 
2148  while (varElement)
2149  {
2150  stringstream tagcontent;
2151  tagcontent << *varElement;
2152 
2153  /// All elements are of the form: "<V ID="#"> name = value
2154  /// </V>", with ? being the element type.
2155  nextVariableNumber++;
2156 
2157  int i;
2158  int err = varElement->QueryIntAttribute("ID", &i);
2159  ASSERTL0(err == TIXML_SUCCESS,
2160  "Variables must have a unique ID number attribute "
2161  "in XML element: \n\t'" + tagcontent.str() + "'");
2162  ASSERTL0(i == nextVariableNumber,
2163  "ID numbers for variables must begin with zero and"
2164  " be sequential in XML element: \n\t'"
2165  + tagcontent.str() + "'");
2166 
2167  TiXmlNode* varChild = varElement->FirstChild();
2168  // This is primarily to skip comments that may be present.
2169  // Comments appear as nodes just like elements. We are
2170  // specifically looking for text in the body of the
2171  // definition.
2172  while(varChild && varChild->Type() != TiXmlNode::TINYXML_TEXT)
2173  {
2174  varChild = varChild->NextSibling();
2175  }
2176 
2177  ASSERTL0(varChild,
2178  "Unable to read variable definition body for "
2179  "variable with ID "
2180  + boost::lexical_cast<string>(i)
2181  + " in XML element: \n\t'"
2182  + tagcontent.str() + "'");
2183  std::string variableName = varChild->ToText()->ValueStr();
2184 
2185  std::istringstream variableStrm(variableName);
2186  variableStrm >> variableName;
2187 
2188  ASSERTL0(std::find(m_variables.begin(), m_variables.end(),
2189  variableName) == m_variables.end(),
2190  "Variable with ID "
2191  + boost::lexical_cast<string>(i)
2192  + " in XML element \n\t'" + tagcontent.str()
2193  + "'\nhas already been defined.");
2194 
2195  m_variables.push_back(variableName);
2196 
2197  varElement = varElement->NextSiblingElement("V");
2198  }
2199 
2200  ASSERTL0(nextVariableNumber > -1,
2201  "Number of variables must be greater than zero.");
2202  }
2203  }
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:362

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

◆ 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 672 of file SessionReader.h.

676  {
677  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
678  CmdLineArg x;
679  x.shortName = pShortName;
680  x.description = pDescription;
681  x.isFlag = false;
682  GetCmdLineArgMap()[pName] = x;
683  return pName;
684  }

References ASSERTL0, Nektar::LibUtilities::CmdLineArg::description, GetCmdLineArgMap(), Nektar::LibUtilities::CmdLineArg::isFlag, and Nektar::LibUtilities::CmdLineArg::shortName.

◆ 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 690 of file SessionReader.h.

694  {
695  ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
696  CmdLineArg x;
697  x.shortName = pShortName;
698  x.description = pDescription;
699  x.isFlag = true;
700  GetCmdLineArgMap()[pName] = x;
701  return pName;
702  }

References ASSERTL0, Nektar::LibUtilities::CmdLineArg::description, GetCmdLineArgMap(), Nektar::LibUtilities::CmdLineArg::isFlag, and Nektar::LibUtilities::CmdLineArg::shortName.

◆ 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");
static std::string RegisterDefaultSolverInfo(const std::string &pName, const std::string &pValue)
Registers the default string value of a solver info property.
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 659 of file SessionReader.h.

662  {
663  std::string vName = boost::to_upper_copy(pName);
664  GetSolverInfoDefaults()[vName] = pValue;
665  return pValue;
666  }

References GetSolverInfoDefaults().

◆ 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:

std::string GlobalLinSys::lookupIds[2] = {
"GlobalSysSoln",
"DirectFull",
"GlobalSysSoln",
"DirectStaticCond",
}
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.
static std::string lookupIds[]
Definition: GlobalLinSys.h:163
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 625 of file SessionReader.h.

627  {
628  std::string vEnum = boost::to_upper_copy(pEnum);
629  auto x = GetSolverInfoEnums().find(vEnum);
630 
631  if (x == GetSolverInfoEnums().end())
632  {
633  GetSolverInfoEnums()[vEnum] = EnumMap();
634  x = GetSolverInfoEnums().find(vEnum);
635  }
636 
637  x->second[pString] = pEnumValue;
638  return pString;
639  }
std::map< std::string, int > EnumMap
Definition: SessionReader.h:76

References GetSolverInfoEnums().

◆ SetParameter() [1/2]

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

Set an integer parameter.

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

805  {
806  std::string vName = boost::to_upper_copy(pName);
807  m_parameters[vName] = pVar;
808  }

◆ SetParameter() [2/2]

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

Set a double precision parameter.

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

816  {
817  std::string vName = boost::to_upper_copy(pName);
818  m_parameters[vName] = pVar;
819  }

◆ 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 852 of file BasicUtils/SessionReader.cpp.

854  {
855  std::string vProperty = boost::to_upper_copy(pProperty);
856  auto iter = m_solverInfo.find(vProperty);
857 
858  ASSERTL1(iter != m_solverInfo.end(),
859  "Unable to find requested property: " + pProperty);
860 
861  iter->second = pValue;
862  }

References ASSERTL1.

◆ SetTag()

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

Sets a specified tag.

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

1409  {
1410  std::string vName = boost::to_upper_copy(pName);
1411  m_tags[vName] = pValue;
1412  }

◆ SetUpXmlDoc()

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

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

2571  {
2573  }

◆ SetVariable()

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

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

1138  {
1139  ASSERTL0(idx < m_variables.size(), "Variable index out of range.");
1140  m_variables[idx] = newname;
1141  }

References ASSERTL0.

◆ SubstituteExpressions()

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

Substitutes expressions defined in the XML document.

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

1451  {
1452  for (auto &exprIter : m_expressions)
1453  {
1454  boost::replace_all(pExpr, exprIter.first, exprIter.second);
1455  }
1456  }

◆ TestSharedFilesystem()

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

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

336  {
337  m_sharedFilesystem = false;
338 
339  if (m_comm->GetSize() > 1)
340  {
341  if (m_comm->GetRank() == 0)
342  {
343  std::ofstream testfile("shared-fs-testfile");
344  testfile << "" << std::endl;
345  ASSERTL1(!testfile.fail(), "Test file creation failed");
346  testfile.close();
347  }
348  m_comm->Block();
349 
350  int exists = (bool)boost::filesystem::exists("shared-fs-testfile");
351  m_comm->AllReduce(exists, LibUtilities::ReduceSum);
352 
353  m_sharedFilesystem = (exists == m_comm->GetSize());
354 
355  if ((m_sharedFilesystem && m_comm->GetRank() == 0) ||
357  {
358  std::remove("shared-fs-testfile");
359  }
360  }
361  else
362  {
363  m_sharedFilesystem = false;
364  }
365 
366  if (m_verbose && m_comm->GetRank() == 0 && m_sharedFilesystem)
367  {
368  cout << "Shared filesystem detected" << endl;
369  }
370  }

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

◆ VerifySolverInfo()

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

Check values of solver info options are valid.

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

2552  {
2553  for (auto &x : m_solverInfo)
2554  {
2555  std::string solverProperty = x.first;
2556  std::string solverValue = x.second;
2557 
2558  auto propIt = GetSolverInfoEnums().find(solverProperty);
2559  if (propIt != GetSolverInfoEnums().end())
2560  {
2561  auto valIt = propIt->second.find(solverValue);
2562  ASSERTL0(valIt != propIt->second.end(),
2563  "Value '" + solverValue + "' is not valid for "
2564  "property '" + solverProperty + "'");
2565  }
2566  }
2567  }

References ASSERTL0.

Friends And Related Function Documentation

◆ MemoryManager< SessionReader >

friend class MemoryManager< SessionReader >
friend

Support creation through MemoryManager.

Definition at line 112 of file SessionReader.h.

Member Data Documentation

◆ m_cmdLineOptions

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

Definition at line 435 of file SessionReader.h.

Referenced by GetCmdLineArgument().

◆ m_comm

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

Communication object.

Definition at line 438 of file SessionReader.h.

◆ m_expressions

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

Expressions.

Definition at line 452 of file SessionReader.h.

◆ m_filenames

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

Filenames.

Definition at line 440 of file SessionReader.h.

◆ m_filters

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

Filters map.

Definition at line 462 of file SessionReader.h.

◆ m_functions

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

Functions.

Definition at line 456 of file SessionReader.h.

◆ m_geometricInfo

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

Geometric information properties.

Definition at line 450 of file SessionReader.h.

◆ m_interpreter

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

Interpreter instance.

Definition at line 454 of file SessionReader.h.

◆ m_parameters

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

Parameters.

Definition at line 446 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 442 of file SessionReader.h.

◆ m_sharedFilesystem

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

Running on a shared filesystem.

Definition at line 468 of file SessionReader.h.

◆ m_solverInfo

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

Solver information properties.

Definition at line 448 of file SessionReader.h.

◆ m_tags

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

Custom tags.

Definition at line 460 of file SessionReader.h.

◆ m_timeIntScheme

TimeIntScheme Nektar::LibUtilities::SessionReader::m_timeIntScheme
private

Time integration scheme information.

Definition at line 464 of file SessionReader.h.

◆ m_variables

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

Variables.

Definition at line 458 of file SessionReader.h.

◆ m_verbose

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

Be verbose.

Definition at line 466 of file SessionReader.h.

◆ m_xmlDoc

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

Pointer to the loaded XML document.

Definition at line 444 of file SessionReader.h.