Skip to content

Commit fe71bab

Browse files
committed
BUG: static causes issues for second grid
1 parent d8c29af commit fe71bab

File tree

1 file changed

+107
-31
lines changed

1 file changed

+107
-31
lines changed

src/exchange_messages.cpp

Lines changed: 107 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,58 @@ bool Neutrals::exchange_old(Grid &grid) {
3636
return DidWork;
3737
}
3838

39+
void average_value_at_pole(Grid &grid, arma_cube &value, arma_cube &velocity,
40+
int64_t iLast, int64_t iPole,
41+
bool doesTouchPole) {
42+
// Now let's deal with the poles:
43+
// north pole first:
44+
int64_t iX, nX = grid.get_nX();
45+
int64_t iZ, nZ = grid.get_nZ();
46+
int64_t nGCs = grid.get_nGCs();
47+
int64_t iY, iInc = 1;
48+
49+
if (iPole < iLast)
50+
iInc = -1;
51+
52+
double weight, sumValue, sumWeight, totalValue, totalWeight, poleValue;
53+
54+
for (iZ = nGCs; iZ < nZ - nGCs; iZ++) {
55+
56+
sumValue = 0.0;
57+
sumWeight = 0.0;
58+
59+
if (doesTouchPole) {
60+
for (iX = nGCs; iX < nX - nGCs; iX++) {
61+
// determine the weight based on the northward velocity:
62+
weight = iInc * velocity(iX, iLast, iZ) / 1000.0 + 1.0;
63+
64+
if (weight < 0.01)
65+
weight = 0.01;
66+
67+
sumValue = sumValue + value(iX, iLast, iZ) * weight;
68+
sumWeight = sumWeight + weight;
69+
}
70+
}
71+
72+
MPI_Allreduce(&sumValue, &totalValue, 1, MPI_DOUBLE, MPI_SUM,
73+
aether_comm);
74+
MPI_Allreduce(&sumWeight, &totalWeight, 1, MPI_DOUBLE, MPI_SUM,
75+
aether_comm);
76+
poleValue = totalValue / totalWeight;
77+
78+
//if (iZ == 10)
79+
//std::cout << "pole value : " << poleValue << " " << totalValue << " " << totalWeight << " "
80+
//<< iProc << " " << doesTouchPole << "\n";
81+
82+
if (doesTouchPole) {
83+
for (iX = nGCs; iX < nX - nGCs; iX++)
84+
for (iY = iLast + iInc; iY == iPole; iY += iInc)
85+
value(iX, iY, iZ) = poleValue;
86+
}
87+
}
88+
89+
}
90+
3991
// -----------------------------------------------------------------------------
4092
// This is the main exchange messages for the neutrals.
4193
// We are exchanging densities, temperatures, and velocities
@@ -53,7 +105,7 @@ bool Ions::exchange_old(Grid &grid) {
53105
for (int iSpecies = 0; iSpecies < nSpecies; iSpecies++)
54106
DidWork = exchange_one_var(grid, species[iSpecies].density_scgc, false);
55107

56-
DidWork = exchange_one_var(grid, temperature_scgc, false);
108+
//DidWork = exchange_one_var(grid, temperature_scgc, false);
57109
DidWork = exchange_one_var(grid, electron_temperature_scgc, false);
58110

59111
// velocity components:
@@ -64,6 +116,25 @@ bool Ions::exchange_old(Grid &grid) {
64116
// don't reverse vertical across the pole:
65117
DidWork = exchange_one_var(grid, velocity_vcgc[2], false);
66118

119+
int64_t iPole = grid.get_nY() - 1;
120+
int64_t iLast = iPole - nGCs;
121+
122+
average_value_at_pole(grid, temperature_scgc, velocity_vcgc[1],
123+
iLast, iPole, grid.DoesTouchNorthPole);
124+
125+
for (int iSpecies = 0; iSpecies < nSpecies; iSpecies++)
126+
average_value_at_pole(grid, species[iSpecies].density_scgc, velocity_vcgc[1],
127+
iLast, iPole, grid.DoesTouchNorthPole);
128+
129+
iPole = 0;
130+
iLast = nGCs;
131+
average_value_at_pole(grid, temperature_scgc, velocity_vcgc[1],
132+
iLast, iPole, grid.DoesTouchSouthPole);
133+
134+
for (int iSpecies = 0; iSpecies < nSpecies; iSpecies++)
135+
average_value_at_pole(grid, species[iSpecies].density_scgc, velocity_vcgc[1],
136+
iLast, iPole, grid.DoesTouchSouthPole);
137+
67138
report.exit(function);
68139
return DidWork;
69140
}
@@ -119,9 +190,9 @@ bool pack_border(const arma_cube &value,
119190
int iDir) {
120191

121192
bool DidWork = true;
122-
static int64_t nX = value.n_rows;
123-
static int64_t nY = value.n_cols;
124-
static int64_t nZ = value.n_slices;
193+
int64_t nX = value.n_rows;
194+
int64_t nY = value.n_cols;
195+
int64_t nZ = value.n_slices;
125196

126197
int64_t iXstart, iXend;
127198
int64_t iYstart, iYend;
@@ -221,9 +292,9 @@ bool unpack_border(arma_cube &value,
221292
bool XbecomesY) {
222293

223294
bool DidWork = true;
224-
static int64_t nX = value.n_rows;
225-
static int64_t nY = value.n_cols;
226-
static int64_t nZ = value.n_slices;
295+
int64_t nX = value.n_rows;
296+
int64_t nY = value.n_cols;
297+
int64_t nZ = value.n_slices;
227298

228299
int64_t iXstart, iXend;
229300
int64_t iYstart, iYend;
@@ -345,6 +416,7 @@ bool unpack_border(arma_cube &value,
345416
} catch (...) {
346417
DidWork = false;
347418
}
419+
348420
return DidWork;
349421
}
350422

@@ -394,7 +466,7 @@ bool pack_one_var_on_one_face(arma_cube var_scgc,
394466
int iDirToPass,
395467
Grid &grid) {
396468

397-
static int nG = grid.get_nGCs();
469+
int nG = grid.get_nGCs();
398470
int iDir = grid.interchangesOneVar[iDirToPass].iFace;
399471
int iReceiver = grid.interchangesOneVar[iDirToPass].iProc_to;
400472
precision_t *buffer = grid.interchangesOneVar[iDirToPass].buffer;
@@ -475,9 +547,9 @@ bool Grid::send_one_var_one_face(int64_t iFace) {
475547

476548
if (report.test_verbose(4))
477549
std::cout << "in send_one_var_one_face : " << iFace << " from: " <<
478-
iProc << " to: " <<
479-
interchangesOneVar[iFace].iProc_to << " tag: " <<
480-
interchangesOneVar[iFace].iTag << "\n";
550+
iProc << " to: " <<
551+
interchangesOneVar[iFace].iProc_to << " tag: " <<
552+
interchangesOneVar[iFace].iTag << "\n";
481553

482554
MPI_Isend(interchangesOneVar[iFace].buffer,
483555
interchangesOneVar[iFace].iSizeTotal,
@@ -521,9 +593,9 @@ bool Grid::receive_one_var_one_face(int64_t iFace) {
521593

522594
if (report.test_verbose(4))
523595
std::cout << "in receive_one_var_one_face : " << iFace << " from: " <<
524-
iProc << " to: " <<
525-
interchangesOneVar[iFace].iProc_to << " tag: " <<
526-
interchangesOneVar[iFace].iTag << "\n";
596+
iProc << " to: " <<
597+
interchangesOneVar[iFace].iProc_to << " tag: " <<
598+
interchangesOneVar[iFace].iTag << "\n";
527599

528600

529601
MPI_Recv(interchangesOneVar[iFace].rbuffer,
@@ -1026,24 +1098,28 @@ bool exchange_one_var(Grid &grid,
10261098
int iTag, iDir, nDir;
10271099
int iSpecies;
10281100

1029-
static int64_t nX = grid.get_nX();
1030-
static int64_t nY = grid.get_nY();
1031-
static int64_t nZ = grid.get_nZ();
1032-
static int64_t nG = grid.get_nGCs();
1033-
static arma_cube var_scgc;
1101+
int64_t nX = grid.get_nX();
1102+
int64_t nY = grid.get_nY();
1103+
int64_t nZ = grid.get_nZ();
1104+
int64_t nG = grid.get_nGCs();
1105+
arma_cube var_scgc;
10341106

1035-
static int64_t nVarsToPass = 1;
1107+
int64_t nVarsToPass = 1;
10361108

10371109
if (!grid.isExchangeInitialized) {
10381110
DidWork = exchange_sides_init(grid, nVarsToPass);
10391111
grid.isExchangeInitialized = true;
1112+
std::cout << "initializing : " << grid.get_gridtype() << " " << nZ << " " <<
1113+
iProc << "\n";
10401114
}
1115+
10411116
var_scgc.set_size(nX, nY, nZ);
10421117

10431118
int64_t iP;
10441119
precision_t oneSign = 1.0;
10451120

10461121
nDir = 4;
1122+
10471123
if (grid.get_IsDipole() && grid.get_IsClosed())
10481124
nDir++;
10491125

@@ -1139,10 +1215,10 @@ bool test_ghostcell_interpolation(Grid &grid) {
11391215

11401216
bool didWork = true;
11411217

1142-
static int64_t iX, nX = grid.get_nX();
1143-
static int64_t iY, nY = grid.get_nY();
1144-
static int64_t iZ, nZ = grid.get_nZ();
1145-
static int64_t nG = grid.get_nGCs();
1218+
int64_t iX, nX = grid.get_nX();
1219+
int64_t iY, nY = grid.get_nY();
1220+
int64_t iZ, nZ = grid.get_nZ();
1221+
int64_t nG = grid.get_nGCs();
11461222
int64_t iStart, iEnd, jStart, jEnd, iDir;
11471223

11481224
// Check the latitudes and longitudes to make sure that they map to
@@ -1252,9 +1328,9 @@ arma_cube interpolate_ghostcells(arma_cube varIn, Grid &grid) {
12521328
bool didWork = true;
12531329

12541330
int64_t iDir;
1255-
static int64_t iX, ix_, nX = grid.get_nX();
1256-
static int64_t iY, iy_, nY = grid.get_nY();
1257-
static int64_t iG, nG = grid.get_nGCs();
1331+
int64_t iX, ix_, nX = grid.get_nX();
1332+
int64_t iY, iy_, nY = grid.get_nY();
1333+
int64_t iG, nG = grid.get_nGCs();
12581334
precision_t r_;
12591335
arma_cube varOut = varIn;
12601336

@@ -1322,10 +1398,10 @@ bool find_ghostcell_interpolation_coefs(Grid &grid) {
13221398

13231399
bool didWork = true;
13241400

1325-
static int64_t iX, nX = grid.get_nX();
1326-
static int64_t iY, nY = grid.get_nY();
1327-
static int64_t iZ, nZ = grid.get_nZ();
1328-
static int64_t nG = grid.get_nGCs();
1401+
int64_t iX, nX = grid.get_nX();
1402+
int64_t iY, nY = grid.get_nY();
1403+
int64_t iZ, nZ = grid.get_nZ();
1404+
int64_t nG = grid.get_nGCs();
13291405

13301406
// Test to see if the longitudes are the same as the original
13311407
arma_cube yOther = grid.refy_angle * cRtoD;

0 commit comments

Comments
 (0)