45 namespace SpatialDomains
50 BoundaryConditions::BoundaryConditions(
53 m_meshGraph(meshGraph), m_session(pSession)
73 std::set<int>::const_iterator it = set.begin(), end = set.end();
74 for (
int i = 0; it != end; ++it, ++i)
96 BoundaryRegionCollection::const_iterator it =
97 boundaryRegions.begin(), end = boundaryRegions.end();
99 for (; it != end; ++it, ++i)
100 ids.insert(it->first);
102 int np = comm->GetSize();
103 int ip = comm->GetRank();
106 bool involved =
true;
107 while (involved && half_size < np)
114 int receiver = ip - half_size;
119 sender_size[0] = idsArray.num_elements();
120 comm->Send(receiver, sender_size);
123 comm->Send(receiver, idsArray);
133 int sender = ip + half_size;
139 comm->Recv(sender, sender_size);
143 comm->Recv(sender, other_ids);
146 ids.insert(other_ids.begin(), other_ids.end());
157 comm->Bcast(nIds, 0);
166 comm->Bcast(idsArray, 0);
168 return std::set<int>(idsArray.begin(), idsArray.end());
181 std::set<int>::const_iterator it = allids.begin(), end =
183 for (; it != end; ++it)
189 this_rank_participates);
191 ASSERTL0(
bool(comm_region) ==
bool(this_rank_participates),
192 "Rank should be in communicator but wasn't or is in "
193 "communicator but shouldn't be.");
195 if (this_rank_participates)
207 ASSERTL0(conditions,
"Unable to find CONDITIONS tag in file.");
209 TiXmlElement *boundaryRegions = conditions->FirstChildElement(
231 TiXmlElement *boundaryRegions = conditions->FirstChildElement(
233 ASSERTL0(boundaryRegions,
"Unable to find BOUNDARYREGIONS block.");
236 TiXmlElement *boundaryRegionsElement =
237 boundaryRegions->FirstChildElement(
"B");
239 while (boundaryRegionsElement)
244 int err = boundaryRegionsElement->QueryIntAttribute(
"ID",
246 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
248 TiXmlNode* boundaryRegionChild =
249 boundaryRegionsElement->FirstChild();
254 while (boundaryRegionChild
255 && boundaryRegionChild->Type()
256 != TiXmlNode::TINYXML_TEXT)
258 boundaryRegionChild = boundaryRegionChild->NextSibling();
262 "Unable to read variable definition body.");
263 std::string boundaryRegionStr =
264 boundaryRegionChild->ToText()->ValueStr();
266 std::string::size_type indxBeg =
267 boundaryRegionStr.find_first_of(
'[') + 1;
268 std::string::size_type indxEnd = boundaryRegionStr.find_last_of(
273 "Error reading boundary region definition:")
274 + boundaryRegionStr).c_str());
276 std::string indxStr = boundaryRegionStr.substr(indxBeg,
277 indxEnd - indxBeg + 1);
279 if (!indxStr.empty())
286 "Boundary region " + indxStr +
" defined more than "
289 m_meshGraph->GetCompositeList(indxStr, *boundaryRegion);
293 boundaryRegionsElement =
294 boundaryRegionsElement->NextSiblingElement(
"B");
302 TiXmlElement *conditions)
311 TiXmlElement *boundaryConditionsElement =
312 conditions->FirstChildElement(
"BOUNDARYCONDITIONS");
314 "Boundary conditions must be specified.");
316 TiXmlElement *regionElement =
317 boundaryConditionsElement->FirstChildElement(
"REGION");
320 while (regionElement)
325 int boundaryRegionID;
326 int err = regionElement->QueryIntAttribute(
"REF",
329 "Error reading boundary region reference.");
332 "Boundary region '" + boost::lexical_cast < std::string
334 +
"' appears multiple times.");
337 std::string boundaryRegionIDStr;
338 std::ostringstream boundaryRegionIDStrm(boundaryRegionIDStr);
339 boundaryRegionIDStrm << boundaryRegionID;
342 "Boundary region " + boost::lexical_cast <
string
343 > (boundaryRegionID) +
" not found");
349 TiXmlElement *conditionElement =
350 regionElement->FirstChildElement();
351 std::vector < std::string > vars =
m_session->GetVariables();
353 while (conditionElement)
356 std::string conditionType = conditionElement->Value();
357 std::string attrData;
358 bool isTimeDependent =
false;
361 TiXmlAttribute *attr = conditionElement->FirstAttribute();
364 std::string attrName;
366 attrData = conditionElement->Attribute(
"VAR");
368 if (!attrData.empty())
370 iter =
std::find(vars.begin(), vars.end(), attrData);
372 (std::string(
"Cannot find variable: ")
373 + attrData).c_str());
376 if (conditionType ==
"N")
378 if (attrData.empty())
382 vars.begin(); varIter != vars.end();
388 (*boundaryConditions)[*varIter] =
399 std::string equation, userDefined, filename;
404 attrName = attr->Name();
406 if (attrName ==
"USERDEFINEDTYPE")
409 attrData = attr->Value();
411 "USERDEFINEDTYPE attribute must have associated value.");
417 userDefined = attrData;
418 isTimeDependent = boost::iequals(attrData,
"TimeDependent");
420 else if (attrName ==
"VALUE")
424 "Unknown attribute: ")
425 + attrName).c_str());
427 attrData = attr->Value();
429 "VALUE attribute must be specified.");
436 else if (attrName ==
"FILE")
440 "Unknown attribute: ")
441 + attrName).c_str());
443 attrData = attr->Value();
445 "FILE attribute must be specified.");
455 (std::string(
"Unknown boundary condition attribute: ") + attrName).c_str());
463 userDefined, filename,
464 boundaryRegionComm));
465 neumannCondition->SetIsTimeDependent(isTimeDependent);
466 (*boundaryConditions)[*iter] = neumannCondition;
474 (*boundaryConditions)[*iter] = neumannCondition;
478 else if (conditionType ==
"D")
480 if (attrData.empty())
484 vars.begin(); varIter != vars.end();
490 (*boundaryConditions)[*varIter] =
501 std::string equation, userDefined, filename;
506 attrName = attr->Name();
508 if (attrName ==
"USERDEFINEDTYPE")
512 attrData = attr->Value();
514 "USERDEFINEDTYPE attribute must have associated value.");
519 userDefined = attrData;
520 isTimeDependent = boost::iequals(attrData,
"TimeDependent");
522 else if (attrName ==
"VALUE")
526 "Unknown attribute: ")
527 + attrName).c_str());
529 attrData = attr->Value();
531 "VALUE attribute must have associated value.");
538 else if (attrName ==
"FILE")
542 "Unknown attribute: ")
543 + attrName).c_str());
545 attrData = attr->Value();
547 "FILE attribute must be specified.");
557 (std::string(
"Unknown boundary condition attribute: ") + attrName).c_str());
565 userDefined, filename,
566 boundaryRegionComm));
567 dirichletCondition->SetIsTimeDependent(isTimeDependent);
568 (*boundaryConditions)[*iter] =
577 (*boundaryConditions)[*iter] =
582 else if (conditionType ==
"R")
584 if (attrData.empty())
588 vars.begin(); varIter != vars.end();
594 (*boundaryConditions)[*varIter] =
607 std::string attrName1;
608 std::string attrData1;
609 std::string equation1, equation2, userDefined;
610 std::string filename;
612 bool primcoeffset =
false;
616 attrName1 = attr->Name();
618 if (attrName1==
"USERDEFINEDTYPE") {
621 attrData1 = attr->Value();
622 ASSERTL0(!attrData1.empty(),
"USERDEFINEDTYPE attribute must have associated value.");
624 m_session->SubstituteExpressions(attrData1);
625 userDefined = attrData1;
626 isTimeDependent = boost::iequals(attrData,
"TimeDependent");
628 else if(attrName1 ==
"VALUE"){
630 attrData1 = attr->Value();
631 ASSERTL0(!attrData1.empty(),
"VALUE attributes must have associated values.");
633 m_session->SubstituteExpressions(attrData1);
635 equation1 = attrData1;
637 else if(attrName1 ==
"PRIMCOEFF")
640 attrData1 = attr->Value();
641 ASSERTL0(!attrData1.empty(),
"PRIMCOEFF attributes must have associated values.");
643 m_session->SubstituteExpressions(attrData1);
645 equation2 = attrData1;
649 else if(attrName1==
"FILE")
651 attrData1 = attr->Value();
652 ASSERTL0(!attrData1.empty(),
"FILE attribute must be specified.");
654 m_session->SubstituteExpressions(attrData1);
656 filename = attrData1;
660 ASSERTL0(
false, (std::string(
"Unknown boundary condition attribute: ") + attrName1).c_str());
666 if(primcoeffset ==
false)
668 ASSERTL0(
false,
"PRIMCOEFF must be specified in a Robin boundary condition");
673 userDefined, filename,
674 boundaryRegionComm));
675 (*boundaryConditions)[*iter] = robinCondition;
683 robinCondition->SetIsTimeDependent(isTimeDependent);
684 (*boundaryConditions)[*iter] = robinCondition;
688 else if (conditionType ==
"P")
690 if (attrData.empty())
696 attrName = attr->Name();
699 (std::string(
"Unknown attribute: ")
700 + attrName).c_str());
702 attrData = attr->Value();
704 "VALUE attribute must have associated value.");
706 int beg = attrData.find_first_of(
"[");
707 int end = attrData.find_first_of(
"]");
708 std::string periodicBndRegionIndexStr =
709 attrData.substr(beg + 1, end - beg - 1);
712 "Error reading periodic boundary region definition for boundary region: ")
713 + boundaryRegionIDStrm.str()).c_str());
715 vector<unsigned int> periodicBndRegionIndex;
717 periodicBndRegionIndexStr.c_str(),
718 periodicBndRegionIndex);
722 && (periodicBndRegionIndex.size()
725 "Unable to read periodic boundary condition for boundary region: ")
726 + boundaryRegionIDStrm.str()).c_str());
730 periodicBndRegionIndex[0]));
733 vars.begin(); varIter != vars.end();
736 (*boundaryConditions)[*varIter] =
743 "Periodic boundary conditions should be explicitely defined");
754 attrName = attr->Name();
757 (std::string(
"Unknown attribute: ")
758 + attrName).c_str());
760 attrData = attr->Value();
762 "VALUE attribute must have associated value.");
764 int beg = attrData.find_first_of(
"[");
765 int end = attrData.find_first_of(
"]");
766 std::string periodicBndRegionIndexStr =
767 attrData.substr(beg + 1, end - beg - 1);
770 "Error reading periodic boundary "
771 "region definition for boundary "
773 + boundaryRegionIDStrm.str())
776 vector<unsigned int> periodicBndRegionIndex;
778 periodicBndRegionIndexStr.c_str(),
779 periodicBndRegionIndex);
782 periodicBndRegionIndex.size() == 1,
784 "Unable to read periodic boundary "
785 "condition for boundary region: "
786 + boundaryRegionIDStrm.str()))
791 periodicBndRegionIndex[0]));
792 (*boundaryConditions)[*iter] =
798 "Periodic boundary conditions should be explicitely defined");
802 else if (conditionType ==
"C")
804 ASSERTL0(
false,
"Cauchy type boundary conditions not "
808 conditionElement = conditionElement->NextSiblingElement();
812 regionElement = regionElement->NextSiblingElement(
"REGION");
#define ASSERTL0(condition, msg)
BoundaryRegionCollection m_boundaryRegions
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
void CreateBoundaryComms()
std::map< int, LibUtilities::CommSharedPtr > m_boundaryCommunicators
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
static bool GenerateSeqVector(const char *const str, std::vector< unsigned int > &vec)
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Array< OneD, int > ToArray(const std::set< int > &set)
std::map< int, BoundaryRegionShPtr > BoundaryRegionCollection
std::set< int > ShareAllBoundaryIDs(const BoundaryRegionCollection &boundaryRegions, LibUtilities::CommSharedPtr comm)
std::map< std::string, BoundaryConditionShPtr > BoundaryConditionMap
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
void ReadBoundaryRegions(TiXmlElement *regions)
void Read(TiXmlElement *conditions)
Read segments (and general MeshGraph) given TiXmlDocument.
boost::shared_ptr< BoundaryConditionMap > BoundaryConditionMapShPtr
LibUtilities::SessionReaderSharedPtr m_session
BoundaryConditionCollection m_boundaryConditions
~BoundaryConditions(void)
MeshGraphSharedPtr m_meshGraph
The mesh graph to use for referencing geometry info.
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
boost::shared_ptr< BoundaryConditionBase > BoundaryConditionShPtr
void ReadBoundaryConditions(TiXmlElement *conditions)
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
boost::shared_ptr< BoundaryRegion > BoundaryRegionShPtr