Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / blockMatrix / CoeffField / CoeffField.H
blob613b2d52aebdb3facbe9e888c06b6245cba57955
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-6 H. Jasak All rights reserved
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     CoeffField<T>
28 Description
29     Generic coefficient field type.  Used in BlockLduMatrix.  HJ, 2/Apr/2005
31 Author
32     Hrvoje Jasak, Wikki Ltd.  All rights reserved
34 SourceFiles
35     CoeffField.C
37 \*---------------------------------------------------------------------------*/
39 #ifndef CoeffField_H
40 #define CoeffField_H
42 #include "VectorSpace.H"
43 #include "primitiveFields.H"
44 #include "blockCoeffs.H"
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 namespace Foam
51 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
53 template<class Type>
54 class CoeffField;
56 template<class Type>
57 Ostream& operator<<(Ostream&, const CoeffField<Type>&);
59 template<class Type>
60 Ostream& operator<<(Ostream&, const tmp<CoeffField<Type> >&);
63 /*---------------------------------------------------------------------------*\
64                           Class CoeffField Declaration
65 \*---------------------------------------------------------------------------*/
67 template<class Type>
68 class CoeffField
70     public refCount
72 public:
74     // Public data types
76         //- Component type
77         typedef typename BlockCoeff<Type>::scalarType scalarType;
78         typedef typename BlockCoeff<Type>::linearType linearType;
79         typedef typename BlockCoeff<Type>::squareType squareType;
81         //- Field type
82         typedef typename BlockCoeff<Type>::scalarTypeField scalarTypeField;
83         typedef typename BlockCoeff<Type>::linearTypeField linearTypeField;
84         typedef typename BlockCoeff<Type>::squareTypeField squareTypeField;
87 private:
89     // Private data
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
101         label size_;
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();
120 public:
122     // Static data members
124         static const char* const typeName;
127     // Constructors
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&);
138         //- Clone
139         tmp<CoeffField<Type> > clone() const;
142     // Destructor
144         ~CoeffField();
146         //- Clear data
147         void clear();
150     // Member functions
152         //- Return size
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
162         void negate();
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();
192         //- Return component
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);
202         // Subset operations
204             //- Get subset with offset and size and store in given field
205             void getSubset
206             (
207                 CoeffField<Type>& f,
208                 const label start,
209                 const label size
210             ) const;
212             //- Get subset with addressing and store in given field
213             void getSubset
214             (
215                 CoeffField<Type>& f,
216                 const labelList& addr
217             ) const;
220             //- Set subset with offset and size from given field
221             void setSubset
222             (
223                 const CoeffField<Type>& f,
224                 const label start,
225                 const label size
226             );
228             //- Get subset with addressing and store in target field
229             void setSubset
230             (
231                 const CoeffField<Type>& f,
232                 const labelList& addr
233             );
235             //- Zero out subset with offset and size
236             void zeroOutSubset
237             (
238                 const label start,
239                 const label size
240             );
242             //- Zero out subset with addressing
243             void zeroOutSubset
244             (
245                 const labelList& addr
246             );
248             //- Add subset with addressing to field
249             void addSubset
250             (
251                 const CoeffField<Type>& f,
252                 const labelList& addr
253             );
256     // Member operators
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>
301         (
302             Ostream&,
303             const CoeffField<Type>&
304         );
306         friend Ostream& operator<< <Type>
307         (
308             Ostream&,
309             const tmp<CoeffField<Type> >&
310         );
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
316 } // End namespace Foam
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 #include "CoeffFieldFunctions.H"
322 #ifdef NoRepository
323 #   include "CoeffField.C"
324 #endif
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 #endif
330 // ************************************************************************* //