1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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
37 const DimensionedField<vector, volMesh>& iF
40 fixedValueFvPatchVectorField(p, iF),
43 cyclicPatchLabel_(-1),
49 maxOpenFractionDelta_(0),
54 Foam::activeBaffleVelocityFvPatchVectorField::
55 activeBaffleVelocityFvPatchVectorField
57 const activeBaffleVelocityFvPatchVectorField& ptf,
59 const DimensionedField<vector, volMesh>& iF,
60 const fvPatchFieldMapper& mapper
63 fixedValueFvPatchVectorField(ptf, p, iF, mapper),
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_),
77 Foam::activeBaffleVelocityFvPatchVectorField::
78 activeBaffleVelocityFvPatchVectorField
81 const DimensionedField<vector, volMesh>& iF,
82 const dictionary& dict
85 fixedValueFvPatchVectorField(p, iF),
87 cyclicPatchName_(dict.lookup("cyclicPatch")),
88 cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
89 orientation_(readLabel(dict.lookup("orientation"))),
91 initCyclicSf_(p.boundaryMesh()[cyclicPatchLabel_].Sf()),
92 openFraction_(readScalar(dict.lookup("openFraction"))),
93 openingTime_(readScalar(dict.lookup("openingTime"))),
94 maxOpenFractionDelta_(readScalar(dict.lookup("maxOpenFractionDelta"))),
97 fvPatchVectorField::operator=(vector::zero);
101 dict.lookup("p") >> pName_;
106 Foam::activeBaffleVelocityFvPatchVectorField::
107 activeBaffleVelocityFvPatchVectorField
109 const activeBaffleVelocityFvPatchVectorField& ptf
112 fixedValueFvPatchVectorField(ptf),
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_),
126 Foam::activeBaffleVelocityFvPatchVectorField::
127 activeBaffleVelocityFvPatchVectorField
129 const activeBaffleVelocityFvPatchVectorField& ptf,
130 const DimensionedField<vector, volMesh>& iF
133 fixedValueFvPatchVectorField(ptf, iF),
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_),
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
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
162 const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
163 initWallSf_ = patch().patchSlice(areas);
164 initCyclicSf_ = patch().boundaryMesh()
170 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
172 const fvPatchVectorField& ptf,
173 const labelList& addr
176 fixedValueFvPatchVectorField::rmap(ptf, addr);
179 const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
180 initWallSf_ = vectorField(patch().patchSlice(areas));
181 initCyclicSf_ = patch().boundaryMesh()
188 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
195 // Execute the change to the openFraction only once per time-step
196 if (curTimeIndex_ != this->db().time().timeIndex())
198 const volScalarField& p = db().lookupObject<volScalarField>
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++)
212 forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
215 for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
217 forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
225 this->db().time().deltaT().value()/openingTime_,
226 maxOpenFractionDelta_
228 *(orientation_*sign(forceDiff)),
231 Info<< "openFraction = " << openFraction_ << endl;
233 vectorField::subField Sfw = patch().patch().faceAreas();
234 vectorField newSfw = (1 - openFraction_)*initWallSf_;
237 Sfw[facei] = newSfw[facei];
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();
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;
267 << pName_ << token::END_STATEMENT << nl;
268 writeEntry("value", os);
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 activeBaffleVelocityFvPatchVectorField
283 // ************************************************************************* //