66 vector<int> &InterfaceVerts);
75 vector<int> &InterfaceVerts,
91int main(
int argc,
char *argv[])
97 "Usage: ./MoveMeshToCriticalLayer meshfile streakfile outfile\n");
105 LibUtilities::SessionReader::CreateInstance(2, argv);
107 SpatialDomains::MeshGraphIO::Read(vSession);
112 TiXmlDocument &meshdoc = vSession->GetDocument();
113 TiXmlHandle docHandle(&meshdoc);
114 TiXmlElement *doc = docHandle.FirstChildElement(
"NEKTAR")
115 .FirstChildElement(
"GEOMETRY")
121 vector<int> InterfaceVerts;
128 string fieldfile(argv[argc - 2]);
135 dverty(mesh->GetNvertices(), 0.0);
137 vSession->LoadParameter(
"MoveMeshMaxIterations", maxiter, 100);
145 if (vSession->DefinesSolverInfo(
"EnforceRotationalSymmetry"))
158 std::string outfile(argv[argc - 1]);
159 meshdoc.SaveFile(outfile);
164 vector<int> &InterfaceVerts)
167 composite = mesh->GetComposite(compositeID);
168 int compsize = composite->m_geomVec.size();
169 map<int, int> vertmap;
171 for (
int i = 0; i < compsize; ++i)
173 if (vertmap.count(composite->m_geomVec[i]->GetVid(0)) == 0)
175 InterfaceVerts.push_back(composite->m_geomVec[i]->GetVid(0));
176 vertmap[composite->m_geomVec[i]->GetVid(0)] = 1;
179 if (vertmap.count(composite->m_geomVec[i]->GetVid(1)) == 0)
181 InterfaceVerts.push_back(composite->m_geomVec[i]->GetVid(1));
182 vertmap[composite->m_geomVec[i]->GetVid(1)] = 1;
202 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
203 vector<vector<NekDouble>> fielddata;
209 string streak_field(
"w");
210 for (
unsigned int i = 0; i < fielddata.size(); ++i)
212 streak->ExtractDataToCoeffs(fielddef[i], fielddata[i], streak_field,
213 streak->UpdateCoeffs());
219 cerr <<
"Extracting Critical Layer ";
225 vector<int> &InterfaceVerts,
232 int nverts = mesh->GetNvertices();
247 for (
auto &segIter : meshedges)
249 vid0 = (segIter.second)->GetVid(0);
250 vid1 = (segIter.second)->GetVid(1);
252 v0 = (segIter.second)->GetVertex(0);
253 v1 = (segIter.second)->GetVertex(1);
255 kspring = 1.0 / v0->
dist(*v1);
257 Verts[vid0].kspring.push_back(kspring);
258 Verts[vid0].springVid.push_back(vid1);
259 Verts[vid1].kspring.push_back(kspring);
260 Verts[vid1].springVid.push_back(vid0);
264 for (i = 0; i < nverts; ++i)
267 for (j = 0; j < Verts[i].kspring.size(); ++j)
269 invktot += Verts[i].kspring[j];
271 invktot = 1.0 / invktot;
272 for (j = 0; j < Verts[i].kspring.size(); ++j)
274 Verts[i].kspring[j] *= invktot;
285 for (i = 0; i < InterfaceVerts.size(); ++i)
287 Verts[InterfaceVerts[i]].solve =
eNoSolve;
288 mesh->GetVertex(InterfaceVerts[i])->GetCoords(x, y,
z);
290 for (j = 0; j < xstreak.size() - 1; ++j)
292 if ((x >= xstreak[j]) && (x <= xstreak[j + 1]))
299 "Did not find x location along critical layer");
301 k = (j == 0) ? 1 : j;
305 (x - xstreak[k]) * (x - xstreak[k + 1]) /
306 ((xstreak[k - 1] - xstreak[k]) * (xstreak[k - 1] - xstreak[k + 1]));
307 h1 = (x - xstreak[k - 1]) * (x - xstreak[k + 1]) /
308 ((xstreak[k] - xstreak[k - 1]) * (xstreak[k] - xstreak[k + 1]));
310 (x - xstreak[k - 1]) * (x - xstreak[k]) /
311 ((xstreak[k + 1] - xstreak[k - 1]) * (xstreak[k + 1] - xstreak[k]));
313 dvertx[InterfaceVerts[i]] =
314 (xstreak[k - 1] * h0 + xstreak[k] * h1 + xstreak[k + 1] * h2) - x;
315 dverty[InterfaceVerts[i]] =
316 (ystreak[k - 1] * h0 + ystreak[k] * h1 + ystreak[k + 1] * h2) - y;
321 for (
auto &quadIter : quadgeom)
323 for (i = 0; i < 4; ++i)
325 vid0 = (quadIter.second)->GetVid(i);
327 switch (Verts[vid0].solve)
331 mesh->GetVertex(vid0)->GetCoords(x, y,
z);
334 mesh->GetVertex(InterfaceVerts[0])->GetCoords(x1, y1, z1);
335 for (j = 0; j < InterfaceVerts.size() - 1; ++j)
337 mesh->GetVertex(InterfaceVerts[j + 1])
338 ->GetCoords(x2, y2, z2);
339 if ((x >= x1) && (x < x2))
349 (x2 - x) / (x2 - x1) * dvertx[InterfaceVerts[j]] +
350 (x - x1) / (x2 - x1) * dvertx[InterfaceVerts[j + 1]];
352 (x2 - x) / (x2 - x1) * dverty[InterfaceVerts[j]] +
353 (x - x1) / (x2 - x1) * dverty[InterfaceVerts[j + 1]];
358 mesh->GetVertex(vid0)->GetCoords(x, y,
z);
359 mesh->GetVertex(InterfaceVerts[0])->GetCoords(x1, y1, z1);
361 if (fabs(x - x1) < 1e-6)
363 dverty[vid0] = dverty[InterfaceVerts[0]];
368 dverty[InterfaceVerts[InterfaceVerts.size() - 1]];
380 bool ContinueToIterate =
true;
383 NekDouble dsum, dx, dy, sum, prev_sum = 0.0;
387 while (ContinueToIterate)
394 fac = (cnt < blend) ? 1.0 / (blend + 1.0) * (cnt + 1) : 1.0;
396 for (i = 0; i < nverts; ++i)
404 for (j = 0; j < Verts[i].kspring.size(); ++j)
406 dx += fac * Verts[i].kspring[j] *
407 dvertx[Verts[i].springVid[j]];
413 for (j = 0; j < Verts[i].kspring.size(); ++j)
415 dy += fac * Verts[i].kspring[j] *
416 dverty[Verts[i].springVid[j]];
420 dsum = (dx * dx + dy * dy);
441 cerr <<
"Iteration " << cnt <<
" : " << chg << endl;
443 if ((chg < tol) && (cnt > blend))
445 ContinueToIterate =
false;
448 else if (cnt > blend)
450 ContinueToIterate =
false;
455 ContinueToIterate =
false;
465 TiXmlElement *
field = doc->FirstChildElement(
"COMPOSITE");
470 TiXmlElement *composite =
field->FirstChildElement(
"C");
475 int err = composite->QueryIntAttribute(
"ID", &indx);
476 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
478 TiXmlNode *compositeChild = composite->FirstChild();
483 while (compositeChild &&
484 compositeChild->Type() != TiXmlNode::TINYXML_TEXT)
486 compositeChild = compositeChild->NextSibling();
489 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
490 std::string compositeStr = compositeChild->ToText()->ValueStr();
493 std::istringstream compositeDataStrm(compositeStr.c_str());
497 std::string compositeElementStr;
498 compositeDataStrm >> compositeElementStr;
500 std::istringstream tokenStream(compositeElementStr);
506 std::string::size_type indxBeg =
507 compositeElementStr.find_first_of(
'[') + 1;
508 std::string::size_type indxEnd =
509 compositeElementStr.find_last_of(
']') - 1;
512 (std::string(
"Error reading index definition:") +
516 std::string indxStr =
517 compositeElementStr.substr(indxBeg, indxEnd - indxBeg + 1);
518 std::vector<unsigned int> seqVector;
520 bool err = ParseUtils::GenerateSeqVector(indxStr, seqVector);
522 ASSERTL0(err, (std::string(
"Error reading composite elements: ") +
530 int seqlen = seqVector.size();
534 for (
int i = 0; i < seqlen; ++i)
536 meshedges[seqVector[i]]->GetVertex(0)->GetCoords(x0, y0,
538 meshedges[seqVector[i]]->GetVertex(1)->GetCoords(x1, y1,
540 vid0 = meshedges[seqVector[i]]->GetVid(0);
541 vid1 = meshedges[seqVector[i]]->GetVid(1);
543 if (fabs(x0 - x1) < 1e-8)
546 if (Verts[vid0].solve ==
eSolveX)
555 if (Verts[vid1].solve ==
eSolveX)
565 if (fabs(y0 - y1) < 1e-8)
568 if (Verts[vid0].solve ==
eSolveY)
577 if (Verts[vid1].solve ==
eSolveY)
597 (std::string(
"Unrecognized composite token: ") +
606 (std::string(
"Unable to read COMPOSITE data for composite: ") +
612 composite = composite->NextSiblingElement(
"C");
620 TiXmlElement *element = doc->FirstChildElement(
"VERTEX");
621 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
623 TiXmlElement *vertex = element->FirstChildElement(
"V");
628 vector<NekDouble> xpts, ypts, zpts;
633 TiXmlAttribute *vertexAttr = vertex->FirstAttribute();
634 std::string attrName(vertexAttr->Name());
637 (std::string(
"Unknown attribute name: ") + attrName).c_str());
639 err = vertexAttr->QueryIntValue(&indx);
640 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
643 std::string vertexBodyStr;
645 TiXmlNode *vertexBody = vertex->FirstChild();
650 if (vertexBody->Type() == TiXmlNode::TINYXML_TEXT)
652 vertexBodyStr += vertexBody->ToText()->Value();
653 vertexBodyStr +=
" ";
656 vertexBody = vertexBody->NextSibling();
660 "Vertex definitions must contain vertex data.");
663 std::istringstream vertexDataStrm(vertexBodyStr.c_str());
667 while (!vertexDataStrm.fail())
669 vertexDataStrm >> xval >> yval >> zval;
672 xval += dvertx[indx];
673 yval += dverty[indx];
676 s << scientific << setprecision(8) << xval <<
" " << yval <<
" "
679 vertex->ReplaceChild(vertex->FirstChild(), TiXmlText(s.str()));
683 ASSERTL0(
false,
"Unable to read VERTEX data.");
685 vertex = vertex->NextSiblingElement(
"V");
694 int nverts = mesh->GetNvertices();
698 for (i = 0; i < nverts; ++i)
700 mesh->GetVertex(i)->GetCoords(xval, yval, zval);
701 x[i] = xval + dvertx[i];
702 y[i] = yval + dverty[i];
709 for (i = 0; i < nverts; ++i)
715 for (j = 0; j < nverts; ++j)
718 (x[j] - xrot) * (x[j] - xrot) + (y[j] - yrot) * (y[j] - yrot);
728 for (i = 0; i < nverts; ++i)
730 mesh->GetVertex(i)->GetCoords(xval, yval, zval);
732 xrot = 0.5 * (-x[index[i]] + xmax + x[i]);
733 yrot = 0.5 * (-y[index[i]] + y[i]);
735 dvertx[i] = xrot - xval;
736 dverty[i] = yrot - yval;
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
int main(int argc, char *argv[])
void GetNewVertexLocation(TiXmlElement *doc, SpatialDomains::MeshGraphSharedPtr &mesh, vector< int > &InterfaceVerts, Array< OneD, NekDouble > &xstreak, Array< OneD, NekDouble > &ystreak, Array< OneD, NekDouble > &vertx, Array< OneD, NekDouble > &verty, int maxiter)
void TurnOffEdges(TiXmlElement *doc, SpatialDomains::SegGeomMap &meshedges, Array< OneD, MoveVerts > &verts)
void EnforceRotationalSymmetry(SpatialDomains::MeshGraphSharedPtr &mesh, Array< OneD, NekDouble > &dvertx, Array< OneD, NekDouble > &dverty)
void RedefineVertices(TiXmlElement *doc, Array< OneD, NekDouble > &dvertx, Array< OneD, NekDouble > &dverty)
void GetInterfaceVerts(const int compositeID, SpatialDomains::MeshGraphSharedPtr &mesh, vector< int > &InterfaceVerts)
void GetStreakLocation(LibUtilities::SessionReaderSharedPtr &vSession, SpatialDomains::MeshGraphSharedPtr &mesh, string &fieldfile, Array< OneD, NekDouble > &xc, Array< OneD, NekDouble > &yc)
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
NekDouble dist(PointGeom &a)
return distance between this and input a
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > &ElementIDs)
This function allows for data to be imported from an FLD file when a session and/or communicator is n...
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::map< int, QuadGeomSharedPtr > QuadGeomMap
std::shared_ptr< Composite > CompositeSharedPtr
std::map< int, SegGeomSharedPtr > SegGeomMap
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::vector< double > z(NPUPPER)
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
scalarT< T > sqrt(scalarT< T > in)
vector< NekDouble > kspring