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 \*---------------------------------------------------------------------------*/
27 #include "pressureDirectedInletOutletVelocityFvPatchVectorField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 pressureDirectedInletOutletVelocityFvPatchVectorField::
41 pressureDirectedInletOutletVelocityFvPatchVectorField
44 const DimensionedField<vector, volMesh>& iF
47 mixedFvPatchVectorField(p, iF),
53 refGrad() = vector::zero;
54 valueFraction() = 0.0;
58 pressureDirectedInletOutletVelocityFvPatchVectorField::
59 pressureDirectedInletOutletVelocityFvPatchVectorField
61 const pressureDirectedInletOutletVelocityFvPatchVectorField& ptf,
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
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()));
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>
145 inletDir_.rmap(tiptf.inletDir_, addr);
149 void pressureDirectedInletOutletVelocityFvPatchVectorField::updateCoeffs()
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)
167 refValue() = inletDir_*phip/ndmagS;
169 else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
171 const fvPatchField<scalar>& rhop =
172 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
174 refValue() = inletDir_*phip/(rhop*ndmagS);
180 "pressureDirectedInletOutletVelocityFvPatchVectorField::"
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()
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")
201 os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
203 if (rhoName_ != "rho")
205 os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
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=
221 valueFraction()*(inletDir_*(inletDir_ & pvf))
222 + (1 - valueFraction())*pvf
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 pressureDirectedInletOutletVelocityFvPatchVectorField
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 } // End namespace Foam
239 // ************************************************************************* //