File: fileNormalEquation.h

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 (108 lines) | stat: -rw-r--r-- 4,226 bytes parent folder | download
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
/***********************************************/
/**
* @file fileNormalEquation.h
*
* @brief Read/write a system of normal equations.
*
* @author Torsten Mayer-Guerr
* @author Sebastian Strasser
* @date 2010-05-27
*
*/
/***********************************************/

#ifndef __GROOPS_FILENORMALEQUATION__
#define __GROOPS_FILENORMALEQUATION__

// Latex documentation
#ifdef DOCSTRING_FILEFORMAT_NormalEquation
static const char *docstringNormalEquation = R"(
Stores a \reference{system of normal equations}{normalEquationType}
\begin{equation}
  \M N \hat{\M x} = \M n.
\end{equation}.
This file format consists of multiple files.
The file name \verb|normals.dat.gz| corresponds to the following files:
\begin{itemize}
\item \verb|normals.dat.gz| or \verb|normals.00.00.dat.gz| ... \verb|normals.0n.0n.dat.gz|:
      the normal matrix $\M N$ as \file{matrix}{matrix},
\item \verb|normals.rightHandSide.dat.gz|:
      the right hand side(s) $\M n$ as \file{matrix}{matrix},
\item \verb|normals.parameterNames.txt|: \file{parameter names}{parameterName},
\item \verb|normals.info.xml|:
\     u.a. containing the number of observations and the quadratic sum of (reduced) observations $\M l^T\M P\M l$.
\end{itemize}
A large normal matrix may be splitted into blocks and stored in multiple files.
The block row/column number is indicated in the file name.
Only the upper blocks of the sysmmetric matrix are considered.
Matrix in blocks can be distributed on muliple nodes in parallel mode to efficiently use distributed memory.
)";
#endif

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

#include "base/parameterName.h"
#include "inputOutput/fileName.h"
#include "inputOutput/fileArchive.h"
#include "files/fileMatrix.h"

/** @addtogroup filesGroup */
/// @{

/***** CONSTANTS ********************************/

const char *const FILE_NORMALEQUATION_TYPE    = "normalEquation";
constexpr UInt    FILE_NORMALEQUATION_VERSION = std::max(std::max(UInt(20200123), FILE_MATRIX_VERSION), FILE_BASE_VERSION);

/***** CLASSES **********************************/

class NormalEquationInfo
{
public:
  std::vector<ParameterName> parameterName;
  Vector lPl;
  UInt observationCount;
  std::vector<UInt> blockIndex;
  Matrix usedBlocks;

  NormalEquationInfo(UInt rhsCount = 1) : lPl(rhsCount), observationCount(0) {}
  NormalEquationInfo(const std::vector<ParameterName> &parameterName_, const Vector &lPl_ = Vector(1), UInt observationCount_ = 0)
    : parameterName(parameterName_), lPl(lPl_), observationCount(observationCount_) {}
};

/***** FUNCTIONS ********************************/

/** @brief Write a system of normal equations. */
void writeFileNormalEquation(const FileName &name, NormalEquationInfo info, const Matrix &N, const Matrix &n);

/** @brief Write a system of normal equations. */
void writeFileNormalEquation(const FileName &name, NormalEquationInfo info, const std::vector<std::vector<Matrix>> &N, const Matrix &n);

class MatrixDistributed;
/** @brief Write a system of normal equations.
* Must be called on every process.
* Only at master needed: @a parameterName, @a n, @a lPl, @a observationCount. */
void writeFileNormalEquation(const FileName &name, NormalEquationInfo info, const MatrixDistributed &N, const Matrix &n);

/** @brief Write a system of normal equations.
* Only the information file, parameter name file and the right hand sides are written. */
void writeFileNormalEquation(const FileName &name, NormalEquationInfo info, const Matrix &n);

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

/** @brief Read a system of normal equations. */
void readFileNormalEquation(const FileName &name, NormalEquationInfo &info, Matrix &N, Matrix &n);

/** @brief Write a system of normal equations.
* Must be called on every process in @p comm. */
void readFileNormalEquation(const FileName &name, NormalEquationInfo &info, MatrixDistributed &normal, Matrix &n, Parallel::CommunicatorPtr comm);

/** @brief Read a system of normal equations.
* Only the information file, parameter name file and the right hand sides are read. */
void readFileNormalEquation(const FileName &name, NormalEquationInfo &info, Matrix &n);

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

/// @}

#endif /* __GROOPS__ */