fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / primitives / BlockCoeff / BlockCoeff.H
blob69c5cef7b4c526dc92136770117e558d6627a004
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-6 H. Jasak All rights reserved
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 Class
26     blockCoeff
28 Description
29     Block coefficient combines a scalar, linear and square coefficient
30     for different levels of coupling
32 Author
33     Hrvoje Jasak, Wikki Ltd.  All rights reserved
35 \*---------------------------------------------------------------------------*/
37 #ifndef BlockCoeff_H
38 #define BlockCoeff_H
40 #include "blockCoeffBase.H"
41 #include "expandTensor.H"
42 #include "Field.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
51 template<class Type>
52 class BlockCoeff;
54 template<class Type>
55 Ostream& operator<<(Ostream&, const BlockCoeff<Type>&);
57 /*---------------------------------------------------------------------------*\
58                           Class BlockCoeff Declaration
59 \*---------------------------------------------------------------------------*/
61 template<class Type>
62 class BlockCoeff
64     public blockCoeffBase
66 public:
68     // Public data types
70         //- Component type
71         typedef Type xType;
72         typedef Field<xType> xTypeField;
74         //- Coefficient type
75         typedef typename pTraits<Type>::cmptType scalarType;
76         typedef Type linearType;
77         typedef typename outerProduct<Type, Type>::type squareType;
79         //- Field type
80         typedef Field<scalarType> scalarTypeField;
81         typedef Field<linearType> linearTypeField;
82         typedef Field<squareType> squareTypeField;
85     //- Multiplication trait
86     class multiply
87     {
88     public:
90         multiply() {}
92         // Coefficient times type multiplication
94             Type operator()(const scalarType& c, const Type& x) const
95             {
96                 return c*x;
97             }
99             Type operator()(const linearType& c, const Type& x) const
100             {
101                 return cmptMultiply(c, x);
102             }
104             Type operator()(const squareType& c, const Type& x) const
105             {
106                 return (c & x);
107             }
109             Type operator()(const BlockCoeff<Type>& c, const Type& x) const
110             {
111                 if (c.scalarCoeffPtr_)
112                 {
113                     return operator()(*c.scalarCoeffPtr_, x);
114                 }
115                 else if (c.linearCoeffPtr_)
116                 {
117                     return operator()(*c.linearCoeffPtr_, x);
118                 }
119                 else if (c.squareCoeffPtr_)
120                 {
121                     return operator()(*c.squareCoeffPtr_, x);
122                 }
123                 else
124                 {
125                     return pTraits<Type>::zero;
126                 }
127             }
130         // Transpose functions
132             scalarType transpose(const scalarType& c) const
133             {
134                 return c;
135             }
137             linearType transpose(const linearType& c) const
138             {
139                 return c;
140             }
142             squareType transpose(const squareType& c) const
143             {
144                 return c.T();
145             }
148         // Inverse functions
150             scalarType inverse(const scalarType& c) const
151             {
152                 return 1.0/c;
153             }
155             linearType inverse(const linearType& c) const
156             {
157                 return cmptDivide(pTraits<linearType>::one, c);
158             }
160             squareType inverse(const squareType& c) const
161             {
162                 return inv(c);
163             }
166         // Triple product of coefficients
168             scalarType tripleProduct
169             (
170                 const scalarType& a,
171                 const scalarType& b,
172                 const scalarType& c
173             ) const
174             {
175                 return a*c/b;
176             }
178             linearType tripleProduct
179             (
180                 const scalarType& a,
181                 const linearType& b,
182                 const scalarType& c
183             ) const
184             {
185                 return a*c*inverse(b);
186             }
188             linearType tripleProduct
189             (
190                 const linearType& a,
191                 const linearType& b,
192                 const linearType& c
193             ) const
194             {
195                 return cmptDivide(cmptMultiply(a, c), b);
196             }
198             squareType tripleProduct
199             (
200                 const scalarType& a,
201                 const squareType& b,
202                 const scalarType& c
203             ) const
204             {
205                 return a*c*inv(b);
206             }
208             squareType tripleProduct
209             (
210                 const linearType& a,
211                 const squareType& b,
212                 const linearType& c
213             ) const
214             {
215                 squareType result;
216                 linearType sac = cmptMultiply(a, c);
218                 expandLinear(result, sac);
219                 return result & inv(b);
220             }
222             squareType tripleProduct
223             (
224                 const squareType& a,
225                 const squareType& b,
226                 const squareType& c
227             ) const
228             {
229                 return (a & inv(b)) & c;
230             }
231     };
234 private:
236     // Private data
238         //- Scalar coefficient
239         mutable scalarType* scalarCoeffPtr_;
241         //- Linear coefficient
242         mutable linearType* linearCoeffPtr_;
244         //- Square coefficient
245         mutable squareType* squareCoeffPtr_;
248     // Private Member Functions
250         //- Promote to scalar
251         scalarType& toScalar();
253         //- Promote to linear
254         linearType& toLinear();
256         //- Promote to square
257         squareType& toSquare();
260 public:
262     // Constructors
264         //- Construct null
265         explicit BlockCoeff();
267         //- Construct as copy
268         BlockCoeff(const BlockCoeff<Type>&);
270         //- Construct from Istream
271         BlockCoeff(Istream&);
273         //- Clone
274         BlockCoeff<Type> clone() const;
277     // Destructor
279         ~BlockCoeff();
281         //- Clear data
282         void clear();
285     // Member functions
287         //- Return active type
288         blockCoeffBase::activeLevel activeType() const;
290         //- Check pointers: only one type should be active (debug only)
291         void checkActive() const;
293         // Return as typed.  Fails when asked for the incorrect type
295             //- Return as scalar
296             const scalarType& asScalar() const;
297             scalarType& asScalar();
299             //- Return as linear
300             const linearType& asLinear() const;
301             linearType& asLinear();
303             //- Return as square
304             const squareType& asSquare() const;
305             squareType& asSquare();
308         //- Return component
309         scalarType component(const direction) const;
312     // Member operators
314         void operator=(const BlockCoeff<Type>&);
317     // IOstream operators
319         friend Ostream& operator<< <Type>
320         (
321             Ostream&,
322             const BlockCoeff<Type>&
323         );
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 } // End namespace Foam
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 #ifdef NoRepository
334 #   include "BlockCoeff.C"
335 #endif
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
339 #endif
341 // ************************************************************************* //