1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
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 \*---------------------------------------------------------------------------*/
26 #include "CoEulerDdtScheme.H"
27 #include "surfaceInterpolate.H"
29 #include "fvMatrices.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 tmp<volScalarField> CoEulerDdtScheme<Type>::CorDeltaT() const
46 const surfaceScalarField cofrDeltaT(CofrDeltaT());
48 tmp<volScalarField> tcorDeltaT
55 cofrDeltaT.instance(),
59 dimensionedScalar("CorDeltaT", cofrDeltaT.dimensions(), 0.0),
60 zeroGradientFvPatchScalarField::typeName
64 volScalarField& corDeltaT = tcorDeltaT();
66 const labelUList& owner = mesh().owner();
67 const labelUList& neighbour = mesh().neighbour();
71 corDeltaT[owner[faceI]] =
72 max(corDeltaT[owner[faceI]], cofrDeltaT[faceI]);
74 corDeltaT[neighbour[faceI]] =
75 max(corDeltaT[neighbour[faceI]], cofrDeltaT[faceI]);
78 forAll(corDeltaT.boundaryField(), patchi)
80 const fvsPatchScalarField& pcofrDeltaT =
81 cofrDeltaT.boundaryField()[patchi];
83 const fvPatch& p = pcofrDeltaT.patch();
84 const labelUList& faceCells = p.patch().faceCells();
86 forAll(pcofrDeltaT, patchFacei)
88 corDeltaT[faceCells[patchFacei]] = max
90 corDeltaT[faceCells[patchFacei]],
91 pcofrDeltaT[patchFacei]
96 corDeltaT.correctBoundaryConditions();
98 //corDeltaT = max(corDeltaT, max(corDeltaT)/100.0);
105 tmp<surfaceScalarField> CoEulerDdtScheme<Type>::CofrDeltaT() const
107 const dimensionedScalar& deltaT = mesh().time().deltaT();
109 const surfaceScalarField& phi =
110 static_cast<const objectRegistry&>(mesh())
111 .lookupObject<surfaceScalarField>(phiName_);
113 if (phi.dimensions() == dimensionSet(0, 3, -1, 0, 0))
115 surfaceScalarField Co
117 mesh().surfaceInterpolation::deltaCoeffs()
118 *(mag(phi)/mesh().magSf())
122 return max(Co/maxCo_, scalar(1))/deltaT;
124 else if (phi.dimensions() == dimensionSet(1, 0, -1, 0, 0))
126 const volScalarField& rho =
127 static_cast<const objectRegistry&>(mesh())
128 .lookupObject<volScalarField>(rhoName_).oldTime();
130 surfaceScalarField Co
132 mesh().surfaceInterpolation::deltaCoeffs()
133 *(mag(phi)/(fvc::interpolate(rho)*mesh().magSf()))
137 return max(Co/maxCo_, scalar(1))/deltaT;
141 FatalErrorIn("CoEulerDdtScheme<Type>::CofrDeltaT() const")
142 << "Incorrect dimensions of phi: " << phi.dimensions()
143 << abort(FatalError);
145 return tmp<surfaceScalarField>(NULL);
151 tmp<GeometricField<Type, fvPatchField, volMesh> >
152 CoEulerDdtScheme<Type>::fvcDdt
154 const dimensioned<Type>& dt
157 const volScalarField rDeltaT(CorDeltaT());
161 "ddt("+dt.name()+')',
162 mesh().time().timeName(),
168 tmp<GeometricField<Type, fvPatchField, volMesh> > tdtdt
170 new GeometricField<Type, fvPatchField, volMesh>
177 dt.dimensions()/dimTime,
183 tdtdt().internalField() =
184 rDeltaT.internalField()*dt.value()*(1.0 - mesh().V0()/mesh().V());
190 return tmp<GeometricField<Type, fvPatchField, volMesh> >
192 new GeometricField<Type, fvPatchField, volMesh>
199 dt.dimensions()/dimTime,
202 calculatedFvPatchField<Type>::typeName
210 tmp<GeometricField<Type, fvPatchField, volMesh> >
211 CoEulerDdtScheme<Type>::fvcDdt
213 const GeometricField<Type, fvPatchField, volMesh>& vf
216 const volScalarField rDeltaT(CorDeltaT());
220 "ddt("+vf.name()+')',
221 mesh().time().timeName(),
227 return tmp<GeometricField<Type, fvPatchField, volMesh> >
229 new GeometricField<Type, fvPatchField, volMesh>
233 rDeltaT.dimensions()*vf.dimensions(),
234 rDeltaT.internalField()*
237 - vf.oldTime().internalField()*mesh().V0()/mesh().V()
239 rDeltaT.boundaryField()*
241 vf.boundaryField() - vf.oldTime().boundaryField()
248 return tmp<GeometricField<Type, fvPatchField, volMesh> >
250 new GeometricField<Type, fvPatchField, volMesh>
253 rDeltaT*(vf - vf.oldTime())
261 tmp<GeometricField<Type, fvPatchField, volMesh> >
262 CoEulerDdtScheme<Type>::fvcDdt
264 const dimensionedScalar& rho,
265 const GeometricField<Type, fvPatchField, volMesh>& vf
268 const volScalarField rDeltaT(CorDeltaT());
272 "ddt("+rho.name()+','+vf.name()+')',
273 mesh().time().timeName(),
279 return tmp<GeometricField<Type, fvPatchField, volMesh> >
281 new GeometricField<Type, fvPatchField, volMesh>
285 rDeltaT.dimensions()*rho.dimensions()*vf.dimensions(),
286 rDeltaT.internalField()*rho.value()*
289 - vf.oldTime().internalField()*mesh().V0()/mesh().V()
291 rDeltaT.boundaryField()*rho.value()*
293 vf.boundaryField() - vf.oldTime().boundaryField()
300 return tmp<GeometricField<Type, fvPatchField, volMesh> >
302 new GeometricField<Type, fvPatchField, volMesh>
305 rDeltaT*rho*(vf - vf.oldTime())
313 tmp<GeometricField<Type, fvPatchField, volMesh> >
314 CoEulerDdtScheme<Type>::fvcDdt
316 const volScalarField& rho,
317 const GeometricField<Type, fvPatchField, volMesh>& vf
320 const volScalarField rDeltaT(CorDeltaT());
324 "ddt("+rho.name()+','+vf.name()+')',
325 mesh().time().timeName(),
331 return tmp<GeometricField<Type, fvPatchField, volMesh> >
333 new GeometricField<Type, fvPatchField, volMesh>
337 rDeltaT.dimensions()*rho.dimensions()*vf.dimensions(),
338 rDeltaT.internalField()*
340 rho.internalField()*vf.internalField()
341 - rho.oldTime().internalField()
342 *vf.oldTime().internalField()*mesh().V0()/mesh().V()
344 rDeltaT.boundaryField()*
346 rho.boundaryField()*vf.boundaryField()
347 - rho.oldTime().boundaryField()
348 *vf.oldTime().boundaryField()
355 return tmp<GeometricField<Type, fvPatchField, volMesh> >
357 new GeometricField<Type, fvPatchField, volMesh>
360 rDeltaT*(rho*vf - rho.oldTime()*vf.oldTime())
369 CoEulerDdtScheme<Type>::fvmDdt
371 const GeometricField<Type, fvPatchField, volMesh>& vf
374 tmp<fvMatrix<Type> > tfvm
379 vf.dimensions()*dimVol/dimTime
383 fvMatrix<Type>& fvm = tfvm();
385 scalarField rDeltaT(CorDeltaT()().internalField());
387 fvm.diag() = rDeltaT*mesh().V();
391 fvm.source() = rDeltaT*vf.oldTime().internalField()*mesh().V0();
395 fvm.source() = rDeltaT*vf.oldTime().internalField()*mesh().V();
404 CoEulerDdtScheme<Type>::fvmDdt
406 const dimensionedScalar& rho,
407 const GeometricField<Type, fvPatchField, volMesh>& vf
410 tmp<fvMatrix<Type> > tfvm
415 rho.dimensions()*vf.dimensions()*dimVol/dimTime
418 fvMatrix<Type>& fvm = tfvm();
420 scalarField rDeltaT(CorDeltaT()().internalField());
422 fvm.diag() = rDeltaT*rho.value()*mesh().V();
426 fvm.source() = rDeltaT
427 *rho.value()*vf.oldTime().internalField()*mesh().V0();
431 fvm.source() = rDeltaT
432 *rho.value()*vf.oldTime().internalField()*mesh().V();
441 CoEulerDdtScheme<Type>::fvmDdt
443 const volScalarField& rho,
444 const GeometricField<Type, fvPatchField, volMesh>& vf
447 tmp<fvMatrix<Type> > tfvm
452 rho.dimensions()*vf.dimensions()*dimVol/dimTime
455 fvMatrix<Type>& fvm = tfvm();
457 scalarField rDeltaT(CorDeltaT()().internalField());
459 fvm.diag() = rDeltaT*rho.internalField()*mesh().V();
463 fvm.source() = rDeltaT
464 *rho.oldTime().internalField()
465 *vf.oldTime().internalField()*mesh().V0();
469 fvm.source() = rDeltaT
470 *rho.oldTime().internalField()
471 *vf.oldTime().internalField()*mesh().V();
479 tmp<typename CoEulerDdtScheme<Type>::fluxFieldType>
480 CoEulerDdtScheme<Type>::fvcDdtPhiCorr
482 const volScalarField& rA,
483 const GeometricField<Type, fvPatchField, volMesh>& U,
484 const fluxFieldType& phi
489 "ddtPhiCorr(" + rA.name() + ',' + U.name() + ',' + phi.name() + ')',
490 mesh().time().timeName(),
496 return tmp<fluxFieldType>
502 dimensioned<typename flux<Type>::type>
505 rA.dimensions()*phi.dimensions()/dimTime,
506 pTraits<typename flux<Type>::type>::zero
513 const volScalarField rDeltaT(CorDeltaT());
515 return tmp<fluxFieldType>
520 this->fvcDdtPhiCoeff(U.oldTime(), phi.oldTime())*
522 fvc::interpolate(rDeltaT*rA)*phi.oldTime()
523 - (fvc::interpolate(rDeltaT*rA*U.oldTime()) & mesh().Sf())
532 tmp<typename CoEulerDdtScheme<Type>::fluxFieldType>
533 CoEulerDdtScheme<Type>::fvcDdtPhiCorr
535 const volScalarField& rA,
536 const volScalarField& rho,
537 const GeometricField<Type, fvPatchField, volMesh>& U,
538 const fluxFieldType& phi
544 + rA.name() + ',' + rho.name() + ',' + U.name() + ',' + phi.name() + ')',
545 mesh().time().timeName(),
551 return tmp<fluxFieldType>
557 dimensioned<typename flux<Type>::type>
560 rA.dimensions()*rho.dimensions()*phi.dimensions()/dimTime,
561 pTraits<typename flux<Type>::type>::zero
568 const volScalarField rDeltaT(CorDeltaT());
572 U.dimensions() == dimVelocity
573 && phi.dimensions() == dimVelocity*dimArea
576 return tmp<fluxFieldType>
581 this->fvcDdtPhiCoeff(U.oldTime(), phi.oldTime())
583 fvc::interpolate(rDeltaT*rA*rho.oldTime())*phi.oldTime()
584 - (fvc::interpolate(rDeltaT*rA*rho.oldTime()*U.oldTime())
592 U.dimensions() == dimVelocity
593 && phi.dimensions() == dimDensity*dimVelocity*dimArea
596 return tmp<fluxFieldType>
604 phi.oldTime()/fvc::interpolate(rho.oldTime())
607 fvc::interpolate(rDeltaT*rA*rho.oldTime())
608 *phi.oldTime()/fvc::interpolate(rho.oldTime())
612 rDeltaT*rA*rho.oldTime()*U.oldTime()
621 U.dimensions() == dimDensity*dimVelocity
622 && phi.dimensions() == dimDensity*dimVelocity*dimArea
625 return tmp<fluxFieldType>
631 (rho.oldTime(), U.oldTime(), phi.oldTime())
633 fvc::interpolate(rDeltaT*rA)*phi.oldTime()
635 fvc::interpolate(rDeltaT*rA*U.oldTime())&mesh().Sf()
645 "CoEulerDdtScheme<Type>::fvcDdtPhiCorr"
646 ) << "dimensions of phi are not correct"
647 << abort(FatalError);
649 return fluxFieldType::null();
656 tmp<surfaceScalarField> CoEulerDdtScheme<Type>::meshPhi
658 const GeometricField<Type, fvPatchField, volMesh>&
661 return tmp<surfaceScalarField>
663 new surfaceScalarField
668 mesh().time().timeName(),
672 dimensionedScalar("0", dimVolume/dimTime, 0.0)
678 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
680 } // End namespace fv
682 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
684 } // End namespace Foam
686 // ************************************************************************* //