Memosa-FVM  0.2
WallDiscretization.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _WALLDISCRETIZATION_H_
6 #define _WALLDISCRETIZATION_H_
7 
8 #include <math.h>
9 #include "CRMatrix.h"
10 #include "Field.h"
11 #include "MultiField.h"
12 #include "MultiFieldMatrix.h"
13 #include "Mesh.h"
14 #include "Discretization.h"
15 #include "StorageSite.h"
16 #include "DiagonalMatrix.h"
17 #include "Gradient.h"
18 #include "DiagonalTensor.h"
19 
20 template<class T>
21 inline T harmonicAvg(const T& x0, const T& x1)
22 {
23  const T sum = x0+x1;
24  if (x0+x1 != NumTypeTraits<T>::getZero())
25  return 2.0*x0*x1/sum;
26  else
27  return sum;
28 }
29 
30 
31 template<class X, class Diag, class OffDiag>
33 {
34 public:
36 
38  typedef typename CCMatrix::DiagArray DiagArray;
40 
41  typedef Gradient<X> XGrad;
43 
44  typedef Array<X> XArray;
48 
50 
51 
53  const GeomFields& geomFields,
54  Field& varField,
55  Field& energyField,
56  Field& densityField,
57  Field& wallstressField,
58  Field& parallelvelocityField,
59  Field& tauwallField,
60  Field& diffusivityField,
61  Field& muField,
62  const Field& varGradientField,
63  const T_Scalar thickness=0.0):
64 
65  Discretization(meshes),
66  _geomFields(geomFields),
67  _varField(varField),
68  _energyField(energyField),
69  _densityField(densityField),
70  _wallstressField(wallstressField),
71  _parallelvelocityField(parallelvelocityField),
72  _tauwallField(tauwallField),
73  _diffusivityField(diffusivityField),
74  _muField(muField),
75  _varGradientField(varGradientField),
76  _thickness(thickness)
77 
78  {}
79 
81 
82  void discretize(const Mesh& mesh,MultiFieldMatrix& mfmatrix,
83  MultiField& xField, MultiField& rField)
84 
85  {
86 
87 
88  const StorageSite& cells = mesh.getCells();
89 
90  const MultiField::ArrayIndex cVarIndex(&_varField,&cells);
91  CCMatrix& matrix = dynamic_cast<CCMatrix&>(mfmatrix.getMatrix(cVarIndex,
92  cVarIndex));
93 
94  const VectorT3Array& cellCentroid =
95  dynamic_cast<const VectorT3Array&>(_geomFields.coordinate[cells]);
96 
97  const IntArray& ibType = dynamic_cast<const IntArray&>(_geomFields.ibType[cells]);
98  const TArray& cellVolume =
99  dynamic_cast<const TArray&>(_geomFields.volume[cells]);
100 
101 
102  const TArray & rhoCell =
103  dynamic_cast<const TArray&>(_densityField[cells]);
104 
105  const TArray & kCell =
106  dynamic_cast<const TArray&>(_energyField[cells]);
107 
108  const TArray & muCell=
109  dynamic_cast<const TArray&>(_muField[cells]);
110 
111 
112  const VectorT3Array& U =
113  dynamic_cast<const VectorT3Array&>(_varField[cells]);
114 
115  VectorT3Array& Up =
116  dynamic_cast<VectorT3Array&>(_parallelvelocityField[cells]);
117 
118  const TArray& diffCell =
119  dynamic_cast<const TArray&>(_diffusivityField[cells]);
120 
121  const GradArray& xGradCell =
122  dynamic_cast<const GradArray&>(_varGradientField[cells]);
123 
124  const XArray& xCell = dynamic_cast<const XArray&>(xField[cVarIndex]);
125  XArray& rCell = dynamic_cast<XArray&>(rField[cVarIndex]);
126 
127 
128 
129 foreach(const FaceGroupPtr fgPtr, mesh.getAllFaceGroups())
130  {
131  const FaceGroup& fg = *fgPtr;
132  const StorageSite& faces = fg.site;
133  if (fg.groupType =="wall")
134  {
135  const TArray& faceAreaMag =
136  dynamic_cast<const TArray &>(_geomFields.areaMag[faces]);
137 
138  const VectorT3Array& faceArea=
139  dynamic_cast<const VectorT3Array&>(_geomFields.area[faces]);
140 
141  const VectorT3Array& faceCentroid =
142  dynamic_cast<const VectorT3Array&>(_geomFields.coordinate[faces]);
143 
144 
145 
146  VectorT3Array& tauCell =
147  dynamic_cast<VectorT3Array&>(_wallstressField[faces]);
148 
149  //tau parallel to the wall in direction of flow
150 
151  VectorT3Array& TauWallCell =
152  dynamic_cast<VectorT3Array&>(_tauwallField[faces]);
153 
154  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
155 
156  CCAssembler& assembler = matrix.getPairWiseAssembler(faceCells);
157 
158  DiagArray& diag = matrix.getDiag();
159 
160  const int nFaces = faces.getCount();
161 
162  T_Scalar vonk = _options.vk; //vonKarman
163  T_Scalar Emp = _options.emp; //Empirical constant
164  T_Scalar Cmu = _options.cmu; //Cmu constant of k-e model
165  T_Scalar onefourth(0.25);
166  T_Scalar eleven(11.225);
167 
168  for(int f=0; f<nFaces; f++)
169  {
170 
171  T_Scalar ystar = 0; T_Scalar wallMetric =0;
172  const int c0 = faceCells(f,0);
173  const int c1 = faceCells(f,1);
174  VectorT3 n = faceArea[f]/faceAreaMag[f];
175 
176  T_Scalar vol0 = cellVolume[c0];
177  T_Scalar vol1 = cellVolume[c1];
178  //Computation of Diffusion flux
179 
180  VectorT3 ds = cellCentroid[c1]-cellCentroid[c0];
181 
182  // for ib faces ignore the solid cell and use the face centroid for diff metric
183  if (((ibType[c0] == Mesh::IBTYPE_FLUID)
184  && (ibType[c1] == Mesh::IBTYPE_BOUNDARY)) ||
185  ((ibType[c1] == Mesh::IBTYPE_FLUID)
186  && (ibType[c0] == Mesh::IBTYPE_BOUNDARY)))
187  {
188  if (ibType[c0] == Mesh::IBTYPE_FLUID)
189  {
190  vol1 = 0.;
191  ds = faceCentroid[f]-cellCentroid[c0];
192  }
193  else
194  {
195  vol0 = 0.;
196  ds = cellCentroid[c1]-faceCentroid[f];
197  }
198  }
199  //cout << "ds" << ds << endl;
200 
201  T_Scalar faceDiffusivity(1.0);
202  if (vol0 == 0.)
203  faceDiffusivity = diffCell[c1];
204  else if (vol1 == 0.)
205  faceDiffusivity = diffCell[c0];
206  else
207  faceDiffusivity = harmonicAvg(diffCell[c0],diffCell[c1]);
208  const T_Scalar diffMetric = faceAreaMag[f]*faceAreaMag[f]/dot(faceArea[f],ds);
209  const T_Scalar diffCoeff = faceDiffusivity*diffMetric;
210  const VectorT3 secondaryCoeff = faceDiffusivity*(faceArea[f]-ds*diffMetric);
211 
212  const XGrad gradF = (xGradCell[c0]*vol0+xGradCell[c1]*vol1)/(vol0+vol1);
213 
214  const X dFluxSecondary = gradF*secondaryCoeff;
215 
216  const X dFlux = diffCoeff*(xCell[c1]-xCell[c0]) + dFluxSecondary;
217 
218  const T_Scalar yp = ds[0]*n[0] + ds[1]*n[1] + ds[2]*n[2];
219 
220  ystar = (rhoCell[c0]*sqrt(kCell[c0])*pow(Cmu,onefourth)*yp)/muCell[c0];
221 
222  T_Scalar v_dot_n = U[c0][0]*n[0] + U[c0][1]*n[1] + U[c0][2]*n[2];
223 
224  for (int i=0; i<3; i++)
225  {
226  Up[c0][i] = U[c0][i] - v_dot_n*n[i];
227 
228 
229  if (ystar > eleven)
230  {
231  wallMetric = (vonk*rhoCell[c0]*pow(Cmu,onefourth)*sqrt(kCell[c0]))/log(Emp*ystar);
232 
233  }
234 
235  else
236  {
237 
238  wallMetric = muCell[c0]/yp;
239 
240  }
241 
242  tauCell[f][i] = Up[c0][i]*wallMetric;
243 
244  T_Scalar tau_dot_n = tauCell[f][0]*n[0]+ tauCell[f][1]*n[1]+ tauCell[f][2]*n[2];
245 
246  TauWallCell[f][i] = tauCell[f][i] - tau_dot_n*n[i];
247 
248  }
249  // T_Scalar wFlux = TauWallCell[f][0]*faceArea[f][0]+TauWallCell[f][1]*faceArea[f][1]+TauWallCell[f][2]*faceArea[f][2];
250 
251  // cout << "flux" << TauWallCell[f]-dFlux << endl;
252 
253 
254  X flux = TauWallCell[f]-dFlux ;
255 
256  rCell[c0] += flux;
257  rCell[c1] -= flux;
258 
259 
260  rCell[c0] += dFlux;
261  rCell[c1] -= dFlux;
262 
263  //diag[c0] +=diffCoeff;
264  //assembler.getCoeff01(f) -=diffCoeff;
265 
266  T_Scalar wallCoeff = wallMetric- diffCoeff;
267 
268  diag[c1] -=wallCoeff;
269  assembler.getCoeff10(f) +=wallCoeff;
270 
271  }
272  }
273  }
274 }
275 private:
289 };
290 
291 #endif
292 
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
shared_ptr< FaceGroup > FaceGroupPtr
Definition: Mesh.h:46
Vector< T_Scalar, 3 > VectorT3
Field coordinate
Definition: GeomFields.h:19
const T_Scalar _thickness
Definition: Mesh.h:28
const FaceGroupList & getAllFaceGroups() const
Definition: Mesh.h:193
T harmonicAvg(const T &x0, const T &x1)
Definition: Field.h:14
FlowModelOptions< double > & getOptions()
Definition: Mesh.h:49
double emp
Definition: FlowBC.h:85
OffDiag & getCoeff10(const int np)
Definition: CRMatrix.h:131
double cmu
Definition: FlowBC.h:83
Array< Diag > & getDiag()
Definition: CRMatrix.h:856
const MeshList _meshes
Array< XGrad > GradArray
NumTypeTraits< X >::T_Scalar T_Scalar
string groupType
Definition: Mesh.h:42
Field ibType
Definition: GeomFields.h:38
CCMatrix::PairWiseAssembler CCAssembler
Tangent sqrt(const Tangent &a)
Definition: Tangent.h:317
void discretize(const Mesh &mesh, MultiFieldMatrix &mfmatrix, MultiField &xField, MultiField &rField)
Array< VectorT3 > VectorT3Array
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
const Field & _varGradientField
FlowModelOptions< double > _options
const StorageSite & getCells() const
Definition: Mesh.h:109
WallDiscretization(const MeshList &meshes, const GeomFields &geomFields, Field &varField, Field &energyField, Field &densityField, Field &wallstressField, Field &parallelvelocityField, Field &tauwallField, Field &diffusivityField, Field &muField, const Field &varGradientField, const T_Scalar thickness=0.0)
Field volume
Definition: GeomFields.h:26
const CRConnectivity & getFaceCells(const StorageSite &site) const
Definition: Mesh.cpp:388
CCMatrix::DiagArray DiagArray
Array< T_Scalar > TArray
int getCount() const
Definition: StorageSite.h:39
Field area
Definition: GeomFields.h:23
double vk
Definition: FlowBC.h:84
PairWiseAssembler & getPairWiseAssembler(const CRConnectivity &pairs)
Definition: CRMatrix.h:867
Field areaMag
Definition: GeomFields.h:25
T dot(const Vector< T, 3 > &a, const Vector< T, 3 > &b)
Definition: Vector.h:253
CRMatrix< Diag, OffDiag, X > CCMatrix
const GeomFields & _geomFields
vector< Mesh * > MeshList
Definition: Mesh.h:439
StorageSite site
Definition: Mesh.h:40