00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "solidWallMixedTemperatureCoupledFvPatchScalarField.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "fvPatchFieldMapper.H"
00030 #include "volFields.H"
00031 #include "directMappedPatchBase.H"
00032 #include "regionProperties.H"
00033
00034
00035
00036 bool Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::interfaceOwner
00037 (
00038 const polyMesh& nbrRegion
00039 ) const
00040 {
00041 const fvMesh& myRegion = patch().boundaryMesh().mesh();
00042
00043 const regionProperties& props =
00044 myRegion.objectRegistry::parent().lookupObject<regionProperties>
00045 (
00046 "regionProperties"
00047 );
00048
00049 label myIndex = findIndex(props.fluidRegionNames(), myRegion.name());
00050 if (myIndex == -1)
00051 {
00052 label i = findIndex(props.solidRegionNames(), myRegion.name());
00053
00054 if (i == -1)
00055 {
00056 FatalErrorIn
00057 (
00058 "solidWallMixedTemperatureCoupledFvPatchScalarField"
00059 "::interfaceOwner(const polyMesh&) const"
00060 ) << "Cannot find region " << myRegion.name()
00061 << " neither in fluids " << props.fluidRegionNames()
00062 << " nor in solids " << props.solidRegionNames()
00063 << exit(FatalError);
00064 }
00065 myIndex = props.fluidRegionNames().size() + i;
00066 }
00067 label nbrIndex = findIndex(props.fluidRegionNames(), nbrRegion.name());
00068 if (nbrIndex == -1)
00069 {
00070 label i = findIndex(props.solidRegionNames(), nbrRegion.name());
00071
00072 if (i == -1)
00073 {
00074 FatalErrorIn("coupleManager::interfaceOwner(const polyMesh&) const")
00075 << "Cannot find region " << nbrRegion.name()
00076 << " neither in fluids " << props.fluidRegionNames()
00077 << " nor in solids " << props.solidRegionNames()
00078 << exit(FatalError);
00079 }
00080 nbrIndex = props.fluidRegionNames().size() + i;
00081 }
00082
00083 return myIndex < nbrIndex;
00084 }
00085
00086
00087
00088
00089 Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::
00090 solidWallMixedTemperatureCoupledFvPatchScalarField
00091 (
00092 const fvPatch& p,
00093 const DimensionedField<scalar, volMesh>& iF
00094 )
00095 :
00096 mixedFvPatchScalarField(p, iF),
00097 neighbourFieldName_("undefined-neighbourFieldName"),
00098 KName_("undefined-K")
00099 {
00100 this->refValue() = 0.0;
00101 this->refGrad() = 0.0;
00102 this->valueFraction() = 1.0;
00103 this->fixesValue_ = true;
00104 }
00105
00106
00107 Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::
00108 solidWallMixedTemperatureCoupledFvPatchScalarField
00109 (
00110 const solidWallMixedTemperatureCoupledFvPatchScalarField& ptf,
00111 const fvPatch& p,
00112 const DimensionedField<scalar, volMesh>& iF,
00113 const fvPatchFieldMapper& mapper
00114 )
00115 :
00116 mixedFvPatchScalarField(ptf, p, iF, mapper),
00117 neighbourFieldName_(ptf.neighbourFieldName_),
00118 KName_(ptf.KName_),
00119 fixesValue_(ptf.fixesValue_)
00120 {}
00121
00122
00123 Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::
00124 solidWallMixedTemperatureCoupledFvPatchScalarField
00125 (
00126 const fvPatch& p,
00127 const DimensionedField<scalar, volMesh>& iF,
00128 const dictionary& dict
00129 )
00130 :
00131 mixedFvPatchScalarField(p, iF),
00132 neighbourFieldName_(dict.lookup("neighbourFieldName")),
00133 KName_(dict.lookup("K"))
00134 {
00135 if (!isA<directMappedPatchBase>(this->patch().patch()))
00136 {
00137 FatalErrorIn
00138 (
00139 "solidWallMixedTemperatureCoupledFvPatchScalarField::"
00140 "solidWallMixedTemperatureCoupledFvPatchScalarField\n"
00141 "(\n"
00142 " const fvPatch& p,\n"
00143 " const DimensionedField<scalar, volMesh>& iF,\n"
00144 " const dictionary& dict\n"
00145 ")\n"
00146 ) << "\n patch type '" << p.type()
00147 << "' not type '" << directMappedPatchBase::typeName << "'"
00148 << "\n for patch " << p.name()
00149 << " of field " << dimensionedInternalField().name()
00150 << " in file " << dimensionedInternalField().objectPath()
00151 << exit(FatalError);
00152 }
00153
00154 fvPatchScalarField::operator=(scalarField("value", dict, p.size()));
00155
00156 if (dict.found("refValue"))
00157 {
00158
00159 refValue() = scalarField("refValue", dict, p.size());
00160 refGrad() = scalarField("refGradient", dict, p.size());
00161 valueFraction() = scalarField("valueFraction", dict, p.size());
00162 fixesValue_ = readBool(dict.lookup("fixesValue"));
00163 }
00164 else
00165 {
00166
00167 refValue() = *this;
00168 refGrad() = 0.0;
00169 valueFraction() = 1.0;
00170 fixesValue_ = true;
00171 }
00172 }
00173
00174
00175 Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::
00176 solidWallMixedTemperatureCoupledFvPatchScalarField
00177 (
00178 const solidWallMixedTemperatureCoupledFvPatchScalarField& wtcsf,
00179 const DimensionedField<scalar, volMesh>& iF
00180 )
00181 :
00182 mixedFvPatchScalarField(wtcsf, iF),
00183 neighbourFieldName_(wtcsf.neighbourFieldName_),
00184 KName_(wtcsf.KName_),
00185 fixesValue_(wtcsf.fixesValue_)
00186 {}
00187
00188
00189
00190
00191 const Foam::fvPatchScalarField&
00192 Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::K() const
00193 {
00194 return this->patch().lookupPatchField<volScalarField, scalar>(KName_);
00195 }
00196
00197
00198 void Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::updateCoeffs()
00199 {
00200 if (updated())
00201 {
00202 return;
00203 }
00204
00205
00206 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
00207 (
00208 patch().patch()
00209 );
00210 const polyMesh& nbrMesh = mpp.sampleMesh();
00211
00212 tmp<scalarField> intFld = patchInternalField();
00213
00214 if (interfaceOwner(nbrMesh))
00215 {
00216
00217
00218
00219
00220 const mapDistribute& distMap = mpp.map();
00221 const fvPatch& nbrPatch = refCast<const fvMesh>
00222 (
00223 nbrMesh
00224 ).boundary()[mpp.samplePolyPatch().index()];
00225
00226
00227
00228
00229
00230 const solidWallMixedTemperatureCoupledFvPatchScalarField& nbrField =
00231 refCast<const solidWallMixedTemperatureCoupledFvPatchScalarField>
00232 (
00233 nbrPatch.lookupPatchField<volScalarField, scalar>
00234 (
00235 neighbourFieldName_
00236 )
00237 );
00238
00239
00240 scalarField nbrIntFld = nbrField.patchInternalField();
00241 mapDistribute::distribute
00242 (
00243 Pstream::defaultCommsType,
00244 distMap.schedule(),
00245 distMap.constructSize(),
00246 distMap.subMap(),
00247 distMap.constructMap(),
00248 nbrIntFld
00249 );
00250
00251
00252 scalarField nbrKDelta = nbrField.K()*nbrPatch.deltaCoeffs();
00253 mapDistribute::distribute
00254 (
00255 Pstream::defaultCommsType,
00256 distMap.schedule(),
00257 distMap.constructSize(),
00258 distMap.subMap(),
00259 distMap.constructMap(),
00260 nbrKDelta
00261 );
00262
00263
00264 tmp<scalarField> myKDelta = K()*patch().deltaCoeffs();
00265
00266
00267 scalarField Twall
00268 (
00269 (myKDelta()*intFld() + nbrKDelta*nbrIntFld)
00270 / (myKDelta() + nbrKDelta)
00271 );
00272
00273 fvPatchScalarField::operator=(Twall);
00274
00275 mapDistribute::distribute
00276 (
00277 Pstream::defaultCommsType,
00278 distMap.schedule(),
00279 nbrField.size(),
00280 distMap.constructMap(),
00281 distMap.subMap(),
00282 Twall
00283 );
00284 const_cast<solidWallMixedTemperatureCoupledFvPatchScalarField&>
00285 (
00286 nbrField
00287 ).fvPatchScalarField::operator=(Twall);
00288 }
00289
00290
00291
00292
00293
00294 label nFixed = 0;
00295
00296
00297 tmp<scalarField> normalGradient = (*this-intFld())*patch().deltaCoeffs();
00298
00299 if (debug)
00300 {
00301 scalar Q = gSum(K()*patch().magSf()*normalGradient());
00302
00303 Info<< "solidWallMixedTemperatureCoupledFvPatchScalarField::"
00304 << "updateCoeffs() :"
00305 << " patch:" << patch().name()
00306 << " heatFlux:" << Q
00307 << " walltemperature "
00308 << " min:" << gMin(*this)
00309 << " max:" << gMax(*this)
00310 << " avg:" << gAverage(*this)
00311 << endl;
00312 }
00313
00314 forAll(*this, i)
00315 {
00316
00317 if (normalGradient()[i] < 0.0)
00318 {
00319 this->refValue()[i] = operator[](i);
00320 this->refGrad()[i] = 0.0;
00321 this->valueFraction()[i] = 1.0;
00322 nFixed++;
00323 }
00324 else
00325 {
00326 this->refValue()[i] = 0.0;
00327 this->refGrad()[i] = normalGradient()[i];
00328 this->valueFraction()[i] = 0.0;
00329 }
00330 }
00331
00332 reduce(nFixed, sumOp<label>());
00333
00334 fixesValue_ = (nFixed > 0);
00335
00336 if (debug)
00337 {
00338 label nTotSize = returnReduce(this->size(), sumOp<label>());
00339
00340 Info<< "solidWallMixedTemperatureCoupledFvPatchScalarField::"
00341 << "updateCoeffs() :"
00342 << " patch:" << patch().name()
00343 << " out of:" << nTotSize
00344 << " fixedBC:" << nFixed
00345 << " gradient:" << nTotSize-nFixed << endl;
00346 }
00347
00348 mixedFvPatchScalarField::updateCoeffs();
00349 }
00350
00351
00352 void Foam::solidWallMixedTemperatureCoupledFvPatchScalarField::write
00353 (
00354 Ostream& os
00355 ) const
00356 {
00357 mixedFvPatchScalarField::write(os);
00358 os.writeKeyword("neighbourFieldName")<< neighbourFieldName_
00359 << token::END_STATEMENT << nl;
00360 os.writeKeyword("K") << KName_ << token::END_STATEMENT << nl;
00361 os.writeKeyword("fixesValue") << fixesValue_ << token::END_STATEMENT << nl;
00362 }
00363
00364
00365
00366
00367 namespace Foam
00368 {
00369
00370 makePatchTypeField
00371 (
00372 fvPatchScalarField,
00373 solidWallMixedTemperatureCoupledFvPatchScalarField
00374 );
00375
00376 }
00377
00378