File: tidesEarth.cpp

package info (click to toggle)
groops 0%2Bgit20250907%2Bds-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 11,140 kB
  • sloc: cpp: 135,607; fortran: 1,603; makefile: 20
file content (280 lines) | stat: -rwxr-xr-x 10,088 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/***********************************************/
/**
* @file tidesEarth.cpp
*
* @brief Earth tides.
* Following the IERS conventions.
* @see Tides
*
* @author Torsten Mayer-Guerr
* @date 2002-12-13
*
*/
/***********************************************/

#include "base/import.h"
#include "base/sphericalHarmonics.h"
#include "base/doodson.h"
#include "config/config.h"
#include "files/fileEarthTide.h"
#include "classes/earthRotation/earthRotation.h"
#include "classes/tides/tidesEarth.h"

/***********************************************/

TidesEarth::TidesEarth(Config &config)
{
  try
  {
    FileName earthTidesName;
    readConfig(config, "inputfileEarthtide",   earthTidesName,       Config::MUSTSET, "{groopsDataDir}/tides/earthAnelastic2003.xml", "");
    readConfig(config, "includePermanentTide", includePermanentTide, Config::DEFAULT, "0",   "results in FALSE: zero tide, TRUE: tide free gravity field");
    readConfig(config, "factor",               factor,               Config::DEFAULT, "1.0", "the result is multiplied by this factor, set -1 to subtract the field");
    if(isCreateSchema(config)) return;

    readFileEarthTide(earthTidesName, kReal, kImag, kPlus, doodson20, doodson21, doodson22,
                      ampIp20, ampOp20, ampIp21, ampOp21, amp22,
                      h2_0, h2_2, l2_0, l2_2, l21_1, l22_1, h21_imag, l21_imag, h22_imag, l22_imag, h3, l3,
                      deformationArg21, deformationArg20,
                      dR21_ip, dR21_op, dR20_ip, dR20_op, dT21_ip, dT21_op, dT20_ip, dT20_op);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/************************************************/

// Geopotential (IERS-Convetions 1996, S.40) Step 1
// ------------------------------------------------
void TidesEarth::earthCoefficients1(Double GM_third, const Vector3d &third, Matrix &cnm, Matrix &snm) const
{
  // Kugelflaechenfunktionen berechnen
  Matrix Cnm, Snm;
  SphericalHarmonics::CnmSnm(1./R_Earth * third, 3, Cnm, Snm);

  Double factor = GM_third/GM_Earth;

  // Formel (1)
  for(UInt n=2; n<=3; n++)
    for(UInt m=0; m<=n; m++)
    {
      cnm(n,m) += factor/(2.*n+1.) * (kReal(n,m) * Cnm(n,m) + kImag(n,m) * Snm(n,m));
      snm(n,m) += factor/(2.*n+1.) * (kReal(n,m) * Snm(n,m) - kImag(n,m) * Cnm(n,m));
    }

  // Formel (4)
  for(UInt m=0; m<=2; m++)
  {
    cnm(4,m) += kPlus(2,m)/5. * factor * Cnm(2,m);
    snm(4,m) += kPlus(2,m)/5. * factor * Snm(2,m);
  }
}

/***********************************************/

// Geopotential (IERS-Convetions 1996, S.40) Step 2
// ------------------------------------------------
void TidesEarth::earthCoefficients2(const Time &time, Matrix &cnm, Matrix &snm) const
{
  Vector d = Doodson::arguments(time);

  // Korrektion fuer c20
  Vector thetaf = doodson20 * d;
  for(UInt i=0; i<thetaf.rows(); i++)
    cnm(2,0) += 1e-12 * (ampIp20(i) * cos(thetaf(i)) - ampOp20(i) * sin(thetaf(i)));

  // Korrektion fur c21 und s21
  thetaf = doodson21 * d;
  for(UInt i=0; i<thetaf.rows(); i++)
  {
    cnm(2,1) += 1e-12 * (ampIp21(i) * sin(thetaf(i)) + ampOp21(i) * cos(thetaf(i)));
    snm(2,1) += 1e-12 * (ampIp21(i) * cos(thetaf(i)) - ampOp21(i) * sin(thetaf(i)));
  }

  // Korrektion fur c22 und s22
  thetaf = doodson22 * d;
  for(UInt i=0; i<thetaf.rows(); i++)
  {
    cnm(2,2) +=  1e-12 * amp22(i) * cos(thetaf(i));
    snm(2,2) += -1e-12 * amp22(i) * sin(thetaf(i));
  }
}

/***********************************************/

SphericalHarmonics TidesEarth::sphericalHarmonics(const Time &time, const Rotary3d &rotEarth, EarthRotationPtr /*rotation*/, EphemeridesPtr ephemerides, UInt maxDegree, UInt minDegree, Double GM, Double R) const
{
  try
  {
    if(!ephemerides)
      throw(Exception("No ephemerides given"));

    Matrix cnm(5, Matrix::TRIANGULAR, Matrix::LOWER);
    Matrix snm(5, Matrix::TRIANGULAR, Matrix::LOWER);

    const Vector3d moon = rotEarth.rotate(ephemerides->position(time, Ephemerides::MOON));
    const Vector3d sun  = rotEarth.rotate(ephemerides->position(time, Ephemerides::SUN));

    earthCoefficients1(GM_Sun,  sun,  cnm, snm);
    earthCoefficients1(GM_Moon, moon, cnm, snm);
    earthCoefficients2(time, cnm, snm);

    if(!includePermanentTide)
      cnm(2,0) -= 4.4228e-8*(-0.31460)*kReal(2,0);  // Abzug Permanentgezeiten

    return SphericalHarmonics(GM_Earth, R_Earth, factor*cnm, factor*snm).get(maxDegree, minDegree, GM, R);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/
/***********************************************/

Vector3d TidesEarth::deformation(const Time &time, const Vector3d &point, const Rotary3d &rotEarth, EarthRotationPtr /*rotation*/, EphemeridesPtr ephemerides,
                                 Double /*gravity*/, const Vector &/*hn*/, const Vector &/*ln*/) const
{
  try
  {
    if(!ephemerides)
      throw(Exception("No ephemerides given"));

    Vector3d displacement; // the result

    // local coordinate system
    Double   lambda = point.lambda();
    Double   phi    = point.phi();
    Vector3d up     = normalize(point);
    Vector3d east   = normalize(Vector3d(-up.y(), up.x(), 0.0));
    Vector3d north  = crossProduct(up, east);

    const Vector3d moon = rotEarth.rotate(ephemerides->position(time, Ephemerides::MOON));
    const Vector3d sun  = rotEarth.rotate(ephemerides->position(time, Ephemerides::SUN));

    // in-phase
    // --------
    Double h2 = h2_0 + h2_2*0.5*(3.*pow(sin(phi),2)-1.);
    Double l2 = l2_0 + l2_2*0.5*(3.*pow(sin(phi),2)-1.);
    displacement += deformationInPhase(GM_Sun,  sun,  point, h2, l2, h3, l3);
    displacement += deformationInPhase(GM_Moon, moon, point, h2, l2, h3, l3);

    // out-phase
    // ---------
    Double dUp    = 0;
    Double dEast  = 0;
    Double dNorth = 0;
    deformationOutPhase(GM_Sun,  sun,  lambda, phi, dUp, dEast, dNorth);
    deformationOutPhase(GM_Moon, moon, lambda, phi, dUp, dEast, dNorth);

    // frequency dependent correction
    // ------------------------------
    Vector d = Doodson::arguments(time);

    // diurnal band, equation (16)
    Vector thetaf = deformationArg21 * d;
    Double dUp21    = 0;
    Double dEast21  = 0;
    Double dNorth21 = 0;
    for(UInt i=0; i<thetaf.rows(); i++)
    {
      Double cosf = cos(thetaf(i)+lambda);
      Double sinf = sin(thetaf(i)+lambda);
      dUp21    += dR21_ip(i)*sinf + dR21_op(i)*cosf;
      dEast21  += dT21_ip(i)*cosf - dT21_op(i)*sinf;
      dNorth21 += dT21_ip(i)*sinf + dT21_op(i)*cosf;
    }
    dUp21    *= sin(2*phi);
    dEast21  *= sin(phi);
    dNorth21 *= cos(2*phi);

    // long periodic band, equation (17)
    thetaf = deformationArg20 * d;
    Double dUp20    = 0;
    Double dNorth20 = 0;
    for(UInt i=0; i<thetaf.rows(); i++)
    {
      Double cosf = cos(thetaf(i));
      Double sinf = sin(thetaf(i));
      dUp20    += dR20_ip(i)*cosf + dR20_op(i)*sinf;
      dNorth20 += dT20_ip(i)*cosf + dT20_op(i)*sinf;
    }
    dUp20    *= 1.5*pow(sin(phi),2)-0.5;
    dNorth20 *= sin(2*phi);

    displacement += (dUp+dUp21+dUp20)*up + (dEast+dEast21)*east + (dNorth+dNorth21+dNorth20)*north;

    return this->factor*displacement;
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/***********************************************/

void TidesEarth::deformation(const std::vector<Time> &time, const std::vector<Vector3d> &point, const std::vector<Rotary3d> &rotEarth,
                             EarthRotationPtr rotation, EphemeridesPtr ephemerides, const std::vector<Double> &gravity, const Vector &hn, const Vector &ln,
                             std::vector<std::vector<Vector3d>> &disp) const
{
  try
  {
    for(UInt i=0; i<time.size(); i++)
      for(UInt k=0; k<point.size(); k++)
        disp.at(k).at(i) += deformation(time.at(i), point.at(k), rotEarth.at(i), rotation, ephemerides, gravity.at(k), hn, ln);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

/************************************************/

Vector3d TidesEarth::deformationInPhase(Double GM_third, const Vector3d &third, const Vector3d &point, Double h2, Double l2, Double h3, Double l3) const
{
  Vector3d er = normalize(point);
  Vector3d eR = third;
  Double   R  = eR.normalize();
  Double   rR = inner(eR,er);
  Double   factor = GM_third/GM_Earth * R_Earth * pow(R_Earth/R,3);

  // displacement due to degree 2 tides, (eq.9)
  Vector3d displacement = factor * (h2*(1.5*rR*rR-0.5) * er + 3*l2*rR*(eR - rR*er));

  // displacement due to degree 3 tides, (eq.10)
  factor *= R_Earth/R;
  displacement += factor * (h3*(2.5*pow(rR,3)-1.5*rR) * er + l3*(7.5*rR*rR-1.5)*(eR - rR*er));

  return displacement;
}

/************************************************/

void TidesEarth::deformationOutPhase(Double GM_third, const Vector3d &third, Double lambda, Double phi, Double &dUp, Double &dEast, Double &dNorth) const
{
  Matrix Pnm     = SphericalHarmonics::Pnm(third.theta(), 1.0, 2);
  Double phij    = third.phi();
  Double dlambda = lambda-third.lambda();
  Double factor  = GM_third/GM_Earth * R_Earth * pow(R_Earth/third.r(),3);

  // equation (12) and (13)
  dNorth +=   -l21_1 * sin(phi) * sin(phi)  * factor * Pnm(2,1)*sqrt(3./5.)  * cos(dlambda)
         - 0.5*l22_1 * sin(phi) * cos(phi)  * factor * Pnm(2,2)*sqrt(12./5.) * cos(2*dlambda);
  dEast  +=    l21_1 * sin(phi) * cos(2*phi)* factor * Pnm(2,1)*sqrt(3./5.)  * sin(dlambda)
         - 0.5*l22_1 * sin(phi) * cos(phi)  * factor * Pnm(2,2)*sqrt(12./5.) * sin(phi) * sin(2*dlambda);
  // equation (14a) and (15a)
  dUp    += -0.75 * h21_imag * factor * sin(2*phij)*sin(2*phi)    * sin(dlambda)
         +  -0.75 * h22_imag * factor * pow(cos(phij)*cos(phi),2) * sin(2*dlambda);
  // equation (14b) and (15b)
  dNorth +=  -1.5 * l21_imag * factor * sin(2*phij)*cos(2*phi)      * sin(dlambda)
         +   0.75 * l22_imag * factor * pow(cos(phij),2)*sin(2*phi) * sin(2*dlambda);
  dEast  +=  -1.5 * l21_imag * factor * sin(2*phij)*sin(phi)        * cos(dlambda)
         +  -0.75 * l22_imag * factor * pow(cos(phij),2)*2*cos(phi) * cos(2*dlambda);
}

/***********************************************/