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_pppClient
|
---|
31 | *
|
---|
32 | * Purpose: PPP Client processing starts here
|
---|
33 | *
|
---|
34 | * Author: L. Mervart
|
---|
35 | *
|
---|
36 | * Created: 29-Jul-2014
|
---|
37 | *
|
---|
38 | * Changes:
|
---|
39 | *
|
---|
40 | * -----------------------------------------------------------------------*/
|
---|
41 |
|
---|
42 | #include <QThreadStorage>
|
---|
43 |
|
---|
44 | #include <iostream>
|
---|
45 | #include <iomanip>
|
---|
46 | #include <stdlib.h>
|
---|
47 | #include <string.h>
|
---|
48 | #include <stdexcept>
|
---|
49 |
|
---|
50 | #include "pppClient.h"
|
---|
51 | #include "ephpool.h"
|
---|
52 | #include "obspool.h"
|
---|
53 | #include "satbias.h"
|
---|
54 | #include "bncconst.h"
|
---|
55 | #include "bncutils.h"
|
---|
56 | #include "station.h"
|
---|
57 | #include "bnctides.h"
|
---|
58 | #include "bncantex.h"
|
---|
59 | #include "filter.h"
|
---|
60 |
|
---|
61 | using namespace BNC;
|
---|
62 | using namespace std;
|
---|
63 |
|
---|
64 | // Global variable holding thread-specific pointers
|
---|
65 | //////////////////////////////////////////////////////////////////////////////
|
---|
66 | QThreadStorage<t_pppClient*> CLIENTS;
|
---|
67 |
|
---|
68 | // Static function returning thread-specific pointer
|
---|
69 | //////////////////////////////////////////////////////////////////////////////
|
---|
70 | t_pppClient* t_pppClient::instance() {
|
---|
71 | return CLIENTS.localData();
|
---|
72 | }
|
---|
73 |
|
---|
74 | // Constructor
|
---|
75 | //////////////////////////////////////////////////////////////////////////////
|
---|
76 | t_pppClient::t_pppClient(const t_options* opt) {
|
---|
77 | _output = 0;
|
---|
78 | _opt = new t_options(*opt);
|
---|
79 | _log = new ostringstream();
|
---|
80 | _ephPool = new t_ephPool();
|
---|
81 | _obsPool = new t_obsPool();
|
---|
82 | _staRover = new t_station();
|
---|
83 | _filter = new t_filter();
|
---|
84 |
|
---|
85 | if (!_opt->_antexFile.empty()) {
|
---|
86 | _antex = new bncAntex(_opt->_antexFile.c_str());
|
---|
87 | }
|
---|
88 | else {
|
---|
89 | _antex = 0;
|
---|
90 | }
|
---|
91 |
|
---|
92 | CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
|
---|
93 | }
|
---|
94 |
|
---|
95 | // Destructor
|
---|
96 | //////////////////////////////////////////////////////////////////////////////
|
---|
97 | t_pppClient::~t_pppClient() {
|
---|
98 | delete _log;
|
---|
99 | delete _opt;
|
---|
100 | delete _ephPool;
|
---|
101 | delete _obsPool;
|
---|
102 | delete _staRover;
|
---|
103 | delete _antex;
|
---|
104 | delete _filter;
|
---|
105 | clearObs();
|
---|
106 | }
|
---|
107 |
|
---|
108 | //
|
---|
109 | //////////////////////////////////////////////////////////////////////////////
|
---|
110 | void t_pppClient::putEphemeris(const t_eph* eph) {
|
---|
111 | const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
|
---|
112 | const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
|
---|
113 | const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
|
---|
114 | if (ephGPS) {
|
---|
115 | _ephPool->putEphemeris(new t_ephGPS(*ephGPS));
|
---|
116 | LOG << OPT->_roverName << " putEphemeris GPS" << endl;
|
---|
117 | }
|
---|
118 | else if (ephGlo) {
|
---|
119 | _ephPool->putEphemeris(new t_ephGlo(*ephGlo));
|
---|
120 | LOG << OPT->_roverName << " putEphemeris Glo" << endl;
|
---|
121 | }
|
---|
122 | else if (ephGal) {
|
---|
123 | _ephPool->putEphemeris(new t_ephGal(*ephGal));
|
---|
124 | LOG << OPT->_roverName << " putEphemeris Gal" << endl;
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | //
|
---|
129 | //////////////////////////////////////////////////////////////////////////////
|
---|
130 | void t_pppClient::putOrbCorrections(const vector<t_orbCorr>& corr) {
|
---|
131 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
---|
132 | _ephPool->putOrbCorrection(new t_orbCorr(corr[ii]));
|
---|
133 | }
|
---|
134 | LOG << OPT->_roverName << " putOrbCorrections " << corr.size() << endl;
|
---|
135 | }
|
---|
136 |
|
---|
137 | //
|
---|
138 | //////////////////////////////////////////////////////////////////////////////
|
---|
139 | void t_pppClient::putClkCorrections(const vector<t_clkCorr>& corr) {
|
---|
140 | for (unsigned ii = 0; ii < corr.size(); ii++) {
|
---|
141 | _ephPool->putClkCorrection(new t_clkCorr(corr[ii]));
|
---|
142 | }
|
---|
143 | LOG << OPT->_roverName << " putClkCorrections " << corr.size() << endl;
|
---|
144 | }
|
---|
145 |
|
---|
146 | //
|
---|
147 | //////////////////////////////////////////////////////////////////////////////
|
---|
148 | void t_pppClient::putBiases(const vector<t_satBiases>& biases) {
|
---|
149 | for (unsigned ii = 0; ii < biases.size(); ii++) {
|
---|
150 | _obsPool->putBiases(new t_satBias(biases[ii]));
|
---|
151 | }
|
---|
152 | LOG << OPT->_roverName << " putBiases " << biases.size() << endl;
|
---|
153 | }
|
---|
154 |
|
---|
155 | //
|
---|
156 | //////////////////////////////////////////////////////////////////////////////
|
---|
157 | t_irc t_pppClient::prepareObs(const vector<t_pppSatObs>& pppSatObs,
|
---|
158 | vector<t_satObs*>& obsVector, bncTime& epoTime) {
|
---|
159 | // Default
|
---|
160 | // -------
|
---|
161 | epoTime.reset();
|
---|
162 |
|
---|
163 | if (pppSatObs.size() == 0) {
|
---|
164 | return success;
|
---|
165 | }
|
---|
166 |
|
---|
167 | // Create vector of valid observations
|
---|
168 | // -----------------------------------
|
---|
169 | int numValidGPS = 0;
|
---|
170 | for (unsigned ii = 0; ii < pppSatObs.size(); ii++) {
|
---|
171 | char system = pppSatObs[ii]._prn.system();
|
---|
172 | if (system == 'G' || (system == 'R' && OPT->useGlonass())) {
|
---|
173 | t_satObs* satObs = new t_satObs(pppSatObs[ii]);
|
---|
174 | if (satObs->isValid()) {
|
---|
175 | obsVector.push_back(satObs);
|
---|
176 | if (satObs->prn().system() == 'G') {
|
---|
177 | ++numValidGPS;
|
---|
178 | }
|
---|
179 | }
|
---|
180 | else {
|
---|
181 | delete satObs;
|
---|
182 | }
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | // Check whether data are synchronized, compute epoTime
|
---|
187 | // ----------------------------------------------------
|
---|
188 | const double MAXSYNC = 0.05; // synchronization limit
|
---|
189 | double meanDt = 0.0;
|
---|
190 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
191 | const t_satObs* satObs = obsVector.at(ii);
|
---|
192 | if (epoTime.undef()) {
|
---|
193 | epoTime = satObs->time();
|
---|
194 | }
|
---|
195 | else {
|
---|
196 | double dt = satObs->time() - epoTime;
|
---|
197 | if (fabs(dt) > MAXSYNC) {
|
---|
198 | LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
|
---|
199 | return failure;
|
---|
200 | }
|
---|
201 | meanDt += dt;
|
---|
202 | }
|
---|
203 | }
|
---|
204 | epoTime += meanDt / obsVector.size();
|
---|
205 |
|
---|
206 | return success;
|
---|
207 | }
|
---|
208 |
|
---|
209 | // Compute the Bancroft position, check for blunders
|
---|
210 | //////////////////////////////////////////////////////////////////////////////
|
---|
211 | t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
|
---|
212 | vector<t_satObs*>& obsVector,
|
---|
213 | ColumnVector& xyzc, bool print) {
|
---|
214 |
|
---|
215 | t_lc::type tLC = (OPT->dualFreqRequired() ? t_lc::cIF : t_lc::c1);
|
---|
216 |
|
---|
217 | while (true) {
|
---|
218 | Matrix BB(obsVector.size(), 4);
|
---|
219 | int iObs = -1;
|
---|
220 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
221 | const t_satObs* satObs = obsVector.at(ii);
|
---|
222 | if ( satObs->isValid() && satObs->prn().system() == 'G' &&
|
---|
223 | (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle) ) {
|
---|
224 | ++iObs;
|
---|
225 | BB[iObs][0] = satObs->xc()[0];
|
---|
226 | BB[iObs][1] = satObs->xc()[1];
|
---|
227 | BB[iObs][2] = satObs->xc()[2];
|
---|
228 | BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
|
---|
229 | }
|
---|
230 | }
|
---|
231 | if (iObs + 1 < OPT->_minObs) {
|
---|
232 | LOG << "t_pppClient::cmpBancroft not enough observations" << endl;
|
---|
233 | return failure;
|
---|
234 | }
|
---|
235 | BB = BB.Rows(1,iObs+1);
|
---|
236 | bancroft(BB, xyzc);
|
---|
237 |
|
---|
238 | xyzc[3] /= t_CST::c;
|
---|
239 |
|
---|
240 | // Check Blunders
|
---|
241 | // --------------
|
---|
242 | const double BLUNDER = 100.0;
|
---|
243 | double maxRes = 0.0;
|
---|
244 | unsigned maxResIndex = 0;
|
---|
245 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
246 | const t_satObs* satObs = obsVector.at(ii);
|
---|
247 | if ( satObs->isValid() && satObs->prn().system() == 'G' &&
|
---|
248 | (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle) ) {
|
---|
249 | ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
|
---|
250 | double res = rr.norm_Frobenius() - satObs->obsValue(tLC)
|
---|
251 | - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
|
---|
252 | if (fabs(res) > maxRes) {
|
---|
253 | maxRes = fabs(res);
|
---|
254 | maxResIndex = ii;
|
---|
255 | }
|
---|
256 | }
|
---|
257 | }
|
---|
258 | if (maxRes < BLUNDER) {
|
---|
259 | if (print) {
|
---|
260 | LOG.setf(ios::fixed);
|
---|
261 | LOG << string(epoTime) << " BANCROFT:" << ' '
|
---|
262 | << setw(14) << setprecision(3) << xyzc[0] << ' '
|
---|
263 | << setw(14) << setprecision(3) << xyzc[1] << ' '
|
---|
264 | << setw(14) << setprecision(3) << xyzc[2] << ' '
|
---|
265 | << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
|
---|
266 | }
|
---|
267 | break;
|
---|
268 | }
|
---|
269 | else {
|
---|
270 | t_satObs* satObs = obsVector.at(maxResIndex);
|
---|
271 | LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
|
---|
272 | << " " << maxRes << endl;
|
---|
273 | delete satObs;
|
---|
274 | obsVector.erase(obsVector.begin() + maxResIndex);
|
---|
275 | }
|
---|
276 | }
|
---|
277 |
|
---|
278 | return success;
|
---|
279 | }
|
---|
280 |
|
---|
281 | // Compute A Priori GPS-Glonass Offset
|
---|
282 | //////////////////////////////////////////////////////////////////////////////
|
---|
283 | double t_pppClient::cmpOffGG(vector<t_satObs*>& obsVector) {
|
---|
284 |
|
---|
285 | t_lc::type tLC = (OPT->dualFreqRequired() ? t_lc::cIF : t_lc::c1);
|
---|
286 | double offGG = 0.0;
|
---|
287 |
|
---|
288 | if (OPT->useGlonass()) {
|
---|
289 | while (true) {
|
---|
290 | offGG = 0.0;
|
---|
291 | bool outlierFound = false;
|
---|
292 | unsigned nObs = 0;
|
---|
293 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
---|
294 | t_satObs* satObs = obsVector.at(ii);
|
---|
295 | if ( !satObs->outlier() && satObs->isValid() && satObs->prn().system() == 'R' &&
|
---|
296 | (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle) ) {
|
---|
297 | ++nObs;
|
---|
298 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
---|
299 | if (fabs(ll) > 1000.0) {
|
---|
300 | satObs->setOutlier();
|
---|
301 | outlierFound = true;
|
---|
302 | LOG << "t_pppClient::cmpOffGG outlier " << satObs->prn().toString()
|
---|
303 | << " " << ll << endl;
|
---|
304 | }
|
---|
305 | offGG += ll;
|
---|
306 | }
|
---|
307 | }
|
---|
308 | if (nObs > 0) {
|
---|
309 | offGG = offGG / nObs;
|
---|
310 | }
|
---|
311 | else {
|
---|
312 | offGG = 0.0;
|
---|
313 | }
|
---|
314 | if (!outlierFound) {
|
---|
315 | break;
|
---|
316 | }
|
---|
317 | }
|
---|
318 | }
|
---|
319 |
|
---|
320 | return offGG;
|
---|
321 | }
|
---|
322 |
|
---|
323 | //
|
---|
324 | //////////////////////////////////////////////////////////////////////////////
|
---|
325 | void t_pppClient::initOutput(t_output* output) {
|
---|
326 | _output = output;
|
---|
327 | _output->_numSat = 0;
|
---|
328 | _output->_pDop = 0.0;
|
---|
329 | _output->_error = false;
|
---|
330 | }
|
---|
331 |
|
---|
332 | //
|
---|
333 | //////////////////////////////////////////////////////////////////////////////
|
---|
334 | void t_pppClient::clearObs() {
|
---|
335 | for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
|
---|
336 | delete _obsRover.at(ii);
|
---|
337 | }
|
---|
338 | _obsRover.clear();
|
---|
339 | }
|
---|
340 |
|
---|
341 | //
|
---|
342 | //////////////////////////////////////////////////////////////////////////////
|
---|
343 | void t_pppClient::finish(t_irc irc) {
|
---|
344 |
|
---|
345 | clearObs();
|
---|
346 |
|
---|
347 | _output->_epoTime = _epoTimeRover;
|
---|
348 |
|
---|
349 | if (irc == success) {
|
---|
350 | _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
|
---|
351 | _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
|
---|
352 | _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
|
---|
353 | copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
|
---|
354 | _output->_numSat = _filter->numSat();
|
---|
355 | _output->_pDop = _filter->PDOP();
|
---|
356 | _output->_error = false;
|
---|
357 | }
|
---|
358 | else {
|
---|
359 | _output->_error = true;
|
---|
360 | }
|
---|
361 | _output->_log = _log->str();
|
---|
362 | delete _log; _log = new ostringstream();
|
---|
363 | }
|
---|
364 |
|
---|
365 | //
|
---|
366 | //////////////////////////////////////////////////////////////////////////////
|
---|
367 | t_irc t_pppClient::cmpModel(t_station* station, const ColumnVector& xyzc,
|
---|
368 | vector<t_satObs*>& obsVector) {
|
---|
369 |
|
---|
370 | bncTime time;
|
---|
371 | time = _epoTimeRover;
|
---|
372 | station->setName(OPT->_roverName);
|
---|
373 | station->setAntName(OPT->_antNameRover);
|
---|
374 | if (OPT->xyzAprRoverSet()) {
|
---|
375 | station->setXyzApr(OPT->_xyzAprRover);
|
---|
376 | }
|
---|
377 | else {
|
---|
378 | station->setXyzApr(xyzc.Rows(1,3));
|
---|
379 | }
|
---|
380 | station->setNeuEcc(OPT->_neuEccRover);
|
---|
381 |
|
---|
382 | // Receiver Clock
|
---|
383 | // --------------
|
---|
384 | station->setDClk(xyzc[3]);
|
---|
385 |
|
---|
386 | // Tides
|
---|
387 | // -----
|
---|
388 | ColumnVector hlp = station->xyzApr();
|
---|
389 | tides(time, hlp);
|
---|
390 | station->setTideDspl(hlp - station->xyzApr());
|
---|
391 |
|
---|
392 | // Observation model
|
---|
393 | // -----------------
|
---|
394 | vector<t_satObs*>::iterator it = obsVector.begin();
|
---|
395 | while (it != obsVector.end()) {
|
---|
396 | t_satObs* satObs = *it;
|
---|
397 | satObs->cmpModel(station);
|
---|
398 | if (satObs->isValid() && satObs->eleSat() >= OPT->_minEle) {
|
---|
399 | ++it;
|
---|
400 | }
|
---|
401 | else {
|
---|
402 | delete satObs;
|
---|
403 | it = obsVector.erase(it);
|
---|
404 | }
|
---|
405 | }
|
---|
406 |
|
---|
407 | return success;
|
---|
408 | }
|
---|
409 |
|
---|
410 | //
|
---|
411 | //////////////////////////////////////////////////////////////////////////////
|
---|
412 | void t_pppClient::processEpoch(const vector<t_pppSatObs>& pppSatObs, t_output* output) {
|
---|
413 |
|
---|
414 | try {
|
---|
415 | initOutput(output);
|
---|
416 |
|
---|
417 | // Prepare Observations of the Rover
|
---|
418 | // ---------------------------------
|
---|
419 | if (prepareObs(pppSatObs, _obsRover, _epoTimeRover) != success) {
|
---|
420 | return finish(failure);
|
---|
421 | }
|
---|
422 |
|
---|
423 | LOG << "\nResults of Epoch ";
|
---|
424 | if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
|
---|
425 | LOG << "\n--------------------------------------\n";
|
---|
426 |
|
---|
427 | for (int iter = 1; iter <= 2; iter++) {
|
---|
428 | ColumnVector xyzc(4); xyzc = 0.0;
|
---|
429 | bool print = (iter == 2);
|
---|
430 | if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
|
---|
431 | return finish(failure);
|
---|
432 | }
|
---|
433 | if (cmpModel(_staRover, xyzc, _obsRover) != success) {
|
---|
434 | return finish(failure);
|
---|
435 | }
|
---|
436 | }
|
---|
437 |
|
---|
438 | _offGG = cmpOffGG(_obsRover);
|
---|
439 |
|
---|
440 | // Store last epoch of data
|
---|
441 | // ------------------------
|
---|
442 | _obsPool->putEpoch(_epoTimeRover, _obsRover);
|
---|
443 |
|
---|
444 | // Process Epoch in Filter
|
---|
445 | // -----------------------
|
---|
446 | if (_filter->processEpoch(_obsPool) != success) {
|
---|
447 | return finish(failure);
|
---|
448 | }
|
---|
449 | }
|
---|
450 | catch (Exception& exc) {
|
---|
451 | LOG << exc.what() << endl;
|
---|
452 | return finish(failure);
|
---|
453 | }
|
---|
454 | catch (pppExcept msg) {
|
---|
455 | LOG << msg.what() << endl;
|
---|
456 | return finish(failure);
|
---|
457 | }
|
---|
458 | catch (...) {
|
---|
459 | LOG << "unknown exception" << endl;
|
---|
460 | return finish(failure);
|
---|
461 | }
|
---|
462 |
|
---|
463 | return finish(success);
|
---|
464 | }
|
---|
465 |
|
---|
466 | //
|
---|
467 | ////////////////////////////////////////////////////////////////////////////
|
---|
468 | double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
|
---|
469 | return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
|
---|
470 | }
|
---|
471 |
|
---|
472 | //
|
---|
473 | ////////////////////////////////////////////////////////////////////////////
|
---|
474 | void t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
|
---|
475 |
|
---|
476 | if (pos.Nrows() != 4) {
|
---|
477 | pos.ReSize(4);
|
---|
478 | }
|
---|
479 | pos = 0.0;
|
---|
480 |
|
---|
481 | for (int iter = 1; iter <= 2; iter++) {
|
---|
482 | Matrix BB = BBpass;
|
---|
483 | int mm = BB.Nrows();
|
---|
484 | for (int ii = 1; ii <= mm; ii++) {
|
---|
485 | double xx = BB(ii,1);
|
---|
486 | double yy = BB(ii,2);
|
---|
487 | double traveltime = 0.072;
|
---|
488 | if (iter > 1) {
|
---|
489 | double zz = BB(ii,3);
|
---|
490 | double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
|
---|
491 | (yy-pos(2)) * (yy-pos(2)) +
|
---|
492 | (zz-pos(3)) * (zz-pos(3)) );
|
---|
493 | traveltime = rho / t_CST::c;
|
---|
494 | }
|
---|
495 | double angle = traveltime * t_CST::omega;
|
---|
496 | double cosa = cos(angle);
|
---|
497 | double sina = sin(angle);
|
---|
498 | BB(ii,1) = cosa * xx + sina * yy;
|
---|
499 | BB(ii,2) = -sina * xx + cosa * yy;
|
---|
500 | }
|
---|
501 |
|
---|
502 | Matrix BBB;
|
---|
503 | if (mm > 4) {
|
---|
504 | SymmetricMatrix hlp; hlp << BB.t() * BB;
|
---|
505 | BBB = hlp.i() * BB.t();
|
---|
506 | }
|
---|
507 | else {
|
---|
508 | BBB = BB.i();
|
---|
509 | }
|
---|
510 | ColumnVector ee(mm); ee = 1.0;
|
---|
511 | ColumnVector alpha(mm); alpha = 0.0;
|
---|
512 | for (int ii = 1; ii <= mm; ii++) {
|
---|
513 | alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
|
---|
514 | }
|
---|
515 | ColumnVector BBBe = BBB * ee;
|
---|
516 | ColumnVector BBBalpha = BBB * alpha;
|
---|
517 | double aa = lorentz(BBBe, BBBe);
|
---|
518 | double bb = lorentz(BBBe, BBBalpha)-1;
|
---|
519 | double cc = lorentz(BBBalpha, BBBalpha);
|
---|
520 | double root = sqrt(bb*bb-aa*cc);
|
---|
521 |
|
---|
522 | Matrix hlpPos(4,2);
|
---|
523 | hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
|
---|
524 | hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
|
---|
525 |
|
---|
526 | ColumnVector omc(2);
|
---|
527 | for (int pp = 1; pp <= 2; pp++) {
|
---|
528 | hlpPos(4,pp) = -hlpPos(4,pp);
|
---|
529 | omc(pp) = BB(1,4) -
|
---|
530 | sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
|
---|
531 | (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
|
---|
532 | (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
|
---|
533 | hlpPos(4,pp);
|
---|
534 | }
|
---|
535 | if ( fabs(omc(1)) > fabs(omc(2)) ) {
|
---|
536 | pos = hlpPos.Column(2);
|
---|
537 | }
|
---|
538 | else {
|
---|
539 | pos = hlpPos.Column(1);
|
---|
540 | }
|
---|
541 | }
|
---|
542 | }
|
---|
543 |
|
---|