1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 //- Note: we don't want to use Sf here since triggers rebuilding of
161 // fvMesh::S() which will give problems when mapped (since already
163 const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
164 initWallSf_ = patch().patchSlice(areas);
165 initCyclicSf_ = patch().boundaryMesh()
171 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
173 const fvPatchVectorField& ptf,
174 const labelList& addr
177 fixedValueFvPatchVectorField::rmap(ptf, addr);
180 const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
181 initWallSf_ = vectorField(patch().patchSlice(areas));
182 initCyclicSf_ = patch().boundaryMesh()
189 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
196 // Execute the change to the openFraction only once per time-step
197 if (curTimeIndex_ != this->db().time().timeIndex())
199 const volScalarField& p = db().lookupObject<volScalarField>
204 const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
205 const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
206 label nCyclicFaces = cyclicFaceCells.size();
207 label nCyclicFacesPerSide = nCyclicFaces/2;
209 scalar forceDiff = 0;
211 for (label facei=0; facei<nCyclicFacesPerSide; facei++)
213 forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
216 for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
218 forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
226 this->db().time().deltaT().value()/openingTime_,
227 maxOpenFractionDelta_
229 *(orientation_*sign(forceDiff)),
232 Info<< "openFraction = " << openFraction_ << endl;
234 vectorField::subField Sfw = patch().patch().faceAreas();
235 vectorField newSfw = (1 - openFraction_)*initWallSf_;
238 Sfw[facei] = newSfw[facei];
240 const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf());
242 const_cast<vectorField&>(cyclicPatch.Sf()) =
243 openFraction_*initCyclicSf_;
244 const_cast<scalarField&>(cyclicPatch.magSf()) =
245 mag(cyclicPatch.Sf());
247 curTimeIndex_ = this->db().time().timeIndex();
250 fixedValueFvPatchVectorField::updateCoeffs();
254 void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
256 fvPatchVectorField::write(os);
257 os.writeKeyword("cyclicPatch")
258 << cyclicPatchName_ << token::END_STATEMENT << nl;
259 os.writeKeyword("orientation")
260 << orientation_ << token::END_STATEMENT << nl;
261 os.writeKeyword("openingTime")
262 << openingTime_ << token::END_STATEMENT << nl;
263 os.writeKeyword("maxOpenFractionDelta")
264 << maxOpenFractionDelta_ << token::END_STATEMENT << nl;
265 os.writeKeyword("openFraction")
266 << openFraction_ << token::END_STATEMENT << nl;
268 << pName_ << token::END_STATEMENT << nl;
269 writeEntry("value", os);
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 activeBaffleVelocityFvPatchVectorField
284 // ************************************************************************* //