LifeV
KimMoin.cpp
Go to the documentation of this file.
1 /* -*- mode: c++ -*-
2 
3 This file is part of the LifeV library
4 
5 Author(s): Mauro Perego <mauro@mathcs.emory.edu>
6 Date: 2004-11-12
7 
8 Copyright (C) 2004 EPFL
9 
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14 
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /**
26  \file KimMoin.cpp
27  \author Mauro Perego <mauro@mathcs.emory.edu>
28  \date 2009-10-02
29 */
30 #include <lifev/core/LifeV.hpp>
31 
32 #include <lifev/navier_stokes/function/KimMoin.hpp>
33 
34 namespace LifeV
35 {
36 const Real Pi = 3.14159265358979323846264338328;
37 
38 Real KimMoin::uexact ( const Real& t, const Real& x, const Real& y, const Real& /*z*/, const ID& i)
39 {
40  Real e = std::exp (-8 * Pi * Pi * a * a * nu * t);
41  switch (i)
42  {
43  case 0: //u_1
44  return -std::cos (2 * Pi * a * x) * std::sin (2 * Pi * a * y) * e;
45  case 1: //u_2
46  return std::sin (2 * Pi * a * x) * std::cos (2 * Pi * a * y) * e;
47  default:
48  exit (1);
49  }
50  //dummy return as required by IBM xlC compiler
51  return 1.;
52 }
53 
54 Real KimMoin::pexact ( const Real& t, const Real& x, const Real& y, const Real& /*z*/, const ID& /* i */ )
55 {
56  Real e2 = rho * std::exp (-16 * a * a * Pi * Pi * nu * t);
57  return - (std::cos (4 * Pi * a * x) + std::cos (4 * Pi * a * y) ) * e2 / 4;
58 }
59 
60 Real KimMoin::uderexact ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& i)
61 {
62  return -8 * Pi * Pi * a * a * nu * uexact (t, x, y, z, i);
63 }
64 
65 Real KimMoin::grad_u ( const UInt& icoor, const Real& t, const Real& x, const Real& y, const Real& /*z*/, const ID& i )
66 {
67  Real e = std::exp (-8 * Pi * Pi * a * a * nu * t);
68  switch (icoor)
69  {
70  case 0: // u_x
71  switch (i)
72  {
73  case 0:
74  return 2 * Pi * e * a * std::sin (2 * Pi * a * x) * std::sin (2 * Pi * a * y);
75  case 1:
76  return 2 * Pi * e * a * std::cos (2 * Pi * a * x) * std::cos (2 * Pi * a * y);
77  default:
78  exit (1);
79  }
80  case 1: // u_y
81  switch (i)
82  {
83  case 0:
84  return -2 * Pi * e * a * std::cos (2 * Pi * a * x) * std::cos (2 * Pi * a * y);
85  case 1:
86  return -2 * Pi * e * a * std::sin (2 * Pi * a * x) * std::sin (2 * Pi * a * y);
87  default:
88  exit (1);
89  }
90  default:
91  exit (1);
92  }
93  //dummy return as required by IBM xlC compiler
94  return 1.;
95 }
96 
97 Real KimMoin::f ( const Real& /* t */, const Real& /* x */, const Real& /* y */, const Real& /* z */, const ID& /* i */ )
98 {
99  return 0;
100 }
101 
102 Real KimMoin::xexact ( const Real& t,
103  const Real& x,
104  const Real& y,
105  const Real& z,
106  const ID& i )
107 {
108  switch (i)
109  {
110  case 0: //u_1
111  case 1: //u_2
112  return uexact (t, x, y, z, i);
113  case 2: //pressure
114  return pexact (t, x, y, z, 1);
115  break;
116  default:
117  exit (1);
118  }
119  //dummy return as required by IBM xlC compiler
120  return 1.;
121 }
122 
123 
124 
125 
126 Real KimMoin::x0 ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& i )
127 {
128  return xexact (t, x, y, z, i);
129 }
130 
131 // Initial velocity
132 Real KimMoin::u0 ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& i )
133 {
134  return uexact (t, x, y, z, i);
135 }
136 
137 // Initial pressure
138 Real KimMoin::p0 ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& /*i*/ )
139 {
140  return pexact (t, x, y, z, 1);
141 }
142 
143 
144 
145 
146 //we suppose that the problem geometry is the square [0,1]x[0,1]
147 Real KimMoin::fNeumann ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& i )
148 {
149  Real n[2] = {0, 0};
150  Real out = 0;
151  if ( x == 0. )
152  {
153  n[0] = -1.;
154  }
155  else if ( x == 1. )
156  {
157  n[0] = 1.;
158  }
159  else if ( y == 0. )
160  {
161  n[1] = -1.;
162  }
163  else if ( y == 1. )
164  {
165  n[1] = 1.;
166  }
167  else
168  {
169  std::cout << "strange point: x=" << x << " y=" << y << " z=" << z
170  << std::endl;
171  }
172 
173  for (UInt k = 0; k < 2; k++) //mu gradu n
174  {
175  out += mu * grad_u (k, t, x, y, z, i) * n[k];
176  }
177 
178  if (flag_strain)
179  for (UInt k = 0; k < 2; k++) //mu gradu^T n
180  {
181  out += mu * grad_u (i, t, x, y, z, k) * n[k];
182  }
183 
184  out -= pexact (t, x, y, z, i) * n[i];
185 
186 
187  return out;
188 }
189 
190 //we suppose that the problem geometry is the square [0,1]x[0,1]
191 Real KimMoin::normalVector ( const Real& /*t*/, const Real& x, const Real& y, const Real& /*z*/, const ID& i )
192 {
193  Real n[2] = {0, 0};
194  if ( x == 0. )
195  {
196  n[0] = -1.;
197  }
198  else if ( x == 1. )
199  {
200  n[0] = 1.;
201  }
202  else if ( y == 0. )
203  {
204  n[1] = -1.;
205  }
206  else if ( y == 1. )
207  {
208  n[1] = 1.;
209  }
210  else
211  {
212  // std::cout << "strange point: x=" << x << " y=" << y << " z=" << z
213  // << std::endl;
214  }
215 
216  return n[i];
217 }
218 
219 Real KimMoin::fShearStress ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& i )
220 {
221  Real out = 0;
222 
223  for (UInt k = 0; k < nDimensions; k++) //mu gradu n
224  {
225  out += mu * grad_u (k, t, x, y, z, i) * normalVector ( t, x, y, z, k );
226  }
227 
228  if (flag_strain)
229  for (UInt k = 0; k < nDimensions; k++) //mu gradu^T n
230  {
231  out += mu * grad_u (i, t, x, y, z, k) * normalVector ( t, x, y, z, k );
232  }
233 
234  return out;
235 }
236 
237 Real KimMoin::fWallShearStress ( const Real& t, const Real& x, const Real& y, const Real& z, const ID& i )
238 {
239  // wss = s_n - ( s_n \cdot n ) n
240  Real wss = 0;
241  Real s_n_n (0.);
242  // this is the i-component of the normal stress
243  wss = fShearStress (t, x, y, z, i);
244 
245  for (UInt k = 0; k < nDimensions; k++) // ( s_n \cdot n )
246  {
247  s_n_n += fShearStress (t, x, y, z, k) * normalVector ( t, x, y, z, k );
248  }
249 
250  wss -= s_n_n * normalVector ( t, x, y, z, i );
251 
252  return wss;
253 }
254 
255 void KimMoin::setParamsFromGetPot ( const GetPot& dataFile )
256 {
257  mu = dataFile ( "fluid/physics/viscosity", 1. );
258  rho = dataFile ( "fluid/physics/density", 1. );
259  flag_strain = dataFile ( "fluid/space_discretization/stiff_strain", false );
260  nu = mu / rho;
261  a = dataFile ( "fluid/problem/a", 1. );
262 }
263 
264 Real KimMoin::nu;
265 Real KimMoin::rho;
266 Real KimMoin::mu;
267 Real KimMoin::a;
268 bool KimMoin::flag_strain;
269 
270 } // namespace LifeV
static Real grad_u(const UInt &icoor, const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:65
static Real rho
Definition: KimMoin.hpp:89
double operator()(const char *VarName, const double &Default) const
Definition: GetPot.hpp:2033
static Real x0(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:126
static Real fNeumann(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:147
static Real fShearStress(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:219
static Real xexact(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:102
static Real p0(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:138
static Real normalVector(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:191
static Real f(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:97
void updateInverseJacobian(const UInt &iQuadPt)
static Real nu
Definition: KimMoin.hpp:90
static Real uderexact(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:60
static Real u0(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:132
uint32_type ID
IDs.
Definition: LifeV.hpp:194
static Real pexact(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:54
static bool flag_strain
Definition: KimMoin.hpp:83
static Real fWallShearStress(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:237
double Real
Generic real data.
Definition: LifeV.hpp:175
static Real a
Definition: KimMoin.hpp:91
static void setParamsFromGetPot(const GetPot &dataFile)
Definition: KimMoin.cpp:255
const UInt nDimensions(NDIM)
bool operator()(const char *VarName, bool Default) const
Definition: GetPot.hpp:2008
static Real uexact(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
Definition: KimMoin.cpp:38
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
static Real mu
Definition: KimMoin.hpp:88
const Real Pi
Definition: KimMoin.cpp:36