00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::DynamicField 00026 00027 Description 00028 Dynamically sized Field. 00029 00030 SourceFiles 00031 DynamicFieldI.H 00032 DynamicField.C 00033 00034 \*---------------------------------------------------------------------------*/ 00035 00036 #ifndef DynamicField_H 00037 #define DynamicField_H 00038 00039 #include <OpenFOAM/Field.H> 00040 00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00042 00043 namespace Foam 00044 { 00045 00046 // Forward declaration of friend functions and operators 00047 00048 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 00049 class DynamicField; 00050 00051 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 00052 Ostream& operator<< 00053 ( 00054 Ostream&, 00055 const DynamicField<T, SizeInc, SizeMult, SizeDiv>& 00056 ); 00057 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv> 00058 Istream& operator>> 00059 ( 00060 Istream&, 00061 DynamicField<T, SizeInc, SizeMult, SizeDiv>& 00062 ); 00063 00064 00065 /*---------------------------------------------------------------------------*\ 00066 Class DynamicField Declaration 00067 \*---------------------------------------------------------------------------*/ 00068 00069 template<class T, unsigned SizeInc=0, unsigned SizeMult=2, unsigned SizeDiv=1> 00070 class DynamicField 00071 : 00072 public Field<T> 00073 { 00074 // Private data 00075 00076 //- The capacity (allocated size) of the underlying field. 00077 label capacity_; 00078 00079 00080 public: 00081 00082 // Static Member Functions 00083 00084 //- Return a null field 00085 inline static const DynamicField<T, SizeInc, SizeMult, SizeDiv>& null() 00086 { 00087 return *reinterpret_cast 00088 < 00089 DynamicField<T, SizeInc, SizeMult, SizeDiv>* 00090 >(0); 00091 } 00092 00093 00094 // Constructors 00095 00096 //- Construct null 00097 inline DynamicField(); 00098 00099 //- Construct given size. 00100 explicit inline DynamicField(const label); 00101 00102 //- Construct from UList. Size set to UList size. 00103 // Also constructs from DynamicField with different sizing parameters. 00104 explicit inline DynamicField(const UList<T>&); 00105 00106 //- Construct by transferring the parameter contents 00107 explicit inline DynamicField(const Xfer<List<T> >&); 00108 00109 //- Construct by 1 to 1 mapping from the given field 00110 inline DynamicField 00111 ( 00112 const UList<T>& mapF, 00113 const labelList& mapAddressing 00114 ); 00115 00116 //- Construct by interpolative mapping from the given field 00117 inline DynamicField 00118 ( 00119 const UList<T>& mapF, 00120 const labelListList& mapAddressing, 00121 const scalarListList& weights 00122 ); 00123 00124 //- Construct by mapping from the given field 00125 inline DynamicField 00126 ( 00127 const UList<T>& mapF, 00128 const FieldMapper& map 00129 ); 00130 00131 //- Construct copy 00132 inline DynamicField(const DynamicField<T, SizeInc, SizeMult, SizeDiv>&); 00133 00134 //- Construct by transferring the Field contents 00135 inline DynamicField 00136 ( 00137 const Xfer<DynamicField<T, SizeInc, SizeMult, SizeDiv> >& 00138 ); 00139 00140 //- Construct from Istream. Size set to size of list read. 00141 explicit DynamicField(Istream&); 00142 00143 //- Clone 00144 tmp<DynamicField<T, SizeInc, SizeMult, SizeDiv> > clone() const; 00145 00146 00147 // Member Functions 00148 00149 // Access 00150 00151 //- Size of the underlying storage. 00152 inline label capacity() const; 00153 00154 // Edit 00155 00156 //- Alter the size of the underlying storage. 00157 // The addressed size will be truncated if needed to fit, but will 00158 // remain otherwise untouched. 00159 // Use this or reserve() in combination with append(). 00160 inline void setCapacity(const label); 00161 00162 //- Alter the addressed list size. 00163 // New space will be allocated if required. 00164 // Use this to resize the list prior to using the operator[] for 00165 // setting values (as per List usage). 00166 inline void setSize(const label); 00167 00168 //- Alter the addressed list size and fill new space with a 00169 // constant. 00170 inline void setSize(const label, const T&); 00171 00172 //- Alter the addressed list size. 00173 // New space will be allocated if required. 00174 // Use this to resize the list prior to using the operator[] for 00175 // setting values (as per List usage). 00176 inline void resize(const label); 00177 00178 //- Alter the addressed list size and fill new space with a 00179 // constant. 00180 inline void resize(const label, const T&); 00181 00182 //- Reserve allocation space for at least this size. 00183 // Never shrinks the allocated size, use setCapacity() for that. 00184 inline void reserve(const label); 00185 00186 //- Clear the addressed list, i.e. set the size to zero. 00187 // Allocated size does not change 00188 inline void clear(); 00189 00190 //- Clear the list and delete storage. 00191 inline void clearStorage(); 00192 00193 //- Shrink the allocated space to the number of elements used. 00194 // Returns a reference to the DynamicField. 00195 inline DynamicField<T, SizeInc, SizeMult, SizeDiv>& shrink(); 00196 00197 //- Transfer contents to the Xfer container as a plain List 00198 inline Xfer<List<T> > xfer(); 00199 00200 00201 // Member Operators 00202 00203 //- Append an element at the end of the list 00204 inline DynamicField<T, SizeInc, SizeMult, SizeDiv>& append 00205 ( 00206 const T& 00207 ); 00208 00209 //- Append a List at the end of this list 00210 inline DynamicField<T, SizeInc, SizeMult, SizeDiv>& append 00211 ( 00212 const UList<T>& 00213 ); 00214 00215 //- Remove and return the top element 00216 inline T remove(); 00217 00218 //- Return non-const access to an element, resizing list if 00219 // necessary 00220 inline T& operator()(const label); 00221 00222 //- Assignment of all addressed entries to the given value 00223 inline void operator=(const T&); 00224 00225 //- Assignment from DynamicField 00226 inline void operator= 00227 ( 00228 const DynamicField<T, SizeInc, SizeMult, SizeDiv>& 00229 ); 00230 00231 //- Assignment from UList 00232 inline void operator=(const UList<T>&); 00233 00234 00235 // IOstream operators 00236 00237 // Write DynamicField to Ostream. 00238 friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv> 00239 ( 00240 Ostream&, 00241 const DynamicField<T, SizeInc, SizeMult, SizeDiv>& 00242 ); 00243 00244 //- Read from Istream, discarding contents of existing DynamicField. 00245 friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv> 00246 ( 00247 Istream&, 00248 DynamicField<T, SizeInc, SizeMult, SizeDiv>& 00249 ); 00250 }; 00251 00252 00253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00254 00255 } // End namespace Foam 00256 00257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00258 00259 #include "DynamicFieldI.H" 00260 00261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00262 00263 #ifdef NoRepository 00264 # include "DynamicField.C" 00265 #endif 00266 00267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00268 00269 #endif 00270 00271 // ************************ vim: set sw=4 sts=4 et: ************************ //