Nektar++
ExtractCriticalLayerFunctions.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File ComputeCriticalLayer.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: Compute location of critical layer from streak file
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include <cstdio>
36 
37 #include <MultiRegions/ExpList.h>
38 
39 using namespace std;
40 using namespace Nektar;
41 
45  NekDouble cr,
46  NekDouble trans)
47 {
48  int i;
49  int npts = xc.size();
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
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
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
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.cpp:992
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:892
scalarT< T > abs(scalarT< T > in)
Definition: scalar.hpp:272
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:267