FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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