49std::string
static inline ReadTag(std::string &tagStr)
51 std::string::size_type indxBeg = tagStr.find_first_of(
'[') + 1;
52 std::string::size_type indxEnd = tagStr.find_last_of(
']') - 1;
56 (std::string(
"Error reading interface region definition:") + tagStr)
59 std::string indxStr = tagStr.substr(indxBeg, indxEnd - indxBeg + 1);
66 auto length = str.length();
67 return str.substr(1, length - 2);
73 TiXmlNode *nektar = pSession->GetElement(
"NEKTAR");
74 if (nektar ==
nullptr)
79 TiXmlNode *movement = nektar->FirstChild(
"MOVEMENT");
80 if (movement !=
nullptr)
82 bool zones = movement->FirstChild(
"ZONES") !=
nullptr;
85 TiXmlElement *zonesTag =
86 pSession->GetElement(
"NEKTAR/MOVEMENT/ZONES");
90 bool interfaces = movement->FirstChild(
"INTERFACES") !=
nullptr;
93 TiXmlElement *interfacesTag =
94 pSession->GetElement(
"NEKTAR/MOVEMENT/INTERFACES");
99 "Only one of ZONES or INTERFACES present in the MOVEMENT "
106 auto comm = pSession->GetComm();
107 for (
int i = 0; i < 3; ++i)
119 if (movement !=
nullptr && pSession->DefinesCmdLineArgument(
"verbose"))
121 auto comm = pSession->GetComm();
122 if (comm->TreatAsRankZero())
124 std::cout <<
"Movement Info:\n";
125 std::cout <<
"\tNum zones: " <<
m_zones.size() <<
"\n";
130 auto numEl = zone.second->GetElements().size();
135 !zone.second->GetElements().empty()
136 ? zone.second->GetElements().front()->GetShapeType()
140 if (comm->TreatAsRankZero())
142 std::cout <<
"\t- " << zone.first <<
" "
144 zone.second->GetMovementType())]
145 <<
": " << numEl <<
" "
150 if (comm->TreatAsRankZero())
152 std::cout <<
"\tNum interfaces: " <<
m_interfaces.size() <<
"\n";
158 interface.second->GetLeftInterface()->GetEdge().size();
160 interface.second->GetRightInterface()->GetEdge().size();
166 !interface.second->GetLeftInterface()->GetEdge().empty()
167 ? interface.second->GetLeftInterface()
170 ->second->GetShapeType()
172 comm->GetSpaceComm()->AllReduce(shapeTypeLeft,
175 !interface.second->GetRightInterface()->GetEdge().empty()
176 ? interface.second->GetRightInterface()
179 ->second->GetShapeType()
181 comm->GetSpaceComm()->AllReduce(shapeTypeRight,
184 if (comm->TreatAsRankZero())
186 std::cout <<
"\t- \"" << interface.first.second <<
"\": "
187 << interface.second->GetLeftInterface()->GetId()
188 <<
" (" << numLeft <<
" "
191 << interface.second->GetRightInterface()->GetId()
192 <<
" (" << numRight <<
" "
198 comm->GetSpaceComm()->Block();
199 if (comm->TreatAsRankZero())
201 std::cout << std::endl;
211 ASSERTL0(zonesTag,
"Unable to find ZONES tag in file.");
212 TiXmlElement *zonesElement = zonesTag->FirstChildElement();
215 std::string zoneType = zonesElement->Value();
220 err = zonesElement->QueryIntAttribute(
"ID", &indx);
221 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read zone ID.");
223 std::string interfaceDomainStr;
224 err = zonesElement->QueryStringAttribute(
"DOMAIN", &interfaceDomainStr);
225 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read zone domain.");
228 auto domFind = std::stoi(
ReadTag(interfaceDomainStr));
229 std::map<int, CompositeSharedPtr> domain;
230 if (domains.find(domFind) != domains.end())
232 domain = domains.at(domFind);
236 if (zoneType ==
"F" || zoneType ==
"FIXED")
239 indx, domFind, domain, coordDim));
241 else if (zoneType ==
"R" || zoneType ==
"ROTATE" ||
242 zoneType ==
"ROTATING")
244 std::string originStr;
245 err = zonesElement->QueryStringAttribute(
"ORIGIN", &originStr);
246 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read origin.");
247 std::vector<NekDouble> originVec;
253 err = zonesElement->QueryStringAttribute(
"AXIS", &axisStr);
254 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read axis.");
258 std::string angularVelStr;
259 err = zonesElement->QueryStringAttribute(
"ANGVEL", &angularVelStr);
260 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read angular velocity.");
264 pSession->GetInterpreter(), angularVelStr);
267 indx, domFind, domain, coordDim,
origin,
axis, angularVelEqn));
271 else if (zoneType ==
"T" || zoneType ==
"TRANSLATE" ||
272 zoneType ==
"TRANSLATING")
276 err = zonesElement->QueryStringAttribute(
"VELOCITY", &
velocityStr);
278 "Unable to read VELOCITY for translating zone " +
279 std::to_string(indx));
281 std::vector<std::string> velocityStrSplit;
284 ASSERTL0(velocityStrSplit.size() >= coordDim,
285 "VELOCITY dimensions must be greater than or equal to the "
286 "coordinate dimension for translating zone " +
287 std::to_string(indx));
290 for (
int i = 0; i < coordDim; ++i)
294 pSession->GetInterpreter(), velocityStrSplit[i]);
299 err = zonesElement->QueryStringAttribute(
"DISPLACEMENT",
302 "Unable to read DISPLACEMENT for translating zone " +
303 std::to_string(indx));
305 std::vector<std::string> displacementStrSplit;
309 displacementStrSplit.size() >= coordDim,
310 "DISPLACEMENT dimensions must be greater than or equal to the "
311 "coordinate dimension for translating zone " +
312 std::to_string(indx));
316 for (
int i = 0; i < coordDim; ++i)
318 displacementEqns[i] =
320 pSession->GetInterpreter(), displacementStrSplit[i]);
325 indx, domFind, domain, coordDim, velocityEqns,
333 WARNINGL0(
false,
"Zone type '" + zoneType +
334 "' is unsupported. Valid types are: 'Fixed', "
335 "'Rotate', or 'Translate'.")
339 zonesElement = zonesElement->NextSiblingElement();
345 ASSERTL0(interfacesTag,
"Unable to find INTERFACES tag in file.");
346 TiXmlElement *interfaceElement = interfacesTag->FirstChildElement();
348 while (interfaceElement)
351 "INTERFACE" == (std::string)interfaceElement->Value(),
352 "Only INTERFACE tags may be present inside the INTERFACES block.")
357 err = interfaceElement->QueryStringAttribute(
"NAME", &
name);
358 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read interface name.");
359 TiXmlElement *sideElement = interfaceElement->FirstChildElement();
362 std::vector<int> cnt;
367 "In INTERFACE NAME " +
name +
368 ", only two sides may be present in each INTERFACE block.")
372 err = sideElement->QueryIntAttribute(
"ID", &indx);
373 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read interface ID.");
376 std::string boundaryStr;
377 err = sideElement->QueryStringAttribute(
"BOUNDARY", &boundaryStr);
379 "Unable to read BOUNDARY in interface " +
380 std::to_string(indx));
383 std::string indxStr =
ReadTag(boundaryStr);
387 bool skipCheck =
false;
388 err = sideElement->QueryBoolAttribute(
"SKIPCHECK", &skipCheck);
391 auto sideElVal = sideElement->ValueStr();
392 if (sideElVal ==
"LEFT" || sideElVal ==
"L")
396 else if (sideElVal ==
"RIGHT" || sideElVal ==
"R")
403 sideElement->ValueStr() +
404 " is not a valid interface side for interface "
406 name +
". Please only use LEFT or RIGHT.")
409 interfaces[cnt[cnt.size() - 1]] =
411 indx, boundaryEdge, skipCheck));
413 sideElement = sideElement->NextSiblingElement();
416 ASSERTL0(std::accumulate(cnt.begin(), cnt.end(), 0) == 1,
417 "You must have only one LEFT and one RIGHT side"
418 " present in interface NAME " +
423 interfaces[0], interfaces[1]));
424 interfaceElement = interfaceElement->NextSiblingElement();
435 TiXmlElement *movement =
new TiXmlElement(
"MOVEMENT");
436 root->LinkEndChild(movement);
438 TiXmlElement *zones =
new TiXmlElement(
"ZONES");
444 TiXmlElement *e =
new TiXmlElement(
label.substr(0, 1));
445 e->SetAttribute(
"ID", i.first);
447 s <<
"D[" <<
z->GetDomainID() <<
"]";
448 e->SetAttribute(
"DOMAIN", s.str());
454 auto rotate = std::static_pointer_cast<ZoneRotate>(
z);
457 e->SetAttribute(
"AXIS",
459 e->SetAttribute(
"ANGVEL",
460 rotate->GetAngularVelEqn()->GetExpression());
465 auto translate = std::static_pointer_cast<ZoneTranslate>(
z);
468 translate->GetVelocityEquation()[0]->GetExpression());
471 translate->GetDisplacementEquation()[0]->GetExpression());
474 translate->GetVelocityEquation()[1]->GetExpression());
477 translate->GetDisplacementEquation()[1]->GetExpression());
480 translate->GetVelocityEquation()[2]->GetExpression());
483 translate->GetDisplacementEquation()[2]->GetExpression());
489 zones->LinkEndChild(e);
491 movement->LinkEndChild(zones);
493 TiXmlElement *interfaces =
new TiXmlElement(
"INTERFACES");
496 const std::string interfaceName = i.first.second;
497 TiXmlElement *e =
new TiXmlElement(
"INTERFACE");
498 e->SetAttribute(
"NAME", interfaceName);
503 TiXmlElement *left_e =
new TiXmlElement(
"L");
504 left_e->SetAttribute(
"ID", left->GetId());
505 left_e->SetAttribute(
509 e->LinkEndChild(left_e);
513 TiXmlElement *right_e =
new TiXmlElement(
"R");
514 right_e->SetAttribute(
"ID", right->GetId());
515 right_e->SetAttribute(
519 e->LinkEndChild(right_e);
521 interfaces->LinkEndChild(e);
523 movement->LinkEndChild(interfaces);
530 std::set<int> movedZoneIds;
533 if (zone.second->Move(timeStep))
535 movedZoneIds.insert(zone.first);
542 int leftId = interPair.second->GetLeftInterface()->GetId();
543 int rightId = interPair.second->GetRightInterface()->GetId();
545 if (movedZoneIds.find(leftId) != movedZoneIds.end() ||
546 movedZoneIds.find(rightId) != movedZoneIds.end())
548 m_zones[leftId]->GetMoved() =
true;
549 m_zones[rightId]->GetMoved() =
true;
587 int NumVerts = zones.second->GetOriginalVertex().size();
590 PointGeom p = zones.second->GetOriginalVertex()[0];
591 p.GetCoords(x[0], x[1], x[2]);
592 for (
int j = 0; j < 3; ++j)
604 int NumVerts = zones.second->GetOriginalVertex().size();
605 for (
int i = 0; i < NumVerts; ++i)
607 PointGeom p = zones.second->GetOriginalVertex()[i];
608 p.GetCoords(x[0], x[1], x[2]);
609 for (
int j = 0; j < 3; ++j)
611 min[j] = (x[j] < min[j] ? x[j] : min[j]);
612 max[j] = (x[j] > max[j] ? x[j] : max[j]);
620 for (
int j = 0; j < 3; ++j)
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
#define WARNINGL0(condition, msg)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static std::string GenerateSeqString(const std::vector< T > &v)
Generate a compressed comma-separated string representation of a vector of unsigned integers.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Base class for a spectral/hp element mesh.
std::map< int, std::map< int, CompositeSharedPtr > > & GetDomain()
void GetCompositeList(const std::string &compositeStr, CompositeMap &compositeVector) const
int GetSpaceDimension()
Dimension of the space (can be a 1D curve in 3D space).
void DomainBox()
Calculate length of the domain.
void PerformMovement(NekDouble timeStep)
Array< OneD, NekDouble > m_DomainLength
void ReadZones(TiXmlElement *zonesTag, MeshGraph *meshGraph, const LibUtilities::SessionReaderSharedPtr &pSession)
Read zones given TiXmlDocument.
void AddInterface(std::string name, InterfaceShPtr left, InterfaceShPtr right)
Add pair of interfaces to this data.
void ReadInterfaces(TiXmlElement *interfacesTag, MeshGraph *meshGraph)
Read interfaces given TiXmlDocument.
Array< OneD, NekDouble > m_DomainBox
void AddZone(ZoneBaseShPtr zone)
Add a zone object to this Movement data.
void WriteMovement(TiXmlElement *root)
Write the MOVEMENT section of the XML file.
InterfaceCollection m_interfaces
std::map< int, ZoneBaseShPtr > m_zones
Movement()=default
Default constructor.
const char *const ShapeTypeMap[SIZE_ShapeType]
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
std::vector< std::string > velocityStr
const NekPoint< NekDouble > origin
std::vector< std::string > displacementStr
static std::string StripParentheses(const std::string &str)
std::shared_ptr< ZoneBase > ZoneBaseShPtr
std::shared_ptr< ZoneTranslate > ZoneTranslateShPtr
std::shared_ptr< InterfacePair > InterfacePairShPtr
std::shared_ptr< ZoneRotate > ZoneRotateShPtr
std::shared_ptr< Interface > InterfaceShPtr
MovementType
Enum of zone movement type.
std::shared_ptr< ZoneFixed > ZoneFixedShPtr
static std::string ReadTag(std::string &tagStr)
const std::string MovementTypeStr[]
Map of zone movement type to movement type string.
std::map< int, CompositeSharedPtr > CompositeMap
std::vector< double > z(NPUPPER)