@@ -59,6 +59,9 @@ void Grid::init_dipole_grid(Quadtree quadtree, Planets planet)
59
59
60
60
Inputs::grid_input_struct grid_input = input.get_grid_inputs (" ionGrid" );
61
61
62
+ // Number of ghost cells:
63
+ int64_t nGCs = get_nGCs ();
64
+
62
65
// Get inputs
63
66
report.print (3 , " Setting inputs in dipole grid" );
64
67
precision_t min_apex = grid_input.min_apex * cKMtoM;
@@ -85,6 +88,11 @@ void Grid::init_dipole_grid(Quadtree quadtree, Planets planet)
85
88
precision_t dlon = size_right_norm (0 ) * cPI / (nLons - 2 * nGCs);
86
89
precision_t lon0 = lower_left_norm (0 ) * cPI;
87
90
arma_vec lon1d (nLons);
91
+
92
+ // Quick 1D check for longitudes:
93
+ // Same as geo_grid here...
94
+ if (!HasXdim) dlon = 1.0 * cDtoR;
95
+
88
96
for (iLon = 0 ; iLon < nLons; iLon++)
89
97
lon1d (iLon) = lon0 + (iLon - nGCs + 0.5 ) * dlon;
90
98
@@ -96,7 +104,7 @@ void Grid::init_dipole_grid(Quadtree quadtree, Planets planet)
96
104
97
105
geoLon_scgc = magLon_scgc;
98
106
99
- // LATITUDES
107
+ // LATITUDES:
100
108
101
109
// min_latitude calculated from min_lshell (min_apex input)
102
110
precision_t min_lat = get_lat_from_r_and_lshell (1.0 , min_lshell);
@@ -105,38 +113,44 @@ void Grid::init_dipole_grid(Quadtree quadtree, Planets planet)
105
113
// some intermediates:
106
114
precision_t del_lat, blat_min_, blat_max_, tmp_lat;
107
115
// Integers for field-line loops:
108
- // - nF=nLats/2 (so nLarts MUST be even)
109
- // - nZ=nAlts
110
- // - nZby2 = nZ/2
111
- int64_t nF = nLats / 2 , nZ = nAlts*2 , nZby2 = nAlts;
116
+ // - nF=nLats/2 (so nLats MUST be even)
117
+ // - nZ=nAlts*2 - (we fill up HALF field lines)
118
+ // - nZby2 = nAlts
119
+ // -> Plus, experinemtal support for altitude ghost cells...
120
+ int64_t nF = (nLats) / 2 , nZ = (nAlts) * 2 , nZby2 = (nAlts);
112
121
// lShells and baseLats are currently set for southern hemisphere then mirrored
113
122
arma_vec Lshells (nF), baseLats (nF);
114
123
124
+ blat_min_ = cos (pow (min_lat, 1.0 / LatStretch));
125
+ blat_max_ = cos (pow (max_lat, 1.0 / LatStretch));
126
+ del_lat = (blat_max_ - blat_min_) / (nF - nGCs * 2.0 );
127
+
115
128
// now make sure the user used 1 or an even number for nLats
116
129
if (nLats % 2 != 0 )
117
130
{
118
- if (nLats == 1 )
131
+ if (!HasYdim)
119
132
{
120
- report.print (0 , " >> Running in 1D. Experinental!!" );
133
+ del_lat = 1.0 * cDtoR;
134
+ report.print (0 , " Running in single latitude dimension. Experinental!!" );
121
135
nF = 1 ;
122
136
}
123
137
else
124
138
report.error (" Cannot use odd nLats with dipole grid!" );
125
139
}
126
140
127
- blat_min_ = cos (pow (min_lat, 1.0 / LatStretch));
128
- blat_max_ = cos (pow (max_lat, 1.0 / LatStretch));
129
- del_lat = (blat_max_ - blat_min_) / (nF - nGCs * 2.0 );
130
-
141
+ // loop over all cells - everything including the ghost cells
142
+ // -> This means some points will go over the pole (baseLat > +- 90 degrees)
143
+ // They're taken care of in the conversion to geographic coordinates.
131
144
for (int i = 0 ; i < nF; i++)
132
145
{
133
146
// first put down "linear" spacing
134
147
tmp_lat = blat_min_ + del_lat * (i - nGCs + 0.5 );
135
- // then scale it according to the exponent & acos it
148
+ // then scale it according to the exponent & acos
136
149
tmp_lat = pow (acos (tmp_lat), LatStretch);
137
150
// place values in array backwards, South pole -> equator.
138
151
baseLats (nF - i - 1 ) = -tmp_lat;
139
152
}
153
+ report.print (3 , " Done setting base latitudes for dipole grid." );
140
154
141
155
// Find L-Shell for each baseLat
142
156
// using L=R/sin2(theta), where theta is from north pole
@@ -176,8 +190,7 @@ void Grid::init_dipole_grid(Quadtree quadtree, Planets planet)
176
190
// inlo loop thru southern hemisphere, mirror in north.
177
191
for (int i_nZ = 0 ; i_nZ < nAlts; i_nZ++)
178
192
{
179
- // Should be using lshell_to_qn_qs, but it wasn't working right.
180
- // This does the same, but won't work for offset dipoles.
193
+ // This won't work for offset dipoles.
181
194
// Doesn't have any lat/lon dependence.
182
195
delqp = (q_N - q_S) / (nZ + 1 );
183
196
qp0 = q_S + i_nZ * (delqp);
@@ -194,6 +207,7 @@ void Grid::init_dipole_grid(Quadtree quadtree, Planets planet)
194
207
bLats (i_nF, i_nZ) = r_theta.second ;
195
208
}
196
209
}
210
+ report.print (3 , " Done generating q-spacing for dipole grid." );
197
211
198
212
arma_vec rNorm1d (nAlts), lat1dAlong (nAlts);
199
213
arma_cube r3d (nLons, nLats, nAlts);
@@ -218,11 +232,13 @@ void Grid::init_dipole_grid(Quadtree quadtree, Planets planet)
218
232
magLat_scgc.tube (iLon, nLats - iLat - 1 ) = -lat1dAlong;
219
233
}
220
234
}
235
+ report.print (3 , " Done generating symmetric latitude & altitude spacing in dipole." );
221
236
222
237
geoLat_scgc = magLat_scgc;
223
238
magAlt_scgc = r3d - planetRadius;
224
239
geoAlt_scgc = magAlt_scgc;
225
240
241
+ report.print (4 , " Beginning coordinate transformations of the dipole grid." );
226
242
// Calculate the radius, of planet
227
243
fill_grid_radius (planet);
228
244
@@ -256,6 +272,8 @@ void Grid::init_dipole_grid(Quadtree quadtree, Planets planet)
256
272
gravity_vcgc[1 ] % gravity_vcgc[1 ] +
257
273
gravity_vcgc[2 ] % gravity_vcgc[2 ]);
258
274
275
+ report.print (4 , " Done gravity calculations for the dipole grid." );
276
+
259
277
std::vector<arma_cube> llr, xyz, xyzRot1, xyzRot2;
260
278
llr.push_back (magLon_scgc);
261
279
llr.push_back (magLat_scgc);
@@ -275,11 +293,14 @@ void Grid::init_dipole_grid(Quadtree quadtree, Planets planet)
275
293
geoLon_scgc = llr[0 ];
276
294
geoLat_scgc = llr[1 ];
277
295
geoAlt_scgc = llr[2 ] - planetRadius;
296
+ report.print (4 , " Done dipole -> geographic transformations for the dipole grid." );
278
297
279
298
calc_alt_grid_spacing ();
299
+ report.print (4 , " Done altitude spacing for the dipole grid." );
280
300
281
301
// Calculate magnetic field and magnetic coordinates:
282
302
fill_grid_bfield (planet);
303
+ report.print (4 , " Done filling dipole grid with b-field!" );
283
304
284
305
report.exit (function);
285
306
return ;
0 commit comments