General Purpose Geodetic Library
SgPwlStorage.cpp
Go to the documentation of this file.
1 /*
2  *
3  * This file is a part of Space Geodetic Library. The library is used by
4  * nuSolve, a part of CALC/SOLVE system, and designed to make analysis of
5  * geodetic VLBI observations.
6  * Copyright (C) 2010-2020 Sergei Bolotin.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include <SgLogger.h>
24 
25 #include <SgPwlStorage.h>
26 
27 #include <SgTaskConfig.h>
28 
29 
30 
31 
32 /*=======================================================================================================
33 *
34 * METHODS:
35 *
36 *======================================================================================================*/
37 //
38 // static first:
39 const QString SgPwlStorage::className()
40 {
41  return "SgPwlStorage";
42 };
43 
44 
45 
46 //
48 {
49  tStart_ = s.tStart();
50  tFinis_ = s.tFinis();
51  tRefer_ = s.tRefer();
52  if (isPOrigOwner_)
53  delete pOrig_;
54  pOrig_ = new SgParameter(*s.pOrig_);
55  isPOrigOwner_ = true; // that is for reporter
56  step_ = s.step();
59  if (pAi_)
60  delete pAi_;
62  for (int i=0; i<numOfPolynomials_; i++)
63  pAi_[i] = s.pAi_[i];
64  if (pBi_)
65  delete pBi_;
67  for (int i=0; i<numOfNodes_; i++)
68  pBi_[i] = s.pBi_[i];
69 
70  sumP2_ = s.sumP2_;
71  sumX1P2_ = s.sumX1P2_;
72  sumX2P2_ = s.sumX2P2_;
73  sumT1P2_ = s.sumT1P2_;
74 
75  trace_ = s.trace_;
76 
77  return *this;
78 };
79 
80 
81 
82 //
84 {
85  for (int i=0; i<numOfPolynomials_; i++)
86  pAi_[i].zerofy();
87  for (int i=0; i<numOfNodes_; i++)
88  pBi_[i].zerofy();
89 };
90 
91 
92 
93 //
95 {
96  return calcPolySolution(t) + calcRateSolution(t);
97 };
98 
99 
100 
101 //
103 {
104  double f(0.0);
105  // Polynomials only:
106  if (numOfPolynomials_)
107  {
108  double dt = (t - tRefer_);
109  double dd = 1.0;
110  for (int i=0; i<numOfPolynomials_; i++)
111  {
112  f += pAi_[i].getSolution()*dd;
113  dd *= dt;
114  };
115  };
116  return f;
117 };
118 
119 
120 
121 //
123 {
124  // Rates only:
125  int j(calcCurrentIdx(t));
126  if (j < 0)
127  j = 0;
128  else if (j > numOfNodes_-1)
129  j = numOfNodes_ - 1;
130  return pBi_[j].getSigma()*step_;
131 };
132 
133 
134 
135 /*
136 double SgPwlStorage::calcMeansResids4Sfo(double& sumSqr, double& rateSigma)
137 {
138  double v, s;
139  double sWX2, sWX1, sW, sX, sX2;
140 
141  sWX2 = sWX1 = sW = sX = sX2 = 0.0;
142  for (int i=0; i<numOfNodes_; i++)
143  {
144  v = pBi_[i].getSolution();
145  s = pBi_[i].getSigma();
146  sX += v;
147  sW += 1.0/s/s;
148  sWX1 += v/s/s;
149  sWX2 += v*v/s/s;
150  sX2 += v*v;
151  };
152 //wrmsRate = sqrt(fabs(sWX2 - sWX1*sWX1/sW)/sW);
153  sumSqr = sX2;
154  rateSigma = 1.0;
155  return sX/numOfNodes_;
156 };
157 */
158 
159 
160 
161 //
163 {
164  double v, sX2;
165  sX2 = 0.0;
166  for (int i=0; i<numOfNodes_; i++)
167  {
168  v = pBi_[i].getSolution();
169  sX2 += v*v;
170  };
171  return sX2;
172 };
173 
174 
175 
176 //
178 {
179  QMap<QString, SgParameter*> name2par;
180  QMap<QString, int> name2idx;
181 
182  for (int i=0; i<listX->size(); i++)
183  {
184  name2par[listX->at(i)->getName()] = listX->at(i);
185  name2idx[listX->at(i)->getName()] = i;
186  };
187  //
189  // collect B_i parameters that are in this partial solution:
190  for (int i=0; i<numOfNodes_; i++)
191  if (name2par.contains(pBi_[i].getName()))
192  l.append(&pBi_[i]);
193  //
194  // collect indices:
195  int *idx2r;
196  idx2r = new int[l.size()];
197  for (int i=0; i<l.size(); i++)
198  idx2r[i] = name2idx[l.at(i)->getName()];
199  //
200  // calc trace:
201  double d;
202  d = 0.0;
203  for (int i=0; i<l.size(); i++)
204  {
205  double aConstr=l.at(i)->getSigmaAPriori();
206  d += mPx.getElement(idx2r[i], idx2r[i])/aConstr/aConstr;
207  };
208  trace_ += d;
209  l.clear();
210  delete[] idx2r;
211 };
212 /*=====================================================================================================*/
213 
214 
215 
216 
217 /*=======================================================================================================
218 *
219 * FRIENDS:
220 *
221 *======================================================================================================*/
222 //
223 
224 
225 
226 /*=====================================================================================================*/
227 //
228 // aux functions:
229 //
230 
231 
232 // i/o:
233 
234 
235 /*=====================================================================================================*/
236 //
237 // constants:
238 //
239 
240 
241 /*=====================================================================================================*/
Definition: SgMJD.h:59
double getSolution() const
Definition: SgParameter.h:435
double getSigma() const
Definition: SgParameter.h:443
const QString & getName() const
Definition: SgPartial.h:283
int getNumOfPolynomials() const
Definition: SgPwlStorage.h:259
double sumT1P2_
Definition: SgPwlStorage.h:179
const SgMJD & tStart() const
Definition: SgPwlStorage.h:275
int numOfPolynomials_
Definition: SgPwlStorage.h:169
bool isPOrigOwner_
Definition: SgPwlStorage.h:180
int getNumOfNodes() const
Definition: SgPwlStorage.h:251
void collectTraces4Sfo(const QList< SgParameter * > *listX, const SgSymMatrix &mPx)
static const QString className()
virtual double calcSolution(const SgMJD &)
const SgMJD & tRefer() const
Definition: SgPwlStorage.h:291
virtual SgPwlStorage & operator=(const SgPwlStorage &)
double step() const
Definition: SgPwlStorage.h:267
double sumX2P2_
Definition: SgPwlStorage.h:178
virtual double calcRateRms4Sfo()
SgParameter * pOrig_
Definition: SgPwlStorage.h:165
double calcPolySolution(const SgMJD &)
virtual double calcRateSolution(const SgMJD &)=0
int calcCurrentIdx(const SgMJD &t)
Definition: SgPwlStorage.h:345
const SgMJD & tFinis() const
Definition: SgPwlStorage.h:283
SgParameter * pAi_
Definition: SgPwlStorage.h:167
double sumX1P2_
Definition: SgPwlStorage.h:177
virtual double calcRateSigma(const SgMJD &)
SgParameter * pBi_
Definition: SgPwlStorage.h:168
double getElement(unsigned int i, unsigned int j) const
Definition: SgSymMatrix.h:274