Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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>

Collaboration diagram for Nektar::LibUtilities::SessionReader:
Collaboration graph
[legend]

Public Member Functions

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

Static Public Member Functions

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

Private Member Functions

 SessionReader (int argc, char *argv[])
 Main constructor.
void InitSession ()
SessionReaderSharedPtr GetSharedThisPtr ()
 Returns a shared pointer to the current object.
std::vector< std::string > ParseCommandLineArguments (int argc, char *argv[])
 Parse the program arguments and fill m_cmdLineOptions.
void LoadDoc (const std::string &pFilename, TiXmlDocument *pDoc) const
 Loads an xml file into a tinyxml doc and decompresses if needed.
TiXmlDocument * MergeDoc (const std::vector< std::string > &pFilenames) const
 Creates an XML document from a list of input files.
void ParseDocument ()
 Loads and parses the specified file.
void CreateComm (int &argc, char *argv[])
 Loads the given XML document and instantiates an appropriate communication object.
void PartitionMesh ()
 Partitions the mesh when running in parallel.
void PartitionComm ()
 Partitions the comm object based on session parameters.
void ReadParameters (TiXmlElement *conditions)
 Reads the PARAMETERS section of the XML document.
void ReadSolverInfo (TiXmlElement *conditions)
 Reads the SOLVERINFO section of the XML document.
void ReadGlobalSysSolnInfo (TiXmlElement *conditions)
 Reads the GLOBALSYSSOLNINFO section of the XML document.
void ReadGeometricInfo (TiXmlElement *geometry)
 Reads the GEOMETRICINFO section of the XML document.
void ReadExpressions (TiXmlElement *conditions)
 Reads the EXPRESSIONS section of the XML document.
void ReadVariables (TiXmlElement *conditions)
 Reads the VARIABLES section of the XML document.
void ReadFunctions (TiXmlElement *conditions)
 Reads the FUNCTIONS section of the XML document.
void ReadFilters (TiXmlElement *filters)
 Reads the FILTERS section of the XML document.
void CmdLineOverride ()
 Enforce parameters from command line arguments.
void ParseEquals (const std::string &line, std::string &lhs, std::string &rhs)
 Parse a string in the form lhs = rhs.

Static Private Member Functions

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

Private Attributes

boost::program_options::variables_map m_cmdLineOptions
CommSharedPtr m_comm
 Communication object.
std::vector< std::string > m_filenames
 Filenames.
std::string m_filename
 Filename of the loaded XML document.
std::string m_sessionName
 Session name of the loaded XML document (filename minus ext).
TiXmlDocument * m_xmlDoc
 Pointer to the loaded XML document.
ParameterMap m_parameters
 Parameters.
SolverInfoMap m_solverInfo
 Solver information properties.
GeometricInfoMap m_geometricInfo
 Geometric information properties.
ExpressionMap m_expressions
 Expressions.
AnalyticExpressionEvaluator m_exprEvaluator
 Analytic expression evaluator instance.
FunctionMap m_functions
 Functions.
VariableList m_variables
 Variables.
TagMap m_tags
 Custom tags.
FilterMap m_filters
 Filters map.
bool m_verbose
 Be verbose.
CompositeOrdering m_compOrder
 Map of original composite ordering for parallel periodic bcs.
BndRegionOrdering m_bndRegOrder
 Map of original boundary region ordering for parallel periodic bcs.

Friends

class MemoryManager< SessionReader >
 Support creation through MemoryManager.

Detailed Description

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

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

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

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

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

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

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

Definition at line 121 of file SessionReader.h.

Constructor & Destructor Documentation

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

Definition at line 212 of file SessionReader.cpp.

References ASSERTL0.

{
ASSERTL0(pFilenames.size() > 0, "No filenames specified.");
m_xmlDoc = 0;
m_filenames = pFilenames;
m_filename = pFilenames[0];
m_sessionName = m_filename.substr(0, m_filename.find_last_of('.'));
if (m_filename.size() > 3 &&
m_filename.substr(m_filename.size() - 3, 3) == ".gz")
{
m_sessionName.substr(0, m_sessionName.find_last_of('.'));
}
// Create communicator
if (!pComm.get())
{
CreateComm(argc, argv);
}
else
{
m_comm = pComm;
if (m_comm->GetSize() > 1)
{
GetSolverInfoDefaults()["GLOBALSYSSOLN"] =
"IterativeStaticCond";
}
}
// If running in parallel change the default global sys solution
// type.
if (m_comm->GetSize() > 1)
{
GetSolverInfoDefaults()["GLOBALSYSSOLN"] =
"IterativeStaticCond";
}
}
Nektar::LibUtilities::SessionReader::~SessionReader ( )

Destructor.

Definition at line 262 of file SessionReader.cpp.

{
delete m_xmlDoc;
}
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 180 of file SessionReader.cpp.

References ASSERTL0.

{
m_xmlDoc = 0;
ASSERTL0(m_filenames.size() > 0, "No session file(s) given.");
m_sessionName = m_filename.substr(0, m_filename.find_last_of('.'));
if (m_filename.size() > 3 &&
m_filename.substr(m_filename.size() - 3, 3) == ".gz")
{
m_sessionName.substr(0, m_sessionName.find_last_of('.'));
}
// Create communicator
CreateComm(argc, argv);
// If running in parallel change the default global sys solution
// type.
if (m_comm->GetSize() > 1)
{
GetSolverInfoDefaults()["GLOBALSYSSOLN"] =
"IterativeStaticCond";
}
}

Member Function Documentation

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

Enforce parameters from command line arguments.

Definition at line 2410 of file SessionReader.cpp.

References ASSERTL0, and Nektar::lhs.

{
// Parse solver info overrides
if (m_cmdLineOptions.count("solverinfo"))
{
std::vector<std::string> solverInfoList =
m_cmdLineOptions["solverinfo"].as<
std::vector<std::string> >();
for (int i = 0; i < solverInfoList.size(); ++i)
{
std::string lhs, rhs;
try
{
ParseEquals(solverInfoList[i], lhs, rhs);
}
catch (...)
{
ASSERTL0(false, "Parse error with command line "
"option: "+solverInfoList[i]);
}
std::string lhsUpper = boost::to_upper_copy(lhs);
m_solverInfo[lhsUpper] = rhs;
}
}
if (m_cmdLineOptions.count("parameter"))
{
std::vector<std::string> parametersList =
m_cmdLineOptions["parameter"].as<
std::vector<std::string> >();
for (int i = 0; i < parametersList.size(); ++i)
{
std::string lhs, rhs;
try
{
ParseEquals(parametersList[i], lhs, rhs);
}
catch (...)
{
ASSERTL0(false, "Parse error with command line "
"option: "+parametersList[i]);
}
std::string lhsUpper = boost::to_upper_copy(lhs);
try
{
m_parameters[lhsUpper] =
boost::lexical_cast<NekDouble>(rhs);
}
catch (...)
{
ASSERTL0(false, "Unable to convert string: "+rhs+
"to double value.");
}
}
}
}
void Nektar::LibUtilities::SessionReader::CreateComm ( int &  argc,
char *  argv[] 
)
private

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

Definition at line 1396 of file SessionReader.cpp.

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

{
if (argc == 0)
{
m_comm = GetCommFactory().CreateInstance("Serial", 0, 0);
}
else
{
string vCommModule("Serial");
if (GetCommFactory().ModuleExists("ParallelMPI"))
{
vCommModule = "ParallelMPI";
}
m_comm = GetCommFactory().CreateInstance(vCommModule,argc,argv);
}
}
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 138 of file SessionReader.h.

Referenced by Diffusion::Diffusion(), main(), Nektar::Utilities::InputXml::Process(), Nektar::Utilities::InputNekpp::Process(), Nektar::Utilities::ProcessInterpPoints::Process(), Nektar::Utilities::ProcessInterpField::Process(), and Nektar::VortexWaveInteraction::VortexWaveInteraction().

{
SessionReaderSharedPtr p = MemoryManager<
LibUtilities::SessionReader>::AllocateSharedPtr(argc, argv);
p->InitSession();
return p;
}
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 157 of file SessionReader.h.

{
SessionReaderSharedPtr p = MemoryManager<
LibUtilities::SessionReader>
::AllocateSharedPtr(argc, argv, pFilenames, pComm);
p->InitSession();
return p;
}
bool Nektar::LibUtilities::SessionReader::DefinesCmdLineArgument ( const std::string &  pName) const

Checks if a specified cmdline argument has been given.

Definition at line 1240 of file SessionReader.cpp.

{
return (m_cmdLineOptions.find(pName) != m_cmdLineOptions.end());
}
bool Nektar::LibUtilities::SessionReader::DefinesElement ( const std::string &  pPath) const

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

Definition at line 492 of file SessionReader.cpp.

References ASSERTL0.

{
std::string vPath = boost::to_upper_copy(pPath);
std::vector<std::string> st;
boost::split(st, vPath, boost::is_any_of("\\/ "));
ASSERTL0(st.size() > 0, "No path given in XML element request.");
TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
ASSERTL0(vReturn, std::string("Cannot find element '")
+ st[0] + std::string("'."));
for (int i = 1; i < st.size(); ++i)
{
vReturn = vReturn->FirstChildElement(st[i].c_str());
if (!vReturn) return false;
}
return true;
}
bool Nektar::LibUtilities::SessionReader::DefinesFunction ( const std::string &  name) const

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

Definition at line 978 of file SessionReader.cpp.

{
FunctionMap::const_iterator it1;
std::string vName = boost::to_upper_copy(pName);
if ((it1 = m_functions.find(vName)) != m_functions.end())
{
return true;
}
return false;
}
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 994 of file SessionReader.cpp.

{
FunctionMap::const_iterator it1;
FunctionVariableMap::const_iterator it2;
std::string vName = boost::to_upper_copy(pName);
// Check function exists
if ((it1 = m_functions.find(vName)) != m_functions.end())
{
pair<std::string, int> key(pVariable,pDomain);
pair<std::string, int> defkey("*",pDomain);
bool varExists =
(it2 = it1->second.find(key)) != it1->second.end() ||
(it2 = it1->second.find(defkey)) != it1->second.end();
return varExists;
}
return false;
}
bool Nektar::LibUtilities::SessionReader::DefinesGeometricInfo ( const std::string &  name) const

Checks if a geometric info property is defined.

Definition at line 843 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
return (iter != m_geometricInfo.end());
}
bool Nektar::LibUtilities::SessionReader::DefinesGlobalSysSolnInfo ( const std::string &  variable,
const std::string &  property 
) const

Definition at line 797 of file SessionReader.cpp.

{
GloSysSolnInfoList::const_iterator iter =
GetGloSysSolnList().find(pVariable);
if(iter == GetGloSysSolnList().end())
{
return false;
}
std::string vProperty = boost::to_upper_copy(pProperty);
GloSysInfoMap::const_iterator iter1 = iter->second.find(vProperty);
if(iter1 == iter->second.end())
{
return false;
}
return true;
}
bool Nektar::LibUtilities::SessionReader::DefinesParameter ( const std::string &  name) const

Checks if a parameter is specified in the XML document.

Definition at line 570 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
ParameterMap::const_iterator paramIter = m_parameters.find(vName);
return (paramIter != m_parameters.end());
}
bool Nektar::LibUtilities::SessionReader::DefinesSolverInfo ( const std::string &  name) const

Checks if a solver info property is specified.

Definition at line 693 of file SessionReader.cpp.

Referenced by GetSolverInfoAsEnum().

{
std::string vName = boost::to_upper_copy(pName);
SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
return (infoIter != m_solverInfo.end());
}
bool Nektar::LibUtilities::SessionReader::DefinesTag ( const std::string &  pName) const

Checks if a specified tag is defined.

Definition at line 1195 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
TagMap::const_iterator vTagIterator = m_tags.find(vName);
return (vTagIterator != m_tags.end());
}
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 561 of file SessionReader.cpp.

{
m_comm->Finalise();
}
BndRegionOrdering Nektar::LibUtilities::SessionReader::GetBndRegionOrdering ( ) const

Definition at line 1265 of file SessionReader.cpp.

{
return m_bndRegOrder;
}
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 165 of file SessionReader.cpp.

Referenced by RegisterCmdLineArgument(), and RegisterCmdLineFlag().

{
static CmdLineArgMap cmdLineArguments;
return cmdLineArguments;
}
template<typename T >
T Nektar::LibUtilities::SessionReader::GetCmdLineArgument ( const std::string &  pName) const
inline

Retrieves a command-line argument value.

Definition at line 395 of file SessionReader.h.

References m_cmdLineOptions.

{
return m_cmdLineOptions.find(pName)->second.as<T>();
}
CommSharedPtr & Nektar::LibUtilities::SessionReader::GetComm ( )

Returns the communication object.

Definition at line 549 of file SessionReader.cpp.

{
return m_comm;
}
CompositeOrdering Nektar::LibUtilities::SessionReader::GetCompositeOrdering ( ) const

Definition at line 1260 of file SessionReader.cpp.

{
return m_compOrder;
}
TiXmlDocument & Nektar::LibUtilities::SessionReader::GetDocument ( )

Provides direct access to the TiXmlDocument object.

Definition at line 440 of file SessionReader.cpp.

References ASSERTL1.

{
ASSERTL1(m_xmlDoc, "XML Document not defined.");
return *m_xmlDoc;
}
TiXmlElement * Nektar::LibUtilities::SessionReader::GetElement ( const std::string &  pPath)

Provides direct access to the TiXmlElement specified.

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

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

the PARAMETERS element would be retrieved by requesting the path:

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

Definition at line 469 of file SessionReader.cpp.

References ASSERTL0.

{
std::string vPath = boost::to_upper_copy(pPath);
std::vector<std::string> st;
boost::split(st, vPath, boost::is_any_of("\\/ "));
ASSERTL0(st.size() > 0, "No path given in XML element request.");
TiXmlElement* vReturn = m_xmlDoc->FirstChildElement(st[0].c_str());
ASSERTL0(vReturn, std::string("Cannot find element '")
+ st[0] + std::string("'."));
for (int i = 1; i < st.size(); ++i)
{
vReturn = vReturn->FirstChildElement(st[i].c_str());
ASSERTL0(vReturn, std::string("Cannot find element '")
+ st[i] + std::string("'."));
}
return vReturn;
}
AnalyticExpressionEvaluator & Nektar::LibUtilities::SessionReader::GetExpressionEvaluator ( )

Returns the instance of AnalyticExpressionEvaluator specific to this session.

Definition at line 1186 of file SessionReader.cpp.

{
}
const std::string & Nektar::LibUtilities::SessionReader::GetFilename ( ) const

Returns the filename of the loaded XML document.

Definition at line 514 of file SessionReader.cpp.

{
return m_filename;
}
const FilterMap & Nektar::LibUtilities::SessionReader::GetFilters ( ) const

Definition at line 1231 of file SessionReader.cpp.

{
return m_filters;
}
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 1020 of file SessionReader.cpp.

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

{
FunctionMap::const_iterator it1;
FunctionVariableMap::const_iterator it2, it3;
std::string vName = boost::to_upper_copy(pName);
ASSERTL0((it1 = m_functions.find(vName)) != m_functions.end(),
std::string("No such function '") + pName
+ std::string("' has been defined in the session file."));
// Check for specific and wildcard definitions
pair<std::string,int> key(pVariable,pDomain);
pair<std::string,int> defkey("*",pDomain);
bool specific = (it2 = it1->second.find(key)) !=
it1->second.end();
bool wildcard = (it3 = it1->second.find(defkey)) !=
it1->second.end();
// Check function is defined somewhere
ASSERTL0(specific || wildcard,
"No such variable " + pVariable
+ " in domain " + boost::lexical_cast<string>(pDomain)
+ " defined for function " + pName
+ " in session file.");
// If not specific, must be wildcard
if (!specific)
{
it2 = it3;
}
ASSERTL0((it2->second.m_type == eFunctionTypeExpression),
std::string("Function is defined by a file."));
return it2->second.m_expression;
}
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 1063 of file SessionReader.cpp.

References ASSERTL0.

{
ASSERTL0(pVar < m_variables.size(), "Variable index out of range.");
return GetFunction(pName, m_variables[pVar],pDomain);
}
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 1131 of file SessionReader.cpp.

References ASSERTL0.

{
FunctionMap::const_iterator it1;
FunctionVariableMap::const_iterator it2, it3;
std::string vName = boost::to_upper_copy(pName);
it1 = m_functions.find(vName);
ASSERTL0 (it1 != m_functions.end(),
std::string("Function '") + pName
+ std::string("' not found."));
// Check for specific and wildcard definitions
pair<std::string,int> key(pVariable,pDomain);
pair<std::string,int> defkey("*",pDomain);
bool specific = (it2 = it1->second.find(key)) !=
it1->second.end();
bool wildcard = (it3 = it1->second.find(defkey)) !=
it1->second.end();
// Check function is defined somewhere
ASSERTL0(specific || wildcard,
"No such variable " + pVariable
+ " in domain " + boost::lexical_cast<string>(pDomain)
+ " defined for function " + pName
+ " in session file.");
// If not specific, must be wildcard
if (!specific)
{
it2 = it3;
}
return it2->second.m_filename;
}
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 1173 of file SessionReader.cpp.

References ASSERTL0.

{
ASSERTL0(pVar < m_variables.size(), "Variable index out of range.");
return GetFunctionFilename(pName, m_variables[pVar],pDomain);
}
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 1076 of file SessionReader.cpp.

References ASSERTL0.

{
FunctionMap::const_iterator it1;
FunctionVariableMap::const_iterator it2, it3;
std::string vName = boost::to_upper_copy(pName);
it1 = m_functions.find(vName);
ASSERTL0 (it1 != m_functions.end(),
std::string("Function '") + pName
+ std::string("' not found."));
// Check for specific and wildcard definitions
pair<std::string,int> key(pVariable,pDomain);
pair<std::string,int> defkey("*",pDomain);
bool specific = (it2 = it1->second.find(key)) !=
it1->second.end();
bool wildcard = (it3 = it1->second.find(defkey)) !=
it1->second.end();
// Check function is defined somewhere
ASSERTL0(specific || wildcard,
"No such variable " + pVariable
+ " in domain " + boost::lexical_cast<string>(pDomain)
+ " defined for function " + pName
+ " in session file.");
// If not specific, must be wildcard
if (!specific)
{
it2 = it3;
}
return it2->second.m_type;
}
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 1118 of file SessionReader.cpp.

References ASSERTL0.

{
ASSERTL0(pVar < m_variables.size(), "Variable index out of range.");
return GetFunctionType(pName, m_variables[pVar],pDomain);
}
const std::string & Nektar::LibUtilities::SessionReader::GetGlobalSysSolnInfo ( const std::string &  variable,
const std::string &  property 
) const

Definition at line 823 of file SessionReader.cpp.

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

{
GloSysSolnInfoList::const_iterator iter;
ASSERTL0( (iter = GetGloSysSolnList().find(pVariable)) !=
"Failed to find variable in GlobalSysSolnInfoList");
std::string vProperty = boost::to_upper_copy(pProperty);
GloSysInfoMap::const_iterator iter1;
ASSERTL0( (iter1 = iter->second.find(vProperty)) != iter->second.end(),
"Failed to find property: " + vProperty + " in GlobalSysSolnInfoList");
return iter1->second;
}
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 151 of file SessionReader.cpp.

{
static GloSysSolnInfoList gloSysSolnInfoList;
return gloSysSolnInfoList;
}
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 586 of file SessionReader.cpp.

References ASSERTL0.

{
std::string vName = boost::to_upper_copy(pName);
ParameterMap::const_iterator paramIter = m_parameters.find(vName);
ASSERTL0(paramIter != m_parameters.end(),
"Unable to find requested parameter: " + pName);
return paramIter->second;
}
const std::string & Nektar::LibUtilities::SessionReader::GetSessionName ( ) const

Returns the session name of the loaded XML document.

Definition at line 523 of file SessionReader.cpp.

{
return m_sessionName;
}
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 533 of file SessionReader.cpp.

References Nektar::LibUtilities::PortablePath().

{
std::string dirname = m_sessionName + "_xml";
fs::path pdirname(dirname);
std::string vFilename = "P" + boost::lexical_cast<std::string>(m_comm->GetRowComm()->GetRank());
fs::path pFilename(vFilename);
fs::path fullpath = pdirname / pFilename;
return PortablePath(fullpath);
}
SessionReaderSharedPtr Nektar::LibUtilities::SessionReader::GetSharedThisPtr ( )
inlineprivate

Returns a shared pointer to the current object.

This allows a member function to pass a shared pointer to itself during a call to another function.

Definition at line 698 of file SessionReader.h.

{
return shared_from_this();
}
const std::string & Nektar::LibUtilities::SessionReader::GetSolverInfo ( const std::string &  pProperty) const

Returns the value of the specified solver info property.

Definition at line 704 of file SessionReader.cpp.

References ASSERTL1.

Referenced by GetSolverInfoAsEnum().

{
std::string vProperty = boost::to_upper_copy(pProperty);
SolverInfoMap::const_iterator iter = m_solverInfo.find(vProperty);
ASSERTL1(iter != m_solverInfo.end(),
"Unable to find requested property: " + pProperty);
return iter->second;
}
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 544 of file SessionReader.h.

References ASSERTL0, DefinesSolverInfo(), Nektar::StdRegions::find(), GetSolverInfo(), GetSolverInfoEnums(), and Nektar::iterator.

{
std::string vName = boost::to_upper_copy(pName);
"Solver info '" + pName + "' not defined.");
std::string vValue = GetSolverInfo(vName);
ASSERTL0((x = GetSolverInfoEnums().find(vName)) !=
"Enum for SolverInfo property '" + pName + "' not found.");
ASSERTL0((y = x->second.find(vValue)) != x->second.end(),
"Value of SolverInfo property '" + pName +
"' is invalid.");
return T(y->second);
}
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 135 of file SessionReader.cpp.

Referenced by RegisterDefaultSolverInfo().

{
static SolverInfoMap solverInfoMap;
return solverInfoMap;
}
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 120 of file SessionReader.cpp.

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

{
static EnumMapList solverInfoEnums;
return solverInfoEnums;
}
const std::string & Nektar::LibUtilities::SessionReader::GetTag ( const std::string &  pName) const

Returns the value of a specified tag.

Definition at line 1218 of file SessionReader.cpp.

References ASSERTL0.

{
std::string vName = boost::to_upper_copy(pName);
TagMap::const_iterator vTagIterator = m_tags.find(vName);
ASSERTL0(vTagIterator != m_tags.end(),
"Requested tag does not exist.");
return vTagIterator->second;
}
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 571 of file SessionReader.h.

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

{
std::string vName = boost::to_upper_copy(pName);
ASSERTL0((x = GetSolverInfoEnums().find(vName)) !=
"Enum for property '" + pName + "' not found.");
ASSERTL0((y = x->second.find(pValue)) != x->second.end(),
"Value of property '" + pValue + "' is invalid.");
return T(y->second);
}
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 946 of file SessionReader.cpp.

References ASSERTL0.

{
ASSERTL0(idx < m_variables.size(), "Variable index out of range.");
return m_variables[idx];
}
std::vector< std::string > Nektar::LibUtilities::SessionReader::GetVariables ( ) const

Returns the names of all variables.

Definition at line 969 of file SessionReader.cpp.

{
return m_variables;
}
void Nektar::LibUtilities::SessionReader::InitSession ( )
private

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 274 of file SessionReader.cpp.

References Nektar::iterator.

{
m_exprEvaluator.SetRandomSeed((m_comm->GetRank() + 1) * time(NULL));
// Split up the communicator
// Partition mesh
// Parse the XML data in #m_xmlDoc
// Override SOLVERINFO and parameters with any specified on the
// command line.
// In verbose mode, print out parameters and solver info sections
if (m_verbose && m_comm)
{
if (m_comm->GetRank() == 0 && m_parameters.size() > 0)
{
cout << "Parameters:" << endl;
for (x = m_parameters.begin(); x != m_parameters.end(); ++x)
{
cout << "\t" << x->first << " = " << x->second << endl;
}
cout << endl;
}
if (m_comm->GetRank() == 0 && m_solverInfo.size() > 0)
{
cout << "Solver Info:" << endl;
for (x = m_solverInfo.begin(); x != m_solverInfo.end(); ++x)
{
cout << "\t" << x->first << " = " << x->second << endl;
}
cout << endl;
}
}
}
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 1273 of file SessionReader.cpp.

References ASSERTL0.

{
if (pFilename.size() > 3 &&
pFilename.substr(pFilename.size() - 3, 3) == ".gz")
{
ifstream file(pFilename.c_str(),
ios_base::in | ios_base::binary);
ASSERTL0(file.good(), "Unable to open file: " + pFilename);
stringstream ss;
io::filtering_streambuf<io::input> in;
in.push(io::gzip_decompressor());
in.push(file);
try
{
io::copy(in, ss);
ss >> (*pDoc);
}
catch (io::gzip_error& e)
{
ASSERTL0(false,
"Error: File '" + pFilename + "' is corrupt.");
}
}
else
{
ifstream file(pFilename.c_str());
ASSERTL0(file.good(), "Unable to open file: " + pFilename);
file >> (*pDoc);
}
}
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 854 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
if(iter != m_geometricInfo.end())
{
pVar = iter->second;
}
else
{
pVar = pDefault;
}
}
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 875 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
if(iter != m_geometricInfo.end())
{
if (iter->second == "TRUE")
{
pVar = true;
}
else
{
pVar = false;
}
}
else
{
pVar = pDefault;
}
}
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 903 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
if(iter != m_geometricInfo.end())
{
pVar = std::atoi(iter->second.c_str());
}
else
{
pVar = pDefault;
}
}
void Nektar::LibUtilities::SessionReader::LoadParameter ( const std::string &  name,
int &  var 
) const

Load an integer parameter.

Definition at line 602 of file SessionReader.cpp.

References ASSERTL0.

{
std::string vName = boost::to_upper_copy(pName);
ParameterMap::const_iterator paramIter = m_parameters.find(vName);
ASSERTL0(paramIter != m_parameters.end(), "Required parameter '" +
pName + "' not specified in session.");
pVar = (int)floor(paramIter->second);
}
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 616 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
ParameterMap::const_iterator paramIter = m_parameters.find(vName);
if(paramIter != m_parameters.end())
{
pVar = (int)floor(paramIter->second);
}
else
{
pVar = pDefault;
}
}
void Nektar::LibUtilities::SessionReader::LoadParameter ( const std::string &  name,
NekDouble var 
) const

Load a double precision parameter.

Definition at line 635 of file SessionReader.cpp.

References ASSERTL0.

{
std::string vName = boost::to_upper_copy(pName);
ParameterMap::const_iterator paramIter = m_parameters.find(vName);
ASSERTL0(paramIter != m_parameters.end(), "Required parameter '" +
pName + "' not specified in session.");
pVar = paramIter->second;
}
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 649 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
ParameterMap::const_iterator paramIter = m_parameters.find(vName);
if(paramIter != m_parameters.end())
{
pVar = paramIter->second;
}
else
{
pVar = pDefault;
}
}
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 734 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
if(infoIter != m_solverInfo.end())
{
pVar = infoIter->second;
}
else
{
pVar = pDefault;
}
}
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 924 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
GeometricInfoMap::const_iterator iter = m_geometricInfo.find(vName);
if(iter != m_geometricInfo.end())
{
pVar = boost::iequals(iter->second, pTrueVal);
}
else
{
pVar = pDefault;
}
}
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 755 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
SolverInfoMap::const_iterator infoIter = m_solverInfo.find(vName);
if(infoIter != m_solverInfo.end())
{
pVar = boost::iequals(infoIter->second, pTrueVal);
}
else
{
pVar = pDefault;
}
}
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 777 of file SessionReader.cpp.

{
if (DefinesSolverInfo(pName))
{
std::string vName = boost::to_upper_copy(pName);
SolverInfoMap::const_iterator iter = m_solverInfo.find(vName);
if(iter != m_solverInfo.end())
{
return true;
}
}
return false;
}
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 533 of file SessionReader.h.

{
return (GetSolverInfoAsEnum<T>(name) == trueval);
}
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 1309 of file SessionReader.cpp.

References ASSERTL0.

{
ASSERTL0(pFilenames.size() > 0, "No filenames for merging.");
// Read the first document
TiXmlDocument *vMainDoc = new TiXmlDocument;
LoadDoc(pFilenames[0], vMainDoc);
TiXmlHandle vMainHandle(vMainDoc);
TiXmlElement* vMainNektar =
vMainHandle.FirstChildElement("NEKTAR").Element();
// Read all subsequent XML documents.
// For each element within the NEKTAR tag, use it to replace the
// version already present in the loaded XML data.
for (int i = 1; i < pFilenames.size(); ++i)
{
if((pFilenames[i].compare(pFilenames[i].size()-3,3,"xml") == 0)
||(pFilenames[i].compare(pFilenames[i].size()-6,6,"xml.gz") == 0))
{
TiXmlDocument* vTempDoc = new TiXmlDocument;
LoadDoc(pFilenames[i], vTempDoc);
TiXmlHandle docHandle(vTempDoc);
TiXmlElement* vTempNektar;
vTempNektar = docHandle.FirstChildElement("NEKTAR").Element();
ASSERTL0(vTempNektar, "Unable to find NEKTAR tag in file.");
TiXmlElement* p = vTempNektar->FirstChildElement();
while (p)
{
TiXmlElement *vMainEntry =
vMainNektar->FirstChildElement(p->Value());
TiXmlElement *q = new TiXmlElement(*p);
if (vMainEntry)
{
vMainNektar->RemoveChild(vMainEntry);
}
vMainNektar->LinkEndChild(q);
p = p->NextSiblingElement();
}
delete vTempDoc;
}
}
return vMainDoc;
}
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 323 of file SessionReader.cpp.

References Nektar::iterator.

{
// List the publically visible options (listed using --help)
po::options_description desc("Allowed options");
desc.add_options()
("verbose,v", "be verbose")
("help,h", "print this help message")
("solverinfo,I", po::value<vector<std::string> >(),
"override a SOLVERINFO property")
("parameter,P", po::value<vector<std::string> >(),
"override a parameter")
("shared-filesystem,s", "Using shared filesystem.")
("npx", po::value<int>(),
"number of procs in X-dir")
("npy", po::value<int>(),
"number of procs in Y-dir")
("npz", po::value<int>(),
"number of procs in Z-dir")
("part-info", "Output partition information")
;
CmdLineArgMap::const_iterator cmdIt;
for (cmdIt = GetCmdLineArgMap().begin();
cmdIt != GetCmdLineArgMap().end(); ++cmdIt)
{
std::string names = cmdIt->first;
if (cmdIt->second.shortName != "")
{
names += "," + cmdIt->second.shortName;
}
if (cmdIt->second.isFlag)
{
desc.add_options()
(names.c_str(), cmdIt->second.description.c_str())
;
}
else
{
desc.add_options()
(names.c_str(), po::value<std::string>(),
cmdIt->second.description.c_str())
;
}
}
// List hidden options (e.g. session file arguments are not actually
// specified using the input-file option by the user).
po::options_description hidden("Hidden options");
hidden.add_options()
("input-file", po::value< vector<string> >(),
"input filename")
;
// Combine all options for the parser
po::options_description all("All options");
all.add(desc).add(hidden);
// Session file is a positional option
po::positional_options_description p;
p.add("input-file", -1);
// Parse the command-line options
po::parsed_options parsed = po::command_line_parser(argc, argv).
options(all).
positional(p).
allow_unregistered().
run();
// Extract known options to map and update
po::store(parsed, m_cmdLineOptions);
po::notify(m_cmdLineOptions);
// Help message
if (m_cmdLineOptions.count("help"))
{
cout << desc << endl;
exit(0);
}
// Enable verbose mode
if (m_cmdLineOptions.count("verbose"))
{
m_verbose = true;
}
else
{
m_verbose = false;
}
// Print a warning for unknown options
std::vector< po::basic_option<char> >::iterator x;
for (x = parsed.options.begin(); x != parsed.options.end(); ++x)
{
if (x->unregistered)
{
cout << "Warning: Unknown option: " << x->string_key
<< endl;
}
}
// Return the vector of filename(s) given as positional options
if (m_cmdLineOptions.count("input-file"))
{
return m_cmdLineOptions["input-file"].as<
std::vector<std::string> >();
}
else
{
return std::vector<std::string>();
}
}
void Nektar::LibUtilities::SessionReader::ParseDocument ( )
private

Loads and parses the specified file.

Definition at line 1362 of file SessionReader.cpp.

References ASSERTL0.

{
// Check we actually have a document loaded.
ASSERTL0(m_xmlDoc, "No XML document loaded.");
// Look for all data in CONDITIONS block.
TiXmlHandle docHandle(m_xmlDoc);
TiXmlElement* e;
e = docHandle.FirstChildElement("NEKTAR").
FirstChildElement("CONDITIONS").Element();
// Read the various sections of the CONDITIONS block
e = docHandle.FirstChildElement("NEKTAR").
FirstChildElement("GEOMETRY").Element();
e = docHandle.FirstChildElement("NEKTAR").
FirstChildElement("FILTERS").Element();
}
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 2384 of file SessionReader.cpp.

{
/// Pull out lhs and rhs and eliminate any spaces.
int beg = line.find_first_not_of(" ");
int end = line.find_first_of("=");
// Check for no parameter name
if (beg == end) throw 1;
// Check for no parameter value
if (end != line.find_last_of("=")) throw 1;
// Check for no equals sign
if (end == std::string::npos) throw 1;
lhs = line.substr(line.find_first_not_of(" "),
end-beg);
lhs = lhs .substr(0, lhs.find_last_not_of(" ")+1);
rhs = line.substr(line.find_last_of("=")+1);
rhs = rhs .substr(rhs.find_first_not_of(" "));
rhs = rhs .substr(0, rhs.find_last_not_of(" ")+1);
}
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 1631 of file SessionReader.cpp.

References ASSERTL0.

{
if (m_comm->GetSize() > 1)
{
int nProcZ = 1;
int nProcY = 1;
int nProcX = 1;
if (DefinesCmdLineArgument("npx")) {
nProcX = GetCmdLineArgument<int>("npx");
}
if (DefinesCmdLineArgument("npy")) {
nProcY = GetCmdLineArgument<int>("npy");
}
if (DefinesCmdLineArgument("npz")) {
nProcZ = GetCmdLineArgument<int>("npz");
}
ASSERTL0(m_comm->GetSize() % (nProcZ*nProcY*nProcX) == 0,
"Cannot exactly partition using PROC_Z value.");
ASSERTL0(nProcZ % nProcY == 0,
"Cannot exactly partition using PROC_Y value.");
ASSERTL0(nProcY % nProcX == 0,
"Cannot exactly partition using PROC_X value.");
// Number of processes associated with the spectral method
int nProcSm = nProcZ * nProcY * nProcX;
// Number of processes associated with the spectral element
// method.
int nProcSem = m_comm->GetSize() / nProcSm;
m_comm->SplitComm(nProcSm,nProcSem);
m_comm->GetColumnComm()->SplitComm((nProcY*nProcX),nProcZ);
m_comm->GetColumnComm()->GetColumnComm()->SplitComm(
nProcX,nProcY);
}
}
void Nektar::LibUtilities::SessionReader::PartitionMesh ( )
private

Partitions the mesh when running in parallel.

Definition at line 1420 of file SessionReader.cpp.

References ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, >::CreateInstance(), Nektar::LibUtilities::GetMeshPartitionFactory(), Nektar::iterator, Nektar::LibUtilities::NekFactory< tKey, tBase, >::ModuleExists(), and Nektar::LibUtilities::PortablePath().

{
ASSERTL0(m_comm.get(), "Communication not initialised.");
// Get row of comm, or the whole comm if not split
CommSharedPtr vCommMesh = m_comm->GetRowComm();
// Partition mesh into length of row comms
if (vCommMesh->GetSize() > 1)
{
// Default partitioner to use is Metis. Use Scotch as default
// if it is installed. Override default with command-line flags
// if they are set.
string vPartitionerName = "Metis";
{
vPartitionerName = "Scotch";
}
if (DefinesCmdLineArgument("use-metis"))
{
vPartitionerName = "Metis";
}
if (DefinesCmdLineArgument("use-scotch"))
{
vPartitionerName = "Scotch";
}
if (DefinesCmdLineArgument("shared-filesystem"))
{
vector<unsigned int> keys, vals;
int i;
if (vComm->GetRank() == 0)
{
MeshPartitionSharedPtr vPartitioner =
vPartitionerName, vSession);
vPartitioner->PartitionMesh(true);
vPartitioner->WriteAllPartitions(vSession);
vPartitioner->GetCompositeOrdering(m_compOrder);
vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
// Communicate orderings to the other processors.
// First send sizes of the orderings and boundary
// regions to allocate storage on the remote end.
keys.resize(2);
keys[0] = m_compOrder.size();
keys[1] = m_bndRegOrder.size();
for (i = 1; i < vComm->GetSize(); ++i)
{
vComm->Send(i, keys);
}
// Construct the keys and sizes of values for composite
// ordering
keys.resize(m_compOrder.size());
vals.resize(m_compOrder.size());
for (cIt = m_compOrder.begin(), i = 0;
cIt != m_compOrder.end(); ++cIt, ++i)
{
keys[i] = cIt->first;
vals[i] = cIt->second.size();
}
// Send across data.
for (i = 1; i < vComm->GetSize(); ++i)
{
vComm->Send(i, keys);
vComm->Send(i, vals);
for (cIt = m_compOrder.begin();
cIt != m_compOrder.end(); ++cIt)
{
vComm->Send(i, cIt->second);
}
}
// Construct the keys and sizes of values for composite
// ordering
keys.resize(m_bndRegOrder.size());
vals.resize(m_bndRegOrder.size());
for (bIt = m_bndRegOrder.begin(), i = 0;
bIt != m_bndRegOrder.end(); ++bIt, ++i)
{
keys[i] = bIt->first;
vals[i] = bIt->second.size();
}
// Send across data.
for (i = 1; i < vComm->GetSize(); ++i)
{
vComm->Send(i, keys);
vComm->Send(i, vals);
for (bIt = m_bndRegOrder.begin();
bIt != m_bndRegOrder.end(); ++bIt)
{
vComm->Send(i, bIt->second);
}
}
if (DefinesCmdLineArgument("part-info"))
{
vPartitioner->PrintPartInfo(std::cout);
}
}
else
{
keys.resize(2);
vComm->Recv(0, keys);
int cmpSize = keys[0];
int bndSize = keys[1];
keys.resize(cmpSize);
vals.resize(cmpSize);
vComm->Recv(0, keys);
vComm->Recv(0, vals);
for (int i = 0; i < keys.size(); ++i)
{
vector<unsigned int> tmp(vals[i]);
vComm->Recv(0, tmp);
m_compOrder[keys[i]] = tmp;
}
keys.resize(bndSize);
vals.resize(bndSize);
vComm->Recv(0, keys);
vComm->Recv(0, vals);
for (int i = 0; i < keys.size(); ++i)
{
vector<unsigned int> tmp(vals[i]);
vComm->Recv(0, tmp);
m_bndRegOrder[keys[i]] = tmp;
}
}
}
else
{
// Partitioner now operates in parallel
// Each process receives partitioning over interconnect
// and writes its own session file to the working directory.
MeshPartitionSharedPtr vPartitioner =
vPartitionerName, vSession);
vPartitioner->PartitionMesh(false);
vPartitioner->WriteLocalPartition(vSession);
vPartitioner->GetCompositeOrdering(m_compOrder);
vPartitioner->GetBndRegionOrdering(m_bndRegOrder);
if (DefinesCmdLineArgument("part-info"))
{
vPartitioner->PrintPartInfo(std::cout);
}
}
m_comm->Block();
std::string dirname = GetSessionName() + "_xml";
fs::path pdirname(dirname);
boost::format pad("P%1$07d.xml");
pad % m_comm->GetRank();
fs::path pFilename(pad.str());
fs::path fullpath = pdirname / pFilename;
m_filename = PortablePath(fullpath);
if (m_xmlDoc)
{
delete m_xmlDoc;
}
m_xmlDoc = new TiXmlDocument(m_filename);
ASSERTL0(m_xmlDoc, "Failed to create XML document object.");
bool loadOkay = m_xmlDoc->LoadFile(m_filename);
ASSERTL0(loadOkay, "Unable to load file: " + m_filename +
". Check XML standards compliance. Error on line: " +
boost::lexical_cast<std::string>(m_xmlDoc->Row()));
}
else
{
if (m_xmlDoc)
{
delete m_xmlDoc;
}
}
}
void Nektar::LibUtilities::SessionReader::ReadExpressions ( TiXmlElement *  conditions)
private

Reads the EXPRESSIONS section of the XML document.

Definition at line 2050 of file SessionReader.cpp.

References ASSERTL0, and Nektar::iterator.

{
m_expressions.clear();
if (!conditions)
{
return;
}
TiXmlElement *expressionsElement =
conditions->FirstChildElement("EXPRESSIONS");
if (expressionsElement)
{
TiXmlElement *expr = expressionsElement->FirstChildElement("E");
while (expr)
{
ASSERTL0(expr->Attribute("NAME"),
"Missing NAME attribute in expression definition. "
"File: '" + m_filename + "', line: "
+ boost::lexical_cast<std::string>(expr->Row()));
std::string nameString = expr->Attribute("NAME");
ASSERTL0(!nameString.empty(),
"Expressions must have a non-empty name. "
"File: '" + m_filename + "', line: "
+ boost::lexical_cast<std::string>(expr->Row()));
ASSERTL0(expr->Attribute("VALUE"),
"Missing VALUE attribute in expression definition."
" File: '" + m_filename + "', line: "
+ boost::lexical_cast<std::string>(expr->Row()));
std::string valString = expr->Attribute("VALUE");
ASSERTL0(!valString.empty(),
"Expressions must have a non-empty value. "
"File: '" + m_filename + "', line: "
+ boost::lexical_cast<std::string>(expr->Row()));
= m_expressions.find(nameString);
ASSERTL0(exprIter == m_expressions.end(),
std::string("Expression '") + nameString
+ std::string("' already specified."));
m_expressions[nameString] = valString;
expr = expr->NextSiblingElement("E");
}
}
}
void Nektar::LibUtilities::SessionReader::ReadFilters ( TiXmlElement *  filters)
private

Reads the FILTERS section of the XML document.

Definition at line 2343 of file SessionReader.cpp.

References ASSERTL0.

{
if (!filters)
{
return;
}
m_filters.clear();
TiXmlElement *filter = filters->FirstChildElement("FILTER");
while (filter)
{
ASSERTL0(filter->Attribute("TYPE"),
"Missing attribute 'TYPE' for filter.");
std::string typeStr = filter->Attribute("TYPE");
std::map<std::string, std::string> vParams;
TiXmlElement *param = filter->FirstChildElement("PARAM");
while (param)
{
ASSERTL0(param->Attribute("NAME"),
"Missing attribute 'NAME' for parameter in filter "
+ typeStr + "'.");
std::string nameStr = param->Attribute("NAME");
ASSERTL0(param->GetText(), "Empty value string for param.");
std::string valueStr = param->GetText();
vParams[nameStr] = valueStr;
param = param->NextSiblingElement("PARAM");
}
m_filters.push_back(
std::pair<std::string, FilterParams>(typeStr, vParams));
filter = filter->NextSiblingElement("FILTER");
}
}
void Nektar::LibUtilities::SessionReader::ReadFunctions ( TiXmlElement *  conditions)
private

Reads the FUNCTIONS section of the XML document.

Definition at line 2185 of file SessionReader.cpp.

References ASSERTL0, Nektar::LibUtilities::eFunctionTypeExpression, Nektar::LibUtilities::eFunctionTypeFile, Nektar::iterator, Nektar::LibUtilities::FunctionVariableDefinition::m_expression, Nektar::LibUtilities::FunctionVariableDefinition::m_filename, and Nektar::LibUtilities::FunctionVariableDefinition::m_type.

{
m_functions.clear();
if (!conditions)
{
return;
}
// Scan through conditions section looking for functions.
TiXmlElement *function = conditions->FirstChildElement("FUNCTION");
while (function)
{
// Every function must have a NAME attribute
ASSERTL0(function->Attribute("NAME"),
"Functions must have a NAME attribute defined. "
"File: '" + m_filename + "', line: "
+ boost::lexical_cast<std::string>(function->Row()));
std::string functionStr = function->Attribute("NAME");
ASSERTL0(!functionStr.empty(),
"Functions must have a non-empty name. "
"File: '" + m_filename + "', line: "
+ boost::lexical_cast<string>(function->Row()));
// Store function names in uppercase to remain case-insensitive.
boost::to_upper(functionStr);
// Retrieve first entry (variable, or file)
TiXmlElement *variable = function->FirstChildElement();
// Create new function structure with default type of none.
FunctionVariableMap functionVarMap;
// Process all entries in the function block
while (variable)
{
FunctionVariableDefinition funcDef;
std::string conditionType = variable->Value();
// If no var is specified, assume wildcard
std::string variableStr;
if (!variable->Attribute("VAR"))
{
variableStr = "*";
}
else
{
variableStr = variable->Attribute("VAR");
}
// Parse list of variables
std::vector<std::string> variableList;
variableList);
// If no domain string put to 0
std::string domainStr;
if (!variable->Attribute("DOMAIN"))
{
domainStr = "0";
}
else
{
domainStr = variable->Attribute("DOMAIN");
}
// Parse list of variables
std::vector<unsigned int> domainList;
ParseUtils::GenerateSeqVector(domainStr.c_str(), domainList);
// Expressions are denoted by E
if (conditionType == "E")
{
funcDef.m_type = eFunctionTypeExpression;
// Expression must have a VALUE.
ASSERTL0(variable->Attribute("VALUE"),
"Attribute VALUE expected for function '"
+ functionStr + "'.");
std::string fcnStr = variable->Attribute("VALUE");
ASSERTL0(!fcnStr.empty(),
(std::string("Expression for var: ")
+ variableStr
+ std::string(" must be specified.")).c_str());
// set expression
funcDef.m_expression = MemoryManager<Equation>
::AllocateSharedPtr(GetSharedThisPtr(),fcnStr);
}
// Files are denoted by F
else if (conditionType == "F")
{
funcDef.m_type = eFunctionTypeFile;
// File must have a FILE.
ASSERTL0(variable->Attribute("FILE"),
"Attribute FILE expected for function '"
+ functionStr + "'.");
std::string filenameStr = variable->Attribute("FILE");
ASSERTL0(!filenameStr.empty(),
"A filename must be specified for the FILE "
"attribute of function '" + functionStr
+ "'.");
// set the filename
funcDef.m_filename = filenameStr;
}
// Nothing else supported so throw an error
else
{
ASSERTL0(false,
"Identifier " + conditionType + " in function "
+ std::string(function->Attribute("NAME"))
+ " is not recognised. "
"File: '" + m_filename + "', line: "
+ boost::lexical_cast<string>(variable->Row()));
}
// Add variables to function
for (unsigned int i = 0; i < variableList.size(); ++i)
{
for(unsigned int j = 0; j < domainList.size(); ++j)
{
// Check it has not already been defined
pair<std::string,int> key(variableList[i],domainList[j]);
= functionVarMap.find(key);
ASSERTL0(fcnsIter == functionVarMap.end(),
"Error setting expression '" + variableList[i]
+ " in domain "
+ boost::lexical_cast<std::string>(domainList[j])
+ "' in function '" + functionStr + "'. "
"Expression has already been defined.");
functionVarMap[key] = funcDef;
}
}
variable = variable->NextSiblingElement();
}
// Add function definition to map
m_functions[functionStr] = functionVarMap;
function = function->NextSiblingElement("FUNCTION");
}
}
void Nektar::LibUtilities::SessionReader::ReadGeometricInfo ( TiXmlElement *  geometry)
private

Reads the GEOMETRICINFO section of the XML document.

Definition at line 1972 of file SessionReader.cpp.

References ASSERTL0, and Nektar::iterator.

{
m_geometricInfo.clear();
if (!geometry)
{
return;
}
TiXmlElement *geometricInfoElement =
geometry->FirstChildElement("GEOMINFO");
if (geometricInfoElement)
{
TiXmlElement *geometricInfo =
geometricInfoElement->FirstChildElement("I");
while (geometricInfo)
{
ASSERTL0(geometricInfo->Attribute("PROPERTY"),
"Missing PROPERTY attribute in geometric info "
"section. File: '" + m_filename + "', line: " +
boost::lexical_cast<string>(geometricInfo->Row()));
std::string geometricProperty =
geometricInfo->Attribute("PROPERTY");
ASSERTL0(!geometricProperty.empty(),
"Geometric info properties must have a non-empty "
"name. File: '" + m_filename + "', line: " +
boost::lexical_cast<string>(geometricInfo->Row()));
// make sure that geometric property is capitalised
boost::to_upper(geometricProperty);
// check the property has not already been defined
GeometricInfoMap::iterator geometricInfoIter =
m_geometricInfo.find(geometricProperty);
ASSERTL0(geometricInfoIter == m_geometricInfo.end(),
"geometricInfo value: " + geometricProperty +
" already specified.");
// read the property value
ASSERTL0(geometricInfo->Attribute("VALUE"),
"Missing VALUE attribute in geometric info section"
". File: '" + m_filename + ", line: " +
boost::lexical_cast<string>(geometricInfo->Row()));
std::string geometricValue =
geometricInfo->Attribute("VALUE");
ASSERTL0(!geometricValue.empty(),
"Geometric info properties must have a non-empty "
"value. File: '" + m_filename + ", line: " +
boost::lexical_cast<string>(geometricInfo->Row()));
// Set Variable
m_geometricInfo[geometricProperty] = geometricValue;
geometricInfo = geometricInfo->NextSiblingElement("I");
}
}
if (m_verbose && m_geometricInfo.size() > 0 && m_comm)
{
if(m_comm->GetRank() == 0)
{
cout << "Geometric Info:" << endl;
for (x = m_geometricInfo.begin();
x != m_geometricInfo.end(); ++x)
{
cout << "\t" << x->first << " = " << x->second << endl;
}
cout << endl;
}
}
}
void Nektar::LibUtilities::SessionReader::ReadGlobalSysSolnInfo ( TiXmlElement *  conditions)
private

Reads the GLOBALSYSSOLNINFO section of the XML document.

Definition at line 1844 of file SessionReader.cpp.

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

{
GetGloSysSolnList().clear();
if (!conditions)
{
return;
}
TiXmlElement *GlobalSys =
conditions->FirstChildElement("GLOBALSYSSOLNINFO");
if(!GlobalSys)
{
return;
}
TiXmlElement *VarInfo = GlobalSys->FirstChildElement("V");
while (VarInfo)
{
ASSERTL0(VarInfo->Attribute("VAR"),
"Missing VAR in attribute of GobalSysSolnInfo section."
"File: '" + m_filename + ", line: " +
boost::lexical_cast<string>(GlobalSys->Row()));
std::string VarList = VarInfo->Attribute("VAR");
// generate a list of variables.
std::vector<std::string> varStrings;
VarList.c_str(),varStrings);
ASSERTL0(valid,"Unable to process list of variable in "
"GlobalSysSolnInfo data, File '" + m_filename +
", line: " +
boost::lexical_cast<string>(GlobalSys->Row()));
if(varStrings.size())
{
TiXmlElement *SysSolnInfo = VarInfo->FirstChildElement("I");
while (SysSolnInfo)
{
// read the property name
ASSERTL0(SysSolnInfo->Attribute("PROPERTY"),
"Missing PROPERTY attribute in "
"GlobalSysSolnInfo section. File: '" +
m_filename + "', line: " +
boost::lexical_cast<string>(VarInfo->Row()));
std::string SysSolnProperty =
SysSolnInfo->Attribute("PROPERTY");
ASSERTL0(!SysSolnProperty.empty(),
"GlobalSysSolnIno properties must have a "
"non-empty name for variable(s) : '" +
VarList + ". File: '" + m_filename + ", line: "
+ boost::lexical_cast<string>(VarInfo->Row()));
// make sure that solver property is capitalised
std::string SysSolnPropertyUpper =
boost::to_upper_copy(SysSolnProperty);
// read the value
ASSERTL0(SysSolnInfo->Attribute("VALUE"),
"Missing VALUE attribute in GlobalSysSolnInfo "
"section. File: '" + m_filename + "', line: "
+ boost::lexical_cast<string>(VarInfo->Row()));
std::string SysSolnValue =
SysSolnInfo->Attribute("VALUE");
ASSERTL0(!SysSolnValue.empty(),
"GlobalSysSolnInfo properties must have a "
"non-empty value. File: '" + m_filename +
"', line: "
+ boost::lexical_cast<string>(VarInfo->Row()));
// Store values under variable map.
for(int i = 0; i < varStrings.size(); ++i)
{
if ((x = GetGloSysSolnList().find(varStrings[i])) ==
{
(GetGloSysSolnList()[varStrings[i]])[
SysSolnPropertyUpper] = SysSolnValue;
}
else
{
x->second[SysSolnPropertyUpper] = SysSolnValue;
}
}
SysSolnInfo = SysSolnInfo->NextSiblingElement("I");
}
VarInfo = VarInfo->NextSiblingElement("V");
}
}
if (m_verbose && GetGloSysSolnList().size() > 0 && m_comm)
{
if(m_comm->GetRank() == 0)
{
cout << "GlobalSysSoln Info:" << endl;
for (x = GetGloSysSolnList().begin();
x != GetGloSysSolnList().end();
++x)
{
cout << "\t Variable: " << x->first << endl;
for (y = x->second.begin(); y != x->second.end(); ++y)
{
cout << "\t\t " << y->first << " = " << y->second
<< endl;
}
}
cout << endl;
}
}
}
void Nektar::LibUtilities::SessionReader::ReadParameters ( TiXmlElement *  conditions)
private

Reads the PARAMETERS section of the XML document.

Definition at line 1673 of file SessionReader.cpp.

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

{
m_parameters.clear();
if (!conditions)
{
return;
}
TiXmlElement *parametersElement = conditions->FirstChildElement(
"PARAMETERS");
// See if we have parameters defined. They are optional so we go on
// if not.
if (parametersElement)
{
TiXmlElement *parameter =
parametersElement->FirstChildElement("P");
ParameterMap caseSensitiveParameters;
// Multiple nodes will only occur if there is a comment in
// between definitions.
while (parameter)
{
TiXmlNode *node = parameter->FirstChild();
while (node && node->Type() != TiXmlNode::TEXT)
{
node = node->NextSibling();
}
if (node)
{
// Format is "paramName = value"
std::string line = node->ToText()->Value(), lhs, rhs;
try {
ParseEquals(line, lhs, rhs);
}
catch (...)
{
ASSERTL0(false, "Syntax error. "
"File: '" + m_filename + "', line: "
+ boost::lexical_cast<string>(node->Row()));
}
// We want the list of parameters to have their RHS
// evaluated, so we use the expression evaluator to do
// the dirty work.
if (!lhs.empty() && !rhs.empty())
{
NekDouble value=0.0;
try
{
LibUtilities::Equation expession(
value = expession.Evaluate();
}
catch (const std::runtime_error &)
{
ASSERTL0(false,
"Error evaluating parameter expression"
" '" + rhs + "'." );
}
caseSensitiveParameters[lhs] = value;
boost::to_upper(lhs);
m_parameters[lhs] = value;
}
}
parameter = parameter->NextSiblingElement();
}
}
}
void Nektar::LibUtilities::SessionReader::ReadSolverInfo ( TiXmlElement *  conditions)
private

Reads the SOLVERINFO section of the XML document.

Definition at line 1754 of file SessionReader.cpp.

References ASSERTL0.

{
m_solverInfo.clear();
if (!conditions)
{
return;
}
TiXmlElement *solverInfoElement =
conditions->FirstChildElement("SOLVERINFO");
if (solverInfoElement)
{
TiXmlElement *solverInfo =
solverInfoElement->FirstChildElement("I");
while (solverInfo)
{
// read the property name
ASSERTL0(solverInfo->Attribute("PROPERTY"),
"Missing PROPERTY attribute in solver info "
"section. File: '" + m_filename + "', line: " +
boost::lexical_cast<string>(solverInfo->Row()));
std::string solverProperty =
solverInfo->Attribute("PROPERTY");
ASSERTL0(!solverProperty.empty(),
"Solver info properties must have a non-empty "
"name. File: '" + m_filename + "', line: "
+ boost::lexical_cast<string>(solverInfo->Row()));
// make sure that solver property is capitalised
std::string solverPropertyUpper =
boost::to_upper_copy(solverProperty);
// read the value
ASSERTL0(solverInfo->Attribute("VALUE"),
"Missing VALUE attribute in solver info section. "
"File: '" + m_filename + "', line: "
+ boost::lexical_cast<string>(solverInfo->Row()));
std::string solverValue = solverInfo->Attribute("VALUE");
ASSERTL0(!solverValue.empty(),
"Solver info properties must have a non-empty "
"value. File: '" + m_filename + "', line: "
+ boost::lexical_cast<string>(solverInfo->Row()));
EnumMapList::const_iterator propIt =
GetSolverInfoEnums().find(solverPropertyUpper);
if (propIt != GetSolverInfoEnums().end())
{
EnumMap::const_iterator valIt =
propIt->second.find(solverValue);
ASSERTL0(valIt != propIt->second.end(),
"Value '" + solverValue + "' is not valid for "
"property '" + solverProperty + "'. File: '" +
m_filename + "', line: " + boost::lexical_cast<
string>(solverInfo->Row()));
}
// Set Variable
m_solverInfo[solverPropertyUpper] = solverValue;
solverInfo = solverInfo->NextSiblingElement("I");
}
}
if (m_comm && m_comm->GetRowComm()->GetSize() > 1)
{
m_solverInfo["GLOBALSYSSOLN"] == "IterativeFull" ||
m_solverInfo["GLOBALSYSSOLN"] == "IterativeStaticCond" ||
m_solverInfo["GLOBALSYSSOLN"] ==
"IterativeMultiLevelStaticCond" ||
m_solverInfo["GLOBALSYSSOLN"] == "XxtFull" ||
m_solverInfo["GLOBALSYSSOLN"] == "XxtStaticCond" ||
m_solverInfo["GLOBALSYSSOLN"] ==
"XxtMultiLevelStaticCond" ||
m_solverInfo["GLOBALSYSSOLN"] == "PETScFull" ||
m_solverInfo["GLOBALSYSSOLN"] == "PETScStaticCond" ||
m_solverInfo["GLOBALSYSSOLN"] ==
"PETScMultiLevelStaticCond",
"A parallel solver must be used when run in parallel.");
}
}
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 2104 of file SessionReader.cpp.

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

{
m_variables.clear();
if (!conditions)
{
return;
}
TiXmlElement *variablesElement =
conditions->FirstChildElement("VARIABLES");
// See if we have parameters defined. They are optional so we go on
// if not.
if (variablesElement)
{
TiXmlElement *varElement =
variablesElement->FirstChildElement("V");
// Sequential counter for the composite numbers.
int nextVariableNumber = -1;
while (varElement)
{
/// All elements are of the form: "<V ID="#"> name = value
/// </V>", with ? being the element type.
nextVariableNumber++;
int i;
int err = varElement->QueryIntAttribute("ID", &i);
ASSERTL0(err == TIXML_SUCCESS,
"Variables must have a unique ID number attribute."
" File: '" + m_filename + "', line: " +
boost::lexical_cast<string>(varElement->Row()));
ASSERTL0(i == nextVariableNumber,
"ID numbers for variables must begin with zero and"
" be sequential. File: '"+m_filename+"', line: " +
boost::lexical_cast<string>(varElement->Row()));
TiXmlNode* varChild = varElement->FirstChild();
// This is primarily to skip comments that may be present.
// Comments appear as nodes just like elements. We are
// specifically looking for text in the body of the
// definition.
while(varChild && varChild->Type() != TiXmlNode::TEXT)
{
varChild = varChild->NextSibling();
}
ASSERTL0(varChild,
"Unable to read variable definition body for "
"variable with ID "
+ boost::lexical_cast<string>(i) + ". "
" File: '" + m_filename + "', line: "
+ boost::lexical_cast<string>(varElement->Row()));
std::string variableName = varChild->ToText()->ValueStr();
std::istringstream variableStrm(variableName);
variableStrm >> variableName;
variableName) == m_variables.end(),
"Variable with ID "+boost::lexical_cast<string>(i)
+ " has already been defined. "
" File: '" + m_filename + "', line: "
+ boost::lexical_cast<string>(varElement->Row()));
m_variables.push_back(variableName);
varElement = varElement->NextSiblingElement("V");
}
ASSERTL0(nextVariableNumber > -1,
"Number of variables must be greater than zero.");
}
}
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 661 of file SessionReader.h.

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

{
ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
CmdLineArg x;
x.shortName = pShortName;
x.description = pDescription;
x.isFlag = false;
GetCmdLineArgMap()[pName] = x;
return pName;
}
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 679 of file SessionReader.h.

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

Referenced by main().

{
ASSERTL0(!pName.empty(), "Empty name for cmdline argument.");
CmdLineArg x;
x.shortName = pShortName;
x.description = pDescription;
x.isFlag = true;
GetCmdLineArgMap()[pName] = x;
return pName;
}
std::string Nektar::LibUtilities::SessionReader::RegisterDefaultSolverInfo ( const std::string &  pName,
const std::string &  pValue 
)
inlinestatic

Registers the default string value of a solver info property.

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

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

Definition at line 648 of file SessionReader.h.

References GetSolverInfoDefaults().

{
std::string vName = boost::to_upper_copy(pName);
GetSolverInfoDefaults()[vName] = pValue;
return pValue;
}
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",
}
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 615 of file SessionReader.h.

References Nektar::StdRegions::find(), GetSolverInfoEnums(), and Nektar::iterator.

{
std::string vEnum = boost::to_upper_copy(pEnum);
if ((x = GetSolverInfoEnums().find(vEnum)) ==
{
x = GetSolverInfoEnums().find(vEnum);
}
x->second[pString] = pEnumValue;
return pString;
}
void Nektar::LibUtilities::SessionReader::SetParameter ( const std::string &  name,
int &  var 
)

Set an integer parameter.

Definition at line 671 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
m_parameters[vName] = pVar;
}
void Nektar::LibUtilities::SessionReader::SetParameter ( const std::string &  name,
NekDouble var 
)

Set a double precision parameter.

Definition at line 681 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
m_parameters[vName] = pVar;
}
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 719 of file SessionReader.cpp.

References ASSERTL1, and Nektar::iterator.

{
std::string vProperty = boost::to_upper_copy(pProperty);
SolverInfoMap::iterator iter = m_solverInfo.find(vProperty);
ASSERTL1(iter != m_solverInfo.end(),
"Unable to find requested property: " + pProperty);
iter->second = pValue;
}
void Nektar::LibUtilities::SessionReader::SetTag ( const std::string &  pName,
const std::string &  pValue 
)

Sets a specified tag.

Definition at line 1206 of file SessionReader.cpp.

{
std::string vName = boost::to_upper_copy(pName);
m_tags[vName] = pValue;
}
void Nektar::LibUtilities::SessionReader::SetUpXmlDoc ( void  )

Definition at line 2474 of file SessionReader.cpp.

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

Definition at line 958 of file SessionReader.cpp.

References ASSERTL0.

{
ASSERTL0(idx < m_variables.size(), "Variable index out of range.");
m_variables[idx] = newname;
}
void Nektar::LibUtilities::SessionReader::SubstituteExpressions ( std::string &  expr)

Substitutes expressions defined in the XML document.

Definition at line 1250 of file SessionReader.cpp.

References Nektar::iterator.

{
for (exprIter = m_expressions.begin();
exprIter != m_expressions.end(); ++exprIter)
{
boost::replace_all(pExpr, exprIter->first, exprIter->second);
}
}

Friends And Related Function Documentation

friend class MemoryManager< SessionReader >
friend

Support creation through MemoryManager.

Definition at line 126 of file SessionReader.h.

Member Data Documentation

BndRegionOrdering Nektar::LibUtilities::SessionReader::m_bndRegOrder
private

Map of original boundary region ordering for parallel periodic bcs.

Definition at line 457 of file SessionReader.h.

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

Definition at line 421 of file SessionReader.h.

Referenced by GetCmdLineArgument().

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

Communication object.

Definition at line 424 of file SessionReader.h.

CompositeOrdering Nektar::LibUtilities::SessionReader::m_compOrder
private

Map of original composite ordering for parallel periodic bcs.

Definition at line 454 of file SessionReader.h.

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

Expressions.

Definition at line 440 of file SessionReader.h.

AnalyticExpressionEvaluator Nektar::LibUtilities::SessionReader::m_exprEvaluator
private

Analytic expression evaluator instance.

Definition at line 442 of file SessionReader.h.

std::string Nektar::LibUtilities::SessionReader::m_filename
private

Filename of the loaded XML document.

Definition at line 428 of file SessionReader.h.

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

Filenames.

Definition at line 426 of file SessionReader.h.

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

Filters map.

Definition at line 450 of file SessionReader.h.

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

Functions.

Definition at line 444 of file SessionReader.h.

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

Geometric information properties.

Definition at line 438 of file SessionReader.h.

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

Parameters.

Definition at line 434 of file SessionReader.h.

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

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

Definition at line 430 of file SessionReader.h.

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

Solver information properties.

Definition at line 436 of file SessionReader.h.

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

Custom tags.

Definition at line 448 of file SessionReader.h.

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

Variables.

Definition at line 446 of file SessionReader.h.

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

Be verbose.

Definition at line 452 of file SessionReader.h.

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

Pointer to the loaded XML document.

Definition at line 432 of file SessionReader.h.