-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyp.inc
145 lines (110 loc) · 3.69 KB
/
yp.inc
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
/*
Usage:
include yp.inc in udf file
include yp.oudf in the oudf block in udf file
call options (from UDF_ExecuteStep):
To only get min/max/avg values and use inbuild cheap_dist function for ywd:
y_p(nrs, time);
To print y_p to file:
y_p(nrs, time, true)
User specified wall distance and boundary IDs
y_p(nrs, time, nbID, o_bID, o_ywd)
or with y_p print to file:
y_p(nrs, time, nbID, o_bID, o_ywd, true)
*/
static int outfldCounter = 0;
void y_p(nrs_t *nrs, double time, const bool iffld = false);
void y_p(nrs_t* nrs, double time, const int &nbID, const occa::memory &o_bID, const occa::memory &o_ywd, const bool iffld = false);
dfloat reduce_sum(const std::vector<dfloat> tmp, const dlong N)
{
dfloat sum = 0.0;
for (dlong i = 0; i < N; i++) {
sum += tmp[i];
}
MPI_Allreduce(MPI_IN_PLACE, &sum, 1, MPI_DFLOAT, MPI_SUM, platform->comm.mpiComm);
return sum;
}
dfloat reduce_min(const std::vector<dfloat> tmp, const dlong N)
{
dfloat smin = 1e9;
for (dlong i = 0; i < N; i++) {
smin = fmin(smin, tmp[i]);
}
MPI_Allreduce(MPI_IN_PLACE, &smin, 1, MPI_DFLOAT, MPI_MIN, platform->comm.mpiComm);
return smin;
}
dfloat reduce_max(const std::vector<dfloat> tmp, const dlong N)
{
dfloat smax = -1e9;
for (dlong i = 0; i < N; i++) {
smax = fmax(smax, tmp[i]);
}
MPI_Allreduce(MPI_IN_PLACE, &smax, 1, MPI_DFLOAT, MPI_MAX, platform->comm.mpiComm);
return smax;
}
void y_p(nrs_t *nrs, double time, const bool iffld)
{
auto mesh = nrs->meshV;
std::vector<int> wbID;
occa::memory o_wbID;
for (auto &[key, bcID] : bcMap::map()) {
const auto field = key.first;
if (field == "velocity") {
if (bcID == bcMap::bcTypeW) {
wbID.push_back(key.second + 1);
}
}
}
o_wbID = platform->device.malloc<int>(wbID.size(), wbID.data());
auto o_ywd = mesh->minDistance(wbID.size(), o_wbID, "cheap_dist");
y_p(nrs, time, wbID.size(), o_wbID, o_ywd, iffld);
}
void y_p(nrs_t* nrs, double time, const int &nbID, const occa::memory &o_bID, const occa::memory &o_ywd, const bool iffld)
{
auto mesh = nrs->meshV;
auto o_Sij = nrs->strainRate();
auto o_miny = platform->o_memPool.reserve<dfloat>(mesh->Nelements);
auto o_maxy = platform->o_memPool.reserve<dfloat>(mesh->Nelements);
auto o_sumy = platform->o_memPool.reserve<dfloat>(mesh->Nelements);
occa::memory o_yp = o_NULL;
if(iffld) o_yp = platform->o_memPool.reserve<dfloat>(nrs->fieldOffset);
yplusKernel(mesh->Nelements,
nrs->fieldOffset,
nbID,
o_bID,
static_cast<int>(iffld),
mesh->o_sgeo,
mesh->o_vmapM,
mesh->o_EToB,
nrs->o_rho,
nrs->o_mue,
o_Sij,
o_ywd,
o_yp,
o_miny,
o_maxy,
o_sumy);
static std::vector<dfloat> tmp;
if (tmp.size() < o_sumy.size()) {
tmp.resize(o_sumy.size());
}
auto o_tmp2 = platform->o_memPool.reserve<dfloat>(mesh->Nlocal);
platform->linAlg->fill(mesh->Nlocal, 1.0, o_tmp2);
const auto areaWall = mesh->surfaceAreaMultiplyIntegrate(nbID, o_bID, o_tmp2);
o_sumy.copyTo(tmp.data());
const dfloat sumy = reduce_sum(tmp, mesh->Nelements);
o_miny.copyTo(tmp.data());
const dfloat miny = reduce_min(tmp, mesh->Nelements);
o_maxy.copyTo(tmp.data());
const dfloat maxy = reduce_max(tmp, mesh->Nelements);
if(platform->comm.mpiRank == 0)
std::cout << std::scientific << "\n y+ min: " << miny <<" max: "<< maxy <<" avg: "<< sumy/areaWall.at(0)<<"\n";
if(iffld){
int outXYZ = 0;
if(!outfldCounter) outXYZ = 1;
std::vector<occa::memory> o_out;
o_out.push_back(o_yp);
fld::write("yplus", time, outfldCounter, o_out, outXYZ, 1);
outfldCounter++;
}
}