New active-baffle BC.
[OpenFOAM-1.5.x.git] / src / finiteVolume / fields / fvPatchFields / derived / activeBaffleVelocity / activeBaffleVelocityFvPatchVectorField.C
blob3e1cf7fda2f7b6bd9e01eb58f0af95405ce3eeec
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     initWallSf_(0),
46     initCyclicSf_(0),
47     openFraction_(0),
48     openFractionDelta_(0),
49     curTimeIndex_(-1)
53 Foam::activeBaffleVelocityFvPatchVectorField::
54 activeBaffleVelocityFvPatchVectorField
56     const activeBaffleVelocityFvPatchVectorField& ptf,
57     const fvPatch& p,
58     const DimensionedField<vector, volMesh>& iF,
59     const fvPatchFieldMapper& mapper
62     fixedValueFvPatchVectorField(ptf, p, iF, mapper),
63     pName_(ptf.pName_),
64     cyclicPatchName_(ptf.cyclicPatchName_),
65     cyclicPatchLabel_(ptf.cyclicPatchLabel_),
66     initWallSf_(ptf.initWallSf_),
67     initCyclicSf_(ptf.initCyclicSf_),
68     openFraction_(ptf.openFraction_),
69     openFractionDelta_(ptf.openFractionDelta_),
70     curTimeIndex_(-1)
74 Foam::activeBaffleVelocityFvPatchVectorField::
75 activeBaffleVelocityFvPatchVectorField
77     const fvPatch& p,
78     const DimensionedField<vector, volMesh>& iF,
79     const dictionary& dict
82     fixedValueFvPatchVectorField(p, iF),
83     pName_("p"),
84     cyclicPatchName_(dict.lookup("cyclicPatch")),
85     cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
86     initWallSf_(p.Sf()),
87     initCyclicSf_(p.boundaryMesh()[cyclicPatchLabel_].Sf()),
88     openFraction_(readScalar(dict.lookup("openFraction"))),
89     openFractionDelta_(readScalar(dict.lookup("openFractionDelta"))),
90     curTimeIndex_(-1)
92     fvPatchVectorField::operator=(vector::zero);
94     if (dict.found("p"))
95     {
96         dict.lookup("p") >> pName_;
97     }
101 Foam::activeBaffleVelocityFvPatchVectorField::
102 activeBaffleVelocityFvPatchVectorField
104     const activeBaffleVelocityFvPatchVectorField& ptf
107     fixedValueFvPatchVectorField(ptf),
108     pName_(ptf.pName_),
109     cyclicPatchName_(ptf.cyclicPatchName_),
110     cyclicPatchLabel_(ptf.cyclicPatchLabel_),
111     initWallSf_(ptf.initWallSf_),
112     initCyclicSf_(ptf.initCyclicSf_),
113     openFraction_(ptf.openFraction_),
114     openFractionDelta_(ptf.openFractionDelta_),
115     curTimeIndex_(-1)
119 Foam::activeBaffleVelocityFvPatchVectorField::
120 activeBaffleVelocityFvPatchVectorField
122     const activeBaffleVelocityFvPatchVectorField& ptf,
123     const DimensionedField<vector, volMesh>& iF
126     fixedValueFvPatchVectorField(ptf, iF),
127     pName_(ptf.pName_),
128     cyclicPatchName_(ptf.cyclicPatchName_),
129     cyclicPatchLabel_(ptf.cyclicPatchLabel_),
130     initWallSf_(ptf.initWallSf_),
131     initCyclicSf_(ptf.initCyclicSf_),
132     openFraction_(ptf.openFraction_),
133     openFractionDelta_(ptf.openFractionDelta_),
134     curTimeIndex_(-1)
138 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
140 void Foam::activeBaffleVelocityFvPatchVectorField::autoMap
142     const fvPatchFieldMapper& m
145     fixedValueFvPatchVectorField::autoMap(m);
146     initWallSf_.autoMap(m);
147     initCyclicSf_.autoMap(m);
150 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
152     const fvPatchVectorField& ptf,
153     const labelList& addr
156     fixedValueFvPatchVectorField::rmap(ptf, addr);
158     const activeBaffleVelocityFvPatchVectorField& tiptf =
159         refCast<const activeBaffleVelocityFvPatchVectorField>(ptf);
161     initWallSf_.rmap(tiptf.initWallSf_, addr);
162     initCyclicSf_.rmap(tiptf.initCyclicSf_, addr);
166 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
168     if (updated())
169     {
170         return;
171     }
173     // Execute the change to the openFraction only once per time-step
174     if (curTimeIndex_ != this->db().time().timeIndex())
175     {
176         const volScalarField& p = db().lookupObject<volScalarField>
177         (
178             pName_
179         );
181         const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
182         const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
183         const vectorField& cyclicSf = cyclicPatch.Sf();
184         label nCyclicFaces = cyclicFaceCells.size();
185         label nCyclicFacesPerSide = nCyclicFaces/2;
187         scalar forceDiff = 0;
189         for (label facei=0; facei<nCyclicFacesPerSide; facei++)
190         {
191             forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
192         }
194         for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
195         {
196             forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
197         }
199         openFraction_ =
200             max(min(
201                 openFraction_ + openFractionDelta_*sign(forceDiff),
202               1), 0);
204         Info<< "openFraction = " << openFraction_ << endl;
206         vectorField::subField Sfw = patch().patch().faceAreas();
207         vectorField newSfw = (1 - openFraction_)*initWallSf_;
208         forAll(Sfw, facei)
209         {
210             Sfw[facei] = newSfw[facei];
211         }
213         const_cast<vectorField&>(cyclicSf) = openFraction_*initCyclicSf_;
215         curTimeIndex_ = this->db().time().timeIndex();
216     }
218     fixedValueFvPatchVectorField::updateCoeffs();
222 void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
224     fvPatchVectorField::write(os);
225     os.writeKeyword("cyclicPatch")
226         << cyclicPatchName_ << token::END_STATEMENT << nl;
227     os.writeKeyword("openFraction")
228         << openFraction_ << token::END_STATEMENT << nl;
229     os.writeKeyword("openFractionDelta")
230         << openFractionDelta_ << token::END_STATEMENT << nl;
231     os.writeKeyword("p")
232         << pName_ << token::END_STATEMENT << nl;
233     writeEntry("value", os);
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 namespace Foam
241     makePatchTypeField
242     (
243         fvPatchVectorField,
244         activeBaffleVelocityFvPatchVectorField
245     );
248 // ************************************************************************* //