Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / blockMatrix / CoeffField / DecoupledCoeffField.H
blobd3bda8aead0869e807a43f93ea8c40452e881d66
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     DecoupledCoeffField<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     DecoupledCoeffField.C
37 \*---------------------------------------------------------------------------*/
39 #ifndef DecoupledCoeffField_H
40 #define DecoupledCoeffField_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 DecoupledCoeffField;
56 template<class Type>
57 Ostream& operator<<(Ostream&, const DecoupledCoeffField<Type>&);
59 template<class Type>
60 Ostream& operator<<(Ostream&, const tmp<DecoupledCoeffField<Type> >&);
63 /*---------------------------------------------------------------------------*\
64                           Class DecoupledCoeffField Declaration
65 \*---------------------------------------------------------------------------*/
67 template<class Type>
68 class DecoupledCoeffField
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;
80         //- Field type
81         typedef typename BlockCoeff<Type>::scalarTypeField scalarTypeField;
82         typedef typename BlockCoeff<Type>::linearTypeField linearTypeField;
85 private:
87     // Private data
89         //- Scalar coefficient
90         mutable scalarTypeField* scalarCoeffPtr_;
92         //- Linear coefficient
93         mutable linearTypeField* linearCoeffPtr_;
95         //- Number of elements
96         label size_;
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();
112 public:
114     // Static data members
116         static const char* const typeName;
119     // Constructors
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&);
130         //- Clone
131         tmp<DecoupledCoeffField<Type> > clone() const;
134     // Destructor
136         ~DecoupledCoeffField();
138         //- Clear data
139         void clear();
142     // Member functions
144         //- Return size
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
154         void negate();
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();
178         //- Return component
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);
188         // Subset operations
190             //- Get subset with offset and size and store in given field
191             void getSubset
192             (
193                 DecoupledCoeffField<Type>& f,
194                 const label start,
195                 const label size
196             ) const;
198             //- Get subset with addressing and store in given field
199             void getSubset
200             (
201                 DecoupledCoeffField<Type>& f,
202                 const labelList& addr
203             ) const;
206             //- Set subset with offset and size from given field
207             void setSubset
208             (
209                 const DecoupledCoeffField<Type>& f,
210                 const label start,
211                 const label size
212             );
214             //- Get subset with addressing and store in target field
215             void setSubset
216             (
217                 const DecoupledCoeffField<Type>& f,
218                 const labelList& addr
219             );
221             //- Zero out subset with offset and size
222             void zeroOutSubset
223             (
224                 const label start,
225                 const label size
226             );
228             //- Zero out subset with addressing
229             void zeroOutSubset
230             (
231                 const labelList& addr
232             );
234             //- Add subset with addressing to field
235             void addSubset
236             (
237                 const DecoupledCoeffField<Type>& f,
238                 const labelList& addr
239             );
242     // Member operators
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>
281         (
282             Ostream&,
283             const DecoupledCoeffField<Type>&
284         );
286         friend Ostream& operator<< <Type>
287         (
288             Ostream&,
289             const tmp<DecoupledCoeffField<Type> >&
290         );
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 } // End namespace Foam
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
300 #include "DecoupledCoeffFieldFunctions.H"
302 #ifdef NoRepository
303 #   include "DecoupledCoeffField.C"
304 #endif
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308 #endif
310 // ************************************************************************* //