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 "correlationFunction.H"
00027
00028
00029
00030 template<class Type>
00031 const char* const
00032 Foam::correlationFunction<Type>::typeName("correlationFunction");
00033
00034
00035
00036
00037 template<class Type>
00038 void Foam::correlationFunction<Type>::setTimesAndSizes
00039 (
00040 const label tZeroBufferSize
00041 )
00042 {
00043 sampleSteps_ = ceil(sampleInterval_/mesh_.time().deltaT().value());
00044
00045 sampleInterval_ = sampleSteps_*mesh_.time().deltaT().value();
00046
00047 label bufferLength(ceil(duration_/sampleInterval_));
00048
00049 duration_ = bufferLength*sampleInterval_;
00050
00051 label bufferingInterval(ceil(averagingInterval_/sampleInterval_));
00052
00053 averagingInterval_ = bufferingInterval*sampleInterval_;
00054
00055 label nBuffers(ceil(duration_/averagingInterval_));
00056
00057 this->setSizes
00058 (
00059 nBuffers,
00060 bufferLength,
00061 bufferingInterval
00062 );
00063
00064 tZeroBuffers_ =
00065 Field< Field<Type> >
00066 (
00067 nBuffers,
00068 Field<Type>
00069 (
00070 tZeroBufferSize,
00071 pTraits<Type>::zero
00072 )
00073 );
00074 }
00075
00076
00077
00078
00079 template<class Type>
00080 Foam::correlationFunction<Type>::correlationFunction
00081 (
00082 const polyMesh& mesh,
00083 const dictionary& cfDict,
00084 const label tZeroBufferSize
00085 )
00086 :
00087 bufferedAccumulator<scalar>(),
00088 mesh_(mesh)
00089 {
00090 duration_ = readScalar(cfDict.lookup("duration"));
00091
00092 sampleInterval_ = readScalar(cfDict.lookup("sampleInterval"));
00093
00094 averagingInterval_ = readScalar(cfDict.lookup("averagingInterval"));
00095
00096 setTimesAndSizes(tZeroBufferSize);
00097 }
00098
00099
00100 template<class Type>
00101 Foam::correlationFunction<Type>::correlationFunction
00102 (
00103 const polyMesh& mesh,
00104 const label tZeroBufferSize,
00105 const scalar duration,
00106 const scalar sampleInterval,
00107 const scalar averagingInterval
00108 )
00109 :
00110 bufferedAccumulator<scalar>(),
00111 mesh_(mesh),
00112 duration_(duration),
00113 sampleInterval_(sampleInterval),
00114 averagingInterval_(averagingInterval)
00115 {
00116 setTimesAndSizes(tZeroBufferSize);
00117 }
00118
00119
00120
00121
00122 template<class Type>
00123 Foam::correlationFunction<Type>::~correlationFunction()
00124 {}
00125
00126
00127
00128
00129 template<class Type>
00130 void Foam::correlationFunction<Type>::calculateCorrelationFunction
00131 (
00132 const Field<Type>& currentValues
00133 )
00134 {
00135 if (measurandFieldSize() != currentValues.size())
00136 {
00137 FatalErrorIn("correlationFunction<Type>::calculateCorrelationFunction")
00138 << "Trying to supply a Field of length"
00139 << currentValues.size()
00140 << " to calculate the correlation function. "
00141 << "Expecting a Field of length "
00142 << measurandFieldSize() << nl
00143 << abort(FatalError);
00144 }
00145
00146 List<scalar> cFSums(nBuffers(),0.0);
00147
00148 forAll(tZeroBuffers_, tZB)
00149 {
00150 scalar& cFSum = cFSums[tZB];
00151
00152 const Field<Type>& tZeroBuffer = tZeroBuffers_[tZB];
00153
00154 forAll(currentValues, cV)
00155 {
00156 const Type& tZeroBufferValue = tZeroBuffer[cV];
00157
00158 const Type& currentValue = currentValues[cV];
00159
00160 forAll(currentValue, component)
00161 {
00162 cFSum +=
00163 (
00164 tZeroBufferValue[component]*currentValue[component]
00165 );
00166 }
00167 }
00168
00169 cFSum /= (measurandFieldSize()*currentValues[0].size());
00170 }
00171
00172 label bufferToRefill = addToBuffers(cFSums);
00173
00174 if (bufferToRefill != -1)
00175 {
00176 tZeroBuffers_[bufferToRefill] = currentValues;
00177 }
00178 }
00179
00180
00181 template<class Type>
00182 void Foam::correlationFunction<Type>::calculateCorrelationFunction
00183 (
00184 const Type& currentValue
00185 )
00186 {
00187 if( measurandFieldSize() != 1)
00188 {
00189 FatalErrorIn("correlationFunction<Type>::calculateCorrelationFunction")
00190 << "Trying to supply a single value to calculate the correlation "
00191 << "function. Expecting a Field of length "
00192 << measurandFieldSize()
00193 << abort(FatalError);
00194 }
00195
00196 calculateCorrelationFunction(Field<Type>(1, currentValue));
00197 }
00198
00199
00200 template<class Type>
00201 Foam::scalar Foam::correlationFunction<Type>::integral() const
00202 {
00203 Field<scalar> averageCF(averaged());
00204
00205 scalar cFIntegral = 0.0;
00206
00207 for (label v = 0; v < averageCF.size() - 1; v++)
00208 {
00209 cFIntegral +=
00210 0.5
00211 *sampleInterval_
00212 *(averageCF[v+1] + averageCF[v]);
00213 }
00214
00215 return cFIntegral;
00216 }
00217
00218
00219
00220
00221 # include "correlationFunctionIO.C"
00222
00223