1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, 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().deltaTValue());
45 sampleInterval_ = sampleSteps_*mesh_.time().deltaTValue();
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 // ************************************************************************* //