fixedBlended.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your 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, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::fixedBlended
26 
27 Description
28  Two-scheme fixed-blending interpolation scheme.
29 
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.
33 
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.
37 
38 SourceFiles
39  fixedBlended.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef fixedBlended_H
44 #define fixedBlended_H
45 
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class fixedBlended Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class Type>
58 class fixedBlended
59 :
60  public surfaceInterpolationScheme<Type>
61 {
62  // Private Data
63 
64  const scalar blendingFactor_;
65 
66  // Private Member Functions
67 
68  //- Scheme 1
70 
71  //- Scheme 2
73 
74 
75 public:
76 
77  //- Runtime type information
78  TypeName("fixedBlended");
79 
80 
81  // Constructors
82 
83  //- Construct from mesh and Istream.
84  // The name of the flux field is read from the Istream and looked-up
85  // from the mesh objectRegistry
87  (
88  const fvMesh& mesh,
89  Istream& is
90  )
91  :
92  surfaceInterpolationScheme<Type>(mesh),
93  blendingFactor_(readScalar(is)),
94  tScheme1_
95  (
96  surfaceInterpolationScheme<Type>::New(mesh, is)
97  ),
98  tScheme2_
99  (
100  surfaceInterpolationScheme<Type>::New(mesh, is)
101  )
102  {
103  if (blendingFactor_ < 0 || blendingFactor_ > 1)
104  {
106  << "coefficient = " << blendingFactor_
107  << " should be >= 0 and <= 1"
108  << exit(FatalIOError);
109  }
111  {
112  Info<<"fixedBlended: " << blendingFactor_
113  << "*" << tScheme1_().type()
114  << " + (1-" << blendingFactor_ << ")*"
115  << tScheme2_().type()
116  <<endl;
117  }
118  }
119 
120 
121  //- Construct from mesh, faceFlux and Istream
123  (
124  const fvMesh& mesh,
125  const surfaceScalarField& faceFlux,
126  Istream& is
127  )
128  :
129  surfaceInterpolationScheme<Type>(mesh),
130  blendingFactor_(readScalar(is)),
131  tScheme1_
132  (
133  surfaceInterpolationScheme<Type>::New(mesh, faceFlux, is)
134  ),
135  tScheme2_
136  (
137  surfaceInterpolationScheme<Type>::New(mesh, faceFlux, is)
138  )
139  {
140  if (blendingFactor_ < 0 || blendingFactor_ > 1)
141  {
143  << "coefficient = " << blendingFactor_
144  << " should be >= 0 and <= 1"
145  << exit(FatalIOError);
146  }
148  {
149  Info<<"fixedBlended: " << blendingFactor_
150  << "*" << tScheme1_().type()
151  << " + (1-" << blendingFactor_ << ")*"
152  << tScheme2_().type()
153  <<endl;
154  }
155  }
156 
157  //- Disallow default bitwise copy construction
158  fixedBlended(const fixedBlended&) = delete;
159 
160 
161  // Member Functions
162 
163  //- Return the interpolation weighting factors
166  (
168  ) const
169  {
170  return
171  blendingFactor_*tScheme1_().weights(vf)
172  + (scalar(1) - blendingFactor_)*tScheme2_().weights(vf);
173  }
174 
175 
176  //- Return the face-interpolate of the given cell field
177  // with explicit correction
180  (
182  ) const
183  {
184  return
185  blendingFactor_*tScheme1_().interpolate(vf)
186  + (scalar(1) - blendingFactor_)*tScheme2_().interpolate(vf);
187  }
188 
189 
190  //- Return true if this scheme uses an explicit correction
191  virtual bool corrected() const
192  {
193  return tScheme1_().corrected() || tScheme2_().corrected();
194  }
195 
196 
197  //- Return the explicit correction to the face-interpolate
198  // for the given field
201  (
203  ) const
204  {
205  if (tScheme1_().corrected())
206  {
207  if (tScheme2_().corrected())
208  {
209  return
210  (
211  blendingFactor_
212  * tScheme1_().correction(vf)
213  + (scalar(1) - blendingFactor_)
214  * tScheme2_().correction(vf)
215  );
216  }
217  else
218  {
219  return
220  (
221  blendingFactor_
222  * tScheme1_().correction(vf)
223  );
224  }
225  }
226  else if (tScheme2_().corrected())
227  {
228  return
229  (
230  (scalar(1) - blendingFactor_)
231  * tScheme2_().correction(vf)
232  );
233  }
234  else
235  {
237  (
238  nullptr
239  );
240  }
241  }
242 
243 
244  // Member Operators
245 
246  //- Disallow default bitwise assignment
247  void operator=(const fixedBlended&) = delete;
248 };
249 
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 } // End namespace Foam
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 #endif
258 
259 // ************************************************************************* //
TypeName("fixedBlended")
Runtime type information.
virtual tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > correction(const GeometricField< Type, fvPatchField, volMesh > &vf) const
Return the explicit correction to the face-interpolate.
Definition: fixedBlended.H:200
Two-scheme fixed-blending interpolation scheme.
Definition: fixedBlended.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &vf) const
Return the face-interpolate of the given cell field.
Definition: fixedBlended.H:179
static tmp< surfaceInterpolationScheme< Type > > New(const fvMesh &mesh, Istream &schemeData)
Return new tmp interpolation scheme.
fixedBlended(const fvMesh &mesh, Istream &is)
Construct from mesh and Istream.
Definition: fixedBlended.H:86
virtual bool corrected() const
Return true if this scheme uses an explicit correction.
Definition: fixedBlended.H:190
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
void operator=(const fixedBlended &)=delete
Disallow default bitwise assignment.
messageStream Info
A class for managing temporary objects.
Definition: PtrList.H:53
Abstract base class for surface interpolation schemes.
tmp< surfaceScalarField > weights(const GeometricField< Type, fvPatchField, volMesh > &vf) const
Return the interpolation weighting factors.
Definition: fixedBlended.H:165
Namespace for OpenFOAM.
IOerror FatalIOError