OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

activeBaffleVelocityFvPatchVectorField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "activeBaffleVelocityFvPatchVectorField.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 #include "volFields.H"
00030 #include "surfaceFields.H"
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 Foam::activeBaffleVelocityFvPatchVectorField::
00035 activeBaffleVelocityFvPatchVectorField
00036 (
00037     const fvPatch& p,
00038     const DimensionedField<vector, volMesh>& iF
00039 )
00040 :
00041     fixedValueFvPatchVectorField(p, iF),
00042     pName_("p"),
00043     cyclicPatchName_(),
00044     cyclicPatchLabel_(-1),
00045     orientation_(1),
00046     initWallSf_(0),
00047     initCyclicSf_(0),
00048     openFraction_(0),
00049     openingTime_(0),
00050     maxOpenFractionDelta_(0),
00051     curTimeIndex_(-1)
00052 {}
00053 
00054 
00055 Foam::activeBaffleVelocityFvPatchVectorField::
00056 activeBaffleVelocityFvPatchVectorField
00057 (
00058     const activeBaffleVelocityFvPatchVectorField& ptf,
00059     const fvPatch& p,
00060     const DimensionedField<vector, volMesh>& iF,
00061     const fvPatchFieldMapper& mapper
00062 )
00063 :
00064     fixedValueFvPatchVectorField(ptf, p, iF, mapper),
00065     pName_(ptf.pName_),
00066     cyclicPatchName_(ptf.cyclicPatchName_),
00067     cyclicPatchLabel_(ptf.cyclicPatchLabel_),
00068     orientation_(ptf.orientation_),
00069     initWallSf_(ptf.initWallSf_),
00070     initCyclicSf_(ptf.initCyclicSf_),
00071     openFraction_(ptf.openFraction_),
00072     openingTime_(ptf.openingTime_),
00073     maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
00074     curTimeIndex_(-1)
00075 {}
00076 
00077 
00078 Foam::activeBaffleVelocityFvPatchVectorField::
00079 activeBaffleVelocityFvPatchVectorField
00080 (
00081     const fvPatch& p,
00082     const DimensionedField<vector, volMesh>& iF,
00083     const dictionary& dict
00084 )
00085 :
00086     fixedValueFvPatchVectorField(p, iF),
00087     pName_("p"),
00088     cyclicPatchName_(dict.lookup("cyclicPatch")),
00089     cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
00090     orientation_(readLabel(dict.lookup("orientation"))),
00091     initWallSf_(p.Sf()),
00092     initCyclicSf_(p.boundaryMesh()[cyclicPatchLabel_].Sf()),
00093     openFraction_(readScalar(dict.lookup("openFraction"))),
00094     openingTime_(readScalar(dict.lookup("openingTime"))),
00095     maxOpenFractionDelta_(readScalar(dict.lookup("maxOpenFractionDelta"))),
00096     curTimeIndex_(-1)
00097 {
00098     fvPatchVectorField::operator=(vector::zero);
00099 
00100     if (dict.found("p"))
00101     {
00102         dict.lookup("p") >> pName_;
00103     }
00104 }
00105 
00106 
00107 Foam::activeBaffleVelocityFvPatchVectorField::
00108 activeBaffleVelocityFvPatchVectorField
00109 (
00110     const activeBaffleVelocityFvPatchVectorField& ptf
00111 )
00112 :
00113     fixedValueFvPatchVectorField(ptf),
00114     pName_(ptf.pName_),
00115     cyclicPatchName_(ptf.cyclicPatchName_),
00116     cyclicPatchLabel_(ptf.cyclicPatchLabel_),
00117     orientation_(ptf.orientation_),
00118     initWallSf_(ptf.initWallSf_),
00119     initCyclicSf_(ptf.initCyclicSf_),
00120     openFraction_(ptf.openFraction_),
00121     openingTime_(ptf.openingTime_),
00122     maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
00123     curTimeIndex_(-1)
00124 {}
00125 
00126 
00127 Foam::activeBaffleVelocityFvPatchVectorField::
00128 activeBaffleVelocityFvPatchVectorField
00129 (
00130     const activeBaffleVelocityFvPatchVectorField& ptf,
00131     const DimensionedField<vector, volMesh>& iF
00132 )
00133 :
00134     fixedValueFvPatchVectorField(ptf, iF),
00135     pName_(ptf.pName_),
00136     cyclicPatchName_(ptf.cyclicPatchName_),
00137     cyclicPatchLabel_(ptf.cyclicPatchLabel_),
00138     orientation_(ptf.orientation_),
00139     initWallSf_(ptf.initWallSf_),
00140     initCyclicSf_(ptf.initCyclicSf_),
00141     openFraction_(ptf.openFraction_),
00142     openingTime_(ptf.openingTime_),
00143     maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
00144     curTimeIndex_(-1)
00145 {}
00146 
00147 
00148 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00149 
00150 void Foam::activeBaffleVelocityFvPatchVectorField::autoMap
00151 (
00152     const fvPatchFieldMapper& m
00153 )
00154 {
00155     fixedValueFvPatchVectorField::autoMap(m);
00156 
00157     //- Note: cannot map field from cyclic patch anyway so just recalculate
00158     //  Areas should be consistent when doing autoMap except in case of
00159     //  topo changes.
00160     //- Note: we don't want to use Sf here since triggers rebuilding of
00161     //  fvMesh::S() which will give problems when mapped (since already
00162     //  on new mesh)
00163     const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
00164     initWallSf_ = patch().patchSlice(areas);
00165     initCyclicSf_ = patch().boundaryMesh()
00166     [
00167         cyclicPatchLabel_
00168     ].patchSlice(areas);
00169 }
00170 
00171 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
00172 (
00173     const fvPatchVectorField& ptf,
00174     const labelList& addr
00175 )
00176 {
00177     fixedValueFvPatchVectorField::rmap(ptf, addr);
00178 
00179     // See autoMap.
00180     const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
00181     initWallSf_ = patch().patchSlice(areas);
00182     initCyclicSf_ = patch().boundaryMesh()
00183     [
00184         cyclicPatchLabel_
00185     ].patchSlice(areas);
00186 }
00187 
00188 
00189 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
00190 {
00191     if (updated())
00192     {
00193         return;
00194     }
00195 
00196     // Execute the change to the openFraction only once per time-step
00197     if (curTimeIndex_ != this->db().time().timeIndex())
00198     {
00199         const volScalarField& p = db().lookupObject<volScalarField>
00200         (
00201             pName_
00202         );
00203 
00204         const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
00205         const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
00206         label nCyclicFaces = cyclicFaceCells.size();
00207         label nCyclicFacesPerSide = nCyclicFaces/2;
00208 
00209         scalar forceDiff = 0;
00210 
00211         for (label facei=0; facei<nCyclicFacesPerSide; facei++)
00212         {
00213             forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
00214         }
00215 
00216         for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
00217         {
00218             forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
00219         }
00220 
00221         openFraction_ =
00222             max(min(
00223                 openFraction_
00224               + max
00225                 (
00226                     this->db().time().deltaT().value()/openingTime_,
00227                     maxOpenFractionDelta_
00228                 )
00229                *(orientation_*sign(forceDiff)),
00230               1 - 1e-6), 1e-6);
00231 
00232         Info<< "openFraction = " << openFraction_ << endl;
00233 
00234         vectorField::subField Sfw = patch().patch().faceAreas();
00235         vectorField newSfw = (1 - openFraction_)*initWallSf_;
00236         forAll(Sfw, facei)
00237         {
00238             Sfw[facei] = newSfw[facei];
00239         }
00240         const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf());
00241 
00242         const_cast<vectorField&>(cyclicPatch.Sf()) =
00243             openFraction_*initCyclicSf_;
00244         const_cast<scalarField&>(cyclicPatch.magSf()) =
00245             mag(cyclicPatch.Sf());
00246 
00247         curTimeIndex_ = this->db().time().timeIndex();
00248     }
00249 
00250     fixedValueFvPatchVectorField::updateCoeffs();
00251 }
00252 
00253 
00254 void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
00255 {
00256     fvPatchVectorField::write(os);
00257     os.writeKeyword("cyclicPatch")
00258         << cyclicPatchName_ << token::END_STATEMENT << nl;
00259     os.writeKeyword("orientation")
00260         << orientation_ << token::END_STATEMENT << nl;
00261     os.writeKeyword("openingTime")
00262         << openingTime_ << token::END_STATEMENT << nl;
00263     os.writeKeyword("maxOpenFractionDelta")
00264         << maxOpenFractionDelta_ << token::END_STATEMENT << nl;
00265     os.writeKeyword("openFraction")
00266         << openFraction_ << token::END_STATEMENT << nl;
00267     os.writeKeyword("p")
00268         << pName_ << token::END_STATEMENT << nl;
00269     writeEntry("value", os);
00270 }
00271 
00272 
00273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00274 
00275 namespace Foam
00276 {
00277     makePatchTypeField
00278     (
00279         fvPatchVectorField,
00280         activeBaffleVelocityFvPatchVectorField
00281     );
00282 }
00283 
00284 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd