1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 "bufferedAccumulator.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 Foam::bufferedAccumulator<Type>::typeName("bufferedAccumulator");
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 void Foam::bufferedAccumulator<Type>::accumulateAndResetBuffer(const label b)
41 accumulationBuffer() += (*this)[b];
45 (*this)[b] = Field<Type>(bufferLength(), pTraits<Type>::zero);
47 bufferOffsets_[b] = 0;
51 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 Foam::bufferedAccumulator<Type>::bufferedAccumulator()
56 List< Field<Type> >(),
63 Foam::bufferedAccumulator<Type>::bufferedAccumulator
66 const label bufferLength,
67 const label bufferingInterval
70 List< Field<Type> >(),
84 Foam::bufferedAccumulator<Type>::bufferedAccumulator
86 const bufferedAccumulator<Type>& bA
89 List< Field<Type> >(static_cast< List< Field<Type> > >(bA)),
90 averagesTaken_(bA.averagesTaken()),
91 bufferOffsets_(bA.bufferOffsets())
95 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
98 Foam::bufferedAccumulator<Type>::~bufferedAccumulator()
102 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
105 void Foam::bufferedAccumulator<Type>::setSizes
107 const label nBuffers,
108 const label bufferLength,
109 const label bufferingInterval
112 (*this).setSize(nBuffers + 1);
116 (*this)[b] = Field<Type>(bufferLength, pTraits<Type>::zero);
121 bufferOffsets_.setSize(nBuffers);
123 forAll(bufferOffsets_, bO)
125 bufferOffsets_[bO] = -bufferingInterval * bO - 1;
131 Foam::label Foam::bufferedAccumulator<Type>::addToBuffers
133 const List<Type>& valuesToAdd
136 label bufferToRefill = -1;
138 for (label b = 0; b < nBuffers(); b++)
140 Field<Type>& buf((*this)[b]);
142 label& bO = bufferOffsets_[b];
146 buf[bO] = valuesToAdd[b];
151 if (bO == bufferLength())
153 accumulateAndResetBuffer(b);
158 if (bufferToRefill != -1)
160 FatalErrorIn("bufferedAccumulator<Type>::addToBuffers ")
161 << "More than one bufferedAccumulator accumulation "
162 << "buffer filled at once, this is considered an error."
163 << abort(FatalError);
170 return bufferToRefill;
175 Foam::Field<Type> Foam::bufferedAccumulator<Type>::averaged() const
179 Field<Type> bA = accumulationBuffer()/averagesTaken_;
187 "bufferedAccumulator<Type>::averagedbufferedAccumulator() const"
188 ) << "Averaged correlation function requested but averagesTaken = "
190 << ". Returning empty field."
193 return Field<Type>(bufferLength(), pTraits<Type>::zero);
199 void Foam::bufferedAccumulator<Type>::resetAveraging()
201 accumulationBuffer() = Field<Type>(bufferLength(), pTraits<Type>::zero);
207 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
210 void Foam::bufferedAccumulator<Type>::operator=
212 const bufferedAccumulator<Type>& rhs
215 // Check for assignment to self
220 "bufferedAccumulator<Type>::operator=(const bufferedAccumulator&)"
221 ) << "Attempted assignment to self"
222 << abort(FatalError);
225 List< Field<Type> >::operator=(rhs);
227 averagesTaken_ = rhs.averagesTaken();
229 bufferOffsets_ = rhs.bufferOffsets();
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 # include "bufferedAccumulatorIO.C"
237 // ************************************************************************* //