corrected mapping
[OpenFOAM-1.5.x.git] / src / finiteVolume / fields / fvPatchFields / derived / activeBaffleVelocity / activeBaffleVelocityFvPatchVectorField.C
blobc090d5296877c2a92d760bacb568971e0117ed4f
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     initWallSf_ = patch().Sf();
161     initCyclicSf_ = patch().boundaryMesh()[cyclicPatchLabel_].Sf();
164 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
166     const fvPatchVectorField& ptf,
167     const labelList& addr
170     fixedValueFvPatchVectorField::rmap(ptf, addr);
172     //- Note: cannot map field from cyclic patch anyway so just recalculate
173     //  Areas should be consistent when doing rmap (mainly reconstructPar)
174     initWallSf_ = patch().Sf();
175     initCyclicSf_ = patch().boundaryMesh()[cyclicPatchLabel_].Sf();
179 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
181     if (updated())
182     {
183         return;
184     }
186     // Execute the change to the openFraction only once per time-step
187     if (curTimeIndex_ != this->db().time().timeIndex())
188     {
189         const volScalarField& p = db().lookupObject<volScalarField>
190         (
191             pName_
192         );
194         const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
195         const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
196         label nCyclicFaces = cyclicFaceCells.size();
197         label nCyclicFacesPerSide = nCyclicFaces/2;
199         scalar forceDiff = 0;
201         for (label facei=0; facei<nCyclicFacesPerSide; facei++)
202         {
203             forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
204         }
206         for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
207         {
208             forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
209         }
211         openFraction_ =
212             max(min(
213                 openFraction_
214               + max
215                 (
216                     this->db().time().deltaT().value()/openingTime_,
217                     maxOpenFractionDelta_
218                 )
219                *(orientation_*sign(forceDiff)),
220               1 - 1e-6), 1e-6);
222         Info<< "openFraction = " << openFraction_ << endl;
224         vectorField::subField Sfw = patch().patch().faceAreas();
225         vectorField newSfw = (1 - openFraction_)*initWallSf_;
226         forAll(Sfw, facei)
227         {
228             Sfw[facei] = newSfw[facei];
229         }
230         const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf());
232         const_cast<vectorField&>(cyclicPatch.Sf()) =
233             openFraction_*initCyclicSf_;
234         const_cast<scalarField&>(cyclicPatch.magSf()) =
235             mag(cyclicPatch.Sf());
237         curTimeIndex_ = this->db().time().timeIndex();
238     }
240     fixedValueFvPatchVectorField::updateCoeffs();
244 void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
246     fvPatchVectorField::write(os);
247     os.writeKeyword("cyclicPatch")
248         << cyclicPatchName_ << token::END_STATEMENT << nl;
249     os.writeKeyword("orientation")
250         << orientation_ << token::END_STATEMENT << nl;
251     os.writeKeyword("openingTime")
252         << openingTime_ << token::END_STATEMENT << nl;
253     os.writeKeyword("maxOpenFractionDelta")
254         << maxOpenFractionDelta_ << token::END_STATEMENT << nl;
255     os.writeKeyword("openFraction")
256         << openFraction_ << token::END_STATEMENT << nl;
257     os.writeKeyword("p")
258         << pName_ << token::END_STATEMENT << nl;
259     writeEntry("value", os);
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 namespace Foam
267     makePatchTypeField
268     (
269         fvPatchVectorField,
270         activeBaffleVelocityFvPatchVectorField
271     );
274 // ************************************************************************* //