1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
29 #include "volFields.H"
30 #include "surfaceFields.H"
31 #include "slicedVolFields.H"
32 #include "slicedSurfaceFields.H"
34 #include "cyclicFvPatchFields.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 void fvMesh::makeSf() const
47 Info<< "void fvMesh::makeSf() : "
48 << "assembling face areas"
52 // It is an error to attempt to recalculate
53 // if the pointer is already set
56 FatalErrorIn("fvMesh::makeSf()")
57 << "face areas already exist"
61 SfPtr_ = new slicedSurfaceVectorField
77 void fvMesh::makeMagSf() const
81 Info<< "void fvMesh::makeMagSf() : "
82 << "assembling mag face areas"
86 // It is an error to attempt to recalculate
87 // if the pointer is already set
90 FatalErrorIn("void fvMesh::makeMagSf()")
91 << "mag face areas already exist"
95 // Note: Added stabilisation for faces with exactly zero area.
96 // These should be caught on mesh checking but at least this stops
97 // the code from producing Nans.
98 magSfPtr_ = new surfaceScalarField
110 mag(Sf()) + dimensionedScalar("vs", dimArea, VSMALL)
115 void fvMesh::makeC() const
119 Info<< "void fvMesh::makeC() : "
120 << "assembling cell centres"
124 // It is an error to attempt to recalculate
125 // if the pointer is already set
128 FatalErrorIn("fvMesh::makeC()")
129 << "cell centres already exist"
130 << abort(FatalError);
133 CPtr_ = new slicedVolVectorField
152 // Need to correct for cyclics transformation since absolute quantity.
153 // Ok on processor patches since hold opposite cell centre (no
155 slicedVolVectorField& C = *CPtr_;
157 forAll(C.boundaryField(), patchi)
159 if (isA<cyclicFvPatchVectorField>(C.boundaryField()[patchi]))
161 // Note: cyclic is not slice but proper field
162 C.boundaryField()[patchi] == static_cast<const vectorField&>
164 static_cast<const List<vector>&>
166 boundary_[patchi].patchSlice(faceCentres())
174 void fvMesh::makeCf() const
178 Info<< "void fvMesh::makeCf() : "
179 << "assembling face centres"
183 // It is an error to attempt to recalculate
184 // if the pointer is already set
187 FatalErrorIn("fvMesh::makeCf()")
188 << "face centres already exist"
189 << abort(FatalError);
192 CfPtr_ = new slicedSurfaceVectorField
211 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
213 const volScalarField::DimensionedInternalField& fvMesh::V() const
217 VPtr_ = new slicedVolScalarField::DimensionedInternalField
233 return *static_cast<slicedVolScalarField::DimensionedInternalField*>(VPtr_);
237 const volScalarField::DimensionedInternalField& fvMesh::V0() const
241 FatalErrorIn("fvMesh::V0() const")
242 << "V0 is not available"
243 << abort(FatalError);
250 volScalarField::DimensionedInternalField& fvMesh::setV0()
254 FatalErrorIn("fvMesh::setV0()")
255 << "V0 is not available"
256 << abort(FatalError);
263 const volScalarField::DimensionedInternalField& fvMesh::V00() const
267 V00Ptr_ = new DimensionedField<scalar, volMesh>
280 // If V00 is used then V0 should be stored for restart
281 V0Ptr_->writeOpt() = IOobject::AUTO_WRITE;
288 tmp<volScalarField::DimensionedInternalField> fvMesh::Vsc() const
290 if (moving() && time().subCycling())
292 const TimeState& ts = time();
293 const TimeState& ts0 = time().prevTimeState();
297 ts.value() - (ts0.value() - ts0.deltaTValue())
300 if (tFrac < (1 - SMALL))
302 return V0() + tFrac*(V() - V0());
316 tmp<volScalarField::DimensionedInternalField> fvMesh::Vsc0() const
318 if (moving() && time().subCycling())
320 const TimeState& ts = time();
321 const TimeState& ts0 = time().prevTimeState();
325 (ts.value() - ts.deltaTValue())
326 - (ts0.value() - ts0.deltaTValue())
331 return V0() + t0Frac*(V() - V0());
345 const surfaceVectorField& fvMesh::Sf() const
356 const surfaceScalarField& fvMesh::magSf() const
367 const volVectorField& fvMesh::C() const
378 const surfaceVectorField& fvMesh::Cf() const
389 const surfaceScalarField& fvMesh::phi() const
393 FatalErrorIn("fvMesh::phi()")
394 << "mesh flux field does not exists, is the mesh actually moving?"
398 // Set zero current time
399 // mesh motion fluxes if the time has been incremented
400 if (phiPtr_->timeIndex() != time().timeIndex())
402 (*phiPtr_) = dimensionedScalar("0", dimVolume/dimTime, 0.0);
409 surfaceScalarField& fvMesh::setPhi()
413 FatalErrorIn("fvMesh::setPhi()")
414 << "mesh flux field does not exists, is the mesh actually moving?"
422 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
424 } // End namespace Foam
426 // ************************************************************************* //