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
26 DecoupledCoeffField<T>
29 Generic coefficient field type. Used in BlockLduMatrix. HJ, 2/Apr/2005
32 Hrvoje Jasak, Wikki Ltd. All rights reserved
37 \*---------------------------------------------------------------------------*/
39 #ifndef DecoupledCoeffField_H
40 #define DecoupledCoeffField_H
42 #include "VectorSpace.H"
43 #include "primitiveFields.H"
44 #include "blockCoeffs.H"
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
54 class DecoupledCoeffField;
57 Ostream& operator<<(Ostream&, const DecoupledCoeffField<Type>&);
60 Ostream& operator<<(Ostream&, const tmp<DecoupledCoeffField<Type> >&);
63 /*---------------------------------------------------------------------------*\
64 Class DecoupledCoeffField Declaration
65 \*---------------------------------------------------------------------------*/
68 class DecoupledCoeffField
77 typedef typename BlockCoeff<Type>::scalarType scalarType;
78 typedef typename BlockCoeff<Type>::linearType linearType;
81 typedef typename BlockCoeff<Type>::scalarTypeField scalarTypeField;
82 typedef typename BlockCoeff<Type>::linearTypeField linearTypeField;
89 //- Scalar coefficient
90 mutable scalarTypeField* scalarCoeffPtr_;
92 //- Linear coefficient
93 mutable linearTypeField* linearCoeffPtr_;
95 //- Number of elements
99 // Private Member Functions
101 //- Check size for arithmetic operations: resizing is not allowed!
102 template<class Type2>
103 inline void checkSize(const UList<Type2>&) const;
105 //- Promote to scalar
106 scalarTypeField& toScalar();
108 //- Promote to linear
109 linearTypeField& toLinear();
114 // Static data members
116 static const char* const typeName;
121 //- Construct given size
122 explicit DecoupledCoeffField(const label);
124 //- Construct as copy
125 DecoupledCoeffField(const DecoupledCoeffField<Type>&);
127 //- Construct from Istream
128 explicit DecoupledCoeffField(Istream&);
131 tmp<DecoupledCoeffField<Type> > clone() const;
136 ~DecoupledCoeffField();
145 inline label size() const;
147 //- Return active type
148 blockCoeffBase::activeLevel activeType() const;
150 //- Check pointers: only one type should be active (debug only)
151 void checkActive() const;
153 //- Negate this field
156 //- Return the field transpose
157 tmp<DecoupledCoeffField<Type> > transpose() const;
160 // Return as typed. Fails when asked for the incorrect type
162 //- Return as scalar field
163 const scalarTypeField& asScalar() const;
165 //- Return as linear field
166 const linearTypeField& asLinear() const;
169 // Return as typed. Fails when asked for demotion
171 //- Return as scalar field
172 scalarTypeField& asScalar();
174 //- Return as linear field
175 linearTypeField& asLinear();
179 tmp<scalarTypeField> component(const direction) const;
181 //- Return coefficient as block
182 BlockCoeff<Type> getCoeff(const label index) const;
184 //- Set coefficient from a block
185 void setCoeff(const label index, const BlockCoeff<Type>& coeff);
190 //- Get subset with offset and size and store in given field
193 DecoupledCoeffField<Type>& f,
198 //- Get subset with addressing and store in given field
201 DecoupledCoeffField<Type>& f,
202 const labelList& addr
206 //- Set subset with offset and size from given field
209 const DecoupledCoeffField<Type>& f,
214 //- Get subset with addressing and store in target field
217 const DecoupledCoeffField<Type>& f,
218 const labelList& addr
221 //- Zero out subset with offset and size
228 //- Zero out subset with addressing
231 const labelList& addr
234 //- Add subset with addressing to field
237 const DecoupledCoeffField<Type>& f,
238 const labelList& addr
244 void operator=(const DecoupledCoeffField<Type>&);
245 void operator=(const tmp<DecoupledCoeffField<Type> >&);
247 void operator=(const scalarTypeField&);
248 void operator=(const tmp<scalarTypeField>&);
249 void operator=(const linearTypeField&);
250 void operator=(const tmp<linearTypeField>&);
253 void operator+=(const DecoupledCoeffField<Type>&);
254 void operator+=(const tmp<DecoupledCoeffField<Type> >&);
256 void operator+=(const scalarTypeField&);
257 void operator+=(const tmp<scalarTypeField>&);
258 void operator+=(const linearTypeField&);
259 void operator+=(const tmp<linearTypeField>&);
261 void operator-=(const DecoupledCoeffField<Type>&);
262 void operator-=(const tmp<DecoupledCoeffField<Type> >&);
264 void operator-=(const scalarTypeField&);
265 void operator-=(const tmp<scalarTypeField>&);
266 void operator-=(const linearTypeField&);
267 void operator-=(const tmp<linearTypeField>&);
269 void operator*=(const UList<scalar>&);
270 void operator*=(const tmp<Field<scalar> >&);
271 void operator*=(const scalar&);
273 void operator/=(const UList<scalar>&);
274 void operator/=(const tmp<Field<scalar> >&);
275 void operator/=(const scalar&);
278 // IOstream operators
280 friend Ostream& operator<< <Type>
283 const DecoupledCoeffField<Type>&
286 friend Ostream& operator<< <Type>
289 const tmp<DecoupledCoeffField<Type> >&
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 } // End namespace Foam
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 #include "DecoupledCoeffFieldFunctions.H"
303 # include "DecoupledCoeffField.C"
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 // ************************************************************************* //