@@ -121,7 +121,7 @@ bool Grid::init_dipole_grid(Quadtree quadtree_ion, Planets planet) {
121
121
precision_t min_alt = grid_input.alt_min * cKMtoM;
122
122
precision_t max_alt = grid_input.alt_max * cKMtoM;
123
123
124
- // Normalize inputs to planet radius... (update when earth is oblate)
124
+ // Normalize inputs to planet radius... (update one day to support oblate Planet )
125
125
// Here we are using the equatorial radius.
126
126
precision_t planetRadius = planet.get_radius (0.0 );
127
127
// Altitude to begin modeling, normalized to planet radius
@@ -281,10 +281,10 @@ bool Grid::init_dipole_grid(Quadtree quadtree_ion, Planets planet) {
281
281
// invLats are still all in North Hemisphere & increasing.
282
282
// Use minimum p & alt to solve for q
283
283
// 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 );
285
285
286
286
// 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 (
288
288
min_alt_re,
289
289
4.0 )), 0.5 );
290
290
@@ -302,8 +302,7 @@ bool Grid::init_dipole_grid(Quadtree quadtree_ion, Planets planet) {
302
302
303
303
magQ_corner_1d (nAlts) = q_min + (nAlts - nGCs) * delQ;
304
304
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" );
307
306
308
307
// //////////////////////////
309
308
// That is the grid made. //
@@ -510,15 +509,20 @@ bool Grid::init_dipole_grid(Quadtree quadtree_ion, Planets planet) {
510
509
isPhysicalCell = find (geoAlt_scgc >= grid_input.alt_min * cKMtoM);
511
510
UseThisCell.elem (isTooLowCell).fill (false );
512
511
513
- arma::uvec theGCs;
514
512
for (iLon=0 ; iLon<nLons; iLon++){
515
513
for (iLat = 0 ; iLat<nLats; iLat++){
516
514
// 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 ();
520
517
}
521
518
}
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
+ }
522
526
first_upper_gc.fill (nAlts - nGCs * 2 - 1 );
523
527
524
528
report.print (4 , " Done altitude spacing for the dipole grid." );
0 commit comments