OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

fvMeshGeometry.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "fvMesh.H"
00028 #include "Time.H"
00029 #include "volFields.H"
00030 #include "surfaceFields.H"
00031 #include "slicedVolFields.H"
00032 #include "slicedSurfaceFields.H"
00033 #include "SubField.H"
00034 #include "cyclicFvPatchFields.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 
00041 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00042 
00043 void fvMesh::makeSf() const
00044 {
00045     if (debug)
00046     {
00047         Info<< "void fvMesh::makeSf() : "
00048             << "assembling face areas"
00049             << endl;
00050     }
00051 
00052     // It is an error to attempt to recalculate
00053     // if the pointer is already set
00054     if (SfPtr_)
00055     {
00056         FatalErrorIn("fvMesh::makeSf()")
00057             << "face areas already exist"
00058             << abort(FatalError);
00059     }
00060 
00061     SfPtr_ = new slicedSurfaceVectorField
00062     (
00063         IOobject
00064         (
00065             "S",
00066             pointsInstance(),
00067             meshSubDir,
00068             *this
00069         ),
00070         *this,
00071         dimArea,
00072         faceAreas()
00073     );
00074 }
00075 
00076 
00077 void fvMesh::makeMagSf() const
00078 {
00079     if (debug)
00080     {
00081         Info<< "void fvMesh::makeMagSf() : "
00082             << "assembling mag face areas"
00083             << endl;
00084     }
00085 
00086     // It is an error to attempt to recalculate
00087     // if the pointer is already set
00088     if (magSfPtr_)
00089     {
00090         FatalErrorIn("void fvMesh::makeMagSf()")
00091             << "mag face areas already exist"
00092             << abort(FatalError);
00093     }
00094 
00095     // Note: Added stabilisation for faces with exactly zero area.
00096     // These should be caught on mesh checking but at least this stops
00097     // the code from producing Nans.  
00098     magSfPtr_ = new surfaceScalarField
00099     (
00100         IOobject
00101         (
00102             "magSf",
00103             pointsInstance(),
00104             meshSubDir,
00105             *this,
00106             IOobject::NO_READ,
00107             IOobject::NO_WRITE,
00108             false
00109         ),
00110         mag(Sf()) + dimensionedScalar("vs", dimArea, VSMALL)
00111     );
00112 }
00113 
00114 
00115 void fvMesh::makeC() const
00116 {
00117     if (debug)
00118     {
00119         Info<< "void fvMesh::makeC() : "
00120             << "assembling cell centres"
00121             << endl;
00122     }
00123 
00124     // It is an error to attempt to recalculate
00125     // if the pointer is already set
00126     if (CPtr_)
00127     {
00128         FatalErrorIn("fvMesh::makeC()")
00129             << "cell centres already exist"
00130             << abort(FatalError);
00131     }
00132 
00133     CPtr_ = new slicedVolVectorField
00134     (
00135         IOobject
00136         (
00137             "C",
00138             pointsInstance(),
00139             meshSubDir,
00140             *this,
00141             IOobject::NO_READ,
00142             IOobject::NO_WRITE,
00143             false
00144         ),
00145         *this,
00146         dimLength,
00147         cellCentres(),
00148         faceCentres()
00149     );
00150 
00151 
00152     // Need to correct for cyclics transformation since absolute quantity.
00153     // Ok on processor patches since hold opposite cell centre (no
00154     // transformation)
00155     slicedVolVectorField& C = *CPtr_;
00156 
00157     forAll(C.boundaryField(), patchi)
00158     {
00159         if (isA<cyclicFvPatchVectorField>(C.boundaryField()[patchi]))
00160         {
00161             // Note: cyclic is not slice but proper field
00162             C.boundaryField()[patchi] == static_cast<const vectorField&>
00163             (
00164                 static_cast<const List<vector>&>
00165                 (
00166                     boundary_[patchi].patchSlice(faceCentres())
00167                 )
00168             );
00169         }
00170     }
00171 }
00172 
00173 
00174 void fvMesh::makeCf() const
00175 {
00176     if (debug)
00177     {
00178         Info<< "void fvMesh::makeCf() : "
00179             << "assembling face centres"
00180             << endl;
00181     }
00182 
00183     // It is an error to attempt to recalculate
00184     // if the pointer is already set
00185     if (CfPtr_)
00186     {
00187         FatalErrorIn("fvMesh::makeCf()")
00188             << "face centres already exist"
00189             << abort(FatalError);
00190     }
00191 
00192     CfPtr_ = new slicedSurfaceVectorField
00193     (
00194         IOobject
00195         (
00196             "Cf",
00197             pointsInstance(),
00198             meshSubDir,
00199             *this,
00200             IOobject::NO_READ,
00201             IOobject::NO_WRITE,
00202             false
00203         ),
00204         *this,
00205         dimLength,
00206         faceCentres()
00207     );
00208 }
00209 
00210 
00211 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00212 
00213 const volScalarField::DimensionedInternalField& fvMesh::V() const
00214 {
00215     if (!VPtr_)
00216     {
00217         VPtr_ = new slicedVolScalarField::DimensionedInternalField
00218         (
00219             IOobject
00220             (
00221                 "V",
00222                 time().timeName(),
00223                 *this,
00224                 IOobject::NO_READ,
00225                 IOobject::NO_WRITE
00226             ),
00227             *this,
00228             dimVolume,
00229             cellVolumes()
00230         );
00231     }
00232 
00233     return *static_cast<slicedVolScalarField::DimensionedInternalField*>(VPtr_);
00234 }
00235 
00236 
00237 const volScalarField::DimensionedInternalField& fvMesh::V0() const
00238 {
00239     if (!V0Ptr_)
00240     {
00241         FatalErrorIn("fvMesh::V0() const")
00242             << "V0 is not available"
00243             << abort(FatalError);
00244     }
00245 
00246     return *V0Ptr_;
00247 }
00248 
00249 
00250 volScalarField::DimensionedInternalField& fvMesh::setV0()
00251 {
00252     if (!V0Ptr_)
00253     {
00254         FatalErrorIn("fvMesh::setV0()")
00255             << "V0 is not available"
00256             << abort(FatalError);
00257     }
00258 
00259     return *V0Ptr_;
00260 }
00261 
00262 
00263 const volScalarField::DimensionedInternalField& fvMesh::V00() const
00264 {
00265     if (!V00Ptr_)
00266     {
00267         V00Ptr_ = new DimensionedField<scalar, volMesh>
00268         (
00269             IOobject
00270             (
00271                 "V00",
00272                 time().timeName(),
00273                 *this,
00274                 IOobject::NO_READ,
00275                 IOobject::NO_WRITE
00276             ),
00277             V0()
00278         );
00279 
00280         // If V00 is used then V0 should be stored for restart
00281         V0Ptr_->writeOpt() = IOobject::AUTO_WRITE;
00282     }
00283 
00284     return *V00Ptr_;
00285 }
00286 
00287 
00288 const surfaceVectorField& fvMesh::Sf() const
00289 {
00290     if (!SfPtr_)
00291     {
00292         makeSf();
00293     }
00294 
00295     return *SfPtr_;
00296 }
00297 
00298 
00299 const surfaceScalarField& fvMesh::magSf() const
00300 {
00301     if (!magSfPtr_)
00302     {
00303         makeMagSf();
00304     }
00305 
00306     return *magSfPtr_;
00307 }
00308 
00309 
00310 const volVectorField& fvMesh::C() const
00311 {
00312     if (!CPtr_)
00313     {
00314         makeC();
00315     }
00316 
00317     return *CPtr_;
00318 }
00319 
00320 
00321 const surfaceVectorField& fvMesh::Cf() const
00322 {
00323     if (!CfPtr_)
00324     {
00325         makeCf();
00326     }
00327 
00328     return *CfPtr_;
00329 }
00330 
00331 
00332 const surfaceScalarField& fvMesh::phi() const
00333 {
00334     if (!phiPtr_)
00335     {
00336         FatalErrorIn("fvMesh::phi()")
00337             << "mesh flux field does not exists, is the mesh actually moving?"
00338             << exit(FatalError);
00339     }
00340 
00341     // Set zero current time 
00342     // mesh motion fluxes if the time has been incremented
00343     if (phiPtr_->timeIndex() != time().timeIndex())
00344     {
00345         (*phiPtr_) = dimensionedScalar("0", dimVolume/dimTime, 0.0);
00346     }
00347 
00348     return *phiPtr_;
00349 }
00350 
00351 
00352 surfaceScalarField& fvMesh::setPhi()
00353 {
00354     if (!phiPtr_)
00355     {
00356         FatalErrorIn("fvMesh::setPhi()")
00357             << "mesh flux field does not exists, is the mesh actually moving?"
00358             << exit(FatalError);
00359     }
00360 
00361     return *phiPtr_;
00362 }
00363 
00364 
00365 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00366 
00367 } // End namespace Foam
00368 
00369 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd