Skip to content

Commit 98f5831

Browse files
committed
feat: calculate last latitude's p,q in fill_field_line
1 parent c884617 commit 98f5831

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/init_mag_grid.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,28 +155,30 @@ void Grid::fill_field_lines(arma_vec baseLatsLoc,
155155
report.enter(function, iFunction);
156156

157157
precision_t q_Start, delqp;
158-
arma_mat bAlts(nLats, nAlts), bLats(nLats, nAlts);
159158

160159
// allocate & calculate some things outside of the main loop
161160
// - mostly just factors to make the code easier to read
162161
precision_t qp0, fb0, ft, delq, qp2, fa, fb, term0, term1, term2, term3;
163162
// exp_q_dist is the fraction of total q-distance to step for each pt along field line
164163
arma_vec exp_q_dist(nAlts);
164+
165+
// corners/edges have one more lat dimension...
166+
int64_t nLatLoc = baseLatsLoc.n_elem;
165167

166168
// temp holding of results from q,p -> r,theta conversion:
167169
std:: pair<precision_t, precision_t> r_theta;
168170

169171
// Find L-Shell for each baseLat
170172
// using L=R/sin2(theta), where theta is from north pole
171-
arma_vec Lshells(nLats);
172-
for (int64_t iLat = 0; iLat < nLats; iLat++)
173+
arma_vec Lshells(nLatLoc);
174+
for (int64_t iLat = 0; iLat < nLatLoc; iLat++)
173175
Lshells(iLat) = (min_altRe) / pow(sin(cPI / 2 - baseLatsLoc(iLat)), 2.0);
174176

175177
report.print(3, "lshells calculated!");
176178

177179
if (!isCorner){
178180
for (int64_t iLon = 0; iLon < nLons; iLon ++){
179-
for (int64_t iLat = 0; iLat < nLats; iLat ++){
181+
for (int64_t iLat = 0; iLat < nLatLoc; iLat ++){
180182
for (int64_t iAlt = 0; iAlt < nAlts; iAlt ++){
181183
magP_scgc(iLon, iLat, iAlt) = Lshells(iLat);
182184
}
@@ -185,7 +187,7 @@ void Grid::fill_field_lines(arma_vec baseLatsLoc,
185187
}
186188
else{
187189
for (int64_t iLon = 0; iLon < nLons; iLon ++){
188-
for (int64_t iLat = 0; iLat < nLats; iLat ++){
190+
for (int64_t iLat = 0; iLat < nLatLoc; iLat ++){
189191
for (int64_t iAlt = 0; iAlt < nAlts; iAlt ++){
190192
magP_Down(iLon, iLat, iAlt) = Lshells(iLat);
191193
}}}
@@ -196,7 +198,10 @@ void Grid::fill_field_lines(arma_vec baseLatsLoc,
196198
exp_q_dist(iAlt) = Gamma + (1 - Gamma) * exp(-pow(((iAlt - nAlts) / (nAlts / 5.0)), 2.0));
197199
report.print(3, "expQ");
198200

199-
for (int iLat = 0; iLat < nLats; iLat++)
201+
// mag alts and lats:
202+
arma_mat bAlts(nLatLoc, nAlts), bLats(nLatLoc, nAlts);
203+
204+
for (int iLat = 0; iLat < nLatLoc; iLat++)
200205
{
201206
q_Start = -cos(cPI / 2 + baseLatsLoc(iLat)) / pow(min_altRe, 2.0);
202207

@@ -247,7 +252,7 @@ void Grid::fill_field_lines(arma_vec baseLatsLoc,
247252
// This is wrong (same lat everywhere), but get_radius doesnt support oblate earth yet.
248253
planetRadius = planet.get_radius(bLats(0));
249254

250-
for (int64_t iLat = 0; iLat < nLats; iLat++)
255+
for (int64_t iLat = 0; iLat < nLatLoc; iLat++)
251256
{
252257
for (int64_t iLon = 0; iLon < nLons; iLon++)
253258
{

0 commit comments

Comments
 (0)