OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

DynamicField.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::DynamicField
00027 
00028 Description
00029     Dynamically sized Field. WIP.
00030 
00031 SourceFiles
00032     DynamicField.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef DynamicField_H
00037 #define DynamicField_H
00038 
00039 #include "Field.H"
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 namespace Foam
00044 {
00045 
00046 // Forward declaration of friend functions and operators
00047 
00048 template<class Type>
00049 class DynamicField;
00050 
00051 template<class Type>
00052 Ostream& operator<<(Ostream&, const DynamicField<Type>&);
00053 
00054 template<class Type>
00055 Ostream& operator<<(Ostream&, const tmp<DynamicField<Type> >&);
00056 
00057 template<class Type>
00058 Istream& operator>>(Istream&, DynamicField<Type>&);
00059 
00060 
00061 /*---------------------------------------------------------------------------*\
00062                            Class DynamicField Declaration
00063 \*---------------------------------------------------------------------------*/
00064 
00065 template<class Type>
00066 class DynamicField
00067 :
00068     public Field<Type>
00069 {
00070 
00071     // Private data
00072 
00073         //- The capacity (allocated size) of the underlying field.
00074         label capacity_;
00075 
00076 
00077         //- Construct given size and initial value
00078         DynamicField(const label, const Type&);
00079 
00080         //- Construct as copy of tmp<DynamicField>
00081 #       ifdef ConstructFromTmp
00082         DynamicField(const tmp<DynamicField<Type> >&);
00083 #       endif
00084 
00085         //- Construct from a dictionary entry
00086         DynamicField(const word&, const dictionary&, const label);
00087 
00088 public:
00089 
00090     // Static data members
00091 
00092         static const char* const typeName;
00093 
00094 
00095     // Static Member Functions
00096 
00097         //- Return a null field
00098         inline static const DynamicField<Type>& null()
00099         {
00100             return *reinterpret_cast< DynamicField<Type>* >(0);
00101         }
00102 
00103 
00104     // Constructors
00105 
00106         //- Construct null
00107         //  Used for temporary fields which are initialised after construction
00108         DynamicField();
00109 
00110         //- Construct given size
00111         //  Used for temporary fields which are initialised after construction
00112         explicit inline DynamicField(const label);
00113 
00114         //- Construct as copy of a UList<Type>
00115         explicit inline DynamicField(const UList<Type>&);
00116 
00117         //- Construct by transferring the List contents
00118         explicit inline DynamicField(const Xfer<List<Type> >&);
00119 
00120         //- Construct by 1 to 1 mapping from the given field
00121         inline DynamicField
00122         (
00123             const UList<Type>& mapF,
00124             const labelList& mapAddressing
00125         );
00126 
00127         //- Construct by interpolative mapping from the given field
00128         inline DynamicField
00129         (
00130             const UList<Type>& mapF,
00131             const labelListList& mapAddressing,
00132             const scalarListList& weights
00133         );
00134 
00135         //- Construct by mapping from the given field
00136         inline DynamicField
00137         (
00138             const UList<Type>& mapF,
00139             const FieldMapper& map
00140         );
00141 
00142         //- Construct as copy
00143         inline DynamicField(const DynamicField<Type>&);
00144 
00145         //- Construct as copy or re-use as specified.
00146         inline DynamicField(DynamicField<Type>&, bool reUse);
00147 
00148         //- Construct by transferring the Field contents
00149         inline DynamicField(const Xfer<DynamicField<Type> >&);
00150 
00151         //- Construct from Istream
00152         inline DynamicField(Istream&);
00153 
00154         //- Clone
00155         tmp<DynamicField<Type> > clone() const;
00156 
00157 
00158     // Member Functions
00159 
00160         //- Size of the underlying storage.
00161         inline label capacity() const;
00162 
00163         //- Append an element at the end of the list
00164         inline void append(const Type&);
00165 
00166         //- Alter the addressed list size.
00167         //  New space will be allocated if required.
00168         //  Use this to resize the list prior to using the operator[] for
00169         //  setting values (as per List usage).
00170         void setSize(const label nElem);
00171 
00172     // Member operators
00173 
00174         inline void operator=(const DynamicField<Type>&);
00175         inline void operator=(const UList<Type>&);
00176         inline void operator=(const tmp<DynamicField<Type> >&);
00177 
00178         //- Return element of Field.
00179         inline Type& operator[](const label i);
00180 
00181         //- Return element of constant Field.
00182         inline const Type& operator[](const label) const;
00183 
00184     // IOstream operators
00185 
00186         friend Ostream& operator<< <Type>
00187         (Ostream&, const DynamicField<Type>&);
00188 
00189         friend Ostream& operator<< <Type>
00190         (Ostream&, const tmp<DynamicField<Type> >&);
00191 
00192         friend Istream& operator>> <Type>
00193         (Istream&, DynamicField<Type>&);
00194 };
00195 
00196 
00197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00198 
00199 } // End namespace Foam
00200 
00201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00202 
00203 #include "DynamicFieldI.H"
00204 
00205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00206 
00207 #ifdef NoRepository
00208 #   include "DynamicField.C"
00209 #endif
00210 
00211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00212 
00213 #endif
00214 
00215 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd