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 "directMappedFixedValueFvPatchField.H"
00028 #include "directMappedPatchBase.H"
00029 #include "volFields.H"
00030
00031
00032
00033 namespace Foam
00034 {
00035
00036
00037
00038 template<class Type>
00039 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00040 (
00041 const fvPatch& p,
00042 const DimensionedField<Type, volMesh>& iF
00043 )
00044 :
00045 fixedValueFvPatchField<Type>(p, iF),
00046 setAverage_(false),
00047 average_(pTraits<Type>::zero)
00048 {}
00049
00050
00051 template<class Type>
00052 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00053 (
00054 const directMappedFixedValueFvPatchField<Type>& ptf,
00055 const fvPatch& p,
00056 const DimensionedField<Type, volMesh>& iF,
00057 const fvPatchFieldMapper& mapper
00058 )
00059 :
00060 fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
00061 setAverage_(ptf.setAverage_),
00062 average_(ptf.average_)
00063 {
00064 if (!isA<directMappedPatchBase>(this->patch().patch()))
00065 {
00066 FatalErrorIn
00067 (
00068 "directMappedFixedValueFvPatchField<Type>::"
00069 "directMappedFixedValueFvPatchField\n"
00070 "(\n"
00071 " const directMappedFixedValueFvPatchField<Type>&,\n"
00072 " const fvPatch&,\n"
00073 " const Field<Type>&,\n"
00074 " const fvPatchFieldMapper&\n"
00075 ")\n"
00076 ) << "\n patch type '" << p.type()
00077 << "' not type '" << directMappedPatchBase::typeName << "'"
00078 << "\n for patch " << p.name()
00079 << " of field " << this->dimensionedInternalField().name()
00080 << " in file " << this->dimensionedInternalField().objectPath()
00081 << exit(FatalError);
00082 }
00083 }
00084
00085
00086 template<class Type>
00087 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00088 (
00089 const fvPatch& p,
00090 const DimensionedField<Type, volMesh>& iF,
00091 const dictionary& dict
00092 )
00093 :
00094 fixedValueFvPatchField<Type>(p, iF, dict),
00095 setAverage_(readBool(dict.lookup("setAverage"))),
00096 average_(pTraits<Type>(dict.lookup("average")))
00097 {
00098 if (!isA<directMappedPatchBase>(this->patch().patch()))
00099 {
00100 FatalErrorIn
00101 (
00102 "directMappedFixedValueFvPatchField<Type>::"
00103 "directMappedFixedValueFvPatchField\n"
00104 "(\n"
00105 " const fvPatch& p,\n"
00106 " const DimensionedField<Type, volMesh>& iF,\n"
00107 " const dictionary& dict\n"
00108 ")\n"
00109 ) << "\n patch type '" << p.type()
00110 << "' not type '" << directMappedPatchBase::typeName << "'"
00111 << "\n for patch " << p.name()
00112 << " of field " << this->dimensionedInternalField().name()
00113 << " in file " << this->dimensionedInternalField().objectPath()
00114 << exit(FatalError);
00115 }
00116
00117
00118 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
00119 (
00120 this->patch().patch()
00121 );
00122 (void)mpp.map().schedule();
00123 }
00124
00125
00126 template<class Type>
00127 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00128 (
00129 const directMappedFixedValueFvPatchField<Type>& ptf
00130 )
00131 :
00132 fixedValueFvPatchField<Type>(ptf),
00133 setAverage_(ptf.setAverage_),
00134 average_(ptf.average_)
00135 {}
00136
00137
00138 template<class Type>
00139 directMappedFixedValueFvPatchField<Type>::directMappedFixedValueFvPatchField
00140 (
00141 const directMappedFixedValueFvPatchField<Type>& ptf,
00142 const DimensionedField<Type, volMesh>& iF
00143 )
00144 :
00145 fixedValueFvPatchField<Type>(ptf, iF),
00146 setAverage_(ptf.setAverage_),
00147 average_(ptf.average_)
00148 {}
00149
00150
00151
00152
00153 template<class Type>
00154 void directMappedFixedValueFvPatchField<Type>::updateCoeffs()
00155 {
00156 if (this->updated())
00157 {
00158 return;
00159 }
00160
00161 typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
00162
00163
00164 const directMappedPatchBase& mpp = refCast<const directMappedPatchBase>
00165 (
00166 directMappedFixedValueFvPatchField<Type>::patch().patch()
00167 );
00168 const mapDistribute& distMap = mpp.map();
00169 const fvMesh& nbrMesh = refCast<const fvMesh>(mpp.sampleMesh());
00170 const word& fldName = this->dimensionedInternalField().name();
00171
00172
00173 Field<Type> newValues;
00174
00175 switch (mpp.mode())
00176 {
00177 case directMappedPatchBase::NEARESTCELL:
00178 {
00179 if (mpp.sameRegion())
00180 {
00181 newValues = this->internalField();
00182 }
00183 else
00184 {
00185 newValues = nbrMesh.lookupObject<fieldType>
00186 (
00187 fldName
00188 ).internalField();
00189 }
00190 mapDistribute::distribute
00191 (
00192 Pstream::defaultCommsType,
00193 distMap.schedule(),
00194 distMap.constructSize(),
00195 distMap.subMap(),
00196 distMap.constructMap(),
00197 newValues
00198 );
00199
00200 break;
00201 }
00202 case directMappedPatchBase::NEARESTPATCHFACE:
00203 {
00204 const label nbrPatchID = nbrMesh.boundaryMesh().findPatchID
00205 (
00206 mpp.samplePatch()
00207 );
00208 if (nbrPatchID < 0)
00209 {
00210 FatalErrorIn
00211 (
00212 "void directMappedFixedValueFvPatchField<Type>::"
00213 "updateCoeffs()"
00214 )<< "Unable to find sample patch " << mpp.samplePatch()
00215 << " in region " << mpp.sampleRegion()
00216 << " for patch " << this->patch().name() << nl
00217 << abort(FatalError);
00218 }
00219
00220 const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
00221 (
00222 fldName
00223 );
00224 newValues = nbrField.boundaryField()[nbrPatchID];
00225 mapDistribute::distribute
00226 (
00227 Pstream::defaultCommsType,
00228 distMap.schedule(),
00229 distMap.constructSize(),
00230 distMap.subMap(),
00231 distMap.constructMap(),
00232 newValues
00233 );
00234
00235 break;
00236 }
00237 case directMappedPatchBase::NEARESTFACE:
00238 {
00239 Field<Type> allValues(nbrMesh.nFaces(), pTraits<Type>::zero);
00240
00241 const fieldType& nbrField = nbrMesh.lookupObject<fieldType>
00242 (
00243 fldName
00244 );
00245 forAll(nbrField.boundaryField(), patchI)
00246 {
00247 const fvPatchField<Type>& pf =
00248 nbrField.boundaryField()[patchI];
00249 label faceStart = pf.patch().patch().start();
00250
00251 forAll(pf, faceI)
00252 {
00253 allValues[faceStart++] = pf[faceI];
00254 }
00255 }
00256
00257 mapDistribute::distribute
00258 (
00259 Pstream::defaultCommsType,
00260 distMap.schedule(),
00261 distMap.constructSize(),
00262 distMap.subMap(),
00263 distMap.constructMap(),
00264 allValues
00265 );
00266
00267 newValues = this->patch().patchSlice(allValues);
00268
00269 break;
00270 }
00271 default:
00272 {
00273 FatalErrorIn
00274 (
00275 "directMappedFixedValueFvPatchField<Type>::updateCoeffs()"
00276 )<< "Unknown sampling mode: " << mpp.mode()
00277 << nl << abort(FatalError);
00278 }
00279 }
00280
00281 if (setAverage_)
00282 {
00283 Type averagePsi =
00284 gSum(this->patch().magSf()*newValues)
00285 /gSum(this->patch().magSf());
00286
00287 if (mag(averagePsi)/mag(average_) > 0.5)
00288 {
00289 newValues *= mag(average_)/mag(averagePsi);
00290 }
00291 else
00292 {
00293 newValues += (average_ - averagePsi);
00294 }
00295 }
00296
00297 this->operator==(newValues);
00298
00299 if (debug)
00300 {
00301 Info<< "directMapped on field:" << fldName
00302 << " patch:" << this->patch().name()
00303 << " avg:" << gAverage(*this)
00304 << " min:" << gMin(*this)
00305 << " max:" << gMax(*this)
00306 << endl;
00307 }
00308
00309 fixedValueFvPatchField<Type>::updateCoeffs();
00310 }
00311
00312
00313 template<class Type>
00314 void directMappedFixedValueFvPatchField<Type>::write(Ostream& os) const
00315 {
00316 fvPatchField<Type>::write(os);
00317 os.writeKeyword("setAverage") << setAverage_ << token::END_STATEMENT << nl;
00318 os.writeKeyword("average") << average_ << token::END_STATEMENT << nl;
00319 this->writeEntry("value", os);
00320 }
00321
00322
00323
00324
00325 }
00326
00327