1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "activePressureForceBaffleVelocityFvPatchVectorField.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 #include "cyclicFvPatch.H"
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 Foam::activePressureForceBaffleVelocityFvPatchVectorField::
35 activePressureForceBaffleVelocityFvPatchVectorField
38 const DimensionedField<vector, volMesh>& iF
41 fixedValueFvPatchVectorField(p, iF),
44 cyclicPatchLabel_(-1),
51 maxOpenFractionDelta_(0),
53 minThresholdValue_(0),
59 Foam::activePressureForceBaffleVelocityFvPatchVectorField::
60 activePressureForceBaffleVelocityFvPatchVectorField
62 const activePressureForceBaffleVelocityFvPatchVectorField& ptf,
64 const DimensionedField<vector, volMesh>& iF,
65 const fvPatchFieldMapper& mapper
68 fixedValueFvPatchVectorField(ptf, p, iF, mapper),
70 cyclicPatchName_(ptf.cyclicPatchName_),
71 cyclicPatchLabel_(ptf.cyclicPatchLabel_),
72 orientation_(ptf.orientation_),
73 initWallSf_(ptf.initWallSf_),
74 initCyclicSf_(ptf.initCyclicSf_),
75 nbrCyclicSf_(ptf.nbrCyclicSf_),
76 openFraction_(ptf.openFraction_),
77 openingTime_(ptf.openingTime_),
78 maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
80 minThresholdValue_(ptf.minThresholdValue_),
82 baffleActivated_(ptf.baffleActivated_)
86 Foam::activePressureForceBaffleVelocityFvPatchVectorField::
87 activePressureForceBaffleVelocityFvPatchVectorField
90 const DimensionedField<vector, volMesh>& iF,
91 const dictionary& dict
94 fixedValueFvPatchVectorField(p, iF),
96 cyclicPatchName_(dict.lookup("cyclicPatch")),
97 cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
98 orientation_(readLabel(dict.lookup("orientation"))),
102 openFraction_(readScalar(dict.lookup("openFraction"))),
103 openingTime_(readScalar(dict.lookup("openingTime"))),
104 maxOpenFractionDelta_(readScalar(dict.lookup("maxOpenFractionDelta"))),
106 minThresholdValue_(readScalar(dict.lookup("minThresholdValue"))),
107 fBased_(readBool(dict.lookup("forceBased"))),
110 fvPatchVectorField::operator=(vector::zero);
114 initWallSf_ = p.Sf();
115 initCyclicSf_ = p.boundaryMesh()[cyclicPatchLabel_].Sf();
116 nbrCyclicSf_ = refCast<const cyclicFvPatch>
118 p.boundaryMesh()[cyclicPatchLabel_]
119 ).neighbFvPatch().Sf();
124 dict.lookup("p") >> pName_;
129 Foam::activePressureForceBaffleVelocityFvPatchVectorField::
130 activePressureForceBaffleVelocityFvPatchVectorField
132 const activePressureForceBaffleVelocityFvPatchVectorField& ptf
135 fixedValueFvPatchVectorField(ptf),
137 cyclicPatchName_(ptf.cyclicPatchName_),
138 cyclicPatchLabel_(ptf.cyclicPatchLabel_),
139 orientation_(ptf.orientation_),
140 initWallSf_(ptf.initWallSf_),
141 initCyclicSf_(ptf.initCyclicSf_),
142 nbrCyclicSf_(ptf.nbrCyclicSf_),
143 openFraction_(ptf.openFraction_),
144 openingTime_(ptf.openingTime_),
145 maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
147 minThresholdValue_(ptf.minThresholdValue_),
148 fBased_(ptf.fBased_),
149 baffleActivated_(ptf.baffleActivated_)
153 Foam::activePressureForceBaffleVelocityFvPatchVectorField::
154 activePressureForceBaffleVelocityFvPatchVectorField
156 const activePressureForceBaffleVelocityFvPatchVectorField& ptf,
157 const DimensionedField<vector, volMesh>& iF
160 fixedValueFvPatchVectorField(ptf, iF),
162 cyclicPatchName_(ptf.cyclicPatchName_),
163 cyclicPatchLabel_(ptf.cyclicPatchLabel_),
164 orientation_(ptf.orientation_),
165 initWallSf_(ptf.initWallSf_),
166 initCyclicSf_(ptf.initCyclicSf_),
167 nbrCyclicSf_(ptf.nbrCyclicSf_),
168 openFraction_(ptf.openFraction_),
169 openingTime_(ptf.openingTime_),
170 maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
172 minThresholdValue_(ptf.minThresholdValue_),
173 fBased_(ptf.fBased_),
174 baffleActivated_(ptf.baffleActivated_)
178 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
180 void Foam::activePressureForceBaffleVelocityFvPatchVectorField::autoMap
182 const fvPatchFieldMapper& m
185 fixedValueFvPatchVectorField::autoMap(m);
187 //- Note: cannot map field from cyclic patch anyway so just recalculate
188 // Areas should be consistent when doing autoMap except in case of
190 //- Note: we don't want to use Sf here since triggers rebuilding of
191 // fvMesh::S() which will give problems when mapped (since already
193 forAll (patch().boundaryMesh().mesh().faceAreas(), i)
195 if (mag(patch().boundaryMesh().mesh().faceAreas()[i]) == 0)
197 Info << "faceArea[active] "<< i << endl;
200 if (patch().size() > 0)
202 const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
203 initWallSf_ = patch().patchSlice(areas);
204 initCyclicSf_ = patch().boundaryMesh()
208 nbrCyclicSf_ = refCast<const cyclicFvPatch>
210 patch().boundaryMesh()
214 ).neighbFvPatch().patch().patchSlice(areas);
218 void Foam::activePressureForceBaffleVelocityFvPatchVectorField::rmap
220 const fvPatchVectorField& ptf,
221 const labelList& addr
224 fixedValueFvPatchVectorField::rmap(ptf, addr);
227 const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
228 initWallSf_ = patch().patchSlice(areas);
229 initCyclicSf_ = patch().boundaryMesh()
233 nbrCyclicSf_ = refCast<const cyclicFvPatch>
235 patch().boundaryMesh()
239 ).neighbFvPatch().patch().patchSlice(areas);
243 void Foam::activePressureForceBaffleVelocityFvPatchVectorField::updateCoeffs()
249 // Execute the change to the openFraction only once per time-step
250 if (curTimeIndex_ != this->db().time().timeIndex())
252 const volScalarField& p = db().lookupObject<volScalarField>
257 const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
258 const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
259 const fvPatch& nbrPatch = refCast<const cyclicFvPatch>
264 const labelList& nbrFaceCells = nbrPatch.patch().faceCells();
266 scalar valueDiff = 0;
271 forAll(cyclicFaceCells, facei)
273 valueDiff +=p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
277 forAll(nbrFaceCells, facei)
279 valueDiff -=p[nbrFaceCells[facei]]*mag(initCyclicSf_[facei]);
282 else //pressure based
284 forAll(cyclicFaceCells, facei)
286 valueDiff += p[cyclicFaceCells[facei]];
289 forAll(nbrFaceCells, facei)
291 valueDiff -= p[nbrFaceCells[facei]];
295 if ((mag(valueDiff) > mag(minThresholdValue_) || baffleActivated_))
303 this->db().time().deltaT().value()/openingTime_,
304 maxOpenFractionDelta_
311 baffleActivated_ = true;
315 openFraction_ = max(min(1 - 1e-6, openFraction_), 1e-6);
318 Info<< "Open fraction = " << openFraction_ << endl;
319 Info<< "Pressure difference = " << valueDiff << endl;
321 vectorField::subField Sfw = patch().patch().faceAreas();
322 vectorField newSfw((1 - openFraction_)*initWallSf_);
325 Sfw[facei] = newSfw[facei];
327 const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf());
329 // Update owner side of cyclic
330 const_cast<vectorField&>(cyclicPatch.Sf()) =
331 openFraction_*initCyclicSf_;
333 const_cast<scalarField&>(cyclicPatch.magSf()) =
334 mag(cyclicPatch.Sf());
336 // Update neighbour side of cyclic
337 const_cast<vectorField&>(nbrPatch.Sf()) =
338 openFraction_*nbrCyclicSf_;
340 const_cast<scalarField&>(nbrPatch.magSf()) =
343 curTimeIndex_ = this->db().time().timeIndex();
346 fixedValueFvPatchVectorField::updateCoeffs();
350 void Foam::activePressureForceBaffleVelocityFvPatchVectorField::
351 write(Ostream& os) const
353 fvPatchVectorField::write(os);
354 os.writeKeyword("cyclicPatch")
355 << cyclicPatchName_ << token::END_STATEMENT << nl;
356 os.writeKeyword("orientation")
357 << orientation_ << token::END_STATEMENT << nl;
358 os.writeKeyword("openingTime")
359 << openingTime_ << token::END_STATEMENT << nl;
360 os.writeKeyword("maxOpenFractionDelta")
361 << maxOpenFractionDelta_ << token::END_STATEMENT << nl;
362 os.writeKeyword("openFraction")
363 << openFraction_ << token::END_STATEMENT << nl;
365 << pName_ << token::END_STATEMENT << nl;
366 os.writeKeyword("minThresholdValue")
367 << minThresholdValue_ << token::END_STATEMENT << nl;
368 os.writeKeyword("forceBased")
369 << fBased_ << token::END_STATEMENT << nl;
370 writeEntry("value", os);
374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
381 activePressureForceBaffleVelocityFvPatchVectorField
385 // ************************************************************************* //