Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / finiteVolume / fields / fvPatchFields / derived / activeBaffleVelocity / activeBaffleVelocityFvPatchVectorField.C
blobdaa7e4e4df087d88bc889f615035bfa8efc90d8d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "activeBaffleVelocityFvPatchVectorField.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
31 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
33 Foam::activeBaffleVelocityFvPatchVectorField::
34 activeBaffleVelocityFvPatchVectorField
36     const fvPatch& p,
37     const DimensionedField<vector, volMesh>& iF
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)
54 Foam::activeBaffleVelocityFvPatchVectorField::
55 activeBaffleVelocityFvPatchVectorField
57     const activeBaffleVelocityFvPatchVectorField& ptf,
58     const fvPatch& p,
59     const DimensionedField<vector, volMesh>& iF,
60     const fvPatchFieldMapper& mapper
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)
77 Foam::activeBaffleVelocityFvPatchVectorField::
78 activeBaffleVelocityFvPatchVectorField
80     const fvPatch& p,
81     const DimensionedField<vector, volMesh>& iF,
82     const dictionary& dict
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)
97     fvPatchVectorField::operator=(vector::zero);
99     if (dict.found("p"))
100     {
101         dict.lookup("p") >> pName_;
102     }
106 Foam::activeBaffleVelocityFvPatchVectorField::
107 activeBaffleVelocityFvPatchVectorField
109     const activeBaffleVelocityFvPatchVectorField& ptf
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)
126 Foam::activeBaffleVelocityFvPatchVectorField::
127 activeBaffleVelocityFvPatchVectorField
129     const activeBaffleVelocityFvPatchVectorField& ptf,
130     const DimensionedField<vector, volMesh>& iF
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)
147 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
149 void Foam::activeBaffleVelocityFvPatchVectorField::autoMap
151     const fvPatchFieldMapper& m
154     fixedValueFvPatchVectorField::autoMap(m);
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_ = patch().patchSlice(areas);
164     initCyclicSf_ = patch().boundaryMesh()
165     [
166         cyclicPatchLabel_
167     ].patchSlice(areas);
170 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
172     const fvPatchVectorField& ptf,
173     const labelList& addr
176     fixedValueFvPatchVectorField::rmap(ptf, addr);
178     // See autoMap.
179     const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
180     initWallSf_ = vectorField(patch().patchSlice(areas));
181     initCyclicSf_ = patch().boundaryMesh()
182     [
183         cyclicPatchLabel_
184     ].patchSlice(areas);
188 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
190     if (updated())
191     {
192         return;
193     }
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         );
203         const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
204         const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
205         label nCyclicFaces = cyclicFaceCells.size();
206         label nCyclicFacesPerSide = nCyclicFaces/2;
208         scalar forceDiff = 0;
210         for (label facei=0; facei<nCyclicFacesPerSide; facei++)
211         {
212             forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
213         }
215         for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
216         {
217             forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
218         }
220         openFraction_ =
221             max(min(
222                 openFraction_
223               + max
224                 (
225                     this->db().time().deltaT().value()/openingTime_,
226                     maxOpenFractionDelta_
227                 )
228                *(orientation_*sign(forceDiff)),
229               1 - 1e-6), 1e-6);
231         Info<< "openFraction = " << openFraction_ << endl;
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());
241         const_cast<vectorField&>(cyclicPatch.Sf()) =
242             openFraction_*initCyclicSf_;
243         const_cast<scalarField&>(cyclicPatch.magSf()) =
244             mag(cyclicPatch.Sf());
246         curTimeIndex_ = this->db().time().timeIndex();
247     }
249     fixedValueFvPatchVectorField::updateCoeffs();
253 void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
255     fvPatchVectorField::write(os);
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);
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 namespace Foam
276     makePatchTypeField
277     (
278         fvPatchVectorField,
279         activeBaffleVelocityFvPatchVectorField
280     );
283 // ************************************************************************* //