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),
48 openFractionDelta_(0),
53 Foam::activeBaffleVelocityFvPatchVectorField::
54 activeBaffleVelocityFvPatchVectorField
56 const activeBaffleVelocityFvPatchVectorField& ptf,
58 const DimensionedField<vector, volMesh>& iF,
59 const fvPatchFieldMapper& mapper
62 fixedValueFvPatchVectorField(ptf, p, iF, mapper),
64 cyclicPatchName_(ptf.cyclicPatchName_),
65 cyclicPatchLabel_(ptf.cyclicPatchLabel_),
66 initWallSf_(ptf.initWallSf_),
67 initCyclicSf_(ptf.initCyclicSf_),
68 openFraction_(ptf.openFraction_),
69 openFractionDelta_(ptf.openFractionDelta_),
74 Foam::activeBaffleVelocityFvPatchVectorField::
75 activeBaffleVelocityFvPatchVectorField
78 const DimensionedField<vector, volMesh>& iF,
79 const dictionary& dict
82 fixedValueFvPatchVectorField(p, iF),
84 cyclicPatchName_(dict.lookup("cyclicPatch")),
85 cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
87 initCyclicSf_(p.boundaryMesh()[cyclicPatchLabel_].Sf()),
88 openFraction_(readScalar(dict.lookup("openFraction"))),
89 openFractionDelta_(readScalar(dict.lookup("openFractionDelta"))),
92 fvPatchVectorField::operator=(vector::zero);
96 dict.lookup("p") >> pName_;
101 Foam::activeBaffleVelocityFvPatchVectorField::
102 activeBaffleVelocityFvPatchVectorField
104 const activeBaffleVelocityFvPatchVectorField& ptf
107 fixedValueFvPatchVectorField(ptf),
109 cyclicPatchName_(ptf.cyclicPatchName_),
110 cyclicPatchLabel_(ptf.cyclicPatchLabel_),
111 initWallSf_(ptf.initWallSf_),
112 initCyclicSf_(ptf.initCyclicSf_),
113 openFraction_(ptf.openFraction_),
114 openFractionDelta_(ptf.openFractionDelta_),
119 Foam::activeBaffleVelocityFvPatchVectorField::
120 activeBaffleVelocityFvPatchVectorField
122 const activeBaffleVelocityFvPatchVectorField& ptf,
123 const DimensionedField<vector, volMesh>& iF
126 fixedValueFvPatchVectorField(ptf, iF),
128 cyclicPatchName_(ptf.cyclicPatchName_),
129 cyclicPatchLabel_(ptf.cyclicPatchLabel_),
130 initWallSf_(ptf.initWallSf_),
131 initCyclicSf_(ptf.initCyclicSf_),
132 openFraction_(ptf.openFraction_),
133 openFractionDelta_(ptf.openFractionDelta_),
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
140 void Foam::activeBaffleVelocityFvPatchVectorField::autoMap
142 const fvPatchFieldMapper& m
145 fixedValueFvPatchVectorField::autoMap(m);
146 initWallSf_.autoMap(m);
147 initCyclicSf_.autoMap(m);
150 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
152 const fvPatchVectorField& ptf,
153 const labelList& addr
156 fixedValueFvPatchVectorField::rmap(ptf, addr);
158 const activeBaffleVelocityFvPatchVectorField& tiptf =
159 refCast<const activeBaffleVelocityFvPatchVectorField>(ptf);
161 initWallSf_.rmap(tiptf.initWallSf_, addr);
162 initCyclicSf_.rmap(tiptf.initCyclicSf_, addr);
166 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
173 // Execute the change to the openFraction only once per time-step
174 if (curTimeIndex_ != this->db().time().timeIndex())
176 const volScalarField& p = db().lookupObject<volScalarField>
181 const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
182 const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
183 const vectorField& cyclicSf = cyclicPatch.Sf();
184 label nCyclicFaces = cyclicFaceCells.size();
185 label nCyclicFacesPerSide = nCyclicFaces/2;
187 scalar forceDiff = 0;
189 for (label facei=0; facei<nCyclicFacesPerSide; facei++)
191 forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
194 for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
196 forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
201 openFraction_ + openFractionDelta_*sign(forceDiff),
204 Info<< "openFraction = " << openFraction_ << endl;
206 vectorField::subField Sfw = patch().patch().faceAreas();
207 vectorField newSfw = (1 - openFraction_)*initWallSf_;
210 Sfw[facei] = newSfw[facei];
213 const_cast<vectorField&>(cyclicSf) = openFraction_*initCyclicSf_;
215 curTimeIndex_ = this->db().time().timeIndex();
218 fixedValueFvPatchVectorField::updateCoeffs();
222 void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
224 fvPatchVectorField::write(os);
225 os.writeKeyword("cyclicPatch")
226 << cyclicPatchName_ << token::END_STATEMENT << nl;
227 os.writeKeyword("openFraction")
228 << openFraction_ << token::END_STATEMENT << nl;
229 os.writeKeyword("openFractionDelta")
230 << openFractionDelta_ << token::END_STATEMENT << nl;
232 << pName_ << token::END_STATEMENT << nl;
233 writeEntry("value", os);
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 activeBaffleVelocityFvPatchVectorField
248 // ************************************************************************* //