initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fields / fvPatchFields / derived / activeBaffleVelocity / activeBaffleVelocityFvPatchVectorField.C
blobabc4619706097b9d6ff0da884c87d1905d31c256
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 "activeBaffleVelocityFvPatchVectorField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
32 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
34 Foam::activeBaffleVelocityFvPatchVectorField::
35 activeBaffleVelocityFvPatchVectorField
37     const fvPatch& p,
38     const DimensionedField<vector, volMesh>& iF
41     fixedValueFvPatchVectorField(p, iF),
42     pName_("p"),
43     cyclicPatchName_(),
44     cyclicPatchLabel_(-1),
45     orientation_(1),
46     initWallSf_(0),
47     initCyclicSf_(0),
48     openFraction_(0),
49     openingTime_(0),
50     maxOpenFractionDelta_(0),
51     curTimeIndex_(-1)
55 Foam::activeBaffleVelocityFvPatchVectorField::
56 activeBaffleVelocityFvPatchVectorField
58     const activeBaffleVelocityFvPatchVectorField& ptf,
59     const fvPatch& p,
60     const DimensionedField<vector, volMesh>& iF,
61     const fvPatchFieldMapper& mapper
64     fixedValueFvPatchVectorField(ptf, p, iF, mapper),
65     pName_(ptf.pName_),
66     cyclicPatchName_(ptf.cyclicPatchName_),
67     cyclicPatchLabel_(ptf.cyclicPatchLabel_),
68     orientation_(ptf.orientation_),
69     initWallSf_(ptf.initWallSf_),
70     initCyclicSf_(ptf.initCyclicSf_),
71     openFraction_(ptf.openFraction_),
72     openingTime_(ptf.openingTime_),
73     maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
74     curTimeIndex_(-1)
78 Foam::activeBaffleVelocityFvPatchVectorField::
79 activeBaffleVelocityFvPatchVectorField
81     const fvPatch& p,
82     const DimensionedField<vector, volMesh>& iF,
83     const dictionary& dict
86     fixedValueFvPatchVectorField(p, iF),
87     pName_("p"),
88     cyclicPatchName_(dict.lookup("cyclicPatch")),
89     cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
90     orientation_(readLabel(dict.lookup("orientation"))),
91     initWallSf_(p.Sf()),
92     initCyclicSf_(p.boundaryMesh()[cyclicPatchLabel_].Sf()),
93     openFraction_(readScalar(dict.lookup("openFraction"))),
94     openingTime_(readScalar(dict.lookup("openingTime"))),
95     maxOpenFractionDelta_(readScalar(dict.lookup("maxOpenFractionDelta"))),
96     curTimeIndex_(-1)
98     fvPatchVectorField::operator=(vector::zero);
100     if (dict.found("p"))
101     {
102         dict.lookup("p") >> pName_;
103     }
107 Foam::activeBaffleVelocityFvPatchVectorField::
108 activeBaffleVelocityFvPatchVectorField
110     const activeBaffleVelocityFvPatchVectorField& ptf
113     fixedValueFvPatchVectorField(ptf),
114     pName_(ptf.pName_),
115     cyclicPatchName_(ptf.cyclicPatchName_),
116     cyclicPatchLabel_(ptf.cyclicPatchLabel_),
117     orientation_(ptf.orientation_),
118     initWallSf_(ptf.initWallSf_),
119     initCyclicSf_(ptf.initCyclicSf_),
120     openFraction_(ptf.openFraction_),
121     openingTime_(ptf.openingTime_),
122     maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
123     curTimeIndex_(-1)
127 Foam::activeBaffleVelocityFvPatchVectorField::
128 activeBaffleVelocityFvPatchVectorField
130     const activeBaffleVelocityFvPatchVectorField& ptf,
131     const DimensionedField<vector, volMesh>& iF
134     fixedValueFvPatchVectorField(ptf, iF),
135     pName_(ptf.pName_),
136     cyclicPatchName_(ptf.cyclicPatchName_),
137     cyclicPatchLabel_(ptf.cyclicPatchLabel_),
138     orientation_(ptf.orientation_),
139     initWallSf_(ptf.initWallSf_),
140     initCyclicSf_(ptf.initCyclicSf_),
141     openFraction_(ptf.openFraction_),
142     openingTime_(ptf.openingTime_),
143     maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
144     curTimeIndex_(-1)
148 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
150 void Foam::activeBaffleVelocityFvPatchVectorField::autoMap
152     const fvPatchFieldMapper& m
155     fixedValueFvPatchVectorField::autoMap(m);
157     //- Note: cannot map field from cyclic patch anyway so just recalculate
158     //  Areas should be consistent when doing autoMap except in case of
159     //  topo changes.
160     //- Note: we don't want to use Sf here since triggers rebuilding of
161     //  fvMesh::S() which will give problems when mapped (since already
162     //  on new mesh)
163     const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
164     initWallSf_ = patch().patchSlice(areas);
165     initCyclicSf_ = patch().boundaryMesh()
166     [
167         cyclicPatchLabel_
168     ].patchSlice(areas);
171 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
173     const fvPatchVectorField& ptf,
174     const labelList& addr
177     fixedValueFvPatchVectorField::rmap(ptf, addr);
179     // See autoMap.
180     const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
181     initWallSf_ = patch().patchSlice(areas);
182     initCyclicSf_ = patch().boundaryMesh()
183     [
184         cyclicPatchLabel_
185     ].patchSlice(areas);
189 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
191     if (updated())
192     {
193         return;
194     }
196     // Execute the change to the openFraction only once per time-step
197     if (curTimeIndex_ != this->db().time().timeIndex())
198     {
199         const volScalarField& p = db().lookupObject<volScalarField>
200         (
201             pName_
202         );
204         const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
205         const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
206         label nCyclicFaces = cyclicFaceCells.size();
207         label nCyclicFacesPerSide = nCyclicFaces/2;
209         scalar forceDiff = 0;
211         for (label facei=0; facei<nCyclicFacesPerSide; facei++)
212         {
213             forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
214         }
216         for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
217         {
218             forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
219         }
221         openFraction_ =
222             max(min(
223                 openFraction_
224               + max
225                 (
226                     this->db().time().deltaT().value()/openingTime_,
227                     maxOpenFractionDelta_
228                 )
229                *(orientation_*sign(forceDiff)),
230               1 - 1e-6), 1e-6);
232         Info<< "openFraction = " << openFraction_ << endl;
234         vectorField::subField Sfw = patch().patch().faceAreas();
235         vectorField newSfw = (1 - openFraction_)*initWallSf_;
236         forAll(Sfw, facei)
237         {
238             Sfw[facei] = newSfw[facei];
239         }
240         const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf());
242         const_cast<vectorField&>(cyclicPatch.Sf()) =
243             openFraction_*initCyclicSf_;
244         const_cast<scalarField&>(cyclicPatch.magSf()) =
245             mag(cyclicPatch.Sf());
247         curTimeIndex_ = this->db().time().timeIndex();
248     }
250     fixedValueFvPatchVectorField::updateCoeffs();
254 void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
256     fvPatchVectorField::write(os);
257     os.writeKeyword("cyclicPatch")
258         << cyclicPatchName_ << token::END_STATEMENT << nl;
259     os.writeKeyword("orientation")
260         << orientation_ << token::END_STATEMENT << nl;
261     os.writeKeyword("openingTime")
262         << openingTime_ << token::END_STATEMENT << nl;
263     os.writeKeyword("maxOpenFractionDelta")
264         << maxOpenFractionDelta_ << token::END_STATEMENT << nl;
265     os.writeKeyword("openFraction")
266         << openFraction_ << token::END_STATEMENT << nl;
267     os.writeKeyword("p")
268         << pName_ << token::END_STATEMENT << nl;
269     writeEntry("value", os);
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
275 namespace Foam
277     makePatchTypeField
278     (
279         fvPatchVectorField,
280         activeBaffleVelocityFvPatchVectorField
281     );
284 // ************************************************************************* //