initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / interpolation / surfaceInterpolation / schemes / clippedLinear / clippedLinear.H
blob7a39dc346fd9c0124923329910a0cf02b41c437a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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
25 Class
26     Foam::clippedLinear
28 Description
29     Central-differencing interpolation scheme using clipped-weights to
30     improve stability on meshes with very rapid variations in cell size.
32 SourceFiles
33     clippedLinear.C
35 \*---------------------------------------------------------------------------*/
37 #ifndef clippedLinear_H
38 #define clippedLinear_H
40 #include "surfaceInterpolationScheme.H"
41 #include "volFields.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 /*---------------------------------------------------------------------------*\
49                            Class clippedLinear Declaration
50 \*---------------------------------------------------------------------------*/
52 template<class Type>
53 class clippedLinear
55     public surfaceInterpolationScheme<Type>
57     // Private data
59         const scalar cellSizeRatio_;
60         scalar wfLimit_;
63     // Private Member Functions
65         void calcWfLimit()
66         {
67             if (cellSizeRatio_ <= 0 || cellSizeRatio_ > 1)
68             {
69                 FatalErrorIn("clippedLinear::calcWfLimit()")
70                     << "Given cellSizeRatio of " << cellSizeRatio_
71                     << " is not between 0 and 1"
72                     << exit(FatalError);
73             }
75             wfLimit_ = cellSizeRatio_/(1.0 + cellSizeRatio_);
76         }
79         //- Disallow default bitwise assignment
80         void operator=(const clippedLinear&);
83 public:
85     //- Runtime type information
86     TypeName("clippedLinear");
89     // Constructors
91         //- Construct from mesh and cellSizeRatio
92         clippedLinear(const fvMesh& mesh, const scalar cellSizeRatio)
93         :
94             surfaceInterpolationScheme<Type>(mesh),
95             cellSizeRatio_(cellSizeRatio)
96         {
97             calcWfLimit();
98         }
100         //- Construct from Istream
101         clippedLinear(const fvMesh& mesh, Istream& is)
102         :
103             surfaceInterpolationScheme<Type>(mesh),
104             cellSizeRatio_(readScalar(is))
105         {
106             calcWfLimit();
107         }
109         //- Construct from faceFlux and Istream
110         clippedLinear
111         (
112             const fvMesh& mesh,
113             const surfaceScalarField&,
114             Istream& is
115         )
116         :
117             surfaceInterpolationScheme<Type>(mesh),
118             cellSizeRatio_(readScalar(is))
119         {
120             calcWfLimit();
121         }
124     // Member Functions
126         //- Return the interpolation weighting factors
127         tmp<surfaceScalarField> weights
128         (
129             const GeometricField<Type, fvPatchField, volMesh>&
130         ) const
131         {
132             const fvMesh& mesh = this->mesh();
134             tmp<surfaceScalarField> tcdWeights
135             (
136                 mesh.surfaceInterpolation::weights()
137             );
138             const surfaceScalarField& cdWeights = tcdWeights();
140             tmp<surfaceScalarField> tclippedLinearWeights
141             (
142                 new surfaceScalarField
143                 (
144                     IOobject
145                     (
146                         "clippedLinearWeights",
147                         mesh.time().timeName(),
148                         mesh
149                     ),
150                     mesh,
151                     dimless
152                 )
153             );
154             surfaceScalarField& clippedLinearWeights = tclippedLinearWeights();
156             clippedLinearWeights.internalField() = 
157                 max(min(cdWeights.internalField(), 1 - wfLimit_), wfLimit_);
159             forAll (mesh.boundary(), patchi)
160             {
161                 if (mesh.boundary()[patchi].coupled())
162                 {
163                     clippedLinearWeights.boundaryField()[patchi] =
164                         max
165                         (
166                             min
167                             (
168                                 cdWeights.boundaryField()[patchi],
169                                 1 - wfLimit_
170                             ),
171                             wfLimit_
172                         );
173                 }
174                 else
175                 {
176                     clippedLinearWeights.boundaryField()[patchi] =
177                         cdWeights.boundaryField()[patchi];
178                 }
179             }
181             return tclippedLinearWeights;
182         }
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 } // End namespace Foam
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 #endif
194 // ************************************************************************* //