1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-6 H. Jasak All rights reserved
7 -------------------------------------------------------------------------------
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
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
29 Template for the terminal decoupled class. It is designed to avoid
30 endless expansion of tensor order by excluding block coupling at the
34 Hrvoje Jasak, Wikki Ltd. All rights reserved
36 \*---------------------------------------------------------------------------*/
38 #ifndef DecoupledBlockCoeff_H
39 #define DecoupledBlockCoeff_H
41 #include "blockCoeffBase.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
52 class DecoupledBlockCoeff;
55 Ostream& operator<<(Ostream&, const DecoupledBlockCoeff<Type>&);
57 /*---------------------------------------------------------------------------*\
58 Class DecoupledBlockCoeff Declaration
59 \*---------------------------------------------------------------------------*/
62 class DecoupledBlockCoeff
72 typedef Field<xType> xTypeField;
75 typedef scalar scalarType;
76 typedef Type linearType;
79 typedef Field<scalarType> scalarTypeField;
80 typedef Field<linearType> linearTypeField;
83 //- Multiplication trait
90 Type operator()(const scalarType& c, const Type& x) const
95 Type operator()(const linearType& c, const Type& x) const
97 return cmptMultiply(c, x);
100 Type operator()(const DecoupledBlockCoeff<Type>& c, const Type& x) const
102 if (c.scalarCoeffPtr_)
104 return operator()(*c.scalarCoeffPtr_, x);
106 else if (c.linearCoeffPtr_)
108 return operator()(*c.linearCoeffPtr_, x);
112 return pTraits<Type>::zero;
119 scalarType inverse(const scalarType& c) const
124 linearType inverse(const linearType& c) const
126 return cmptDivide(pTraits<linearType>::one, c);
130 // Triple product of coefficients
132 scalarType tripleProduct
142 linearType tripleProduct
149 return cmptDivide(cmptMultiply(a, c), b);
152 linearType tripleProduct
159 return a*c*inverse(b);
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();
189 explicit DecoupledBlockCoeff();
191 //- Construct as copy
192 DecoupledBlockCoeff(const DecoupledBlockCoeff<Type>&);
194 //- Construct from Istream
195 DecoupledBlockCoeff(Istream&);
198 DecoupledBlockCoeff<Type> clone() const;
203 ~DecoupledBlockCoeff();
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
220 const scalarType& asScalar() const;
221 scalarType& asScalar();
224 const linearType& asLinear() const;
225 linearType& asLinear();
229 scalarType component(const direction) const;
234 void operator=(const DecoupledBlockCoeff<Type>&);
237 // IOstream operators
239 friend Ostream& operator<< <Type>
242 const DecoupledBlockCoeff<Type>&
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 } // End namespace Foam
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 # include "DecoupledBlockCoeff.C"
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 // ************************************************************************* //