Advertisement
Guest User

turbulentVFVel .C file

a guest
Jan 30th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.00 KB | None | 0 0
  1. /*---------------------------------------------------------------------------*\
  2.   =========                 |
  3.   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
  4.    \\    /   O peration     |
  5.     \\  /    A nd           | Copyright held by original author
  6.      \\/     M anipulation  |
  7. -------------------------------------------------------------------------------
  8. License
  9.     This file is part of OpenFOAM.
  10.  
  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.
  15.  
  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
  19.     for more details.
  20.  
  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
  24.  
  25. \*---------------------------------------------------------------------------*/
  26.  
  27. #include "turbulentVolumeFlowVelocityFvPatchVectorField.H"
  28. #include "addToRunTimeSelectionTable.H"
  29. #include "fvPatchFieldMapper.H"
  30. #include "volFields.H"
  31. #include "surfaceFields.H"
  32.  
  33. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  34.  
  35. namespace Foam
  36. {
  37.  
  38. // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
  39.  
  40. turbulentVolumeFlowVelocityFvPatchVectorField::turbulentVolumeFlowVelocityFvPatchVectorField
  41. (
  42.     const fvPatch& p,
  43.     const DimensionedField<vector, volMesh>& iF
  44. )
  45. :
  46.     fixedValueFvPatchVectorField(p, iF),
  47.     volumeFlowRate_(0),
  48.     n_(1, 0, 0),
  49.     y_(0, 1, 0)
  50. {}
  51.  
  52.  
  53. turbulentVolumeFlowVelocityFvPatchVectorField::turbulentVolumeFlowVelocityFvPatchVectorField
  54. (
  55.     const turbulentVolumeFlowVelocityFvPatchVectorField& ptf,
  56.     const fvPatch& p,
  57.     const DimensionedField<vector, volMesh>& iF,
  58.     const fvPatchFieldMapper& mapper
  59. )
  60. :
  61.     fixedValueFvPatchVectorField(ptf, p, iF, mapper),
  62.     volumeFlowRate_(ptf.volumeFlowRate_),
  63.     n_(ptf.n_),
  64.     y_(ptf.y_)
  65. {}
  66.  
  67.  
  68. turbulentVolumeFlowVelocityFvPatchVectorField::turbulentVolumeFlowVelocityFvPatchVectorField
  69. (
  70.     const fvPatch& p,
  71.     const DimensionedField<vector, volMesh>& iF,
  72.     const dictionary& dict
  73. )
  74. :
  75.     fixedValueFvPatchVectorField(p, iF),
  76.     volumeFlowRate_(readScalar(dict.lookup("volumeFlowRate"))),
  77.     n_(dict.lookup("n")),
  78.     y_(dict.lookup("y"))
  79. {
  80.     if (mag(n_) < SMALL || mag(y_) < SMALL)
  81.     {
  82.         FatalErrorIn("turbulentVolumeFlowVelocityFvPatchVectorField(dict)")
  83.             << "n or y given with zero size not correct"
  84.             << abort(FatalError);
  85.     }
  86.  
  87.     n_ /= mag(n_);
  88.     y_ /= mag(y_);
  89.  
  90.     evaluate();
  91. }
  92.  
  93.  
  94. turbulentVolumeFlowVelocityFvPatchVectorField::turbulentVolumeFlowVelocityFvPatchVectorField
  95. (
  96.     const turbulentVolumeFlowVelocityFvPatchVectorField& fcvpvf,
  97.     const DimensionedField<vector, volMesh>& iF
  98. )
  99. :
  100.     fixedValueFvPatchVectorField(fcvpvf, iF),
  101.     volumeFlowRate_(fcvpvf.volumeFlowRate_),
  102.     n_(fcvpvf.n_),
  103.     y_(fcvpvf.y_)
  104. {}
  105.  
  106.  
  107. // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
  108.  
  109. void turbulentVolumeFlowVelocityFvPatchVectorField::updateCoeffs()
  110. {
  111.     if (updated())
  112.     {
  113.         return;
  114.     }
  115.     // Get range and orientation
  116.     boundBox bb(patch().patch().localPoints(), true);
  117.  
  118.     vector ctr = 0.5*(bb.max() + bb.min());
  119.    
  120.     const vectorField& c = patch().Cf();
  121.    
  122.     // Calculate mean flow velocity and peak velocity
  123.     double dHid = mag(bb.max() - bb.min());
  124.     double rHid = 0.5*dHid;
  125.    
  126.     double nPowerInverse = 1.0/nPower_;
  127.  
  128.     double meanU = volumeFlowRate_/(constant::mathematical::pi*pow(rHid,2.0));
  129.     double peakU = meanU*(((nPower_ + 1.0)*(2.0*nPower_ + 1.0))/(2.0*pow(nPower_,2.0)));
  130.  
  131.     // Calculate local 1-D coordinate for the n-power law profile
  132.     scalarField coord = 2*((c - ctr) & y_)/((bb.max() - bb.min()) & y_);
  133.    
  134.     vectorField::operator=(n_*peakU*pow((1.0 - coord),nPowerInverse));
  135. }
  136.  
  137.  
  138. // Write
  139. void turbulentVolumeFlowVelocityFvPatchVectorField::write(Ostream& os) const
  140. {
  141.     fvPatchVectorField::write(os);
  142.     os.writeKeyword("volumeFlowRate")
  143.         << volumeFlowRate_ << token::END_STATEMENT << nl;
  144.     os.writeKeyword("n")
  145.         << y_ << token::END_STATEMENT << nl;
  146.     os.writeKeyword("nPower")
  147.         << n_ << token::END_STATEMENT << nl;
  148.     os.writeKeyword("y")
  149.         << y_ << token::END_STATEMENT << nl;
  150.     writeEntry("value", os);
  151. }
  152.  
  153.  
  154. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  155.  
  156. makePatchTypeField(fvPatchVectorField, turbulentVolumeFlowVelocityFvPatchVectorField);
  157.  
  158. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  159.  
  160. } // End namespace Foam
  161.  
  162. // ************************************************************************* //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement