43 namespace SpatialDomains
46 : m_meshGraph(meshGraph),
68 ASSERTL0(conditions,
"Unable to find CONDITIONS tag in file.");
70 TiXmlElement *boundaryRegions = conditions->FirstChildElement(
"BOUNDARYREGIONS");
92 TiXmlElement *boundaryRegions = conditions->FirstChildElement(
"BOUNDARYREGIONS");
93 ASSERTL0(boundaryRegions,
"Unable to find BOUNDARYREGIONS block.");
96 TiXmlElement *boundaryRegionsElement = boundaryRegions->FirstChildElement(
"B");
98 while (boundaryRegionsElement)
103 int err = boundaryRegionsElement->QueryIntAttribute(
"ID", &indx);
104 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
106 TiXmlNode* boundaryRegionChild = boundaryRegionsElement->FirstChild();
111 while(boundaryRegionChild && boundaryRegionChild->Type() != TiXmlNode::TEXT)
113 boundaryRegionChild = boundaryRegionChild->NextSibling();
116 ASSERTL0(boundaryRegionChild,
"Unable to read variable definition body.");
117 std::string boundaryRegionStr = boundaryRegionChild->ToText()->ValueStr();
119 std::string::size_type indxBeg = boundaryRegionStr.find_first_of(
'[') + 1;
120 std::string::size_type indxEnd = boundaryRegionStr.find_last_of(
']') - 1;
122 ASSERTL0(indxBeg <= indxEnd, (std::string(
"Error reading boundary region definition:") + boundaryRegionStr).c_str());
124 std::string indxStr = boundaryRegionStr.substr(indxBeg, indxEnd - indxBeg + 1);
126 if (!indxStr.empty())
132 "Boundary region "+indxStr+
" defined more than "
135 m_meshGraph->GetCompositeList(indxStr, *boundaryRegion);
139 boundaryRegionsElement = boundaryRegionsElement->NextSiblingElement(
"B");
156 TiXmlElement *boundaryConditionsElement = conditions->FirstChildElement(
"BOUNDARYCONDITIONS");
157 ASSERTL0(boundaryConditionsElement,
"Boundary conditions must be specified.");
159 TiXmlElement *regionElement = boundaryConditionsElement->FirstChildElement(
"REGION");
162 while (regionElement)
166 int boundaryRegionID;
167 int err = regionElement->QueryIntAttribute(
"REF", &boundaryRegionID);
168 ASSERTL0(err == TIXML_SUCCESS,
"Error reading boundary region reference.");
171 std::string boundaryRegionIDStr;
172 std::ostringstream boundaryRegionIDStrm(boundaryRegionIDStr);
173 boundaryRegionIDStrm << boundaryRegionID;
176 "Boundary region " + boost::lexical_cast<
177 string>(boundaryRegionID)+
" not found");
179 TiXmlElement *conditionElement = regionElement->FirstChildElement();
180 std::vector<std::string> vars =
m_session->GetVariables();
182 while (conditionElement)
185 std::string conditionType = conditionElement->Value();
186 std::string attrData;
189 TiXmlAttribute *attr = conditionElement->FirstAttribute();
192 std::string attrName;
194 attrData = conditionElement->Attribute(
"VAR");
196 if (!attrData.empty())
198 iter =
std::find(vars.begin(), vars.end(), attrData);
199 ASSERTL0(iter != vars.end(), (std::string(
"Cannot find variable: ") + attrData).c_str());
202 if (conditionType ==
"N")
204 if (attrData.empty())
208 varIter != vars.end(); ++varIter)
211 (*boundaryConditions)[*varIter] = neumannCondition;
221 std::string equation, userDefined, filename;
226 attrName = attr->Name();
228 if (attrName==
"USERDEFINEDTYPE")
232 attrData = attr->Value();
233 ASSERTL0(!attrData.empty(),
"USERDEFINEDTYPE attribute must have associated value.");
236 m_session->SubstituteExpressions(attrData);
238 userDefined = attrData;
240 else if(attrName==
"VALUE")
242 ASSERTL0(attrName ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName).c_str());
244 attrData = attr->Value();
245 ASSERTL0(!attrData.empty(),
"VALUE attribute must be specified.");
247 m_session->SubstituteExpressions(attrData);
251 else if(attrName==
"FILE")
253 ASSERTL0(attrName ==
"FILE", (std::string(
"Unknown attribute: ") + attrName).c_str());
255 attrData = attr->Value();
256 ASSERTL0(!attrData.empty(),
"FILE attribute must be specified.");
258 m_session->SubstituteExpressions(attrData);
265 (*boundaryConditions)[*iter] = neumannCondition;
271 (*boundaryConditions)[*iter] = neumannCondition;
275 else if (conditionType ==
"D")
277 if (attrData.empty())
281 varIter != vars.end(); ++varIter)
284 (*boundaryConditions)[*varIter] = dirichletCondition;
294 std::string equation, userDefined, filename;
298 attrName = attr->Name();
300 if (attrName==
"USERDEFINEDTYPE") {
303 attrData = attr->Value();
304 ASSERTL0(!attrData.empty(),
"USERDEFINEDTYPE attribute must have associated value.");
306 m_session->SubstituteExpressions(attrData);
308 userDefined = attrData;
310 else if(attrName==
"VALUE")
312 ASSERTL0(attrName ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName).c_str());
314 attrData = attr->Value();
315 ASSERTL0(!attrData.empty(),
"VALUE attribute must have associated value.");
317 m_session->SubstituteExpressions(attrData);
321 else if(attrName==
"FILE")
323 ASSERTL0(attrName ==
"FILE", (std::string(
"Unknown attribute: ") + attrName).c_str());
325 attrData = attr->Value();
326 ASSERTL0(!attrData.empty(),
"FILE attribute must be specified.");
328 m_session->SubstituteExpressions(attrData);
336 (*boundaryConditions)[*iter] = dirichletCondition;
342 (*boundaryConditions)[*iter] = dirichletCondition;
346 else if (conditionType ==
"R")
348 if (attrData.empty())
352 varIter != vars.end(); ++varIter)
355 (*boundaryConditions)[*varIter] = robinCondition;
367 std::string attrName1;
368 std::string attrData1;
369 std::string equation1, equation2, userDefined;
370 std::string filename;
374 attrName1 = attr->Name();
376 if (attrName1==
"USERDEFINEDTYPE") {
379 attrData1 = attr->Value();
380 ASSERTL0(!attrData1.empty(),
"USERDEFINEDTYPE attribute must have associated value.");
382 m_session->SubstituteExpressions(attrData1);
384 userDefined = attrData1;
387 else if(attrName1 ==
"VALUE"){
389 ASSERTL0(attrName1 ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName1).c_str());
391 attrData1 = attr->Value();
392 ASSERTL0(!attrData1.empty(),
"VALUE attributes must have associated values.");
394 m_session->SubstituteExpressions(attrData1);
396 equation1 = attrData1;
399 ASSERTL0(attr,
"Unable to read PRIMCOEFF attribute.");
401 attrName1= attr->Name();
402 ASSERTL0(attrName1 ==
"PRIMCOEFF", (std::string(
"Unknown attribute: ") + attrName1).c_str());
404 attrData1 = attr->Value();
405 ASSERTL0(!attrData1.empty(),
"PRIMCOEFF attributes must have associated values.");
407 m_session->SubstituteExpressions(attrData1);
409 equation2 = attrData1;
412 else if(attrName1==
"FILE")
414 ASSERTL0(attrName1 ==
"FILE", (std::string(
"Unknown attribute: ") + attrName1).c_str());
416 attrData1 = attr->Value();
417 ASSERTL0(!attrData1.empty(),
"FILE attribute must be specified.");
419 m_session->SubstituteExpressions(attrData1);
421 filename = attrData1;
428 (*boundaryConditions)[*iter] = robinCondition;
434 (*boundaryConditions)[*iter] = robinCondition;
438 else if (conditionType ==
"P")
440 if (attrData.empty())
446 attrName = attr->Name();
448 ASSERTL0(attrName ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName).c_str());
450 attrData = attr->Value();
451 ASSERTL0(!attrData.empty(),
"VALUE attribute must have associated value.");
453 int beg = attrData.find_first_of(
"[");
454 int end = attrData.find_first_of(
"]");
455 std::string periodicBndRegionIndexStr = attrData.substr(beg+1,end-beg-1);
456 ASSERTL0(beg < end, (std::string(
"Error reading periodic boundary region definition for boundary region: ")
457 + boundaryRegionIDStrm.str()).c_str());
459 vector<unsigned int> periodicBndRegionIndex;
462 ASSERTL0(parseGood && (periodicBndRegionIndex.size()==1), (std::string(
"Unable to read periodic boundary condition for boundary region: ")
463 + boundaryRegionIDStrm.str()).c_str());
468 varIter != vars.end(); ++varIter)
470 (*boundaryConditions)[*varIter] = periodicCondition;
475 ASSERTL0(
false,
"Periodic boundary conditions should be explicitely defined");
486 attrName = attr->Name();
488 ASSERTL0(attrName ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName).c_str());
490 attrData = attr->Value();
491 ASSERTL0(!attrData.empty(),
"VALUE attribute must have associated value.");
493 int beg = attrData.find_first_of(
"[");
494 int end = attrData.find_first_of(
"]");
495 std::string periodicBndRegionIndexStr = attrData.substr(beg+1,end-beg-1);
496 ASSERTL0(beg < end, (std::string(
"Error reading periodic boundary region definition for boundary region: ") + boundaryRegionIDStrm.str()).c_str());
498 vector<unsigned int> periodicBndRegionIndex;
501 ASSERTL0(parseGood && (periodicBndRegionIndex.size()==1), (std::string(
"Unable to read periodic boundary condition for boundary region: ") + boundaryRegionIDStrm.str()).c_str());
504 (*boundaryConditions)[*iter] = periodicCondition;
508 ASSERTL0(
false,
"Periodic boundary conditions should be explicitely defined");
512 else if (conditionType ==
"C")
517 conditionElement = conditionElement->NextSiblingElement();
521 regionElement = regionElement->NextSiblingElement(
"REGION");