BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / finiteVolume / interpolation / surfaceInterpolation / schemes / fixedBlended / fixedBlended.H
blob083ddc9c4efe99cbbc08ffaa13ed043d0ca5376b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::fixedBlended
27 Description
28     Two-scheme fixed-blending differencing scheme.
30     Similar to localBlended but uses a single (global) constant blending
31     factor. The factor applies to the first scheme and 1-factor to the
32     second scheme.
34 Note
35     Although a blending factor of 0 and 1 is permitted, it is more efficient
36     just to use the underlying scheme directly.
38 SourceFiles
39     fixedBlended.C
41 \*---------------------------------------------------------------------------*/
43 #ifndef fixedBlended_H
44 #define fixedBlended_H
46 #include "surfaceInterpolationScheme.H"
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 namespace Foam
53 /*---------------------------------------------------------------------------*\
54                         Class fixedBlended Declaration
55 \*---------------------------------------------------------------------------*/
57 template<class Type>
58 class fixedBlended
60     public surfaceInterpolationScheme<Type>
62     // Private data
64         const scalar blendingFactor_;
66     // Private Member Functions
68         //- Scheme 1
69         tmp<surfaceInterpolationScheme<Type> > tScheme1_;
71         //- Scheme 2
72         tmp<surfaceInterpolationScheme<Type> > tScheme2_;
75         //- Disallow default bitwise copy construct
76         fixedBlended(const fixedBlended&);
78         //- Disallow default bitwise assignment
79         void operator=(const fixedBlended&);
82 public:
84     //- Runtime type information
85     TypeName("fixedBlended");
88     // Constructors
90         //- Construct from mesh and Istream.
91         //  The name of the flux field is read from the Istream and looked-up
92         //  from the mesh objectRegistry
93         fixedBlended
94         (
95             const fvMesh& mesh,
96             Istream& is
97         )
98         :
99             surfaceInterpolationScheme<Type>(mesh),
100             blendingFactor_(readScalar(is)),
101             tScheme1_
102             (
103                 surfaceInterpolationScheme<Type>::New(mesh, is)
104             ),
105             tScheme2_
106             (
107                 surfaceInterpolationScheme<Type>::New(mesh, is)
108             )
109         {
110             if (blendingFactor_ < 0 || blendingFactor_ > 1)
111             {
112                 FatalIOErrorIn("fixedBlended(const fvMesh&, Istream&)", is)
113                     << "coefficient = " << blendingFactor_
114                     << " should be >= 0 and <= 1"
115                     << exit(FatalIOError);
116             }
117             if (surfaceInterpolationScheme<Type>::debug)
118             {
119                 Info<<"fixedBlended: " << blendingFactor_
120                     << "*" << tScheme1_().type()
121                     << " + (1-" << blendingFactor_ << ")*"
122                     << tScheme2_().type()
123                     <<endl;
124             }
125         }
128         //- Construct from mesh, faceFlux and Istream
129         fixedBlended
130         (
131             const fvMesh& mesh,
132             const surfaceScalarField& faceFlux,
133             Istream& is
134         )
135         :
136             surfaceInterpolationScheme<Type>(mesh),
137             blendingFactor_(readScalar(is)),
138             tScheme1_
139             (
140                 surfaceInterpolationScheme<Type>::New(mesh, faceFlux, is)
141             ),
142             tScheme2_
143             (
144                 surfaceInterpolationScheme<Type>::New(mesh, faceFlux, is)
145             )
146         {
147             if (blendingFactor_ < 0 || blendingFactor_ > 1)
148             {
149                 FatalIOErrorIn("fixedBlended(const fvMesh&, Istream&)", is)
150                     << "coefficient = " << blendingFactor_
151                     << " should be >= 0 and <= 1"
152                     << exit(FatalIOError);
153             }
154             if (surfaceInterpolationScheme<Type>::debug)
155             {
156                 Info<<"fixedBlended: " << blendingFactor_
157                     << "*" << tScheme1_().type()
158                     << " + (1-" << blendingFactor_ << ")*"
159                     << tScheme2_().type()
160                     <<endl;
161             }
162         }
165     // Member Functions
167         //- Return the interpolation weighting factors
168         tmp<surfaceScalarField>
169         weights
170         (
171             const GeometricField<Type, fvPatchField, volMesh>& vf
172         ) const
173         {
174             return
175                 blendingFactor_*tScheme1_().weights(vf)
176               + (scalar(1.0) - blendingFactor_)*tScheme2_().weights(vf);
177         }
180         //- Return the face-interpolate of the given cell field
181         //  with explicit correction
182         tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
183         interpolate
184         (
185             const GeometricField<Type, fvPatchField, volMesh>& vf
186         ) const
187         {
188             return
189                 blendingFactor_*tScheme1_().interpolate(vf)
190               + (scalar(1.0) - blendingFactor_)*tScheme2_().interpolate(vf);
191         }
194         //- Return true if this scheme uses an explicit correction
195         virtual bool corrected() const
196         {
197             return tScheme1_().corrected() || tScheme2_().corrected();
198         }
201         //- Return the explicit correction to the face-interpolate
202         //  for the given field
203         virtual tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
204         correction
205         (
206             const GeometricField<Type, fvPatchField, volMesh>& vf
207         ) const
208         {
209             if (tScheme1_().corrected())
210             {
211                 if (tScheme2_().corrected())
212                 {
213                     return
214                     (
215                         blendingFactor_
216                       * tScheme1_().correction(vf)
217                       + (scalar(1.0) - blendingFactor_)
218                       * tScheme2_().correction(vf)
219                     );
220                 }
221                 else
222                 {
223                     return
224                     (
225                         blendingFactor_
226                       * tScheme1_().correction(vf)
227                     );
228                 }
229             }
230             else if (tScheme2_().corrected())
231             {
232                 return
233                 (
234                     (scalar(1.0) - blendingFactor_)
235                   * tScheme2_().correction(vf)
236                 );
237             }
238             else
239             {
240                 return tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
241                 (
242                     NULL
243                 );
244             }
245         }
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 } // End namespace Foam
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 #endif
258 // ************************************************************************* //