File: kaula2SigmaPotentialCoefficients.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 (87 lines) | stat: -rw-r--r-- 3,203 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
/***********************************************/
/**
* @file kaula2SigmaPotentialCoefficients.cpp
*
* @brief Create variances according kaulas rule of thumb.
*
* @author Torsten Mayer-Guerr
* @date 2008-08-08
*
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
Create signal standard deviations of potential coefficients according Kaula's rule of thumb
\begin{equation}
  \sigma_n = \frac{f}{n^p},
\end{equation}
with the degree $n$, the \config{factor} $f$, and the \config{power} $p$.

The standard deviations are written as formal errors of
 \configFile{outputfilePotentialCoefficients}{potentialCoefficients}.
)";

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

#include "programs/program.h"
#include "files/fileSphericalHarmonics.h"

/***** CLASS ***********************************/

/** @brief Create variances according kaulas rule of thumb.
* The coefficients are writen as SphericalHarmonics.
* @ingroup programsGroup */
class Kaula2SigmaPotentialCoefficients
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(Kaula2SigmaPotentialCoefficients, SINGLEPROCESS, "Create variances according kaulas rule of thumb", Misc, PotentialCoefficients)

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

void Kaula2SigmaPotentialCoefficients::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
  try
  {
    FileName potentialCoefficientsName;
    UInt     minDegree, maxDegree;
    Double   GM, R;
    Double   power, factor;

    readConfig(config, "outputfilePotentialCoefficients", potentialCoefficientsName, Config::MUSTSET,  "", "");
    readConfig(config, "minDegree", minDegree, Config::DEFAULT,  "2", "");
    readConfig(config, "maxDegree", maxDegree, Config::MUSTSET,  "",  "");
    readConfig(config, "GM",        GM,        Config::DEFAULT,  STRING_DEFAULT_GM, "Geocentric gravitational constant");
    readConfig(config, "R",         R,         Config::DEFAULT,  STRING_DEFAULT_R,  "reference radius");
    readConfig(config, "power",     power,     Config::DEFAULT,  "2",    "sigma = factor/degree^power");
    readConfig(config, "factor",    factor,    Config::DEFAULT,  "1e-5", "sigma = factor/degree^power");
    if(isCreateSchema(config)) return;

    logStatus<<"create potential coefficients"<<Log::endl;
    Matrix cnm      (maxDegree+1, Matrix::TRIANGULAR, Matrix::LOWER);
    Matrix snm      (maxDegree+1, Matrix::TRIANGULAR, Matrix::LOWER);
    Matrix sigma2cnm(maxDegree+1, Matrix::TRIANGULAR, Matrix::LOWER);
    Matrix sigma2snm(maxDegree+1, Matrix::TRIANGULAR, Matrix::LOWER);

    for(UInt n=minDegree; n<=maxDegree; n++)
    {
      const Double v = factor/std::pow(n, power);
      sigma2cnm(n,0) = v*v;
      for(UInt m=1; m<=n; m++)
        sigma2cnm(n,m) = sigma2snm(n,m) = v*v;
    }

    logStatus<<"writing potential coefficients to file <"<<potentialCoefficientsName<<">"<<Log::endl;
    writeFileSphericalHarmonics(potentialCoefficientsName, SphericalHarmonics(GM, R, cnm, snm, sigma2cnm, sigma2snm));
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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