Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "bufferedAccumulator.H"
00027
00028
00029
00030 template<class Type>
00031 const char* const
00032 Foam::bufferedAccumulator<Type>::typeName("bufferedAccumulator");
00033
00034
00035
00036
00037 template<class Type>
00038 void Foam::bufferedAccumulator<Type>::accumulateAndResetBuffer(const label b)
00039 {
00040 accumulationBuffer() += (*this)[b];
00041
00042 averagesTaken_++;
00043
00044 (*this)[b] = Field<Type>(bufferLength(), pTraits<Type>::zero);
00045
00046 bufferOffsets_[b] = 0;
00047 }
00048
00049
00050
00051
00052 template<class Type>
00053 Foam::bufferedAccumulator<Type>::bufferedAccumulator()
00054 :
00055 List< Field<Type> >(),
00056 averagesTaken_(),
00057 bufferOffsets_()
00058 {}
00059
00060
00061 template<class Type>
00062 Foam::bufferedAccumulator<Type>::bufferedAccumulator
00063 (
00064 const label nBuffers,
00065 const label bufferLength,
00066 const label bufferingInterval
00067 )
00068 :
00069 List< Field<Type> >(),
00070 averagesTaken_(),
00071 bufferOffsets_()
00072 {
00073 setSizes
00074 (
00075 nBuffers,
00076 bufferLength,
00077 bufferingInterval
00078 );
00079 }
00080
00081
00082 template<class Type>
00083 Foam::bufferedAccumulator<Type>::bufferedAccumulator
00084 (
00085 const bufferedAccumulator<Type>& bA
00086 )
00087 :
00088 List< Field<Type> >(static_cast< List< Field<Type> > >(bA)),
00089 averagesTaken_(bA.averagesTaken()),
00090 bufferOffsets_(bA.bufferOffsets())
00091 {}
00092
00093
00094
00095
00096 template<class Type>
00097 Foam::bufferedAccumulator<Type>::~bufferedAccumulator()
00098 {}
00099
00100
00101
00102
00103 template<class Type>
00104 void Foam::bufferedAccumulator<Type>::setSizes
00105 (
00106 const label nBuffers,
00107 const label bufferLength,
00108 const label bufferingInterval
00109 )
00110 {
00111 (*this).setSize(nBuffers + 1);
00112
00113 forAll((*this), b)
00114 {
00115 (*this)[b] = Field<Type>(bufferLength, pTraits<Type>::zero);
00116 }
00117
00118 averagesTaken_ = 0;
00119
00120 bufferOffsets_.setSize(nBuffers);
00121
00122 forAll(bufferOffsets_, bO)
00123 {
00124 bufferOffsets_[bO] = -bufferingInterval * bO - 1;
00125 }
00126 }
00127
00128
00129 template<class Type>
00130 Foam::label Foam::bufferedAccumulator<Type>::addToBuffers
00131 (
00132 const List<Type>& valuesToAdd
00133 )
00134 {
00135 label bufferToRefill = -1;
00136
00137 for (label b = 0; b < nBuffers(); b++)
00138 {
00139 Field<Type>& buf((*this)[b]);
00140
00141 label& bO = bufferOffsets_[b];
00142
00143 if (bO >= 0)
00144 {
00145 buf[bO] = valuesToAdd[b];
00146 }
00147
00148 bO++;
00149
00150 if (bO == bufferLength())
00151 {
00152 accumulateAndResetBuffer(b);
00153 }
00154
00155 if (bO == 0)
00156 {
00157 if (bufferToRefill != -1)
00158 {
00159 FatalErrorIn("bufferedAccumulator<Type>::addToBuffers ")
00160 << "More than one bufferedAccumulator accumulation "
00161 << "buffer filled at once, this is considered an error."
00162 << abort(FatalError);
00163 }
00164
00165 bufferToRefill = b;
00166 }
00167 }
00168
00169 return bufferToRefill;
00170 }
00171
00172
00173 template<class Type>
00174 Foam::Field<Type> Foam::bufferedAccumulator<Type>::averaged() const
00175 {
00176 if (averagesTaken_)
00177 {
00178 Field<Type> bA = accumulationBuffer()/averagesTaken_;
00179
00180 return bA;
00181 }
00182 else
00183 {
00184 WarningIn
00185 (
00186 "bufferedAccumulator<Type>::averagedbufferedAccumulator() const"
00187 ) << "Averaged correlation function requested but averagesTaken = "
00188 << averagesTaken_
00189 << ". Returning empty field."
00190 << endl;
00191
00192 return Field<Type>(bufferLength(), pTraits<Type>::zero);
00193 }
00194 }
00195
00196
00197 template<class Type>
00198 void Foam::bufferedAccumulator<Type>::resetAveraging()
00199 {
00200 accumulationBuffer() = Field<Type>(bufferLength(), pTraits<Type>::zero);
00201
00202 averagesTaken_ = 0;
00203 }
00204
00205
00206
00207
00208 template<class Type>
00209 void Foam::bufferedAccumulator<Type>::operator=
00210 (
00211 const bufferedAccumulator<Type>& rhs
00212 )
00213 {
00214
00215 if (this == &rhs)
00216 {
00217 FatalErrorIn
00218 (
00219 "bufferedAccumulator<Type>::operator=(const bufferedAccumulator&)"
00220 ) << "Attempted assignment to self"
00221 << abort(FatalError);
00222 }
00223
00224 List< Field<Type> >::operator=(rhs);
00225
00226 averagesTaken_ = rhs.averagesTaken();
00227
00228 bufferOffsets_ = rhs.bufferOffsets();
00229 }
00230
00231
00232
00233
00234 # include "bufferedAccumulatorIO.C"
00235
00236