-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathPressure.C
130 lines (115 loc) · 3.59 KB
/
Pressure.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
#include "Pressure.H"
#include "coupledPressureFvPatchField.H"
using namespace Foam;
preciceAdapter::FF::Pressure::Pressure(
const Foam::fvMesh& mesh,
const std::string nameP)
: p_(
const_cast<volScalarField*>(
&mesh.lookupObject<volScalarField>(nameP)))
{
dataType_ = scalar;
}
std::size_t preciceAdapter::FF::Pressure::write(double* buffer, bool meshConnectivity, const unsigned int dim)
{
int bufferIndex = 0;
if (this->locationType_ == LocationType::volumeCenters)
{
if (cellSetNames_.empty())
{
for (const auto& cell : p_->internalField())
{
buffer[bufferIndex++] = cell;
}
}
else
{
for (const auto& cellSetName : cellSetNames_)
{
cellSet overlapRegion(p_->mesh(), cellSetName);
const labelList& cells = overlapRegion.toc();
for (const auto& currentCell : cells)
{
// Copy the pressure into the buffer
buffer[bufferIndex++] = p_->internalField()[currentCell];
}
}
}
}
// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);
// For every cell of the patch
forAll(p_->boundaryFieldRef()[patchID], i)
{
// Copy the pressure into the buffer
buffer[bufferIndex++] =
p_->boundaryFieldRef()[patchID][i];
}
}
return bufferIndex;
}
void preciceAdapter::FF::Pressure::read(double* buffer, const unsigned int dim)
{
int bufferIndex = 0;
if (this->locationType_ == LocationType::volumeCenters)
{
if (cellSetNames_.empty())
{
for (auto& cell : p_->ref())
{
cell = buffer[bufferIndex++];
}
}
else
{
for (const auto& cellSetName : cellSetNames_)
{
cellSet overlapRegion(p_->mesh(), cellSetName);
const labelList& cells = overlapRegion.toc();
for (const auto& currentCell : cells)
{
// Copy the pressure into the buffer
p_->ref()[currentCell] = buffer[bufferIndex++];
}
}
}
}
// For every boundary patch of the interface
for (uint j = 0; j < patchIDs_.size(); j++)
{
int patchID = patchIDs_.at(j);
// Get the pressure value boundary patch
scalarField* valuePatchPtr = &p_->boundaryFieldRef()[patchID];
if (isA<coupledPressureFvPatchField>(p_->boundaryFieldRef()[patchID]))
{
valuePatchPtr = &refCast<coupledPressureFvPatchField>(
p_->boundaryFieldRef()[patchID])
.refValue();
}
scalarField& valuePatch = *valuePatchPtr;
// For every cell of the patch
forAll(p_->boundaryFieldRef()[patchID], i)
{
// Set the pressure as the buffer value
valuePatch[i] =
buffer[bufferIndex++];
}
}
}
bool preciceAdapter::FF::Pressure::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::Pressure::getDataName() const
{
return "Pressure";
}