Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
Nektar::SpatialDomains::BoundaryConditions Class Reference

#include <Conditions.h>

Collaboration diagram for Nektar::SpatialDomains::BoundaryConditions:
Collaboration graph
[legend]

Public Member Functions

 BoundaryConditions (const LibUtilities::SessionReaderSharedPtr &pSession, const MeshGraphSharedPtr &meshGraph)
 BoundaryConditions (void)
 ~BoundaryConditions (void)
const BoundaryRegionCollectionGetBoundaryRegions (void) const
void AddBoundaryRegions (const int regionID, BoundaryRegionShPtr &bRegion)
const BoundaryConditionCollectionGetBoundaryConditions (void) const
void AddBoundaryConditions (const int regionID, BoundaryConditionMapShPtr &bCond)
const std::string GetVariable (unsigned int indx)

Protected Attributes

MeshGraphSharedPtr m_meshGraph
 The mesh graph to use for referencing geometry info.
LibUtilities::SessionReaderSharedPtr m_session
BoundaryRegionCollection m_boundaryRegions
BoundaryConditionCollection m_boundaryConditions

Private Member Functions

void Read (TiXmlElement *conditions)
 Read segments (and general MeshGraph) given TiXmlDocument.
void ReadBoundaryRegions (TiXmlElement *regions)
void ReadBoundaryConditions (TiXmlElement *conditions)

Detailed Description

Definition at line 299 of file Conditions.h.

Constructor & Destructor Documentation

Nektar::SpatialDomains::BoundaryConditions::BoundaryConditions ( const LibUtilities::SessionReaderSharedPtr pSession,
const MeshGraphSharedPtr meshGraph 
)

Definition at line 45 of file Conditions.cpp.

References m_session, and Read().

: m_meshGraph(meshGraph),
m_session (pSession)
{
Read(m_session->GetElement("Nektar/Conditions"));
}
Nektar::SpatialDomains::BoundaryConditions::BoundaryConditions ( void  )

Definition at line 54 of file Conditions.cpp.

{
}
Nektar::SpatialDomains::BoundaryConditions::~BoundaryConditions ( void  )

Definition at line 58 of file Conditions.cpp.

{
}

Member Function Documentation

void Nektar::SpatialDomains::BoundaryConditions::AddBoundaryConditions ( const int  regionID,
BoundaryConditionMapShPtr bCond 
)
inline

Definition at line 323 of file Conditions.h.

References m_boundaryConditions.

{
m_boundaryConditions[regionID] = bCond;
}
void Nektar::SpatialDomains::BoundaryConditions::AddBoundaryRegions ( const int  regionID,
BoundaryRegionShPtr bRegion 
)
inline

Definition at line 312 of file Conditions.h.

References m_boundaryRegions.

{
m_boundaryRegions[regionID] = bRegion;
}
const BoundaryConditionCollection& Nektar::SpatialDomains::BoundaryConditions::GetBoundaryConditions ( void  ) const
inline
const BoundaryRegionCollection& Nektar::SpatialDomains::BoundaryConditions::GetBoundaryRegions ( void  ) const
inline
const std::string Nektar::SpatialDomains::BoundaryConditions::GetVariable ( unsigned int  indx)
inline

Definition at line 328 of file Conditions.h.

References m_session.

{
return m_session->GetVariable(indx);
}
void Nektar::SpatialDomains::BoundaryConditions::Read ( TiXmlElement *  conditions)
private

Read segments (and general MeshGraph) given TiXmlDocument.

Definition at line 66 of file Conditions.cpp.

References ASSERTL0, ReadBoundaryConditions(), and ReadBoundaryRegions().

Referenced by BoundaryConditions().

{
ASSERTL0(conditions, "Unable to find CONDITIONS tag in file.");
TiXmlElement *boundaryRegions = conditions->FirstChildElement("BOUNDARYREGIONS");
if(boundaryRegions)
{
ReadBoundaryRegions(conditions);
}
}
void Nektar::SpatialDomains::BoundaryConditions::ReadBoundaryConditions ( TiXmlElement *  conditions)
private

Definition at line 147 of file Conditions.cpp.

References ASSERTL0, ErrorUtil::ewarning, Nektar::StdRegions::find(), Nektar::ParseUtils::GenerateSeqVector(), Nektar::iterator, m_boundaryConditions, m_boundaryRegions, m_session, and NEKERROR.

Referenced by Read().

{
// Protect against multiple reads.
if(m_boundaryConditions.size() != 0)
{
return;
}
// Read REGION tags
TiXmlElement *boundaryConditionsElement = conditions->FirstChildElement("BOUNDARYCONDITIONS");
ASSERTL0(boundaryConditionsElement, "Boundary conditions must be specified.");
TiXmlElement *regionElement = boundaryConditionsElement->FirstChildElement("REGION");
// Read R (Robin), D (Dirichlet), N (Neumann), P (Periodic) C(Cauchy) tags
while (regionElement)
{
BoundaryConditionMapShPtr boundaryConditions = MemoryManager<BoundaryConditionMap>::AllocateSharedPtr();
int boundaryRegionID;
int err = regionElement->QueryIntAttribute("REF", &boundaryRegionID);
ASSERTL0(err == TIXML_SUCCESS, "Error reading boundary region reference.");
// Find the boundary region corresponding to this ID.
std::string boundaryRegionIDStr;
std::ostringstream boundaryRegionIDStrm(boundaryRegionIDStr);
boundaryRegionIDStrm << boundaryRegionID;
ASSERTL0(m_boundaryRegions.count(boundaryRegionID) == 1,
"Boundary region " + boost::lexical_cast<
string>(boundaryRegionID)+ " not found");
TiXmlElement *conditionElement = regionElement->FirstChildElement();
std::vector<std::string> vars = m_session->GetVariables();
while (conditionElement)
{
// Check type.
std::string conditionType = conditionElement->Value();
std::string attrData;
// All have var specified, or else all variables are zero.
TiXmlAttribute *attr = conditionElement->FirstAttribute();
std::string attrName;
attrData = conditionElement->Attribute("VAR");
if (!attrData.empty())
{
iter = std::find(vars.begin(), vars.end(), attrData);
ASSERTL0(iter != vars.end(), (std::string("Cannot find variable: ") + attrData).c_str());
}
if (conditionType == "N")
{
if (attrData.empty())
{
// All variables are Neumann and are set to zero.
for (std::vector<std::string>::iterator varIter = vars.begin();
varIter != vars.end(); ++varIter)
{
BoundaryConditionShPtr neumannCondition(MemoryManager<NeumannBoundaryCondition>::AllocateSharedPtr(m_session,"00.0"));
(*boundaryConditions)[*varIter] = neumannCondition;
}
}
else
{
// Use the iterator from above, which must point to the variable.
attr = attr->Next();
if (attr)
{
std::string equation, userDefined, filename;
while(attr)
{
attrName = attr->Name();
if (attrName=="USERDEFINEDTYPE")
{
// Do stuff for the user defined attribute
attrData = attr->Value();
ASSERTL0(!attrData.empty(), "USERDEFINEDTYPE attribute must have associated value.");
// Suppose to go here?
m_session->SubstituteExpressions(attrData);
userDefined = attrData;
}
else if(attrName=="VALUE")
{
ASSERTL0(attrName == "VALUE", (std::string("Unknown attribute: ") + attrName).c_str());
attrData = attr->Value();
ASSERTL0(!attrData.empty(), "VALUE attribute must be specified.");
m_session->SubstituteExpressions(attrData);
equation = attrData;
}
else if(attrName=="FILE")
{
ASSERTL0(attrName == "FILE", (std::string("Unknown attribute: ") + attrName).c_str());
attrData = attr->Value();
ASSERTL0(!attrData.empty(), "FILE attribute must be specified.");
m_session->SubstituteExpressions(attrData);
filename = attrData;
}
attr = attr->Next();
}
BoundaryConditionShPtr neumannCondition(MemoryManager<NeumannBoundaryCondition>::AllocateSharedPtr(m_session, equation, userDefined, filename));
(*boundaryConditions)[*iter] = neumannCondition;
}
else
{
// This variable's condition is zero.
BoundaryConditionShPtr neumannCondition(MemoryManager<NeumannBoundaryCondition>::AllocateSharedPtr(m_session, "0"));
(*boundaryConditions)[*iter] = neumannCondition;
}
}
}
else if (conditionType == "D")
{
if (attrData.empty())
{
// All variables are Dirichlet and are set to zero.
for (std::vector<std::string>::iterator varIter = vars.begin();
varIter != vars.end(); ++varIter)
{
BoundaryConditionShPtr dirichletCondition(MemoryManager<DirichletBoundaryCondition>::AllocateSharedPtr(m_session, "0"));
(*boundaryConditions)[*varIter] = dirichletCondition;
}
}
else
{
// Use the iterator from above, which must point to the variable.
attr = attr->Next();
if (attr)
{
std::string equation, userDefined, filename;
while(attr) {
attrName = attr->Name();
if (attrName=="USERDEFINEDTYPE") {
// Do stuff for the user defined attribute
attrData = attr->Value();
ASSERTL0(!attrData.empty(), "USERDEFINEDTYPE attribute must have associated value.");
m_session->SubstituteExpressions(attrData);
userDefined = attrData;
}
else if(attrName=="VALUE")
{
ASSERTL0(attrName == "VALUE", (std::string("Unknown attribute: ") + attrName).c_str());
attrData = attr->Value();
ASSERTL0(!attrData.empty(), "VALUE attribute must have associated value.");
m_session->SubstituteExpressions(attrData);
equation = attrData;
}
else if(attrName=="FILE")
{
ASSERTL0(attrName == "FILE", (std::string("Unknown attribute: ") + attrName).c_str());
attrData = attr->Value();
ASSERTL0(!attrData.empty(), "FILE attribute must be specified.");
m_session->SubstituteExpressions(attrData);
filename = attrData;
}
attr = attr->Next();
}
BoundaryConditionShPtr dirichletCondition(MemoryManager<DirichletBoundaryCondition>::AllocateSharedPtr(m_session, equation, userDefined, filename));
(*boundaryConditions)[*iter] = dirichletCondition;
}
else
{
// This variable's condition is zero.
BoundaryConditionShPtr dirichletCondition(MemoryManager<DirichletBoundaryCondition>::AllocateSharedPtr(m_session, "0"));
(*boundaryConditions)[*iter] = dirichletCondition;
}
}
}
else if (conditionType == "R") // Read du/dn + PRIMCOEFF u = VALUE
{
if (attrData.empty())
{
// All variables are Robin and are set to zero.
for (std::vector<std::string>::iterator varIter = vars.begin();
varIter != vars.end(); ++varIter)
{
BoundaryConditionShPtr robinCondition(MemoryManager<RobinBoundaryCondition>::AllocateSharedPtr(m_session, "0", "0"));
(*boundaryConditions)[*varIter] = robinCondition;
}
}
else
{
// Use the iterator from above, which must
// point to the variable. Read the A and
// B attributes.
attr = attr->Next();
if (attr)
{
std::string attrName1;
std::string attrData1;
std::string equation1, equation2, userDefined;
std::string filename;
while(attr){
attrName1 = attr->Name();
if (attrName1=="USERDEFINEDTYPE") {
// Do stuff for the user defined attribute
attrData1 = attr->Value();
ASSERTL0(!attrData1.empty(), "USERDEFINEDTYPE attribute must have associated value.");
m_session->SubstituteExpressions(attrData1);
userDefined = attrData1;
}
else if(attrName1 == "VALUE"){
ASSERTL0(attrName1 == "VALUE", (std::string("Unknown attribute: ") + attrName1).c_str());
attrData1 = attr->Value();
ASSERTL0(!attrData1.empty(), "VALUE attributes must have associated values.");
m_session->SubstituteExpressions(attrData1);
equation1 = attrData1;
attr = attr->Next();
ASSERTL0(attr, "Unable to read PRIMCOEFF attribute.");
attrName1= attr->Name();
ASSERTL0(attrName1 == "PRIMCOEFF", (std::string("Unknown attribute: ") + attrName1).c_str());
attrData1 = attr->Value();
ASSERTL0(!attrData1.empty(), "PRIMCOEFF attributes must have associated values.");
m_session->SubstituteExpressions(attrData1);
equation2 = attrData1;
}
else if(attrName1=="FILE")
{
ASSERTL0(attrName1 == "FILE", (std::string("Unknown attribute: ") + attrName1).c_str());
attrData1 = attr->Value();
ASSERTL0(!attrData1.empty(), "FILE attribute must be specified.");
m_session->SubstituteExpressions(attrData1);
filename = attrData1;
}
attr = attr->Next();
}
BoundaryConditionShPtr robinCondition(MemoryManager<RobinBoundaryCondition>::AllocateSharedPtr(m_session, equation1, equation2, userDefined, filename));
(*boundaryConditions)[*iter] = robinCondition;
}
else
{
// This variable's condition is zero.
BoundaryConditionShPtr robinCondition(MemoryManager<RobinBoundaryCondition>::AllocateSharedPtr(m_session, "0", "0"));
(*boundaryConditions)[*iter] = robinCondition;
}
}
}
else if (conditionType == "P")
{
if (attrData.empty())
{
attr = attr->Next();
if (attr)
{
attrName = attr->Name();
ASSERTL0(attrName == "VALUE", (std::string("Unknown attribute: ") + attrName).c_str());
attrData = attr->Value();
ASSERTL0(!attrData.empty(), "VALUE attribute must have associated value.");
int beg = attrData.find_first_of("[");
int end = attrData.find_first_of("]");
std::string periodicBndRegionIndexStr = attrData.substr(beg+1,end-beg-1);
ASSERTL0(beg < end, (std::string("Error reading periodic boundary region definition for boundary region: ")
+ boundaryRegionIDStrm.str()).c_str());
vector<unsigned int> periodicBndRegionIndex;
bool parseGood = ParseUtils::GenerateSeqVector(periodicBndRegionIndexStr.c_str(), periodicBndRegionIndex);
ASSERTL0(parseGood && (periodicBndRegionIndex.size()==1), (std::string("Unable to read periodic boundary condition for boundary region: ")
+ boundaryRegionIDStrm.str()).c_str());
BoundaryConditionShPtr periodicCondition(MemoryManager<PeriodicBoundaryCondition>::AllocateSharedPtr(periodicBndRegionIndex[0]));
for (std::vector<std::string>::iterator varIter = vars.begin();
varIter != vars.end(); ++varIter)
{
(*boundaryConditions)[*varIter] = periodicCondition;
}
}
else
{
ASSERTL0(false, "Periodic boundary conditions should be explicitely defined");
}
}
else
{
// Use the iterator from above, which must point to the variable.
// Read the VALUE attribute. It is the next and only other attribute.
attr = attr->Next();
if (attr)
{
attrName = attr->Name();
ASSERTL0(attrName == "VALUE", (std::string("Unknown attribute: ") + attrName).c_str());
attrData = attr->Value();
ASSERTL0(!attrData.empty(), "VALUE attribute must have associated value.");
int beg = attrData.find_first_of("[");
int end = attrData.find_first_of("]");
std::string periodicBndRegionIndexStr = attrData.substr(beg+1,end-beg-1);
ASSERTL0(beg < end, (std::string("Error reading periodic boundary region definition for boundary region: ") + boundaryRegionIDStrm.str()).c_str());
vector<unsigned int> periodicBndRegionIndex;
bool parseGood = ParseUtils::GenerateSeqVector(periodicBndRegionIndexStr.c_str(), periodicBndRegionIndex);
ASSERTL0(parseGood && (periodicBndRegionIndex.size()==1), (std::string("Unable to read periodic boundary condition for boundary region: ") + boundaryRegionIDStrm.str()).c_str());
BoundaryConditionShPtr periodicCondition(MemoryManager<PeriodicBoundaryCondition>::AllocateSharedPtr(periodicBndRegionIndex[0]));
(*boundaryConditions)[*iter] = periodicCondition;
}
else
{
ASSERTL0(false, "Periodic boundary conditions should be explicitely defined");
}
}
}
else if (conditionType == "C")
{
NEKERROR(ErrorUtil::ewarning, "Cauchy type boundary conditions not implemented.");
}
conditionElement = conditionElement->NextSiblingElement();
}
m_boundaryConditions[boundaryRegionID] = boundaryConditions;
regionElement = regionElement->NextSiblingElement("REGION");
}
}
void Nektar::SpatialDomains::BoundaryConditions::ReadBoundaryRegions ( TiXmlElement *  regions)
private

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

Definition at line 84 of file Conditions.cpp.

References ASSERTL0, m_boundaryRegions, and m_meshGraph.

Referenced by Read().

{
// ensure boundary regions only read once per class definition
if(m_boundaryRegions.size() != 0)
{
return;
}
TiXmlElement *boundaryRegions = conditions->FirstChildElement("BOUNDARYREGIONS");
ASSERTL0(boundaryRegions, "Unable to find BOUNDARYREGIONS block.");
// See if we have boundary regions defined.
TiXmlElement *boundaryRegionsElement = boundaryRegions->FirstChildElement("B");
while (boundaryRegionsElement)
{
/// All elements are of the form: "<B ID="#"> ... </B>", with
/// ? being the element type.
int indx;
int err = boundaryRegionsElement->QueryIntAttribute("ID", &indx);
ASSERTL0(err == TIXML_SUCCESS, "Unable to read attribute ID.");
TiXmlNode* boundaryRegionChild = boundaryRegionsElement->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(boundaryRegionChild && boundaryRegionChild->Type() != TiXmlNode::TEXT)
{
boundaryRegionChild = boundaryRegionChild->NextSibling();
}
ASSERTL0(boundaryRegionChild, "Unable to read variable definition body.");
std::string boundaryRegionStr = boundaryRegionChild->ToText()->ValueStr();
std::string::size_type indxBeg = boundaryRegionStr.find_first_of('[') + 1;
std::string::size_type indxEnd = boundaryRegionStr.find_last_of(']') - 1;
ASSERTL0(indxBeg <= indxEnd, (std::string("Error reading boundary region definition:") + boundaryRegionStr).c_str());
std::string indxStr = boundaryRegionStr.substr(indxBeg, indxEnd - indxBeg + 1);
if (!indxStr.empty())
{
// Extract the composites from the string and return them in a list.
BoundaryRegionShPtr boundaryRegion(MemoryManager<BoundaryRegion>::AllocateSharedPtr());
ASSERTL0(m_boundaryRegions.count(indx) == 0,
"Boundary region "+indxStr+ " defined more than "
"once!");
m_meshGraph->GetCompositeList(indxStr, *boundaryRegion);
m_boundaryRegions[indx] = boundaryRegion;
}
boundaryRegionsElement = boundaryRegionsElement->NextSiblingElement("B");
}
}

Member Data Documentation

BoundaryConditionCollection Nektar::SpatialDomains::BoundaryConditions::m_boundaryConditions
protected
BoundaryRegionCollection Nektar::SpatialDomains::BoundaryConditions::m_boundaryRegions
protected
MeshGraphSharedPtr Nektar::SpatialDomains::BoundaryConditions::m_meshGraph
protected

The mesh graph to use for referencing geometry info.

Definition at line 335 of file Conditions.h.

Referenced by ReadBoundaryRegions().

LibUtilities::SessionReaderSharedPtr Nektar::SpatialDomains::BoundaryConditions::m_session
protected

Definition at line 336 of file Conditions.h.

Referenced by BoundaryConditions(), GetVariable(), and ReadBoundaryConditions().