39#include <MultiRegions/ExpList2D.h>
42 Array<OneD, NekDouble> &xc,
46int main(
int argc,
char *argv[])
54 "Usage: ./ExtractCriticalLayer meshfile fieldfile \n");
61 LibUtilities::SessionReader::CreateInstance(argc, argv);
67 SpatialDomains::MeshGraph::Read(vSession);
74 streak = MemoryManager<MultiRegions::ExpList2D>::AllocateSharedPtr(
81 string fieldfile(argv[argc - 1]);
82 vector<SpatialDomains::FieldDefinitionsSharedPtr> fielddef;
83 vector<vector<NekDouble>> fielddata;
84 graphShPt->Import(fieldfile, fielddef, fielddata);
89 string streak_field(
"w");
90 for (
unsigned int i = 0; i < fielddata.size(); ++i)
92 streak->ExtractDataToCoeffs(fielddef[i], fielddata[i], streak_field);
97 vSession->LoadParameter(
"NumCriticalLayerPts", npts, 30);
98 Array<OneD, NekDouble> x_c(npts);
99 Array<OneD, NekDouble> y_c(npts);
103 vSession->LoadParameter(
"WidthOfLayers", trans, 0.1);
107 cout <<
"# x_c y_c" << endl;
108 for (i = 0; i < npts; ++i)
110 fprintf(stdout,
"%12.10lf %12.10lf \n", x_c[i], y_c[i]);
116 Array<OneD, NekDouble> &xc,
117 Array<OneD, NekDouble> &yc,
NekDouble cr,
121 int npts = xc.size();
123 int nq = streak->GetTotPoints();
124 Array<OneD, NekDouble> derstreak(nq);
125 Array<OneD, NekDouble> x(nq);
126 Array<OneD, NekDouble> y(nq);
127 streak->GetCoords(x, y);
129 streak->BwdTrans(streak->GetCoeffs(), streak->UpdatePhys());
136 for (i = 0; i < npts; ++i)
138 xc[i] = x_min + (x_max - x_min) * i / ((
NekDouble)(npts - 1));
142 int elmtid, offset, cnt;
148 Array<OneD, NekDouble> coord(2);
152 for (
int e = 0; e < npts; e++)
167 while (
abs(F) > 0.000000001)
170 elmtid = streak->GetExpIndex(coord, 0.00001);
171 offset = streak->GetPhys_Offset(elmtid);
172 U = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() +
175 streak->GetExp(elmtid)->PhysEvaluate(coord, derstreak + offset);
176 coord[1] = coord[1] - (U - cr) / dU;
178 ASSERTL0(coord[0] == xc[e],
" x coordinate must remain the same");
183 if (
abs(coord[1]) > 1)
185 coord[1] = ytmp + 0.01;
186 elmtid = streak->GetExpIndex(coord, 0.00001);
187 offset = streak->GetPhys_Offset(elmtid);
188 NekDouble Utmp = streak->GetExp(elmtid)->PhysEvaluate(
189 coord, streak->GetPhys() + offset);
190 NekDouble dUtmp = streak->GetExp(elmtid)->PhysEvaluate(
191 coord, derstreak + offset);
192 coord[1] = coord[1] - (Utmp - cr) / dUtmp;
194 if ((
abs(Utmp - cr) >
abs(F)) || (
abs(coord[1]) > 1))
196 coord[1] = ytmp - 0.01;
203 ASSERTL0(
abs(coord[1]) <= 1,
" y value out of bound +/-1");
207 if (its > 1000 &&
abs(F) < 0.0001)
209 cout <<
"warning streak position obtained with precision:" << F
215 ASSERTL0(
false,
"no convergence after 1000 iterations");
224 FILE *fp = fopen(
"interfacedat.geo",
"w");
230 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, x_min, y_min);
231 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, x_max, y_min);
232 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, x_max, y_max);
233 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, x_min, y_max);
235 for (i = 0; i < npts; ++i)
237 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, xc[i],
245 fp = fopen(
"interfacedat_up.geo",
"w");
249 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, xc[0],
252 for (i = 1; i < npts - 1; ++i)
254 norm =
sqrt((xc[i + 1] - xc[i - 1]) * (xc[i + 1] - xc[i - 1]) +
255 (yc[i + 1] - yc[i - 1]) * (yc[i + 1] - yc[i - 1]));
256 nx = (yc[i - 1] - yc[i + 1]) / norm;
257 ny = (xc[i + 1] - xc[i - 1]) / norm;
259 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++,
260 xc[i] + nx * trans, yc[i] + ny * trans);
263 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, xc[npts - 1],
264 yc[npts - 1] + trans);
268 fp = fopen(
"interfacedat_dn.geo",
"w");
272 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, xc[0],
275 for (i = 1; i < npts - 1; ++i)
277 norm =
sqrt((xc[i + 1] - xc[i - 1]) * (xc[i + 1] - xc[i - 1]) +
278 (yc[i + 1] - yc[i - 1]) * (yc[i + 1] - yc[i - 1]));
279 nx = (yc[i - 1] - yc[i + 1]) / norm;
280 ny = (xc[i + 1] - xc[i - 1]) / norm;
282 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++,
283 xc[i] + nx * trans, yc[i] + ny * trans);
286 fprintf(fp,
"Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, xc[npts - 1],
287 yc[npts - 1] + trans);
#define ASSERTL0(condition, msg)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
scalarT< T > abs(scalarT< T > in)
scalarT< T > sqrt(scalarT< T > in)