FreeFOAM The Cross-Platform CFD Toolkit
activeBaffleVelocityFvPatchVectorField.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 
28 #include <finiteVolume/volFields.H>
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
35 (
36  const fvPatch& p,
38 )
39 :
40  fixedValueFvPatchVectorField(p, iF),
41  pName_("p"),
42  cyclicPatchName_(),
43  cyclicPatchLabel_(-1),
44  orientation_(1),
45  initWallSf_(0),
46  initCyclicSf_(0),
47  openFraction_(0),
48  openingTime_(0),
49  maxOpenFractionDelta_(0),
50  curTimeIndex_(-1)
51 {}
52 
53 
56 (
58  const fvPatch& p,
60  const fvPatchFieldMapper& mapper
61 )
62 :
63  fixedValueFvPatchVectorField(ptf, p, iF, mapper),
64  pName_(ptf.pName_),
65  cyclicPatchName_(ptf.cyclicPatchName_),
66  cyclicPatchLabel_(ptf.cyclicPatchLabel_),
67  orientation_(ptf.orientation_),
68  initWallSf_(ptf.initWallSf_),
69  initCyclicSf_(ptf.initCyclicSf_),
70  openFraction_(ptf.openFraction_),
71  openingTime_(ptf.openingTime_),
72  maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
73  curTimeIndex_(-1)
74 {}
75 
76 
79 (
80  const fvPatch& p,
82  const dictionary& dict
83 )
84 :
85  fixedValueFvPatchVectorField(p, iF),
86  pName_("p"),
87  cyclicPatchName_(dict.lookup("cyclicPatch")),
88  cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
89  orientation_(readLabel(dict.lookup("orientation"))),
90  initWallSf_(p.Sf()),
91  initCyclicSf_(p.boundaryMesh()[cyclicPatchLabel_].Sf()),
92  openFraction_(readScalar(dict.lookup("openFraction"))),
93  openingTime_(readScalar(dict.lookup("openingTime"))),
94  maxOpenFractionDelta_(readScalar(dict.lookup("maxOpenFractionDelta"))),
95  curTimeIndex_(-1)
96 {
97  fvPatchVectorField::operator=(vector::zero);
98 
99  if (dict.found("p"))
100  {
101  dict.lookup("p") >> pName_;
102  }
103 }
104 
105 
108 (
110 )
111 :
112  fixedValueFvPatchVectorField(ptf),
113  pName_(ptf.pName_),
114  cyclicPatchName_(ptf.cyclicPatchName_),
115  cyclicPatchLabel_(ptf.cyclicPatchLabel_),
116  orientation_(ptf.orientation_),
117  initWallSf_(ptf.initWallSf_),
118  initCyclicSf_(ptf.initCyclicSf_),
119  openFraction_(ptf.openFraction_),
120  openingTime_(ptf.openingTime_),
121  maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
122  curTimeIndex_(-1)
123 {}
124 
125 
128 (
131 )
132 :
133  fixedValueFvPatchVectorField(ptf, iF),
134  pName_(ptf.pName_),
135  cyclicPatchName_(ptf.cyclicPatchName_),
136  cyclicPatchLabel_(ptf.cyclicPatchLabel_),
137  orientation_(ptf.orientation_),
138  initWallSf_(ptf.initWallSf_),
139  initCyclicSf_(ptf.initCyclicSf_),
140  openFraction_(ptf.openFraction_),
141  openingTime_(ptf.openingTime_),
142  maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
143  curTimeIndex_(-1)
144 {}
145 
146 
147 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
148 
150 (
151  const fvPatchFieldMapper& m
152 )
153 {
154  fixedValueFvPatchVectorField::autoMap(m);
155 
156  //- Note: cannot map field from cyclic patch anyway so just recalculate
157  // Areas should be consistent when doing autoMap except in case of
158  // topo changes.
159  //- Note: we don't want to use Sf here since triggers rebuilding of
160  // fvMesh::S() which will give problems when mapped (since already
161  // on new mesh)
162  const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
163  initWallSf_ = static_cast<UList<vector> >(patch().patchSlice(areas));
164  initCyclicSf_ = static_cast<UList<vector> >(patch().boundaryMesh()
165  [
166  cyclicPatchLabel_
167  ].patchSlice(areas));
168 }
169 
171 (
172  const fvPatchVectorField& ptf,
173  const labelList& addr
174 )
175 {
176  fixedValueFvPatchVectorField::rmap(ptf, addr);
177 
178  // See autoMap.
179  const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
180  initWallSf_ = static_cast<UList<vector> >(patch().patchSlice(areas));
181  initCyclicSf_ = static_cast<UList<vector> >(patch().boundaryMesh()
182  [
183  cyclicPatchLabel_
184  ].patchSlice(areas));
185 }
186 
187 
189 {
190  if (updated())
191  {
192  return;
193  }
194 
195  // Execute the change to the openFraction only once per time-step
196  if (curTimeIndex_ != this->db().time().timeIndex())
197  {
198  const volScalarField& p = db().lookupObject<volScalarField>
199  (
200  pName_
201  );
202 
203  const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
204  const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
205  label nCyclicFaces = cyclicFaceCells.size();
206  label nCyclicFacesPerSide = nCyclicFaces/2;
207 
208  scalar forceDiff = 0;
209 
210  for (label facei=0; facei<nCyclicFacesPerSide; facei++)
211  {
212  forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
213  }
214 
215  for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
216  {
217  forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
218  }
219 
220  openFraction_ =
221  max(min(
222  openFraction_
223  + min
224  (
225  this->db().time().deltaT().value()/openingTime_,
226  maxOpenFractionDelta_
227  )
228  *(orientation_*sign(forceDiff)),
229  1 - 1e-6), 1e-6);
230 
231  Info<< "openFraction = " << openFraction_ << endl;
232 
233  vectorField::subField Sfw = patch().patch().faceAreas();
234  vectorField newSfw = (1 - openFraction_)*initWallSf_;
235  forAll(Sfw, facei)
236  {
237  Sfw[facei] = newSfw[facei];
238  }
239  const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf());
240 
241  const_cast<vectorField&>(cyclicPatch.Sf()) =
242  openFraction_*initCyclicSf_;
243  const_cast<scalarField&>(cyclicPatch.magSf()) =
244  mag(cyclicPatch.Sf());
245 
246  curTimeIndex_ = this->db().time().timeIndex();
247  }
248 
250 }
251 
252 
254 {
256  os.writeKeyword("cyclicPatch")
257  << cyclicPatchName_ << token::END_STATEMENT << nl;
258  os.writeKeyword("orientation")
259  << orientation_ << token::END_STATEMENT << nl;
260  os.writeKeyword("openingTime")
261  << openingTime_ << token::END_STATEMENT << nl;
262  os.writeKeyword("maxOpenFractionDelta")
263  << maxOpenFractionDelta_ << token::END_STATEMENT << nl;
264  os.writeKeyword("openFraction")
265  << openFraction_ << token::END_STATEMENT << nl;
266  os.writeKeyword("p")
267  << pName_ << token::END_STATEMENT << nl;
268  writeEntry("value", os);
269 }
270 
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 namespace Foam
275 {
277  (
280  );
281 }
282 
283 // ************************ vim: set sw=4 sts=4 et: ************************ //