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

clippedLinear.H

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 Class
00026     Foam::clippedLinear
00027 
00028 Description
00029     Central-differencing interpolation scheme using clipped-weights to
00030     improve stability on meshes with very rapid variations in cell size.
00031 
00032 SourceFiles
00033     clippedLinear.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #ifndef clippedLinear_H
00038 #define clippedLinear_H
00039 
00040 #include "surfaceInterpolationScheme.H"
00041 #include "volFields.H"
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 /*---------------------------------------------------------------------------*\
00049                            Class clippedLinear Declaration
00050 \*---------------------------------------------------------------------------*/
00051 
00052 template<class Type>
00053 class clippedLinear
00054 :
00055     public surfaceInterpolationScheme<Type>
00056 {
00057     // Private data
00058 
00059         const scalar cellSizeRatio_;
00060         scalar wfLimit_;
00061 
00062 
00063     // Private Member Functions
00064 
00065         void calcWfLimit()
00066         {
00067             if (cellSizeRatio_ <= 0 || cellSizeRatio_ > 1)
00068             {
00069                 FatalErrorIn("clippedLinear::calcWfLimit()")
00070                     << "Given cellSizeRatio of " << cellSizeRatio_
00071                     << " is not between 0 and 1"
00072                     << exit(FatalError);
00073             }
00074 
00075             wfLimit_ = cellSizeRatio_/(1.0 + cellSizeRatio_);
00076         }
00077 
00078 
00079         //- Disallow default bitwise assignment
00080         void operator=(const clippedLinear&);
00081 
00082 
00083 public:
00084 
00085     //- Runtime type information
00086     TypeName("clippedLinear");
00087 
00088 
00089     // Constructors
00090 
00091         //- Construct from mesh and cellSizeRatio
00092         clippedLinear(const fvMesh& mesh, const scalar cellSizeRatio)
00093         :
00094             surfaceInterpolationScheme<Type>(mesh),
00095             cellSizeRatio_(cellSizeRatio)
00096         {
00097             calcWfLimit();
00098         }
00099 
00100         //- Construct from Istream
00101         clippedLinear(const fvMesh& mesh, Istream& is)
00102         :
00103             surfaceInterpolationScheme<Type>(mesh),
00104             cellSizeRatio_(readScalar(is))
00105         {
00106             calcWfLimit();
00107         }
00108 
00109         //- Construct from faceFlux and Istream
00110         clippedLinear
00111         (
00112             const fvMesh& mesh,
00113             const surfaceScalarField&,
00114             Istream& is
00115         )
00116         :
00117             surfaceInterpolationScheme<Type>(mesh),
00118             cellSizeRatio_(readScalar(is))
00119         {
00120             calcWfLimit();
00121         }
00122 
00123 
00124     // Member Functions
00125 
00126         //- Return the interpolation weighting factors
00127         tmp<surfaceScalarField> weights
00128         (
00129             const GeometricField<Type, fvPatchField, volMesh>&
00130         ) const
00131         {
00132             const fvMesh& mesh = this->mesh();
00133 
00134             tmp<surfaceScalarField> tcdWeights
00135             (
00136                 mesh.surfaceInterpolation::weights()
00137             );
00138             const surfaceScalarField& cdWeights = tcdWeights();
00139 
00140             tmp<surfaceScalarField> tclippedLinearWeights
00141             (
00142                 new surfaceScalarField
00143                 (
00144                     IOobject
00145                     (
00146                         "clippedLinearWeights",
00147                         mesh.time().timeName(),
00148                         mesh
00149                     ),
00150                     mesh,
00151                     dimless
00152                 )
00153             );
00154             surfaceScalarField& clippedLinearWeights = tclippedLinearWeights();
00155 
00156             clippedLinearWeights.internalField() = 
00157                 max(min(cdWeights.internalField(), 1 - wfLimit_), wfLimit_);
00158 
00159             forAll (mesh.boundary(), patchi)
00160             {
00161                 if (mesh.boundary()[patchi].coupled())
00162                 {
00163                     clippedLinearWeights.boundaryField()[patchi] =
00164                         max
00165                         (
00166                             min
00167                             (
00168                                 cdWeights.boundaryField()[patchi],
00169                                 1 - wfLimit_
00170                             ),
00171                             wfLimit_
00172                         );
00173                 }
00174                 else
00175                 {
00176                     clippedLinearWeights.boundaryField()[patchi] =
00177                         cdWeights.boundaryField()[patchi];
00178                 }
00179             }
00180 
00181             return tclippedLinearWeights;
00182         }
00183 };
00184 
00185 
00186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00187 
00188 } // End namespace Foam
00189 
00190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00191 
00192 #endif
00193 
00194 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd