Skip to content

Commit c38c7dc

Browse files
committed
FEAT: move to interpolated GC scheme
1 parent 02b2a97 commit c38c7dc

File tree

1 file changed

+59
-40
lines changed

1 file changed

+59
-40
lines changed

src/exchange_messages.cpp

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,35 @@ Grid::messages_struct Grid::make_new_interconnection(int64_t iDir,
478478
// -----------------------------------------------------------------------------
479479

480480

481+
bool Neutrals::exchange_old(Grid &grid) {
482+
483+
std::string function = "Neutrals::exchange";
484+
static int iFunction = -1;
485+
report.enter(function, iFunction);
486+
487+
bool DidWork = true;
488+
489+
for (int iSpecies = 0; iSpecies < nSpecies; iSpecies++) {
490+
if (species[iSpecies].DoAdvect)
491+
DidWork = exchange_one_var(grid, species[iSpecies].density_scgc, false);
492+
}
493+
494+
DidWork = exchange_one_var(grid, temperature_scgc, false);
495+
496+
// velocity components:
497+
// reverse east across the pole:
498+
DidWork = exchange_one_var(grid, velocity_vcgc[0], true);
499+
// reverse north across the pole:
500+
DidWork = exchange_one_var(grid, velocity_vcgc[1], true);
501+
// don't reverse vertical across the pole:
502+
DidWork = exchange_one_var(grid, velocity_vcgc[2], false);
503+
504+
report.exit(function);
505+
return DidWork;
506+
}
507+
481508

509+
/*
482510
// -----------------------------------------------------------------------------
483511
// Exchange messages for the NEUTRALS:
484512
// 1. (first time) Set up the exchanging interfaces between edges / side
@@ -491,7 +519,7 @@ Grid::messages_struct Grid::make_new_interconnection(int64_t iDir,
491519
// 5. Unpack variables from all sides
492520
// -----------------------------------------------------------------------------
493521
494-
bool Neutrals::exchange_old(Grid &grid) {
522+
bool Neutrals::exchange_really_old(Grid &grid) {
495523
496524
std::string function = "Neutrals::exchange";
497525
static int iFunction = -1;
@@ -699,7 +727,7 @@ bool Neutrals::exchange_old(Grid &grid) {
699727
700728
return DidWork;
701729
}
702-
730+
*/
703731

704732

705733
// -----------------------------------------------------------------------------
@@ -843,6 +871,7 @@ bool exchange_sides_init(Grid &grid, int64_t nVarsToPass) {
843871
ReverseY,
844872
XbecomesY));
845873

874+
report.exit(function);
846875
return DidWork;
847876
}
848877

@@ -959,17 +988,20 @@ bool exchange_one_var(Grid &grid,
959988
MPI_Barrier(aether_comm);
960989

961990
// If this is a cubesphere grid, interpolate ghostcells to their proper location
962-
if (grid.IsCubeSphereGrid) {
991+
if (grid.IsCubeSphereGrid & grid.gcInterpolationSet) {
992+
report.print(3, "Interpolating Ghostcells to Proper Location");
963993
var_scgc = interpolate_ghostcells(var_to_pass, grid);
964994
var_to_pass = var_scgc;
965995
}
966996

967997
report.exit(function);
968-
969998
return DidWork;
970999
}
9711000

9721001
// -----------------------------------------------------------------------------
1002+
// This tests the ghostcell interpolation on the cubesphere by message passing
1003+
// latitudes and longitudes and checking to see if they match where they are
1004+
// expected to be.
9731005
// -----------------------------------------------------------------------------
9741006

9751007
bool test_ghostcell_interpolation(Grid &grid) {
@@ -989,13 +1021,15 @@ bool test_ghostcell_interpolation(Grid &grid) {
9891021
// Check the latitudes and longitudes to make sure that they map to
9901022
// the same location after message passing
9911023

1024+
// original lats and lons in degrees:
9921025
arma_cube lats = grid.geoLat_scgc * cRtoD;
9931026
arma_cube lons = grid.geoLon_scgc * cRtoD;
9941027

995-
arma_cube latsFixed = lats;
996-
arma_cube lonsFixed = lons;
1028+
// save the lats and lons that are the gold standard:
1029+
arma_cube latsGood = lats;
1030+
arma_cube lonsGood = lons;
9971031

998-
// Set the ghostcells to 0:
1032+
// Set the ghostcells in the test cells to 0:
9991033
set_gcs_to_value(lats, 0.0, nG);
10001034
set_gcs_to_value(lons, 0.0, nG);
10011035

@@ -1004,6 +1038,8 @@ bool test_ghostcell_interpolation(Grid &grid) {
10041038
didWork = exchange_one_var(grid, lats, false);
10051039
didWork = exchange_one_var(grid, lons, false);
10061040

1041+
// Now we will go through can compare the cells from the message passed cells to
1042+
// the saved cells:
10071043
if (report.test_verbose(1)) {
10081044

10091045
// Loop through the different directions:
@@ -1042,28 +1078,27 @@ bool test_ghostcell_interpolation(Grid &grid) {
10421078
iEnd = nX - nG;
10431079
}
10441080

1081+
// we really only care about one slice, so just take the first non-ghostcell slice:
10451082
iZ = nG;
10461083
std::cout << "Looping through iDir = " << iDir << "\n";
10471084

10481085
for (iX = iStart; iX < iEnd; iX++) {
10491086
for (iY = jStart; iY < jEnd; iY++) {
10501087

10511088
std::cout << "iX, iY : " << iX << " " << iY << " ";
1052-
std::cout << " lats pre-inter : " << lats(iX, iY, iZ);
1053-
std::cout << " lats post-inter : " << latsFixed(iX, iY, iZ);
1054-
std::cout << " should be : " << grid.geoLat_scgc(iX, iY, iZ) * cRtoD;
1089+
std::cout << " lats message passed : " << lats(iX, iY, iZ);
1090+
std::cout << " lats pre-pass : " << latsGood(iX, iY, iZ);
10551091

1056-
if (!compare(latsFixed(iX, iY, iZ), grid.geoLat_scgc(iX, iY, iZ) * cRtoD)) {
1092+
if (!compare(latsGood(iX, iY, iZ), lats(iX, iY, iZ))) {
10571093
std::cout << " <-- lats don't match!!! ";
10581094
didWork = false;
10591095
}
10601096

10611097
std::cout << "\n";
1062-
std::cout << " lons pre-inter : " << lons(iX, iY, iZ);
1063-
std::cout << " lons post-inter : " << lonsFixed(iX, iY, iZ);
1064-
std::cout << " should be : " << grid.geoLon_scgc(iX, iY, iZ) * cRtoD;
1098+
std::cout << " lons message passed : " << lons(iX, iY, iZ);
1099+
std::cout << " lons pre-pass : " << lonsGood(iX, iY, iZ);
10651100

1066-
if (!compare(lonsFixed(iX, iY, iZ), grid.geoLon_scgc(iX, iY, iZ) * cRtoD)) {
1101+
if (!compare(lonsGood(iX, iY, iZ), lons(iX, iY, iZ))) {
10671102
std::cout << " <-- lons don't match!!! ";
10681103
didWork = false;
10691104
}
@@ -1073,7 +1108,7 @@ bool test_ghostcell_interpolation(Grid &grid) {
10731108
}
10741109
}
10751110
}
1076-
1111+
report.exit(function);
10771112
return didWork;
10781113
}
10791114

@@ -1139,6 +1174,7 @@ arma_cube interpolate_ghostcells(arma_cube varIn, Grid &grid) {
11391174
}
11401175
}
11411176

1177+
report.exit(function);
11421178
return varOut;
11431179
}
11441180

@@ -1171,26 +1207,14 @@ bool find_ghostcell_interpolation_coefs(Grid &grid) {
11711207
set_gcs_to_value(xOther, 0.0, nG);
11721208

11731209
// Message pass to get the X and Y from the other faces
1174-
report.print(1, "starting exchange to find interpolation indices");
1210+
report.print(2, "starting exchange to find interpolation indices");
11751211
didWork = exchange_one_var(grid, yOther, false);
11761212
didWork = exchange_one_var(grid, xOther, false);
11771213

1178-
report.print(1, "finished exchange");
1179-
1180-
for (int64_t ip = 0; ip < 6; ip++) {
1181-
MPI_Barrier(aether_comm);
1214+
if (report.test_verbose(2)) {
11821215

1183-
if (iProc == ip) {
1184-
std::cout << "ip : " << ip << "\n";
1185-
std::cout << "xLocal : \n" << xLocal.slice(iZ) << "\n";
1186-
std::cout << "yLocal : \n" << yLocal.slice(iZ) << "\n";
1187-
}
1188-
}
1189-
1190-
1191-
MPI_Barrier(aether_comm);
1216+
std::cout << "finished exchange";
11921217

1193-
if (report.test_verbose(1)) {
11941218
std::cout << "xLocal : \n" << xLocal.slice(iZ) << "\n";
11951219
std::cout << "xOther : \n" << xOther.slice(iZ) << "\n";
11961220
std::cout << "yLocal : \n" << yLocal.slice(iZ) << "\n";
@@ -1261,7 +1285,7 @@ bool find_ghostcell_interpolation_coefs(Grid &grid) {
12611285
to = xLocal.slice(iZ).col(iY);
12621286
}
12631287

1264-
if (report.test_verbose(1)) {
1288+
if (report.test_verbose(3)) {
12651289
std::cout << "iDir : " << iDir << "\n";
12661290
std::cout << "drx : " << grid.interchangesOneVar[iDir].DoReverseX << "\n";
12671291
std::cout << "dry : " << grid.interchangesOneVar[iDir].DoReverseY << "\n";
@@ -1287,24 +1311,19 @@ bool find_ghostcell_interpolation_coefs(Grid &grid) {
12871311
std::cout << ind;
12881312
std::cout << "rat :\n";
12891313
std::cout << rat;
1290-
/*
1291-
for (int64_t iY = nG; iY < nY - nG; iY++) {
1292-
iy_ = grid.interchangesOneVar[iDir].index(iG, iY);
1293-
r = grid.interchangesOneVar[iDir].ratio(iG, iY);
1294-
*/
12951314
}
12961315
}
12971316
}
12981317

1299-
report.print(1, "finished compare");
1318+
grid.gcInterpolationSet = true;
13001319

1301-
didWork = test_ghostcell_interpolation(grid);
1320+
if (report.test_verbose(3))
1321+
didWork = test_ghostcell_interpolation(grid);
13021322

13031323
// Wait for all processors to be done.
13041324
MPI_Barrier(aether_comm);
13051325

13061326
report.exit(function);
1307-
13081327
return didWork;
13091328
}
13101329

0 commit comments

Comments
 (0)