1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "bufferedAccumulator.H"
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 Foam::bufferedAccumulator<Type>::typeName("bufferedAccumulator");
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 void Foam::bufferedAccumulator<Type>::accumulateAndResetBuffer(const label b)
40 accumulationBuffer() += (*this)[b];
44 (*this)[b] = Field<Type>(bufferLength(), pTraits<Type>::zero);
46 bufferOffsets_[b] = 0;
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 Foam::bufferedAccumulator<Type>::bufferedAccumulator()
55 List< Field<Type> >(),
62 Foam::bufferedAccumulator<Type>::bufferedAccumulator
65 const label bufferLength,
66 const label bufferingInterval
69 List< Field<Type> >(),
83 Foam::bufferedAccumulator<Type>::bufferedAccumulator
85 const bufferedAccumulator<Type>& bA
88 List< Field<Type> >(static_cast< List< Field<Type> > >(bA)),
89 averagesTaken_(bA.averagesTaken()),
90 bufferOffsets_(bA.bufferOffsets())
94 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
97 Foam::bufferedAccumulator<Type>::~bufferedAccumulator()
101 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
104 void Foam::bufferedAccumulator<Type>::setSizes
106 const label nBuffers,
107 const label bufferLength,
108 const label bufferingInterval
111 (*this).setSize(nBuffers + 1);
115 (*this)[b] = Field<Type>(bufferLength, pTraits<Type>::zero);
120 bufferOffsets_.setSize(nBuffers);
122 forAll(bufferOffsets_, bO)
124 bufferOffsets_[bO] = -bufferingInterval * bO - 1;
130 Foam::label Foam::bufferedAccumulator<Type>::addToBuffers
132 const List<Type>& valuesToAdd
135 label bufferToRefill = -1;
137 for (label b = 0; b < nBuffers(); b++)
139 Field<Type>& buf((*this)[b]);
141 label& bO = bufferOffsets_[b];
145 buf[bO] = valuesToAdd[b];
150 if (bO == bufferLength())
152 accumulateAndResetBuffer(b);
157 if (bufferToRefill != -1)
159 FatalErrorIn("bufferedAccumulator<Type>::addToBuffers ")
160 << "More than one bufferedAccumulator accumulation "
161 << "buffer filled at once, this is considered an error."
162 << abort(FatalError);
169 return bufferToRefill;
174 Foam::Field<Type> Foam::bufferedAccumulator<Type>::averaged() const
178 Field<Type> bA = accumulationBuffer()/averagesTaken_;
186 "bufferedAccumulator<Type>::averagedbufferedAccumulator() const"
187 ) << "Averaged correlation function requested but averagesTaken = "
189 << ". Returning empty field."
192 return Field<Type>(bufferLength(), pTraits<Type>::zero);
198 void Foam::bufferedAccumulator<Type>::resetAveraging()
200 accumulationBuffer() = Field<Type>(bufferLength(), pTraits<Type>::zero);
206 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
209 void Foam::bufferedAccumulator<Type>::operator=
211 const bufferedAccumulator<Type>& rhs
214 // Check for assignment to self
219 "bufferedAccumulator<Type>::operator=(const bufferedAccumulator&)"
220 ) << "Attempted assignment to self"
221 << abort(FatalError);
224 List< Field<Type> >::operator=(rhs);
226 averagesTaken_ = rhs.averagesTaken();
228 bufferOffsets_ = rhs.bufferOffsets();
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 # include "bufferedAccumulatorIO.C"
236 // ************************************************************************* //