FreeFOAM The Cross-Platform CFD Toolkit
pressureDirectedInletOutletVelocityFvPatchVectorField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
29 #include <finiteVolume/volFields.H>
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
41 (
42  const fvPatch& p,
44 )
45 :
46  mixedFvPatchVectorField(p, iF),
47  phiName_("phi"),
48  rhoName_("rho"),
49  inletDir_(p.size())
50 {
51  refValue() = *this;
52  refGrad() = vector::zero;
53  valueFraction() = 0.0;
54 }
55 
56 
59 (
61  const fvPatch& p,
63  const fvPatchFieldMapper& mapper
64 )
65 :
66  mixedFvPatchVectorField(ptf, p, iF, mapper),
67  phiName_(ptf.phiName_),
68  rhoName_(ptf.rhoName_),
69  inletDir_(ptf.inletDir_, mapper)
70 {}
71 
72 
75 (
76  const fvPatch& p,
78  const dictionary& dict
79 )
80 :
81  mixedFvPatchVectorField(p, iF),
82  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
83  rhoName_(dict.lookupOrDefault<word>("rho", "rho")),
84  inletDir_("inletDirection", dict, p.size())
85 {
86  fvPatchVectorField::operator=(vectorField("value", dict, p.size()));
87  refValue() = *this;
88  refGrad() = vector::zero;
89  valueFraction() = 0.0;
90 }
91 
92 
95 (
97 )
98 :
99  mixedFvPatchVectorField(pivpvf),
100  phiName_(pivpvf.phiName_),
101  rhoName_(pivpvf.rhoName_),
102  inletDir_(pivpvf.inletDir_)
103 {}
104 
105 
108 (
111 )
112 :
113  mixedFvPatchVectorField(pivpvf, iF),
114  phiName_(pivpvf.phiName_),
115  rhoName_(pivpvf.rhoName_),
116  inletDir_(pivpvf.inletDir_)
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
123 (
124  const fvPatchFieldMapper& m
125 )
126 {
127  mixedFvPatchVectorField::autoMap(m);
128  inletDir_.autoMap(m);
129 }
130 
131 
133 (
134  const fvPatchVectorField& ptf,
135  const labelList& addr
136 )
137 {
138  mixedFvPatchVectorField::rmap(ptf, addr);
139 
141  refCast<const pressureDirectedInletOutletVelocityFvPatchVectorField>
142  (ptf);
143 
144  inletDir_.rmap(tiptf.inletDir_, addr);
145 }
146 
147 
149 {
150  if (updated())
151  {
152  return;
153  }
154 
155  const surfaceScalarField& phi =
156  db().lookupObject<surfaceScalarField>(phiName_);
157 
158  const fvsPatchField<scalar>& phip =
159  patch().patchField<surfaceScalarField, scalar>(phi);
160 
161  vectorField n = patch().nf();
162  scalarField ndmagS = (n & inletDir_)*patch().magSf();
163 
164  if (phi.dimensions() == dimVelocity*dimArea)
165  {
166  refValue() = inletDir_*phip/ndmagS;
167  }
168  else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
169  {
170  const fvPatchField<scalar>& rhop =
171  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
172 
173  refValue() = inletDir_*phip/(rhop*ndmagS);
174  }
175  else
176  {
178  (
179  "pressureDirectedInletOutletVelocityFvPatchVectorField::"
180  "updateCoeffs()"
181  ) << "dimensions of phi are not correct"
182  << "\n on patch " << this->patch().name()
183  << " of field " << this->dimensionedInternalField().name()
184  << " in file " << this->dimensionedInternalField().objectPath()
185  << exit(FatalError);
186  }
187 
188  valueFraction() = 1.0 - pos(phip);
189 
191 }
192 
193 
195 write(Ostream& os) const
196 {
198  if (phiName_ != "phi")
199  {
200  os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
201  }
202  if (rhoName_ != "rho")
203  {
204  os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
205  }
206  inletDir_.writeEntry("inletDirection", os);
207  writeEntry("value", os);
208 }
209 
210 
211 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
212 
213 void pressureDirectedInletOutletVelocityFvPatchVectorField::operator=
214 (
215  const fvPatchField<vector>& pvf
216 )
217 {
219  (
220  valueFraction()*(inletDir_*(inletDir_ & pvf))
221  + (1 - valueFraction())*pvf
222  );
223 }
224 
225 
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 
229 (
232 );
233 
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 
236 } // End namespace Foam
237 
238 // ************************ vim: set sw=4 sts=4 et: ************************ //