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 "correlationFunction.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 Foam::correlationFunction<Type>::typeName("correlationFunction");
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 void Foam::correlationFunction<Type>::setTimesAndSizes
41 const label tZeroBufferSize
44 sampleSteps_ = ceil(sampleInterval_/mesh_.time().deltaT().value());
46 sampleInterval_ = sampleSteps_*mesh_.time().deltaT().value();
48 label bufferLength(ceil(duration_/sampleInterval_));
50 duration_ = bufferLength*sampleInterval_;
52 label bufferingInterval(ceil(averagingInterval_/sampleInterval_));
54 averagingInterval_ = bufferingInterval*sampleInterval_;
56 label nBuffers(ceil(duration_/averagingInterval_));
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 Foam::correlationFunction<Type>::correlationFunction
84 const dictionary& cfDict,
85 const label tZeroBufferSize
88 bufferedAccumulator<scalar>(),
91 duration_ = readScalar(cfDict.lookup("duration"));
93 sampleInterval_ = readScalar(cfDict.lookup("sampleInterval"));
95 averagingInterval_ = readScalar(cfDict.lookup("averagingInterval"));
97 setTimesAndSizes(tZeroBufferSize);
102 Foam::correlationFunction<Type>::correlationFunction
104 const polyMesh& mesh,
105 const label tZeroBufferSize,
106 const scalar duration,
107 const scalar sampleInterval,
108 const scalar averagingInterval
111 bufferedAccumulator<scalar>(),
114 sampleInterval_(sampleInterval),
115 averagingInterval_(averagingInterval)
117 setTimesAndSizes(tZeroBufferSize);
121 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
124 Foam::correlationFunction<Type>::~correlationFunction()
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 void Foam::correlationFunction<Type>::calculateCorrelationFunction
133 const Field<Type>& currentValues
136 if (measurandFieldSize() != currentValues.size())
138 FatalErrorIn("correlationFunction<Type>::calculateCorrelationFunction")
139 << "Trying to supply a Field of length"
140 << currentValues.size()
141 << " to calculate the correlation function. "
142 << "Expecting a Field of length "
143 << measurandFieldSize() << nl
144 << abort(FatalError);
147 List<scalar> cFSums(nBuffers(),0.0);
149 forAll(tZeroBuffers_, tZB)
151 scalar& cFSum = cFSums[tZB];
153 const Field<Type>& tZeroBuffer = tZeroBuffers_[tZB];
155 forAll(currentValues, cV)
157 const Type& tZeroBufferValue = tZeroBuffer[cV];
159 const Type& currentValue = currentValues[cV];
161 forAll(currentValue, component)
165 tZeroBufferValue[component]*currentValue[component]
170 cFSum /= (measurandFieldSize()*currentValues[0].size());
173 label bufferToRefill = addToBuffers(cFSums);
175 if (bufferToRefill != -1)
177 tZeroBuffers_[bufferToRefill] = currentValues;
183 void Foam::correlationFunction<Type>::calculateCorrelationFunction
185 const Type& currentValue
188 if( measurandFieldSize() != 1)
190 FatalErrorIn("correlationFunction<Type>::calculateCorrelationFunction")
191 << "Trying to supply a single value to calculate the correlation "
192 << "function. Expecting a Field of length "
193 << measurandFieldSize()
194 << abort(FatalError);
197 calculateCorrelationFunction(Field<Type>(1, currentValue));
202 Foam::scalar Foam::correlationFunction<Type>::integral() const
204 Field<scalar> averageCF(averaged());
206 scalar cFIntegral = 0.0;
208 for (label v = 0; v < averageCF.size() - 1; v++)
213 *(averageCF[v+1] + averageCF[v]);
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 # include "correlationFunctionIO.C"
224 // ************************************************************************* //