Nektar++
RinglebFlowBC.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: RinglebFlowBC.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: Ringleb flow boundary condition
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #include "RinglebFlowBC.h"
37 
38 using namespace std;
39 
40 namespace Nektar
41 {
42 
43 std::string RinglebFlowBC::className = GetCFSBndCondFactory().
44  RegisterCreatorFunction("RinglebFlow",
45  RinglebFlowBC::create,
46  "Ringleb flow boundary condition.");
47 
48 RinglebFlowBC::RinglebFlowBC(const LibUtilities::SessionReaderSharedPtr& pSession,
50  const Array<OneD, Array<OneD, NekDouble> >& pTraceNormals,
51  const int pSpaceDim,
52  const int bcRegion,
53  const int cnt)
54  : CFSBndCond(pSession, pFields, pTraceNormals, pSpaceDim, bcRegion, cnt)
55 {
56  m_expdim = pFields[0]->GetGraph()->GetMeshDimension();
57 
58  m_homo1D = false;
59  if (m_session->DefinesSolverInfo("HOMOGENEOUS"))
60  {
61  std::string HomoStr = m_session->GetSolverInfo("HOMOGENEOUS");
62  if ((HomoStr == "HOMOGENEOUS1D") || (HomoStr == "Homogeneous1D")
63  || (HomoStr == "1D") || (HomoStr == "Homo1D"))
64  {
65  m_homo1D = true;
66  }
67  }
68 }
69 
72  Array<OneD, Array<OneD, NekDouble> > &physarray,
73  const NekDouble &time)
74 {
75  int nvariables = physarray.size();
76 
77  // For 3DHomogenoeus1D
78  int n_planes = 1;
79  if (m_expdim == 2 && m_homo1D)
80  {
81  int nPointsTot = m_fields[0]->GetTotPoints();
82  int nPointsTot_plane = m_fields[0]->GetPlane(0)->GetTotPoints();
83  n_planes = nPointsTot/nPointsTot_plane;
84  }
85 
86  int id2, id2_plane, e_max;
87 
88  e_max = m_fields[0]->GetBndCondExpansions()[m_bcRegion]->GetExpSize();
89 
90  for(int e = 0; e < e_max; ++e)
91  {
92  int npoints = m_fields[0]->
93  GetBndCondExpansions()[m_bcRegion]->GetExp(e)->GetTotPoints();
94  int id1 = m_fields[0]->
95  GetBndCondExpansions()[m_bcRegion]->GetPhys_Offset(e);
96 
97  // For 3DHomogenoeus1D
98  if (m_expdim == 2 && m_homo1D)
99  {
100  int m_offset_plane = m_offset/n_planes;
101  int e_plane;
102  int e_max_plane = e_max/n_planes;
103  int nTracePts_plane = m_fields[0]->GetTrace()->GetNpoints();
104 
105  int planeID = floor((e + 0.5 )/ e_max_plane );
106  e_plane = e - e_max_plane*planeID;
107 
108  id2_plane = m_fields[0]->GetTrace()->GetPhys_Offset(
109  m_fields[0]->GetTraceMap()->
110  GetBndCondIDToGlobalTraceID(m_offset_plane + e_plane));
111  id2 = id2_plane + planeID*nTracePts_plane;
112  }
113  else // For general case
114  {
115  id2 = m_fields[0]->
116  GetTrace()->GetPhys_Offset(m_fields[0]->GetTraceMap()->
117  GetBndCondIDToGlobalTraceID(m_offset+e));
118  }
119 
120  Array<OneD,NekDouble> x0(npoints, 0.0);
121  Array<OneD,NekDouble> x1(npoints, 0.0);
122  Array<OneD,NekDouble> x2(npoints, 0.0);
123 
124  m_fields[0]->GetBndCondExpansions()[m_bcRegion]->
125  GetExp(e)->GetCoords(x0, x1, x2);
126 
127  // Flow parameters
128  NekDouble c, k, phi, r, J, VV, pp, sint, P, ss;
129  NekDouble J11, J12, J21, J22, det;
130  NekDouble Fx, Fy;
131  NekDouble xi, yi;
132  NekDouble dV;
133  NekDouble dtheta;
134  NekDouble par1;
135  NekDouble theta = M_PI / 4.0;
136  NekDouble kExt = 0.7;
137  NekDouble V = kExt * sin(theta);
138  NekDouble toll = 1.0e-8;
139  NekDouble errV = 1.0;
140  NekDouble errTheta = 1.0;
141  NekDouble gamma = m_gamma;
142  NekDouble gamma_1_2 = (gamma - 1.0) / 2.0;
143 
144  // Loop on all the points of that edge
145  for (int j = 0; j < npoints; j++)
146  {
147 
148  while ((abs(errV) > toll) || (abs(errTheta) > toll))
149  {
150  VV = V * V;
151  sint = sin(theta);
152  c = sqrt(1.0 - gamma_1_2 * VV);
153  k = V / sint;
154  phi = 1.0 / k;
155  pp = phi * phi;
156  J = 1.0 / c + 1.0 / (3.0 * c * c * c) +
157  1.0 / (5.0 * c * c * c * c * c) -
158  0.5 * log((1.0 + c) / (1.0 - c));
159 
160  r = pow(c, 1.0 / gamma_1_2);
161  xi = 1.0 / (2.0 * r) * (1.0 / VV - 2.0 * pp) + J / 2.0;
162  yi = phi / (r * V) * sqrt(1.0 - VV * pp);
163  par1 = 25.0 - 5.0 * VV;
164  ss = sint * sint;
165 
166  Fx = xi - x0[j];
167  Fy = yi - x1[j];
168 
169  J11 = 39062.5 / pow(par1, 3.5) *
170  (1.0 / VV - 2.0 / VV * ss) * V + 1562.5 /
171  pow(par1, 2.5) * (-2.0 / (VV * V) + 4.0 /
172  (VV * V) * ss) + 12.5 / pow(par1, 1.5) * V +
173  312.5 / pow(par1, 2.5) * V + 7812.5 /
174  pow(par1, 3.5) * V - 0.25 *
175  (-1.0 / pow(par1, 0.5) * V / (1.0 - 0.2 *
176  pow(par1, 0.5)) - (1.0 + 0.2 * pow(par1, 0.5)) /
177  pow((1.0 - 0.2 * pow(par1, 0.5)), 2.0) /
178  pow(par1, 0.5) * V) / (1.0 + 0.2 * pow(par1, 0.5)) *
179  (1.0 - 0.2 * pow(par1, 0.5));
180 
181  J12 = -6250.0 / pow(par1, 2.5) / VV * sint * cos(theta);
182  J21 = -6250.0 / (VV * V) * sint / pow(par1, 2.5) *
183  pow((1.0 - ss), 0.5) + 78125.0 / V * sint /
184  pow(par1, 3.5) * pow((1.0 - ss), 0.5);
185 
186  // the matrix is singular when theta = pi/2
187  if (abs(x1[j]) < toll && abs(cos(theta)) < toll)
188  {
189  J22 = -39062.5 / pow(par1, 3.5) / V + 3125 /
190  pow(par1, 2.5) / (VV * V) + 12.5 /
191  pow(par1, 1.5) * V + 312.5 / pow(par1, 2.5) *
192  V + 7812.5 / pow(par1, 3.5) * V - 0.25 *
193  (-1.0 / pow(par1, 0.5) * V / (1.0 - 0.2 *
194  pow(par1, 0.5)) - (1.0 + 0.2 * pow(par1, 0.5)) /
195  pow((1.0 - 0.2 * pow(par1, 0.5)), 2.0) /
196  pow(par1, 0.5) * V) / (1.0 + 0.2 *
197  pow(par1, 0.5)) * (1.0 - 0.2 * pow(par1, 0.5));
198 
199  // dV = -dV/dx * Fx
200  dV = -1.0 / J22 * Fx;
201  dtheta = 0.0;
202  theta = M_PI / 2.0;
203  }
204  else
205  {
206  J22 = 3125.0 / VV * cos(theta) / pow(par1, 2.5) *
207  pow((1.0 - ss), 0.5) - 3125.0 / VV * ss /
208  pow(par1, 2.5) / pow((1.0 - ss), 0.5) *
209  cos(theta);
210 
211  det = -1.0 / (J11 * J22 - J12 * J21);
212 
213  // [dV dtheta]' = -[invJ]*[Fx Fy]'
214  dV = det * ( J22 * Fx - J12 * Fy);
215  dtheta = det * (-J21 * Fx + J11 * Fy);
216  }
217 
218  V = V + dV;
219  theta = theta + dtheta;
220 
221  errV = abs(dV);
222  errTheta = abs(dtheta);
223  }
224 
225  c = sqrt(1.0 - gamma_1_2 * VV);
226  int kk = id2 + j;
227  NekDouble timeramp = 200.0;;
228  if (time<timeramp &&
229  !(m_session->DefinesFunction("InitialConditions") &&
230  m_session->GetFunctionType("InitialConditions", 0) ==
232  {
233  Fwd[0][kk] = pow(c, 1.0 / gamma_1_2) *
234  exp(-1.0 + time /timeramp);
235 
236  Fwd[1][kk] = Fwd[0][kk] * V * cos(theta) *
237  exp(-1 + time / timeramp);
238 
239  Fwd[2][kk] = Fwd[0][kk] * V * sin(theta) *
240  exp(-1 + time / timeramp);
241  }
242  else
243  {
244  Fwd[0][kk] = pow(c, 1.0 / gamma_1_2);
245  Fwd[1][kk] = Fwd[0][kk] * V * cos(theta);
246  Fwd[2][kk] = Fwd[0][kk] * V * sin(theta);
247  }
248 
249  P = (c * c) * Fwd[0][kk] / gamma;
250  Fwd[3][kk] = P / (gamma - 1.0) + 0.5 *
251  (Fwd[1][kk] * Fwd[1][kk] / Fwd[0][kk] +
252  Fwd[2][kk] * Fwd[2][kk] / Fwd[0][kk]);
253 
254  errV = 1.0;
255  errTheta = 1.0;
256  theta = M_PI / 4.0;
257  V = kExt * sin(theta);
258  }
259 
260  for (int i = 0; i < nvariables; ++i)
261  {
262  Vmath::Vcopy(npoints, &Fwd[i][id2], 1,
263  &(m_fields[i]->GetBndCondExpansions()[m_bcRegion]->
264  UpdatePhys())[id1],1);
265  }
266  }
267 }
268 
269 }
Encapsulates the user-defined boundary conditions for compressible flow solver.
Definition: CFSBndCond.h:71
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: CFSBndCond.h:89
NekDouble m_gamma
Parameters of the flow.
Definition: CFSBndCond.h:102
int m_bcRegion
Id of the boundary region.
Definition: CFSBndCond.h:109
int m_offset
Offset.
Definition: CFSBndCond.h:111
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array of fields.
Definition: CFSBndCond.h:91
virtual void v_Apply(Array< OneD, Array< OneD, NekDouble > > &Fwd, Array< OneD, Array< OneD, NekDouble > > &physarray, const NekDouble &time)
std::shared_ptr< SessionReader > SessionReaderSharedPtr
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
CFSBndCondFactory & GetCFSBndCondFactory()
Declaration of the boundary condition factory singleton.
Definition: CFSBndCond.cpp:41
double NekDouble
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199
P
Definition: main.py:133
scalarT< T > log(scalarT< T > in)
Definition: scalar.hpp:278
scalarT< T > abs(scalarT< T > in)
Definition: scalar.hpp:272
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:267