-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathVelocity.C
223 lines (194 loc) · 6.35 KB
/
Velocity.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
#include "Velocity.H"
#include "coupledVelocityFvPatchField.H"
using namespace Foam;
preciceAdapter::FF::Velocity::Velocity(
const Foam::fvMesh& mesh,
const std::string nameU,
const std::string namePhi,
bool fluxCorrection)
: phi_(const_cast<surfaceScalarField*>(
&mesh.lookupObject<surfaceScalarField>(namePhi))),
fluxCorrection_(fluxCorrection)
{
if (mesh.foundObject<volVectorField>(nameU))
{
adapterInfo("Using existing velocity object " + nameU, "debug");
U_ = const_cast<volVectorField*>(
&mesh.lookupObject<volVectorField>(nameU));
}
else
{
adapterInfo("Creating a new velocity object " + nameU, "debug");
U_ = new volVectorField(
IOobject(
nameU,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE),
mesh);
}
dataType_ = vector;
}
std::size_t preciceAdapter::FF::Velocity::write(double* buffer, bool meshConnectivity, const unsigned int dim)
{
int bufferIndex = 0;
if (this->locationType_ == LocationType::volumeCenters)
{
if (cellSetNames_.empty())
{
for (const auto& cell : U_->internalField())
{
// x-dimension
buffer[bufferIndex++] = cell.x();
// y-dimension
buffer[bufferIndex++] = cell.y();
if (dim == 3)
{
// z-dimension
buffer[bufferIndex++] = cell.z();
}
}
}
else
{
for (const auto& cellSetName : cellSetNames_)
{
cellSet overlapRegion(U_->mesh(), cellSetName);
const labelList& cells = overlapRegion.toc();
for (const auto& currentCell : cells)
{
// x-dimension
buffer[bufferIndex++] = U_->internalField()[currentCell].x();
// y-dimension
buffer[bufferIndex++] = U_->internalField()[currentCell].y();
if (dim == 3)
{
// z-dimension
buffer[bufferIndex++] = U_->internalField()[currentCell].z();
}
}
}
}
}
// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);
vectorField UPatch = U_->boundaryField()[patchID];
// Correct the velocity by the boundary face flux
if (fluxCorrection_)
{
scalarField phip = phi_->boundaryFieldRef()[patchID];
vectorField n = U_->boundaryField()[patchID].patch().nf();
const scalarField& magS = U_->boundaryFieldRef()[patchID].patch().magSf();
UPatch = UPatch - n * (n & U_->boundaryField()[patchID]) + n * phip / magS;
}
// For every cell of the patch
forAll(U_->boundaryFieldRef()[patchID], i)
{
// Copy the velocity into the buffer
// x-dimension
buffer[bufferIndex++] =
UPatch[i].x();
// y-dimension
buffer[bufferIndex++] =
UPatch[i].y();
if (dim == 3)
{
// z-dimension
buffer[bufferIndex++] =
UPatch[i].z();
}
}
}
return bufferIndex;
}
void preciceAdapter::FF::Velocity::read(double* buffer, const unsigned int dim)
{
int bufferIndex = 0;
if (this->locationType_ == LocationType::volumeCenters)
{
if (cellSetNames_.empty())
{
for (auto& cell : U_->ref())
{
// x-dimension
cell.x() = buffer[bufferIndex++];
// y-dimension
cell.y() = buffer[bufferIndex++];
if (dim == 3)
{
// z-dimension
cell.z() = buffer[bufferIndex++];
}
}
}
else
{
for (const auto& cellSetName : cellSetNames_)
{
cellSet overlapRegion(U_->mesh(), cellSetName);
const labelList& cells = overlapRegion.toc();
for (const auto& currentCell : cells)
{
// x-dimension
U_->ref()[currentCell].x() = buffer[bufferIndex++];
// y-dimension
U_->ref()[currentCell].y() = buffer[bufferIndex++];
if (dim == 3)
{
// z-dimension
U_->ref()[currentCell].z() = buffer[bufferIndex++];
}
}
}
}
}
// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);
// Get the velocity value boundary patch
vectorField* valuePatchPtr = &U_->boundaryFieldRef()[patchID];
if (isA<coupledVelocityFvPatchField>(U_->boundaryFieldRef()[patchID]))
{
valuePatchPtr = &refCast<coupledVelocityFvPatchField>(
U_->boundaryFieldRef()[patchID])
.refValue();
}
vectorField& valuePatch = *valuePatchPtr;
// For every cell of the patch
forAll(U_->boundaryFieldRef()[patchID], i)
{
// Set the velocity as the buffer value
// x-dimension
valuePatch[i].x() =
buffer[bufferIndex++];
// y-dimension
valuePatch[i].y() =
buffer[bufferIndex++];
if (dim == 3)
{
// z-dimension
valuePatch[i].z() =
buffer[bufferIndex++];
}
}
}
}
bool preciceAdapter::FF::Velocity::isLocationTypeSupported(const bool meshConnectivity) const
{
if (meshConnectivity)
{
return (this->locationType_ == LocationType::faceCenters);
}
else
{
return (this->locationType_ == LocationType::faceCenters || this->locationType_ == LocationType::volumeCenters);
}
}
std::string preciceAdapter::FF::Velocity::getDataName() const
{
return "Velocity";
}