1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | 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 Generic coefficient field type. Used in BlockLduMatrix. HJ, 2/Apr/2005
31 Hrvoje Jasak, Wikki Ltd. All rights reserved
36 \*---------------------------------------------------------------------------*/
41 #include "VectorSpace.H"
42 #include "primitiveFields.H"
43 #include "blockCoeffs.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
56 Ostream& operator<<(Ostream&, const CoeffField<Type>&);
59 Ostream& operator<<(Ostream&, const tmp<CoeffField<Type> >&);
62 /*---------------------------------------------------------------------------*\
63 Class CoeffField Declaration
64 \*---------------------------------------------------------------------------*/
76 typedef typename BlockCoeff<Type>::scalarType scalarType;
77 typedef typename BlockCoeff<Type>::linearType linearType;
78 typedef typename BlockCoeff<Type>::squareType squareType;
81 typedef typename BlockCoeff<Type>::scalarTypeField scalarTypeField;
82 typedef typename BlockCoeff<Type>::linearTypeField linearTypeField;
83 typedef typename BlockCoeff<Type>::squareTypeField squareTypeField;
90 //- Scalar coefficient
91 mutable scalarTypeField* scalarCoeffPtr_;
93 //- Linear coefficient
94 mutable linearTypeField* linearCoeffPtr_;
96 //- Square coefficient
97 mutable squareTypeField* squareCoeffPtr_;
99 //- Number of elements
103 // Private Member Functions
105 //- Check size for arithmetic operations: resizing is not allowed!
106 template<class Type2>
107 inline void checkSize(const UList<Type2>&) const;
109 //- Promote to scalar
110 scalarTypeField& toScalar();
112 //- Promote to linear
113 linearTypeField& toLinear();
115 //- Promote to square
116 squareTypeField& toSquare();
121 // Static data members
123 static const char* const typeName;
128 //- Construct given size
129 explicit CoeffField(const label);
131 //- Construct as copy
132 CoeffField(const CoeffField<Type>&);
134 //- Construct from Istream
135 explicit CoeffField(Istream&);
138 tmp<CoeffField<Type> > clone() const;
152 inline label size() const;
154 //- Return active type
155 blockCoeffBase::activeLevel activeType() const;
157 //- Check pointers: only one type should be active (debug only)
158 void checkActive() const;
160 //- Negate this field
163 //- Return the field transpose
164 tmp<CoeffField<Type> > transpose() const;
167 // Return as typed. Fails when asked for the incorrect type
169 //- Return as scalar field
170 const scalarTypeField& asScalar() const;
172 //- Return as linear field
173 const linearTypeField& asLinear() const;
175 //- Return as square field
176 const squareTypeField& asSquare() const;
179 // Return as typed. Fails when asked for demotion
181 //- Return as scalar field
182 scalarTypeField& asScalar();
184 //- Return as linear field
185 linearTypeField& asLinear();
187 //- Return as square field
188 squareTypeField& asSquare();
192 tmp<scalarTypeField> component(const direction) const;
194 //- Return coefficient as block
195 BlockCoeff<Type> getCoeff(const label index) const;
197 //- Set coefficient from a block
198 void setCoeff(const label index, const BlockCoeff<Type>& coeff);
203 //- Get subset with offset and size and store in given field
211 //- Get subset with addressing and store in given field
215 const labelList& addr
219 //- Set subset with offset and size from given field
222 const CoeffField<Type>& f,
227 //- Get subset with addressing and store in target field
230 const CoeffField<Type>& f,
231 const labelList& addr
234 //- Zero out subset with offset and size
241 //- Zero out subset with addressing
244 const labelList& addr
247 //- Add subset with addressing to field
250 const CoeffField<Type>& f,
251 const labelList& addr
254 //- Subtract subset with addressing to field
257 const CoeffField<Type>& f,
258 const labelList& addr
262 void operator=(const CoeffField<Type>&);
263 void operator=(const tmp<CoeffField<Type> >&);
265 void operator=(const scalarTypeField&);
266 void operator=(const tmp<scalarTypeField>&);
267 void operator=(const linearTypeField&);
268 void operator=(const tmp<linearTypeField>&);
269 void operator=(const squareTypeField&);
270 void operator=(const tmp<squareTypeField>&);
273 void operator+=(const CoeffField<Type>&);
274 void operator+=(const tmp<CoeffField<Type> >&);
276 void operator+=(const scalarTypeField&);
277 void operator+=(const tmp<scalarTypeField>&);
278 void operator+=(const linearTypeField&);
279 void operator+=(const tmp<linearTypeField>&);
280 void operator+=(const squareTypeField&);
281 void operator+=(const tmp<squareTypeField>&);
283 void operator-=(const CoeffField<Type>&);
284 void operator-=(const tmp<CoeffField<Type> >&);
286 void operator-=(const scalarTypeField&);
287 void operator-=(const tmp<scalarTypeField>&);
288 void operator-=(const linearTypeField&);
289 void operator-=(const tmp<linearTypeField>&);
290 void operator-=(const squareTypeField&);
291 void operator-=(const tmp<squareTypeField>&);
293 void operator*=(const UList<scalar>&);
294 void operator*=(const tmp<Field<scalar> >&);
295 void operator*=(const scalar&);
297 void operator/=(const UList<scalar>&);
298 void operator/=(const tmp<Field<scalar> >&);
299 void operator/=(const scalar&);
301 tmp<CoeffField<Type> > operator-();
303 // IOstream operators
305 friend Ostream& operator<< <Type>
308 const CoeffField<Type>&
311 friend Ostream& operator<< <Type>
314 const tmp<CoeffField<Type> >&
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 } // End namespace Foam
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 #include "CoeffFieldFunctions.H"
328 # include "CoeffField.C"
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 // ************************************************************************* //