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 Generic coefficient field type. Used in BlockLduMatrix. HJ, 2/Apr/2005
32 Hrvoje Jasak, Wikki Ltd. All rights reserved
37 \*---------------------------------------------------------------------------*/
42 #include "VectorSpace.H"
43 #include "primitiveFields.H"
44 #include "blockCoeffs.H"
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
57 Ostream& operator<<(Ostream&, const CoeffField<Type>&);
60 Ostream& operator<<(Ostream&, const tmp<CoeffField<Type> >&);
63 /*---------------------------------------------------------------------------*\
64 Class CoeffField Declaration
65 \*---------------------------------------------------------------------------*/
77 typedef typename BlockCoeff<Type>::scalarType scalarType;
78 typedef typename BlockCoeff<Type>::linearType linearType;
79 typedef typename BlockCoeff<Type>::squareType squareType;
82 typedef typename BlockCoeff<Type>::scalarTypeField scalarTypeField;
83 typedef typename BlockCoeff<Type>::linearTypeField linearTypeField;
84 typedef typename BlockCoeff<Type>::squareTypeField squareTypeField;
91 //- Scalar coefficient
92 mutable scalarTypeField* scalarCoeffPtr_;
94 //- Linear coefficient
95 mutable linearTypeField* linearCoeffPtr_;
97 //- Square coefficient
98 mutable squareTypeField* squareCoeffPtr_;
100 //- Number of elements
104 // Private Member Functions
106 //- Check size for arithmetic operations: resizing is not allowed!
107 template<class Type2>
108 inline void checkSize(const UList<Type2>&) const;
110 //- Promote to scalar
111 scalarTypeField& toScalar();
113 //- Promote to linear
114 linearTypeField& toLinear();
116 //- Promote to square
117 squareTypeField& toSquare();
122 // Static data members
124 static const char* const typeName;
129 //- Construct given size
130 explicit CoeffField(const label);
132 //- Construct as copy
133 CoeffField(const CoeffField<Type>&);
135 //- Construct from Istream
136 explicit CoeffField(Istream&);
139 tmp<CoeffField<Type> > clone() const;
153 inline label size() const;
155 //- Return active type
156 blockCoeffBase::activeLevel activeType() const;
158 //- Check pointers: only one type should be active (debug only)
159 void checkActive() const;
161 //- Negate this field
164 //- Return the field transpose
165 tmp<CoeffField<Type> > transpose() const;
168 // Return as typed. Fails when asked for the incorrect type
170 //- Return as scalar field
171 const scalarTypeField& asScalar() const;
173 //- Return as linear field
174 const linearTypeField& asLinear() const;
176 //- Return as square field
177 const squareTypeField& asSquare() const;
180 // Return as typed. Fails when asked for demotion
182 //- Return as scalar field
183 scalarTypeField& asScalar();
185 //- Return as linear field
186 linearTypeField& asLinear();
188 //- Return as square field
189 squareTypeField& asSquare();
193 tmp<scalarTypeField> component(const direction) const;
195 //- Return coefficient as block
196 BlockCoeff<Type> getCoeff(const label index) const;
198 //- Set coefficient from a block
199 void setCoeff(const label index, const BlockCoeff<Type>& coeff);
204 //- Get subset with offset and size and store in given field
212 //- Get subset with addressing and store in given field
216 const labelList& addr
220 //- Set subset with offset and size from given field
223 const CoeffField<Type>& f,
228 //- Get subset with addressing and store in target field
231 const CoeffField<Type>& f,
232 const labelList& addr
235 //- Zero out subset with offset and size
242 //- Zero out subset with addressing
245 const labelList& addr
248 //- Add subset with addressing to field
251 const CoeffField<Type>& f,
252 const labelList& addr
258 void operator=(const CoeffField<Type>&);
259 void operator=(const tmp<CoeffField<Type> >&);
261 void operator=(const scalarTypeField&);
262 void operator=(const tmp<scalarTypeField>&);
263 void operator=(const linearTypeField&);
264 void operator=(const tmp<linearTypeField>&);
265 void operator=(const squareTypeField&);
266 void operator=(const tmp<squareTypeField>&);
269 void operator+=(const CoeffField<Type>&);
270 void operator+=(const tmp<CoeffField<Type> >&);
272 void operator+=(const scalarTypeField&);
273 void operator+=(const tmp<scalarTypeField>&);
274 void operator+=(const linearTypeField&);
275 void operator+=(const tmp<linearTypeField>&);
276 void operator+=(const squareTypeField&);
277 void operator+=(const tmp<squareTypeField>&);
279 void operator-=(const CoeffField<Type>&);
280 void operator-=(const tmp<CoeffField<Type> >&);
282 void operator-=(const scalarTypeField&);
283 void operator-=(const tmp<scalarTypeField>&);
284 void operator-=(const linearTypeField&);
285 void operator-=(const tmp<linearTypeField>&);
286 void operator-=(const squareTypeField&);
287 void operator-=(const tmp<squareTypeField>&);
289 void operator*=(const UList<scalar>&);
290 void operator*=(const tmp<Field<scalar> >&);
291 void operator*=(const scalar&);
293 void operator/=(const UList<scalar>&);
294 void operator/=(const tmp<Field<scalar> >&);
295 void operator/=(const scalar&);
298 // IOstream operators
300 friend Ostream& operator<< <Type>
303 const CoeffField<Type>&
306 friend Ostream& operator<< <Type>
309 const tmp<CoeffField<Type> >&
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 } // End namespace Foam
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 #include "CoeffFieldFunctions.H"
323 # include "CoeffField.C"
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 // ************************************************************************* //