Report patch name instead of index in debug
[foam-extend-3.2.git] / src / foam / fields / CoeffField / CoeffField.H
bloba4ff4c7a571199195ee0aba26962d64912105b19
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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/>.
24 Class
25     CoeffField<T>
27 Description
28     Generic coefficient field type.  Used in BlockLduMatrix.  HJ, 2/Apr/2005
30 Author
31     Hrvoje Jasak, Wikki Ltd.  All rights reserved
33 SourceFiles
34     CoeffField.C
36 \*---------------------------------------------------------------------------*/
38 #ifndef CoeffField_H
39 #define CoeffField_H
41 #include "VectorSpace.H"
42 #include "primitiveFields.H"
43 #include "blockCoeffs.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 namespace Foam
50 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
52 template<class Type>
53 class CoeffField;
55 template<class Type>
56 Ostream& operator<<(Ostream&, const CoeffField<Type>&);
58 template<class Type>
59 Ostream& operator<<(Ostream&, const tmp<CoeffField<Type> >&);
62 /*---------------------------------------------------------------------------*\
63                           Class CoeffField Declaration
64 \*---------------------------------------------------------------------------*/
66 template<class Type>
67 class CoeffField
69     public refCount
71 public:
73     // Public data types
75         //- Component type
76         typedef typename BlockCoeff<Type>::scalarType scalarType;
77         typedef typename BlockCoeff<Type>::linearType linearType;
78         typedef typename BlockCoeff<Type>::squareType squareType;
80         //- Field type
81         typedef typename BlockCoeff<Type>::scalarTypeField scalarTypeField;
82         typedef typename BlockCoeff<Type>::linearTypeField linearTypeField;
83         typedef typename BlockCoeff<Type>::squareTypeField squareTypeField;
86 private:
88     // Private data
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
100         label size_;
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();
119 public:
121     // Static data members
123         static const char* const typeName;
126     // Constructors
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&);
137         //- Clone
138         tmp<CoeffField<Type> > clone() const;
141     // Destructor
143         ~CoeffField();
145         //- Clear data
146         void clear();
149     // Member functions
151         //- Return size
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
161         void negate();
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();
191         //- Return component
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);
201         // Subset operations
203             //- Get subset with offset and size and store in given field
204             void getSubset
205             (
206                 CoeffField<Type>& f,
207                 const label start,
208                 const label size
209             ) const;
211             //- Get subset with addressing and store in given field
212             void getSubset
213             (
214                 CoeffField<Type>& f,
215                 const labelList& addr
216             ) const;
219             //- Set subset with offset and size from given field
220             void setSubset
221             (
222                 const CoeffField<Type>& f,
223                 const label start,
224                 const label size
225             );
227             //- Get subset with addressing and store in target field
228             void setSubset
229             (
230                 const CoeffField<Type>& f,
231                 const labelList& addr
232             );
234             //- Zero out subset with offset and size
235             void zeroOutSubset
236             (
237                 const label start,
238                 const label size
239             );
241             //- Zero out subset with addressing
242             void zeroOutSubset
243             (
244                 const labelList& addr
245             );
247             //- Add subset with addressing to field
248             void addSubset
249             (
250                 const CoeffField<Type>& f,
251                 const labelList& addr
252             );
254             //- Subtract subset with addressing to field
255             void subtractSubset
256             (
257                 const CoeffField<Type>& f,
258                 const labelList& addr
259             );
260     // Member operators
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>
306         (
307             Ostream&,
308             const CoeffField<Type>&
309         );
311         friend Ostream& operator<< <Type>
312         (
313             Ostream&,
314             const tmp<CoeffField<Type> >&
315         );
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 } // End namespace Foam
323 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 #include "CoeffFieldFunctions.H"
327 #ifdef NoRepository
328 #   include "CoeffField.C"
329 #endif
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
333 #endif
335 // ************************************************************************* //