Skip to content

Commit b429fe2

Browse files
authored
Merge pull request #160 from abukowski21/dipole_again
Dipole grid for the ions
2 parents 7013fd8 + cd6447a commit b429fe2

File tree

16 files changed

+997
-219
lines changed

16 files changed

+997
-219
lines changed

include/aether.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ using json = nlohmann::json;
8080
#include "cubesphere.h"
8181
#include "sphere.h"
8282
#include "quadtree.h"
83+
#include "dipole.h"
8384

8485
// not done
8586
#include "grid.h"
87+
#include "init_mag_grid.h"
8688

8789
// Contains the neutral states and derived quantities
8890
#include "neutrals.h"

include/dipole.h

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright 2020, the Aether Development Team (see doc/dev_team.md for members)
2+
// Full license can be found in License.md
3+
4+
#ifndef INCLUDE_DIPOLE_H_
5+
#define INCLUDE_DIPOLE_H_
6+
7+
#include "aether.h"
8+
#include <memory>
9+
10+
/*************************************************
11+
* \brief A namespace with all (1-root) dipole grid logic.
12+
*************************************************/
13+
namespace Dipole {
14+
15+
/// The normalized origins of each face of the cube (i.e. corner)
16+
static const arma_mat ORIGINS = {
17+
{ 0.0, -0.5, 0.0}
18+
};
19+
20+
/// Normalized right steps in cube
21+
static const arma_mat RIGHTS = {
22+
{2.0, 0.0, 0.0}
23+
};
24+
25+
/// Normalized up steps in cube
26+
static const arma_mat UPS = {
27+
{0.0, 1.0, 0.0}
28+
};
29+
30+
};
31+
32+
/*************************************************
33+
* \brief A namespace with all (2-root) dipole grid logic.
34+
*************************************************/
35+
namespace Dipole2 {
36+
37+
/// The normalized origins of each face of the cube (i.e. corner)
38+
static const arma_mat ORIGINS = {
39+
{ 0.0, -0.5, 0.0},
40+
{ 0.0, 0.0, 0.0}
41+
};
42+
43+
/// Normalized right steps in cube
44+
static const arma_mat RIGHTS = {
45+
{2.0, 0.0, 0.0},
46+
{2.0, 0.0, 0.0}
47+
};
48+
49+
/// Normalized up steps in cube
50+
static const arma_mat UPS = {
51+
{0.0, 0.5, 0.0},
52+
{0.0, 0.5, 0.0}
53+
};
54+
55+
};
56+
57+
/*************************************************
58+
* \brief A namespace with all (4-root) dipole grid logic.
59+
*************************************************/
60+
namespace Dipole4 {
61+
62+
/// The normalized origins of each face of the cube (i.e. corner)
63+
static const arma_mat ORIGINS = {
64+
{ 0.0, -0.5, 0.0},
65+
{ 1.0, -0.5, 0.0},
66+
{ 1.0, 0.0, 0.0},
67+
{ 0.0, 0.0, 0.0}
68+
};
69+
70+
/// Normalized right steps in cube
71+
static const arma_mat RIGHTS = {
72+
{1.0, 0.0, 0.0},
73+
{1.0, 0.0, 0.0},
74+
{1.0, 0.0, 0.0},
75+
{1.0, 0.0, 0.0}
76+
};
77+
78+
/// Normalized up steps in cube
79+
static const arma_mat UPS = {
80+
{0.0, 0.5, 0.0},
81+
{0.0, 0.5, 0.0},
82+
{0.0, 0.5, 0.0},
83+
{0.0, 0.5, 0.0}
84+
};
85+
86+
};
87+
88+
89+
/*************************************************
90+
* \brief A namespace with all (6-root) dipole grid logic.
91+
* This is the same as the Sphere6
92+
*************************************************/
93+
94+
namespace Dipole6 {
95+
96+
/// The normalized origins of each face of the cube (i.e. corner)
97+
static const arma_mat ORIGINS = {
98+
{ 0.0, -0.5, 0.0},
99+
{2.0/3.0, -0.5, 0.0},
100+
{4.0/3.0, -0.5, 0.0},
101+
{ 0.0, 0.0, 0.0},
102+
{2.0/3.0, 0.0, 0.0},
103+
{4.0/3.0, 0.0, 0.0}
104+
};
105+
106+
/// Normalized right steps in cube
107+
static const arma_mat RIGHTS = {
108+
{ 2.0/3.0, 0.0, 0.0},
109+
{ 2.0/3.0, 0.0, 0.0},
110+
{ 2.0/3.0, 0.0, 0.0},
111+
{ 2.0/3.0, 0.0, 0.0},
112+
{ 2.0/3.0, 0.0, 0.0},
113+
{ 2.0/3.0, 0.0, 0.0}
114+
};
115+
116+
/// Normalized right steps in cube
117+
static const arma_mat UPS = {
118+
{ 0.0, 0.5, 0.0},
119+
{ 0.0, 0.5, 0.0},
120+
{ 0.0, 0.5, 0.0},
121+
{ 0.0, 0.5, 0.0},
122+
{ 0.0, 0.5, 0.0},
123+
{ 0.0, 0.5, 0.0}
124+
};
125+
126+
}
127+
128+
129+
#endif // INCLUDE_DIPOLE_H_

include/grid.h

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,37 @@ class Grid
7373
arma_cube magAlt_scgc, magZ_scgc;
7474
arma_cube magLocalTime_scgc;
7575

76+
// Dipole coordinates:
77+
// Phi => Longitude
78+
// P => L-shell
79+
// Q => Distance along field line
7680
arma_cube magPhi_scgc;
7781
arma_cube magP_scgc;
7882
arma_cube magQ_scgc;
7983

84+
// And the corners/edges for the magnetic grid:
85+
arma_cube magLon_Left;
86+
arma_cube magLon_Corner;
87+
88+
arma_cube magLat_Down;
89+
arma_cube magLat_Below;
90+
arma_cube magLat_Corner;
91+
92+
arma_cube magAlt_Down;
93+
arma_cube magAlt_Below;
94+
arma_cube magAlt_Corner;
95+
96+
//For easier interpolation:
97+
arma_vec baseLats_down;
98+
99+
// these need to be stored in (p,q) coords for a bit, its messy:
100+
arma_cube magP_Down;
101+
arma_cube magP_Below;
102+
arma_cube magQ_Down;
103+
arma_cube magQ_Below;
104+
arma_cube magP_Corner;
105+
arma_cube magQ_Corner;
106+
80107
// These are the locations of the magnetic poles:
81108
// ll -> lat, lon, radius independent
82109
arma_vec mag_pole_north_ll;
@@ -213,6 +240,7 @@ class Grid
213240
void calc_alt_grid_spacing();
214241
void calc_lat_grid_spacing();
215242
void calc_long_grid_spacing();
243+
216244
void fill_grid_radius(Planets planet);
217245
void calc_rad_unit(Planets planet);
218246
void calc_gravity(Planets planet);
@@ -230,21 +258,33 @@ class Grid
230258
void calc_cent_acc(Planets planet);
231259

232260
// Make mag-field grid:
233-
std::pair<precision_t, precision_t> lshell_to_qn_qs(Planets planet,
234-
precision_t Lshell,
235-
precision_t Lon,
236-
precision_t AltMin);
237261
void convert_dipole_geo_xyz(Planets planet, precision_t XyzDipole[3],
238262
precision_t XyzGeo[3]);
239-
std::pair<arma_vec, arma_vec> fill_dipole_q_line(precision_t qN_,
240-
precision_t qS_,
241-
precision_t Gamma_,
242-
int64_t nZ_,
243-
precision_t Lshell_,
244-
precision_t min_alt_);
245-
std::pair<precision_t, precision_t> qp_to_r_theta(precision_t q, precision_t p);
246-
void init_dipole_grid(Quadtree quadtree, Planets planet);
247-
arma_vec rNorm1d, lat1dalong;
263+
264+
bool init_dipole_grid(Quadtree quadtree_ion, Planets planet);
265+
// Support functions:
266+
void calc_dipole_grid_spacing(Planets planet);
267+
void calc_alt_dipole_grid_spacing();
268+
void calc_lat_dipole_grid_spacing();
269+
void calc_long_dipole_grid_spacing();
270+
void fill_field_lines(arma_vec baseLats, precision_t min_altRe,
271+
precision_t Gamma, Planets planet,
272+
bool isCorner);
273+
void dipole_alt_edges(Planets planet, precision_t min_altRe);
274+
// get the latitude spacing given the quadtree start & size, and the latitude limits
275+
// extent: quadtree up
276+
// origin: quadtree origin
277+
// upper_lim: upper latitude limit (input)
278+
// lower_lim: lower latitude limit (from min_apex)
279+
// nLats: number of latitudes (nY)
280+
// spacing_factor: (not supported yet), so always 1.0. Will adjust baselat spacing, eventually.
281+
arma_vec baselat_spacing(precision_t extent,
282+
precision_t origin,
283+
precision_t upper_lim,
284+
precision_t lower_lim,
285+
// int16_t nLats,
286+
precision_t spacing_factor);
287+
248288
// Update ghost cells with values from other processors
249289
void exchange(arma_cube &data, const bool pole_inverse);
250290

include/init_mag_grid.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2020, the Aether Development Team (see doc/dev_team.md for members)
2+
// Full license can be found in License.md
3+
4+
5+
#ifndef INCLUDE_INIT_MAG_GRID_H_
6+
#define INCLUDE_INIT_MAG_GRID_H_
7+
8+
#include "aether.h"
9+
#include "planets.h"
10+
#include "grid.h"
11+
12+
bool init_dipole_grid(Grid &mGrid, Planets planet);
13+
14+
// Analytic solution to get from q,p dipole coords to r,theta
15+
// q coordinate along b-field line
16+
// p l-shell
17+
// return (r,theta)
18+
std::pair<precision_t, precision_t> qp_to_r_theta(precision_t q, precision_t p);
19+
20+
// Take limits & specs of field line, fill it with points.
21+
// std:: tuple <arma_mat, arma_mat, arma_vec> Grid::fill_field_lines (arma_vec lShells,
22+
// int64_t nAlts,
23+
// int64_t nLats,
24+
// precision_t Gamma);
25+
26+
27+
// convert mag to geographic
28+
std::vector <arma_cube> mag_to_geo(arma_cube magLon,
29+
arma_cube magLat,
30+
arma_cube magAlt,
31+
Planets planet);
32+
33+
34+
#endif // INCLUDE_INIT_GEO_GRID_H_
35+

include/inputs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Inputs {
6363
// Only needed for Mag Field grid:
6464
// min_apex (not used) and LatStretch is used
6565
// as lat = min_lat + dlat where dlat = acos(cos(lat^stretch))^(1/stretch)
66-
precision_t min_apex, LatStretch, FieldLineStretch, max_lat_dipole;
66+
precision_t min_apex, LatStretch, FieldLineStretch, max_blat;
6767

6868
// Some grid shapes allow specification of altitudes based on a file:
6969
std::string alt_file;

include/parallel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern MPI_Comm aether_comm;
3434
/**********************************************************************
3535
\brief initialize mpi and figure out ensembles and grid blocks
3636
**/
37-
bool init_parallel(Quadtree &quadtree);
37+
bool init_parallel(Quadtree &quadtree, Quadtree &quadtree_ion);
3838

3939
/**********************************************************************
4040
\brief Pack variables for message passing

include/sphere.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static const arma_mat ORIGINS = {
4141
{4.0/3.0, -0.5, 0.0},
4242
{ 0.0, 0.0, 0.0},
4343
{2.0/3.0, 0.0, 0.0},
44-
{3.0/3.0, 0.0, 0.0}
44+
{4.0/3.0, 0.0, 0.0}
4545
};
4646

4747
/// Normalized right steps in cube

share/run/UA/inputs/defaults.json

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,16 @@
8080
"AltFile" : ""},
8181

8282
"ionGrid" : {
83-
"Shape" : "sphere",
84-
"LatRange" : [-90.0, 90.0],
83+
"Shape" : "dipole",
8584
"nLatsPerBlock" : 18,
86-
"LonRange" : [0.0, 360.0],
85+
"LonRange" : [0.0, 360.0],
8786
"nLonsPerBlock" : 22,
8887
"nAlts" : 50,
8988
"MinAlt" : 80.0,
9089
"MinApex" : 120.0,
91-
"MaxAlt" : 5000.0,
9290
"LatMax":88.0,
93-
"LineSpacing":0.2,
94-
"LatStretch":6.0,
95-
"dAltkm" : 5.0,
96-
"dAltScale" : 0.25,
97-
"IsUniformAlt" : true,
98-
"AltFile" : ""},
91+
"LatStretch":1.0,
92+
"dAltStretch" : 0.6},
9993

10094
"Oblate" : {
10195
"isOblate" : false,

share/run/aether.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626
"IsUniformAlt" : false},
2727

2828
"ionGrid": {
29-
"dAltScale": 0.2,
30-
"LatStretch": 6,
29+
"dAltStretch": 0.6,
30+
"LatStretch": 1,
3131
"Shape": "dipole",
32-
"nLatsPerBlock" : 22,
33-
"nAlts":159,
32+
"nLonsPerBlock": 36,
33+
"nLatsPerBlock" : 18,
34+
"nAlts":36,
3435
"LatMax":88,
3536
"MinAlt":100.0,
3637
"MinApex":150.0

0 commit comments

Comments
 (0)