1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 #include "slicedVolFields.H"
31 #include "slicedSurfaceFields.H"
33 #include "cyclicFvPatchFields.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 void fvMesh::makeSf() const
46 Info<< "void fvMesh::makeSf() : "
47 << "assembling face areas"
51 // It is an error to attempt to recalculate
52 // if the pointer is already set
55 FatalErrorIn("fvMesh::makeSf()")
56 << "face areas already exist"
60 SfPtr_ = new slicedSurfaceVectorField
79 void fvMesh::makeMagSf() const
83 Info<< "void fvMesh::makeMagSf() : "
84 << "assembling mag face areas"
88 // It is an error to attempt to recalculate
89 // if the pointer is already set
92 FatalErrorIn("void fvMesh::makeMagSf()")
93 << "mag face areas already exist"
97 // Note: Added stabilisation for faces with exactly zero area.
98 // These should be caught on mesh checking but at least this stops
99 // the code from producing Nans.
100 magSfPtr_ = new surfaceScalarField
112 mag(Sf()) + dimensionedScalar("vs", dimArea, VSMALL)
117 void fvMesh::makeC() const
121 Info<< "void fvMesh::makeC() : "
122 << "assembling cell centres"
126 // It is an error to attempt to recalculate
127 // if the pointer is already set
130 FatalErrorIn("fvMesh::makeC()")
131 << "cell centres already exist"
132 << abort(FatalError);
135 CPtr_ = new slicedVolVectorField
154 // Need to correct for cyclics transformation since absolute quantity.
155 // Ok on processor patches since hold opposite cell centre (no
157 slicedVolVectorField& C = *CPtr_;
159 forAll(C.boundaryField(), patchi)
161 if (isA<cyclicFvPatchVectorField>(C.boundaryField()[patchi]))
163 // Note: cyclic is not slice but proper field
164 C.boundaryField()[patchi] == static_cast<const vectorField&>
166 static_cast<const List<vector>&>
168 boundary_[patchi].patchSlice(faceCentres())
176 void fvMesh::makeCf() const
180 Info<< "void fvMesh::makeCf() : "
181 << "assembling face centres"
185 // It is an error to attempt to recalculate
186 // if the pointer is already set
189 FatalErrorIn("fvMesh::makeCf()")
190 << "face centres already exist"
191 << abort(FatalError);
194 CfPtr_ = new slicedSurfaceVectorField
213 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
215 const volScalarField::DimensionedInternalField& fvMesh::V() const
219 VPtr_ = new slicedVolScalarField::DimensionedInternalField
235 return *static_cast<slicedVolScalarField::DimensionedInternalField*>(VPtr_);
239 const volScalarField::DimensionedInternalField& fvMesh::V0() const
243 FatalErrorIn("fvMesh::V0() const")
244 << "V0 is not available"
245 << abort(FatalError);
252 volScalarField::DimensionedInternalField& fvMesh::setV0()
256 FatalErrorIn("fvMesh::setV0()")
257 << "V0 is not available"
258 << abort(FatalError);
265 const volScalarField::DimensionedInternalField& fvMesh::V00() const
269 V00Ptr_ = new DimensionedField<scalar, volMesh>
282 // If V00 is used then V0 should be stored for restart
283 V0Ptr_->writeOpt() = IOobject::AUTO_WRITE;
290 tmp<volScalarField::DimensionedInternalField> fvMesh::Vsc() const
292 if (moving() && time().subCycling())
294 const TimeState& ts = time();
295 const TimeState& ts0 = time().prevTimeState();
299 ts.value() - (ts0.value() - ts0.deltaTValue())
302 if (tFrac < (1 - SMALL))
304 return V0() + tFrac*(V() - V0());
318 tmp<volScalarField::DimensionedInternalField> fvMesh::Vsc0() const
320 if (moving() && time().subCycling())
322 const TimeState& ts = time();
323 const TimeState& ts0 = time().prevTimeState();
327 (ts.value() - ts.deltaTValue())
328 - (ts0.value() - ts0.deltaTValue())
333 return V0() + t0Frac*(V() - V0());
347 const surfaceVectorField& fvMesh::Sf() const
358 const surfaceScalarField& fvMesh::magSf() const
369 const volVectorField& fvMesh::C() const
380 const surfaceVectorField& fvMesh::Cf() const
391 const surfaceScalarField& fvMesh::phi() const
395 FatalErrorIn("fvMesh::phi()")
396 << "mesh flux field does not exists, is the mesh actually moving?"
400 // Set zero current time
401 // mesh motion fluxes if the time has been incremented
402 if (phiPtr_->timeIndex() != time().timeIndex())
404 (*phiPtr_) = dimensionedScalar("0", dimVolume/dimTime, 0.0);
411 surfaceScalarField& fvMesh::setPhi()
415 FatalErrorIn("fvMesh::setPhi()")
416 << "mesh flux field does not exists, is the mesh actually moving?"
424 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
426 } // End namespace Foam
428 // ************************************************************************* //