Nektar++
Functions
ExtractCriticalLayerFunctions.cpp File Reference
#include <cstdio>
#include <MultiRegions/ExpList.h>

Go to the source code of this file.

Functions

void Computestreakpositions (MultiRegions::ExpListSharedPtr &streak, Array< OneD, NekDouble > &xc, Array< OneD, NekDouble > &yc, NekDouble cr, NekDouble trans)
 

Function Documentation

◆ Computestreakpositions()

void Computestreakpositions ( MultiRegions::ExpListSharedPtr streak,
Array< OneD, NekDouble > &  xc,
Array< OneD, NekDouble > &  yc,
NekDouble  cr,
NekDouble  trans 
)

Definition at line 42 of file ExtractCriticalLayerFunctions.cpp.

References ASSERTL0, Nektar::MultiRegions::eY, Nektar::NekConstants::kNekUnsetDouble, Vmath::Vmax(), and Vmath::Vmin().

47 {
48  int i;
49  int npts = xc.num_elements();
50 
51  int nq = streak->GetTotPoints();
52  Array<OneD, NekDouble> derstreak(nq);
55  streak->GetCoords(x,y);
56 
57  streak->BwdTrans(streak->GetCoeffs(),streak->UpdatePhys());
58  streak->PhysDeriv(MultiRegions::eY, streak->GetPhys(), derstreak);
59 
60  // set intiial xc to be equispaced over mesh and yc to be zero
61  NekDouble x_max = Vmath::Vmax(nq,x,1);
62  NekDouble x_min = Vmath::Vmin(nq,x,1);
63 
64  for(i = 0; i < npts; ++i)
65  {
66  xc[i] = x_min + (x_max - x_min)*i/((NekDouble)(npts-1));
67  yc[i] = 0.0;
68  }
69 
70 
71  int elmtid, offset,cnt;
72  NekDouble U,dU;
73  NekDouble F;
74  NekDouble ConvTol = 1e-9;
75  NekDouble CoordTol = 1e-5;
76  int maxiter = 100;
77  Array<OneD, NekDouble> coord(2);
78 
79  // Do Newton iteration on y direction
80  cerr << "[";
81  for(int e=0; e<npts; e++)
82  {
83  coord[0] = xc[e];
84  coord[1] = yc[e];
85 
86  if(!(e%10))
87  {
88  cerr << ".";
89  }
90 
91  F = 1000;
92  cnt = 0;
93  while((abs(F)> ConvTol)&&(cnt < maxiter))
94  {
95  elmtid = streak->GetExpIndex(coord,CoordTol);
96  offset = streak->GetPhys_Offset(elmtid);
97 
98  U = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() + offset);
99  dU = streak->GetExp(elmtid)->PhysEvaluate(coord, derstreak + offset);
100 
101  coord[1] = coord[1] - (U-cr)/dU;
102 
103  F = U-cr;
104  cnt++;
105  }
106  ASSERTL0(cnt < maxiter, "Failed to converge Newton iteration");
107 
108  yc[e] = coord[1];
109  }
110  cerr << "]" << endl;
111 
112  if(trans != NekConstants::kNekUnsetDouble)
113  {
114  // output to interface file
115  FILE *fp = fopen("interfacedat.geo","w");
116 
117  NekDouble y_max = Vmath::Vmax(nq,y,1);
118  NekDouble y_min = Vmath::Vmin(nq,y,1);
119 
120  cnt = 1;
121  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",
122  cnt++,x_min,y_min);
123  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",
124  cnt++,x_max,y_min);
125  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",
126  cnt++,x_max,y_max);
127  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",
128  cnt++,x_min,y_max);
129 
130  for(i = 0; i < npts; ++i)
131  {
132  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",
133  cnt++,xc[i],yc[i]);
134  }
135 
136  fclose(fp);
137 
138 
139  // output to interface_up file as bend of vertical shift and 45 degrees shift
140  fp = fopen("interfacedat_up.geo","w");
141 
142 
143  NekDouble nx,ny,norm;
144 
145  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",cnt++,xc[0],yc[0]+trans);
146 
147  for(i = 1; i < npts-1; ++i)
148  {
149  norm = sqrt((xc[i+1]-xc[i-1])*(xc[i+1]-xc[i-1])+(yc[i+1]-yc[i-1])*(yc[i+1]-yc[i-1]));
150  nx = (yc[i-1]-yc[i+1])/norm;
151  ny = (xc[i+1]-xc[i-1])/norm;
152 
153  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",
154  cnt++,xc[i]+nx*trans,yc[i]+ny*trans);
155  }
156 
157  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",cnt++,xc[npts-1],yc[npts-1]+trans);
158 
159 
160  // output to interface_up file as bend of vertical shift and 45 degrees shift
161  fp = fopen("interfacedat_dn.geo","w");
162 
163  trans = -trans;
164 
165  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",cnt++,xc[0],yc[0]+trans);
166 
167  for(i = 1; i < npts-1; ++i)
168  {
169  norm = sqrt((xc[i+1]-xc[i-1])*(xc[i+1]-xc[i-1])+(yc[i+1]-yc[i-1])*(yc[i+1]-yc[i-1]));
170  nx = (yc[i-1]-yc[i+1])/norm;
171  ny = (xc[i+1]-xc[i-1])/norm;
172 
173  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",
174  cnt++,xc[i]+nx*trans,yc[i]+ny*trans);
175  }
176 
177  fprintf(fp,"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n",cnt++,xc[npts-1],yc[npts-1]+trans);
178  }
179 
180 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
Definition: Vmath.cpp:782
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
Definition: Vmath.cpp:874
double NekDouble
static const NekDouble kNekUnsetDouble