Skip to content

Commit 58e2f21

Browse files
committed
FEAT: Better handling of alt gc's. And add mat of first ghost cell.
1 parent 18c6740 commit 58e2f21

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

include/grid.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,14 @@ class Grid
102102
arma_cube magQ_Corner;
103103
arma_cube magInvLat_Corner;
104104

105-
// Dipole grid has cells below the surface of earth. These variables hold masks
106-
// to either access those cells or ignore them (with .elem()).
105+
// Masks to either access the non-physical (ghost) cells, or ignore them - use with
106+
// .elem()). Together they *should* hold the indices of all cells.
107107
arma::uvec isTooLowCell, isPhysicalCell;
108-
arma_cube UseThisCell; // (bool values whether altitude is valid)
108+
// (bool values whether altitude is valid)
109+
arma_cube UseThisCell;
110+
// Matrices whose elements denote the altitude index of the interiormost ghost cell
111+
// in the k-up and k-down direction (altitude for geo grids, q for dipole).
112+
arma_mat first_lower_gc, first_upper_gc;
109113

110114
// These are the locations of the magnetic poles:
111115
// ll -> lat, lon, radius independent

src/grid.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Grid::Grid(std::string gridtype) {
1313

1414
// At this point, we only need 2 ghostcells. Hardcode this:
15+
// This is also (kinda?) set in sizes.h for the geo & mag grid independently
1516
nGCs = 2;
1617

1718
Inputs::grid_input_struct grid_input = input.get_grid_inputs(gridtype);
@@ -272,6 +273,8 @@ Grid::Grid(std::string gridtype) {
272273

273274
UseThisCell.set_size(nX, nY, nZ);
274275
UseThisCell.fill(true);
276+
first_lower_gc.set_size(nX, nY);
277+
first_upper_gc.set_size(nX, nY);
275278

276279
cent_acc_vcgc = make_cube_vector(nLons, nLats, nAlts, 3);
277280

src/init_geo_grid.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,20 @@ void Grid::create_altitudes(Planets planet) {
151151
}
152152

153153
// All cells on the geographic grid *should* be ok
154-
isTooLowCell = find(geoAlt_scgc < 0.0);
155-
isPhysicalCell = find(geoAlt_scgc > 0.0);
154+
isTooLowCell = find(geoAlt_scgc < grid_input.alt_min * cKMtoM);
155+
isPhysicalCell = find(geoAlt_scgc >= grid_input.alt_min * cKMtoM);
156+
// get the ghost cell indices on each lat/lon point.
157+
// may be redundant can fill lower with nGCs-1, but this is here for now
158+
arma::uvec theGCs;
159+
for (iLon=0; iLon<nLons; iLon++){
160+
for (iLat = 0; iLat<nLats; iLat++){
161+
// find *last* cell below alt_min
162+
theGCs = find(geoAlt_scgc.tube(iLon, iLat) < grid_input.alt_min * cKMtoM);
163+
// Get the last element if the col-vec
164+
first_lower_gc(iLon, iLat) = theGCs(theGCs.n_elem - 1);
165+
}
166+
}
167+
first_upper_gc.fill(nAlts - nGCs * 2 - 1);
156168

157169
report.exit(function);
158170
return;

src/init_mag_grid.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,21 @@ bool Grid::init_dipole_grid(Quadtree quadtree_ion, Planets planet) {
506506
// Generate mask for physicsl cells //
507507
//////////////////////////////////////
508508

509-
isTooLowCell = find(geoAlt_scgc <= 0.0);
510-
isPhysicalCell = find(geoAlt_scgc > 0.0);
509+
isTooLowCell = find(geoAlt_scgc < grid_input.alt_min * cKMtoM);
510+
isPhysicalCell = find(geoAlt_scgc >= grid_input.alt_min * cKMtoM);
511511
UseThisCell.elem(isTooLowCell).fill(false);
512512

513+
arma::uvec theGCs;
514+
for (iLon=0; iLon<nLons; iLon++){
515+
for (iLat = 0; iLat<nLats; iLat++){
516+
// 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);
520+
}
521+
}
522+
first_upper_gc.fill(nAlts - nGCs * 2 - 1);
523+
513524
report.print(4, "Done altitude spacing for the dipole grid.");
514525

515526
// Calculate magnetic field and magnetic coordinates:

0 commit comments

Comments
 (0)