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.num_elements();
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  GetBndCondCoeffsToGlobalCoeffsMap(
111  m_offset_plane + e_plane));
112  id2 = id2_plane + planeID*nTracePts_plane;
113  }
114  else // For general case
115  {
116  id2 = m_fields[0]->
117  GetTrace()->GetPhys_Offset(m_fields[0]->GetTraceMap()->
118  GetBndCondTraceToGlobalTraceMap(m_offset+e));
119  }
120 
121  Array<OneD,NekDouble> x0(npoints, 0.0);
122  Array<OneD,NekDouble> x1(npoints, 0.0);
123  Array<OneD,NekDouble> x2(npoints, 0.0);
124 
125  m_fields[0]->GetBndCondExpansions()[m_bcRegion]->
126  GetExp(e)->GetCoords(x0, x1, x2);
127 
128  // Flow parameters
129  NekDouble c, k, phi, r, J, VV, pp, sint, P, ss;
130  NekDouble J11, J12, J21, J22, det;
131  NekDouble Fx, Fy;
132  NekDouble xi, yi;
133  NekDouble dV;
134  NekDouble dtheta;
135  NekDouble par1;
136  NekDouble theta = M_PI / 4.0;
137  NekDouble kExt = 0.7;
138  NekDouble V = kExt * sin(theta);
139  NekDouble toll = 1.0e-8;
140  NekDouble errV = 1.0;
141  NekDouble errTheta = 1.0;
142  NekDouble gamma = m_gamma;
143  NekDouble gamma_1_2 = (gamma - 1.0) / 2.0;
144 
145  // Loop on all the points of that edge
146  for (int j = 0; j < npoints; j++)
147  {
148 
149  while ((abs(errV) > toll) || (abs(errTheta) > toll))
150  {
151  VV = V * V;
152  sint = sin(theta);
153  c = sqrt(1.0 - gamma_1_2 * VV);
154  k = V / sint;
155  phi = 1.0 / k;
156  pp = phi * phi;
157  J = 1.0 / c + 1.0 / (3.0 * c * c * c) +
158  1.0 / (5.0 * c * c * c * c * c) -
159  0.5 * log((1.0 + c) / (1.0 - c));
160 
161  r = pow(c, 1.0 / gamma_1_2);
162  xi = 1.0 / (2.0 * r) * (1.0 / VV - 2.0 * pp) + J / 2.0;
163  yi = phi / (r * V) * sqrt(1.0 - VV * pp);
164  par1 = 25.0 - 5.0 * VV;
165  ss = sint * sint;
166 
167  Fx = xi - x0[j];
168  Fy = yi - x1[j];
169 
170  J11 = 39062.5 / pow(par1, 3.5) *
171  (1.0 / VV - 2.0 / VV * ss) * V + 1562.5 /
172  pow(par1, 2.5) * (-2.0 / (VV * V) + 4.0 /
173  (VV * V) * ss) + 12.5 / pow(par1, 1.5) * V +
174  312.5 / pow(par1, 2.5) * V + 7812.5 /
175  pow(par1, 3.5) * V - 0.25 *
176  (-1.0 / pow(par1, 0.5) * V / (1.0 - 0.2 *
177  pow(par1, 0.5)) - (1.0 + 0.2 * pow(par1, 0.5)) /
178  pow((1.0 - 0.2 * pow(par1, 0.5)), 2.0) /
179  pow(par1, 0.5) * V) / (1.0 + 0.2 * pow(par1, 0.5)) *
180  (1.0 - 0.2 * pow(par1, 0.5));
181 
182  J12 = -6250.0 / pow(par1, 2.5) / VV * sint * cos(theta);
183  J21 = -6250.0 / (VV * V) * sint / pow(par1, 2.5) *
184  pow((1.0 - ss), 0.5) + 78125.0 / V * sint /
185  pow(par1, 3.5) * pow((1.0 - ss), 0.5);
186 
187  // the matrix is singular when theta = pi/2
188  if (abs(x1[j]) < toll && abs(cos(theta)) < toll)
189  {
190  J22 = -39062.5 / pow(par1, 3.5) / V + 3125 /
191  pow(par1, 2.5) / (VV * V) + 12.5 /
192  pow(par1, 1.5) * V + 312.5 / pow(par1, 2.5) *
193  V + 7812.5 / pow(par1, 3.5) * V - 0.25 *
194  (-1.0 / pow(par1, 0.5) * V / (1.0 - 0.2 *
195  pow(par1, 0.5)) - (1.0 + 0.2 * pow(par1, 0.5)) /
196  pow((1.0 - 0.2 * pow(par1, 0.5)), 2.0) /
197  pow(par1, 0.5) * V) / (1.0 + 0.2 *
198  pow(par1, 0.5)) * (1.0 - 0.2 * pow(par1, 0.5));
199 
200  // dV = -dV/dx * Fx
201  dV = -1.0 / J22 * Fx;
202  dtheta = 0.0;
203  theta = M_PI / 2.0;
204  }
205  else
206  {
207  J22 = 3125.0 / VV * cos(theta) / pow(par1, 2.5) *
208  pow((1.0 - ss), 0.5) - 3125.0 / VV * ss /
209  pow(par1, 2.5) / pow((1.0 - ss), 0.5) *
210  cos(theta);
211 
212  det = -1.0 / (J11 * J22 - J12 * J21);
213 
214  // [dV dtheta]' = -[invJ]*[Fx Fy]'
215  dV = det * ( J22 * Fx - J12 * Fy);
216  dtheta = det * (-J21 * Fx + J11 * Fy);
217  }
218 
219  V = V + dV;
220  theta = theta + dtheta;
221 
222  errV = abs(dV);
223  errTheta = abs(dtheta);
224  }
225 
226  c = sqrt(1.0 - gamma_1_2 * VV);
227  int kk = id2 + j;
228  NekDouble timeramp = 200.0;;
229  if (time<timeramp &&
230  !(m_session->DefinesFunction("InitialConditions") &&
231  m_session->GetFunctionType("InitialConditions", 0) ==
233  {
234  Fwd[0][kk] = pow(c, 1.0 / gamma_1_2) *
235  exp(-1.0 + time /timeramp);
236 
237  Fwd[1][kk] = Fwd[0][kk] * V * cos(theta) *
238  exp(-1 + time / timeramp);
239 
240  Fwd[2][kk] = Fwd[0][kk] * V * sin(theta) *
241  exp(-1 + time / timeramp);
242  }
243  else
244  {
245  Fwd[0][kk] = pow(c, 1.0 / gamma_1_2);
246  Fwd[1][kk] = Fwd[0][kk] * V * cos(theta);
247  Fwd[2][kk] = Fwd[0][kk] * V * sin(theta);
248  }
249 
250  P = (c * c) * Fwd[0][kk] / gamma;
251  Fwd[3][kk] = P / (gamma - 1.0) + 0.5 *
252  (Fwd[1][kk] * Fwd[1][kk] / Fwd[0][kk] +
253  Fwd[2][kk] * Fwd[2][kk] / Fwd[0][kk]);
254 
255  errV = 1.0;
256  errTheta = 1.0;
257  theta = M_PI / 4.0;
258  V = kExt * sin(theta);
259  }
260 
261  for (int i = 0; i < nvariables; ++i)
262  {
263  Vmath::Vcopy(npoints, &Fwd[i][id2], 1,
264  &(m_fields[i]->GetBndCondExpansions()[m_bcRegion]->
265  UpdatePhys())[id1],1);
266  }
267  }
268 }
269 
270 }
STL namespace.
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: CFSBndCond.h:83
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array of fields.
Definition: CFSBndCond.h:85
CFSBndCondFactory & GetCFSBndCondFactory()
Declaration of the boundary condition factory singleton.
Definition: CFSBndCond.cpp:41
virtual void v_Apply(Array< OneD, Array< OneD, NekDouble > > &Fwd, Array< OneD, Array< OneD, NekDouble > > &physarray, const NekDouble &time)
Encapsulates the user-defined boundary conditions for compressible flow solver.
Definition: CFSBndCond.h:70
double NekDouble
NekDouble m_gamma
Parameters of the flow.
Definition: CFSBndCond.h:94
int m_offset
Offset.
Definition: CFSBndCond.h:102
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
std::shared_ptr< SessionReader > SessionReaderSharedPtr
int m_bcRegion
Id of the boundary region.
Definition: CFSBndCond.h:100