53 _geomFields(geomFields),
55 _flowFields(flowFields),
58 _energyGradientModel(
_meshes,_keFields.energy,
59 _keFields.energyGradient,_geomFields),
60 _dissipationGradientModel(
_meshes,_keFields.dissipation,
61 _keFields.dissipationGradient,_geomFields),
66 const int numMeshes =
_meshes.size();
67 for (
int n=0; n<numMeshes; n++)
77 _vcMap[mesh.
getID()] = vc;
91 else if ((fg.
groupType ==
"velocity-inlet"))
93 bc->
bcType =
"Specifiedkandepsilon";
100 else if ((fg.
groupType ==
"pressure-inlet") ||
103 bc->
bcType =
"PressureBoundary";
107 throw CException(
"KeModel: unknown face group type "
116 const int numMeshes =
_meshes.size();
117 for (
int n=0; n<numMeshes; n++)
127 *kCell = vc[
"InitialEnergy"];
128 _keFields.energy.addArray(cells,kCell);
132 *eCell = vc[
"InitialDissipation"];
133 _keFields.dissipation.addArray(cells,eCell);
137 *sourcekCell = T(1.0);
138 _keFields.sourcek.addArray(cells,sourcekCell);
141 *sourcedCell = T(1.0);
142 _keFields.sourced.addArray(cells,sourcedCell);
145 *sourcecCell = T(1.0);
146 _keFields.sourcec.addArray(cells,sourcecCell);
149 *sourcepCell = T(1.0);
150 _keFields.sourcep.addArray(cells,sourcepCell);
153 if (_options.transient)
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()));
173 _keFields.energyGradient.addArray(cells,gradE);
178 _keFields.dissipationGradient.addArray(cells,gradD);
182 *densityCell = T(1.225);
184 _flowFields.density.addArray(cells,densityCell);
189 _keFields.c1.addArray(cells,c1Cell);
194 _keFields.c2.addArray(cells,c2Cell);
205 _keFields.kFlux.addArray(faces,fluxFace);
216 _keFields.kFlux.addArray(faces,fluxFace);
229 _keFields.eFlux.addArray(faces,fluxFace);
240 _keFields.eFlux.addArray(faces,fluxFace);
247 *lmuCell = T(1.7894e-5);
249 _flowFields.viscosity.addArray(cells,lmuCell);
255 _flowFields.eddyviscosity.addArray(cells,muCell);
262 _flowFields.totalviscosity.addArray(cells,tmuCell);
282 const int numMeshes =
_meshes.size();
283 for (
int n=0; n<numMeshes; n++)
289 dynamic_cast<TArray&
>(_keFields.energy[cells]);
291 dynamic_cast<TArray&
>(_keFields.energyN1[cells]);
293 if (_options.timeDiscretizationOrder > 1)
296 dynamic_cast<TArray&
>(_keFields.energyN2[cells]);
309 const int numMeshes =
_meshes.size();
310 for (
int n=0; n<numMeshes; n++)
316 dynamic_cast<TArray&
>(_keFields.dissipation[cells]);
318 dynamic_cast<TArray&
>(_keFields.dissipationN1[cells]);
320 if (_options.timeDiscretizationOrder > 1)
323 dynamic_cast<TArray&
>(_keFields.dissipationN2[cells]);
335 const int numMeshes =
_meshes.size();
336 for (
int n=0; n<numMeshes; n++)
343 lsk.
getX().
addArray(kIndex,_keFields.energy.getArrayPtr(cells));
357 lsk.
getX().
addArray(fIndex,_keFields.kFlux.getArrayPtr(faces));
374 lsk.
getX().
addArray(fIndex,_keFields.kFlux.getArrayPtr(faces));
391 _energyGradientModel.compute();
394 if (_options.transient)
397 shared_ptr<Discretization>
404 _options[
"timeStep"]));
406 discretizations.push_back(td);
409 shared_ptr<Discretization>
414 _keFields.energyGradient));
415 discretizations.push_back(dd);
417 shared_ptr<Discretization>
421 _flowFields.massFlux,
422 _flowFields.continuityResidual,
423 _keFields.energyGradient,
424 _options.useCentralDifference));
425 discretizations.push_back(cd);
428 shared_ptr<Discretization>
433 _flowFields.velocity,
434 _flowFields.eddyviscosity,
435 _keFields.dissipation,
438 _flowFields.velocityGradient));
439 discretizations.push_back(sd);
441 shared_ptr<Discretization>
443 (
_meshes,_geomFields,_keFields.energy));
445 discretizations.push_back(ene);
452 const int numMeshes =
_meshes.size();
453 for (
int n=0; n<numMeshes; n++)
470 bk(bc.
getVal(
"Specifiedk"),faces);
471 TArray& massFlux =
dynamic_cast<TArray&
>(_flowFields.massFlux[faces]);
472 const int nFaces = faces.
getCount();
477 if ( bc.
bcType ==
"Specifiedkandepsilon")
479 for(
int f=0; f<nFaces; f++)
484 if (massFlux[f] > 0.)
486 gbc.applyExtrapolationBC(f);
490 gbc.applyDirichletBC(f,bk[f]);
496 else if ((bc.
bcType ==
"Wall"))
498 for(
int f=0; f<nFaces; f++)
501 gbc.applyNeumannBC(f,0);
504 else if ((bc.
bcType ==
"PressureBoundary"))
506 for(
int f=0; f<nFaces; f++)
509 if (massFlux[f] > 0.)
511 gbc.applyExtrapolationBC(f);
515 gbc.applyDirichletBC(f,bk[f]);
523 else if ((bc.
bcType ==
"Symmetry"))
525 cout <<
"nfaces" << nFaces << endl;
527 gbc.applySymmetryBC();
548 shared_ptr<Discretization>
551 _options[
"energyURF"]));
553 discretizations2.push_back(ud);
562 const int numMeshes =
_meshes.size();
563 for (
int n=0; n<numMeshes; n++)
570 lse.
getX().
addArray(eIndex,_keFields.dissipation.getArrayPtr(cells));
584 lse.
getX().
addArray(fIndex,_keFields.eFlux.getArrayPtr(faces));
600 lse.
getX().
addArray(fIndex,_keFields.eFlux.getArrayPtr(faces));
618 _dissipationGradientModel.compute();
621 if (_options.transient)
624 shared_ptr<Discretization>
627 _keFields.dissipation,
628 _keFields.dissipationN1,
629 _keFields.dissipationN2,
631 _options[
"timeStep"]));
632 discretizations1.push_back(td);
635 shared_ptr<Discretization>
638 _keFields.dissipation,
640 _keFields.dissipationGradient));
641 discretizations1.push_back(dd);
643 shared_ptr<Discretization>
646 _keFields.dissipation,
647 _flowFields.massFlux,
648 _flowFields.continuityResidual,
649 _keFields.dissipationGradient,
650 _options.useCentralDifference));
651 discretizations1.push_back(cd);
654 shared_ptr<Discretization>
658 _keFields.dissipation,
659 _flowFields.velocity,
660 _flowFields.eddyviscosity,
666 _flowFields.velocityGradient));
667 discretizations1.push_back(sd);
669 shared_ptr<Discretization>
671 (
_meshes,_geomFields,_keFields.dissipation));
673 discretizations1.push_back(dis);
679 const int numMeshes =
_meshes.size();
680 for (
int n=0; n<numMeshes; n++)
695 _keFields.dissipation,
700 be(bc.
getVal(
"specifiede"),faces);
710 const TArray& faceAreaMag =
dynamic_cast<const TArray &
>(_geomFields.areaMag[faces]);
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;
725 TArray& massFlux =
dynamic_cast<TArray&
>(_flowFields.massFlux[faces]);
726 const int nFaces = faces.
getCount();
729 if (bc.
bcType ==
"Specifiedkandepsilon")
731 for(
int f=0; f<nFaces; f++)
733 if (massFlux[f] > 0.)
734 gbc.applyExtrapolationBC(f);
737 gbc.applyDirichletBC(f,be[f]);
743 else if((bc.
bcType ==
"Wall"))
745 for (
int f=0; f<nFaces; f++)
748 const int c0 = faceCells(f,0);
753 VectorT3 n = faceArea[f]/faceAreaMag[f];
761 ds =faceCentroid[f] - cellCentroid[c0];
762 const T yp = ds[0]*n[0] + ds[1]*n[1] + ds[2]*n[2];
764 eCell[c0] = (pow(kCell[c0],1.5)*pow(cmu,0.75))/(vonk*yp);
771 else if ((bc.
bcType ==
"PressureBoundary"))
773 for(
int f=0; f<nFaces; f++)
775 if (massFlux[f] > 0.)
777 gbc.applyExtrapolationBC(f);
781 gbc.applyDirichletBC(f,be[f]);
786 else if ((bc.
bcType ==
"Symmetry"))
788 gbc.applySymmetryBC();
800 _keFields.dissipation,
810 shared_ptr<Discretization>
812 (
_meshes,_keFields.dissipation,
813 _options[
"dissipationURF"]));
815 discretizations3.push_back(ud1);
830 dynamic_cast<TArray&
>(_flowFields.eddyviscosity[cells]);
834 dynamic_cast<TArray&
>(_flowFields.viscosity[cells]);
838 dynamic_cast<TArray&
>(_flowFields.totalviscosity[cells]);
841 dynamic_cast<const TArray&
>(_flowFields.density[cells]);
844 dynamic_cast<const TArray&
>(_keFields.dissipation[cells]);
847 dynamic_cast<const TArray&
>(_keFields.energy[cells]);
850 dynamic_cast<TArray&
>(_keFields.c1[cells]);
853 dynamic_cast<TArray&
>(_keFields.c2[cells]);
857 const int nCells = cells.
getCount();
859 T cmu = _options.cmu;
860 T sigmak = _options.sigmak;
861 T sigmae = _options.sigmae;
862 for(
int c=0; c<nCells; c++)
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];
877 for(
int n=0; n<niter; n++)
882 initLinearizationk(lsk);
886 linearizeenergy(lsk);
890 MFRPtr rNorm(_options.getLinearSolver().solve(lsk));
893 if (!_initialNormk) _initialNormk = rNorm;
895 MFRPtr normRatio((*rNorm)/(*_initialNormk));
897 if (_options.printNormalizedResiduals)
898 cout << _niters <<
": " << *normRatio << endl;
900 cout << _niters <<
": " << *rNorm << endl;
903 _options.getLinearSolver().cleanup();
911 if (*rNorm < _options.absoluteTolerance ||
912 *normRatio < _options.relativeTolerance)
918 initLinearization(lse);
922 linearizedissipation(lse);
926 MFRPtr rNorm(_options.getLinearSolver().solve(lse));
928 if (!_initialNorm) _initialNorm = rNorm;
930 MFRPtr normRatio((*rNorm)/(*_initialNorm));
932 cout << _niters <<
": " << *rNorm << endl;
935 _options.getLinearSolver().cleanup();
941 if (*rNorm < _options.absoluteTolerance ||
942 *normRatio < _options.relativeTolerance)
946 const int numMeshes =
_meshes.size();
947 for (
int n=0; n<numMeshes; n++)
960 foreach(
typename KeBCMap::value_type& pos, _bcMap)
962 cout <<
"Face Group " << pos.first <<
":" << endl;
963 cout <<
" bc type " << pos.second->bcType << endl;
966 cout <<
" " << vp.first <<
" " << vp.second.constant << endl;
995 _impl(new
Impl(geomFields,keFields,flowFields,meshes))
1042 _impl->advance(niter);
1049 _impl->updateTimek();
1056 _impl->updateTimee();
1066 _impl->getViscosity(mesh);
const FaceGroupList & getBoundaryFaceGroups() const
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
shared_ptr< FaceGroup > FaceGroupPtr
void getViscosity(const Mesh &mesh)
CRMatrix< T, T, T > T_Matrix
KeModelOptions< T > & getOptions()
Impl(const GeomFields &geomFields, KeFields &keFields, FlowFields &flowFields, const MeshList &meshes)
KeModelOptions< T > & getOptions()
Array< DGradType > DGradArray
KeBC< T > & getBC(const int id)
FloatVal< T > getVal(const string varName) const
void advance(const int niter)
KeModelOptions< T > _options
GradientModel< T > _dissipationGradientModel
pair< const Field *, const StorageSite * > ArrayIndex
void advance(const int niter)
void getViscosity(const Mesh &mesh)
vector< shared_ptr< Discretization > > DiscrList
KeBC< T > & getBC(const int id)
const CRConnectivity & getCellCells() const
void initLinearization(LinearSystem &lse)
const StorageSite & getCells() const
void applyInterfaceBC(const int f) const
std::map< int, KeVC< T > * > KeVCMap
const GeomFields & _geomFields
const CRConnectivity & getFaceCells(const StorageSite &site) const
void addMatrix(const Index &rowI, const Index &colI, shared_ptr< Matrix > m)
void linearizeenergy(LinearSystem &lsk)
shared_ptr< MultiFieldReduction > MFRPtr
void addArray(const ArrayIndex &aIndex, shared_ptr< ArrayBase > a)
Array< Gradient< VectorT3 > > VGradArray
const FaceGroupList & getInterfaceGroups() const
void setDirichlet(const int nr)
Array< EGradType > EGradArray
Array< VectorT3 > VectorT3Array
void linearizedissipation(LinearSystem &lse)
void initLinearizationk(LinearSystem &lsk)
std::map< int, KeBC< T > * > KeBCMap
virtual void linearize(DiscrList &discretizations, const MeshList &meshes, MultiFieldMatrix &matrix, MultiField &x, MultiField &b)
KeModel(const GeomFields &geomFields, KeFields &keFields, FlowFields &flowFields, const MeshList &meshes)
MultiFieldMatrix & getMatrix()
vector< Mesh * > MeshList
GradientModel< T > _energyGradientModel
Gradient< VectorT3 > VGradType