45 _geomFields(geomFields),
46 _thermalFields(thermalFields),
47 _temperatureGradientModel(
_meshes,_thermalFields.temperature,
48 _thermalFields.temperatureGradient,_geomFields),
52 const int numMeshes =
_meshes.size();
53 for (
int n=0; n<numMeshes; n++)
58 _vcMap[mesh.
getID()] = vc;
70 bc->
bcType =
"SpecifiedHeatFlux";
72 else if ((fg.
groupType ==
"velocity-inlet") ||
75 bc->
bcType =
"SpecifiedTemperature";
78 throw CException(
"ThermalModel: unknown face group type "
86 const int numMeshes =
_meshes.size();
87 for (
int n=0; n<numMeshes; n++)
96 *tCell = _options[
"initialTemperature"];
97 _thermalFields.temperature.addArray(cells,tCell);
99 if(_options.transient)
101 _thermalFields.temperatureN1.addArray(cells, dynamic_pointer_cast<ArrayBase>(tCell->newCopy()));
102 if (_options.timeDiscretizationOrder > 1)
103 _thermalFields.temperatureN2.addArray(cells, dynamic_pointer_cast<ArrayBase>(tCell->newCopy()));
108 *condCell = vc[
"thermalConductivity"];
109 _thermalFields.conductivity.addArray(cells,condCell);
114 _thermalFields.source.addArray(cells,sCell);
119 _thermalFields.zero.addArray(cells,zeroCell);
124 _thermalFields.one.addArray(cells,oneCell);
128 *cp = vc[
"density"] * vc[
"specificHeat"];
129 _thermalFields.specificHeat.addArray(cells, cp);
134 _thermalFields.temperatureGradient.addArray(cells,gradT);
141 _thermalFields.convectionFlux.addArray(allFaces,convFlux);
152 _thermalFields.heatFlux.addArray(faces,fluxFace);
163 _thermalFields.heatFlux.addArray(faces,fluxFace);
169 _thermalFields.conductivity.syncLocal();
183 const int numMeshes =
_meshes.size();
184 for (
int n=0; n<numMeshes; n++)
191 ls.
getX().
addArray(tIndex,_thermalFields.temperature.getArrayPtr(cells));
205 ls.
getX().
addArray(fIndex,_thermalFields.heatFlux.getArrayPtr(faces));
222 ls.
getX().
addArray(fIndex,_thermalFields.heatFlux.getArrayPtr(faces));
238 _temperatureGradientModel.compute();
242 shared_ptr<Discretization>
245 _thermalFields.temperature,
246 _thermalFields.conductivity,
247 _thermalFields.temperatureGradient));
248 discretizations.push_back(dd);
250 shared_ptr<Discretization>
253 _thermalFields.temperature,
254 _thermalFields.convectionFlux,
256 _thermalFields.temperatureGradient,
257 _options.useCentralDifference));
258 discretizations.push_back(cd);
261 shared_ptr<Discretization>
265 _thermalFields.temperature,
266 _thermalFields.source));
267 discretizations.push_back(sd);
269 if (_options.transient)
271 shared_ptr<Discretization>
274 _thermalFields.temperature,
275 _thermalFields.temperatureN1,
276 _thermalFields.temperatureN2,
277 _thermalFields.specificHeat,
278 _options[
"timeStep"]));
279 discretizations.push_back(td);
282 shared_ptr<Discretization>
284 (
_meshes,_geomFields,_thermalFields.temperature));
286 discretizations.push_back(ibm);
294 const int numMeshes =
_meshes.size();
295 for (
int n=0; n<numMeshes; n++)
309 _thermalFields.temperature,
310 _thermalFields.heatFlux,
313 if (bc.
bcType ==
"SpecifiedTemperature")
316 bT(bc.
getVal(
"specifiedTemperature"),faces);
317 if (_thermalFields.convectionFlux.hasArray(faces))
319 const TArray& convectingFlux =
320 dynamic_cast<const TArray&
>
321 (_thermalFields.convectionFlux[faces]);
322 const int nFaces = faces.
getCount();
324 for(
int f=0; f<nFaces; f++)
326 if (convectingFlux[f] > 0.)
328 gbc.applyExtrapolationBC(f);
332 gbc.applyDirichletBC(f,bT[f]);
337 gbc.applyDirichletBC(bT);
339 else if (bc.
bcType ==
"SpecifiedHeatFlux")
342 bHeatFlux(bc.
getVal(
"specifiedHeatFlux"),faces);
344 const int nFaces = faces.
getCount();
346 for(
int f=0; f<nFaces; f++)
348 gbc.applyNeumannBC(f, bHeatFlux[f]);
351 else if (bc.
bcType ==
"Symmetry")
354 gbc.applyNeumannBC(zeroFlux);
356 else if (bc.
bcType ==
"Convective")
360 const int nFaces = faces.
getCount();
361 for(
int f=0; f<nFaces; f++)
362 gbc.applyConvectionBC(f, hCoeff[f], Xinf[f]);
364 else if (bc.
bcType ==
"Radiative")
368 const int nFaces = faces.
getCount();
369 for(
int f=0; f<nFaces; f++)
370 gbc.applyRadiationBC(f, emissivity[f], Xinf[f]);
372 else if (bc.
bcType ==
"Mixed")
377 const int nFaces = faces.
getCount();
378 for(
int f=0; f<nFaces; f++)
379 gbc.applyMixedBC(f, hCoeff[f], emissivity[f], Xinf[f]);
391 _thermalFields.temperature,
392 _thermalFields.heatFlux,
407 if (fg.
id == faceGroupId)
410 const int nFaces = faces.
getCount();
412 dynamic_cast<const TArray&
>(_thermalFields.heatFlux[faces]);
413 for(
int f=0; f<nFaces; f++)
419 throw CException(
"getHeatFluxIntegral: invalid faceGroupID");
426 for(
int n=0; n<niter; n++)
429 initLinearization(ls);
437 MFRPtr rNorm(_options.getLinearSolver().solve(ls));
439 if (!_initialNorm) _initialNorm = rNorm;
441 MFRPtr normRatio((*rNorm)/(*_initialNorm));
443 cout << _niters <<
": " << *rNorm << endl;
446 _options.getLinearSolver().cleanup();
452 if (*rNorm < _options.absoluteTolerance ||
453 *normRatio < _options.relativeTolerance)
460 foreach(
typename ThermalBCMap::value_type& pos, _bcMap)
462 cout <<
"Face Group " << pos.first <<
":" << endl;
463 cout <<
" bc type " << pos.second->bcType << endl;
466 cout <<
" " << vp.first <<
" " << vp.second.constant << endl;
474 const int numMeshes =
_meshes.size();
475 for (
int n=0; n<numMeshes; n++) {
482 dynamic_cast<TArray&
>(_thermalFields.temperature[cells]);
484 dynamic_cast<TArray&
>(_thermalFields.temperatureN1[cells]);
486 if (_options.timeDiscretizationOrder > 1)
489 dynamic_cast<TArray&
>(_thermalFields.temperatureN2[cells]);
490 temperatureN2 = temperatureN1;
492 temperatureN1 = temperature;
497 #if !(defined(USING_ATYPE_TANGENT) || defined(USING_ATYPE_PC))
502 initLinearization(ls);
512 for (
unsigned int id = 0;
id <
_meshes.size();
id++ ){
532 int nCoeffs = nCells;
534 for(
int i=0; i<nCells; i++)
535 for(
int jp=row[i]; jp<row[i+1]; jp++)
537 const int j = col[jp];
538 if (j<nCells) nCoeffs++;
542 string matFileName = fileBase +
"_mesh" + ss.str() +
".mat";
545 FILE *matFile = fopen(matFileName.c_str(),
"wb");
547 fprintf(matFile,
"%%%%MatrixMarket matrix coordinate real general\n");
548 fprintf(matFile,
"%d %d %d\n", nCells,nCells,nCoeffs);
550 for(
int i=0; i<nCells; i++)
552 fprintf(matFile,
"%d %d %lf\n", i+1, i+1, tDiag[i]);
553 for(
int jp=row[i]; jp<row[i+1]; jp++)
555 const int j = col[jp];
557 fprintf(matFile,
"%d %d %lf\n", i+1, j+1, tCoeff[jp]);
563 string rhsFileName = fileBase +
".rhs";
564 FILE *rhsFile = fopen(rhsFileName.c_str(),
"wb");
566 for(
int i=0; i<nCells; i++)
567 fprintf(rhsFile,
"%lf\n",-rCell[i]);
580 dynamic_cast<const TArray&
>(_thermalFields.temperature[particles]);
582 const int numMeshes =
_meshes.size();
583 for (
int n=0; n<numMeshes; n++)
592 dynamic_cast<const IMatrix&
>
593 (*_geomFields._interpolationMatrices[key1]);
597 dynamic_cast<const IMatrix&
>
598 (*_geomFields._interpolationMatrices[key2]);
603 dynamic_cast<const TArray&
>(_thermalFields.temperature[cells]);
608 mIC.multiplyAndAdd(*ibT,cT);
609 mIP.multiplyAndAdd(*ibT,pT);
610 _thermalFields.temperature.addArray(ibFaces,ibT);
635 _impl(new
Impl(geomFields,thermalFields,meshes))
682 _impl->advance(niter);
689 _impl->computeIBFaceTemperature(particles);
692 #if !(defined(USING_ATYPE_TANGENT) || defined(USING_ATYPE_PC))
698 _impl->dumpMatrix(fileBase);
706 return _impl->getHeatFluxIntegral(mesh, faceGroupId);
Array< Gradient< T > > TGradArray
const FaceGroupList & getBoundaryFaceGroups() const
const Array< int > & getCol() const
void linearize(LinearSystem &ls)
const Array< int > & getRow() const
void advance(const int niter)
Matrix & getMatrix(const Index &rowIndex, const Index &colIndex)
shared_ptr< FaceGroup > FaceGroupPtr
const StorageSite & getIBFaces() const
T getHeatFluxIntegral(const Mesh &mesh, const int faceGroupId)
ThermalBCMap & getBCMap()
ThermalFields & _thermalFields
ThermalModelOptions< T > & getOptions()
ThermalModelOptions< T > & getOptions()
ThermalModel(const GeomFields &geomFields, ThermalFields &thermalFields, const MeshList &meshes)
void advance(const int niter)
void initLinearization(LinearSystem &ls)
Array< Diag > & getDiag()
ThermalVCMap & getVCMap()
void dumpMatrix(const string fileBase)
void computeIBFaceTemperature(const StorageSite &particles)
std::map< int, ThermalBC< T > * > ThermalBCMap
void dumpMatrix(const string fileBase)
virtual const CRConnectivity & getConnectivity() const
FloatVal< T > getVal(const string varName) const
std::map< int, ThermalVC< T > * > ThermalVCMap
Impl(const GeomFields &geomFields, ThermalFields &thermalFields, const MeshList &meshes)
GradientModel< T > _temperatureGradientModel
Array< OffDiag > & getOffDiag()
ThermalVCMap & getVCMap()
pair< const Field *, const StorageSite * > ArrayIndex
ThermalBCMap & getBCMap()
Array< VectorT3 > VectorT3Array
vector< shared_ptr< Discretization > > DiscrList
const StorageSite & getFaces() const
const CRConnectivity & getCellCells() const
const StorageSite & getCells() const
const GeomFields & _geomFields
void applyInterfaceBC(const int f) const
CRMatrix< T, T, T > T_Matrix
int getCountLevel1() const
ThermalModelOptions< T > _options
const CRConnectivity & getFaceCells(const StorageSite &site) const
void addMatrix(const Index &rowI, const Index &colI, shared_ptr< Matrix > m)
void computeIBFaceTemperature(const StorageSite &particles)
T getHeatFluxIntegral(const Mesh &mesh, const int faceGroupId)
shared_ptr< MultiFieldReduction > MFRPtr
void addArray(const ArrayIndex &aIndex, shared_ptr< ArrayBase > a)
const FaceGroupList & getInterfaceGroups() const
ThermalBC< T > & getBC(const int id)
ThermalBC< T > & getBC(const int id)
virtual void linearize(DiscrList &discretizations, const MeshList &meshes, MultiFieldMatrix &matrix, MultiField &x, MultiField &b)
pair< const StorageSite *, const StorageSite * > SSPair
MultiFieldMatrix & getMatrix()
vector< Mesh * > MeshList