initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fields / fvPatchFields / derived / pressureDirectedInletOutletVelocity / pressureDirectedInletOutletVelocityFvPatchVectorField.C
blob49923ea891a7a8c8f88e1021afaf005838716b1f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
27 #include "pressureDirectedInletOutletVelocityFvPatchVectorField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
40 pressureDirectedInletOutletVelocityFvPatchVectorField::
41 pressureDirectedInletOutletVelocityFvPatchVectorField
43     const fvPatch& p,
44     const DimensionedField<vector, volMesh>& iF
47     mixedFvPatchVectorField(p, iF),
48     phiName_("phi"),
49     rhoName_("rho"),
50     inletDir_(p.size())
52     refValue() = *this;
53     refGrad() = vector::zero;
54     valueFraction() = 0.0;
58 pressureDirectedInletOutletVelocityFvPatchVectorField::
59 pressureDirectedInletOutletVelocityFvPatchVectorField
61     const pressureDirectedInletOutletVelocityFvPatchVectorField& ptf,
62     const fvPatch& p,
63     const DimensionedField<vector, volMesh>& iF,
64     const fvPatchFieldMapper& mapper
67     mixedFvPatchVectorField(ptf, p, iF, mapper),
68     phiName_(ptf.phiName_),
69     rhoName_(ptf.rhoName_),
70     inletDir_(ptf.inletDir_, mapper)
74 pressureDirectedInletOutletVelocityFvPatchVectorField::
75 pressureDirectedInletOutletVelocityFvPatchVectorField
77     const fvPatch& p,
78     const DimensionedField<vector, volMesh>& iF,
79     const dictionary& dict
82     mixedFvPatchVectorField(p, iF),
83     phiName_(dict.lookupOrDefault<word>("phi", "phi")),
84     rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
85     inletDir_("inletDirection", dict, p.size())
87     fvPatchVectorField::operator=(vectorField("value", dict, p.size()));
88     refValue() = *this;
89     refGrad() = vector::zero;
90     valueFraction() = 0.0;
94 pressureDirectedInletOutletVelocityFvPatchVectorField::
95 pressureDirectedInletOutletVelocityFvPatchVectorField
97     const pressureDirectedInletOutletVelocityFvPatchVectorField& pivpvf
100     mixedFvPatchVectorField(pivpvf),
101     phiName_(pivpvf.phiName_),
102     rhoName_(pivpvf.rhoName_),
103     inletDir_(pivpvf.inletDir_)
107 pressureDirectedInletOutletVelocityFvPatchVectorField::
108 pressureDirectedInletOutletVelocityFvPatchVectorField
110     const pressureDirectedInletOutletVelocityFvPatchVectorField& pivpvf,
111     const DimensionedField<vector, volMesh>& iF
114     mixedFvPatchVectorField(pivpvf, iF),
115     phiName_(pivpvf.phiName_),
116     rhoName_(pivpvf.rhoName_),
117     inletDir_(pivpvf.inletDir_)
121 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
123 void pressureDirectedInletOutletVelocityFvPatchVectorField::autoMap
125     const fvPatchFieldMapper& m
128     mixedFvPatchVectorField::autoMap(m);
129     inletDir_.autoMap(m);
133 void pressureDirectedInletOutletVelocityFvPatchVectorField::rmap
135     const fvPatchVectorField& ptf,
136     const labelList& addr
139     mixedFvPatchVectorField::rmap(ptf, addr);
141     const pressureDirectedInletOutletVelocityFvPatchVectorField& tiptf =
142         refCast<const pressureDirectedInletOutletVelocityFvPatchVectorField>
143         (ptf);
145     inletDir_.rmap(tiptf.inletDir_, addr);
149 void pressureDirectedInletOutletVelocityFvPatchVectorField::updateCoeffs()
151     if (updated())
152     {
153         return;
154     }
156     const surfaceScalarField& phi =
157         db().lookupObject<surfaceScalarField>(phiName_);
159     const fvsPatchField<scalar>& phip =
160         patch().patchField<surfaceScalarField, scalar>(phi);
162     vectorField n = patch().nf();
163     scalarField ndmagS = (n & inletDir_)*patch().magSf();
165     if (phi.dimensions() == dimVelocity*dimArea)
166     {
167         refValue() = inletDir_*phip/ndmagS;
168     }
169     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
170     {
171         const fvPatchField<scalar>& rhop =
172             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
174         refValue() = inletDir_*phip/(rhop*ndmagS);
175     }
176     else
177     {
178         FatalErrorIn
179         (
180             "pressureDirectedInletOutletVelocityFvPatchVectorField::"
181             "updateCoeffs()"
182         )   << "dimensions of phi are not correct"
183             << "\n    on patch " << this->patch().name()
184             << " of field " << this->dimensionedInternalField().name()
185             << " in file " << this->dimensionedInternalField().objectPath()
186             << exit(FatalError);
187     }
189     valueFraction() = 1.0 - pos(phip);
191     mixedFvPatchVectorField::updateCoeffs();
195 void pressureDirectedInletOutletVelocityFvPatchVectorField::
196 write(Ostream& os) const
198     fvPatchVectorField::write(os);
199     if (phiName_ != "phi")
200     {
201         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
202     }
203     if (rhoName_ != "rho")
204     {
205         os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
206     }
207     inletDir_.writeEntry("inletDirection", os);
208     writeEntry("value", os);
212 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
214 void pressureDirectedInletOutletVelocityFvPatchVectorField::operator=
216     const fvPatchField<vector>& pvf
219     fvPatchField<vector>::operator=
220     (
221         valueFraction()*(inletDir_*(inletDir_ & pvf))
222       + (1 - valueFraction())*pvf
223     );
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 makePatchTypeField
231     fvPatchVectorField,
232     pressureDirectedInletOutletVelocityFvPatchVectorField
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 } // End namespace Foam
239 // ************************************************************************* //