correlationFunction.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "correlationFunction.H"
29
30// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31
32template<class Type>
33const char* const
34 Foam::correlationFunction<Type>::typeName("correlationFunction");
35
36
37// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38
39template<class Type>
41(
42 const label tZeroBufferSize
43)
44{
45 sampleSteps_ = ceil(sampleInterval_/mesh_.time().deltaTValue());
46
47 sampleInterval_ = sampleSteps_*mesh_.time().deltaTValue();
48
49 label bufferLength(ceil(duration_/sampleInterval_));
50
51 duration_ = bufferLength*sampleInterval_;
52
53 label bufferingInterval(ceil(averagingInterval_/sampleInterval_));
54
55 averagingInterval_ = bufferingInterval*sampleInterval_;
56
57 label nBuffers(ceil(duration_/averagingInterval_));
58
59 this->setSizes
60 (
61 nBuffers,
62 bufferLength,
63 bufferingInterval
64 );
65
66 tZeroBuffers_ =
67 Field<Field<Type>>
68 (
69 nBuffers,
70 Field<Type>
71 (
72 tZeroBufferSize,
73 Zero
74 )
75 );
76}
77
78
79// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80
81template<class Type>
83(
84 const polyMesh& mesh,
85 const dictionary& dict,
86 const label tZeroBufferSize
87)
88:
89 bufferedAccumulator<scalar>(),
90 mesh_(mesh),
91 duration_(dict.get<scalar>("duration")),
92 sampleInterval_(dict.get<scalar>("sampleInterval")),
93 averagingInterval_(dict.get<scalar>("averagingInterval"))
94{
95 setTimesAndSizes(tZeroBufferSize);
96}
97
98
99template<class Type>
101(
102 const polyMesh& mesh,
103 const label tZeroBufferSize,
104 const scalar duration,
105 const scalar sampleInterval,
106 const scalar averagingInterval
107)
108:
109 bufferedAccumulator<scalar>(),
110 mesh_(mesh),
111 duration_(duration),
112 sampleInterval_(sampleInterval),
113 averagingInterval_(averagingInterval)
114{
115 setTimesAndSizes(tZeroBufferSize);
116}
117
118
119// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120
121template<class Type>
123{}
124
125
126// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127
128template<class Type>
130(
131 const Field<Type>& currentValues
132)
133{
134 if (measurandFieldSize() != currentValues.size())
135 {
137 << "Trying to supply a Field of length"
138 << currentValues.size()
139 << " to calculate the correlation function. "
140 << "Expecting a Field of length "
141 << measurandFieldSize() << nl
142 << abort(FatalError);
143 }
144
145 List<scalar> cFSums(nBuffers(), Zero);
146
147 forAll(tZeroBuffers_, tZB)
148 {
149 scalar& cFSum = cFSums[tZB];
150
151 const Field<Type>& tZeroBuffer = tZeroBuffers_[tZB];
152
153 forAll(currentValues, cV)
154 {
155 const Type& tZeroBufferValue = tZeroBuffer[cV];
156
157 const Type& currentValue = currentValues[cV];
158
159 forAll(currentValue, component)
160 {
161 cFSum +=
162 (
163 tZeroBufferValue[component]*currentValue[component]
164 );
165 }
166 }
167
168 cFSum /= (measurandFieldSize()*currentValues[0].size());
169 }
170
171 label bufferToRefill = addToBuffers(cFSums);
172
173 if (bufferToRefill != -1)
174 {
175 tZeroBuffers_[bufferToRefill] = currentValues;
176 }
177}
178
179
180template<class Type>
182(
183 const Type& currentValue
184)
185{
186 if (measurandFieldSize() != 1)
187 {
189 << "Trying to supply a single value to calculate the correlation "
190 << "function. Expecting a Field of length "
191 << measurandFieldSize()
192 << abort(FatalError);
193 }
194
195 calculateCorrelationFunction(Field<Type>(1, currentValue));
196}
197
198
199template<class Type>
201{
202 Field<scalar> averageCF(averaged());
203
204 scalar cFIntegral = 0.0;
205
206 for (label v = 0; v < averageCF.size() - 1; v++)
207 {
208 cFIntegral +=
209 0.5
210 *sampleInterval_
211 *(averageCF[v+1] + averageCF[v]);
212 }
213
214 return cFIntegral;
215}
216
217
218// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
219
220 #include "correlationFunctionIO.C"
221
222// ************************************************************************* //
Generic templated field type.
Definition: Field.H:82
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
void calculateCorrelationFunction(const Field< Type > &)
static const char *const typeName
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333