Added more controls to the active-baffles.
[OpenFOAM-1.5.x.git] / src / finiteVolume / fields / fvPatchFields / derived / activeBaffleVelocity / activeBaffleVelocityFvPatchVectorField.C
blobd10de7e1fc5404a49292d5b5b4a27e53d8fe7df2
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);
156     initWallSf_.autoMap(m);
157     initCyclicSf_.autoMap(m);
160 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
162     const fvPatchVectorField& ptf,
163     const labelList& addr
166     fixedValueFvPatchVectorField::rmap(ptf, addr);
168     const activeBaffleVelocityFvPatchVectorField& tiptf =
169         refCast<const activeBaffleVelocityFvPatchVectorField>(ptf);
171     initWallSf_.rmap(tiptf.initWallSf_, addr);
172     initCyclicSf_.rmap(tiptf.initCyclicSf_, addr);
176 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
178     if (updated())
179     {
180         return;
181     }
183     // Execute the change to the openFraction only once per time-step
184     if (curTimeIndex_ != this->db().time().timeIndex())
185     {
186         const volScalarField& p = db().lookupObject<volScalarField>
187         (
188             pName_
189         );
191         const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
192         const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
193         label nCyclicFaces = cyclicFaceCells.size();
194         label nCyclicFacesPerSide = nCyclicFaces/2;
196         scalar forceDiff = 0;
198         for (label facei=0; facei<nCyclicFacesPerSide; facei++)
199         {
200             forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
201         }
203         for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
204         {
205             forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
206         }
208         openFraction_ =
209             max(min(
210                 openFraction_
211               + max
212                 (
213                     this->db().time().deltaT().value()/openingTime_,
214                     maxOpenFractionDelta_
215                 )
216                *(orientation_*sign(forceDiff)),
217               1 - 1e-6), 1e-6);
219         Info<< "openFraction = " << openFraction_ << endl;
221         vectorField::subField Sfw = patch().patch().faceAreas();
222         vectorField newSfw = (1 - openFraction_)*initWallSf_;
223         forAll(Sfw, facei)
224         {
225             Sfw[facei] = newSfw[facei];
226         }
227         const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf());
229         const_cast<vectorField&>(cyclicPatch.Sf()) =
230             openFraction_*initCyclicSf_;
231         const_cast<scalarField&>(cyclicPatch.magSf()) =
232             mag(cyclicPatch.Sf());
234         curTimeIndex_ = this->db().time().timeIndex();
235     }
237     fixedValueFvPatchVectorField::updateCoeffs();
241 void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
243     fvPatchVectorField::write(os);
244     os.writeKeyword("cyclicPatch")
245         << cyclicPatchName_ << token::END_STATEMENT << nl;
246     os.writeKeyword("orientation")
247         << orientation_ << token::END_STATEMENT << nl;
248     os.writeKeyword("openingTime")
249         << openingTime_ << token::END_STATEMENT << nl;
250     os.writeKeyword("maxOpenFractionDelta")
251         << maxOpenFractionDelta_ << token::END_STATEMENT << nl;
252     os.writeKeyword("openFraction")
253         << openFraction_ << token::END_STATEMENT << nl;
254     os.writeKeyword("p")
255         << pName_ << token::END_STATEMENT << nl;
256     writeEntry("value", os);
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 namespace Foam
264     makePatchTypeField
265     (
266         fvPatchVectorField,
267         activeBaffleVelocityFvPatchVectorField
268     );
271 // ************************************************************************* //