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::TINYXML_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 "Boundary region '" + boost::lexical_cast<std::string>(boundaryRegionID)
172 +
"' appears multiple times.");
175 std::string boundaryRegionIDStr;
176 std::ostringstream boundaryRegionIDStrm(boundaryRegionIDStr);
177 boundaryRegionIDStrm << boundaryRegionID;
180 "Boundary region " + boost::lexical_cast<
181 string>(boundaryRegionID)+
" not found");
183 TiXmlElement *conditionElement = regionElement->FirstChildElement();
184 std::vector<std::string> vars =
m_session->GetVariables();
186 while (conditionElement)
189 std::string conditionType = conditionElement->Value();
190 std::string attrData;
193 TiXmlAttribute *attr = conditionElement->FirstAttribute();
196 std::string attrName;
198 attrData = conditionElement->Attribute(
"VAR");
200 if (!attrData.empty())
202 iter =
std::find(vars.begin(), vars.end(), attrData);
203 ASSERTL0(iter != vars.end(), (std::string(
"Cannot find variable: ") + attrData).c_str());
206 if (conditionType ==
"N")
208 if (attrData.empty())
212 varIter != vars.end(); ++varIter)
215 (*boundaryConditions)[*varIter] = neumannCondition;
225 std::string equation, userDefined, filename;
230 attrName = attr->Name();
232 if (attrName==
"USERDEFINEDTYPE")
236 attrData = attr->Value();
237 ASSERTL0(!attrData.empty(),
"USERDEFINEDTYPE attribute must have associated value.");
240 m_session->SubstituteExpressions(attrData);
242 userDefined = attrData;
244 else if(attrName==
"VALUE")
246 ASSERTL0(attrName ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName).c_str());
248 attrData = attr->Value();
249 ASSERTL0(!attrData.empty(),
"VALUE attribute must be specified.");
251 m_session->SubstituteExpressions(attrData);
255 else if(attrName==
"FILE")
257 ASSERTL0(attrName ==
"FILE", (std::string(
"Unknown attribute: ") + attrName).c_str());
259 attrData = attr->Value();
260 ASSERTL0(!attrData.empty(),
"FILE attribute must be specified.");
262 m_session->SubstituteExpressions(attrData);
269 (*boundaryConditions)[*iter] = neumannCondition;
275 (*boundaryConditions)[*iter] = neumannCondition;
279 else if (conditionType ==
"D")
281 if (attrData.empty())
285 varIter != vars.end(); ++varIter)
288 (*boundaryConditions)[*varIter] = dirichletCondition;
298 std::string equation, userDefined, filename;
302 attrName = attr->Name();
304 if (attrName==
"USERDEFINEDTYPE") {
307 attrData = attr->Value();
308 ASSERTL0(!attrData.empty(),
"USERDEFINEDTYPE attribute must have associated value.");
310 m_session->SubstituteExpressions(attrData);
312 userDefined = attrData;
314 else if(attrName==
"VALUE")
316 ASSERTL0(attrName ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName).c_str());
318 attrData = attr->Value();
319 ASSERTL0(!attrData.empty(),
"VALUE attribute must have associated value.");
321 m_session->SubstituteExpressions(attrData);
325 else if(attrName==
"FILE")
327 ASSERTL0(attrName ==
"FILE", (std::string(
"Unknown attribute: ") + attrName).c_str());
329 attrData = attr->Value();
330 ASSERTL0(!attrData.empty(),
"FILE attribute must be specified.");
332 m_session->SubstituteExpressions(attrData);
340 (*boundaryConditions)[*iter] = dirichletCondition;
346 (*boundaryConditions)[*iter] = dirichletCondition;
350 else if (conditionType ==
"R")
352 if (attrData.empty())
356 varIter != vars.end(); ++varIter)
359 (*boundaryConditions)[*varIter] = robinCondition;
371 std::string attrName1;
372 std::string attrData1;
373 std::string equation1, equation2, userDefined;
374 std::string filename;
378 attrName1 = attr->Name();
380 if (attrName1==
"USERDEFINEDTYPE") {
383 attrData1 = attr->Value();
384 ASSERTL0(!attrData1.empty(),
"USERDEFINEDTYPE attribute must have associated value.");
386 m_session->SubstituteExpressions(attrData1);
388 userDefined = attrData1;
391 else if(attrName1 ==
"VALUE"){
393 ASSERTL0(attrName1 ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName1).c_str());
395 attrData1 = attr->Value();
396 ASSERTL0(!attrData1.empty(),
"VALUE attributes must have associated values.");
398 m_session->SubstituteExpressions(attrData1);
400 equation1 = attrData1;
403 ASSERTL0(attr,
"Unable to read PRIMCOEFF attribute.");
405 attrName1= attr->Name();
406 ASSERTL0(attrName1 ==
"PRIMCOEFF", (std::string(
"Unknown attribute: ") + attrName1).c_str());
408 attrData1 = attr->Value();
409 ASSERTL0(!attrData1.empty(),
"PRIMCOEFF attributes must have associated values.");
411 m_session->SubstituteExpressions(attrData1);
413 equation2 = attrData1;
416 else if(attrName1==
"FILE")
418 ASSERTL0(attrName1 ==
"FILE", (std::string(
"Unknown attribute: ") + attrName1).c_str());
420 attrData1 = attr->Value();
421 ASSERTL0(!attrData1.empty(),
"FILE attribute must be specified.");
423 m_session->SubstituteExpressions(attrData1);
425 filename = attrData1;
432 (*boundaryConditions)[*iter] = robinCondition;
438 (*boundaryConditions)[*iter] = robinCondition;
442 else if (conditionType ==
"P")
444 if (attrData.empty())
450 attrName = attr->Name();
452 ASSERTL0(attrName ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName).c_str());
454 attrData = attr->Value();
455 ASSERTL0(!attrData.empty(),
"VALUE attribute must have associated value.");
457 int beg = attrData.find_first_of(
"[");
458 int end = attrData.find_first_of(
"]");
459 std::string periodicBndRegionIndexStr = attrData.substr(beg+1,end-beg-1);
460 ASSERTL0(beg < end, (std::string(
"Error reading periodic boundary region definition for boundary region: ")
461 + boundaryRegionIDStrm.str()).c_str());
463 vector<unsigned int> periodicBndRegionIndex;
466 ASSERTL0(parseGood && (periodicBndRegionIndex.size()==1), (std::string(
"Unable to read periodic boundary condition for boundary region: ")
467 + boundaryRegionIDStrm.str()).c_str());
472 varIter != vars.end(); ++varIter)
474 (*boundaryConditions)[*varIter] = periodicCondition;
479 ASSERTL0(
false,
"Periodic boundary conditions should be explicitely defined");
490 attrName = attr->Name();
492 ASSERTL0(attrName ==
"VALUE", (std::string(
"Unknown attribute: ") + attrName).c_str());
494 attrData = attr->Value();
495 ASSERTL0(!attrData.empty(),
"VALUE attribute must have associated value.");
497 int beg = attrData.find_first_of(
"[");
498 int end = attrData.find_first_of(
"]");
499 std::string periodicBndRegionIndexStr = attrData.substr(beg+1,end-beg-1);
500 ASSERTL0(beg < end, (std::string(
"Error reading periodic boundary region definition for boundary region: ") + boundaryRegionIDStrm.str()).c_str());
502 vector<unsigned int> periodicBndRegionIndex;
505 ASSERTL0(parseGood && (periodicBndRegionIndex.size()==1), (std::string(
"Unable to read periodic boundary condition for boundary region: ") + boundaryRegionIDStrm.str()).c_str());
508 (*boundaryConditions)[*iter] = periodicCondition;
512 ASSERTL0(
false,
"Periodic boundary conditions should be explicitely defined");
516 else if (conditionType ==
"C")
521 conditionElement = conditionElement->NextSiblingElement();
525 regionElement = regionElement->NextSiblingElement(
"REGION");