62 #include <boost/lexical_cast.hpp>
68 Array<OneD, int>& Vids,
int v1,
int v2 ,
NekDouble x_connect,
70 Array<OneD, NekDouble>& x, Array<OneD, NekDouble>& y);
72 Array<OneD, NekDouble> xold_up, Array<OneD, NekDouble> yold_up,
73 Array<OneD, NekDouble> xold_low, Array<OneD, NekDouble> yold_low,
74 Array<OneD, NekDouble> xold_c, Array<OneD, NekDouble> yold_c,
75 Array<OneD, NekDouble> &xc, Array<OneD, NekDouble> &yc,
NekDouble cr,
82 Array<OneD, int> &V1, Array<OneD, int> &V2);
84 void MappingEVids(Array<OneD, NekDouble> xoldup, Array<OneD, NekDouble> yoldup,
85 Array<OneD, NekDouble> xolddown, Array<OneD, NekDouble> yolddown,
86 Array<OneD, NekDouble> xcold, Array<OneD, NekDouble> ycold,
87 Array<OneD, int> Vids_c,
90 Array<OneD, int> V1, Array<OneD, int> V2,
91 int & nlays, Array<
OneD, Array<OneD, int> >& Eids_lay,
92 Array<
OneD, Array<OneD, int> >& Vids_lay);
93 bool checkcommonvert(Array<OneD, int> Vids_laybefore, Array<OneD, int> Vids_c,
int Vid);
96 Array<OneD, NekDouble>& outarray);
101 Array<OneD, NekDouble> yArray,Array<OneD, NekDouble>& Neighbour_x,
102 Array<OneD, NekDouble>& Neighbour_y);
105 Array<OneD,NekDouble> xpts, Array<OneD, NekDouble> funcvals);
108 Array<OneD, NekDouble> coeffsinterp,
109 Array<OneD, NekDouble> & txQedge, Array<OneD, NekDouble> & tyQedge);
110 void PolyInterp( Array<OneD, NekDouble> xpol, Array<OneD, NekDouble> ypol,
111 Array<OneD, NekDouble> & coeffsinterp,
112 Array<OneD, NekDouble> & xcout, Array<OneD, NekDouble> & ycout,
113 int edge,
int npedge);
114 void PolyFit(
int polyorder,
int npoints,
115 Array<OneD, NekDouble> xin, Array<OneD, NekDouble> fin,
116 Array<OneD, NekDouble> & coeffsinterp,
117 Array<OneD, NekDouble> & xout, Array<OneD, NekDouble> & fout,
120 Array<OneD, NekDouble> inarray_y, Array<OneD, NekDouble>& outarray_x,
121 Array<OneD, NekDouble>& outarray_y);
124 Array<
OneD, Array<OneD, int > > lay_Vids, Array<OneD, NekDouble> xc,
125 Array<OneD, NekDouble> yc, Array<OneD, int> Down, Array<OneD, int> Up,
126 Array<OneD, NekDouble >& xnew, Array<OneD, NekDouble>& ynew,
127 Array<
OneD, Array<OneD, NekDouble > >& layers_x,
128 Array<
OneD, Array<OneD, NekDouble > >& layers_y);
131 Array<OneD, NekDouble> tmpx_lay, Array<OneD, NekDouble> tmpy_lay,
132 Array<OneD, int> Vids,
133 Array<OneD, NekDouble> &xlay, Array<OneD, NekDouble> &ylay,
134 Array<OneD, NekDouble> &xnew, Array<OneD, NekDouble> &ynew);
137 Array<OneD, NekDouble> tmpx_lay, Array<OneD, NekDouble> tmpy_lay,
138 Array<OneD, int> Vids,
139 Array<OneD, NekDouble> &xlay, Array<OneD, NekDouble> &ylay,
140 Array<OneD, NekDouble> &xnew, Array<OneD, NekDouble> &ynew);
143 Array<OneD, NekDouble> xcold,Array<OneD, NekDouble> ycold,
144 Array<OneD, NekDouble> xolddown,Array<OneD, NekDouble> yolddown,
145 Array<OneD, NekDouble> xoldup,Array<OneD, NekDouble> yoldup,
146 Array<OneD, NekDouble> ylaydown,Array<OneD, NekDouble> ylayup,
147 Array<OneD, NekDouble>& xnew,Array<OneD, NekDouble>& ynew);
150 Array<OneD, NekDouble> xcold,Array<OneD, NekDouble> ycold,
151 Array<OneD, NekDouble> xolddown,Array<OneD, NekDouble> yolddown,
152 Array<OneD, NekDouble> xoldup,Array<OneD, NekDouble> yoldup,
153 Array<OneD, NekDouble> xlaydown,Array<OneD, NekDouble> ylaydown,
154 Array<OneD, NekDouble> xlayup,Array<OneD, NekDouble> ylayup,
155 Array<OneD, NekDouble> nxPhys,Array<OneD, NekDouble> nyPhys,
156 Array<OneD, NekDouble>& xnew,Array<OneD, NekDouble>& ynew) ;
159 Array<OneD, int> V1, Array<OneD, int> V2,
160 Array<OneD, NekDouble>& xnew,Array<OneD, NekDouble>& ynew);
163 Array<OneD, NekDouble> newy,
164 Array<OneD, NekDouble> xcPhys, Array<OneD, NekDouble> ycPhys,
165 Array<OneD, int>Eids,
int Npoints,
string s_alp,
166 Array<
OneD, Array<OneD, NekDouble> > x_lay,
167 Array<
OneD, Array<OneD, NekDouble> > y_lay,
168 Array<
OneD, Array<OneD, int > >lay_eids,
bool curv_lay) ;
170 int main(
int argc,
char *argv[])
176 if(argc > 6 || argc < 5)
179 "Usage: ./MoveMesh meshfile fieldfile changefile alpha cr(optional)\n");
185 = LibUtilities::SessionReader::CreateInstance(2, argv);
189 vSession->DefinesSolverInfo(
"INTERFACE")
190 && vSession->GetSolverInfo(
"INTERFACE")==
"phase" )
192 cr = boost::lexical_cast<
NekDouble>(argv[argc-1]);
197 string meshfile(argv[argc-4]);
215 string changefile(argv[argc-2]);
219 string charalp (argv[argc-1]);
221 cout<<
"read alpha="<<charalp<<endl;
225 string fieldfile(argv[argc-3]);
226 vector<LibUtilities::FieldDefinitionsSharedPtr> fielddef;
227 vector<vector<NekDouble> > fielddata;
236 for(
int i=0; i<fielddata.size(); i++)
238 streak->ExtractDataToCoeffs(fielddef[i], fielddata[i], fielddef[i]->m_fields[0], streak->UpdateCoeffs());
240 streak->BwdTrans_IterPerExp(streak->GetCoeffs(), streak->UpdatePhys());
246 int nIregions, lastIregion;
247 const Array<OneD, SpatialDomains::BoundaryConditionShPtr> bndConditions = streak->GetBndConditions();
248 Array<OneD, int> Iregions =Array<OneD, int>(bndConditions.num_elements(),-1);
251 int nbnd= bndConditions.num_elements();
252 for(
int r=0; r<nbnd; r++)
262 ASSERTL0(nIregions>0,
"there is any boundary region with the tag USERDEFINEDTYPE=""CalcBC"" specified");
263 cout<<
"nIregions="<<nIregions<<endl;
265 Array<OneD, MultiRegions::ExpListSharedPtr> bndfieldx= streak->GetBndCondExpansions();
268 int nedges = bndfieldx[lastIregion]->GetExpSize();
269 int nvertl = nedges +1 ;
270 Array<OneD, int> Vids_low(nvertl,-10);
271 Array<OneD, NekDouble> xold_low(nvertl);
272 Array<OneD, NekDouble> yold_low(nvertl);
273 Array<OneD, NekDouble> zi(nvertl);
285 ( (bndfieldx[lastIregion]->GetExp(0)->as<LocalRegions::SegExp>())
290 vertex0->GetCoords(x0,y0,z0);
293 cout<<
"WARNING x0="<<x0<<endl;
299 Vids_low, v1, v2 , x_connect ,lastedge, xold_low,yold_low);
300 ASSERTL0(Vids_low[v2]!=-10,
"Vids_low[v2] is wrong");
304 cout<<
"x_conn="<<x_connect<<
" yt="<<yt<<
" zt="<<zt<<
" vid="<<Vids_low[v2]<<endl;
305 vertex->GetCoords(x_connect,yt,zt);
312 Vids_low, v1, v2 , x_connect, lastedge, xold_low, yold_low );
315 vertex->GetCoords(x_connect,yt,zt);
321 Array<OneD, int> Vids_up(nvertl,-10);
322 Array<OneD,NekDouble> xold_up(nvertl);
323 Array<OneD,NekDouble> yold_up(nvertl);
329 ( (bndfieldx[lastIregion]->GetExp(0)->as<LocalRegions::SegExp>())
334 vertex0->GetCoords(x0,y0,z0);
337 cout<<
"WARNING x0="<<x0<<endl;
345 Vids_up, v1, v2 , x_connect ,lastedge, xold_up, yold_up);
347 vertexU->GetCoords(x_connect,yt,zt);
354 Vids_up, v1, v2 , x_connect, lastedge, xold_up, yold_up );
358 vertex->GetCoords(x_connect,yt,zt);
364 Array<OneD, int> Vids_c(nvertl,-10);
365 Array<OneD,NekDouble> xold_c(nvertl);
366 Array<OneD,NekDouble> yold_c(nvertl);
370 graphShPt->GetVertex(((bndfieldx[lastIregion]->GetExp(0)
371 ->as<LocalRegions::SegExp>())->GetGeom1D())->GetVid(0));
372 vertex0->GetCoords(x0,y0,z0);
375 cout<<
"WARNING x0="<<x0<<endl;
384 Vids_c, v1, v2 , x_connect ,lastedge, xold_c, yold_c);
388 vertexc->GetCoords(x_connect,yt,zt);
395 Vids_c, v1, v2 , x_connect, lastedge, xold_c, yold_c );
399 vertex->GetCoords(x_connect,yt,zt);
405 Array<OneD, NekDouble> Deltaup (nvertl, -200);
406 Array<OneD, NekDouble> Deltalow (nvertl, -200);
408 for(
int r=0; r<nvertl; r++)
412 Deltaup[r] = yold_up[r] - yold_c[r];
413 Deltalow[r] = yold_c[r] - yold_low[r];
414 ASSERTL0(Deltaup[r]>0,
"distance between upper and layer curve is not positive");
415 ASSERTL0(Deltalow[r]>0,
"distance between lower and layer curve is not positive");
436 if(vSession->DefinesParameter(
"npedge"))
438 npedge = (int)vSession->GetParameter(
"npedge");
446 int nq= streak->GetTotPoints();
447 Array<OneD, NekDouble> x(nq);
448 Array<OneD,NekDouble> y(nq);
449 streak->GetCoords(x,y);
450 Array<OneD, NekDouble> x_c(nvertl);
451 Array<OneD,NekDouble> y_c(nvertl,-200);
452 Array<OneD, NekDouble> tmp_w (nvertl, 200);
453 Array<OneD, int> Sign (nvertl,1);
454 Array<OneD, NekDouble> Delta_c(nvertl,-200);
458 xold_low, yold_low, xold_c, yold_c, x_c, y_c,cr,
true);
461 for(
int q=0; q<nvertl; q++)
463 if(y_c[q] < yold_c[q])
468 Delta_c[q] = abs(yold_c[q]-y_c[q]);
471 cout<<x_c[q]<<
" "<<y_c[q]<<endl;
476 cout<<
"Warning: the critical layer is stationary"<<endl;
482 Array<OneD, NekDouble> Cpointsx (nedges);
483 Array<OneD, NekDouble> Cpointsy (nedges, 0.0);
484 Array<OneD, int> Eids (nedges);
485 Array<OneD, NekDouble> Addpointsx (nedges*(npedge-2), 0.0);
486 Array<OneD, NekDouble> Addpointsy (nedges*(npedge-2), 0.0);
488 Array<OneD, NekDouble> dU(streak->GetTotPoints());
499 for(
int r=0; r<nedges; r++)
502 bndSegExp = bndfieldx[lastIregion]->GetExp(r)
504 Eid = (bndSegExp->GetGeom1D())->GetEid();
505 id1 = (bndSegExp->GetGeom1D())->GetVid(0);
506 id2 = (bndSegExp->GetGeom1D())->GetVid(1);
507 vertex1 = graphShPt->GetVertex(id1);
508 vertex2 = graphShPt->GetVertex(id2);
510 vertex2->GetCoords(x2,y2,z2);
513 cout<<
"edge="<<r<<
" x1="<<x1<<
" y1="<<y1<<
" x2="<<x2<<
" y2="<<y2<<endl;
516 Cpointsx[r] = x1 +(x2-x1)/2;
519 if( Cpointsx[r]>x2 || Cpointsx[r]< x1)
521 Cpointsx[r] = -Cpointsx[r];
523 for(
int w=0; w< npedge-2; w++)
526 Addpointsx[r*(npedge-2) +w] = x1 +((x2-x1)/(npedge - 1))*(w+1);
527 if( Addpointsx[r*(npedge-2) +w] > x2 || Addpointsx[r*(npedge-2) +w] < x1)
529 Addpointsx[r*(npedge-2) +w] = -Addpointsx[r*(npedge-2) +w];
532 Addpointsy[r*(npedge-2) +w] = y_c[r] + ((y_c[r+1]-y_c[r])/(x_c[r+1]-x_c[r]))*(Addpointsx[r*(npedge-2) +w]-x1);
535 Addpointsx[r*(npedge-2) +w], Addpointsy[r*(npedge-2) +w], streak, dU,cr);
548 Cpointsx[r] = x2+ (x1-x2)/2;
550 if( Cpointsx[r] > x1 || Cpointsx[r] < x2)
552 Cpointsx[r] = -Cpointsx[r];
554 for(
int w=0; w< npedge-2; w++)
556 Addpointsx[r*(npedge-2) +w] = x2 +((x1-x2)/(npedge - 1))*(w+1);
557 if( Addpointsx[r*(npedge-2) +w] > x1 || Addpointsx[r*(npedge-2) +w] < x2)
559 Addpointsx[r*(npedge-2) +w] = -Addpointsx[r*(npedge-2) +w];
563 Addpointsy[r*(npedge-2) +w] = y_c[r+1] + ((y_c[r]-y_c[r+1])/(x_c[r]-x_c[r+1]))*(Addpointsx[r*(npedge-2) +w]-x2);
567 Addpointsx[r*(npedge-2) +w], Addpointsy[r*(npedge-2) +w], streak, dU,cr);
578 ASSERTL0(
false,
"point not generated");
594 Array<OneD, NekDouble> xcPhys (nedges*npedge, 0.0);
595 Array<OneD, NekDouble> ycPhys (nedges*npedge, 0.0);
597 for(
int a=0; a<nedges; a++)
600 xcPhys[a*npedge+0] = x_c[a];
601 ycPhys[a*npedge+0] = y_c[a];
603 xcPhys[a*npedge+npedge-1] = x_c[a+1];
604 ycPhys[a*npedge+npedge-1] = y_c[a+1];
606 for(
int b=0; b<npedge-2; b++)
608 xcPhys[a*npedge +b+1] = Addpointsx[a*(npedge-2)+b];
609 ycPhys[a*npedge +b+1] = Addpointsy[a*(npedge-2)+b];
613 cout<<
"xc,yc before tanevaluate"<<endl;
614 for(
int v=0; v< xcPhys.num_elements(); v++)
616 cout<<xcPhys[v]<<
" "<<ycPhys[v]<<endl;
626 Array<OneD, Array<OneD, int> > lay_Eids;
627 Array<OneD, Array<OneD, int> > lay_Vids;
629 MappingEVids(xold_up, yold_up, xold_low, yold_low, xold_c, yold_c, Vids_c,
630 graphShPt,streak, V1, V2, nlays, lay_Eids, lay_Vids);
634 cout<<
"nlays="<<nlays<<endl;
635 Array<OneD, Array<OneD, NekDouble> > layers_y(nlays);
636 Array<OneD, Array<OneD, NekDouble> > layers_x(nlays);
638 for(
int g=0; g<nlays; g++)
640 layers_y[g]= Array<OneD, NekDouble> ( (nvertl-1)*npedge );
651 if(vSession->DefinesParameter(
"Delta"))
653 Delta0 = vSession->GetParameter(
"Delta");
665 int nVertTot = graphShPt->GetNvertices();
667 Array<OneD, NekDouble> xold(nVertTot);
668 Array<OneD, NekDouble> yold(nVertTot);
670 Array<OneD, NekDouble> xnew(nVertTot);
671 Array<OneD, NekDouble> ynew(nVertTot,-20);
672 Array<OneD, int> Up(nvertl);
673 Array<OneD, int> Down(nvertl);
681 for(
int i=0; i<nVertTot; i++)
686 vertex->GetCoords(x,y,z);
696 if(x==0 && y< yold_low[0]
702 if(x== xold_c[nvertl-1] && y> yold_up[nvertl-1]
708 if(x==xold_c[nvertl-1] && y<yold_low[nvertl-1]
714 if(x== 0 && y> yold_up[0]
720 for(
int j=0; j<nvertl; j++)
722 if((xold_up[j]==x)&&(yold_up[j]==y))
726 ynew[i] = y_c[j] +Delta0;
730 if((xold_low[j]==x)&&(yold_low[j]==y))
734 ynew[i] = y_c[j] -Delta0;
738 if((xold_c[j]==x)&&(yold_c[j]==y))
749 for(
int k=0; k<nvertl; k++)
751 if(abs(x-xold_up[k]) < diff)
753 diff = abs(x-xold_up[k]);
757 if( y>yold_up[qp_closer] && y< 1)
765 ynew[i] = y_c[qp_closer] +(y-yold_c[qp_closer])*
766 (1-y_c[qp_closer])/(1-yold_c[qp_closer]);
772 else if(y<yold_low[qp_closer] && y> -1)
780 ynew[i] = y_c[qp_closer] + (y-yold_c[qp_closer] )*
781 (-1-y_c[qp_closer])/(-1-yold_c[qp_closer]);
785 else if ( y>yold_c[qp_closer] && y < yold_up[qp_closer])
792 else if (y<yold_c[qp_closer] && y > yold_low[qp_closer])
794 if(x==0){ cntlow++; }
799 else if( y==1 || y==-1)
806 if( (ynew[i]>1 || ynew[i]<-1)
807 && ( y>yold_up[qp_closer] || y<yold_low[qp_closer]) )
809 cout<<
"point x="<<xnew[i]<<
" y="<<y<<
" closer x="<<xold_up[qp_closer]<<
" ynew="<<ynew[i]<<endl;
810 ASSERTL0(
false,
"shifting out of range");
820 int nqedge = streak->GetExp(0)->GetNumPoints(0);
821 int nquad_lay = (nvertl-1)*nqedge;
822 Array<OneD, NekDouble> coeffstmp(Cont_y->GetNcoeffs(),0.0);
826 int np_lay = (nvertl-1)*npedge;
828 Array<OneD, NekDouble> xcQ(nqedge*nedges,0.0);
829 Array<OneD, NekDouble> ycQ(nqedge*nedges,0.0);
830 Array<OneD, NekDouble> zcQ(nqedge*nedges,0.0);
831 Array<OneD, NekDouble> nxPhys(npedge*nedges,0.0);
832 Array<OneD, NekDouble> nyPhys(npedge*nedges,0.0);
833 Array<OneD, NekDouble> nxQ(nqedge*nedges,0.0);
834 Array<OneD, NekDouble> nyQ(nqedge*nedges,0.0);
836 if( move_norm==
true )
840 Array<OneD, NekDouble> xcPhysMOD(xcPhys.num_elements());
841 Array<OneD, NekDouble> ycPhysMOD(ycPhys.num_elements());
843 Vmath::Vcopy(xcPhys.num_elements(),xcPhys,1,xcPhysMOD,1);
844 Vmath::Vcopy(xcPhys.num_elements(),ycPhys,1,ycPhysMOD,1);
846 Array<OneD, StdRegions::StdExpansion1DSharedPtr> Edge_newcoords(2);
848 cout<<
"nquad per edge="<<nqedge<<endl;
849 for(
int l=0; l<2; l++)
851 Edge_newcoords[l] = bndfieldx[lastIregion]->GetExp(0)
854 Array<OneD, NekDouble> xnull(nqedge);
855 Array<OneD, NekDouble> ynull(nqedge);
856 Array<OneD, NekDouble> xcedgeQ(nqedge,0.0);
857 Array<OneD, NekDouble> ycedgeQ(nqedge,0.0);
858 Array<OneD, NekDouble> txedgeQ(nqedge,0.0);
859 Array<OneD, NekDouble> tyedgeQ(nqedge,0.0);
860 Array<OneD, NekDouble> normsQ(nqedge,0.0);
862 Array<OneD, NekDouble> txQ(nqedge*nedges,0.0);
863 Array<OneD, NekDouble> tyQ(nqedge*nedges,0.0);
864 Array<OneD, NekDouble> tx_tyedgeQ(nqedge,0.0);
865 Array<OneD, NekDouble> nxedgeQ(nqedge,0.0);
866 Array<OneD, NekDouble> nyedgeQ(nqedge,0.0);
867 Array<OneD, const NekDouble> ntempQ(nqedge) ;
869 Array<OneD, NekDouble> nxedgePhys(npedge,0.0);
870 Array<OneD, NekDouble> nyedgePhys(npedge,0.0);
873 Array<OneD, NekDouble> CoordsPhys(2);
876 bndfieldx[lastIregion]->GetCoords(xcQ, ycQ, zcQ);
879 Array<OneD, NekDouble>x_tmp(np_lay-(nedges-1),0.0);
880 Array<OneD, NekDouble>y_tmp(np_lay-(nedges-1),0.0);
881 Array<OneD, NekDouble>closex(4,0.0);
882 Array<OneD, NekDouble>closey(4,0.0);
885 for(
int l=0; l< xcQ.num_elements(); l++)
895 xcQ[l],4,closex,closey );
906 Array<OneD, NekDouble> coeffsy(Cont_y->GetNcoeffs(),0.0);
908 Cont_y->FwdTrans_IterPerExp(Cont_y->GetPhys(), coeffsy);
909 Cont_y->BwdTrans_IterPerExp( coeffsy, Cont_y->UpdatePhys());
912 cout<<
"xcQ, ycQ"<<endl;
913 for(
int s=0; s<xcQ.num_elements(); s++)
915 cout<<xcQ[s]<<
" "<<ycQ[s]<<endl;
918 bool evaluatetan=
false;
920 Array<OneD, int> edgeinterp(2);
922 for(
int k=0; k<nedges; k++)
927 Edge_newcoords[0]->StdPhysDeriv(xcedgeQ,txedgeQ);
928 Edge_newcoords[1]->StdPhysDeriv(ycedgeQ,tyedgeQ);
932 Vmath::Vvtvp(nqedge,tyedgeQ,1,tyedgeQ,1,normsQ,1,normsQ,1);
947 for(
int u=0; u<nqedge-1; u++)
949 incratio = (ycedgeQ[u+1]- ycedgeQ[u])/(xcedgeQ[u+1]- xcedgeQ[u]);
950 cout<<
"incratio="<<incratio<<endl;
951 if(abs(incratio)> 4.0 && evaluatetan==false )
953 cout<<
"wrong="<<wrong<<endl;
955 ASSERTL0(wrong<2,
"number edges to change is too high!!");
963 cout<<
"tan bef"<<endl;
964 for(
int e=0; e< nqedge; e++)
966 cout<<xcedgeQ[e]<<
" "<<ycedgeQ[e]<<
" "<<txedgeQ[e]<<endl;
971 Array<OneD, NekDouble> coeffsinterp(polyorder+1);
972 Array<OneD, NekDouble> yPedges(npedge,0.0);
973 Array<OneD, NekDouble> xPedges(npedge,0.0);
974 Vmath::Vcopy(npedge, &xcPhysMOD[k*npedge+0],1,&xPedges[0],1);
975 Vmath::Vcopy(npedge, &ycPhysMOD[k*npedge+0],1,&yPedges[0],1);
977 PolyFit(polyorder,nqedge, xcedgeQ,ycedgeQ, coeffsinterp, xPedges,yPedges, npedge);
979 Vmath::Vcopy(npedge, &xPedges[0],1, &xcPhysMOD[k*npedge+0],1);
980 Vmath::Vcopy(npedge, &yPedges[0],1, &ycPhysMOD[k*npedge+0],1);
987 Vmath::Vcopy(nqedge, &(txedgeQ[0]), 1, &(txQ[nqedge*k]),1);
988 Vmath::Vcopy(nqedge, &(tyedgeQ[0]), 1, &(tyQ[nqedge*k]),1);
991 Array<OneD, NekDouble> fz(nedges*nqedge,0.0);
993 for(
int w=0; w< fz.num_elements(); w++)
995 txQ[w] = cos(atan(fz[w]));
996 tyQ[w] = sin(atan(fz[w]));
997 cout<<xcQ[w]<<
" "<<ycQ[w]<<
" "<<fz[w]<<endl;
1002 Vmath::Vcopy(nquad_lay, txQ,1, Cont_y->UpdatePhys(),1);
1003 Cont_y->FwdTrans_IterPerExp(Cont_y->GetPhys(), coeffsy);
1004 Cont_y->BwdTrans_IterPerExp( coeffsy, Cont_y->UpdatePhys());
1007 Vmath::Vcopy(nquad_lay, tyQ,1, Cont_y->UpdatePhys(),1);
1008 Cont_y->FwdTrans_IterPerExp(Cont_y->GetPhys(), coeffsy);
1009 Cont_y->BwdTrans_IterPerExp( coeffsy, Cont_y->UpdatePhys());
1021 for(
int q=0; q<2; q++)
1023 edgebef = edgeinterp[q]-1;
1024 incbefore = (txQ[edgebef*nqedge+nqedge-1]-txQ[edgebef*nqedge])/
1025 (xcQ[edgebef*nqedge+nqedge-1]-xcQ[edgebef*nqedge]);
1026 inc = (txQ[edgeinterp[q]*nqedge+nqedge-1]-txQ[edgeinterp[q]*nqedge])/
1027 (xcQ[edgeinterp[q]*nqedge+nqedge-1]-xcQ[edgeinterp[q]*nqedge]);
1028 int npoints = 2*nqedge;
1030 Array<OneD, NekDouble> yQedges(npoints,0.0);
1031 Array<OneD, NekDouble> xQedges(npoints,0.0);
1032 Array<OneD, NekDouble> tyQedges(npoints,0.0);
1033 Array<OneD, NekDouble> txQedges(npoints,0.0);
1034 cout<<
"inc="<<inc<<
" incbef="<<incbefore<<endl;
1035 if( (inc/incbefore)>0. )
1037 cout<<
"before!!"<<edgebef<<endl;
1039 Array<OneD, NekDouble> coeffsinterp(polyorder+1);
1040 Vmath::Vcopy(npoints, &xcQ[edgebef*nqedge+0],1,&xQedges[0],1);
1041 Vmath::Vcopy(npoints, &ycQ[edgebef*nqedge+0],1,&yQedges[0],1);
1042 Vmath::Vcopy(npoints, &txQ[edgebef*nqedge+0],1,&txQedges[0],1);
1043 Vmath::Vcopy(npoints, &tyQ[edgebef*nqedge+0],1,&tyQedges[0],1);
1047 coeffsinterp, xQedges,txQedges, npoints);
1050 Vmath::Vcopy(npoints,&txQedges[0],1, &txQ[edgebef*nqedge+0],1);
1054 coeffsinterp, xQedges,tyQedges, npoints);
1057 Vmath::Vcopy(npoints,&tyQedges[0],1, &tyQ[edgebef*nqedge+0],1);
1062 cout<<
"after!!"<<endl;
1064 Array<OneD, NekDouble> coeffsinterp(polyorder+1);
1065 Vmath::Vcopy(npoints, &xcQ[edgeinterp[q]*nqedge+0],1,&xQedges[0],1);
1066 Vmath::Vcopy(npoints, &ycQ[edgeinterp[q]*nqedge+0],1,&yQedges[0],1);
1067 Vmath::Vcopy(npoints, &txQ[edgeinterp[q]*nqedge+0],1,&txQedges[0],1);
1068 Vmath::Vcopy(npoints, &tyQ[edgeinterp[q]*nqedge+0],1,&tyQedges[0],1);
1073 coeffsinterp, xQedges,txQedges, npoints);
1076 Vmath::Vcopy(npoints,&txQedges[0],1, &txQ[edgeinterp[q]*nqedge+0],1);
1080 coeffsinterp, xQedges,tyQedges, npoints);
1083 Vmath::Vcopy(npoints,&tyQedges[0],1, &tyQ[edgeinterp[q]*nqedge+0],1);
1092 Vmath::Vcopy(nquad_lay, tyQ,1, Cont_y->UpdatePhys(),1);
1093 Cont_y->FwdTrans_IterPerExp(Cont_y->GetPhys(), coeffstmp);
1094 Cont_y->BwdTrans_IterPerExp( coeffstmp, Cont_y->UpdatePhys());
1097 Vmath::Vcopy(nquad_lay, txQ,1, Cont_y->UpdatePhys(),1);
1098 Cont_y->FwdTrans_IterPerExp(Cont_y->GetPhys(), coeffstmp);
1099 Cont_y->BwdTrans_IterPerExp( coeffstmp, Cont_y->UpdatePhys());
1102 for(
int k=0; k<nedges; k++)
1110 Vmath::Vcopy(nqedge, &(txQ[nqedge*k]),1, &(txedgeQ[0]), 1);
1111 Vmath::Vcopy(nqedge, &(tyQ[nqedge*k]),1, &(tyedgeQ[0]), 1);
1113 Vmath::Vdiv(nqedge, txedgeQ,1,tyedgeQ,1,tx_tyedgeQ,1);
1114 Vmath::Vmul(nqedge, tx_tyedgeQ,1,tx_tyedgeQ,1,tx_tyedgeQ,1);
1120 Vmath::Vcopy(nqedge, &(nxedgeQ[0]),1, &(nxQ[nqedge*k]),1);
1122 Vmath::Vmul(nqedge, nxedgeQ,1,nxedgeQ,1,nyedgeQ,1);
1128 Vmath::Vcopy(nqedge, &(nyedgeQ[0]), 1, &(nyQ[nqedge*k]),1);
1131 cout<<
"edge:"<<k<<endl;
1132 cout<<
"tan/normal"<<endl;
1133 for(
int r=0; r<nqedge; r++)
1135 cout<<xcQ[k*nqedge+r]<<
" "<<txedgeQ[r]<<
" "<<tyedgeQ[r]<<
" "
1136 <<nxedgeQ[r]<<
" "<<nyedgeQ[r]<<endl;
1142 Vmath::Vcopy(nquad_lay, nyQ,1, Cont_y->UpdatePhys(),1);
1144 Cont_y->FwdTrans_IterPerExp(Cont_y->GetPhys(), coeffstmp);
1145 Cont_y->BwdTrans_IterPerExp( coeffstmp, Cont_y->UpdatePhys());
1149 Vmath::Zero(Cont_y->GetNcoeffs(),Cont_y->UpdateCoeffs(),1);
1150 Vmath::Vcopy(nquad_lay, nxQ,1, Cont_y->UpdatePhys(),1);
1151 Cont_y->FwdTrans_IterPerExp(Cont_y->GetPhys(), coeffstmp);
1152 Cont_y->BwdTrans_IterPerExp( coeffstmp, Cont_y->UpdatePhys());
1156 for(
int k=0; k<nedges; k++)
1162 nyQ[(k-1)*nqedge+nqedge-1]=
1167 nxQ[(k-1)*nqedge+nqedge-1]=
1172 Array<OneD, NekDouble>x_tmpQ(nquad_lay-(nedges-1));
1174 Array<OneD, NekDouble>tmpnyQ(nquad_lay-(nedges-1));
1176 cout<<
"nx,yQbefore"<<endl;
1177 for(
int u=0; u<xcQ.num_elements(); u++)
1179 cout<<xcQ[u]<<
" "<<nyQ[u]<<
" "<<txQ[u]<<endl;
1185 cout<<
"nx,yQ"<<endl;
1186 for(
int u=0; u<x_tmpQ.num_elements(); u++)
1188 cout<<x_tmpQ[u]<<
" "<<tmpnyQ[u]<<endl;
1192 for(
int k=0; k<nedges; k++)
1195 for(
int a=0; a<npedge; a++)
1199 nxPhys[k*npedge +a]= nxQ[k*nqedge +0];
1200 nyPhys[k*npedge +a]= nyQ[k*nqedge +0];
1203 else if(a== npedge-1)
1205 nxPhys[k*npedge +a]= nxQ[k*nqedge +nqedge-1];
1206 nyPhys[k*npedge +a]= nyQ[k*nqedge +nqedge-1];
1224 Array<OneD, NekDouble> Pxinterp(4);
1225 Array<OneD, NekDouble> Pyinterp(4);
1230 nyPhys[k*npedge +a]=
1240 nxPhys[k*npedge +a]= -sqrt(abs(1- nyPhys[k*npedge +a]*nyPhys[k*npedge +a]));
1256 nyPhys[(k-1)*npedge+npedge-1]=
1261 nxPhys[(k-1)*npedge+npedge-1]=
1266 cout<<
"xcPhys,,"<<endl;
1267 for(
int s=0; s<np_lay; s++)
1270 cout<<xcPhysMOD[s]<<
" "<<ycPhysMOD[s]<<
" "<<nxPhys[s]<<
" "<<nyPhys[s]<<endl;
1280 Array<OneD, NekDouble> delta(nlays);
1281 Array<OneD, NekDouble>tmpy_lay(np_lay);
1282 Array<OneD, NekDouble>tmpx_lay(np_lay);
1283 for(
int m=0; m<nlays; m++)
1290 delta[m] = -(cntlow+1-m)*Delta0/(cntlow+1);
1294 delta[m] = ( m-(cntlow) )*Delta0/(cntlow+1);
1298 layers_x[m]= Array<OneD, NekDouble>(np_lay);
1301 for(
int h=0; h< nvertl; h++)
1308 if(move_norm==
false)
1310 ynew[lay_Vids[m][h] ]= y_c[h] +delta[m];
1311 xnew[lay_Vids[m][h] ]= x_c[h];
1315 if(h==0 || h==nvertl-1 )
1317 ynew[lay_Vids[m][h] ]= y_c[h] +delta[m];
1318 xnew[lay_Vids[m][h] ]= x_c[h];
1322 ynew[lay_Vids[m][h] ]= y_c[h] +delta[m]*abs(nyPhys[h*npedge+0]);
1323 xnew[lay_Vids[m][h] ]= x_c[h] +delta[m]*abs(nxPhys[h*npedge+0]);
1326 cout<<
"Vid x="<<xnew[lay_Vids[m][h] ]<<
" y="<<ynew[lay_Vids[m][h] ]<<endl;
1331 cout<<
"edge=="<<h<<endl;
1334 ASSERTL0( nyPhys[h*npedge+0]==nyPhys[(h-1)*npedge+npedge-1],
" normaly wrong");
1335 ASSERTL0( nxPhys[h*npedge+0]==nxPhys[(h-1)*npedge+npedge-1],
" normalx wrong");
1338 if(move_norm==
false)
1341 layers_y[m][h*npedge +0] = y_c[h] +delta[m];
1342 layers_x[m][h*npedge +0] = xnew[lay_Vids[m][h] ];
1344 layers_y[m][h*npedge +npedge-1] = y_c[h+1] +delta[m];
1345 layers_x[m][h*npedge +npedge-1] = xnew[lay_Vids[m][h+1] ];
1347 for(
int d=0; d< npedge-2; d++)
1349 layers_y[m][h*npedge +d+1]= ycPhysMOD[h*npedge +d+1] +delta[m];
1351 layers_x[m][h*npedge +d+1]= xcPhysMOD[h*npedge +d+1];
1360 tmpy_lay[h*npedge +0] = y_c[h] +delta[m];
1361 tmpx_lay[h*npedge +0] = xnew[lay_Vids[m][h] ];
1363 tmpy_lay[h*npedge +npedge-1] =
1364 y_c[h+1] +delta[m]*abs(nyPhys[h*npedge +npedge-1]);
1365 tmpx_lay[h*npedge +npedge-1] =
1366 x_c[h+1] +delta[m]*abs(nxPhys[h*npedge +npedge-1]);
1368 else if(h==nedges-1)
1371 tmpy_lay[h*npedge +0] =
1372 y_c[h] +delta[m]*abs(nyPhys[h*npedge +0]);
1373 tmpx_lay[h*npedge +0] =
1374 x_c[h] +delta[m]*abs(nxPhys[h*npedge +0]);
1376 tmpy_lay[h*npedge +npedge-1] = y_c[h+1] +delta[m];
1377 tmpx_lay[h*npedge +npedge-1] = xnew[lay_Vids[m][h+1] ];
1382 tmpy_lay[h*npedge +0] =
1383 y_c[h] +delta[m]*abs(nyPhys[h*npedge +0]);
1384 tmpx_lay[h*npedge +0] =
1385 x_c[h] +delta[m]*abs(nxPhys[h*npedge +0]);
1387 tmpy_lay[h*npedge +npedge-1] =
1388 y_c[h+1] +delta[m]*abs(nyPhys[h*npedge +npedge-1]);
1389 tmpx_lay[h*npedge +npedge-1] =
1390 x_c[h+1] +delta[m]*abs(nxPhys[h*npedge +npedge-1]);
1394 for(
int d=0; d< npedge-2; d++)
1397 tmpy_lay[h*npedge +d+1] = ycPhysMOD[h*npedge +d+1] +
1398 delta[m]*abs(nyPhys[h*npedge +d+1]);
1401 tmpx_lay[h*npedge +d+1]= xcPhysMOD[h*npedge +d+1] +
1402 delta[m]*abs(nxPhys[h*npedge +d+1]);
1419 for(
int s=0; s<np_lay; s++)
1421 cout<<tmpx_lay[s]<<
" "<<tmpy_lay[s]<<endl;
1424 cout<<
"fisrt interp"<<endl;
1425 for(
int s=0; s<np_lay; s++)
1427 cout<<tmpx_lay[s]<<
" "<<tmpy_lay[s]<<endl;
1439 NekDouble boundright = xcPhysMOD[np_lay-1];
1440 bool outboundleft=
false;
1441 bool outboundright=
false;
1442 if(tmpx_lay[1]< boundleft )
1444 outboundleft =
true;
1446 if(tmpx_lay[np_lay-2] > boundright )
1448 outboundright =
true;
1455 Array<OneD, int> vertout(nvertl);
1456 for(
int r=0; r< nedges; r++)
1459 if(tmpx_lay[r*npedge + npedge-1]< boundleft && outboundleft==
true )
1467 if( tmpx_lay[(r+1)*npedge + npedge-1]> boundleft )
1469 for(
int s=0; s<npedge-2; s++)
1471 if(tmpx_lay[(r+1)*npedge + s+1]< boundleft)
1481 if(tmpx_lay[r*npedge + 0]> boundright && outboundright==
true )
1489 if( tmpx_lay[(r-1)*npedge + 0]< boundright )
1491 for(
int s=0; s<npedge-2; s++)
1493 if(tmpx_lay[(r-1)*npedge + s+1]> boundright)
1505 outcount = outvert*npedge+1+ outmiddle;
1507 int replacepointsfromindex=0;
1508 for(
int c=0; c<nedges; c++)
1511 if(xcPhysMOD[c*npedge+npedge-1] <= tmpx_lay[c*(npedge-(npedge-2)) +2] && outboundright==
true)
1513 replacepointsfromindex = c*(npedge-(npedge-2))+2;
1518 if(xcPhysMOD[(nedges-1 -c)*npedge+0] >= tmpx_lay[np_lay-1 -(c*(npedge-(npedge-2)) +2)] && outboundleft==
true)
1520 replacepointsfromindex = np_lay-1 -(c*(npedge-(npedge-2)) +2);
1536 if( outboundright==
true)
1538 pstart = replacepointsfromindex;
1539 shift = np_lay-outcount;
1540 increment = (xcPhysMOD[np_lay-outcount]-xcPhysMOD[pstart])/(outcount+1);
1541 outcount = outcount-1;
1542 ASSERTL0(tmpx_lay[np_lay-outcount]>xcPhysMOD[(nedges-1)*npedge+0],
"no middle points in the last edge");
1548 increment = (xcPhysMOD[replacepointsfromindex]-xcPhysMOD[pstart])/(outcount+1);
1549 ASSERTL0(tmpx_lay[pstart]<xcPhysMOD[0*npedge +npedge-1],
"no middle points in the first edge");
1553 Array<OneD, NekDouble> replace_x(outcount);
1554 Array<OneD, NekDouble> replace_y(outcount);
1556 Array<OneD, NekDouble>x_tmp(np_lay-(nedges-1));
1557 Array<OneD, NekDouble>y_tmp(np_lay-(nedges-1));
1558 Array<OneD, NekDouble>tmpny(np_lay-(nedges-1));
1563 Array<OneD, NekDouble>closex(4);
1564 Array<OneD, NekDouble>closey(4);
1565 Array<OneD, NekDouble>closeny(4);
1566 NekDouble xctmp,ycinterp,nxinterp,nyinterp;
1568 for(
int v=0; v<outcount;v++)
1570 xctmp = xcPhysMOD[pstart]+(v+1)*increment;
1583 xctmp,4,closex,closeny );
1586 nxinterp = sqrt(abs(1-nyinterp*nyinterp));
1593 replace_x[v] = xctmp +delta[m]*abs(nxinterp);
1594 replace_y[v] = ycinterp +delta[m]*abs(nyinterp);
1595 tmpx_lay[ v+shift ] = replace_x[v];
1596 tmpy_lay[ v+shift ] = replace_y[v];
1617 int closepoints = 4;
1619 Array<OneD, NekDouble> Pyinterp(closepoints);
1620 Array<OneD, NekDouble> Pxinterp(closepoints);
1624 for(
int q=0; q<np_lay; q++)
1626 for(
int e=0; e<nedges; e++)
1628 if(tmpx_lay[q]<= x_c[e+1] && tmpx_lay[q]>= x_c[e])
1632 if(q == e*npedge +npedge-1 && pointscount!=npedge )
1637 else if(q == e*npedge +npedge-1)
1657 lay_Vids[m], layers_x[m], layers_y[m],xnew,ynew);
1740 int npoints = npedge;
1741 Array<OneD, NekDouble> xPedges(npoints);
1742 Array<OneD, NekDouble> yPedges(npoints);
1743 for(
int f=0; f<nedges; f++)
1747 Array<OneD, NekDouble> coeffsinterp(polyorder+1);
1749 Vmath::Vcopy(npoints, &layers_x[m][(f)*npedge+0],1,&xPedges[0],1);
1750 Vmath::Vcopy(npoints, &layers_y[m][(f)*npedge+0],1,&yPedges[0],1);
1754 coeffsinterp, xPedges,yPedges, npoints);
1757 Vmath::Vcopy(npoints,&yPedges[0],1, &layers_y[m][(f)*npedge+0],1);
1760 layers_y[m][f*npedge+0]= ynew[lay_Vids[m][f]];
1761 layers_y[m][f*npedge+npedge-1]= ynew[lay_Vids[m][f+1]];
1764 cout<<
" xlay ylay lay:"<<m<<endl;
1765 for(
int l=0; l<np_lay; l++)
1768 cout<<std::setprecision(8)<<layers_x[m][l]<<
" "<<layers_y[m][l]<<endl;
1802 cout<<
"lay="<<m<<endl;
1804 " different layer ymin val");
1806 " different layer ymax val");
1808 " different layer xmin val");
1810 " different layer xmax val");
1820 layers_x[0], layers_y[0], layers_x[nlays-1], layers_y[nlays-1],nxPhys, nyPhys,xnew, ynew);
1902 lay_Vids, x_c, y_c, Down, Up, xnew, ynew, layers_x, layers_y);
1913 cout<<std::setprecision(8)<<
"xmin="<<
Vmath::Vmin(nVertTot, xnew,1)<<endl;
1915 " different xmin val");
1917 " different ymin val");
1919 " different xmax val");
1921 " different ymax val");
1927 Replacevertices(changefile, xnew , ynew, xcPhys, ycPhys, Eids, npedge, charalp, layers_x,layers_y, lay_Eids, curv_lay);
1935 Array<OneD, int>& Vids,
int v1,
int v2,
NekDouble x_connect,
int & lastedge,
1936 Array<OneD, NekDouble>& x, Array<OneD, NekDouble>& y)
1938 int nvertl = nedges+1;
1940 Array<OneD, int> Vids_temp(nvertl,-10);
1942 for(
int j=0; j<nedges; j++)
1946 edge = (bndSegExplow->GetGeom1D())->GetEid();
1948 for(
int k=0; k<2; k++)
1950 Vids_temp[j+k]=(bndSegExplow->GetGeom1D())->GetVid(k);
1954 if(x1==x_connect && edge!=lastedge)
1957 if(x_connect==x0layer)
1959 Vids[v1]=Vids_temp[j+k];
1965 Vids_temp[j+1]=(bndSegExplow->GetGeom1D())->GetVid(1);
1966 Vids[v2]=Vids_temp[j+1];
1969 vertex->GetCoords(x2,y2,z2);
1975 Vids_temp[j+0]=(bndSegExplow->GetGeom1D())->GetVid(0);
1976 Vids[v2]=Vids_temp[j+0];
1979 vertex->GetCoords(x2,y2,z2);
1988 Vids_temp[j+1]=(bndSegExplow->GetGeom1D())->GetVid(1);
1989 Vids[v1]=Vids_temp[j+1];
1992 vertex->GetCoords(x1,y1,z1);
1998 Vids_temp[j+0]=(bndSegExplow->GetGeom1D())->GetVid(0);
1999 Vids[v1]=Vids_temp[j+0];
2002 vertex->GetCoords(x1,y1,z1);
2021 Array<OneD, NekDouble> xold_up, Array<OneD, NekDouble> yold_up,
2022 Array<OneD, NekDouble> xold_low, Array<OneD, NekDouble> yold_low,
2023 Array<OneD, NekDouble> xold_c, Array<OneD, NekDouble> yold_c,
2024 Array<OneD, NekDouble> &xc, Array<OneD, NekDouble> &yc,
NekDouble cr,
2027 cout<<
"Computestreakpositions"<<endl;
2028 int nq = streak->GetTotPoints();
2029 Array<OneD, NekDouble> coord(2);
2031 Array<OneD, NekDouble> derstreak(nq);
2042 Vmath::Vadd(xc.num_elements(), yold_up,1,yold_low,1, yc,1);
2056 for(
int e=0; e<npoints; e++)
2061 elmtid = streak->GetExpIndex(coord,0.00001);
2062 offset = streak->GetPhys_Offset(elmtid);
2068 while( abs(F)> 0.000000001)
2071 elmtid = streak->GetExpIndex(coord,0.00001);
2076 if( (abs(coord[1])>1 || elmtid==-1)
2077 && attempt==0 && verts==
true
2081 coord[1] = yold_c[e];
2084 else if( (abs(coord[1])>1 || elmtid==-1) )
2086 coord[1] = ytmp +0.01;
2087 elmtid = streak->GetExpIndex(coord,0.001);
2088 offset = streak->GetPhys_Offset(elmtid);
2089 NekDouble Utmp = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() + offset);
2090 NekDouble dUtmp = streak->GetExp(elmtid)->PhysEvaluate(coord, derstreak + offset);
2091 coord[1] = coord[1] - (Utmp-cr)/dUtmp;
2092 if( (abs(Utmp-cr)>abs(F))||(abs(coord[1])>1) )
2094 coord[1] = ytmp -0.01;
2101 ASSERTL0(abs(coord[1])<= 1,
" y value out of bound +/-1");
2103 offset = streak->GetPhys_Offset(elmtid);
2104 U = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() + offset);
2105 dU = streak->GetExp(elmtid)->PhysEvaluate(coord, derstreak + offset);
2106 coord[1] = coord[1] - (U-cr)/dU;
2108 ASSERTL0( coord[0]==xc[e],
" x coordinate must remain the same");
2111 if(its>200 && abs(F)<0.00001)
2113 cout<<
"warning streak position obtained with precision:"<<F<<endl;
2116 else if(its>1000 && abs(F)< 0.0001)
2118 cout<<
"warning streak position obtained with precision:"<<F<<endl;
2123 ASSERTL0(
false,
"no convergence after 1000 iterations");
2126 yc[e] = coord[1] - (U-cr)/dU;
2127 ASSERTL0( U<= cr + tol,
"streak wrong+");
2128 ASSERTL0( U>= cr -tol,
"streak wrong-");
2130 cout<<
"result streakvert x="<<xc[e]<<
" y="<<yc[e]<<
" streak="<<U<<endl;
2142 Array<OneD, NekDouble> coords(2);
2151 while( abs(F)> 0.00000001)
2155 elmtid =
function->GetExpIndex(coords, 0.01);
2157 cout<<
"gen newton xi="<<xi<<
" yi="<<coords[1]<<
" elmtid="<<elmtid<<
" F="<<F<<endl;
2159 if( (abs(coords[1])>1 || elmtid==-1) )
2162 coords[1] = ytmp +0.01;
2163 elmtid =
function->GetExpIndex(coords,0.01);
2164 offset =
function->GetPhys_Offset(elmtid);
2165 NekDouble Utmp =
function->GetExp(elmtid)->PhysEvaluate(coords, function->GetPhys() + offset);
2166 NekDouble dUtmp =
function->GetExp(elmtid)->PhysEvaluate(coords, derfunction + offset);
2167 coords[1] = coords[1] - (Utmp-cr)/dUtmp;
2168 cout<<
"attempt:"<<coords[1]<<endl;
2169 if( (abs(Utmp-cr)>abs(F))||(abs(coords[1])>1.01) )
2171 coords[1] = ytmp -0.01;
2176 else if( abs(coords[1])<1.01 &&attempt==0)
2183 ASSERTL0(abs(coords[1])<= 1.00,
" y value out of bound +/-1");
2185 offset =
function->GetPhys_Offset(elmtid);
2186 U =
function->GetExp(elmtid)->PhysEvaluate(coords, function->GetPhys() + offset);
2187 dU =
function->GetExp(elmtid)->PhysEvaluate(coords, derfunction + offset);
2188 coords[1] = coords[1] - (U-cr)/dU;
2189 cout<<cr<<
"U-cr="<<U-cr<<
" tmp result y:"<<coords[1]<<
" dU="<<dU<<endl;
2193 if(its>200 && abs(F)<0.00001)
2195 cout<<
"warning streak position obtained with precision:"<<F<<endl;
2198 else if(its>1000 && abs(F)< 0.0001)
2200 cout<<
"warning streak position obtained with precision:"<<F<<endl;
2205 ASSERTL0(
false,
"no convergence after 1000 iterations");
2209 ASSERTL0( coords[0]==xi,
" x coordinate must remain the same");
2212 yout = coords[1] - (U-cr)/dU;
2213 cout<<
"NewtonIt result x="<<xout<<
" y="<<coords[1]<<
" U="<<U<<endl;
2217 Array<OneD, int> &V1, Array<OneD, int> &V2)
2220 const boost::shared_ptr<LocalRegions::ExpansionVector> exp2D = field->GetExp();
2221 int nel = exp2D->size();
2227 Array<OneD, int> V1tmp(4*nel, 10000);
2228 Array<OneD, int> V2tmp(4*nel, 10000);
2229 for(
int i=0; i<nel; i++)
2231 if((locQuadExp = (*exp2D)[i]->as<LocalRegions::QuadExp>()))
2233 for(
int j = 0; j < locQuadExp->GetNedges(); ++j)
2235 SegGeom = (locQuadExp->GetGeom2D())->
GetEdge(j);
2236 id = SegGeom->GetEid();
2237 if( V1tmp[
id] == 10000)
2239 V1tmp[id]= SegGeom->GetVertex(0)->GetVid();
2240 V2tmp[id]= SegGeom->GetVertex(1)->GetVid();
2247 else if((locTriExp = (*exp2D)[i]->as<LocalRegions::TriExp>()))
2249 for(
int j = 0; j < locTriExp->GetNedges(); ++j)
2251 SegGeom = (locTriExp->GetGeom2D())->
GetEdge(j);
2252 id = SegGeom->GetEid();
2254 if( V1tmp[
id] == 10000)
2256 V1tmp[id]= SegGeom->GetVertex(0)->GetVid();
2257 V2tmp[id]= SegGeom->GetVertex(1)->GetVid();
2266 V1 = Array<OneD, int>(cnt);
2267 V2 = Array<OneD, int>(cnt);
2269 for(
int g=0; g<cnt; g++)
2272 ASSERTL0(V1tmp[g]!=10000,
"V1 wrong");
2274 ASSERTL0(V2tmp[g]!=10000,
"V2 wrong");
2286 void MappingEVids(Array<OneD, NekDouble> xoldup, Array<OneD, NekDouble> yoldup,
2287 Array<OneD, NekDouble> xolddown, Array<OneD, NekDouble> yolddown,
2288 Array<OneD, NekDouble> xcold, Array<OneD, NekDouble> ycold,
2289 Array<OneD, int> Vids_c,
2292 Array<OneD, int> V1, Array<OneD, int> V2,
2293 int & nlays, Array<
OneD, Array<OneD, int> >& Eids_lay,
2294 Array<
OneD, Array<OneD, int> >& Vids_lay)
2297 int nlay_Eids = xcold.num_elements()-1;
2298 int nlay_Vids = xcold.num_elements();
2300 int nVertsTot = mesh->GetNvertices();
2301 cout<<
"nverttot="<<nVertsTot<<endl;
2305 cout<<
"init nlays="<<nlays<<endl;
2307 Array<OneD, int> tmpVids0(100);
2308 Array<OneD, NekDouble> tmpx0(100);
2309 Array<OneD, NekDouble> tmpy0(100);
2310 Array<OneD, NekDouble> x2D(nVertsTot);
2311 Array<OneD, NekDouble> y2D(nVertsTot);
2312 cout<<
"yoldup="<<yoldup[0]<<endl;
2313 cout<<
"yolddown="<<yolddown[0]<<endl;
2315 for(
int r=0; r< nVertsTot; r++)
2320 vertex->GetCoords(x,y,z);
2327 y<= yoldup[0] && y>= yolddown[0]
2340 cout<<
"nlays="<<nlays<<endl;
2343 Array<OneD, NekDouble> tmpx(nlays);
2344 Array<OneD, NekDouble> tmpf(nlays);
2345 Array<OneD, int> tmpV(nlays);
2352 for(
int w=0; w< nlays; w++)
2355 tmpx0[w]= tmpx[index];
2356 tmpy0[w]= tmpf[index];
2357 tmpVids0[w] = tmpV[index];
2358 tmpf[index] = max+1000;
2367 Eids_lay = Array<OneD, Array<OneD,int> >(nlays);
2368 Vids_lay = Array<OneD, Array<OneD,int> >(nlays);
2369 for(
int m=0; m<nlays; m++)
2371 Eids_lay[m] = Array<OneD, int> (nlay_Eids);
2372 Vids_lay[m] = Array<OneD, int> (nlay_Vids);
2376 NekDouble normbef, normtmp,xbef,ybef,xtmp,ytmp,normnext,xnext,ynext,diff;
2378 Array<OneD, NekDouble> coord(2);
2380 int nTotEdges = V1.num_elements();
2381 Array<OneD, int> edgestmp(6);
2382 for(
int m=0; m<nlays; m++)
2384 for(
int g=0; g<nlay_Eids; g++)
2388 for(
int h=0; h< nTotEdges; h++)
2391 if( tmpVids0[m]== V1[h] )
2395 vertex->GetCoords(x,y,z);
2399 Vids_lay[m][0] = V1[h];
2400 Vids_lay[m][1] = V2[h];
2402 = mesh->GetVertex(V1[h]);
2404 vertex1->GetCoords(x1,y1,z1);
2405 normbef= sqrt( (y-y1)*(y-y1)+(x-x1)*(x-x1) );
2410 elmtid = streak->GetExpIndex(coord,0.00001);
2411 offset = streak->GetPhys_Offset(elmtid);
2412 Ubef = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() + offset);
2417 if( tmpVids0[m]== V2[h] )
2421 vertex->GetCoords(x,y,z);
2425 Vids_lay[m][0] = V2[h];
2426 Vids_lay[m][1] = V1[h];
2428 = mesh->GetVertex(V2[h]);
2430 normbef= sqrt( (y-y2)*(y-y2)+(x-x2)*(x-x2) );
2435 elmtid = streak->GetExpIndex(coord,0.00001);
2436 offset = streak->GetPhys_Offset(elmtid);
2437 Ubef = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() + offset);
2444 cout<<
"Eid="<<Eids_lay[m][0]<<
" Vids_lay0="<<Vids_lay[m][0]<<
" Vidslay1="<<Vids_lay[m][1]<<endl;
2451 for(
int h=0; h< nTotEdges; h++)
2454 if( (Vids_lay[m][g]==V1[h] || Vids_lay[m][g]==V2[h]) && h!= Eids_lay[m][g-1])
2456 cout<<
"edgetmp="<<h<<endl;
2457 ASSERTL0(cnt<=6,
"wrong number of candidates");
2464 Array<OneD, NekDouble > diffarray(cnt);
2465 Array<OneD, NekDouble > diffUarray(cnt);
2466 cout<<
"normbef="<<normbef<<endl;
2467 cout<<
"Ubefcc="<<Ubef<<endl;
2469 for(
int e=0; e< cnt; e++)
2473 vertex1->GetCoords(x1,y1,z1);
2476 vertex2->GetCoords(x2,y2,z2);
2478 normtmp= sqrt( (y2-y1)*(y2-y1)+(x2-x1)*(x2-x1) );
2480 cout<<
"edgetmp1="<<edgestmp[e]<<endl;
2481 cout<<
"V1 x1="<<x1<<
" y1="<<y1<<endl;
2482 cout<<
"V2 x2="<<x2<<
" y2="<<y2<<endl;
2483 if( Vids_lay[m][g]==V1[edgestmp[e]] )
2491 elmtid = streak->GetExpIndex(coord,0.00001);
2492 offset = streak->GetPhys_Offset(elmtid);
2493 Utmp = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() + offset);
2494 diffarray[e] = abs((xtmp*xbef+ytmp*ybef)/(normtmp*normbef)-1);
2495 diffUarray[e] = abs(Ubef-Utmp);
2496 cout<<
" normtmp="<<normtmp<<endl;
2497 cout<<
" Utmpcc="<<Utmp<<endl;
2498 cout<<xtmp<<
" ytmp="<<ytmp<<
" diff="<<abs(((xtmp*xbef+ytmp*ybef)/(normtmp*normbef))-1)<<endl;
2500 abs( (xtmp*xbef+ytmp*ybef)/(normtmp*normbef)-1)<diff
2501 && y2<= yoldup[g+1] && y2>= yolddown[g+1]
2502 && y1<= yoldup[g] && y1>= yolddown[g]
2506 Eids_lay[m][g] = edgestmp[e];
2507 Vids_lay[m][g+1] = V2[edgestmp[e]];
2508 diff = abs((xtmp*xbef+ytmp*ybef)/(normtmp*normbef)-1);
2515 else if( Vids_lay[m][g]==V2[edgestmp[e]] )
2523 elmtid = streak->GetExpIndex(coord,0.00001);
2524 offset = streak->GetPhys_Offset(elmtid);
2525 Utmp = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() + offset);
2526 diffarray[e] = abs((xtmp*xbef+ytmp*ybef)/(normtmp*normbef)-1);
2527 diffUarray[e] = abs(Ubef-Utmp);
2528 cout<<
" normtmp="<<normtmp<<endl;
2529 cout<<
" Utmpcc="<<Utmp<<endl;
2530 cout<<xtmp<<
" ytmp="<<ytmp<<
" diff="<<abs(((xtmp*xbef+ytmp*ybef)/(normtmp*normbef))-1)<<endl;
2532 abs((xtmp*xbef+ytmp*ybef)/(normtmp*normbef)-1)<diff
2533 && y2<= yoldup[g] && y2>= yolddown[g]
2534 && y1<= yoldup[g+1] && y1>= yolddown[g+1]
2537 Eids_lay[m][g] = edgestmp[e];
2538 Vids_lay[m][g+1] = V1[edgestmp[e]];
2539 diff = abs((xtmp*xbef+ytmp*ybef)/(normtmp*normbef)-1);
2555 cout<<
"Eid before check="<<Eids_lay[m][g]<<endl;
2556 for(
int q=0; q<cnt; q++)
2558 cout<<q<<
" diff"<<diffarray[q]<<endl;
2568 cout<<
"COMMON VERT"<<endl;
2570 diffarray[eid]=1000;
2576 vertex1->GetCoords(x1,y1,z1);
2579 vertex2->GetCoords(x2,y2,z2);
2581 normtmp= sqrt( (y2-y1)*(y2-y1)+(x2-x1)*(x2-x1) );
2583 Eids_lay[m][g] = edgestmp[eid];
2584 if(Vids_lay[m][g] == V1[edgestmp[eid]])
2588 elmtid = streak->GetExpIndex(coord,0.00001);
2589 offset = streak->GetPhys_Offset(elmtid);
2590 Utmp = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() + offset);
2591 Vids_lay[m][g+1] = V2[edgestmp[eid]];
2599 if(Vids_lay[m][g] == V2[edgestmp[eid]])
2603 elmtid = streak->GetExpIndex(coord,0.00001);
2604 offset = streak->GetPhys_Offset(elmtid);
2605 Utmp = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() + offset);
2606 Vids_lay[m][g+1] = V1[edgestmp[eid]];
2617 cout<<m<<
"edge aft:"<<Eids_lay[m][g]<<
" Vid="<<Vids_lay[m][g+1]<<endl;
2623 cout<<
"endelse"<<normtmp<<endl;
2635 for(
int w=0; w< nlays; w++)
2637 for(
int f=0; f< nlay_Eids; f++)
2639 cout<<
"check="<<w<<
" Eid:"<<Eids_lay[w][f]<<endl;
2649 for(
int u=0; u< Vids_laybefore.num_elements(); u++)
2651 if( Vids_laybefore[u]==Vid || Vids_c[u]==Vid)
2655 cout<<Vid<<
" Vert test="<<Vids_laybefore[u]<<endl;
2663 Array<OneD, NekDouble>& outarray)
2667 int np_lay = inarray.num_elements();
2668 ASSERTL0(inarray.num_elements()%nedges==0,
" something on number npedge");
2672 for(
int w=0; w< np_lay; w++)
2677 if(inarray[w] ==inarray[w+1])
2682 outarray[cnt]= inarray[w];
2687 ASSERTL0( cnt== np_lay-(nedges-1),
"wrong cut");
2693 int npts = xArray.num_elements();
2694 Array<OneD, NekDouble> xcopy(npts);
2702 if(xArray[index]> x)
2710 Array<OneD, NekDouble> yArray,Array<OneD, NekDouble>& Neighbour_x,
2711 Array<OneD, NekDouble>& Neighbour_y)
2713 ASSERTL0( neighpoints%2==0,
"number of neighbour points should be even");
2714 int leftpoints = (neighpoints/2)-1;
2715 int rightpoints = neighpoints/2;
2719 if(index-leftpoints<0)
2722 diff = index-leftpoints;
2724 Vmath::Vcopy(neighpoints, &yArray[0],1,&Neighbour_y[0],1);
2725 Vmath::Vcopy(neighpoints, &xArray[0],1,&Neighbour_x[0],1);
2727 else if( (yArray.num_elements()-1)-index < rightpoints)
2730 int rpoints = (yArray.num_elements()-1)-index;
2731 diff = rightpoints-rpoints;
2733 start = index-leftpoints-diff;
2734 Vmath::Vcopy(neighpoints, &yArray[start],1,&Neighbour_y[0],1);
2735 Vmath::Vcopy(neighpoints, &xArray[start],1,&Neighbour_x[0],1);
2740 start = index-leftpoints;
2741 Vmath::Vcopy(neighpoints, &yArray[start],1,&Neighbour_y[0],1);
2742 Vmath::Vcopy(neighpoints, &xArray[start],1,&Neighbour_x[0],1);
2751 for(
int f=1; f< neighpoints; f++)
2753 ASSERTL0(Neighbour_x[f]!=Neighbour_x[f-1],
" repetition on NeighbourArrays");
2759 Array<OneD,NekDouble> xpts, Array<OneD, NekDouble> funcvals)
2764 for(
int pt=0;pt<
npts;++pt)
2768 for(
int j=0;j<pt; ++j)
2770 h = h * (x - xpts[j])/(xpts[pt]-xpts[j]);
2773 for(
int k=pt+1;k<
npts;++k)
2775 h = h * (x - xpts[k])/(xpts[pt]-xpts[k]);
2779 sum += funcvals[pt]*LagrangePoly;
2787 Array<OneD, NekDouble> coeffsinterp,
2788 Array<OneD, NekDouble> & txQedge, Array<OneD, NekDouble> & tyQedge)
2790 Array<OneD, NekDouble> yprime(npoints,0.0);
2791 int np_pol= coeffsinterp.num_elements();
2792 cout<<
"evaluatetan with "<<np_pol<<endl;
2796 Array<OneD, NekDouble> yinterp(npoints,0.0);
2798 for(
int q=0; q< npoints; q++)
2803 for(
int d=0; d< np_pol-1; d++)
2805 yprime[q] += (derorder +1)*coeffsinterp[d]*std::pow(xcQedge[q],derorder);
2809 for(
int a=0; a< np_pol; a++)
2811 yinterp[q] += coeffsinterp[a]*std::pow(xcQedge[q],polorder);
2819 for(
int n=0; n< npoints; n++)
2823 txQedge[n] = cos((atan((yprime[n]))));
2824 tyQedge[n] = sin((atan((yprime[n]))));
2825 cout<<xcQedge[n]<<
" "<<yinterp[n]<<
" "<<yprime[n]<<
" "<<txQedge[n]<<
" "<<tyQedge[n]<<endl;
2829 void PolyInterp( Array<OneD, NekDouble> xpol, Array<OneD, NekDouble> ypol,
2830 Array<OneD, NekDouble> & coeffsinterp,
2831 Array<OneD, NekDouble> & xcout, Array<OneD, NekDouble> & ycout,
2832 int edge,
int npedge)
2834 int np_pol = xpol.num_elements();
2836 Array<OneD, NekDouble> A (N*N,1.0);
2837 Array<OneD, NekDouble> b (N);
2840 for(
int e=0; e<N; e++)
2843 for(
int w=0; w < N; w++)
2845 A[N*e+row] = std::pow( xpol[w], N-1-e);
2850 for(
int r= 0; r< np_pol; r++)
2858 Array<OneD, int> ipivot (N);
2861 Lapack::Dgetrf( N, N, A.get(), N, ipivot.get(), info);
2864 std::string message =
"ERROR: The " + boost::lexical_cast<std::string>(-info) +
2865 "th parameter had an illegal parameter for dgetrf";
2870 std::string message =
"ERROR: Element u_" + boost::lexical_cast<std::string>(info) +
2871 boost::lexical_cast<std::string>(info) +
" is 0 from dgetrf";
2877 Lapack::Dgetrs(
'N', N, ncolumns_b , A.get() , N, ipivot.get(), b.get(), N, info);
2880 std::string message =
"ERROR: The " + boost::lexical_cast<std::string>(-info) +
2881 "th parameter had an illegal parameter for dgetrf";
2886 std::string message =
"ERROR: Element u_" + boost::lexical_cast<std::string>(info) +
2887 boost::lexical_cast<std::string>(info) +
" is 0 from dgetrf";
2901 for(
int c=0; c< npedge; c++)
2905 ycout[edge*(npedge)+c+1]=0;
2906 for(
int d=0; d< np_pol; d++)
2908 ycout[edge*(npedge)+c+1] += b[d]
2909 *std::pow(xcout[edge*(npedge)+c+1],polorder);
2921 Array<OneD, NekDouble> xin, Array<OneD, NekDouble> fin,
2922 Array<OneD, NekDouble> & coeffsinterp,
2923 Array<OneD, NekDouble> & xout, Array<OneD, NekDouble> & fout,
2927 int N = polyorder+1;
2928 Array<OneD, NekDouble> A (N*N,0.0);
2929 Array<OneD, NekDouble> b (N,0.0);
2930 cout<<npoints<<endl;
2931 for(
int u=0; u<npoints; u++)
2933 cout<<
"c="<<xin[u]<<
" "<<
2938 for(
int e=0; e<N; e++)
2941 for(
int row=0; row<N; row++)
2943 for(
int w=0; w < npoints; w++)
2945 A[N*e+row] += std::pow( xin[w], e+row);
2950 for(
int row= 0; row< N; row++)
2952 for(
int h=0; h< npoints; h++)
2954 b[row] += fin[h]*std::pow(xin[h],row);
2965 Array<OneD, int> ipivot (N);
2968 Lapack::Dgetrf( N, N, A.get(), N, ipivot.get(), info);
2972 std::string message =
"ERROR: The " + boost::lexical_cast<std::string>(-info) +
2973 "th parameter had an illegal parameter for dgetrf";
2978 std::string message =
"ERROR: Element u_" + boost::lexical_cast<std::string>(info) +
2979 boost::lexical_cast<std::string>(info) +
" is 0 from dgetrf";
2984 Lapack::Dgetrs(
'N', N, ncolumns_b , A.get() , N, ipivot.get(), b.get(), N, info);
2987 std::string message =
"ERROR: The " + boost::lexical_cast<std::string>(-info) +
2988 "th parameter had an illegal parameter for dgetrf";
2993 std::string message =
"ERROR: Element u_" + boost::lexical_cast<std::string>(info) +
2994 boost::lexical_cast<std::string>(info) +
" is 0 from dgetrf";
3000 Array<OneD, NekDouble> tmp(N);
3003 for(
int j=0; j<N; j++)
3009 for(
int h=0; h<N; h++)
3011 cout<<
"coeff:"<<b[h]<<endl;
3016 for(
int c=0; c< npout; c++)
3021 for(
int d=0; d< N; d++)
3025 *std::pow(xout[c],polorder);
3039 Array<OneD, NekDouble> inarray_y, Array<OneD, NekDouble>& outarray_x,
3040 Array<OneD, NekDouble>& outarray_y)
3042 Array<OneD, NekDouble>tmpx(inarray_x.num_elements());
3043 Array<OneD, NekDouble>tmpy(inarray_x.num_elements());
3045 Vmath::Vcopy(inarray_x.num_elements() , inarray_x,1,tmpx,1);
3046 Vmath::Vcopy(inarray_x.num_elements() , inarray_y,1,tmpy,1);
3051 for(
int w=0; w<tmpx.num_elements(); w++)
3054 outarray_x[w]= tmpx[index];
3055 outarray_y[w]= tmpy[index];
3056 if(w< tmpx.num_elements()-1)
3058 if(tmpx[index] == tmpx[index+1])
3060 outarray_x[w+1]= tmpx[index+1];
3061 outarray_y[w+1]= tmpy[index+1];
3062 tmpx[index+1] = max+1000;
3078 tmpx[index] = max+1000;
3084 Array<
OneD, Array<OneD, int > > lay_Vids, Array<OneD, NekDouble> xc,
3085 Array<OneD, NekDouble> yc, Array<OneD, int> Down, Array<OneD, int> Up,
3086 Array<OneD, NekDouble >& xnew,Array<OneD, NekDouble>& ynew,
3087 Array<
OneD, Array<OneD, NekDouble > >& layers_x,
3088 Array<
OneD, Array<OneD, NekDouble > >& layers_y)
3090 int np_lay = layers_y[0].num_elements();
3092 for(
int h=1; h<nlays-1; h++)
3094 layers_x[h]= Array<OneD, NekDouble>(np_lay);
3095 for(
int s=0; s<nvertl; s++)
3098 ASSERTL0(ynew[ lay_Vids[h][s] ]==-20,
"ynew layers not empty");
3102 ynew[ lay_Vids[h][s] ] = ynew[Down[s]]+ h*abs(ynew[Down[s]] - yc[s])/(cntlow+1);
3104 xnew[lay_Vids[h][s] ] = xc[s];
3108 layers_y[h][s] = ynew[ lay_Vids[h][s] ];
3109 layers_x[h][s] = xnew[ lay_Vids[h][s] ];
3114 ynew[ lay_Vids[h][s] ] = yc[s] + (h-cntlow)*abs(ynew[Up[s]] - yc[s])/(cntup+1);
3116 xnew[lay_Vids[h][s] ] = xc[s];
3118 layers_y[h][s] = ynew[ lay_Vids[h][s] ];
3119 layers_x[h][s] = xnew[ lay_Vids[h][s] ];
3128 Array<OneD, NekDouble> tmpx_lay, Array<OneD, NekDouble> tmpy_lay,
3129 Array<OneD, int> Vids,
3130 Array<OneD, NekDouble> &xlay, Array<OneD, NekDouble> &ylay,
3131 Array<OneD, NekDouble> &xnew, Array<OneD, NekDouble> &ynew)
3133 int np_lay = xcPhys.num_elements();
3134 int nedges = nvertl-1;
3135 Array<OneD, NekDouble>tmpx(np_lay-(nedges-1));
3136 Array<OneD, NekDouble>tmpy(np_lay-(nedges-1));
3141 int closepoints = 4;
3142 Array<OneD, NekDouble>Pxinterp(closepoints);
3143 Array<OneD, NekDouble>Pyinterp(closepoints);
3146 for(
int g=0; g< nedges; g++)
3155 xnew[Vids[g] ]= xcPhys[g*npedge+0];
3156 ylay[g*npedge +0] = ynew[ Vids[g] ];
3157 xlay[g*npedge +0] = xnew[ Vids[g] ];
3165 ynew[Vids[g+1] ]=
LagrangeInterpolant(xcPhys[g*npedge +npedge-1],closepoints,Pxinterp,Pyinterp );
3166 xnew[Vids[g+1] ]= xcPhys[g*npedge +npedge-1];
3167 ylay[g*npedge +npedge-1] = ynew[Vids[g+1] ];
3168 xlay[g*npedge +npedge-1] = xnew[Vids[g+1] ];
3173 for(
int r=0; r< npedge-2; r++)
3181 ASSERTL0( index<= tmpy.num_elements()-1,
" index wrong");
3185 ylay[g*npedge +r+1]=
3187 xcPhys[g*npedge +r+1],closepoints,Pxinterp,Pyinterp );
3189 xlay[g*npedge +r+1]= xcPhys[g*npedge +r+1];
3207 Array<OneD, NekDouble> tmpx_lay, Array<OneD, NekDouble> tmpy_lay,
3208 Array<OneD, int> Vids,
3209 Array<OneD, NekDouble> &xlay, Array<OneD, NekDouble> &ylay,
3210 Array<OneD, NekDouble> &xnew, Array<OneD, NekDouble> &ynew)
3212 int np_lay = xcPhys.num_elements();
3213 int nedges = nvertl-1;
3215 Array<OneD, NekDouble>tmpx(np_lay-(nedges-1));
3216 Array<OneD, NekDouble>tmpy(np_lay-(nedges-1));
3221 int closepoints = 4;
3222 Array<OneD, NekDouble>Pxinterp(closepoints);
3223 Array<OneD, NekDouble>Pyinterp(closepoints);
3226 for(
int g=0; g< nedges; g++)
3230 ynew[Vids[g] ]= tmpy_lay[g*npedge+0];
3231 xnew[Vids[g] ]= tmpx_lay[g*npedge+0];
3234 ylay[g*npedge +0] = ynew[ Vids[g] ];
3235 xlay[g*npedge +0] = xnew[ Vids[g] ];
3238 ynew[Vids[g+1] ]= tmpy_lay[g*npedge+npedge-1];
3239 xnew[Vids[g+1] ]= tmpx_lay[g*npedge+npedge-1];
3240 ylay[g*npedge +npedge-1] = ynew[Vids[g+1] ];
3241 xlay[g*npedge +npedge-1] = xnew[Vids[g+1] ];
3246 for(
int r=0; r< npedge-2; r++)
3248 x0 = xlay[g*npedge +0];
3249 x1 = xlay[g*npedge +npedge-1];
3250 xtmp = x0 + r*(x1-x0)/(npedge-1);
3256 ASSERTL0( index<= tmpy.num_elements()-1,
" index wrong");
3260 ylay[g*npedge +r+1]=
3262 xtmp,closepoints,Pxinterp,Pyinterp );
3264 xlay[g*npedge +r+1]= xtmp;
3273 Array<OneD, NekDouble> xcold,Array<OneD, NekDouble> ycold,
3274 Array<OneD, NekDouble> xolddown,Array<OneD, NekDouble> yolddown,
3275 Array<OneD, NekDouble> xoldup,Array<OneD, NekDouble> yoldup,
3276 Array<OneD, NekDouble> ylaydown,Array<OneD, NekDouble> ylayup,
3277 Array<OneD, NekDouble>& xnew,Array<OneD, NekDouble>& ynew)
3280 int nvertl = ycold.num_elements();
3281 int nVertTot = mesh->GetNvertices();
3282 for(
int n=0; n<nVertTot; n++)
3287 vertex->GetCoords(x,y,z);
3292 for(
int k=0; k<nvertl; k++)
3294 if(abs(x-xcold[k]) < tmp)
3296 tmp = abs(x-xcold[k]);
3309 nplay_closer= (qp_closer-1)*npedge +npedge-1;
3313 if( y>yoldup[qp_closer] && y<1 )
3318 ratio = (1-ylayup[nplay_closer])/
3319 ( (1-yoldup[qp_closer]) );
3321 ynew[n] = ylayup[nplay_closer]
3322 + (y-yoldup[qp_closer])*ratio;
3326 else if( y< yolddown[qp_closer] && y>-1 )
3329 ratio = (1+ylaydown[nplay_closer])/
3330 ( (1+yolddown[qp_closer]) );
3332 ynew[n] = ylaydown[nplay_closer]
3333 + (y-yolddown[qp_closer])*ratio;
3341 Array<OneD, NekDouble> xcold,Array<OneD, NekDouble> ycold,
3342 Array<OneD, NekDouble> xolddown,Array<OneD, NekDouble> yolddown,
3343 Array<OneD, NekDouble> xoldup,Array<OneD, NekDouble> yoldup,
3344 Array<OneD, NekDouble> xlaydown,Array<OneD, NekDouble> ylaydown,
3345 Array<OneD, NekDouble> xlayup,Array<OneD, NekDouble> ylayup,
3346 Array<OneD, NekDouble> nxPhys,Array<OneD, NekDouble> nyPhys,
3347 Array<OneD, NekDouble>& xnew,Array<OneD, NekDouble>& ynew)
3364 int nvertl = xoldup.num_elements();
3365 int nedges = nvertl-1;
3366 Array<OneD, NekDouble> xnew_down(nvertl);
3367 Array<OneD, NekDouble> ynew_down(nvertl);
3368 Array<OneD, NekDouble> xnew_up(nvertl);
3369 Array<OneD, NekDouble> ynew_up(nvertl);
3370 Array<OneD, NekDouble> nxvert(nvertl);
3371 Array<OneD, NekDouble> nyvert(nvertl);
3372 Array<OneD, NekDouble> norm(nvertl);
3373 Array<OneD, NekDouble> tmp(nvertl);
3374 for(
int a=0; a< nedges;a++)
3379 xnew_down[a] = xlaydown[a*npedge+0];
3380 ynew_down[a] = ylaydown[a*npedge+0];
3381 xnew_up[a] = xlayup[a*npedge+0];
3382 ynew_up[a] = ylayup[a*npedge+0];
3383 nxvert[a] = nxPhys[a*npedge+0];
3384 nyvert[a] = nyPhys[a*npedge+0];
3386 xnew_down[a+1] = xlaydown[a*npedge+npedge-1];
3387 ynew_down[a+1] = ylaydown[a*npedge+npedge-1];
3388 xnew_up[a+1] = xlayup[a*npedge+npedge-1];
3389 ynew_up[a+1] = ylayup[a*npedge+npedge-1];
3390 nxvert[a+1] = nxPhys[a*npedge+npedge-1];
3391 nyvert[a+1] = nyPhys[a*npedge+npedge-1];
3396 xnew_down[a+1] = xlaydown[a*npedge+npedge-1];
3397 ynew_down[a+1] = ylaydown[a*npedge+npedge-1];
3398 xnew_up[a+1] = xlayup[a*npedge+npedge-1];
3399 ynew_up[a+1] = ylayup[a*npedge+npedge-1];
3400 nxvert[a+1] = nxPhys[a*npedge+npedge-1];
3401 nyvert[a+1] = nyPhys[a*npedge+npedge-1];
3413 int nVertTot = mesh->GetNvertices();
3414 for(
int n=0; n<nVertTot; n++)
3419 vertex->GetCoords(x,y,z);
3420 int qp_closeroldup, qp_closerolddown;
3429 for(
int k=0; k<nvertl; k++)
3431 if(abs(x-xolddown[k]) < diffdown)
3433 diffdown = abs(x-xolddown[k]);
3436 if(abs(x-xoldup[k]) < diffup)
3438 diffup = abs(x-xoldup[k]);
3448 int qp_closerup, qp_closerdown;
3450 for(
int f=0; f< nvertl; f++)
3452 if(abs(x-xnew_down[f]) < diffdown)
3454 diffdown = abs(x-xnew_down[f]);
3457 if(abs(x-xnew_up[f]) < diffup)
3459 diffup = abs(x-xnew_up[f]);
3486 int qp_closernormup;
3497 int qp_closernormdown;
3508 if( y>yoldup[qp_closeroldup] && y<1 )
3513 ratio = (1-ynew_up[qp_closerup])/
3514 ( (1-yoldup[qp_closeroldup]) );
3519 ynew[n] = ynew_up[qp_closerup]
3520 + (y-yoldup[qp_closeroldup])*ratio;
3526 if(x> (xmax-xmin)/2. && x< xmax)
3528 ratiox = (xmax-xnew_up[qp_closernormup])/
3529 (xmax-xoldup[qp_closernormup]) ;
3530 if( (xmax-xoldup[qp_closernormup])==0)
3537 xnew[n] = x + abs(nxvert[qp_closernormup])*(xnew_up[qp_closeroldup]-xoldup[qp_closeroldup])*ratiox;
3538 ASSERTL0(x>xmin,
" x value <xmin up second half");
3539 ASSERTL0(x<xmax," x value >xmax up second half
");
3541 else if( x> xmin && x<= (xmax-xmin)/2.)
3543 //cout<<"up close normold=
"<<qp_closernormoldup<<" closenorm=
"<<qp_closernormup<<endl;
3544 ratiox = (xnew_up[qp_closernormup]-xmin)/
3545 ( (xoldup[qp_closernormup]-xmin) );
3546 if( (xoldup[qp_closernormup]-xmin)==0)
3550 //xnew[n] = xnew_up[qp_closerup]
3551 // + (x-xoldup[qp_closeroldup])*ratiox;
3552 xnew[n] = x + abs(nxvert[qp_closernormup])*(xnew_up[qp_closeroldup]-xoldup[qp_closeroldup])*ratiox;
3553 //cout<<"up xold=
"<<x<<" xnew=
"<<xnew[n]<<endl;
3554 ASSERTL0(x>xmin," x value <xmin up first half
");
3555 ASSERTL0(x<xmax," x value >xmax up first half
");
3560 else if( y< yolddown[qp_closerolddown] && y>-1 )
3563 ratio = (1+ynew_down[qp_closerdown])/
3564 ( (1+yolddown[qp_closerolddown]) );
3566 // ratioy = (1-ynew_down[qp_closernormdown])/
3567 // ( (1-yolddown[qp_closernormolddown]) );
3569 //distance prop to layerlow
3570 ynew[n] = ynew_down[qp_closerdown]
3571 + (y-yolddown[qp_closerolddown])*ratio;
3572 //ynew[n] = y +abs(nyvert[qp_closernormdown])*
3573 // (ynew_down[qp_closerolddown]-yolddown[qp_closerolddown])*ratioy;
3574 //ynew[n] = y + 0.3*(ynew_down[qp_closerdown]-yolddown[qp_closerdown]);
3575 //xnew[n] = x + abs(nxvert[qp_closerolddown])*(xnew_down[qp_closerolddown]-xolddown[qp_closerolddown]);
3579 cout<<qp_closerolddown<<" nplaydown=
"<<qp_closerdown<<endl;
3580 cout<<"xolddown=
"<<xolddown[qp_closerolddown]<<" xnewdown=
"<<xnew_down[qp_closerdown]<<endl;
3581 cout<<"xold+
"<<x<<" xnew+
"<<xnew[n]<<endl;
3585 if(x> (xmax-xmin)/2. && x <xmax)
3587 ratiox = (xmax-xnew_down[qp_closernormdown])/
3588 ( (xmax-xolddown[qp_closernormdown]) );
3589 if( (xmax-xolddown[qp_closernormdown])==0)
3593 //xnew[n] = xnew_down[qp_closerdown]
3594 // + (x-xolddown[qp_closerolddown])*ratiox;
3596 abs(nxvert[qp_closernormdown])*(xnew_down[qp_closerolddown]-xolddown[qp_closerolddown])*ratiox;
3597 ASSERTL0(x>xmin," x value <xmin down second half
");
3598 ASSERTL0(x<xmax," x value >xmax down second half
");
3600 else if( x>xmin && x<= (xmax-xmin)/2.)
3602 ratiox = (xnew_down[qp_closernormdown]-xmin)/
3603 ( (xolddown[qp_closernormdown]-xmin) );
3604 if( (xolddown[qp_closernormdown]-xmin)==0)
3608 //xnew[n] = xnew_down[qp_closerdown]
3609 // + (x-xolddown[qp_closerolddown])*ratiox;
3611 abs(nxvert[qp_closernormdown])*(xnew_down[qp_closerolddown]-xolddown[qp_closerolddown])*ratiox;
3612 ASSERTL0(x>xmin," x value <xmin down first half
");
3613 ASSERTL0(x<xmax," x value >xmax down first half
");
3618 cout<<"xold
"<<x<<" xnew=
"<<xnew[n]<<endl;
3619 ASSERTL0(xnew[n] >= xmin, "newx < xmin
");
3620 ASSERTL0(xnew[n]<= xmax, "newx > xmax
");
3625 void CheckSingularQuads( MultiRegions::ExpListSharedPtr Exp,
3626 Array<OneD, int> V1, Array<OneD, int> V2,
3627 Array<OneD, NekDouble>& xnew,Array<OneD, NekDouble>& ynew)
3629 const boost::shared_ptr<LocalRegions::ExpansionVector> exp2D = Exp->GetExp();
3630 int nel = exp2D->size();
3631 LocalRegions::QuadExpSharedPtr locQuadExp;
3632 LocalRegions::TriExpSharedPtr locTriExp;
3633 SpatialDomains::Geometry1DSharedPtr SegGeom;
3635 NekDouble xV1, yV1, xV2,yV2;
3636 NekDouble slopebef,slopenext,slopenew;
3637 Array<OneD, int> locEids(4);
3638 for(int i=0; i<nel; i++)
3640 if((locQuadExp = (*exp2D)[i]->as<LocalRegions::QuadExp>()))
3642 SegGeom = (locQuadExp->GetGeom2D())->GetEdge(0);
3643 idbef = SegGeom->GetEid();
3644 if(xnew[ V1[idbef] ]<= xnew[ V2[idbef] ])
3646 xV1 = xnew[ V1[idbef] ];
3647 yV1 = ynew[ V1[idbef] ];
3648 xV2 = xnew[ V2[idbef] ];
3649 yV2 = ynew[ V2[idbef] ];
3650 slopebef = (yV2 -yV1)/(xV2 -xV1);
3654 xV1 = xnew[ V2[idbef] ];
3655 yV1 = ynew[ V2[idbef] ];
3656 xV2 = xnew[ V1[idbef] ];
3657 yV2 = ynew[ V1[idbef] ];
3658 slopebef = (yV2 -yV1)/(xV2 -xV1);
3660 //cout<<"00 V1 x=
"<<xnew[ V1[idbef] ]<<" y=
"<<ynew[ V1[idbef] ]<<endl;
3661 //cout<<"00 V2 x=
"<<xnew[ V2[idbef] ]<<" y=
"<<ynew[ V2[idbef] ]<<endl;
3662 for(int j = 1; j < locQuadExp->GetNedges(); ++j)
3664 SegGeom = (locQuadExp->GetGeom2D())->GetEdge(j);
3665 idnext = SegGeom->GetEid();
3666 //cout<<"id=
"<<idnext<<" locid=
"<<j<<endl;
3667 //cout<<" V1 x=
"<<xnew[ V1[idnext] ]<<" y=
"<<ynew[ V1[idnext] ]<<endl;
3668 //cout<<" V2 x=
"<<xnew[ V2[idnext] ]<<" y=
"<<ynew[ V2[idnext] ]<<endl;
3669 if(xV1 == xnew[ V1[idnext] ] && yV1 == ynew[ V1[idnext] ] )
3671 xV1 = xnew[ V1[idnext] ];
3672 yV1 = ynew[ V1[idnext] ];
3673 xV2 = xnew[ V2[idnext] ];
3674 yV2 = ynew[ V2[idnext] ];
3675 slopenext = (yV2 -yV1)/(xV2 -xV1);
3678 cout<<"case1 x0=
"<<xV1<<" x1=
"<<xV2<<endl;
3679 cout<<idnext<<" 11slope bef =
"<<slopebef<<" slopenext=
"<<slopenext<<endl;
3681 //compare with slope before
3682 if( slopebef/slopenext>0.84 && slopebef/slopenext <1.18)
3684 xnew[ V1[idnext] ] = xnew[ V1[idnext] ] -0.01;
3685 slopenew = (yV2-yV1)/(xV2- xnew[ V1[idnext] ]);
3687 if( abs(slopebef-slopenew) < abs(slopebef-slopenext) )
3689 xnew[ V1[idnext] ] = xnew[ V1[idnext] ] +0.02;
3690 slopenew = (yV2-yV1)/(xV2- xnew[ V1[idnext] ]);
3692 slopenext = slopenew;
3693 cout<<"slopenew=
"<<slopenew<<endl;
3694 cout<<"moved x=
"<<xnew[ V1[idnext] ]<<endl;
3697 else if(xV2 == xnew[ V2[idnext] ] && yV2 == ynew[ V2[idnext] ] )
3699 xV1 = xnew[ V2[idnext] ];
3700 yV1 = ynew[ V2[idnext] ];
3701 xV2 = xnew[ V1[idnext] ];
3702 yV2 = ynew[ V1[idnext] ];
3703 slopenext = (yV2 -yV1)/(xV2 -xV1);
3706 cout<<"case2 x0=
"<<xV1<<" x1=
"<<xV2<<endl;
3707 cout<<idnext<<" 22slope bef =
"<<slopebef<<" slopenext=
"<<slopenext<<endl;
3709 //compare with slope before
3710 if( slopebef/slopenext>0.84 && slopebef/slopenext <1.18)
3712 xnew[ V2[idnext] ] = xnew[ V2[idnext] ] -0.01;
3713 slopenew = (yV2-yV1)/(xV2- xnew[ V2[idnext] ]);
3715 if( abs(slopebef-slopenew) < abs(slopebef-slopenext) )
3717 xnew[ V2[idnext] ] = xnew[ V2[idnext] ] +0.02;
3718 slopenew = (yV2-yV1)/(xV2- xnew[ V2[idnext] ]);
3721 slopenext = slopenew;
3722 cout<<"slopenew=
"<<slopenew<<endl;
3723 cout<<"moved x=
"<<xnew[ V2[idnext] ]<<endl;
3726 else if(xV1 == xnew[ V2[idnext] ] && yV1 == ynew[ V2[idnext] ] )
3728 xV1 = xnew[ V2[idnext] ];
3729 yV1 = ynew[ V2[idnext] ];
3730 xV2 = xnew[ V1[idnext] ];
3731 yV2 = ynew[ V1[idnext] ];
3732 slopenext = (yV2 -yV1)/(xV2 -xV1);
3735 cout<<"case3 x0=
"<<xV1<<" x1=
"<<xV2<<endl;
3736 cout<<idnext<<" 22slope bef =
"<<slopebef<<" slopenext=
"<<slopenext<<endl;
3738 //compare with slope before
3739 if( slopebef/slopenext>0.84 && slopebef/slopenext <1.18)
3741 xnew[ V2[idnext] ] = xnew[ V2[idnext] ] -0.01;
3742 slopenew = (yV2-yV1)/(xV2- xnew[ V2[idnext] ]);
3744 if( abs(slopebef-slopenew) < abs(slopebef-slopenext) )
3746 xnew[ V2[idnext] ] = xnew[ V2[idnext] ] +0.02;
3747 slopenew = (yV2-yV1)/(xV2- xnew[ V2[idnext] ]);
3749 slopenext = slopenew;
3750 cout<<"slopenew=
"<<slopenew<<endl;
3751 cout<<"moved x=
"<<xnew[ V2[idnext] ]<<endl;
3755 else if(xV2 == xnew[ V1[idnext] ] && yV2 == ynew[ V1[idnext] ] )
3757 xV1 = xnew[ V1[idnext] ];
3758 yV1 = ynew[ V1[idnext] ];
3759 xV2 = xnew[ V2[idnext] ];
3760 yV2 = ynew[ V2[idnext] ];
3761 slopenext = (yV2 -yV1)/(xV2 -xV1);
3764 cout<<"case4 x0=
"<<xV1<<" x1=
"<<xV2<<endl;
3765 cout<<idnext<<" 22slope bef =
"<<slopebef<<" slopenext=
"<<slopenext<<endl;
3767 //compare with slope before
3768 if( slopebef/slopenext>0.84 && slopebef/slopenext <1.18)
3770 xnew[ V1[idnext] ] = xnew[ V1[idnext] ] -0.01;
3771 slopenew = (yV2-yV1)/(xV2- xnew[ V1[idnext] ]);
3773 if( abs(slopebef-slopenew) < abs(slopebef-slopenext) )
3775 xnew[ V1[idnext] ] = xnew[ V1[idnext] ] +0.02;
3776 slopenew = (yV2-yV1)/(xV2- xnew[ V1[idnext] ]);
3778 slopenext = slopenew;
3779 cout<<"slopenew=
"<<slopenew<<endl;
3780 cout<<"moved x=
"<<xnew[ V1[idnext] ]<<endl;
3786 ASSERTL0(false, "edge not connected
");
3788 slopebef = slopenext;
3797 void Replacevertices(string filename, Array<OneD, NekDouble> newx,
3798 Array<OneD, NekDouble> newy,
3799 Array<OneD, NekDouble> xcPhys, Array<OneD, NekDouble> ycPhys,
3800 Array<OneD, int>Eids, int Npoints, string s_alp,
3801 Array<OneD, Array<OneD, NekDouble> > x_lay,
3802 Array<OneD, Array<OneD, NekDouble> > y_lay,
3803 Array<OneD, Array<OneD, int > >lay_eids, bool curv_lay)
3805 //load existing file
3807 TiXmlDocument doc(filename);
3808 //load xscale parameter (if exists)
3809 TiXmlElement* master = doc.FirstChildElement("NEKTAR
");
3810 TiXmlElement* mesh = master->FirstChildElement("GEOMETRY
");
3811 TiXmlElement* element = mesh->FirstChildElement("VERTEX
");
3812 NekDouble xscale = 1.0;
3813 LibUtilities::AnalyticExpressionEvaluator expEvaluator;
3814 const char *xscal = element->Attribute("XSCALE
");
3817 std::string xscalstr = xscal;
3818 int expr_id = expEvaluator.DefineFunction("",xscalstr);
3819 xscale = expEvaluator.Evaluate(expr_id);
3823 // Save a new XML file.
3824 newfile = filename.substr(0, filename.find_last_of(".
"))+"_moved.xml
";
3825 doc.SaveFile( newfile );
3827 //write the new vertices
3828 TiXmlDocument docnew(newfile);
3829 bool loadOkaynew = docnew.LoadFile();
3831 std::string errstr = "Unable to load file:
";
3833 ASSERTL0(loadOkaynew, errstr.c_str());
3835 TiXmlHandle docHandlenew(&docnew);
3836 TiXmlElement* meshnew = NULL;
3837 TiXmlElement* masternew = NULL;
3838 TiXmlElement* condnew = NULL;
3839 TiXmlElement* Parsnew = NULL;
3840 TiXmlElement* parnew = NULL;
3842 // Master tag within which all data is contained.
3845 masternew = docnew.FirstChildElement("NEKTAR
");
3846 ASSERTL0(masternew, "Unable to
find NEKTAR tag in file.
");
3848 //set the alpha value
3850 condnew = masternew->FirstChildElement("CONDITIONS
");
3851 Parsnew = condnew->FirstChildElement("PARAMETERS
");
3852 cout<<"alpha=
"<<s_alp<<endl;
3853 parnew = Parsnew->FirstChildElement("P
");
3856 TiXmlNode *node = parnew->FirstChild();
3859 // Format is "paramName = value
"
3860 std::string line = node->ToText()->Value();
3864 int beg = line.find_first_not_of("
");
3865 int end = line.find_first_of("=
");
3866 // Check for no parameter name
3867 if (beg == end) throw 1;
3868 // Check for no parameter value
3869 if (end != line.find_last_of("=
")) throw 1;
3870 // Check for no equals sign
3871 if (end == std::string::npos) throw 1;
3872 lhs = line.substr(line.find_first_not_of(" "), end-beg);
3873 lhs = lhs.substr(0, lhs.find_last_not_of(" ")+1);
3875 //rhs = line.substr(line.find_last_of("=
")+1);
3876 //rhs = rhs.substr(rhs.find_first_not_of(" "));
3877 //rhs = rhs.substr(0, rhs.find_last_not_of(" ")+1);
3879 boost::to_upper(lhs);
3882 alphastring = "Alpha =
"+ s_alp;
3883 parnew->RemoveChild(node);
3884 parnew->LinkEndChild(new TiXmlText(alphastring) );
3888 parnew = parnew->NextSiblingElement("P
");
3892 // Find the Mesh tag and same the dim and space attributes
3893 meshnew = masternew->FirstChildElement("GEOMETRY
");
3895 ASSERTL0(meshnew, "Unable to
find GEOMETRY tag in file.
");
3896 // Now read the vertices
3897 TiXmlElement* elementnew = meshnew->FirstChildElement("VERTEX
");
3898 ASSERTL0(elementnew, "Unable to
find mesh VERTEX tag in file.
");
3902 elementnew->SetAttribute("XSCALE
",1.0);
3904 TiXmlElement *vertexnew = elementnew->FirstChildElement("V
");
3910 int nextVertexNumber = -1;
3915 //delete the old one
3916 TiXmlAttribute *vertexAttr = vertexnew->FirstAttribute();
3917 std::string attrName(vertexAttr->Name());
3918 ASSERTL0(attrName == "ID
", (std::string("Unknown attribute name:
") + attrName).c_str());
3920 err = vertexAttr->QueryIntValue(&indx);
3921 ASSERTL0(err == TIXML_SUCCESS, "Unable to read attribute ID.
");
3922 ASSERTL0(indx == nextVertexNumber, "Vertex IDs must begin with zero and be sequential.
");
3924 std::string vertexBodyStr;
3925 // Now read body of vertex
3926 TiXmlNode *vertexBody = vertexnew->FirstChild();
3927 // Accumulate all non-comment body data.
3928 if (vertexBody->Type() == TiXmlNode::TEXT)
3930 vertexBodyStr += vertexBody->ToText()->Value();
3931 vertexBodyStr += " ";
3933 ASSERTL0(!vertexBodyStr.empty(), "Vertex definitions must contain vertex data.
");
3934 //remove the old coordinates
3935 vertexnew->RemoveChild(vertexBody);
3937 //cout<<"writing.. v:
"<<nextVertexNumber<<endl;
3939 //we need at least 5 digits (setprecision 5) to get the streak position with
3941 s << std::scientific << std::setprecision(8) << newx[nextVertexNumber] << " "
3942 << newy[nextVertexNumber] << " " << 0.0;
3943 vertexnew->LinkEndChild(new TiXmlText(s.str()));
3944 //TiXmlNode *newvertexBody = vertexnew->FirstChild();
3945 //string newvertexbodystr= newvertexBody->SetValue(s.str());
3946 //vertexnew->ReplaceChild(vertexBody,new TiXmlText(newvertexbodystr));
3948 vertexnew = vertexnew->NextSiblingElement("V
");
3953 //read the curved tag
3954 TiXmlElement* curvednew = meshnew->FirstChildElement("CURVED
");
3955 ASSERTL0(curvednew, "Unable to
find mesh CURVED tag in file.
");
3956 TiXmlElement *edgenew = curvednew->FirstChildElement("E
");
3958 //ID is different from index...
3959 std::string charindex;
3963 int neids_lay = lay_eids[0].num_elements();
3964 //if edgenew belongs to the crit lay replace it, else delete it.
3970 TiXmlAttribute *edgeAttr = edgenew->FirstAttribute();
3971 std::string attrName(edgeAttr->Name());
3972 charindex = edgeAttr->Value();
3973 std::istringstream iss(charindex);
3974 iss >> std::dec >> index;
3976 edgenew->QueryIntAttribute("EDGEID
", &eid);
3977 //cout<<"eid=
"<<eid<<" neid=
"<<Eids.num_elements()<<endl;
3978 //find the corresponding index curve point
3979 for(int u=0; u<Eids.num_elements(); u++)
3981 //cout<<"Eids=
"<<Eids[u]<<" eid=
"<<eid<<endl;
3989 curvednew->RemoveChild(edgenew);
3990 //ASSERTL0(false, "edge to update not found
");
3995 std::string edgeBodyStr;
3996 //read the body of the edge
3997 TiXmlNode *edgeBody = edgenew->FirstChild();
3998 if(edgeBody->Type() == TiXmlNode::TEXT)
4000 edgeBodyStr += edgeBody->ToText()->Value();
4003 ASSERTL0(!edgeBodyStr.empty(), "Edge definitions must contain edge data
");
4004 //remove the old coordinates
4005 edgenew->RemoveChild(edgeBody);
4006 //write the new points coordinates
4007 //we need at least 5 digits (setprecision 5) to get the streak position with
4010 //Determine the number of points
4011 err = edgenew->QueryIntAttribute("NUMPOINTS
", &numPts);
4012 ASSERTL0(err == TIXML_SUCCESS, "Unable to read curve attribute NUMPOINTS.
");
4015 edgenew->SetAttribute("NUMPOINTS
", Npoints);
4016 for(int u=0; u< Npoints; u++)
4018 st << std::scientific <<
4019 std::setprecision(8) <<xcPhys[cnt*Npoints+u]
4020 << " " << ycPhys[cnt*Npoints+u] << " " << 0.000<<" ";
4023 edgenew->LinkEndChild(new TiXmlText(st.str()));
4027 st << std::scientific << std::setprecision(8) << x_crit[v1] << " "
4028 << y_crit[v1] << " " << 0.000<<" ";
4029 for(int a=0; a< Npoints-2; a++)
4031 st << std::scientific << std::setprecision(8) <<
4032 " "<<Pcurvx[indexeid*(Npoints-2) +a]<<" "<<Pcurvy[indexeid*(Npoints-2) +a]
4036 st << std::scientific << std::setprecision(8) <<
4037 " "<<x_crit[v2]<<" "<< y_crit[v2] <<" "<< 0.000;
4038 edgenew->LinkEndChild(new TiXmlText(st.str()));
4045 edgenew = edgenew->NextSiblingElement("E
");
4049 //write also the others layers curve points
4050 if(curv_lay == true)
4052 cout<<"write other curved edges
"<<endl;
4053 TiXmlElement * curved = meshnew->FirstChildElement("CURVED
");
4055 int nlays = lay_eids.num_elements();
4057 //TiXmlComment * comment = new TiXmlComment();
4058 //comment->SetValue(" new edges
");
4059 //curved->LinkEndChild(comment);
4060 for (int g=0; g< nlays; ++g)
4062 for(int p=0; p< neids_lay; p++)
4065 TiXmlElement * e = new TiXmlElement( "E
" );
4066 e->SetAttribute("ID
", idcnt++);
4067 e->SetAttribute("EDGEID
", lay_eids[g][p]);
4068 e->SetAttribute("NUMPOINTS
", Npoints);
4069 e->SetAttribute("TYPE
", "PolyEvenlySpaced
");
4070 for(int c=0; c< Npoints; c++)
4072 st << std::scientific << std::setprecision(8) <<x_lay[g][p*Npoints +c]
4073 << " " << y_lay[g][p*Npoints +c] << " " << 0.000<<" ";
4077 TiXmlText * t0 = new TiXmlText(st.str());
4078 e->LinkEndChild(t0);
4079 curved->LinkEndChild(e);
4087 docnew.SaveFile( newfile );
4089 cout<<"new file:
"<<newfile<<endl;