1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
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/>.
28 Template for the terminal decoupled class. It is designed to avoid
29 endless expansion of tensor order by excluding block coupling at the
33 Hrvoje Jasak, Wikki Ltd. All rights reserved
35 \*---------------------------------------------------------------------------*/
37 #ifndef DecoupledBlockCoeff_H
38 #define DecoupledBlockCoeff_H
40 #include "blockCoeffBase.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
51 class DecoupledBlockCoeff;
54 Ostream& operator<<(Ostream&, const DecoupledBlockCoeff<Type>&);
56 /*---------------------------------------------------------------------------*\
57 Class DecoupledBlockCoeff Declaration
58 \*---------------------------------------------------------------------------*/
61 class DecoupledBlockCoeff
71 typedef Field<xType> xTypeField;
74 typedef scalar scalarType;
75 typedef Type linearType;
78 typedef Field<scalarType> scalarTypeField;
79 typedef Field<linearType> linearTypeField;
82 //- Multiplication trait
89 Type operator()(const scalarType& c, const Type& x) const
94 Type operator()(const linearType& c, const Type& x) const
96 return cmptMultiply(c, x);
99 Type operator()(const DecoupledBlockCoeff<Type>& c, const Type& x) const
101 if (c.scalarCoeffPtr_)
103 return operator()(*c.scalarCoeffPtr_, x);
105 else if (c.linearCoeffPtr_)
107 return operator()(*c.linearCoeffPtr_, x);
111 return pTraits<Type>::zero;
118 scalarType inverse(const scalarType& c) const
123 linearType inverse(const linearType& c) const
125 return cmptDivide(pTraits<linearType>::one, c);
129 // Triple product of coefficients
131 scalarType tripleProduct
141 linearType tripleProduct
148 return cmptDivide(cmptMultiply(a, c), b);
151 linearType tripleProduct
158 return a*c*inverse(b);
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();
188 explicit DecoupledBlockCoeff();
190 //- Construct as copy
191 DecoupledBlockCoeff(const DecoupledBlockCoeff<Type>&);
193 //- Construct from Istream
194 DecoupledBlockCoeff(Istream&);
197 DecoupledBlockCoeff<Type> clone() const;
202 ~DecoupledBlockCoeff();
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
219 const scalarType& asScalar() const;
220 scalarType& asScalar();
223 const linearType& asLinear() const;
224 linearType& asLinear();
228 scalarType component(const direction) const;
233 void operator=(const DecoupledBlockCoeff<Type>&);
236 // IOstream operators
238 friend Ostream& operator<< <Type>
241 const DecoupledBlockCoeff<Type>&
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 } // End namespace Foam
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 # include "DecoupledBlockCoeff.C"
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 // ************************************************************************* //