1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
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
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
38 const DimensionedField<vector, volMesh>& iF
41 fixedValueFvPatchVectorField(p, iF),
44 cyclicPatchLabel_(-1),
50 maxOpenFractionDelta_(0),
55 Foam::activeBaffleVelocityFvPatchVectorField::
56 activeBaffleVelocityFvPatchVectorField
58 const activeBaffleVelocityFvPatchVectorField& ptf,
60 const DimensionedField<vector, volMesh>& iF,
61 const fvPatchFieldMapper& mapper
64 fixedValueFvPatchVectorField(ptf, p, iF, mapper),
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_),
78 Foam::activeBaffleVelocityFvPatchVectorField::
79 activeBaffleVelocityFvPatchVectorField
82 const DimensionedField<vector, volMesh>& iF,
83 const dictionary& dict
86 fixedValueFvPatchVectorField(p, iF),
88 cyclicPatchName_(dict.lookup("cyclicPatch")),
89 cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
90 orientation_(readLabel(dict.lookup("orientation"))),
92 initCyclicSf_(p.boundaryMesh()[cyclicPatchLabel_].Sf()),
93 openFraction_(readScalar(dict.lookup("openFraction"))),
94 openingTime_(readScalar(dict.lookup("openingTime"))),
95 maxOpenFractionDelta_(readScalar(dict.lookup("maxOpenFractionDelta"))),
98 fvPatchVectorField::operator=(vector::zero);
102 dict.lookup("p") >> pName_;
107 Foam::activeBaffleVelocityFvPatchVectorField::
108 activeBaffleVelocityFvPatchVectorField
110 const activeBaffleVelocityFvPatchVectorField& ptf
113 fixedValueFvPatchVectorField(ptf),
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_),
127 Foam::activeBaffleVelocityFvPatchVectorField::
128 activeBaffleVelocityFvPatchVectorField
130 const activeBaffleVelocityFvPatchVectorField& ptf,
131 const DimensionedField<vector, volMesh>& iF
134 fixedValueFvPatchVectorField(ptf, iF),
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_),
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
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()
186 // Execute the change to the openFraction only once per time-step
187 if (curTimeIndex_ != this->db().time().timeIndex())
189 const volScalarField& p = db().lookupObject<volScalarField>
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++)
203 forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
206 for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
208 forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
216 this->db().time().deltaT().value()/openingTime_,
217 maxOpenFractionDelta_
219 *(orientation_*sign(forceDiff)),
222 Info<< "openFraction = " << openFraction_ << endl;
224 vectorField::subField Sfw = patch().patch().faceAreas();
225 vectorField newSfw = (1 - openFraction_)*initWallSf_;
228 Sfw[facei] = newSfw[facei];
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();
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;
258 << pName_ << token::END_STATEMENT << nl;
259 writeEntry("value", os);
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 activeBaffleVelocityFvPatchVectorField
274 // ************************************************************************* //