fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / primitives / BlockCoeff / DecoupledBlockCoeff.H
blob462b6016c5f35032377d0f496d9a2edeede0442b
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     Template for the terminal decoupled class.  It is designed to avoid
30     endless expansion of tensor order by excluding block coupling at the
31     terminal type level.
33 Author
34     Hrvoje Jasak, Wikki Ltd.  All rights reserved
36 \*---------------------------------------------------------------------------*/
38 #ifndef DecoupledBlockCoeff_H
39 #define DecoupledBlockCoeff_H
41 #include "blockCoeffBase.H"
42 #include "Field.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
51 template<class Type>
52 class DecoupledBlockCoeff;
54 template<class Type>
55 Ostream& operator<<(Ostream&, const DecoupledBlockCoeff<Type>&);
57 /*---------------------------------------------------------------------------*\
58                       Class DecoupledBlockCoeff Declaration
59 \*---------------------------------------------------------------------------*/
61 template<class Type>
62 class DecoupledBlockCoeff
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 scalar scalarType;
76         typedef Type linearType;
78         //- Field type
79         typedef Field<scalarType> scalarTypeField;
80         typedef Field<linearType> linearTypeField;
83     //- Multiplication trait
84     class multiply
85     {
86     public:
88         multiply() {}
90         Type operator()(const scalarType& c, const Type& x) const
91         {
92             return c*x;
93         }
95         Type operator()(const linearType& c, const Type& x) const
96         {
97             return cmptMultiply(c, x);
98         }
100         Type operator()(const DecoupledBlockCoeff<Type>& c, const Type& x) const
101         {
102             if (c.scalarCoeffPtr_)
103             {
104                 return operator()(*c.scalarCoeffPtr_, x);
105             }
106             else if (c.linearCoeffPtr_)
107             {
108                 return operator()(*c.linearCoeffPtr_, x);
109             }
110             else
111             {
112                 return pTraits<Type>::zero;
113             }
114         }
117         // Inverse functions
119             scalarType inverse(const scalarType& c) const
120             {
121                 return 1.0/c;
122             }
123                 
124             linearType inverse(const linearType& c) const
125             {
126                 return cmptDivide(pTraits<linearType>::one, c);
127             }
130         // Triple product of coefficients
132             scalarType tripleProduct
133             (
134                 const scalarType& a,
135                 const scalarType& b,
136                 const scalarType& c
137             ) const
138             {
139                 return a*c/b;
140             }
142             linearType tripleProduct
143             (
144                 const linearType& a,
145                 const linearType& b,
146                 const linearType& c
147             ) const
148             {
149                 return cmptDivide(cmptMultiply(a, c), b);
150             }
152             linearType tripleProduct
153             (
154                 const scalarType& a,
155                 const linearType& b,
156                 const scalarType& c
157             ) const
158             {
159                 return a*c*inverse(b);
160             }
161     };
164 private:
166     // Private data
168         //- Scalar coefficient
169         mutable scalarType* scalarCoeffPtr_;
171         //- Linear coefficient
172         mutable linearType* linearCoeffPtr_;
175     // Private Member Functions
177         //- Promote to scalar
178         scalarType& toScalar();
180         //- Promote to linear
181         linearType& toLinear();
184 public:
186     // Constructors
188         //- Construct null
189         explicit DecoupledBlockCoeff();
191         //- Construct as copy
192         DecoupledBlockCoeff(const DecoupledBlockCoeff<Type>&);
194         //- Construct from Istream
195         DecoupledBlockCoeff(Istream&);
197         //- Clone
198         DecoupledBlockCoeff<Type> clone() const;
201     // Destructor
203         ~DecoupledBlockCoeff();
205         //- Clear data
206         void clear();
209     // Member functions
211         //- Return active type
212         blockCoeffBase::activeLevel activeType() const;
214         //- Check pointers: only one type should be active (debug only)
215         void checkActive() const;
217         // Return as typed.  Fails when asked for the incorrect type
219             //- Return as scalar
220             const scalarType& asScalar() const;
221             scalarType& asScalar();
223             //- Return as linear
224             const linearType& asLinear() const;
225             linearType& asLinear();
228         //- Return component
229         scalarType component(const direction) const;
232     // Member operators
234         void operator=(const DecoupledBlockCoeff<Type>&);
237     // IOstream operators
239         friend Ostream& operator<< <Type>
240         (
241             Ostream&,
242             const DecoupledBlockCoeff<Type>&
243         );
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 } // End namespace Foam
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 #ifdef NoRepository
254 #   include "DecoupledBlockCoeff.C"
255 #endif
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 #endif
261 // ************************************************************************* //