00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "activeBaffleVelocityFvPatchVectorField.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 #include <finiteVolume/volFields.H>
00029 #include <finiteVolume/surfaceFields.H>
00030
00031
00032
00033 Foam::activeBaffleVelocityFvPatchVectorField::
00034 activeBaffleVelocityFvPatchVectorField
00035 (
00036 const fvPatch& p,
00037 const DimensionedField<vector, volMesh>& iF
00038 )
00039 :
00040 fixedValueFvPatchVectorField(p, iF),
00041 pName_("p"),
00042 cyclicPatchName_(),
00043 cyclicPatchLabel_(-1),
00044 orientation_(1),
00045 initWallSf_(0),
00046 initCyclicSf_(0),
00047 openFraction_(0),
00048 openingTime_(0),
00049 maxOpenFractionDelta_(0),
00050 curTimeIndex_(-1)
00051 {}
00052
00053
00054 Foam::activeBaffleVelocityFvPatchVectorField::
00055 activeBaffleVelocityFvPatchVectorField
00056 (
00057 const activeBaffleVelocityFvPatchVectorField& ptf,
00058 const fvPatch& p,
00059 const DimensionedField<vector, volMesh>& iF,
00060 const fvPatchFieldMapper& mapper
00061 )
00062 :
00063 fixedValueFvPatchVectorField(ptf, p, iF, mapper),
00064 pName_(ptf.pName_),
00065 cyclicPatchName_(ptf.cyclicPatchName_),
00066 cyclicPatchLabel_(ptf.cyclicPatchLabel_),
00067 orientation_(ptf.orientation_),
00068 initWallSf_(ptf.initWallSf_),
00069 initCyclicSf_(ptf.initCyclicSf_),
00070 openFraction_(ptf.openFraction_),
00071 openingTime_(ptf.openingTime_),
00072 maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
00073 curTimeIndex_(-1)
00074 {}
00075
00076
00077 Foam::activeBaffleVelocityFvPatchVectorField::
00078 activeBaffleVelocityFvPatchVectorField
00079 (
00080 const fvPatch& p,
00081 const DimensionedField<vector, volMesh>& iF,
00082 const dictionary& dict
00083 )
00084 :
00085 fixedValueFvPatchVectorField(p, iF),
00086 pName_("p"),
00087 cyclicPatchName_(dict.lookup("cyclicPatch")),
00088 cyclicPatchLabel_(p.patch().boundaryMesh().findPatchID(cyclicPatchName_)),
00089 orientation_(readLabel(dict.lookup("orientation"))),
00090 initWallSf_(p.Sf()),
00091 initCyclicSf_(p.boundaryMesh()[cyclicPatchLabel_].Sf()),
00092 openFraction_(readScalar(dict.lookup("openFraction"))),
00093 openingTime_(readScalar(dict.lookup("openingTime"))),
00094 maxOpenFractionDelta_(readScalar(dict.lookup("maxOpenFractionDelta"))),
00095 curTimeIndex_(-1)
00096 {
00097 fvPatchVectorField::operator=(vector::zero);
00098
00099 if (dict.found("p"))
00100 {
00101 dict.lookup("p") >> pName_;
00102 }
00103 }
00104
00105
00106 Foam::activeBaffleVelocityFvPatchVectorField::
00107 activeBaffleVelocityFvPatchVectorField
00108 (
00109 const activeBaffleVelocityFvPatchVectorField& ptf
00110 )
00111 :
00112 fixedValueFvPatchVectorField(ptf),
00113 pName_(ptf.pName_),
00114 cyclicPatchName_(ptf.cyclicPatchName_),
00115 cyclicPatchLabel_(ptf.cyclicPatchLabel_),
00116 orientation_(ptf.orientation_),
00117 initWallSf_(ptf.initWallSf_),
00118 initCyclicSf_(ptf.initCyclicSf_),
00119 openFraction_(ptf.openFraction_),
00120 openingTime_(ptf.openingTime_),
00121 maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
00122 curTimeIndex_(-1)
00123 {}
00124
00125
00126 Foam::activeBaffleVelocityFvPatchVectorField::
00127 activeBaffleVelocityFvPatchVectorField
00128 (
00129 const activeBaffleVelocityFvPatchVectorField& ptf,
00130 const DimensionedField<vector, volMesh>& iF
00131 )
00132 :
00133 fixedValueFvPatchVectorField(ptf, iF),
00134 pName_(ptf.pName_),
00135 cyclicPatchName_(ptf.cyclicPatchName_),
00136 cyclicPatchLabel_(ptf.cyclicPatchLabel_),
00137 orientation_(ptf.orientation_),
00138 initWallSf_(ptf.initWallSf_),
00139 initCyclicSf_(ptf.initCyclicSf_),
00140 openFraction_(ptf.openFraction_),
00141 openingTime_(ptf.openingTime_),
00142 maxOpenFractionDelta_(ptf.maxOpenFractionDelta_),
00143 curTimeIndex_(-1)
00144 {}
00145
00146
00147
00148
00149 void Foam::activeBaffleVelocityFvPatchVectorField::autoMap
00150 (
00151 const fvPatchFieldMapper& m
00152 )
00153 {
00154 fixedValueFvPatchVectorField::autoMap(m);
00155
00156
00157
00158
00159
00160
00161
00162 const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
00163 initWallSf_ = static_cast<UList<vector> >(patch().patchSlice(areas));
00164 initCyclicSf_ = static_cast<UList<vector> >(patch().boundaryMesh()
00165 [
00166 cyclicPatchLabel_
00167 ].patchSlice(areas));
00168 }
00169
00170 void Foam::activeBaffleVelocityFvPatchVectorField::rmap
00171 (
00172 const fvPatchVectorField& ptf,
00173 const labelList& addr
00174 )
00175 {
00176 fixedValueFvPatchVectorField::rmap(ptf, addr);
00177
00178
00179 const vectorField& areas = patch().boundaryMesh().mesh().faceAreas();
00180 initWallSf_ = static_cast<UList<vector> >(patch().patchSlice(areas));
00181 initCyclicSf_ = static_cast<UList<vector> >(patch().boundaryMesh()
00182 [
00183 cyclicPatchLabel_
00184 ].patchSlice(areas));
00185 }
00186
00187
00188 void Foam::activeBaffleVelocityFvPatchVectorField::updateCoeffs()
00189 {
00190 if (updated())
00191 {
00192 return;
00193 }
00194
00195
00196 if (curTimeIndex_ != this->db().time().timeIndex())
00197 {
00198 const volScalarField& p = db().lookupObject<volScalarField>
00199 (
00200 pName_
00201 );
00202
00203 const fvPatch& cyclicPatch = patch().boundaryMesh()[cyclicPatchLabel_];
00204 const labelList& cyclicFaceCells = cyclicPatch.patch().faceCells();
00205 label nCyclicFaces = cyclicFaceCells.size();
00206 label nCyclicFacesPerSide = nCyclicFaces/2;
00207
00208 scalar forceDiff = 0;
00209
00210 for (label facei=0; facei<nCyclicFacesPerSide; facei++)
00211 {
00212 forceDiff += p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
00213 }
00214
00215 for (label facei=nCyclicFacesPerSide; facei<nCyclicFaces; facei++)
00216 {
00217 forceDiff -= p[cyclicFaceCells[facei]]*mag(initCyclicSf_[facei]);
00218 }
00219
00220 openFraction_ =
00221 max(min(
00222 openFraction_
00223 + min
00224 (
00225 this->db().time().deltaT().value()/openingTime_,
00226 maxOpenFractionDelta_
00227 )
00228 *(orientation_*sign(forceDiff)),
00229 1 - 1e-6), 1e-6);
00230
00231 Info<< "openFraction = " << openFraction_ << endl;
00232
00233 vectorField::subField Sfw = patch().patch().faceAreas();
00234 vectorField newSfw = (1 - openFraction_)*initWallSf_;
00235 forAll(Sfw, facei)
00236 {
00237 Sfw[facei] = newSfw[facei];
00238 }
00239 const_cast<scalarField&>(patch().magSf()) = mag(patch().Sf());
00240
00241 const_cast<vectorField&>(cyclicPatch.Sf()) =
00242 openFraction_*initCyclicSf_;
00243 const_cast<scalarField&>(cyclicPatch.magSf()) =
00244 mag(cyclicPatch.Sf());
00245
00246 curTimeIndex_ = this->db().time().timeIndex();
00247 }
00248
00249 fixedValueFvPatchVectorField::updateCoeffs();
00250 }
00251
00252
00253 void Foam::activeBaffleVelocityFvPatchVectorField::write(Ostream& os) const
00254 {
00255 fvPatchVectorField::write(os);
00256 os.writeKeyword("cyclicPatch")
00257 << cyclicPatchName_ << token::END_STATEMENT << nl;
00258 os.writeKeyword("orientation")
00259 << orientation_ << token::END_STATEMENT << nl;
00260 os.writeKeyword("openingTime")
00261 << openingTime_ << token::END_STATEMENT << nl;
00262 os.writeKeyword("maxOpenFractionDelta")
00263 << maxOpenFractionDelta_ << token::END_STATEMENT << nl;
00264 os.writeKeyword("openFraction")
00265 << openFraction_ << token::END_STATEMENT << nl;
00266 os.writeKeyword("p")
00267 << pName_ << token::END_STATEMENT << nl;
00268 writeEntry("value", os);
00269 }
00270
00271
00272
00273
00274 namespace Foam
00275 {
00276 makePatchTypeField
00277 (
00278 fvPatchVectorField,
00279 activeBaffleVelocityFvPatchVectorField
00280 );
00281 }
00282
00283