66 vector<int> &InterfaceVerts);
74 vector<int> &InterfaceVerts,
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;
125 string fieldfile(argv[argc-2]);
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;
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,
229 int nverts = mesh->GetNvertices();
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;
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::TINYXML_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");
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::TINYXML_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");
685 int nverts = mesh->GetNvertices();
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];
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;
#define ASSERTL0(condition, msg)
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
vector< NekDouble > kspring
void GetStreakLocation(LibUtilities::SessionReaderSharedPtr &vSession, SpatialDomains::MeshGraphSharedPtr &mesh, string &fieldfile, Array< OneD, NekDouble > &xc, Array< OneD, NekDouble > &yc)
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
void Import(const std::string &infilename, std::vector< FieldDefinitionsSharedPtr > &fielddefs, std::vector< std::vector< NekDouble > > &fielddata, FieldMetaDataMap &fieldinfomap, const Array< OneD, int > ElementiDs)
Imports an FLD file.
void EnforceRotationalSymmetry(SpatialDomains::MeshGraphSharedPtr &mesh, Array< OneD, NekDouble > &dvertx, Array< OneD, NekDouble > &dverty)
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 GetInterfaceVerts(const int compositeID, SpatialDomains::MeshGraphSharedPtr &mesh, vector< int > &InterfaceVerts)
std::map< int, SegGeomSharedPtr > SegGeomMap
boost::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
boost::shared_ptr< GeometryVector > Composite
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
std::map< int, QuadGeomSharedPtr > QuadGeomMap
void RedefineVertices(TiXmlElement *doc, Array< OneD, NekDouble > &dvertx, Array< OneD, NekDouble > &dverty)
NekDouble dist(PointGeom &a)
int main(int argc, char *argv[])
boost::shared_ptr< MeshGraph > MeshGraphSharedPtr
boost::shared_ptr< PointGeom > PointGeomSharedPtr