diff --git a/simgear/magvar/coremag.cxx b/simgear/magvar/coremag.cxx index 36fe0c89..4102c387 100644 --- a/simgear/magvar/coremag.cxx +++ b/simgear/magvar/coremag.cxx @@ -51,6 +51,20 @@ // 18/06/2015 Jean-Paul Anceaux -- j.p.r.anceaux@gmail.com +// Updated coefficient arrays to use the current WMM2020 model, +// (valid between 2020.0 and 2025.0) +// Also removed unused variables and corrected earth radii constants +// to the values for WGS84 and WMM2015. +// Reference: +// A. Chulliat , S. Macmillan, P. Alken, C. Beggan, M. +// Nair, B. Hamilton, A. Woods, V. Ridley, +// S Maus, and A Thomson, December 2014, The +// US/UK World Magnetic Model for 2020-2025, +// NOAA Technical Report WMM2020_Report.pdf +// +// 23/06/2020 Jean-Paul Anceaux -- j.p.r.anceaux@gmail.com + + // The routine uses a spherical harmonic expansion of the magnetic // potential up to twelfth order, together with its time variation, as // described in Chapter 4 of "Geomagnetism, Vol 1, Ed. J.A.Jacobs, @@ -104,72 +118,73 @@ static const double a = 6378.137; /* semi-major axis (equatorial radius) o static const double b = 6356.7523142; /* semi-minor axis referenced to the WGS84 ellipsoid */ static const double r_0 = 6371.2; /* standard Earth magnetic reference radius */ -static double gnm_wmm2015[13][13] = +static double gnm_wmm2020[13][13] = { {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {-29438.5, -1501.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {-2445.3, 3012.5, 1676.6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {1351.1, -2352.3, 1225.6, 581.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {907.2, 813.7, 120.3, -335.0, 70.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {-232.6, 360.1, 192.4, -141.0, -157.4, 4.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {69.5, 67.4, 72.8, -129.8, -29.0, 13.2, -70.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {81.6, -76.1, -6.8, 51.9, 15.0, 9.3, -2.8, 6.7, 0.0, 0.0, 0.0, 0.0, 0.0}, - {24.0, 8.6, -16.9, -3.2, -20.6, 13.3, 11.7, -16.0, -2.0, 0.0, 0.0, 0.0, 0.0}, - {5.4, 8.8, 3.1, -3.1, 0.6, -13.3, -0.1, 8.7, -9.1, -10.5, 0.0, 0.0, 0.0}, - {-1.9, -6.5, 0.2, 0.6, -0.6, 1.7, -0.7, 2.1, 2.3, -1.8, -3.6, 0.0, 0.0}, - {3.1, -1.5, -2.3, 2.1, -0.9, 0.6, -0.7, 0.2, 1.7, -0.2, 0.4, 3.5, 0.0}, - {-2.0, -0.3, 0.4, 1.3, -0.9, 0.9, 0.1, 0.5, -0.4, -0.4, 0.2, -0.9, 0.0}, + {-29404.5, -1450.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0}, + {-2500.0, 2982.0, 1676.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0}, + {1363.9, -2381.0, 1236.2, 525.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0}, + {903.1, 809.4, 86.2, -309.4, 47.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0}, + {-234.4, 363.1, 187.8, -140.7, -151.2, 13.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0}, + {65.9, 65.6, 73.0, -121.5, -36.2, 13.5, -64.7, 0.0, 0.0, 0.0, 0.0, 0.0, 0}, + {80.6, -76.8, -8.3, 56.5, 15.8, 6.4, -7.2, 9.8, 0.0, 0.0, 0.0, 0.0, 0}, + {23.6, 9.8, -17.5, -0.4, -21.1, 15.3, 13.7, -16.5, -0.3, 0.0, 0.0, 0.0, 0}, + {5.0, 8.2, 2.9, -1.4, -1.1, -13.3, 1.1, 8.9, -9.3, -11.9, 0.0, 0.0, 0}, + {-1.9, -6.2, -0.1, 1.7, -0.9, 0.6, -0.9, 1.9, 1.4, -2.4, -3.9, 0.0, 0}, + {3.0, -1.4, -2.5, 2.4, -0.9, 0.3, -0.7, -0.1, 1.4, -0.6, 0.2, 3.1, 0}, + {-2.0, -0.1, 0.5, 1.3, -1.2, 0.7, 0.3, 0.5, -0.2, -0.5, 0.1, -1.1, -0.3}, }; -static double hnm_wmm2015[13][13]= +static double hnm_wmm2020[13][13]= { {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, 4796.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, -2845.6, -642.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, -115.3, 245.0, -538.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, 283.4, -188.6, 180.9, -329.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, 47.4, 196.9, -119.4, 16.1, 100.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, -20.7, 33.2, 58.8, -66.5, 7.3, 62.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, -54.1, -19.4, 5.6, 24.4, 3.3, -27.5, -2.3, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, 10.2, -18.1, 13.2, -14.6, 16.2, 5.7, -9.1, 2.2, 0.0, 0.0, 0.0, 0.0}, - {0.0, -21.6, 10.8, 11.7, -6.8, -6.9, 7.8, 1.0, -3.9, 8.5, 0.0, 0.0, 0.0}, - {0.0, 3.3, -0.3, 4.6, 4.4, -7.9, -0.6, -4.1, -2.8, -1.1, -8.7, 0.0, 0.0}, - {0.0, -0.1, 2.1, -0.7, -1.1, 0.7, -0.2, -2.1, -1.5, -2.5, -2.0, -2.3, 0.0}, - {0.0, -1.0, 0.5, 1.8, -2.2, 0.3, 0.7, -0.1, 0.3, 0.2, -0.9, -0.2, 0.7}, + {0.0, 4652.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {0.0, -2991.6, -734.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {0.0, -82.2, 241.8, -542.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {0.0, 282.0, -158.4, 199.8, -350.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {0.0, 47.7, 208.4, -121.3, 32.2, 99.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {0.0, -19.1, 25.0, 52.7, -64.4, 9.0, 68.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {0.0, -51.4, -16.8, 2.3, 23.5, -2.2, -27.2, -1.9, 0.0, 0.0, 0.0, 0.0, 0.0}, + {0.0, 8.4, -15.3, 12.8, -11.8, 14.9, 3.6, -6.9, 2.8, 0.0, 0.0, 0.0, 0.0}, + {0.0, -23.3, 11.1, 9.8, -5.1, -6.2, 7.8, 0.4, -1.5, 9.7, 0.0, 0.0, 0.0}, + {0.0, 3.4, -0.2, 3.5, 4.8, -8.6, -0.1, -4.2, -3.4, -0.1, -8.8, 0.0, 0.0}, + {0.0, -0.0, 2.6, -0.5, -0.4, 0.6, -0.2, -1.7, -1.6, -3.0, -2.0, -2.6, 0.0}, + {0.0, -1.2, 0.5, 1.3, -1.8, 0.1, 0.7, -0.1, 0.6, 0.2, -0.9, -0.0, 0.5}, }; -static double gtnm_wmm2015[13][13]= +static double gtnm_wmm2020[13][13]= { {0.0, 0.0, 0.0, 0.0, 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 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {-1.1, -1.6, -6.0, 5.4, -5.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {-0.3, 0.6, -0.7, 0.1, 1.2, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {-0.6, -0.4, 0.5, 1.4, -1.4, -0.0, 0.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {-0.1, -0.3, -0.1, 0.7, 0.2, -0.5, -0.8, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, + {-0.1, 0.1, -0.1, 0.5, -0.1, 0.4, 0.5, 0.0, 0.4, 0.0, 0.0, 0.0, 0.0}, + {-0.1, -0.2, -0.0, 0.4, -0.3, -0.0, 0.3, -0.0, -0.0, -0.4, 0.0, 0.0, 0.0}, + {0.0, -0.0, -0.0, 0.2, -0.1, -0.2, -0.0, -0.1, -0.2, -0.1, -0.0, 0.0, 0.0}, + {-0.0, -0.1, -0.0, 0.0, -0.0, -0.1, 0.0, -0.0, -0.1, -0.1, -0.1, -0.1, 0.0}, + {0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, 0.0, -0.0, -0.0, -0.0, -0.1}, }; -static double htnm_wmm2015[13][13]= +static double htnm_wmm2020[13][13]= { {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, -26.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, -27.1, -13.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, 8.4, -0.4, 2.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, -0.6, 5.3, 3.0, -5.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, - {0.0, 0.4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3, -0.5, 0.4, 0.1, 0.0, 0.0, 0.0, 0.0}, + {0.0, -0.3, 0.2, -0.4, 0.4, 0.1, -0.0, -0.2, 0.5, 0.2, 0.0, 0.0, 0.0}, + {0.0, -0.0, 0.1, -0.3, 0.1, -0.2, 0.1, -0.0, -0.1, 0.2, -0.0, 0.0, 0.0}, + {0.0, -0.0, 0.1, 0.0, 0.2, -0.0, 0.0, 0.1, -0.0, -0.1, 0.0, -0.0, 0.0}, + {0.0, -0.0, 0.0, -0.1, 0.1, -0.0, 0.0, -0.0, 0.1, -0.0, -0.0, 0.0, -0.1}, + }; static const int nmax = 12; @@ -210,7 +225,7 @@ double calc_magvar( double lat, double lon, double h, long dat, double* field ) /* output field B_r,B_th,B_phi,B_x,B_y,B_z */ int n,m; /* reference date for current model is 1 januari 2015 */ - long date0_wmm2015 = yymmdd_to_julian_days(15,1,1); + long date0_wmm2020 = yymmdd_to_julian_days(15,1,1); double yearfrac,sr,r,theta,c,s,psi,fn,fn_0,B_r,B_theta,B_phi,X,Y,Z; double sinpsi, cospsi, inv_s; @@ -297,12 +312,12 @@ double calc_magvar( double lat, double lon, double h, long dat, double* field ) /* compute Gauss coefficients gnm and hnm of degree n and order m for the desired time achieved by adjusting the coefficients at time t0 for linear secular variation */ - /* WMM2015 */ - yearfrac = (dat - date0_wmm2015) / 365.25; + /* WMM2020 */ + yearfrac = (dat - date0_wmm2020) / 365.25; for ( n = 1; n <= nmax; n++ ) { for ( m = 0; m <= nmax; m++ ) { - gnm[n][m] = gnm_wmm2015[n][m] + yearfrac * gtnm_wmm2015[n][m]; - hnm[n][m] = hnm_wmm2015[n][m] + yearfrac * htnm_wmm2015[n][m]; + gnm[n][m] = gnm_wmm2020[n][m] + yearfrac * gtnm_wmm2020[n][m]; + hnm[n][m] = hnm_wmm2020[n][m] + yearfrac * htnm_wmm2020[n][m]; } } @@ -364,7 +379,7 @@ double SGMagVarOrig( double lat, double lon, double h, long dat, double* field ) /* output field B_r,B_th,B_phi,B_x,B_y,B_z */ int n,m; /* reference dates */ - long date0_wmm2015 = yymmdd_to_julian_days(5,1,1); + long date0_wmm2020 = yymmdd_to_julian_days(5,1,1); double yearfrac,sr,r,theta,c,s,psi,fn,B_r,B_theta,B_phi,X,Y,Z; @@ -421,12 +436,12 @@ double SGMagVarOrig( double lat, double lon, double h, long dat, double* field ) } /* compute gnm, hnm at dat */ - /* WMM2015 */ - yearfrac = (dat - date0_wmm2015) / 365.25; + /* WMM2020 */ + yearfrac = (dat - date0_wmm2020) / 365.25; for ( n = 1; n <= nmax; n++ ) { for ( m = 0; m <= nmax; m++ ) { - gnm[n][m] = gnm_wmm2015[n][m] + yearfrac * gtnm_wmm2015[n][m]; - hnm[n][m] = hnm_wmm2015[n][m] + yearfrac * htnm_wmm2015[n][m]; + gnm[n][m] = gnm_wmm2020[n][m] + yearfrac * gtnm_wmm2020[n][m]; + hnm[n][m] = hnm_wmm2020[n][m] + yearfrac * htnm_wmm2020[n][m]; } }