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

DynamicField.C

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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "DynamicField.H"
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * Static Members  * * * * * * * * * * * * * * //
00035 
00036 template<class Type>
00037 const char* const DynamicField<Type>::typeName("DynamicField");
00038 
00039 
00040 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00041 
00042 template<class Type>
00043 DynamicField<Type>::DynamicField(Istream& is)
00044 :
00045     Field<Type>(is),
00046     capacity_(Field<Type>::size())
00047 {}
00048 
00049 
00050 template<class Type>
00051 tmp<DynamicField<Type> > DynamicField<Type>::clone() const
00052 {
00053     return tmp<DynamicField<Type> >(new DynamicField<Type>(*this));
00054 }
00055 
00056 
00057 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00058 
00059 template<class Type>
00060 void DynamicField<Type>::setSize(const label nElem)
00061 {
00062     // allocate more capacity?
00063     if (nElem > capacity_)
00064     {
00065         capacity_ = max(nElem, label(1 + capacity_*2));
00066 
00067         Field<Type>::setSize(capacity_);
00068     }
00069 
00070     // adjust addressed size
00071     Field<Type>::size(nElem);
00072 }
00073 
00074 
00075 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00076 
00077 
00078 // * * * * * * * * * * * * * * * IOstream Operator * * * * * * * * * * * * * //
00079 
00080 template<class Type>
00081 Ostream& operator<<(Ostream& os, const DynamicField<Type>& f)
00082 {
00083     os << static_cast<const Field<Type>&>(f);
00084     return os;
00085 }
00086 
00087 
00088 template<class Type>
00089 Ostream& operator<<(Ostream& os, const tmp<DynamicField<Type> >& tf)
00090 {
00091     os << tf();
00092     tf.clear();
00093     return os;
00094 }
00095 
00096 
00097 template<class Type>
00098 Istream& operator>>(Istream& is, DynamicField<Type>& lst)
00099 {
00100     is >> static_cast<Field<Type>&>(lst);
00101     lst.capacity_ = lst.Field<Type>::size();
00102 
00103     return is;
00104 }
00105 
00106 
00107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00108 
00109 } // End namespace Foam
00110 
00111 
00112 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd