Skip to content

Commit 7aa0614

Browse files
authored
Merge branch 'messagepass_grids' into develop
2 parents 613d783 + e3859a2 commit 7aa0614

File tree

4 files changed

+71
-6
lines changed

4 files changed

+71
-6
lines changed

include/calc_grid_derived.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ arma_vec calc_bin_edges(arma_vec centers);
1616
std::vector<precision_t> calc_bin_widths(std::vector<precision_t> centers);
1717
arma_vec calc_bin_widths(arma_vec centers);
1818

19+
// ----------------------------------------------------------------------------
20+
// A helper function for mapping grids
21+
// ----------------------------------------------------------------------------
22+
bool grid_match(Grid gGrid,
23+
Grid mGrid,
24+
Quadtree gQuadtree,
25+
Quadtree mQuadtree);
26+
1927
#endif // INCLUDE_CALC_GRID_DERIVED_H_

src/grid_match.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2025, the Aether Development Team (see doc/dev_team.md for members)
2+
// Full license can be found in License.md
3+
4+
#include "aether.h"
5+
6+
bool grid_match(Grid gGrid,
7+
Grid mGrid,
8+
Quadtree gQuadtree,
9+
Quadtree mQuadtree) {
10+
11+
// Let's do magnetic to geographic first:
12+
13+
int64_t iX, mnX = mGrid.get_nX();
14+
int64_t iY, mnY = mGrid.get_nY();
15+
int64_t iZ, mnZ = mGrid.get_nZ();
16+
int64_t mGCs = mGrid.get_nGCs();
17+
precision_t lon, lat;
18+
precision_t normX, normY, normZ;
19+
arma_vec norms(3);
20+
int64_t iNode;
21+
22+
for (iX = mGCs; iX < mnX - mGCs; iX++) {
23+
for (iY = mGCs; iY < mnY - mGCs; iY++) {
24+
for (iZ = mGCs; iZ < mnZ - mGCs; iZ++) {
25+
lon = mGrid.geoLon_scgc(iX, iY, iZ);
26+
lat = mGrid.geoLat_scgc(iX, iY, iZ);
27+
if (gGrid.iGridShape_ == gGrid.iSphere_) {
28+
norms(0) = lon / cPI;
29+
norms(1) = lat / cPI;
30+
norms(2) = 0.0;
31+
iNode = gQuadtree.find_point(norms);
32+
} else {
33+
norms = sphere_to_cube(lon, lat);
34+
iNode = gQuadtree.find_point(norms);
35+
}
36+
std::cout << "lon, lat, node: " << lon*cRtoD << " "
37+
<< lat*cRtoD << " "
38+
<< norms(0) << " "
39+
<< norms(1) << " "
40+
<< norms(2) << " "
41+
<< iNode << "\n";
42+
}
43+
}
44+
}
45+
return true;
46+
}

src/main/main.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ int main() {
5656

5757
// Initialize the planet:
5858
Planets planet;
59+
MPI_Barrier(aether_comm);
5960
if (!planet.is_ok())
6061
throw std::string("planet initialization failed!");
6162

6263
// Initialize the indices, read the files, and perturb:
6364
Indices indices;
6465
didWork = read_and_store_indices(indices);
66+
MPI_Barrier(aether_comm);
6567
if (!didWork)
6668
throw std::string("read_and_store_indices failed!");
6769

@@ -71,6 +73,7 @@ int main() {
7173
// Initialize Geographic grid:
7274
Grid gGrid("neuGrid");
7375
didWork = gGrid.init_geo_grid(quadtree, planet);
76+
MPI_Barrier(aether_comm);
7477
if (!didWork)
7578
throw std::string("init_geo_grid failed!");
7679

@@ -91,14 +94,16 @@ int main() {
9194
didWork = mGrid.init_dipole_grid(quadtree_ion, planet);
9295
if (!didWork)
9396
throw std::string("init_dipole_grid failed!");
94-
}
95-
else {
97+
} else {
98+
std::cout << "Making Spherical Magnetic Grid\n";
9699
mGrid.set_IsDipole(false);
97100
didWork = mGrid.init_geo_grid(quadtree, planet);
98101
mGrid.set_IsGeoGrid(false);
99102
}
100103

101-
// Initialize Neutrals on geographic and magnetic grids:
104+
didWork = grid_match(gGrid, mGrid, quadtree, quadtree_ion);
105+
106+
// Initialize Neutrals on geographic grid:
102107
Neutrals neutrals(gGrid, planet, time, indices);
103108
Neutrals neutralsMag(mGrid, planet, time, indices);
104109

src/quadtree.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ Quadtree::qtnode Quadtree::new_node(arma_vec lower_left_norm_in,
217217
}
218218

219219
// --------------------------------------------------------------------------
220-
//
220+
// This returns the lower left (LL) coordinate in normalized coordinates or
221+
// the size of the node in the right (SR) or up (SU) directions. It can
222+
// also return the midpoint of the node (MID)
221223
// --------------------------------------------------------------------------
222224

223225
arma_vec Quadtree::get_vect(Quadtree::qtnode node, std::string which) {
@@ -499,7 +501,9 @@ arma_vec Quadtree::wrap_point_cubesphere(arma_vec point) {
499501
}
500502

501503
// --------------------------------------------------------------------------
502-
//
504+
// This is the starting point for determining which node a point
505+
// on the sphere is located. The point needs to be in normalized
506+
// coordinates.
503507
// --------------------------------------------------------------------------
504508

505509
int64_t Quadtree::find_point(arma_vec point) {
@@ -525,7 +529,9 @@ int64_t Quadtree::find_point(arma_vec point) {
525529
}
526530

527531
// --------------------------------------------------------------------------
528-
//
532+
// This is the starting point for determining which root a point
533+
// on the sphere is located. The point needs to be in normalized
534+
// coordinates.
529535
// --------------------------------------------------------------------------
530536

531537
int64_t Quadtree::find_root(arma_vec point) {

0 commit comments

Comments
 (0)