Memosa-FVM  0.2
KeModel_impl.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 #include "Mesh.h"
6 #include <sstream>
7 #include <math.h>
8 #include "NumType.h"
9 #include "Array.h"
10 #include "Field.h"
11 #include "CRConnectivity.h"
12 #include "LinearSystem.h"
13 //#include "FieldSet.h"
14 #include "StorageSite.h"
15 #include "MultiFieldMatrix.h"
16 #include "CRMatrix.h"
17 #include "FluxJacobianMatrix.h"
18 #include "DiagonalMatrix.h"
19 #include "GenericBCS.h"
20 #include "Vector.h"
24 #include "AMG.h"
25 #include "Linearizer.h"
26 #include "GradientModel.h"
28 //#include "SourceDiscretization.h"
31 
32 
33 template<class T>
34 class KeModel<T>::Impl
35 {
36 public:
37  typedef Array<T> TArray;
47 
48  Impl(const GeomFields& geomFields,
49  KeFields& keFields,
50  FlowFields& flowFields,
51  const MeshList& meshes) :
52  _meshes(meshes),
53  _geomFields(geomFields),
54  _keFields(keFields),
55  _flowFields(flowFields),
56  // _velocityGradientModel(_meshes,_flowFields.velocity,
57  // _flowFields.velocityGradient,_geomFields),
58  _energyGradientModel(_meshes,_keFields.energy,
59  _keFields.energyGradient,_geomFields),
60  _dissipationGradientModel(_meshes,_keFields.dissipation,
61  _keFields.dissipationGradient,_geomFields),
62  _initialNormk(),
63  _initialNorm(),
64  _niters(0)
65  {
66  const int numMeshes = _meshes.size();
67  for (int n=0; n<numMeshes; n++)
68  {
69  const Mesh& mesh = *_meshes[n];
70  /*
71  FlowVC<T> *vc1(new FlowVC<T>());
72  vc1->vcType = "flow";
73  _vcMap[mesh.getID()] = vc1;
74 */
75  KeVC<T> *vc(new KeVC<T>());
76  vc->vcType = "flow";
77  _vcMap[mesh.getID()] = vc;
78 
79  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
80  {
81  const FaceGroup& fg = *fgPtr;
82  KeBC<T> *bc(new KeBC<T>());
83 
84  _bcMap[fg.id] = bc;
85 
86  if ((fg.groupType == "symmetry"))
87  {
88  bc->bcType = "Symmetry";
89  }
90 
91  else if ((fg.groupType == "velocity-inlet"))
92  {
93  bc->bcType = "Specifiedkandepsilon";
94  }
95  else if ((fg.groupType == "wall"))
96  {
97  bc->bcType = "Wall";
98  }
99 
100  else if ((fg.groupType == "pressure-inlet") ||
101  (fg.groupType == "pressure-outlet"))
102  {
103  bc->bcType = "PressureBoundary";
104  }
105 
106  else
107  throw CException("KeModel: unknown face group type "
108  + fg.groupType);
109 
110  }
111  }
112  }
113 
114  void init()
115  {
116  const int numMeshes = _meshes.size();
117  for (int n=0; n<numMeshes; n++)
118  {
119  const Mesh& mesh = *_meshes[n];
120  //const FlowVC<T>&vc1 = *_vcMap[mesh.getID()];
121  const KeVC<T>&vc = *_vcMap[mesh.getID()];
122 
123  const StorageSite& cells = mesh.getCells();
124  //energy(k)
125 
126  shared_ptr<TArray> kCell(new TArray(cells.getCount()));
127  *kCell = vc["InitialEnergy"];
128  _keFields.energy.addArray(cells,kCell);
129 
130  //dissipation(e)
131  shared_ptr<TArray> eCell(new TArray(cells.getCount()));
132  *eCell = vc["InitialDissipation"];
133  _keFields.dissipation.addArray(cells,eCell);
134 
135 
136  shared_ptr<TArray> sourcekCell(new TArray(cells.getCount()));
137  *sourcekCell = T(1.0);
138  _keFields.sourcek.addArray(cells,sourcekCell);
139 
140  shared_ptr<TArray> sourcedCell(new TArray(cells.getCount()));
141  *sourcedCell = T(1.0);
142  _keFields.sourced.addArray(cells,sourcedCell);
143 
144  shared_ptr<TArray> sourcecCell(new TArray(cells.getCount()));
145  *sourcecCell = T(1.0);
146  _keFields.sourcec.addArray(cells,sourcecCell);
147 
148  shared_ptr<TArray> sourcepCell(new TArray(cells.getCount()));
149  *sourcepCell = T(1.0);
150  _keFields.sourcep.addArray(cells,sourcepCell);
151 
152 
153  if (_options.transient)
154  {
155  _keFields.dissipationN1.addArray(cells,
156  dynamic_pointer_cast<ArrayBase>(eCell->newCopy()));
157  if (_options.timeDiscretizationOrder > 1)
158  _keFields.dissipationN2.addArray(cells,
159  dynamic_pointer_cast<ArrayBase>(eCell->newCopy()));
160 
161  }
162 
163 
164 /*
165  //initial velocity gradient array
166  shared_ptr<VGradArray> gradV(new VGradArray(cells.getCount()));
167  gradV->zero();
168  _flowFields.velocityGradient.addArray(cells,gradV);
169  */
170  //initial energy gradient array
171  shared_ptr<EGradArray> gradE(new EGradArray(cells.getCount()));
172  gradE->zero();
173  _keFields.energyGradient.addArray(cells,gradE);
174 
175  //initial dissipation gradient array
176  shared_ptr<DGradArray> gradD(new DGradArray(cells.getCount()));
177  gradD->zero();
178  _keFields.dissipationGradient.addArray(cells,gradD);
179 
180  // density field
181  shared_ptr<TArray> densityCell(new TArray(cells.getCount()));
182  *densityCell = T(1.225);
183  //*densityCell = vc1["density"];
184  _flowFields.density.addArray(cells,densityCell);
185 
186  //c1
187  shared_ptr<TArray> c1Cell(new TArray(cells.getCount()));
188  *c1Cell = vc["c1"];
189  _keFields.c1.addArray(cells,c1Cell);
190 
191  //c2
192  shared_ptr<TArray> c2Cell(new TArray(cells.getCount()));
193  *c2Cell = vc["c2"];
194  _keFields.c2.addArray(cells,c2Cell);
195 
196  //kflux at faces
197  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
198  {
199  const FaceGroup& fg = *fgPtr;
200  const StorageSite& faces = fg.site;
201 
202  shared_ptr<TArray> fluxFace(new TArray(faces.getCount()));
203 
204  fluxFace->zero();
205  _keFields.kFlux.addArray(faces,fluxFace);
206 
207  }
208  foreach(const FaceGroupPtr fgPtr, mesh.getInterfaceGroups())
209  {
210  const FaceGroup& fg = *fgPtr;
211  const StorageSite& faces = fg.site;
212 
213  shared_ptr<TArray> fluxFace(new TArray(faces.getCount()));
214 
215  fluxFace->zero();
216  _keFields.kFlux.addArray(faces,fluxFace);
217 
218  }
219 
220  //eflux at faces
221  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
222  {
223  const FaceGroup& fg = *fgPtr;
224  const StorageSite& faces = fg.site;
225 
226  shared_ptr<TArray> fluxFace(new TArray(faces.getCount()));
227 
228  fluxFace->zero();
229  _keFields.eFlux.addArray(faces,fluxFace);
230 
231  }
232  foreach(const FaceGroupPtr fgPtr, mesh.getInterfaceGroups())
233  {
234  const FaceGroup& fg = *fgPtr;
235  const StorageSite& faces = fg.site;
236 
237  shared_ptr<TArray> fluxFace(new TArray(faces.getCount()));
238 
239  fluxFace->zero();
240  _keFields.eFlux.addArray(faces,fluxFace);
241 
242  }
243 
244 
245  //laminar viscosity
246  shared_ptr<TArray> lmuCell(new TArray(cells.getCount()));
247  *lmuCell = T(1.7894e-5);
248  // *lmuCell = vc["viscosity"];
249  _flowFields.viscosity.addArray(cells,lmuCell);
250 
251  //turbulent viscosity
252  shared_ptr<TArray> muCell(new TArray(cells.getCount()));
253  *muCell = T(1e-05);
254  //*muCell = vc["eddyviscosity"];
255  _flowFields.eddyviscosity.addArray(cells,muCell);
256 
257 
258  //total viscosity
259  shared_ptr<TArray> tmuCell(new TArray(cells.getCount()));
260  *tmuCell = T(1e-03);
261  // *tmuCell = vc["totalviscosity"];
262  _flowFields.totalviscosity.addArray(cells,tmuCell);
263 
264  }
265  //_keFields.energy.synclocal();
266  // _keFields.dissipation.synclocal();
267  _niters =0;
268  _initialNormk = MFRPtr();
269  _initialNorm = MFRPtr();
270 
271  }
272 
273  KeBCMap& getBCMap() {return _bcMap;}
274  KeVCMap& getVCMap() {return _vcMap;}
275  // FlowVCMap& getVCMap() {return _vcMap;}
276  KeBC<T>& getBC(const int id) {return *_bcMap[id];}
277 
278  KeModelOptions<T>& getOptions() {return _options;}
279 
280  void updateTimek()
281  {
282  const int numMeshes = _meshes.size();
283  for (int n=0; n<numMeshes; n++)
284  {
285  const Mesh& mesh = *_meshes[n];
286 
287  const StorageSite& cells = mesh.getCells();
288  TArray& k =
289  dynamic_cast<TArray&>(_keFields.energy[cells]);
290  TArray& kN1 =
291  dynamic_cast<TArray&>(_keFields.energyN1[cells]);
292 
293  if (_options.timeDiscretizationOrder > 1)
294  {
295  TArray& kN2 =
296  dynamic_cast<TArray&>(_keFields.energyN2[cells]);
297  kN2 = kN1;
298  }
299  kN1 = k;
300 
301  }
302  }
303 
304 
305 
306 
307  void updateTimee()
308  {
309  const int numMeshes = _meshes.size();
310  for (int n=0; n<numMeshes; n++)
311  {
312  const Mesh& mesh = *_meshes[n];
313 
314  const StorageSite& cells = mesh.getCells();
315  TArray& e =
316  dynamic_cast<TArray&>(_keFields.dissipation[cells]);
317  TArray& eN1 =
318  dynamic_cast<TArray&>(_keFields.dissipationN1[cells]);
319 
320  if (_options.timeDiscretizationOrder > 1)
321  {
322  TArray& eN2 =
323  dynamic_cast<TArray&>(_keFields.dissipationN2[cells]);
324  eN2 = eN1;
325  }
326  eN1 = e;
327  }
328  }
329 
330 
331 
332 
334  {
335  const int numMeshes = _meshes.size();
336  for (int n=0; n<numMeshes; n++)
337  {
338  const Mesh& mesh = *_meshes[n];
339 
340  const StorageSite& cells = mesh.getCells();
341  MultiField::ArrayIndex kIndex(&_keFields.energy,&cells);
342 
343  lsk.getX().addArray(kIndex,_keFields.energy.getArrayPtr(cells));
344 
345  const CRConnectivity& cellCells = mesh.getCellCells();
346 
347  shared_ptr<Matrix> m(new CRMatrix<T,T,T>(cellCells));
348 
349  lsk.getMatrix().addMatrix(kIndex,kIndex,m);
350 
351  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
352  {
353  const FaceGroup& fg = *fgPtr;
354  const StorageSite& faces = fg.site;
355 
356  MultiField::ArrayIndex fIndex(&_keFields.kFlux,&faces);
357  lsk.getX().addArray(fIndex,_keFields.kFlux.getArrayPtr(faces));
358 
359  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
360 
361  shared_ptr<Matrix> mft(new FluxJacobianMatrix<T,T>(faceCells));
362  lsk.getMatrix().addMatrix(fIndex,kIndex,mft);
363 
364  shared_ptr<Matrix> mff(new DiagonalMatrix<T,T>(faces.getCount()));
365  lsk.getMatrix().addMatrix(fIndex,fIndex,mff);
366  }
367 
368  foreach(const FaceGroupPtr fgPtr, mesh.getInterfaceGroups())
369  {
370  const FaceGroup& fg = *fgPtr;
371  const StorageSite& faces = fg.site;
372 
373  MultiField::ArrayIndex fIndex(&_keFields.kFlux,&faces);
374  lsk.getX().addArray(fIndex,_keFields.kFlux.getArrayPtr(faces));
375 
376  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
377 
378  shared_ptr<Matrix> mft(new FluxJacobianMatrix<T,T>(faceCells));
379  lsk.getMatrix().addMatrix(fIndex,kIndex,mft);
380 
381  shared_ptr<Matrix> mff(new DiagonalMatrix<T,T>(faces.getCount()));
382  lsk.getMatrix().addMatrix(fIndex,fIndex,mff);
383  }
384 
385  }
386  }
387 
389  {
390  //_velocityGradientModel.compute();
391  _energyGradientModel.compute();
392  DiscrList discretizations;
393 
394  if (_options.transient)
395  {
396 
397  shared_ptr<Discretization>
399  (_meshes,_geomFields,
400  _keFields.energy,
401  _keFields.energyN1,
402  _keFields.energyN2,
403  _flowFields.density,
404  _options["timeStep"]));
405 
406  discretizations.push_back(td);
407  }
408 
409  shared_ptr<Discretization>
411  (_meshes,_geomFields,
412  _keFields.energy,
413  _keFields.c1,
414  _keFields.energyGradient));
415  discretizations.push_back(dd);
416 
417  shared_ptr<Discretization>
419  (_meshes,_geomFields,
420  _keFields.energy,
421  _flowFields.massFlux,
422  _flowFields.continuityResidual,
423  _keFields.energyGradient,
424  _options.useCentralDifference));
425  discretizations.push_back(cd);
426 
427 
428  shared_ptr<Discretization>
430  (_meshes,
431  _geomFields,
432  _keFields.energy,
433  _flowFields.velocity,
434  _flowFields.eddyviscosity,
435  _keFields.dissipation,
436  _flowFields.density,
437  _keFields.sourcek,
438  _flowFields.velocityGradient));
439  discretizations.push_back(sd);
440 
441  shared_ptr<Discretization>
443  (_meshes,_geomFields,_keFields.energy));
444 
445  discretizations.push_back(ene);
446 
447  Linearizer linearizer;
448 
449  linearizer.linearize(discretizations,_meshes,lsk.getMatrix(),
450  lsk.getX(), lsk.getB());
451 
452  const int numMeshes = _meshes.size();
453  for (int n=0; n<numMeshes; n++)
454  {
455  const Mesh& mesh = *_meshes[n];
456 
457  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
458  {
459  const FaceGroup& fg = *fgPtr;
460  const StorageSite& faces = fg.site;
461  const KeBC<T>& bc = *_bcMap[fg.id];
462 
463  GenericBCS<T,T,T> gbc(faces,mesh,
464  _geomFields,
465  _keFields.energy,
466  _keFields.kFlux,
467  lsk.getMatrix(), lsk.getX(), lsk.getB());
468 
470  bk(bc.getVal("Specifiedk"),faces);
471  TArray& massFlux = dynamic_cast<TArray&>(_flowFields.massFlux[faces]);
472  const int nFaces = faces.getCount();
473 
474 
475 
476  // if (bc.bcType == "Specifiedk")
477  if ( bc.bcType == "Specifiedkandepsilon")
478  {
479  for(int f=0; f<nFaces; f++)
480  {
481 
482  //cout << "massflux" << massFlux[f] << endl;
483 
484  if (massFlux[f] > 0.)
485  {
486  gbc.applyExtrapolationBC(f);
487  }
488  else
489  {
490  gbc.applyDirichletBC(f,bk[f]);
491  }
492  }
493 
494  }
495 
496  else if ((bc.bcType == "Wall"))
497  {
498  for(int f=0; f<nFaces; f++)
499  {
500 
501  gbc.applyNeumannBC(f,0);
502  }
503  }
504  else if ((bc.bcType == "PressureBoundary"))
505  {
506  for(int f=0; f<nFaces; f++)
507  {
508 
509  if (massFlux[f] > 0.)
510  {
511  gbc.applyExtrapolationBC(f);
512  }
513  else
514  {
515  gbc.applyDirichletBC(f,bk[f]);
516  }
517  }
518  }
519 
520 
521 
522 
523  else if ((bc.bcType == "Symmetry"))
524  {
525  cout <<"nfaces" << nFaces << endl;
526 
527  gbc.applySymmetryBC();
528  }
529  else
530  throw CException(bc.bcType + " not implemented for KeModel");
531  }
532 
533  foreach(const FaceGroupPtr fgPtr, mesh.getInterfaceGroups())
534  {
535  const FaceGroup& fg = *fgPtr;
536  const StorageSite& faces = fg.site;
537  GenericBCS<T,T,T> gbc(faces,mesh,
538  _geomFields,
539  _keFields.energy,
540  _keFields.kFlux,
541  lsk.getMatrix(), lsk.getX(), lsk.getB());
542 
543  gbc.applyInterfaceBC();
544 
545  }
546  }
547  DiscrList discretizations2;
548  shared_ptr<Discretization>
549  ud(new Underrelaxer<T,T,T>
550  (_meshes,_keFields.energy,
551  _options["energyURF"]));
552 
553  discretizations2.push_back(ud);
554 
555  linearizer.linearize(discretizations2,_meshes,lsk.getMatrix(),
556  lsk.getX(), lsk.getB());
557 
558  }
559 
561  {
562  const int numMeshes = _meshes.size();
563  for (int n=0; n<numMeshes; n++)
564  {
565  const Mesh& mesh = *_meshes[n];
566 
567  const StorageSite& cells = mesh.getCells();
568  MultiField::ArrayIndex eIndex(&_keFields.dissipation,&cells);
569 
570  lse.getX().addArray(eIndex,_keFields.dissipation.getArrayPtr(cells));
571 
572  const CRConnectivity& cellCells = mesh.getCellCells();
573 
574  shared_ptr<Matrix> m(new CRMatrix<T,T,T>(cellCells));
575 
576  lse.getMatrix().addMatrix(eIndex,eIndex,m);
577 
578  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
579  {
580  const FaceGroup& fg = *fgPtr;
581  const StorageSite& faces = fg.site;
582 
583  MultiField::ArrayIndex fIndex(&_keFields.eFlux,&faces);
584  lse.getX().addArray(fIndex,_keFields.eFlux.getArrayPtr(faces));
585 
586  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
587 
588  shared_ptr<Matrix> mft(new FluxJacobianMatrix<T,T>(faceCells));
589  lse.getMatrix().addMatrix(fIndex,eIndex,mft);
590 
591  shared_ptr<Matrix> mff(new DiagonalMatrix<T,T>(faces.getCount()));
592  lse.getMatrix().addMatrix(fIndex,fIndex,mff);
593  }
594  foreach(const FaceGroupPtr fgPtr, mesh.getInterfaceGroups())
595  {
596  const FaceGroup& fg = *fgPtr;
597  const StorageSite& faces = fg.site;
598 
599  MultiField::ArrayIndex fIndex(&_keFields.eFlux,&faces);
600  lse.getX().addArray(fIndex,_keFields.eFlux.getArrayPtr(faces));
601 
602  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
603 
604  shared_ptr<Matrix> mft(new FluxJacobianMatrix<T,T>(faceCells));
605  lse.getMatrix().addMatrix(fIndex,eIndex,mft);
606 
607  shared_ptr<Matrix> mff(new DiagonalMatrix<T,T>(faces.getCount()));
608  lse.getMatrix().addMatrix(fIndex,fIndex,mff);
609  }
610 
611  }
612  }
613 
614 
616  {
617  //_velocityGradientModel.compute();
618  _dissipationGradientModel.compute();
619 
620  DiscrList discretizations1;
621  if (_options.transient)
622  {
623 
624  shared_ptr<Discretization>
626  (_meshes,_geomFields,
627  _keFields.dissipation,
628  _keFields.dissipationN1,
629  _keFields.dissipationN2,
630  _flowFields.density,
631  _options["timeStep"]));
632  discretizations1.push_back(td);
633 
634 }
635  shared_ptr<Discretization>
637  (_meshes,_geomFields,
638  _keFields.dissipation,
639  _keFields.c2,
640  _keFields.dissipationGradient));
641  discretizations1.push_back(dd);
642 
643  shared_ptr<Discretization>
645  (_meshes,_geomFields,
646  _keFields.dissipation,
647  _flowFields.massFlux,
648  _flowFields.continuityResidual,
649  _keFields.dissipationGradient,
650  _options.useCentralDifference));
651  discretizations1.push_back(cd);
652 
653 
654  shared_ptr<Discretization>
656  (_meshes,
657  _geomFields,
658  _keFields.dissipation,
659  _flowFields.velocity,
660  _flowFields.eddyviscosity,
661  _keFields.energy,
662  _flowFields.density,
663  _keFields.sourced,
664  _keFields.sourcec,
665  _keFields.sourcep,
666  _flowFields.velocityGradient));
667  discretizations1.push_back(sd);
668 
669  shared_ptr<Discretization>
671  (_meshes,_geomFields,_keFields.dissipation));
672 
673  discretizations1.push_back(dis);
674 
675  Linearizer linearizer;
676  linearizer.linearize(discretizations1,_meshes,lse.getMatrix(),
677  lse.getX(), lse.getB());
678 
679  const int numMeshes = _meshes.size();
680  for (int n=0; n<numMeshes; n++)
681  {
682  const Mesh& mesh = *_meshes[n];
683 
684  foreach(const FaceGroupPtr fgPtr, mesh.getBoundaryFaceGroups())
685  {
686  const FaceGroup& fg = *fgPtr;
687  const StorageSite& faces = fg.site;
688  // const int nFaces = faces.getCount();
689 
690  const KeBC<T>& bc = *_bcMap[fg.id];
691 
692 
693  GenericBCS<T,T,T> gbc(faces,mesh,
694  _geomFields,
695  _keFields.dissipation,
696  _keFields.eFlux,
697  lse.getMatrix(), lse.getX(), lse.getB());
698 
700  be(bc.getVal("specifiede"),faces);
701 
702  const StorageSite& cells = mesh.getCells();
703  const CRConnectivity& faceCells = mesh.getFaceCells(faces);
704  MultiFieldMatrix& MFMatrix = lse.getMatrix();
705  MultiField::ArrayIndex beIndex(&_keFields.dissipation,&cells);
706  MultiField& b = lse.getB();
707  TArray& rCell = dynamic_cast<TArray&>(b[beIndex]);
708  T_Matrix& matrix = dynamic_cast<T_Matrix&>(MFMatrix.getMatrix(beIndex,beIndex));
709 
710  const TArray& faceAreaMag =dynamic_cast<const TArray &>(_geomFields.areaMag[faces]);
711 
712  const VectorT3Array& faceArea=dynamic_cast<const VectorT3Array&>(_geomFields.area[faces]);
713 
714  //const TArray& cellVolume = dynamic_cast<const TArray&>(_geomFields.volume[cells]);
715 
716  const VectorT3Array& faceCentroid =dynamic_cast<const VectorT3Array&> (_geomFields.coordinate[faces]);
717 
718  const VectorT3Array& cellCentroid = dynamic_cast<const VectorT3Array&>(_geomFields.coordinate[cells]);
719 
720  TArray& kCell = dynamic_cast< TArray&>(_keFields.energy[cells]);
721  TArray& eCell = dynamic_cast<TArray&>(_keFields.dissipation[cells]);
722  T cmu = _options.cmu;
723  T vonk = _options.vk;
724 
725  TArray& massFlux = dynamic_cast<TArray&>(_flowFields.massFlux[faces]);
726  const int nFaces = faces.getCount();
727 
728  // if (bc.bcType == "Specifiede")
729  if (bc.bcType == "Specifiedkandepsilon")
730  {
731  for(int f=0; f<nFaces; f++)
732  {
733  if (massFlux[f] > 0.)
734  gbc.applyExtrapolationBC(f);
735 
736  else
737  gbc.applyDirichletBC(f,be[f]);
738 
739  }
740 
741  }
742 
743  else if((bc.bcType == "Wall"))
744  {
745  for ( int f=0; f<nFaces; f++)
746  {
747 
748  const int c0 = faceCells(f,0);
749  // const int c1 = faceCells(f,1);
750  // T vol0 = cellVolume[c0];
751  // T vol1 = cellVolume[c1];
752  VectorT3 ds;
753  VectorT3 n = faceArea[f]/faceAreaMag[f];
754  /*
755  if (vol1==0)
756  ds =faceCentroid[f] - cellCentroid[c0];
757  else
758  ds = cellCentroid[c1]-faceCentroid[f];
759 
760  */
761  ds =faceCentroid[f] - cellCentroid[c0];
762  const T yp = ds[0]*n[0] + ds[1]*n[1] + ds[2]*n[2];
763  rCell[0] = T(0);
764  eCell[c0] = (pow(kCell[c0],1.5)*pow(cmu,0.75))/(vonk*yp);
765  matrix.setDirichlet(c0);
766 
767 
768  }
769 
770  }
771  else if ((bc.bcType == "PressureBoundary"))
772  {
773  for(int f=0; f<nFaces; f++)
774  {
775  if (massFlux[f] > 0.)
776  {
777  gbc.applyExtrapolationBC(f);
778  }
779  else
780  {
781  gbc.applyDirichletBC(f,be[f]);
782  }
783  }
784  }
785 
786  else if ((bc.bcType == "Symmetry"))
787  {
788  gbc.applySymmetryBC();
789  }
790  else
791  throw CException(bc.bcType + " not implemented for KeModel");
792  }
793 
794  foreach(const FaceGroupPtr fgPtr, mesh.getInterfaceGroups())
795  {
796  const FaceGroup& fg = *fgPtr;
797  const StorageSite& faces = fg.site;
798  GenericBCS<T,T,T> gbc(faces,mesh,
799  _geomFields,
800  _keFields.dissipation,
801  _keFields.eFlux,
802  lse.getMatrix(), lse.getX(), lse.getB());
803 
804  gbc.applyInterfaceBC();
805 
806 
807  }
808  }
809  DiscrList discretizations3;
810  shared_ptr<Discretization>
811  ud1(new Underrelaxer<T,T,T>
812  (_meshes,_keFields.dissipation,
813  _options["dissipationURF"]));
814 
815  discretizations3.push_back(ud1);
816 
817  linearizer.linearize(discretizations3,_meshes,lse.getMatrix(),
818  lse.getX(), lse.getB());
819 
820 }
821 
822 
823 
824  void getViscosity(const Mesh& mesh)
825  {
826  const StorageSite& cells = mesh.getCells();
827 
828 //turbulent viscosity
829  TArray& muCell =
830  dynamic_cast<TArray&>(_flowFields.eddyviscosity[cells]);
831 
832 //laminar viscosity
833  TArray& lmuCell =
834  dynamic_cast<TArray&>(_flowFields.viscosity[cells]);
835 
836 //total viscosity
837  TArray& tmuCell =
838  dynamic_cast<TArray&>(_flowFields.totalviscosity[cells]);
839 
840  const TArray & rhoCell =
841  dynamic_cast<const TArray&>(_flowFields.density[cells]);
842 
843  const TArray& eCell =
844  dynamic_cast<const TArray&>(_keFields.dissipation[cells]);
845 
846  const TArray& kCell =
847  dynamic_cast<const TArray&>(_keFields.energy[cells]);
848 
849  TArray& c1Cell =
850  dynamic_cast<TArray&>(_keFields.c1[cells]);
851 
852  TArray& c2Cell =
853  dynamic_cast<TArray&>(_keFields.c2[cells]);
854 
855 
856 
857  const int nCells = cells.getCount();
858  T two(2.0);
859  T cmu = _options.cmu;
860  T sigmak = _options.sigmak;
861  T sigmae = _options.sigmae;
862  for(int c=0; c<nCells; c++)
863  {
864  //cout << "c2" << c2Cell[c] << endl;
865  muCell[c] = (cmu*pow(kCell[c],two)*rhoCell[c])/eCell[c];
866  c1Cell[c] = muCell[c]/sigmak;
867  c2Cell[c] = muCell[c]/sigmae;
868  tmuCell[c] = muCell[c] + lmuCell[c];
869 
870  }
871 
872  }
873 
874 
875  void advance(const int niter)
876  {
877  for(int n=0; n<niter; n++)
878  {
879 
880  {
881  LinearSystem lsk;
882  initLinearizationk(lsk);
883 
884  lsk.initAssembly();
885 
886  linearizeenergy(lsk);
887 
888  lsk.initSolve();
889 
890  MFRPtr rNorm(_options.getLinearSolver().solve(lsk));
891 
892 
893  if (!_initialNormk) _initialNormk = rNorm;
894 
895  MFRPtr normRatio((*rNorm)/(*_initialNormk));
896 
897  if (_options.printNormalizedResiduals)
898  cout << _niters << ": " << *normRatio << endl;
899  else
900  cout << _niters << ": " << *rNorm << endl;
901 
902 
903  _options.getLinearSolver().cleanup();
904 
905  lsk.postSolve();
906  lsk.updateSolution();
907 
908 
909  _niters++;
910 
911  if (*rNorm < _options.absoluteTolerance ||
912  *normRatio < _options.relativeTolerance)
913  break;
914  }
915 
916  {
917  LinearSystem lse;
918  initLinearization(lse);
919 
920  lse.initAssembly();
921 
922  linearizedissipation(lse);
923 
924  lse.initSolve();
925 
926  MFRPtr rNorm(_options.getLinearSolver().solve(lse));
927 
928  if (!_initialNorm) _initialNorm = rNorm;
929 
930  MFRPtr normRatio((*rNorm)/(*_initialNorm));
931 
932  cout << _niters << ": " << *rNorm << endl;
933 
934 
935  _options.getLinearSolver().cleanup();
936 
937  lse.postSolve();
938  lse.updateSolution();
939 
940  _niters++;
941  if (*rNorm < _options.absoluteTolerance ||
942  *normRatio < _options.relativeTolerance)
943  break;
944  }
945 
946  const int numMeshes = _meshes.size();
947  for (int n=0; n<numMeshes; n++)
948  {
949  const Mesh& mesh = *_meshes[n];
950 
951  getViscosity(mesh);
952  }
953 
954  }
955 
956  }
957 
958  void printBCs()
959  {
960  foreach(typename KeBCMap::value_type& pos, _bcMap)
961  {
962  cout << "Face Group " << pos.first << ":" << endl;
963  cout << " bc type " << pos.second->bcType << endl;
964  foreach(typename KeBC<T>::value_type& vp, *pos.second)
965  {
966  cout << " " << vp.first << " " << vp.second.constant << endl;
967  }
968  }
969  }
970 
971 private:
976 
978 
981  //GradientModel<VectorT3> _velocityGradientModel;
986  int _niters;
987 };
988 
989 template<class T>
990 KeModel<T>::KeModel(const GeomFields& geomFields,
991  KeFields& keFields,
992  FlowFields& flowFields,
993  const MeshList& meshes) :
994  Model(meshes),
995  _impl(new Impl(geomFields,keFields,flowFields,meshes))
996 {
997  logCtor();
998 }
999 
1000 
1001 template<class T>
1003 {
1004  logDtor();
1005 }
1006 
1007 template<class T>
1008 void
1010 {
1011  _impl->init();
1012 }
1013 
1014 template<class T>
1015 typename KeModel<T>::KeBCMap&
1016 KeModel<T>::getBCMap() {return _impl->getBCMap();}
1017 
1018 template<class T>
1019 typename KeModel<T>::KeVCMap&
1020 KeModel<T>::getVCMap() {return _impl->getVCMap();}
1021 
1022 template<class T>
1023 KeBC<T>&
1024 KeModel<T>::getBC(const int id) {return _impl->getBC(id);}
1025 
1026 template<class T>
1028 KeModel<T>::getOptions() {return _impl->getOptions();}
1029 
1030 
1031 template<class T>
1032 void
1034 {
1035  _impl->printBCs();
1036 }
1037 
1038 template<class T>
1039 void
1040 KeModel<T>::advance(const int niter)
1041 {
1042  _impl->advance(niter);
1043 }
1044 
1045 template<class T>
1046 void
1048 {
1049  _impl->updateTimek();
1050 }
1051 
1052 template<class T>
1053 void
1055 {
1056  _impl->updateTimee();
1057 }
1058 
1059 
1060 
1061 
1062 template<class T>
1063 void
1065 {
1066  _impl->getViscosity(mesh);
1067 }
Array< T > TArray
Definition: KeModel_impl.h:37
void updateTimee()
const FaceGroupList & getBoundaryFaceGroups() const
Definition: Mesh.h:187
void initAssembly()
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
shared_ptr< FaceGroup > FaceGroupPtr
Definition: Mesh.h:46
KeBCMap & getBCMap()
Definition: KeModel_impl.h:273
void getViscosity(const Mesh &mesh)
KeBCMap _bcMap
Definition: KeModel_impl.h:977
CRMatrix< T, T, T > T_Matrix
Definition: KeModel_impl.h:46
KeModelOptions< T > & getOptions()
Definition: KeModel_impl.h:278
Definition: Mesh.h:28
Impl(const GeomFields &geomFields, KeFields &keFields, FlowFields &flowFields, const MeshList &meshes)
Definition: KeModel_impl.h:48
KeModelOptions< T > & getOptions()
Array< DGradType > DGradArray
Definition: KeModel_impl.h:45
Definition: KeBC.h:9
string bcType
Definition: KeBC.h:17
KeBC< T > & getBC(const int id)
Definition: KeModel_impl.h:276
Definition: Mesh.h:49
virtual void init()
#define logCtor()
Definition: RLogInterface.h:26
void printBCs()
void updateTimee()
Definition: KeModel_impl.h:307
string groupType
Definition: Mesh.h:42
FloatVal< T > getVal(const string varName) const
Definition: FloatVarDict.h:85
void advance(const int niter)
Definition: KeModel_impl.h:875
KeBCMap & getBCMap()
KeModelOptions< T > _options
Definition: KeModel_impl.h:980
const int id
Definition: Mesh.h:41
void updateSolution()
GradientModel< T > _dissipationGradientModel
Definition: KeModel_impl.h:983
KeVCMap & getVCMap()
Definition: KeModel_impl.h:274
pair< const Field *, const StorageSite * > ArrayIndex
Definition: MultiField.h:21
void initSolve()
void advance(const int niter)
void getViscosity(const Mesh &mesh)
Definition: KeModel_impl.h:824
vector< shared_ptr< Discretization > > DiscrList
KeBC< T > & getBC(const int id)
const MeshList _meshes
Definition: Model.h:29
const CRConnectivity & getCellCells() const
Definition: Mesh.cpp:480
Definition: Model.h:13
void initLinearization(LinearSystem &lse)
Definition: KeModel_impl.h:560
const StorageSite & getCells() const
Definition: Mesh.h:109
MFRPtr _initialNormk
Definition: KeModel_impl.h:984
void applyInterfaceBC(const int f) const
Definition: GenericBCS.h:325
void updateTimek()
Definition: KeModel_impl.h:280
std::map< int, KeVC< T > * > KeVCMap
Definition: KeModel.h:24
KeVCMap _vcMap
Definition: KeModel_impl.h:979
Gradient< T > DGradType
Definition: KeModel_impl.h:44
#define logDtor()
Definition: RLogInterface.h:33
const GeomFields & _geomFields
Definition: KeModel_impl.h:973
Definition: KeBC.h:21
virtual ~KeModel()
const CRConnectivity & getFaceCells(const StorageSite &site) const
Definition: Mesh.cpp:388
KeFields & _keFields
Definition: KeModel_impl.h:974
Definition: Array.h:14
void addMatrix(const Index &rowI, const Index &colI, shared_ptr< Matrix > m)
void linearizeenergy(LinearSystem &lsk)
Definition: KeModel_impl.h:388
string vcType
Definition: KeBC.h:32
Vector< T, 3 > VectorT3
Definition: KeModel_impl.h:38
int getCount() const
Definition: StorageSite.h:39
MultiField & getB()
Definition: LinearSystem.h:33
const MeshList _meshes
Definition: KeModel_impl.h:972
shared_ptr< MultiFieldReduction > MFRPtr
void addArray(const ArrayIndex &aIndex, shared_ptr< ArrayBase > a)
Definition: MultiField.cpp:270
Array< Gradient< VectorT3 > > VGradArray
Definition: KeModel_impl.h:41
MFRPtr _initialNorm
Definition: KeModel_impl.h:985
const FaceGroupList & getInterfaceGroups() const
Definition: Mesh.h:190
MultiField & getX()
Definition: LinearSystem.h:32
void setDirichlet(const int nr)
Definition: CRMatrix.h:887
Array< EGradType > EGradArray
Definition: KeModel_impl.h:43
Array< VectorT3 > VectorT3Array
Definition: KeModel_impl.h:39
FlowFields & _flowFields
Definition: KeModel_impl.h:975
int getID() const
Definition: Mesh.h:106
void linearizedissipation(LinearSystem &lse)
Definition: KeModel_impl.h:615
void initLinearizationk(LinearSystem &lsk)
Definition: KeModel_impl.h:333
std::map< int, KeBC< T > * > KeBCMap
Definition: KeModel.h:23
virtual void linearize(DiscrList &discretizations, const MeshList &meshes, MultiFieldMatrix &matrix, MultiField &x, MultiField &b)
Definition: Linearizer.cpp:17
void updateTimek()
KeModel(const GeomFields &geomFields, KeFields &keFields, FlowFields &flowFields, const MeshList &meshes)
Definition: KeModel_impl.h:990
MultiFieldMatrix & getMatrix()
Definition: LinearSystem.h:37
vector< Mesh * > MeshList
Definition: Mesh.h:439
KeVCMap & getVCMap()
GradientModel< T > _energyGradientModel
Definition: KeModel_impl.h:982
StorageSite site
Definition: Mesh.h:40
Gradient< T > EGradType
Definition: KeModel_impl.h:42
Gradient< VectorT3 > VGradType
Definition: KeModel_impl.h:40