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 #include "fvMesh.H"
00027 #include <OpenFOAM/Time.H>
00028 #include <finiteVolume/volFields.H>
00029 #include <finiteVolume/surfaceFields.H>
00030 #include <finiteVolume/slicedVolFields.H>
00031 #include <finiteVolume/slicedSurfaceFields.H>
00032 #include <OpenFOAM/SubField.H>
00033 #include <finiteVolume/cyclicFvPatchFields.H>
00034
00035
00036
00037 namespace Foam
00038 {
00039
00040
00041
00042 void fvMesh::makeSf() const
00043 {
00044 if (debug)
00045 {
00046 Info<< "void fvMesh::makeSf() : "
00047 << "assembling face areas"
00048 << endl;
00049 }
00050
00051
00052
00053 if (SfPtr_)
00054 {
00055 FatalErrorIn("fvMesh::makeSf()")
00056 << "face areas already exist"
00057 << abort(FatalError);
00058 }
00059
00060 SfPtr_ = new slicedSurfaceVectorField
00061 (
00062 IOobject
00063 (
00064 "S",
00065 pointsInstance(),
00066 meshSubDir,
00067 *this,
00068 IOobject::NO_READ,
00069 IOobject::NO_WRITE,
00070 false
00071 ),
00072 *this,
00073 dimArea,
00074 faceAreas()
00075 );
00076 }
00077
00078
00079 void fvMesh::makeMagSf() const
00080 {
00081 if (debug)
00082 {
00083 Info<< "void fvMesh::makeMagSf() : "
00084 << "assembling mag face areas"
00085 << endl;
00086 }
00087
00088
00089
00090 if (magSfPtr_)
00091 {
00092 FatalErrorIn("void fvMesh::makeMagSf()")
00093 << "mag face areas already exist"
00094 << abort(FatalError);
00095 }
00096
00097
00098
00099
00100 magSfPtr_ = new surfaceScalarField
00101 (
00102 IOobject
00103 (
00104 "magSf",
00105 pointsInstance(),
00106 meshSubDir,
00107 *this,
00108 IOobject::NO_READ,
00109 IOobject::NO_WRITE,
00110 false
00111 ),
00112 mag(Sf()) + dimensionedScalar("vs", dimArea, VSMALL)
00113 );
00114 }
00115
00116
00117 void fvMesh::makeC() const
00118 {
00119 if (debug)
00120 {
00121 Info<< "void fvMesh::makeC() : "
00122 << "assembling cell centres"
00123 << endl;
00124 }
00125
00126
00127
00128 if (CPtr_)
00129 {
00130 FatalErrorIn("fvMesh::makeC()")
00131 << "cell centres already exist"
00132 << abort(FatalError);
00133 }
00134
00135 CPtr_ = new slicedVolVectorField
00136 (
00137 IOobject
00138 (
00139 "C",
00140 pointsInstance(),
00141 meshSubDir,
00142 *this,
00143 IOobject::NO_READ,
00144 IOobject::NO_WRITE,
00145 false
00146 ),
00147 *this,
00148 dimLength,
00149 cellCentres(),
00150 faceCentres()
00151 );
00152
00153
00154
00155
00156
00157 slicedVolVectorField& C = *CPtr_;
00158
00159 forAll(C.boundaryField(), patchi)
00160 {
00161 if (isA<cyclicFvPatchVectorField>(C.boundaryField()[patchi]))
00162 {
00163
00164 C.boundaryField()[patchi] == static_cast<const vectorField&>
00165 (
00166 static_cast<const List<vector>&>
00167 (
00168 boundary_[patchi].patchSlice(faceCentres())
00169 )
00170 );
00171 }
00172 }
00173 }
00174
00175
00176 void fvMesh::makeCf() const
00177 {
00178 if (debug)
00179 {
00180 Info<< "void fvMesh::makeCf() : "
00181 << "assembling face centres"
00182 << endl;
00183 }
00184
00185
00186
00187 if (CfPtr_)
00188 {
00189 FatalErrorIn("fvMesh::makeCf()")
00190 << "face centres already exist"
00191 << abort(FatalError);
00192 }
00193
00194 CfPtr_ = new slicedSurfaceVectorField
00195 (
00196 IOobject
00197 (
00198 "Cf",
00199 pointsInstance(),
00200 meshSubDir,
00201 *this,
00202 IOobject::NO_READ,
00203 IOobject::NO_WRITE,
00204 false
00205 ),
00206 *this,
00207 dimLength,
00208 faceCentres()
00209 );
00210 }
00211
00212
00213
00214
00215 const volScalarField::DimensionedInternalField& fvMesh::V() const
00216 {
00217 if (!VPtr_)
00218 {
00219 VPtr_ = new slicedVolScalarField::DimensionedInternalField
00220 (
00221 IOobject
00222 (
00223 "V",
00224 time().timeName(),
00225 *this,
00226 IOobject::NO_READ,
00227 IOobject::NO_WRITE
00228 ),
00229 *this,
00230 dimVolume,
00231 cellVolumes()
00232 );
00233 }
00234
00235 return *static_cast<slicedVolScalarField::DimensionedInternalField*>(VPtr_);
00236 }
00237
00238
00239 const volScalarField::DimensionedInternalField& fvMesh::V0() const
00240 {
00241 if (!V0Ptr_)
00242 {
00243 FatalErrorIn("fvMesh::V0() const")
00244 << "V0 is not available"
00245 << abort(FatalError);
00246 }
00247
00248 return *V0Ptr_;
00249 }
00250
00251
00252 volScalarField::DimensionedInternalField& fvMesh::setV0()
00253 {
00254 if (!V0Ptr_)
00255 {
00256 FatalErrorIn("fvMesh::setV0()")
00257 << "V0 is not available"
00258 << abort(FatalError);
00259 }
00260
00261 return *V0Ptr_;
00262 }
00263
00264
00265 const volScalarField::DimensionedInternalField& fvMesh::V00() const
00266 {
00267 if (!V00Ptr_)
00268 {
00269 V00Ptr_ = new DimensionedField<scalar, volMesh>
00270 (
00271 IOobject
00272 (
00273 "V00",
00274 time().timeName(),
00275 *this,
00276 IOobject::NO_READ,
00277 IOobject::NO_WRITE
00278 ),
00279 V0()
00280 );
00281
00282
00283 V0Ptr_->writeOpt() = IOobject::AUTO_WRITE;
00284 }
00285
00286 return *V00Ptr_;
00287 }
00288
00289
00290 tmp<volScalarField::DimensionedInternalField> fvMesh::Vsc() const
00291 {
00292 if (moving() && time().subCycling())
00293 {
00294 const TimeState& ts = time();
00295 const TimeState& ts0 = time().prevTimeState();
00296
00297 scalar tFrac =
00298 (
00299 ts.value() - (ts0.value() - ts0.deltaTValue())
00300 )/ts0.deltaTValue();
00301
00302 if (tFrac < (1 - SMALL))
00303 {
00304 return V0() + tFrac*(V() - V0());
00305 }
00306 else
00307 {
00308 return V();
00309 }
00310 }
00311 else
00312 {
00313 return V();
00314 }
00315 }
00316
00317
00318 tmp<volScalarField::DimensionedInternalField> fvMesh::Vsc0() const
00319 {
00320 if (moving() && time().subCycling())
00321 {
00322 const TimeState& ts = time();
00323 const TimeState& ts0 = time().prevTimeState();
00324
00325 scalar t0Frac =
00326 (
00327 (ts.value() - ts.deltaTValue())
00328 - (ts0.value() - ts0.deltaTValue())
00329 )/ts0.deltaTValue();
00330
00331 if (t0Frac > SMALL)
00332 {
00333 return V0() + t0Frac*(V() - V0());
00334 }
00335 else
00336 {
00337 return V0();
00338 }
00339 }
00340 else
00341 {
00342 return V0();
00343 }
00344 }
00345
00346
00347 const surfaceVectorField& fvMesh::Sf() const
00348 {
00349 if (!SfPtr_)
00350 {
00351 makeSf();
00352 }
00353
00354 return *SfPtr_;
00355 }
00356
00357
00358 const surfaceScalarField& fvMesh::magSf() const
00359 {
00360 if (!magSfPtr_)
00361 {
00362 makeMagSf();
00363 }
00364
00365 return *magSfPtr_;
00366 }
00367
00368
00369 const volVectorField& fvMesh::C() const
00370 {
00371 if (!CPtr_)
00372 {
00373 makeC();
00374 }
00375
00376 return *CPtr_;
00377 }
00378
00379
00380 const surfaceVectorField& fvMesh::Cf() const
00381 {
00382 if (!CfPtr_)
00383 {
00384 makeCf();
00385 }
00386
00387 return *CfPtr_;
00388 }
00389
00390
00391 const surfaceScalarField& fvMesh::phi() const
00392 {
00393 if (!phiPtr_)
00394 {
00395 FatalErrorIn("fvMesh::phi()")
00396 << "mesh flux field does not exists, is the mesh actually moving?"
00397 << exit(FatalError);
00398 }
00399
00400
00401
00402 if (phiPtr_->timeIndex() != time().timeIndex())
00403 {
00404 (*phiPtr_) = dimensionedScalar("0", dimVolume/dimTime, 0.0);
00405 }
00406
00407 return *phiPtr_;
00408 }
00409
00410
00411 surfaceScalarField& fvMesh::setPhi()
00412 {
00413 if (!phiPtr_)
00414 {
00415 FatalErrorIn("fvMesh::setPhi()")
00416 << "mesh flux field does not exists, is the mesh actually moving?"
00417 << exit(FatalError);
00418 }
00419
00420 return *phiPtr_;
00421 }
00422
00423
00424
00425
00426 }
00427
00428