OpenCAEPoro  0.2.0 Sep/22/2022
A simulator for multicomponent porous media flow
DenseMat.hpp
Go to the documentation of this file.
1 
12 #ifndef __DENSEMAT_HEADER__
13 #define __DENSEMAT_HEADER__
14 
15 // Standard header files
16 #include <algorithm>
17 #include <iomanip>
18 #include <iostream>
19 #include <string>
20 
21 using namespace std;
22 
23 extern "C" {
24 
26 
28 void dscal_(const int* n, const double* alpha, double* x, const int* incx);
29 
31 double ddot_(const int* n, double* a, const int* inca, double* b, const int* incb);
32 
34 int dcopy_(const int* n, const double* src, const int* incx, double* dst,
35  const int* incy);
36 
38 int daxpy_(const int* n, const double* alpha, const double* x, const int* incx,
39  double* y, const int* incy);
40 
42 double dnrm2_(const int* n, double* x, const int* incx);
43 
45 double dasum_(const int* n, double* x, const int* incx);
46 
48 int idamax_(const int* n, double* x, const int* incx);
49 
51 int dgemm_(const char* transa, const char* transb, const int* m, const int* n,
52  const int* k, const double* alpha, const double* A, const int* lda,
53  const double* B, const int* ldb, const double* beta, double* C,
54  const int* ldc);
55 
57 
59 int dgesv_(const int* n, const int* nrhs, double* A, const int* lda, int* ipiv,
60  double* b, const int* ldb, int* info);
61 
63 int dsysv_(const char* uplo, const int* n, const int* nrhs, double* A, const int* lda,
64  int* ipiv, double* b, const int* ldb, double* work, const int* lwork,
65  int* info);
66 
68 int ssyevd_(char* jobz, char* uplo, const int* n, float* A, const int* lda, float* w, float* work, const int* lwork,
69  int* iwork, const int* liwork, int* info);
70 
71 
72 }
73 
75 void MinEigenSY(const int& N, float* A, float* w, float* work, const int& lwork);
76 
78 // void MinEigenS(const int& N, float* a, float* w);
79 
81 void Dcopy(const int& N, double* dst, const double* src);
82 
84 double Ddot(int n, double* a, double* b);
85 
87 double Dnorm1(const int& N, double* x);
88 
90 double Dnorm2(const int& N, double* x);
91 
93 void Dscalar(const int& n, const double& alpha, double* x);
94 
96 void Daxpy(const int& n, const double& alpha, const double* x, double* y);
97 
99 void DaABpbC(const int& m, const int& n, const int& k, const double& alpha,
100  const double* A, const double* B, const double& beta, double* C);
101 
102 // test
103 void myDABpC(const int& m, const int& n, const int& k, const double* A, const double* B, double* C);
104 void myDABpCp(const int& m, const int& n, const int& k, const double* A, const double* B, double* C, const int* flag, const int N);
105 void myDABpCp1(const int& m, const int& n, const int& k, const double* A, const double* B, double* C, const int* flag, const int N);
106 void myDABpCp2(const int& m, const int& n, const int& k, const double* A, const double* B, double* C, const int* flag, const int N);
107 
109 void DaAxpby(const int& m, const int& n, const double& a, const double* A,
110  const double* x, const double& b, double* y);
111 
113 void LUSolve(const int& nrhs, const int& N, double* A, double* b, int* pivot);
114 
116 void SYSSolve(const int& nrhs, const char* uplo, const int& N, double* A,
117  double* b, int* pivot, double* work, const int& lwork);
118 
119 
121 template <typename T>
122 void PrintDX(const int& N, const T* x)
123 {
124  for (int i = 0; i < N; i++) {
125  cout << i << " " << setprecision(16) << x[i] << endl;
126  }
127  cout << endl;
128 }
129 
131 template <typename T>
132 bool CheckNan(const int& N, const T* x)
133 {
134  for (int i = 0; i < N; i++) {
135  if (!isfinite(x[i]) || isnan(x[i])) {
136  return false;
137  }
138  }
139  return true;
140 }
141 
142 #endif
143 
144 /*----------------------------------------------------------------------------*/
145 /* Brief Change History of This File */
146 /*----------------------------------------------------------------------------*/
147 /* Author Date Actions */
148 /*----------------------------------------------------------------------------*/
149 /* Shizhe Li Oct/24/2021 Create file */
150 /* Chensong Zhang Jan/16/2022 Update Doxygen */
151 /*----------------------------------------------------------------------------*/
void SYSSolve(const int &nrhs, const char *uplo, const int &N, double *A, double *b, int *pivot, double *work, const int &lwork)
Calls dsysy to solve the linear system for symm matrices.
Definition: DenseMat.cpp:199
double dasum_(const int *n, double *x, const int *incx)
Computes the sum of the absolute values of a vector.
int idamax_(const int *n, double *x, const int *incx)
Finds the index of element having max absolute value.
int dsysv_(const char *uplo, const int *n, const int *nrhs, double *A, const int *lda, int *ipiv, double *b, const int *ldb, double *work, const int *lwork, int *info)
Computes the solution to system of linear equations A * X = B for symm matrices.
int dgesv_(const int *n, const int *nrhs, double *A, const int *lda, int *ipiv, double *b, const int *ldb, int *info)
Computes the solution to system of linear equations A * X = B for general matrices.
double Ddot(int n, double *a, double *b)
Dot product of two double vectors stored as pointers.
Definition: DenseMat.cpp:43
void DaABpbC(const int &m, const int &n, const int &k, const double &alpha, const double *A, const double *B, const double &beta, double *C)
Computes C' = alpha B'A' + beta C', all matrices are column-major.
Definition: DenseMat.cpp:76
int ssyevd_(char *jobz, char *uplo, const int *n, float *A, const int *lda, float *w, float *work, const int *lwork, int *iwork, const int *liwork, int *info)
Computes the eigenvalues and, optionally, the leftand /or right eigenvectors for SY matrices.
int daxpy_(const int *n, const double *alpha, const double *x, const int *incx, double *y, const int *incy)
Constant times a vector plus a vector.
void Dscalar(const int &n, const double &alpha, double *x)
Scales a vector by a constant.
Definition: DenseMat.cpp:62
void DaAxpby(const int &m, const int &n, const double &a, const double *A, const double *x, const double &b, double *y)
Computes y = a A x + b y.
Definition: DenseMat.cpp:173
void LUSolve(const int &nrhs, const int &N, double *A, double *b, int *pivot)
Calls dgesv to solve the linear system for general matrices.
Definition: DenseMat.cpp:186
bool CheckNan(const int &N, const T *x)
check NaN
Definition: DenseMat.hpp:132
void Daxpy(const int &n, const double &alpha, const double *x, double *y)
Constant times a vector plus a vector.
Definition: DenseMat.cpp:69
int dcopy_(const int *n, const double *src, const int *incx, double *dst, const int *incy)
Copies a vector, src, to a vector, dst.
void MinEigenSY(const int &N, float *A, float *w, float *work, const int &lwork)
Calculate the minimal eigenvalue for sysmetric matrix with mkl lapack.
Definition: DenseMat.cpp:14
int dgemm_(const char *transa, const char *transb, const int *m, const int *n, const int *k, const double *alpha, const double *A, const int *lda, const double *B, const int *ldb, const double *beta, double *C, const int *ldc)
Performs matrix-matrix operations C : = alpha * op(A) * op(B) + beta * C.
double dnrm2_(const int *n, double *x, const int *incx)
Computes the Euclidean norm of a vector.
void dscal_(const int *n, const double *alpha, double *x, const int *incx)
Scales a vector by a constant.
double Dnorm1(const int &N, double *x)
Computes the L1-norm of a vector.
Definition: DenseMat.cpp:50
void PrintDX(const int &N, const T *x)
Prints a vector.
Definition: DenseMat.hpp:122
void Dcopy(const int &N, double *dst, const double *src)
Calculate the minimal eigenvalue for sysmetric matrix with mkl lapack.
Definition: DenseMat.cpp:37
double ddot_(const int *n, double *a, const int *inca, double *b, const int *incb)
Forms the dot product of two vectors.
double Dnorm2(const int &N, double *x)
Computes the L2-norm of a vector.
Definition: DenseMat.cpp:56