-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathVelocityGradient.C
106 lines (89 loc) · 2.96 KB
/
VelocityGradient.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
#include "VelocityGradient.H"
#include "coupledVelocityFvPatchField.H"
using namespace Foam;
preciceAdapter::FF::VelocityGradient::VelocityGradient(
const Foam::fvMesh& mesh,
const std::string nameU)
: U_(
const_cast<volVectorField*>(
&mesh.lookupObject<volVectorField>(nameU)))
{
dataType_ = vector;
}
std::size_t preciceAdapter::FF::VelocityGradient::write(double* buffer, bool meshConnectivity, const unsigned int dim)
{
int bufferIndex = 0;
// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);
// Get the velocity gradient boundary patch
vectorField gradientPatch((U_->boundaryFieldRef()[patchID])
.snGrad());
// For every cell of the patch
forAll(gradientPatch, i)
{
// Copy the velocity into the buffer
// x-dimension
buffer[bufferIndex++] =
-gradientPatch[i].x();
// y-dimension
buffer[bufferIndex++] =
-gradientPatch[i].y();
if (dim == 3)
{
// z-dimension
buffer[bufferIndex++] =
-gradientPatch[i].z();
}
}
}
return bufferIndex;
}
void preciceAdapter::FF::VelocityGradient::read(double* buffer, const unsigned int dim)
{
int bufferIndex = 0;
// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);
// Get the velocity gradient boundary patch
vectorField* gradientPatchPtr;
if (isA<coupledVelocityFvPatchField>(U_->boundaryFieldRef()[patchID]))
{
gradientPatchPtr = &refCast<coupledVelocityFvPatchField>(
U_->boundaryFieldRef()[patchID])
.refGrad();
}
else
{
gradientPatchPtr = &refCast<fixedGradientFvPatchVectorField>(
U_->boundaryFieldRef()[patchID])
.gradient();
}
vectorField& gradientPatch = *gradientPatchPtr;
// For every cell of the patch
forAll(gradientPatch, i)
{
// Set the velocity as the buffer value
// x-dimension
gradientPatch[i].x() =
buffer[bufferIndex++];
// y-dimension
gradientPatch[i].y() =
buffer[bufferIndex++];
if (dim == 3)
// z-dimension
gradientPatch[i].z() =
buffer[bufferIndex++];
}
}
}
bool preciceAdapter::FF::VelocityGradient::isLocationTypeSupported(const bool meshConnectivity) const
{
return (this->locationType_ == LocationType::faceCenters);
}
std::string preciceAdapter::FF::VelocityGradient::getDataName() const
{
return "VelocityGradient";
}