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
25 \*---------------------------------------------------------------------------*/
27 #include "DynamicField.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 DynamicField<Type>::DynamicField()
45 DynamicField<Type>::DynamicField(const label size)
48 capacity_(Field<Type>::size())
55 inline Foam::DynamicField<Type>::DynamicField
57 const UList<Type>& lst
61 capacity_(Field<Type>::size())
66 inline Foam::DynamicField<Type>::DynamicField
68 const Xfer<List<Type> >& lst
72 capacity_(Field<Type>::size())
77 DynamicField<Type>::DynamicField
79 const UList<Type>& mapF,
80 const labelList& mapAddressing
83 Field<Type>(mapF, mapAddressing),
84 capacity_(Field<Type>::size())
89 DynamicField<Type>::DynamicField
91 const UList<Type>& mapF,
92 const labelListList& mapAddressing,
93 const scalarListList& weights
96 Field<Type>(mapF, mapAddressing, weights),
97 capacity_(Field<Type>::size())
101 //- Construct by mapping from the given field
103 DynamicField<Type>::DynamicField
105 const UList<Type>& mapF,
106 const FieldMapper& map
109 DynamicField<Type>(mapF, map),
110 capacity_(Field<Type>::size())
115 DynamicField<Type>::DynamicField(const DynamicField<Type>& f)
118 capacity_(Field<Type>::size())
123 DynamicField<Type>::DynamicField(DynamicField<Type>& f, bool reUse)
125 Field<Type>(f, reUse),
126 capacity_(Field<Type>::size())
131 DynamicField<Type>::DynamicField(const Xfer<DynamicField<Type> >& f)
134 capacity_(Field<Type>::size())
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 Foam::label DynamicField<Type>::capacity() const
148 void DynamicField<Type>::append(const Type& t)
150 label elemI = Field<Type>::size();
153 this->operator[](elemI) = t;
157 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
160 void DynamicField<Type>::operator=(const DynamicField<Type>& rhs)
164 FatalErrorIn("DynamicField<Type>::operator=(const DynamicField<Type>&)")
165 << "attempted assignment to self"
166 << abort(FatalError);
169 Field<Type>::operator=(rhs);
170 capacity_ = Field<Type>::size();
175 void DynamicField<Type>::operator=(const UList<Type>& rhs)
177 Field<Type>::operator=(rhs);
178 capacity_ = Field<Type>::size();
183 void DynamicField<Type>::operator=(const tmp<DynamicField>& rhs)
185 if (this == &(rhs()))
187 FatalErrorIn("DynamicField<Type>::operator=(const tmp<DynamicField>&)")
188 << "attempted assignment to self"
189 << abort(FatalError);
192 // This is dodgy stuff, don't try it at home.
193 DynamicField* fieldPtr = rhs.ptr();
194 List<Type>::transfer(*fieldPtr);
196 capacity_ = Field<Type>::size();
201 Type& DynamicField<Type>::operator[](const label i)
203 return Field<Type>::operator[](i);
208 const Type& DynamicField<Type>::operator[](const label i) const
210 return Field<Type>::operator[](i);
214 // * * * * * * * * * * * * * * * IOstream Operator * * * * * * * * * * * * * //
217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219 } // End namespace Foam
221 // ************************************************************************* //