1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Dynamically sized Field. WIP.
34 \*---------------------------------------------------------------------------*/
36 #ifndef DynamicField_H
37 #define DynamicField_H
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 // Forward declaration of friend functions and operators
52 Ostream& operator<<(Ostream&, const DynamicField<Type>&);
55 Ostream& operator<<(Ostream&, const tmp<DynamicField<Type> >&);
58 Istream& operator>>(Istream&, DynamicField<Type>&);
61 /*---------------------------------------------------------------------------*\
62 Class DynamicField Declaration
63 \*---------------------------------------------------------------------------*/
73 //- The capacity (allocated size) of the underlying field.
77 //- Construct given size and initial value
78 DynamicField(const label, const Type&);
80 //- Construct as copy of tmp<DynamicField>
81 # ifdef ConstructFromTmp
82 DynamicField(const tmp<DynamicField<Type> >&);
85 //- Construct from a dictionary entry
86 DynamicField(const word&, const dictionary&, const label);
90 // Static data members
92 static const char* const typeName;
95 // Static Member Functions
97 //- Return a null field
98 inline static const DynamicField<Type>& null()
100 return *reinterpret_cast< DynamicField<Type>* >(0);
107 // Used for temporary fields which are initialised after construction
110 //- Construct given size
111 // Used for temporary fields which are initialised after construction
112 explicit inline DynamicField(const label);
114 //- Construct as copy of a UList\<Type\>
115 explicit inline DynamicField(const UList<Type>&);
117 //- Construct by transferring the List contents
118 explicit inline DynamicField(const Xfer<List<Type> >&);
120 //- Construct by 1 to 1 mapping from the given field
123 const UList<Type>& mapF,
124 const labelList& mapAddressing
127 //- Construct by interpolative mapping from the given field
130 const UList<Type>& mapF,
131 const labelListList& mapAddressing,
132 const scalarListList& weights
135 //- Construct by mapping from the given field
138 const UList<Type>& mapF,
139 const FieldMapper& map
142 //- Construct as copy
143 inline DynamicField(const DynamicField<Type>&);
145 //- Construct as copy or re-use as specified.
146 inline DynamicField(DynamicField<Type>&, bool reUse);
148 //- Construct by transferring the Field contents
149 inline DynamicField(const Xfer<DynamicField<Type> >&);
151 //- Construct from Istream
152 inline DynamicField(Istream&);
155 tmp<DynamicField<Type> > clone() const;
160 //- Size of the underlying storage.
161 inline label capacity() const;
163 //- Append an element at the end of the list
164 inline void append(const Type&);
166 //- Alter the addressed list size.
167 // New space will be allocated if required.
168 // Use this to resize the list prior to using the operator[] for
169 // setting values (as per List usage).
170 void setSize(const label nElem);
174 inline void operator=(const DynamicField<Type>&);
175 inline void operator=(const UList<Type>&);
176 inline void operator=(const tmp<DynamicField<Type> >&);
178 //- Return element of Field.
179 inline Type& operator[](const label i);
181 //- Return element of constant Field.
182 inline const Type& operator[](const label) const;
184 // IOstream operators
186 friend Ostream& operator<< <Type>
187 (Ostream&, const DynamicField<Type>&);
189 friend Ostream& operator<< <Type>
190 (Ostream&, const tmp<DynamicField<Type> >&);
192 friend Istream& operator>> <Type>
193 (Istream&, DynamicField<Type>&);
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 } // End namespace Foam
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 #include "DynamicFieldI.H"
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 # include "DynamicField.C"
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 // ************************************************************************* //