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 Block coefficient combines a scalar, linear and square coefficient
30 for different levels of coupling
33 Hrvoje Jasak, Wikki Ltd. All rights reserved
35 \*---------------------------------------------------------------------------*/
40 #include "blockCoeffBase.H"
41 #include "expandTensor.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
55 Ostream& operator<<(Ostream&, const BlockCoeff<Type>&);
57 /*---------------------------------------------------------------------------*\
58 Class BlockCoeff Declaration
59 \*---------------------------------------------------------------------------*/
72 typedef Field<xType> xTypeField;
75 typedef typename pTraits<Type>::cmptType scalarType;
76 typedef Type linearType;
77 typedef typename outerProduct<Type, Type>::type squareType;
80 typedef Field<scalarType> scalarTypeField;
81 typedef Field<linearType> linearTypeField;
82 typedef Field<squareType> squareTypeField;
85 //- Multiplication trait
92 // Coefficient times type multiplication
94 Type operator()(const scalarType& c, const Type& x) const
99 Type operator()(const linearType& c, const Type& x) const
101 return cmptMultiply(c, x);
104 Type operator()(const squareType& c, const Type& x) const
109 Type operator()(const BlockCoeff<Type>& c, const Type& x) const
111 if (c.scalarCoeffPtr_)
113 return operator()(*c.scalarCoeffPtr_, x);
115 else if (c.linearCoeffPtr_)
117 return operator()(*c.linearCoeffPtr_, x);
119 else if (c.squareCoeffPtr_)
121 return operator()(*c.squareCoeffPtr_, x);
125 return pTraits<Type>::zero;
130 // Transpose functions
132 scalarType transpose(const scalarType& c) const
137 linearType transpose(const linearType& c) const
142 squareType transpose(const squareType& c) const
150 scalarType inverse(const scalarType& c) const
155 linearType inverse(const linearType& c) const
157 return cmptDivide(pTraits<linearType>::one, c);
160 squareType inverse(const squareType& c) const
166 // Triple product of coefficients
168 scalarType tripleProduct
178 linearType tripleProduct
185 return a*c*inverse(b);
188 linearType tripleProduct
195 return cmptDivide(cmptMultiply(a, c), b);
198 squareType tripleProduct
208 squareType tripleProduct
216 linearType sac = cmptMultiply(a, c);
218 expandLinear(result, sac);
219 return result & inv(b);
222 squareType tripleProduct
229 return (a & inv(b)) & c;
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();
265 explicit BlockCoeff();
267 //- Construct as copy
268 BlockCoeff(const BlockCoeff<Type>&);
270 //- Construct from Istream
271 BlockCoeff(Istream&);
274 BlockCoeff<Type> clone() const;
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
296 const scalarType& asScalar() const;
297 scalarType& asScalar();
300 const linearType& asLinear() const;
301 linearType& asLinear();
304 const squareType& asSquare() const;
305 squareType& asSquare();
309 scalarType component(const direction) const;
314 void operator=(const BlockCoeff<Type>&);
317 // IOstream operators
319 friend Ostream& operator<< <Type>
322 const BlockCoeff<Type>&
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 } // End namespace Foam
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 # include "BlockCoeff.C"
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
341 // ************************************************************************* //