chombo-discharge
Loading...
Searching...
No Matches
CD_LaPackUtils.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
14#ifndef CD_LAPACKUTILS_H
15#define CD_LAPACKUTILS_H
16
17// Std includes
18#include <vector>
19
20// Our includes
21#include <CD_NamespaceHeader.H>
22
24extern "C" void
25dgelss_(int* a_M,
26 int* a_N,
27 int* a_nRHS,
28 double* a_A,
29 int* a_LDA,
30 double* a_B,
31 int* a_LDB,
32 double* a_S,
33 double* a_rcond,
34 int* a_RANK,
35 double* a_WORK,
36 int* a_LWORK,
37 int* a_INFO);
38
39extern "C" void
40dgesdd_(char* a_JOBZ,
41 int* a_M,
42 int* a_N,
43 double* a_A,
44 int* a_LDA,
45 double* a_S,
46 double* a_U,
47 int* a_LDU,
48 double* a_VT,
49 int* a_LDVT,
50 double* a_WORK,
51 int* a_LWORK,
52 int* a_IWORK,
53 int* a_INFO);
54
55extern "C" void
56sgesdd_(char* a_JOBZ,
57 int* a_M,
58 int* a_N,
59 float* a_A,
60 int* a_LDA,
61 float* a_S,
62 float* a_U,
63 int* a_LDU,
64 float* a_VT,
65 int* a_LDVT,
66 float* a_WORK,
67 int* a_LWORK,
68 int* a_IWORK,
69 int* a_INFO);
70
71extern "C" void
72dgemm_(char* a_TRANSA,
73 char* a_TRANSB,
74 int* a_M,
75 int* a_N,
76 int* a_K,
77 double* a_ALPHA,
78 double* a_A,
79 int* a_LDA,
80 double* a_B,
81 int* a_LDB,
82 double* a_BETA,
83 double* a_C,
84 int* a_LDC);
85
86extern "C" void
87sgemm_(char* a_TRANSA,
88 char* a_TRANSB,
89 int* a_M,
90 int* a_N,
91 int* a_K,
92 float* a_ALPHA,
93 float* a_A,
94 int* a_LDA,
95 float* a_B,
96 int* a_LDB,
97 float* a_BETA,
98 float* a_C,
99 int* a_LDC);
100
101extern "C" void
102dgesv_(int* N, int* NRHS, double* A, int* LDA, int* IPIV, double* B, int* LDB, int* INFO);
104
108namespace LaPackUtils {
109
118int
119linearIndex(const int irow, const int jcol, const int M, const int N);
120
136bool
137computeSVD(std::vector<double>& a_linU,
138 std::vector<double>& a_linSigma,
139 std::vector<double>& a_linVtran,
140 const std::vector<double>& a_linA,
141 const int& a_M,
142 const int& a_N);
143
159bool
160computeSVD(std::vector<float>& a_linU,
161 std::vector<float>& a_linSigma,
162 std::vector<float>& a_linVtran,
163 const std::vector<float>& a_linA,
164 const int& a_M,
165 const int& a_N);
166
175bool
176computePseudoInverse(std::vector<double>& a_linAplus,
177 const std::vector<double>& a_linA,
178 const int& a_M,
179 const int& a_N);
180
189bool
190computePseudoInverse(std::vector<float>& a_linAplus, const std::vector<float>& a_linA, const int& a_M, const int& a_N);
191
201void
202linearizeMatrix(std::vector<double>& a_linA,
203 int& a_M,
204 int& a_N,
205 const std::vector<std::vector<double>>& a_A,
206 const char& a_format);
207
215void
216linearizeColumnMajorMatrix(std::vector<double>& a_linA,
217 int& a_M,
218 int& a_N,
219 const std::vector<std::vector<double>>& a_A);
220
228void
229linearizeRowMajorMatrix(std::vector<double>& a_linA, int& a_M, int& a_N, const std::vector<std::vector<double>>& a_A);
230
240void
241deLinearizeMatrix(std::vector<std::vector<double>>& a_A,
242 const int& a_M,
243 const int& a_N,
244 const std::vector<double>& a_linA,
245 const char& a_format);
246
254void
255deLinearizeColumnMajorMatrix(std::vector<std::vector<double>>& a_A,
256 const int& a_M,
257 const int& a_N,
258 const std::vector<double>& a_linA);
259
267void
268deLinearizeRowMajorMatrix(std::vector<std::vector<double>>& a_A,
269 const int& a_M,
270 const int& a_N,
271 const std::vector<double>& a_linA);
272} // namespace LaPackUtils
273
274#include <CD_NamespaceFooter.H>
275
276#endif
Namespace containing various useful linear algebra routines using LaPACK.
Definition CD_LaPackUtils.H:108
void deLinearizeMatrix(std::vector< std::vector< double > > &a_A, const int &a_M, const int &a_N, const std::vector< double > &a_linA, const char &a_format)
Delinearize a linearized matrix from column major Fortran to row or major column matrix format.
Definition CD_LaPackUtils.cpp:460
void deLinearizeRowMajorMatrix(std::vector< std::vector< double > > &a_A, const int &a_M, const int &a_N, const std::vector< double > &a_linA)
Delinearize a linearized matrix from column major Fortran to row major form.
Definition CD_LaPackUtils.cpp:439
void linearizeMatrix(std::vector< double > &a_linA, int &a_M, int &a_N, const std::vector< std::vector< double > > &a_A, const char &a_format)
Linearize a matrix to column major Fortran form by assuming row or major column format of the input m...
Definition CD_LaPackUtils.cpp:400
void linearizeRowMajorMatrix(std::vector< double > &a_linA, int &a_M, int &a_N, const std::vector< std::vector< double > > &a_A)
Linearize a matrix to column major Fortran form by row major format of the input matrix.
Definition CD_LaPackUtils.cpp:380
bool computeSVD(std::vector< double > &a_linU, std::vector< double > &a_linSigma, std::vector< double > &a_linVtran, const std::vector< double > &a_linA, const int &a_M, const int &a_N)
Compute the singular value decomposition of a matrix.
Definition CD_LaPackUtils.cpp:30
void linearizeColumnMajorMatrix(std::vector< double > &a_linA, int &a_M, int &a_N, const std::vector< std::vector< double > > &a_A)
Linearize a matrix to column major Fortran form by column major format of the input matrix.
Definition CD_LaPackUtils.cpp:360
int linearIndex(const int irow, const int jcol, const int M, const int N)
Get the index in the linearized matrix of size MxN.
Definition CD_LaPackUtils.cpp:24
bool computePseudoInverse(std::vector< double > &a_linAplus, const std::vector< double > &a_linA, const int &a_M, const int &a_N)
Compute the pseudoinverse of matrix through singular value decomposition.
Definition CD_LaPackUtils.cpp:164
void deLinearizeColumnMajorMatrix(std::vector< std::vector< double > > &a_A, const int &a_M, const int &a_N, const std::vector< double > &a_linA)
Delinearize a linearized matrix from column major Fortran to column major form.
Definition CD_LaPackUtils.cpp:418