Nektar++
ExtractCriticalLayerFunctions.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: ExtractCriticalLayerFunctions.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <cstdio>
36
38
39using namespace std;
40using namespace Nektar;
41
45 NekDouble trans)
46{
47 int i;
48 int npts = xc.size();
49
50 int nq = streak->GetTotPoints();
51 Array<OneD, NekDouble> derstreak(nq);
54 streak->GetCoords(x, y);
55
56 streak->BwdTrans(streak->GetCoeffs(), streak->UpdatePhys());
57 streak->PhysDeriv(MultiRegions::eY, streak->GetPhys(), derstreak);
58
59 // set intiial xc to be equispaced over mesh and yc to be zero
60 NekDouble x_max = Vmath::Vmax(nq, x, 1);
61 NekDouble x_min = Vmath::Vmin(nq, x, 1);
62
63 for (i = 0; i < npts; ++i)
64 {
65 xc[i] = x_min + (x_max - x_min) * i / ((NekDouble)(npts - 1));
66 yc[i] = 0.0;
67 }
68
69 int elmtid, offset, cnt;
70 NekDouble U, dU;
71 NekDouble F;
72 NekDouble ConvTol = 1e-9;
73 NekDouble CoordTol = 1e-5;
74 int maxiter = 100;
76
77 // Do Newton iteration on y direction
78 cerr << "[";
79 for (int e = 0; e < npts; e++)
80 {
81 coord[0] = xc[e];
82 coord[1] = yc[e];
83
84 if (!(e % 10))
85 {
86 cerr << ".";
87 }
88
89 F = 1000;
90 cnt = 0;
91 while ((abs(F) > ConvTol) && (cnt < maxiter))
92 {
93 elmtid = streak->GetExpIndex(coord, CoordTol);
94 offset = streak->GetPhys_Offset(elmtid);
95
96 U = streak->GetExp(elmtid)->PhysEvaluate(coord, streak->GetPhys() +
97 offset);
98 dU =
99 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
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", cnt++, x_min,
122 y_min);
123 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, x_max,
124 y_min);
125 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, x_max,
126 y_max);
127 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, x_min,
128 y_max);
129
130 for (i = 0; i < npts; ++i)
131 {
132 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++,
133 xc[i], yc[i]);
134 }
135
136 fclose(fp);
137
138 // output to interface_up file as bend of vertical shift and 45 degrees
139 // shift
140 fp = fopen("interfacedat_up.geo", "w");
141
142 NekDouble nx, ny, norm;
143
144 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, xc[0],
145 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]) +
150 (yc[i + 1] - yc[i - 1]) * (yc[i + 1] - yc[i - 1]));
151 nx = (yc[i - 1] - yc[i + 1]) / norm;
152 ny = (xc[i + 1] - xc[i - 1]) / norm;
153
154 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++,
155 xc[i] + nx * trans, yc[i] + ny * trans);
156 }
157
158 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++,
159 xc[npts - 1], yc[npts - 1] + trans);
160
161 // output to interface_up file as bend of vertical shift and 45 degrees
162 // shift
163 fp = fopen("interfacedat_dn.geo", "w");
164
165 trans = -trans;
166
167 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++, xc[0],
168 yc[0] + trans);
169
170 for (i = 1; i < npts - 1; ++i)
171 {
172 norm = sqrt((xc[i + 1] - xc[i - 1]) * (xc[i + 1] - xc[i - 1]) +
173 (yc[i + 1] - yc[i - 1]) * (yc[i + 1] - yc[i - 1]));
174 nx = (yc[i - 1] - yc[i + 1]) / norm;
175 ny = (xc[i + 1] - xc[i - 1]) / norm;
176
177 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++,
178 xc[i] + nx * trans, yc[i] + ny * trans);
179 }
180
181 fprintf(fp, "Point(%d)={%12.10lf,%12.10lf,0,1.0}; \n", cnt++,
182 xc[npts - 1], yc[npts - 1] + trans);
183 }
184}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
void Computestreakpositions(MultiRegions::ExpListSharedPtr &streak, Array< OneD, NekDouble > &xc, Array< OneD, NekDouble > &yc, NekDouble cr, NekDouble trans)
std::shared_ptr< ExpList > ExpListSharedPtr
Shared pointer to an ExpList object.
static const NekDouble kNekUnsetDouble
double NekDouble
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.hpp:725
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.hpp:644
scalarT< T > abs(scalarT< T > in)
Definition: scalar.hpp:298
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294