-
Notifications
You must be signed in to change notification settings - Fork 0
/
UOmegaStruture.C
327 lines (283 loc) · 10.5 KB
/
UOmegaStruture.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*---------------------------------------------------------------------------* \
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the teRMS of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
vorticity
Description
Calculates and writes the correlation between U and Vorticity.
The -noWrite option just outputs the max/min values without writing
the field.
\*---------------------------------------------------------------------------*/
#include "calc.H"
#include "fvc.H"
#include <vector>
#define Nx 192
#define Ny0 24
#define Ny1 36
#define Ny2 25
#define Ny3 8
#define Nz 160
#define Nblocks 4
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int getGlobalID(std::vector<int> localID)
{
if (localID[3]==0) {
return (Nx*Ny0)*localID[2]+Nx*localID[1]+localID[0];
}
else if(localID[3]==1){
return (Nx*Ny1)*localID[2]+Nx*localID[1]+localID[0]+Nx*Ny0*Nz;
}
else if(localID[3]==2){
return (Nx*Ny2)*localID[2]+Nx*localID[1]+localID[0]+Nx*(Ny0+Ny1)*Nz;
}
else if(localID[3]==3){
return (Nx*Ny3)*localID[2]+Nx*localID[1]+localID[0]+Nx*(Ny0+Ny1+Ny2)*Nz;
}
else{
cout << "out of range, when calculate GlobalID for point i=["
<< localID[0] <<"],j=["<< localID[1]<<"], and k=["
<< localID[2]<<"], and blk_ID=["<< localID[3]<<"]"
<< std::endl;
return -1;
}
}
std::vector<int> getLocalID(int ID)
{
std::vector<int> localID;
if(ID<Nx*Ny0*Nz){
localID.push_back((ID%(Nx*Ny0))%Nx);
localID.push_back((ID%(Nx*Ny0))/Nx);
localID.push_back( ID/(Nx*Ny0));
localID.push_back(0);
}
else if(ID>Nx*Ny0*Nz && ID<Nx*(Ny0+Ny1)*Nz ){
localID.push_back(((ID-Nx*Ny0*Nz)%(Nx*Ny1))%Nx);
localID.push_back(((ID-Nx*Ny0*Nz)%(Nx*Ny1))/Nx + Ny0);
localID.push_back( (ID-Nx*Ny0*Nz)/(Nx*Ny1));
localID.push_back(1);
}
else if(ID>Nx*(Ny0+Ny1)*Nz && ID<Nx*(Ny0+Ny1+Ny2)*Nz){
localID.push_back(((ID-Nx*(Ny0+Ny1)*Nz)%(Nx*Ny2))%Nx);
localID.push_back(((ID-Nx*(Ny0+Ny1)*Nz)%(Nx*Ny2))/Nx + Ny0 + Ny1);
localID.push_back( (ID-Nx*(Ny0+Ny1)*Nz)/(Nx*Ny2));
localID.push_back(2);
}
else if(ID>Nx*(Ny0+Ny1+Ny2)*Nz && ID<Nx*(Ny0+Ny1+Ny2+Ny3)*Nz){
localID.push_back(((ID-Nx*(Ny0+Ny1+Ny2)*Nz)%(Nx*Ny3))%Nx);
localID.push_back(((ID-Nx*(Ny0+Ny1+Ny2)*Nz)%(Nx*Ny3))/Nx + Ny0 + Ny1 + Ny2);
localID.push_back( (ID-Nx*(Ny0+Ny1+Ny2)*Nz)/(Nx*Ny3));
localID.push_back(3);
}
else{
cout << "out of range, when calculate LocalID for global" <<ID << std::endl;
}
return localID;
}
int getsamRefGloablID(std::vector<int> samPtLocalID, std::vector<int> orgPtLocalID, std::vector<int> refLocalID)
{
std::vector<int> samRefLocalID(4);
//get idx in x
samRefLocalID[0] = samPtLocalID[0] + (refLocalID[0] - orgPtLocalID[0]);
if (samRefLocalID[0]<0) {
samRefLocalID[0] = samRefLocalID[0] + Nx;
} else if(samRefLocalID[0] >Nx){
samRefLocalID[0] = samRefLocalID[0] - Nx;
}
//get idx in z
samRefLocalID[2] = samPtLocalID[2] + (refLocalID[2] - orgPtLocalID[2]);
if (samRefLocalID[2]<0) {
samRefLocalID[2] = samRefLocalID[2] + Nz;
} else if(samRefLocalID[2] >Nz){
samRefLocalID[2] = samRefLocalID[2] - Nz;
}
if ( (samRefLocalID[0]<0 || samRefLocalID[0]>Nx )
|| (samRefLocalID[2]<0 || samRefLocalID[2]>Nz)
) {
cout << "out of range, local point is not in the proper position" << std::endl;
}
samRefLocalID[1] = refLocalID[1];
samRefLocalID[3] = refLocalID[3];
return getGlobalID(samRefLocalID);
}
void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
{
bool writeResults = !args.optionFound("noWrite");
//#include "createTime.H"
Info<<"reading the 6 basic data for analysis."<<endl;
volVectorField U
(
IOobject
(
"U",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
volVectorField UMeanMap
(
IOobject
(
"UMeanMap",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
volVectorField Uturb
(
IOobject
(
"Uturb",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
U-UMeanMap
);
volVectorField vorticity
(
IOobject
(
"vorticity",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
volVectorField vorticityMeanMap
(
IOobject
(
"vorticityMeanMap",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
volVectorField Wturb
(
IOobject
(
"Wturb",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
vorticity-vorticityMeanMap
);
/* volVectorField Uturb(U-UMeanMap);
volVectorField Wturb(vorticity-vorticityMeanMap);
*/
Info << "Reading reference points" << endl;
IOdictionary refPointsProperties
(
IOobject
(
"refPointsProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
List<vector> refpts = List<vector>(refPointsProperties.lookup("refPoints"));
forAll(refpts,ref_idx)
{
int gID_refpts = mesh.findCell(refpts[ref_idx]);
std::vector<int> localID_refpts=getLocalID(gID_refpts);
Info << "Calculate R for the point (" <<refpts[ref_idx]<<"),and it is localted at"
<< mesh.C()[gID_refpts] << nl
<< "it's global ID is " << gID_refpts << " and its local id is i=["
<< localID_refpts[0] <<"],j=["<< localID_refpts[1]<<"], and k=["
<< localID_refpts[2]<<"], and blk_ID=["<< localID_refpts[3]<<"]"
<< endl;
}
/*volVectorField RUW(
IOobject
(
"RUW"+name(ref_idx),
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedVector("zero", dimensionSet(0, 1, -2, 0, 0, 0, 0), vector::zero)
);
*/
/* forAll(refpts,ref_idx)
{
forAll(U,cellI)
{
std::vector<int> localID_pts=getLocalID(cellI);
Info << "the " << cellI <<"th cell is at" << mesh.C()[cellI]
<< " and it is i=[" << localID_pts[0] <<"],j=["<< localID_pts[1]<<"], and k=["
<< localID_pts[2]<<"], and blk_ID=["<< localID_pts[3]<<"]"
<< endl;
//loop over layer
for (int i=0; i<Nx; i++) {
for (int k=0; k<Nz; k++) {
//Info << " real i=" << i << ", and k =" << k<<endl;
std::vector<int> localID_samPt;
localID_samPt.push_back(i);
localID_samPt.push_back(localID_pts[1]);
localID_samPt.push_back(k);
localID_samPt.push_back(localID_pts[3]);
//Info << "a"<< endl;
//Info << "i=" << localID_samPt[0] << ",j="<<localID_samPt[1]<<", k=" <<localID_samPt[2]<<",nBK="<<localID_samPt[3]<<endl;
int gID_samPt = getGlobalID(localID_samPt);
//Info << "b global id is " << gID_samPt << endl;
int gID_samRefPt = getsamRefGloablID(localID_samPt,localID_pts,localID_refpts);
RUW.component(vector::X)()[cellI] = RUW.component(vector::X)()[cellI]
+ Uturb.component(vector::X)()[gID_samRefPt]*Wturb.component(vector::X)()[gID_samPt];
// Foam::sqrt(URMSMap.component(tensor::XX)()[gID_samRefPt]*vorticityRMSMap.component(tensor::XX)()[gID_samPt]);
RUW.component(vector::Y)()[cellI] = RUW.component(vector::Y)()[cellI]
+ Uturb.component(vector::X)()[gID_samRefPt]*Wturb.component(vector::Y)()[gID_samPt];
// Foam::sqrt(URMSMap.component(tensor::XX)()[gID_samRefPt]*vorticityRMSMap.component(tensor::YY)()[gID_samPt]);
RUW.component(vector::Z)()[cellI] = RUW.component(tensor::XX)()[cellI]
+ Uturb.component(vector::X)()[gID_samRefPt]*Wturb.component(vector::Z)()[gID_samPt];
//Foam::sqrt(URMSMap.component(tensor::XX)()[gID_samRefPt]*vorticityRMSMap.component(tensor::ZZ)()[gID_samPt]);
}
}
RUW[cellI]=RUW[cellI]/(Nx*Nz);
}
if (writeResults)
{
RUW.write();
}
}*/
if (writeResults)
{
Uturb.write();
Wturb.write();
}
Info<< "\nEnd\n" << endl;
}
// ************************************************************************* //