Blame view

src/ExternLib/Shue/shue_compute.hh 7.25 KB
5d3b0cd0   Hacene SI HADJ MOHAND   shue98 ok
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   shue_compute.hh
 * Author: hacene
 *
 * Created on December 31, 2020, 2:50 PM
 */

#ifndef SHUE_COMPUTE_HH
#define SHUE_COMPUTE_HH

#include "geopack.hh"

namespace AMDA {
    namespace Parameters {
        namespace Shue {
#define LMAX_VAL 2000

            class ShueCompute {
            public:

                static void initInGSM(int iyr, int iday, int ihour, int min, int isec) {
                    // We use GSM coordinate frames
                    float v_default_x = -400.0;
                    float v_default_y = 0.0;
                    float v_default_z = 0.0;

                    recalc_08_(&iyr, &iday, &ihour, &min, &isec, &v_default_x, &v_default_y, &v_default_z);
                }

                static bool shue98(float Pdyn_i, float bzIMF_i, float sat_pos_X_GSM, float sat_pos_Y_GSM, float sat_pos_Z_GSM,
                        float &x_mgnp, float &y_mgnp, float &z_mgnp, float &DIST_MGNP, int &ID_MGNP) {
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
                    /**
                   * 
                   * @param Pdyn_i SOLAR WIND RAM PRESSURE IN NANOPASCALS
                   * @param bzIMF_i IMF BZ IN NANOTESLAS
                   * @param sat_pos_X_GSM
                   * @param sat_pos_Y_GSM
                   * @param sat_pos_Z_GSM
                   * @param x_mgnp x POSITION OF THE BOUNDARY POINT
                   * @param y_mgnp y POSITION OF THE BOUNDARY POINT
                   * @param z_mgnp z POSITION OF THE BOUNDARY POINT
                   * @param DIST_MGNP DISTANCE (IN RE) BETWEEN THE OBSERVATION POINT (XGSW,YGSW,ZGSW) AND THE MODEL NAGNETOPAUSE
                   * @param ID_MGNP POSITION FLAG:  ID=+1 (-1) MEANS THAT THE OBSERVATION POINT LIES INSIDE (OUTSIDE) OF THE MODEL MAGNETOPAUSE, RESPECTIVELY.
                   * @return true of converged or false 
                   */

5d3b0cd0   Hacene SI HADJ MOHAND   shue98 ok
53
54
55
56
57
58
59
                    float vel_mgnp = -1.0;

                    shuetal_mgnp_08_(&Pdyn_i, &vel_mgnp, &bzIMF_i, &sat_pos_X_GSM, &sat_pos_Y_GSM, &sat_pos_Z_GSM,
                            &x_mgnp, &y_mgnp, &z_mgnp, &DIST_MGNP, &ID_MGNP);

                    return ID_MGNP != 0;
                }
e33c6c0b   Hacene SI HADJ MOHAND   progress
60
61
62
                
              static bool shue97(float Pdyn_i, float bzIMF_i, float sat_pos_X_GSM, float sat_pos_Y_GSM, float sat_pos_Z_GSM,
                    float &x_mgnp, float &y_mgnp, float &z_mgnp, float &DIST_MGNP, int &ID_MGNP) {
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
63
64
65
66
67
68
69
70
71
72
73
74
75
76
                  /**
                   * 
                   * @param Pdyn_i SOLAR WIND RAM PRESSURE IN NANOPASCALS
                   * @param bzIMF_i IMF BZ IN NANOTESLAS
                   * @param sat_pos_X_GSM
                   * @param sat_pos_Y_GSM
                   * @param sat_pos_Z_GSM
                   * @param x_mgnp x POSITION OF THE BOUNDARY POINT
                   * @param y_mgnp y POSITION OF THE BOUNDARY POINT
                   * @param z_mgnp z POSITION OF THE BOUNDARY POINT
                   * @param DIST_MGNP DISTANCE (IN RE) BETWEEN THE OBSERVATION POINT (XGSW,YGSW,ZGSW) AND THE MODEL NAGNETOPAUSE
                   * @param ID_MGNP POSITION FLAG:  ID=+1 (-1) MEANS THAT THE OBSERVATION POINT LIES INSIDE (OUTSIDE) OF THE MODEL MAGNETOPAUSE, RESPECTIVELY.
                   * @return true of converged or false 
                   */
e33c6c0b   Hacene SI HADJ MOHAND   progress
77
                  
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
78
79
80
81
                  float r0, r, rm, alpha;
                  float x_mt96, y_mt96, z_mt96;
                  float rho2, rho, st, ct, t, ds, dr, dt, f, gradf, gradf_t, gradf_r;
                  int ID96, nit;
e33c6c0b   Hacene SI HADJ MOHAND   progress
82
                  int iter_limit = 1000;
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
83
84
                  float eps = 1E-4;
                  float vel = -1.0;
e33c6c0b   Hacene SI HADJ MOHAND   progress
85
86
87
88
89
                  /** DEFINE THE ANGLE PHI, MEASURED DUSKWARD FROM THE NOON-MIDNIGHT MERIDIAN PLANE;
                    IF THE OBSERVATION POINT LIES ON THE X AXIS, THE ANGLE PHI CANNOT BE UNIQUELY
                    C  DEFINED, AND WE SET IT AT ZERO: **/
                  ID_MGNP = -1;
                  float phi=0.0;
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
90
                  if(sat_pos_Y_GSM != 0 || sat_pos_Z_GSM !=0 ){
e33c6c0b   Hacene SI HADJ MOHAND   progress
91
                      phi = std::atan2(sat_pos_Y_GSM, sat_pos_Z_GSM);
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
92
                  }
e33c6c0b   Hacene SI HADJ MOHAND   progress
93
94
                  /** FIRST, FIND OUT IF THE OBSERVATION POINT LIES INSIDE THE SHUE ET AL BDRY
                   AND SET THE VALUE OF THE ID FLAG: **/
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
95
96
97
                  r=std::sqrt(sat_pos_X_GSM*sat_pos_X_GSM + sat_pos_Y_GSM*sat_pos_Y_GSM +  sat_pos_Z_GSM*sat_pos_Z_GSM);
                  if(bzIMF_i >=0){
                      r0 = (11.4 + 0.013*bzIMF_i)*std::pow(Pdyn_i, -1/6.6);
e33c6c0b   Hacene SI HADJ MOHAND   progress
98
                  }else{
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
99
                      r0  = (11.4 + 0.14*bzIMF_i)*std::pow(Pdyn_i, -1/6.6);
e33c6c0b   Hacene SI HADJ MOHAND   progress
100
101
102
103
                  }
                  alpha= (0.58 -0.010*bzIMF_i)*(1 + 0.010*Pdyn_i);
                  rm = r0*std::pow((2./(1.0 + sat_pos_X_GSM/r)),alpha);
                  if(r<rm)
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
104
                      ID_MGNP =1;
e33c6c0b   Hacene SI HADJ MOHAND   progress
105
106
107
108
109
                  /**
                    NOW, FIND THE CORRESPONDING T96 MAGNETOPAUSE POSITION, TO BE USED AS
                    A STARTING APPROXIMATION IN THE SEARCH OF A CORRESPONDING SHUE ET AL.
                    BOUNDARY POINT: 
                   */
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
110
111
                  t96_mgnp_08_(&Pdyn_i, &vel, &sat_pos_X_GSM, &sat_pos_Y_GSM, &sat_pos_Z_GSM,
                                &x_mt96, &y_mt96, &z_mt96, &DIST_MGNP, &ID96);
e33c6c0b   Hacene SI HADJ MOHAND   progress
112
                  
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
113
114
                  rho2 = y_mt96*y_mt96 + z_mt96*z_mt96;
                  r = std::sqrt(rho2 + x_mt96*x_mt96);
e33c6c0b   Hacene SI HADJ MOHAND   progress
115
                  st = std::sqrt(rho2)/r;
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
116
                  ct = x_mt96/r;
e33c6c0b   Hacene SI HADJ MOHAND   progress
117
118
119
120
121
                  
                  /*NOW, USE NEWTON'S ITERATIVE METHOD TO FIND THE NEAREST POINT AT THE
                      SHUE ET AL.'S BOUNDARY:
                   **/
                  nit = 0;
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
122
123
124
125
126
127
128
                  ds = 1000.0;
                  bool converged = true;
                  while(ds > eps){
                      if(nit >  iter_limit){
                          converged = false;
                          break; 
                      }
e33c6c0b   Hacene SI HADJ MOHAND   progress
129
130
131
                  t = std::atan2(st,ct);
                  rm = r0*std::pow((2.0/(1.0 + ct)),alpha);
                  
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
132
133
134
135
                  f = r -rm;                  
                  gradf_r = 1.0;
                  gradf_t = -alpha/r*rm*st/(1.0+ct);
                  gradf=std::sqrt(gradf_r*gradf_r + gradf_t*gradf_t);
e33c6c0b   Hacene SI HADJ MOHAND   progress
136
                  
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
137
138
                  dr = -f/(gradf*gradf);
                  dt = dr/r*gradf_t;
e33c6c0b   Hacene SI HADJ MOHAND   progress
139
                  
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
140
141
142
143
                  r = r + dr;                  
                  t = t +dt;
                  st = sin(t);
                  ct = cos(t);
e33c6c0b   Hacene SI HADJ MOHAND   progress
144
                  
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
145
146
147
148
149
150
151
152
153
154
155
                  ds= std::sqrt(dr*dr + (r*dt)*(r*dt));  
                  nit += 1;
                  }
                  if (converged){
                      x_mgnp = r*std::cos(t);
                      rho = r*std::sin(t);
                      y_mgnp = rho*sin(phi);
                      z_mgnp = rho*cos(phi);
                      DIST_MGNP = std::sqrt((sat_pos_X_GSM -x_mgnp)*(sat_pos_X_GSM -x_mgnp) + 
                              (sat_pos_Y_GSM -y_mgnp)*(sat_pos_Y_GSM -y_mgnp)  +
                              (sat_pos_Z_GSM -z_mgnp)*(sat_pos_Z_GSM -z_mgnp) );
e33c6c0b   Hacene SI HADJ MOHAND   progress
156
157
                  }
                  
2cae24f0   Hacene SI HADJ MOHAND   shue 97 ok
158
                    return converged;
e33c6c0b   Hacene SI HADJ MOHAND   progress
159
160
                }
                
5d3b0cd0   Hacene SI HADJ MOHAND   shue98 ok
161
            };
e33c6c0b   Hacene SI HADJ MOHAND   progress
162
163
            
            
5d3b0cd0   Hacene SI HADJ MOHAND   shue98 ok
164
165
166
167
168
169
170
        }

    }
}


#endif /* SHUE_COMPUTE_HH */