source: ntrip/trunk/BNC/src/pppModel.cpp@ 7636

Last change on this file since 7636 was 7259, checked in by stuerze, 9 years ago

small fix in the conversion from vtec to stec

File size: 15.0 KB
Line 
1
2// Part of BNC, a utility for retrieving decoding and
3// converting GNSS data streams from NTRIP broadcasters.
4//
5// Copyright (C) 2007
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://www.bkg.bund.de
8// Czech Technical University Prague, Department of Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26/* -------------------------------------------------------------------------
27 * BKG NTRIP Client
28 * -------------------------------------------------------------------------
29 *
30 * Class: t_astro, t_tides, t_tropo
31 *
32 * Purpose: Observation model
33 *
34 * Author: L. Mervart
35 *
36 * Created: 29-Jul-2014
37 *
38 * Changes:
39 *
40 * -----------------------------------------------------------------------*/
41
42
43#include <cmath>
44
45#include "pppModel.h"
46
47using namespace BNC_PPP;
48using namespace std;
49
50const double t_astro::RHO_DEG = 180.0 / M_PI;
51const double t_astro::RHO_SEC = 3600.0 * 180.0 / M_PI;
52const double t_astro::MJD_J2000 = 51544.5;
53
54Matrix t_astro::rotX(double Angle) {
55 const double C = cos(Angle);
56 const double S = sin(Angle);
57 Matrix UU(3,3);
58 UU[0][0] = 1.0; UU[0][1] = 0.0; UU[0][2] = 0.0;
59 UU[1][0] = 0.0; UU[1][1] = +C; UU[1][2] = +S;
60 UU[2][0] = 0.0; UU[2][1] = -S; UU[2][2] = +C;
61 return UU;
62}
63
64Matrix t_astro::rotY(double Angle) {
65 const double C = cos(Angle);
66 const double S = sin(Angle);
67 Matrix UU(3,3);
68 UU[0][0] = +C; UU[0][1] = 0.0; UU[0][2] = -S;
69 UU[1][0] = 0.0; UU[1][1] = 1.0; UU[1][2] = 0.0;
70 UU[2][0] = +S; UU[2][1] = 0.0; UU[2][2] = +C;
71 return UU;
72}
73
74Matrix t_astro::rotZ(double Angle) {
75 const double C = cos(Angle);
76 const double S = sin(Angle);
77 Matrix UU(3,3);
78 UU[0][0] = +C; UU[0][1] = +S; UU[0][2] = 0.0;
79 UU[1][0] = -S; UU[1][1] = +C; UU[1][2] = 0.0;
80 UU[2][0] = 0.0; UU[2][1] = 0.0; UU[2][2] = 1.0;
81 return UU;
82}
83
84// Greenwich Mean Sidereal Time
85///////////////////////////////////////////////////////////////////////////
86double t_astro::GMST(double Mjd_UT1) {
87
88 const double Secs = 86400.0;
89
90 double Mjd_0 = floor(Mjd_UT1);
91 double UT1 = Secs*(Mjd_UT1-Mjd_0);
92 double T_0 = (Mjd_0 -MJD_J2000)/36525.0;
93 double T = (Mjd_UT1-MJD_J2000)/36525.0;
94
95 double gmst = 24110.54841 + 8640184.812866*T_0 + 1.002737909350795*UT1
96 + (0.093104-6.2e-6*T)*T*T;
97
98 return 2.0*M_PI*Frac(gmst/Secs);
99}
100
101// Nutation Matrix
102///////////////////////////////////////////////////////////////////////////
103Matrix t_astro::NutMatrix(double Mjd_TT) {
104
105 const double T = (Mjd_TT-MJD_J2000)/36525.0;
106
107 double ls = 2.0*M_PI*Frac(0.993133+ 99.997306*T);
108 double D = 2.0*M_PI*Frac(0.827362+1236.853087*T);
109 double F = 2.0*M_PI*Frac(0.259089+1342.227826*T);
110 double N = 2.0*M_PI*Frac(0.347346- 5.372447*T);
111
112 double dpsi = ( -17.200*sin(N) - 1.319*sin(2*(F-D+N)) - 0.227*sin(2*(F+N))
113 + 0.206*sin(2*N) + 0.143*sin(ls) ) / RHO_SEC;
114 double deps = ( + 9.203*cos(N) + 0.574*cos(2*(F-D+N)) + 0.098*cos(2*(F+N))
115 - 0.090*cos(2*N) ) / RHO_SEC;
116
117 double eps = 0.4090928-2.2696E-4*T;
118
119 return rotX(-eps-deps)*rotZ(-dpsi)*rotX(+eps);
120}
121
122// Precession Matrix
123///////////////////////////////////////////////////////////////////////////
124Matrix t_astro::PrecMatrix(double Mjd_1, double Mjd_2) {
125
126 const double T = (Mjd_1-MJD_J2000)/36525.0;
127 const double dT = (Mjd_2-Mjd_1)/36525.0;
128
129 double zeta = ( (2306.2181+(1.39656-0.000139*T)*T)+
130 ((0.30188-0.000344*T)+0.017998*dT)*dT )*dT/RHO_SEC;
131 double z = zeta + ( (0.79280+0.000411*T)+0.000205*dT)*dT*dT/RHO_SEC;
132 double theta = ( (2004.3109-(0.85330+0.000217*T)*T)-
133 ((0.42665+0.000217*T)+0.041833*dT)*dT )*dT/RHO_SEC;
134
135 return rotZ(-z) * rotY(theta) * rotZ(-zeta);
136}
137
138// Sun's position
139///////////////////////////////////////////////////////////////////////////
140ColumnVector t_astro::Sun(double Mjd_TT) {
141
142 const double eps = 23.43929111/RHO_DEG;
143 const double T = (Mjd_TT-MJD_J2000)/36525.0;
144
145 double M = 2.0*M_PI * Frac ( 0.9931267 + 99.9973583*T);
146 double L = 2.0*M_PI * Frac ( 0.7859444 + M/2.0/M_PI +
147 (6892.0*sin(M)+72.0*sin(2.0*M)) / 1296.0e3);
148 double r = 149.619e9 - 2.499e9*cos(M) - 0.021e9*cos(2*M);
149
150 ColumnVector r_Sun(3);
151 r_Sun << r*cos(L) << r*sin(L) << 0.0; r_Sun = rotX(-eps) * r_Sun;
152
153 return rotZ(GMST(Mjd_TT))
154 * NutMatrix(Mjd_TT)
155 * PrecMatrix(MJD_J2000, Mjd_TT)
156 * r_Sun;
157}
158
159// Moon's position
160///////////////////////////////////////////////////////////////////////////
161ColumnVector t_astro::Moon(double Mjd_TT) {
162
163 const double eps = 23.43929111/RHO_DEG;
164 const double T = (Mjd_TT-MJD_J2000)/36525.0;
165
166 double L_0 = Frac ( 0.606433 + 1336.851344*T );
167 double l = 2.0*M_PI*Frac ( 0.374897 + 1325.552410*T );
168 double lp = 2.0*M_PI*Frac ( 0.993133 + 99.997361*T );
169 double D = 2.0*M_PI*Frac ( 0.827361 + 1236.853086*T );
170 double F = 2.0*M_PI*Frac ( 0.259086 + 1342.227825*T );
171
172 double dL = +22640*sin(l) - 4586*sin(l-2*D) + 2370*sin(2*D) + 769*sin(2*l)
173 -668*sin(lp) - 412*sin(2*F) - 212*sin(2*l-2*D)- 206*sin(l+lp-2*D)
174 +192*sin(l+2*D) - 165*sin(lp-2*D) - 125*sin(D) - 110*sin(l+lp)
175 +148*sin(l-lp) - 55*sin(2*F-2*D);
176
177 double L = 2.0*M_PI * Frac( L_0 + dL/1296.0e3 );
178
179 double S = F + (dL+412*sin(2*F)+541*sin(lp)) / RHO_SEC;
180 double h = F-2*D;
181 double N = -526*sin(h) + 44*sin(l+h) - 31*sin(-l+h) - 23*sin(lp+h)
182 +11*sin(-lp+h) - 25*sin(-2*l+F) + 21*sin(-l+F);
183
184 double B = ( 18520.0*sin(S) + N ) / RHO_SEC;
185
186 double cosB = cos(B);
187
188 double R = 385000e3 - 20905e3*cos(l) - 3699e3*cos(2*D-l) - 2956e3*cos(2*D)
189 -570e3*cos(2*l) + 246e3*cos(2*l-2*D) - 205e3*cos(lp-2*D)
190 -171e3*cos(l+2*D) - 152e3*cos(l+lp-2*D);
191
192 ColumnVector r_Moon(3);
193 r_Moon << R*cos(L)*cosB << R*sin(L)*cosB << R*sin(B);
194 r_Moon = rotX(-eps) * r_Moon;
195
196 return rotZ(GMST(Mjd_TT))
197 * NutMatrix(Mjd_TT)
198 * PrecMatrix(MJD_J2000, Mjd_TT)
199 * r_Moon;
200}
201
202// Tidal Correction
203////////////////////////////////////////////////////////////////////////////
204ColumnVector t_tides::displacement(const bncTime& time, const ColumnVector& xyz) {
205
206 if (time.undef()) {
207 ColumnVector dX(3); dX = 0.0;
208 return dX;
209 }
210
211 double Mjd = time.mjd() + time.daysec() / 86400.0;
212
213 if (Mjd != _lastMjd) {
214 _lastMjd = Mjd;
215 _xSun = t_astro::Sun(Mjd);
216 _rSun = sqrt(DotProduct(_xSun,_xSun));
217 _xSun /= _rSun;
218 _xMoon = t_astro::Moon(Mjd);
219 _rMoon = sqrt(DotProduct(_xMoon,_xMoon));
220 _xMoon /= _rMoon;
221 }
222
223 double rRec = sqrt(DotProduct(xyz, xyz));
224 ColumnVector xyzUnit = xyz / rRec;
225
226 // Love's Numbers
227 // --------------
228 const double H2 = 0.6078;
229 const double L2 = 0.0847;
230
231 // Tidal Displacement
232 // ------------------
233 double scSun = DotProduct(xyzUnit, _xSun);
234 double scMoon = DotProduct(xyzUnit, _xMoon);
235
236 double p2Sun = 3.0 * (H2/2.0-L2) * scSun * scSun - H2/2.0;
237 double p2Moon = 3.0 * (H2/2.0-L2) * scMoon * scMoon - H2/2.0;
238
239 double x2Sun = 3.0 * L2 * scSun;
240 double x2Moon = 3.0 * L2 * scMoon;
241
242 const double gmWGS = 398.6005e12;
243 const double gms = 1.3271250e20;
244 const double gmm = 4.9027890e12;
245
246 double facSun = gms / gmWGS *
247 (rRec * rRec * rRec * rRec) / (_rSun * _rSun * _rSun);
248
249 double facMoon = gmm / gmWGS *
250 (rRec * rRec * rRec * rRec) / (_rMoon * _rMoon * _rMoon);
251
252 ColumnVector dX = facSun * (x2Sun * _xSun + p2Sun * xyzUnit) +
253 facMoon * (x2Moon * _xMoon + p2Moon * xyzUnit);
254
255 return dX;
256}
257
258// Constructor
259///////////////////////////////////////////////////////////////////////////
260t_windUp::t_windUp() {
261 for (unsigned ii = 0; ii <= t_prn::MAXPRN; ii++) {
262 sumWind[ii] = 0.0;
263 lastEtime[ii] = 0.0;
264 }
265}
266
267// Phase Wind-Up Correction
268///////////////////////////////////////////////////////////////////////////
269double t_windUp::value(const bncTime& etime, const ColumnVector& rRec,
270 t_prn prn, const ColumnVector& rSat) {
271
272 if (etime.mjddec() != lastEtime[prn.toInt()]) {
273
274 // Unit Vector GPS Satellite --> Receiver
275 // --------------------------------------
276 ColumnVector rho = rRec - rSat;
277 rho /= rho.norm_Frobenius();
278
279 // GPS Satellite unit Vectors sz, sy, sx
280 // -------------------------------------
281 ColumnVector sz = -rSat / rSat.norm_Frobenius();
282
283 ColumnVector xSun = t_astro::Sun(etime.mjddec());
284 xSun /= xSun.norm_Frobenius();
285
286 ColumnVector sy = crossproduct(sz, xSun);
287 ColumnVector sx = crossproduct(sy, sz);
288
289 // Effective Dipole of the GPS Satellite Antenna
290 // ---------------------------------------------
291 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
292 - crossproduct(rho, sy);
293
294 // Receiver unit Vectors rx, ry
295 // ----------------------------
296 ColumnVector rx(3);
297 ColumnVector ry(3);
298
299 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
300 double neu[3];
301
302 neu[0] = 1.0;
303 neu[1] = 0.0;
304 neu[2] = 0.0;
305 neu2xyz(recEll, neu, rx.data());
306
307 neu[0] = 0.0;
308 neu[1] = -1.0;
309 neu[2] = 0.0;
310 neu2xyz(recEll, neu, ry.data());
311
312 // Effective Dipole of the Receiver Antenna
313 // ----------------------------------------
314 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
315 + crossproduct(rho, ry);
316
317 // Resulting Effect
318 // ----------------
319 double alpha = DotProduct(dipSat,dipRec) /
320 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
321
322 if (alpha > 1.0) alpha = 1.0;
323 if (alpha < -1.0) alpha = -1.0;
324
325 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
326
327 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
328 dphi = -dphi;
329 }
330
331 if (lastEtime[prn.toInt()] == 0.0) {
332 sumWind[prn.toInt()] = dphi;
333 }
334 else {
335 sumWind[prn.toInt()] = nint(sumWind[prn.toInt()] - dphi) + dphi;
336 }
337
338 lastEtime[prn.toInt()] = etime.mjddec();
339 }
340
341 return sumWind[prn.toInt()];
342}
343
344// Tropospheric Model (Saastamoinen)
345////////////////////////////////////////////////////////////////////////////
346double t_tropo::delay_saast(const ColumnVector& xyz, double Ele) {
347
348 Tracer tracer("bncModel::delay_saast");
349
350 if (xyz[0] == 0.0 && xyz[1] == 0.0 && xyz[2] == 0.0) {
351 return 0.0;
352 }
353
354 double ell[3];
355 xyz2ell(xyz.data(), ell);
356 double height = ell[2];
357
358 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
359 double TT = 18.0 - height * 0.0065 + 273.15;
360 double hh = 50.0 * exp(-6.396e-4 * height);
361 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
362
363 double h_km = height / 1000.0;
364
365 if (h_km < 0.0) h_km = 0.0;
366 if (h_km > 5.0) h_km = 5.0;
367 int ii = int(h_km + 1); if (ii > 5) ii = 5;
368 double href = ii - 1;
369
370 double bCor[6];
371 bCor[0] = 1.156;
372 bCor[1] = 1.006;
373 bCor[2] = 0.874;
374 bCor[3] = 0.757;
375 bCor[4] = 0.654;
376 bCor[5] = 0.563;
377
378 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
379
380 double zen = M_PI/2.0 - Ele;
381
382 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
383}
384
385// Constructor
386///////////////////////////////////////////////////////////////////////////
387t_iono::t_iono() {
388 _psiPP = _phiPP = _lambdaPP = _lonS = 0.0;
389}
390
391t_iono::~t_iono() {}
392
393double t_iono::stec(const t_vTec* vTec, double signalPropagationTime,
394 const ColumnVector& rSat, const bncTime& epochTime,
395 const ColumnVector& xyzSta) {
396
397 // Latitude, longitude, height are defined with respect to a spherical earth model
398 // -------------------------------------------------------------------------------
399 ColumnVector geocSta(3);
400 if (xyz2geoc(xyzSta.data(), geocSta.data()) != success) {
401 return 0.0;
402 }
403
404 // satellite position rotated to the epoch of signal reception
405 // -----------------------------------------------------------
406 ColumnVector xyzSat(3);
407 double omegaZ = t_CST::omega * signalPropagationTime;
408 xyzSat[0] = rSat[0] * cos(omegaZ) + rSat[1] * sin(omegaZ);
409 xyzSat[1] = rSat[1] * cos(omegaZ) - rSat[0] * sin(omegaZ);
410 xyzSat[2] = rSat[2];
411
412 // elevation and azimuth with respect to a spherical earth model
413 // -------------------------------------------------------------
414 ColumnVector rhoV = xyzSat - xyzSta;
415 double rho = rhoV.norm_Frobenius();
416 ColumnVector neu(3);
417 xyz2neu(geocSta.data(), rhoV.data(), neu.data());
418 double sphEle = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
419 if (neu[2] < 0) {
420 sphEle *= -1.0;
421 }
422 double sphAzi = atan2(neu[1], neu[0]);
423
424 double epoch = fmod(epochTime.gpssec(), 86400.0);
425
426 double stec = 0.0;
427 for (unsigned ii = 0; ii < vTec->_layers.size(); ii++) {
428 piercePoint(vTec->_layers[ii]._height, epoch, geocSta.data(), sphEle, sphAzi);
429 double vtec = vtecSingleLayerContribution(vTec->_layers[ii]);
430 stec += vtec * sin(sphEle + _psiPP);
431 }
432 return stec;
433}
434
435double t_iono::vtecSingleLayerContribution(const t_vTecLayer& vTecLayer) {
436
437 double vtec = 0.0;
438 int N = vTecLayer._C.Nrows()-1;
439 int M = vTecLayer._C.Ncols()-1;
440 double fac;
441
442 for (int n = 0; n <= N; n++) {
443 for (int m = 0; m <= min(n, M); m++) {
444 double pnm = associatedLegendreFunction(n, m, sin(_phiPP));
445 double a = double(factorial(n - m));
446 double b = double(factorial(n + m));
447 if (m == 0) {
448 fac = sqrt(2.0 * n + 1);
449 }
450 else {
451 fac = sqrt(2.0 * (2.0 * n + 1) * a / b);
452 }
453 pnm *= fac;
454 double Cnm_mlambda = vTecLayer._C[n][m] * cos(m * _lonS);
455 double Snm_mlambda = vTecLayer._S[n][m] * sin(m * _lonS);
456 vtec += (Snm_mlambda + Cnm_mlambda) * pnm;
457 }
458 }
459
460 if (vtec < 0.0) {
461 return 0.0;
462 }
463
464 return vtec;
465}
466
467void t_iono::piercePoint(double layerHeight, double epoch, const double* geocSta,
468 double sphEle, double sphAzi) {
469
470 double q = (t_CST::rgeoc + geocSta[2]) / (t_CST::rgeoc + layerHeight);
471
472 _psiPP = M_PI/2 - sphEle - asin(q * cos(sphEle));
473
474 _phiPP = asin(sin(geocSta[0]) * cos(_psiPP) + cos(geocSta[0]) * sin(_psiPP) * cos(sphAzi));
475
476 if (( (geocSta[0]*180.0/M_PI > 0) && ( tan(_psiPP) * cos(sphAzi) > tan(M_PI/2 - geocSta[0])) ) ||
477 ( (geocSta[0]*180.0/M_PI < 0) && (-(tan(_psiPP) * cos(sphAzi)) > tan(M_PI/2 + geocSta[0])) )) {
478 _lambdaPP = geocSta[1] + M_PI - asin((sin(_psiPP) * sin(sphAzi) / cos(_phiPP)));
479 } else {
480 _lambdaPP = geocSta[1] + asin((sin(_psiPP) * sin(sphAzi) / cos(_phiPP)));
481 }
482
483 _lonS = fmod((_lambdaPP + (epoch - 50400) * M_PI / 43200), 2*M_PI);
484
485 return;
486}
487
Note: See TracBrowser for help on using the repository browser.