5
5
6
6
7
7
// -----------------------------------------------------------------------------
8
- // Call (fortran) ionospheric electrodynamics if we enable this
8
+ // Call (fortran) ionospheric electrodynamics if we enable this
9
9
// in the cmake file
10
10
// -----------------------------------------------------------------------------
11
11
@@ -27,36 +27,40 @@ Electrodynamics::Electrodynamics(Times time) {
27
27
HaveFortranIe = false ;
28
28
isSet = false ;
29
29
30
- #ifdef FORTRAN
31
- // Initialize IE components (reading in the data files):
32
- std::string ieDir = input.get_electrodynamics_dir ();
33
- int * ieDir_iArray = copy_string_to_int (ieDir);
34
- std::string efield = input.get_potential_model ();
35
- std::string aurora = input.get_diffuse_auroral_model ();
30
+ #ifdef FORTRAN
31
+ // Initialize IE components (reading in the data files):
32
+ std::string ieDir = input.get_electrodynamics_dir ();
33
+ int * ieDir_iArray = copy_string_to_int (ieDir);
34
+ std::string efield = input.get_potential_model ();
35
+ std::string aurora = input.get_diffuse_auroral_model ();
36
36
37
- if (efield.length () == 0 & aurora.length () == 0 ) {
38
- HaveFortranIe = false ;
37
+ if (efield.length () == 0 & aurora.length () == 0 )
38
+ HaveFortranIe = false ;
39
+
40
+ else {
41
+ int * efield_iArray = copy_string_to_int (efield);
42
+ int * aurora_iArray = copy_string_to_int (aurora);
43
+ ie_init_library (ieDir_iArray, efield_iArray, aurora_iArray, &iError);
44
+
45
+ if (iError > 0 ) {
46
+ report.print (0 , " Error in setting fortran IE!" );
47
+ IsOk = false ;
39
48
} else {
40
- int * efield_iArray = copy_string_to_int (efield);
41
- int * aurora_iArray = copy_string_to_int (aurora);
42
- ie_init_library (ieDir_iArray, efield_iArray, aurora_iArray, &iError);
43
- if (iError > 0 ) {
44
- report.print (0 ," Error in setting fortran IE!" );
45
- IsOk = false ;
46
- } else {
47
- HaveFortranIe = true ;
48
- isSet = true ;
49
- }
49
+ HaveFortranIe = true ;
50
+ isSet = true ;
50
51
}
51
- isCompiled = true ;
52
- #else
53
- isCompiled = false ;
54
- #endif
52
+ }
53
+
54
+ isCompiled = true ;
55
+ #else
56
+ isCompiled = false ;
57
+ #endif
55
58
56
59
// If we don't set IE through Fortran, then try to set it through a file:
57
60
58
61
if (!HaveFortranIe) {
59
62
std::string electrodynamics_file = input.get_electrodynamics_file ();
63
+
60
64
if (electrodynamics_file.length () > 0 &
61
65
electrodynamics_file != " none" ) {
62
66
// This function sets HaveElectrodynamicsFile = true.
@@ -83,7 +87,7 @@ Electrodynamics::Electrodynamics(Times time) {
83
87
// -----------------------------------------------------------------------------
84
88
85
89
void Electrodynamics::set_all_indices_for_ie (Times time,
86
- Indices &indices) {
90
+ Indices &indices) {
87
91
std::string function = " Electrodynamics::set_all_indices_for_ie" ;
88
92
static int iFunction = -1 ;
89
93
report.enter (function, iFunction);
@@ -111,17 +115,18 @@ void Electrodynamics::set_all_indices_for_ie(Times time,
111
115
std::cout << " sw v : " << iVx_ << " " << swv << " \n " ;
112
116
std::cout << " sw n : " << iN_ << " " << swn << " \n " ;
113
117
}
114
- #ifdef FORTRAN
115
- ie_set_time (&time_now);
116
- ie_set_imfby (&imfby);
117
- ie_set_imfbz (&imfbz);
118
- ie_set_swv (&swv);
119
- ie_set_swn (&swn);
120
- ie_set_ae (&ae);
121
- ie_set_au (&au);
122
- ie_set_al (&al);
123
- ie_set_hp_from_ae (&ae);
124
- #endif
118
+
119
+ #ifdef FORTRAN
120
+ ie_set_time (&time_now);
121
+ ie_set_imfby (&imfby);
122
+ ie_set_imfbz (&imfbz);
123
+ ie_set_swv (&swv);
124
+ ie_set_swn (&swn);
125
+ ie_set_ae (&ae);
126
+ ie_set_au (&au);
127
+ ie_set_al (&al);
128
+ ie_set_hp_from_ae (&ae);
129
+ #endif
125
130
126
131
report.exit (function);
127
132
return ;
@@ -154,60 +159,62 @@ bool Electrodynamics::update(Planets planet,
154
159
ions.eflux .zeros ();
155
160
ions.avee .ones ();
156
161
157
- #ifdef FORTRAN
158
- if (HaveFortranIe) {
159
- report.print (3 , " Using Fortran Electrodynamics!" );
160
- set_all_indices_for_ie (time, indices);
161
-
162
- if (!IsAllocated) {
163
- int nXs = gGrid .get_nX ();
164
- ie_set_nxs (&nXs);
165
- int nYs = gGrid .get_nY ();
166
- ie_set_nys (&nYs);
167
- int64_t iTotal = nXs * nYs;
168
- mlt2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
169
- lat2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
170
- pot2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
171
- eflux2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
172
- avee2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
173
- IsAllocated = true ;
174
- }
162
+ #ifdef FORTRAN
163
+
164
+ if (HaveFortranIe) {
165
+ report.print (3 , " Using Fortran Electrodynamics!" );
166
+ set_all_indices_for_ie (time, indices);
167
+
168
+ if (!IsAllocated) {
169
+ int nXs = gGrid .get_nX ();
170
+ ie_set_nxs (&nXs);
171
+ int nYs = gGrid .get_nY ();
172
+ ie_set_nys (&nYs);
173
+ int64_t iTotal = nXs * nYs;
174
+ mlt2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
175
+ lat2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
176
+ pot2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
177
+ eflux2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
178
+ avee2d = static_cast <float *>(malloc (iTotal * sizeof (float )));
179
+ IsAllocated = true ;
180
+ }
175
181
176
- int64_t nZs = gGrid .get_nZ ();
177
- int64_t iZ;
182
+ int64_t nZs = gGrid .get_nZ ();
183
+ int64_t iZ;
178
184
179
- int iError;
185
+ int iError;
180
186
181
- for (iZ = 0 ; iZ < nZs; iZ++) {
182
- copy_mat_to_array (gGrid .magLocalTime_scgc .slice (iZ), mlt2d, true );
183
- copy_mat_to_array (gGrid .magLat_scgc .slice (iZ), lat2d, true );
187
+ for (iZ = 0 ; iZ < nZs; iZ++) {
188
+ copy_mat_to_array (gGrid .magLocalTime_scgc .slice (iZ), mlt2d, true );
189
+ copy_mat_to_array (gGrid .magLat_scgc .slice (iZ), lat2d, true );
184
190
185
- ie_set_mlts (mlt2d, &iError);
186
- ie_set_lats (lat2d, &iError);
187
- ie_update_grid (&iError);
191
+ ie_set_mlts (mlt2d, &iError);
192
+ ie_set_lats (lat2d, &iError);
193
+ ie_update_grid (&iError);
188
194
189
- ie_get_potential (pot2d, &iError);
190
- copy_array_to_mat (pot2d, ions.potential_scgc .slice (iZ), true );
195
+ ie_get_potential (pot2d, &iError);
196
+ copy_array_to_mat (pot2d, ions.potential_scgc .slice (iZ), true );
191
197
192
- if (iZ == nZs-1 ) {
193
- ie_get_electron_diffuse_aurora (eflux2d, avee2d, &iError);
194
- copy_array_to_mat (avee2d, ions.avee , true );
195
- copy_array_to_mat (eflux2d, ions.eflux , true );
196
- }
198
+ if (iZ == nZs - 1 ) {
199
+ ie_get_electron_diffuse_aurora (eflux2d, avee2d, &iError);
200
+ copy_array_to_mat (avee2d, ions.avee , true );
201
+ copy_array_to_mat (eflux2d, ions.eflux , true );
197
202
}
198
203
}
199
- #endif
204
+ }
205
+
206
+ #endif
200
207
201
208
if (HaveElectrodynamicsFile) {
202
209
report.print (3 , " Setting electrodynamics from file!" );
203
210
auto electrodynamics_values =
204
211
get_electrodynamics (gGrid .magLat_scgc ,
205
- gGrid .magLocalTime_scgc );
212
+ gGrid .magLocalTime_scgc );
206
213
ions.potential_scgc = std::get<0 >(electrodynamics_values);
207
214
ions.eflux = std::get<1 >(electrodynamics_values);
208
215
ions.avee = std::get<2 >(electrodynamics_values);
209
216
}
210
- }
217
+ }
211
218
212
219
report.exit (function);
213
220
return true ;
0 commit comments