Remove trailing whitespace systematically
[foam-extend-3.2.git] / src / foam / primitives / BlockCoeff / DecoupledBlockCoeff.H
blob86b04793292b78bf61ea9c5bcb667f302da49752
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     BlockCoeff
27 Description
28     Template for the terminal decoupled class.  It is designed to avoid
29     endless expansion of tensor order by excluding block coupling at the
30     terminal type level.
32 Author
33     Hrvoje Jasak, Wikki Ltd.  All rights reserved
35 \*---------------------------------------------------------------------------*/
37 #ifndef DecoupledBlockCoeff_H
38 #define DecoupledBlockCoeff_H
40 #include "blockCoeffBase.H"
41 #include "Field.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
50 template<class Type>
51 class DecoupledBlockCoeff;
53 template<class Type>
54 Ostream& operator<<(Ostream&, const DecoupledBlockCoeff<Type>&);
56 /*---------------------------------------------------------------------------*\
57                       Class DecoupledBlockCoeff Declaration
58 \*---------------------------------------------------------------------------*/
60 template<class Type>
61 class DecoupledBlockCoeff
63     public blockCoeffBase
65 public:
67     // Public data types
69         //- Component type
70         typedef Type xType;
71         typedef Field<xType> xTypeField;
73         //- Coefficient type
74         typedef scalar scalarType;
75         typedef Type linearType;
77         //- Field type
78         typedef Field<scalarType> scalarTypeField;
79         typedef Field<linearType> linearTypeField;
82     //- Multiplication trait
83     class multiply
84     {
85     public:
87         multiply() {}
89         Type operator()(const scalarType& c, const Type& x) const
90         {
91             return c*x;
92         }
94         Type operator()(const linearType& c, const Type& x) const
95         {
96             return cmptMultiply(c, x);
97         }
99         Type operator()(const DecoupledBlockCoeff<Type>& c, const Type& x) const
100         {
101             if (c.scalarCoeffPtr_)
102             {
103                 return operator()(*c.scalarCoeffPtr_, x);
104             }
105             else if (c.linearCoeffPtr_)
106             {
107                 return operator()(*c.linearCoeffPtr_, x);
108             }
109             else
110             {
111                 return pTraits<Type>::zero;
112             }
113         }
116         // Inverse functions
118             scalarType inverse(const scalarType& c) const
119             {
120                 return 1.0/c;
121             }
123             linearType inverse(const linearType& c) const
124             {
125                 return cmptDivide(pTraits<linearType>::one, c);
126             }
129         // Triple product of coefficients
131             scalarType tripleProduct
132             (
133                 const scalarType& a,
134                 const scalarType& b,
135                 const scalarType& c
136             ) const
137             {
138                 return a*c/b;
139             }
141             linearType tripleProduct
142             (
143                 const linearType& a,
144                 const linearType& b,
145                 const linearType& c
146             ) const
147             {
148                 return cmptDivide(cmptMultiply(a, c), b);
149             }
151             linearType tripleProduct
152             (
153                 const scalarType& a,
154                 const linearType& b,
155                 const scalarType& c
156             ) const
157             {
158                 return a*c*inverse(b);
159             }
160     };
163 private:
165     // Private data
167         //- Scalar coefficient
168         mutable scalarType* scalarCoeffPtr_;
170         //- Linear coefficient
171         mutable linearType* linearCoeffPtr_;
174     // Private Member Functions
176         //- Promote to scalar
177         scalarType& toScalar();
179         //- Promote to linear
180         linearType& toLinear();
183 public:
185     // Constructors
187         //- Construct null
188         explicit DecoupledBlockCoeff();
190         //- Construct as copy
191         DecoupledBlockCoeff(const DecoupledBlockCoeff<Type>&);
193         //- Construct from Istream
194         DecoupledBlockCoeff(Istream&);
196         //- Clone
197         DecoupledBlockCoeff<Type> clone() const;
200     // Destructor
202         ~DecoupledBlockCoeff();
204         //- Clear data
205         void clear();
208     // Member functions
210         //- Return active type
211         blockCoeffBase::activeLevel activeType() const;
213         //- Check pointers: only one type should be active (debug only)
214         void checkActive() const;
216         // Return as typed.  Fails when asked for the incorrect type
218             //- Return as scalar
219             const scalarType& asScalar() const;
220             scalarType& asScalar();
222             //- Return as linear
223             const linearType& asLinear() const;
224             linearType& asLinear();
227         //- Return component
228         scalarType component(const direction) const;
231     // Member operators
233         void operator=(const DecoupledBlockCoeff<Type>&);
236     // IOstream operators
238         friend Ostream& operator<< <Type>
239         (
240             Ostream&,
241             const DecoupledBlockCoeff<Type>&
242         );
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 } // End namespace Foam
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 #ifdef NoRepository
253 #   include "DecoupledBlockCoeff.C"
254 #endif
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 #endif
260 // ************************************************************************* //