66 vector<int> &InterfaceVerts);
70 Array<OneD, NekDouble> &xc, Array<OneD, NekDouble> &yc);
74 vector<int> &InterfaceVerts,
75 Array<OneD, NekDouble> &xstreak,
76 Array<OneD, NekDouble> &ystreak,
77 Array<OneD,NekDouble> &vertx,
78 Array<OneD,NekDouble> &verty,
83 Array<OneD,MoveVerts> &verts);
86 Array<OneD,NekDouble> &dvertx, Array<OneD,NekDouble> &dverty);
89 Array<OneD, NekDouble> &dvertx,
90 Array<OneD, NekDouble> &dverty);
92 int main(
int argc,
char *argv[])
96 fprintf(stderr,
"Usage: ./MoveMeshToCriticalLayer meshfile streakfile outfile\n");
104 = LibUtilities::SessionReader::CreateInstance(2, argv);
109 string meshfile(argv[argc-3]);
111 TiXmlDocument& meshdoc = vSession->GetDocument();
112 TiXmlHandle docHandle(&meshdoc);
113 TiXmlElement* doc = docHandle.FirstChildElement(
"NEKTAR").FirstChildElement(
"GEOMETRY").Element();
118 vector<int> InterfaceVerts;
124 Array<OneD,NekDouble> xstreak(50),ystreak(50);
125 string fieldfile(argv[argc-2]);
131 Array<OneD,NekDouble> dvertx(mesh->GetNvertices(),0.0), dverty(mesh->GetNvertices(),0.0);
133 vSession->LoadParameter(
"MoveMeshMaxIterations",maxiter,100);
140 if(vSession->DefinesSolverInfo(
"EnforceRotationalSymmetry"))
153 std::string outfile(argv[argc-1]);
154 meshdoc.SaveFile(outfile);
161 composite = mesh->GetComposite(compositeID);
162 int compsize = composite->size();
163 map<int,int> vertmap;
165 for(
int i = 0; i < compsize; ++i)
167 if(vertmap.count((*composite)[i]->GetVid(0)) == 0)
169 InterfaceVerts.push_back((*composite)[i]->GetVid(0));
170 vertmap[(*composite)[i]->GetVid(0)] = 1;
173 if(vertmap.count((*composite)[i]->GetVid(1)) == 0)
175 InterfaceVerts.push_back((*composite)[i]->GetVid(1));
176 vertmap[(*composite)[i]->GetVid(1)] = 1;
183 Array<OneD, NekDouble> &xc, Array<OneD, NekDouble> &yc)
195 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
196 vector<vector<NekDouble> > fielddata;
202 string streak_field(
"w");
203 for(
unsigned int i = 0; i < fielddata.size(); ++i)
205 streak->ExtractDataToCoeffs(fielddef [i],
208 streak->UpdateCoeffs());
214 cerr <<
"Extracting Critical Layer ";
221 vector<int> &InterfaceVerts,
222 Array<OneD, NekDouble> &xstreak,
223 Array<OneD, NekDouble> &ystreak,
224 Array<OneD,NekDouble> &dvertx,
225 Array<OneD,NekDouble> &dverty,
229 int nverts = mesh->GetNvertices();
233 Array<OneD,MoveVerts> Verts(nverts);
246 for(segIter = meshedges.begin(); segIter != meshedges.end(); ++segIter)
248 vid0 = (segIter->second)->GetVid(0);
249 vid1 = (segIter->second)->GetVid(1);
251 v0 = (segIter->second)->GetVertex(0);
252 v1 = (segIter->second)->GetVertex(1);
254 kspring = 1.0/v0->
dist(*v1);
256 Verts[vid0].kspring.push_back(kspring);
257 Verts[vid0].springVid.push_back(vid1);
258 Verts[vid1].kspring.push_back(kspring);
259 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;
286 for(i = 0; i < InterfaceVerts.size(); ++i)
288 Verts[InterfaceVerts[i]].solve =
eNoSolve;
289 mesh->GetVertex(InterfaceVerts[i])->GetCoords(x,y,z);
291 for(j = 0; j < xstreak.num_elements()-1; ++j)
293 if((x >= xstreak[j])&&(x <= xstreak[j+1]))
299 ASSERTL0(j != xstreak.num_elements(),
"Did not find x location along critical layer");
304 h0 = (x-xstreak[k])*(x-xstreak[k+1])/
305 ((xstreak[k-1]-xstreak[k])*(xstreak[k-1]-xstreak[k+1]));
306 h1 = (x-xstreak[k-1])*(x-xstreak[k+1])/
307 ((xstreak[k]-xstreak[k-1])*(xstreak[k]-xstreak[k+1]));
308 h2 = (x-xstreak[k-1])*(x-xstreak[k])/
309 ((xstreak[k+1]-xstreak[k-1])*(xstreak[k+1]-xstreak[k]));
311 dvertx[InterfaceVerts[i]] = (xstreak[k-1]*h0 + xstreak[k]*h1 + xstreak[k+1]*h2) - x;
312 dverty[InterfaceVerts[i]] = (ystreak[k-1]*h0 + ystreak[k]*h1 + ystreak[k+1]*h2) - y;
318 for(quadIter = quadgeom.begin(); quadIter != quadgeom.end(); ++quadIter)
320 for(i = 0; i < 4; ++i)
322 vid0 = (quadIter->second)->GetVid(i);
324 switch(Verts[vid0].solve)
328 mesh->GetVertex(vid0)->GetCoords(x,y,z);
331 mesh->GetVertex(InterfaceVerts[0])->GetCoords(x1,y1,z1);
332 for(j = 0; j < InterfaceVerts.size()-1; ++j)
334 mesh->GetVertex(InterfaceVerts[j+1])->GetCoords(x2,y2,z2);
335 if((x >= x1)&&(x < x2))
344 dvertx[vid0] = (x2-x)/(x2-x1)*dvertx[InterfaceVerts[j]]+
345 (x-x1)/(x2-x1)*dvertx[InterfaceVerts[j+1]];
346 dverty[vid0] = (x2-x)/(x2-x1)*dverty[InterfaceVerts[j]]+
347 (x-x1)/(x2-x1)*dverty[InterfaceVerts[j+1]];
352 mesh->GetVertex(vid0)->GetCoords(x,y,z);
353 mesh->GetVertex(InterfaceVerts[0])->GetCoords(x1,y1,z1);
355 if(fabs(x-x1) < 1e-6)
357 dverty[vid0] = dverty[InterfaceVerts[0]];
361 dverty[vid0] = dverty[InterfaceVerts[InterfaceVerts.size()-1]];
377 bool ContinueToIterate =
true;
384 while (ContinueToIterate)
391 fac = (cnt < blend)? 1.0/(blend+1.0)*(cnt+1): 1.0;
393 for(i = 0; i < nverts; ++i)
401 for(j = 0; j < Verts[i].kspring.size(); ++j)
403 dx += fac*Verts[i].kspring[j]*dvertx[Verts[i].springVid[j]];
409 for(j = 0; j < Verts[i].kspring.size(); ++j)
411 dy += fac*Verts[i].kspring[j]*dverty[Verts[i].springVid[j]];
415 dsum = (dx*dx + dy*dy);
436 cerr <<
"Iteration " << cnt <<
" : " << chg << endl;
438 if((chg < tol)&&(cnt > blend))
440 ContinueToIterate =
false;
446 ContinueToIterate =
false;
452 ContinueToIterate =
false;
461 Array<OneD,MoveVerts> &Verts)
463 TiXmlElement* field = doc->FirstChildElement(
"COMPOSITE");
464 ASSERTL0(field,
"Unable to find COMPOSITE tag in file.");
466 int nextCompositeNumber = -1;
470 TiXmlElement *composite = field->FirstChildElement(
"C");
474 nextCompositeNumber++;
477 int err = composite->QueryIntAttribute(
"ID", &indx);
478 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
480 TiXmlNode* compositeChild = composite->FirstChild();
485 while(compositeChild && compositeChild->Type() != TiXmlNode::TEXT)
487 compositeChild = compositeChild->NextSibling();
490 ASSERTL0(compositeChild,
"Unable to read composite definition body.");
491 std::string compositeStr = compositeChild->ToText()->ValueStr();
494 std::istringstream compositeDataStrm(compositeStr.c_str());
498 std::string compositeElementStr;
499 compositeDataStrm >> compositeElementStr;
501 std::istringstream tokenStream(compositeElementStr);
507 std::string::size_type indxBeg = compositeElementStr.find_first_of(
'[') + 1;
508 std::string::size_type indxEnd = compositeElementStr.find_last_of(
']') - 1;
510 ASSERTL0(indxBeg <= indxEnd, (std::string(
"Error reading index definition:") + compositeElementStr).c_str());
512 std::string indxStr = compositeElementStr.substr(indxBeg, indxEnd - indxBeg + 1);
513 std::vector<unsigned int> seqVector;
516 bool err = ParseUtils::GenerateSeqVector(indxStr.c_str(), seqVector);
518 ASSERTL0(err, (std::string(
"Error reading composite elements: ") + indxStr).c_str());
524 int seqlen = seqVector.size();
528 for(
int i = 0; i < seqlen; ++i)
530 meshedges[seqVector[i]]->GetVertex(0)->GetCoords(x0,y0,z0);
531 meshedges[seqVector[i]]->GetVertex(1)->GetCoords(x1,y1,z1);
532 vid0 = meshedges[seqVector[i]]->GetVid(0);
533 vid1 = meshedges[seqVector[i]]->GetVid(1);
535 if(fabs(x0-x1) < 1e-8)
538 if(Verts[vid0].solve ==
eSolveX)
547 if(Verts[vid1].solve ==
eSolveX)
557 if(fabs(y0-y1) < 1e-8)
560 if(Verts[vid0].solve ==
eSolveY)
569 if(Verts[vid1].solve ==
eSolveY)
595 (std::string(
"Unable to read COMPOSITE data for composite: ") + compositeStr).c_str());
599 composite = composite->NextSiblingElement(
"C");
604 Array<OneD,NekDouble> &dvertx,
605 Array<OneD,NekDouble> &dverty)
609 TiXmlElement* element = doc->FirstChildElement(
"VERTEX");
610 ASSERTL0(element,
"Unable to find mesh VERTEX tag in file.");
612 TiXmlElement *vertex = element->FirstChildElement(
"V");
615 int nextVertexNumber = -1;
618 vector<NekDouble> xpts,ypts,zpts;
625 TiXmlAttribute *vertexAttr = vertex->FirstAttribute();
626 std::string attrName(vertexAttr->Name());
628 ASSERTL0(attrName ==
"ID", (std::string(
"Unknown attribute name: ") + attrName).c_str());
630 err = vertexAttr->QueryIntValue(&indx);
631 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read attribute ID.");
634 std::string vertexBodyStr;
636 TiXmlNode *vertexBody = vertex->FirstChild();
641 if (vertexBody->Type() == TiXmlNode::TEXT)
643 vertexBodyStr += vertexBody->ToText()->Value();
644 vertexBodyStr +=
" ";
647 vertexBody = vertexBody->NextSibling();
650 ASSERTL0(!vertexBodyStr.empty(),
"Vertex definitions must contain vertex data.");
653 std::istringstream vertexDataStrm(vertexBodyStr.c_str());
657 while(!vertexDataStrm.fail())
659 vertexDataStrm >> xval >> yval >> zval;
662 xval += dvertx[indx];
663 yval += dverty[indx];
666 s << scientific << setprecision(8)
667 << xval <<
" " << yval <<
" " << zval;
669 vertex->ReplaceChild(vertex->FirstChild(), TiXmlText(s.str()));
673 ASSERTL0(
false,
"Unable to read VERTEX data.");
675 vertex = vertex->NextSiblingElement(
"V");
681 Array<OneD, NekDouble> &dvertx,
682 Array<OneD, NekDouble> &dverty)
685 int nverts = mesh->GetNvertices();
686 Array<OneD, NekDouble> x(nverts),y(nverts);
689 for(i = 0; i < nverts; ++i)
691 mesh->GetVertex(i)->GetCoords(xval,yval,zval);
692 x[i] = xval + dvertx[i];
693 y[i] = yval + dverty[i];
698 Array<OneD,int> index(nverts);
700 for(i = 0; i < nverts; ++i)
706 for(j = 0; j < nverts; ++j)
708 dist2 = (x[j]-xrot)*(x[j]-xrot) + (y[j]-yrot)*(y[j]-yrot);
718 for(i = 0; i < nverts; ++i)
720 mesh->GetVertex(i)->GetCoords(xval,yval,zval);
722 xrot = 0.5*(-x[index[i]] + xmax + x[i]);
723 yrot = 0.5*(-y[index[i]] + y[i]);
725 dvertx[i] = xrot - xval;
726 dverty[i] = yrot - yval;