Skip to content

Commit 6bb4d6d

Browse files
committed
bug??: Make sure the altitude limits & ghost cells on the dipole grid are correct
1 parent e0db896 commit 6bb4d6d

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/init_mag_grid.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ bool Grid::init_dipole_grid(Quadtree quadtree_ion, Planets planet) {
121121
precision_t min_alt = grid_input.alt_min * cKMtoM;
122122
precision_t max_alt = grid_input.alt_max * cKMtoM;
123123

124-
// Normalize inputs to planet radius... (update when earth is oblate)
124+
// Normalize inputs to planet radius... (update one day to support oblate Planet)
125125
// Here we are using the equatorial radius.
126126
precision_t planetRadius = planet.get_radius(0.0);
127127
// Altitude to begin modeling, normalized to planet radius
@@ -281,10 +281,10 @@ bool Grid::init_dipole_grid(Quadtree quadtree_ion, Planets planet) {
281281
// invLats are still all in North Hemisphere & increasing.
282282
// Use minimum p & alt to solve for q
283283
// q = sqrt((1-r/p)/r^4)
284-
q_min = pow(((1 - max_alt_re / Pcenters(nGCs)) / pow(max_alt_re, 4.0)), 0.5);
284+
q_min = pow(((1 - max_alt_re / Pcorners(0)) / pow(max_alt_re, 4.0)), 0.5);
285285

286286
// Trace each field line up to q_max, obtained from the lowest field line in the block
287-
precision_t q_max = pow(((1 - min_alt_re / Pcenters(nLats - nGCs)) / pow(
287+
precision_t q_max = pow(((1 - min_alt_re / Pcorners(nLats -1)) / pow(
288288
min_alt_re,
289289
4.0)), 0.5);
290290

@@ -302,8 +302,7 @@ bool Grid::init_dipole_grid(Quadtree quadtree_ion, Planets planet) {
302302

303303
magQ_corner_1d(nAlts) = q_min + (nAlts - nGCs) * delQ;
304304

305-
report.print(3,
306-
"Done generating points for magnetic grid. Plugging everything in");
305+
report.print(3, "Done generating points for magnetic grid. Plugging everything in");
307306

308307
////////////////////////////
309308
// That is the grid made. //
@@ -510,15 +509,20 @@ bool Grid::init_dipole_grid(Quadtree quadtree_ion, Planets planet) {
510509
isPhysicalCell = find(geoAlt_scgc >= grid_input.alt_min * cKMtoM);
511510
UseThisCell.elem(isTooLowCell).fill(false);
512511

513-
arma::uvec theGCs;
514512
for (iLon=0; iLon<nLons; iLon++){
515513
for (iLat = 0; iLat<nLats; iLat++){
516514
// find *last* cell below alt_min
517-
theGCs = find(geoAlt_scgc.tube(iLon, iLat) < grid_input.alt_min * cKMtoM);
518-
// Get the last element if the col-vec
519-
first_lower_gc(iLon, iLat) = theGCs(theGCs.n_elem - 1);
515+
first_lower_gc(iLon, iLat) = find(geoAlt_scgc.tube(iLon, iLat)
516+
< grid_input.alt_min * cKMtoM).max();
520517
}
521518
}
519+
if (first_lower_gc.min() < nGCs-1 || first_lower_gc.max() > nAlts-nGCs-1){
520+
report.error("Invalid magnetic grid!! Either:");
521+
report.error(" - Lowest latitude field line is entirely below min_alt");
522+
report.error(" - Highest altitude field line is above min_alt");
523+
report.error("This should not happen. Something is terribly wrong. Goodbye.");
524+
return false;
525+
}
522526
first_upper_gc.fill(nAlts - nGCs * 2 - 1);
523527

524528
report.print(4, "Done altitude spacing for the dipole grid.");

0 commit comments

Comments
 (0)