File: gravityfield2GridCovarianceMatrix.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 (83 lines) | stat: -rw-r--r-- 2,980 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
/***********************************************/
/**
* @file gravityfield2GridCovarianceMatrix.cpp
*
* @brief Covariance matrix of values of a gravity field on a grid.
*
* @author Torsten Mayer-Guerr
* @date 2012-05-30
*/
/***********************************************/

// Latex documentation
#define DOCSTRING docstring
static const char *docstring = R"(
This program propagates the covariance matrix of a \configClass{gravityfield}{gravityfieldType}
evaluated at \config{time} to a \configClass{grid}{gridType}. The full variance-covariance matrix is computed
and written to a \file{matrix file}{matrix}:
\begin{equation}
\mathbf{\Sigma}_\mathbf{y} = \mathbf{F}\mathbf{\Sigma}_\mathbf{x}\mathbf{F}^T
\end{equation}
The \configClass{kernel}{kernelType} determines the quantity of the grid values, for example,
\configClass{kernel:waterHeight}{kernelType:waterHeight}.

See also \program{GravityfieldCovariancesPropagation2GriddedData}, \program{GravityfieldVariancesPropagation2GriddedData}.
)";

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

#include "programs/program.h"
#include "files/fileMatrix.h"
#include "classes/grid/grid.h"
#include "classes/kernel/kernel.h"
#include "classes/gravityfield/gravityfield.h"
#include "misc/miscGriddedData.h"

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

/** @brief Covariance matrix of values of a gravity field on a grid.
* @ingroup programsGroup */
class Gravityfield2GridCovarianceMatrix
{
public:
  void run(Config &config, Parallel::CommunicatorPtr comm);
};

GROOPS_REGISTER_PROGRAM(Gravityfield2GridCovarianceMatrix, SINGLEPROCESS, "Covariance matrix of values of a gravity field on a grid.", Gravityfield)

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

void Gravityfield2GridCovarianceMatrix::run(Config &config, Parallel::CommunicatorPtr /*comm*/)
{
  try
  {
    FileName        outName;
    GridPtr         grid;
    GravityfieldPtr gravityfield;
    KernelPtr       kernel;
    Time            time;

    readConfig(config, "outputfileMatrix",     outName,      Config::MUSTSET,  "", "symmetric grid covariance matrix");
    readConfig(config, "grid",                 grid,         Config::MUSTSET,  "", "");
    readConfig(config, "kernel",               kernel,       Config::MUSTSET,  "", "");
    readConfig(config, "gravityfield",         gravityfield, Config::MUSTSET,  "", "");
    readConfig(config, "time",                 time,         Config::OPTIONAL, "", "at this time the gravity field will be evaluated");
    if(isCreateSchema(config)) return;

    // Fcreate covariance matrix
    // ------------------
    logStatus<<"create covariance matrix"<<Log::endl;
    Matrix C = gravityfield->variance(time, grid->points(), *kernel);

    // write file
    // ----------
    logStatus<<"write covariance matrix to file <"<<outName<<">"<<Log::endl;
    writeFileMatrix(outName, C);
  }
  catch(std::exception &e)
  {
    GROOPS_RETHROW(e)
  }
}

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