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 "correlationFunction.H"
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 Foam::correlationFunction<Type>::typeName("correlationFunction");
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 void Foam::correlationFunction<Type>::setTimesAndSizes
40 const label tZeroBufferSize
43 sampleSteps_ = ceil(sampleInterval_/mesh_.time().deltaT().value());
45 sampleInterval_ = sampleSteps_*mesh_.time().deltaT().value();
47 label bufferLength(ceil(duration_/sampleInterval_));
49 duration_ = bufferLength*sampleInterval_;
51 label bufferingInterval(ceil(averagingInterval_/sampleInterval_));
53 averagingInterval_ = bufferingInterval*sampleInterval_;
55 label nBuffers(ceil(duration_/averagingInterval_));
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80 Foam::correlationFunction<Type>::correlationFunction
83 const dictionary& cfDict,
84 const label tZeroBufferSize
87 bufferedAccumulator<scalar>(),
90 duration_ = readScalar(cfDict.lookup("duration"));
92 sampleInterval_ = readScalar(cfDict.lookup("sampleInterval"));
94 averagingInterval_ = readScalar(cfDict.lookup("averagingInterval"));
96 setTimesAndSizes(tZeroBufferSize);
101 Foam::correlationFunction<Type>::correlationFunction
103 const polyMesh& mesh,
104 const label tZeroBufferSize,
105 const scalar duration,
106 const scalar sampleInterval,
107 const scalar averagingInterval
110 bufferedAccumulator<scalar>(),
113 sampleInterval_(sampleInterval),
114 averagingInterval_(averagingInterval)
116 setTimesAndSizes(tZeroBufferSize);
120 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 Foam::correlationFunction<Type>::~correlationFunction()
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 void Foam::correlationFunction<Type>::calculateCorrelationFunction
132 const Field<Type>& currentValues
135 if (measurandFieldSize() != currentValues.size())
137 FatalErrorIn("correlationFunction<Type>::calculateCorrelationFunction")
138 << "Trying to supply a Field of length"
139 << currentValues.size()
140 << " to calculate the correlation function. "
141 << "Expecting a Field of length "
142 << measurandFieldSize() << nl
143 << abort(FatalError);
146 List<scalar> cFSums(nBuffers(),0.0);
148 forAll(tZeroBuffers_, tZB)
150 scalar& cFSum = cFSums[tZB];
152 const Field<Type>& tZeroBuffer = tZeroBuffers_[tZB];
154 forAll(currentValues, cV)
156 const Type& tZeroBufferValue = tZeroBuffer[cV];
158 const Type& currentValue = currentValues[cV];
160 forAll(currentValue, component)
164 tZeroBufferValue[component]*currentValue[component]
169 cFSum /= (measurandFieldSize()*currentValues[0].size());
172 label bufferToRefill = addToBuffers(cFSums);
174 if (bufferToRefill != -1)
176 tZeroBuffers_[bufferToRefill] = currentValues;
182 void Foam::correlationFunction<Type>::calculateCorrelationFunction
184 const Type& currentValue
187 if( measurandFieldSize() != 1)
189 FatalErrorIn("correlationFunction<Type>::calculateCorrelationFunction")
190 << "Trying to supply a single value to calculate the correlation "
191 << "function. Expecting a Field of length "
192 << measurandFieldSize()
193 << abort(FatalError);
196 calculateCorrelationFunction(Field<Type>(1, currentValue));
201 Foam::scalar Foam::correlationFunction<Type>::integral() const
203 Field<scalar> averageCF(averaged());
205 scalar cFIntegral = 0.0;
207 for (label v = 0; v < averageCF.size() - 1; v++)
212 *(averageCF[v+1] + averageCF[v]);
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 # include "correlationFunctionIO.C"
223 // ************************************************************************* //