|
SPI
SLEPc PETSc Interface is used for rapid development and intuitive matrix operations similar to MatLab or NumPy style of operations
|
Go to the documentation of this file.
15 using Block2D = std::vector<std::vector<T>>;
22 SPIMat(std::string _name=
"SPIMat");
23 SPIMat(
const std::vector<SPIVec> &A, std::string _name=
"SPIMat");
25 SPIMat(PetscInt rowscols, std::string _name=
"SPIMat");
26 SPIMat(PetscInt rowsm, PetscInt colsn, std::string _name=
"SPIMat");
35 PetscInt
Init(PetscInt m,PetscInt n, std::string
name=
"SPIMat");
36 SPIMat&
set(PetscInt m, PetscInt n,
const PetscScalar v);
38 SPIMat&
add(PetscInt m, PetscInt n,
const PetscScalar v);
40 PetscScalar
operator()(PetscInt m, PetscInt n, PetscBool global=PETSC_FALSE);
41 PetscScalar
operator()(PetscInt m, PetscInt n, PetscBool global=PETSC_FALSE)
const;
100 std::tuple<std::vector<PetscReal>,std::vector<SPIVec>,std::vector<SPIVec>>
svd(
const SPIMat &A);
103 std::tuple<PetscScalar,SPIVec,SPIVec>
eig(
const SPIMat &A,
const SPIMat &B,
const PetscScalar target,
const PetscReal tol=-1,
const PetscInt max_iter=-1);
104 std::tuple<PetscScalar,SPIVec>
eig_right(
const SPIMat &A,
const SPIMat &B,
const PetscScalar target,
const PetscReal tol=-1,
const PetscInt max_iter=-1);
105 std::tuple<PetscScalar,SPIVec, SPIVec>
eig_init(
const SPIMat &A,
const SPIMat &B,
const PetscScalar target,
const SPIVec &ql,
const SPIVec &qr, PetscReal tol=-1,
const PetscInt max_iter=-1);
106 std::tuple<PetscScalar, SPIVec>
eig_init_right(
const SPIMat &A,
const SPIMat &B,
const PetscScalar target,
const SPIVec &qr, PetscReal tol=-1,
const PetscInt max_iter=-1);
107 std::tuple<std::vector<PetscScalar>, std::vector<SPIVec>>
eig_init_rights(
const SPIMat &A,
const SPIMat &B,
const std::vector<PetscScalar> targets,
const std::vector<SPIVec> &qrs, PetscReal tol=-1,
const PetscInt max_iter=-1);
108 std::tuple<PetscScalar,SPIVec>
polyeig(
const std::vector<SPIMat> &As,
const PetscScalar target,
const PetscReal tol=-1.,
const PetscInt max_iter=-1);
109 std::tuple<PetscScalar,SPIVec>
polyeig_init(
const std::vector<SPIMat> &As,
const PetscScalar target,
const SPIVec &qr,
const PetscReal tol=-1.,
const PetscInt max_iter=-1);
114 PetscInt
save(
const SPIMat &A,
const std::string filename);
115 PetscInt
save(
const std::vector<SPIMat> &A,
const std::string filename);
116 PetscInt
load(
SPIMat &A,
const std::string filename);
117 PetscInt
load(std::vector<SPIMat> &A,
const std::string filename);
PetscBool flag_init
flag if it has been initialized
SPIMat operator^(const PetscScalar a, const SPIMat &A)
Y=a^A operation.
SPIMat sin(const SPIMat &A)
take the sin of each element in a matrix
std::tuple< PetscScalar, SPIVec > polyeig(const std::vector< SPIMat > &As, const PetscScalar target, const PetscReal tol=-1., const PetscInt max_iter=-1)
solve general polynomial eigenvalue problem of (A0 + A1*alpha + A2*alpha^2 + ...)*x = 0 and return a ...
std::tuple< PetscScalar, SPIVec > polyeig_init(const std::vector< SPIMat > &As, const PetscScalar target, const SPIVec &qr, const PetscReal tol=-1., const PetscInt max_iter=-1)
solve general polynomial eigenvalue problem of (A0 + A1*alpha + A2*alpha^2 + ...)*x = 0 and return a ...
PetscInt print()
print mat to screen using PETSC_VIEWER_STDOUT_WORLD
PetscInt rows
number of rows in mat
SPIMat & zero_rows(std::vector< PetscInt > rows)
set rows to zero
PetscInt Init(PetscInt m, PetscInt n, std::string name="SPIMat")
SPIMat & operator+=(const SPIMat &X)
MatAXPY, Y = 1.*X + Y operation.
std::tuple< PetscScalar, SPIVec > eig_right(const SPIMat &A, const SPIMat &B, const PetscScalar target, const PetscReal tol=-1, const PetscInt max_iter=-1)
solve general eigenvalue problem of Ax = kBx and return a tuple of tie(PetscScalar alpha,...
SPIVec lstsq(const SPIMat &A, SPIVec &y)
solve least squares problem of A*x=y for skinny A matrix using SVD
std::vector< std::vector< T > > Block2D
std::string name
Matrix name.
SPIMat & operator/=(const PetscScalar a)
Y = Y/a operation.
SPIMat & operator-=(const SPIMat &X)
Y = -1.*X + Y operation.
SPIMat & operator()()
assmelbe the matrix
PetscInt save(const SPIMat &A, const std::string filename)
save matrix to filename in binary format (see Petsc documentation for format ) Format is (from Petsc ...
PetscErrorCode ierr
ierr for various routines and operators
SPIMat & add(PetscInt m, PetscInt n, const PetscScalar v)
add a scalar value at position row m and column n
SPIMat kron(const SPIMat &A, const SPIMat &B)
set kronecker inner product of two matrices
SPIMat(std::string _name="SPIMat")
constructor with no arguments (no initialization)
SPIMat & axpy(const PetscScalar a, const SPIMat &X)
MatAXPY function call to add a*X to the current mat.
SPIMat operator-() const
-X operation
SPIMat & zero_row_full(const PetscInt row)
set a row to zero using dense format
SPIVec diag()
get diagonal of matrix
SPIMat _Function_on_each_element(T(*f)(T const &), const SPIMat &A)
take the function of each element in a matrix, e.g. (*f)(A(i,j)) for each i,j
SPIMat & operator*=(const PetscScalar a)
Y = Y*a operation.
SPIMat eye(const PetscInt n)
create, form, and return identity matrix of size n
SPIMat inv(const SPIMat &A)
Solve linear system A*Ainv=B using MatMatSolve.
std::vector< SPIVec > orthogonalize(std::vector< SPIVec > &x, SPIgrid1D &grid)
PetscInt draw(const SPIMat &A)
draw nonzero structure of matrix
~SPIMat()
destructor to delete memory
SPIMat tan(const SPIMat &A)
take the tan of each element in a matrix
SPIMat diag(const SPIVec &diag, const PetscInt k=0)
set diagonal of matrix
SPIMat & T()
Transpose the current mat.
SPIMat operator+(const SPIMat &X)
Y + X operation.
SPIMat abs(const SPIMat &A)
take the abs of each element in a matrix
SPIMat & eye_row(const PetscInt row)
set a row to zero and set 1 in diagonal entry
std::tuple< std::vector< PetscScalar >, std::vector< SPIVec > > eig_init_rights(const SPIMat &A, const SPIMat &B, const std::vector< PetscScalar > targets, const std::vector< SPIVec > &qrs, PetscReal tol=-1, const PetscInt max_iter=-1)
solve general eigenvalue problem of Ax = kBx and return a tuple of tie(PetscScalar alpha,...
SPIVec solve(const SPIMat &A, const SPIVec &b)
Solve linear system, Ax=b using solve(A,b) notation.
SPIMat operator*(const PetscScalar a)
Y*a operation.
std::tuple< PetscScalar, SPIVec, SPIVec > eig_init(const SPIMat &A, const SPIMat &B, const PetscScalar target, const SPIVec &ql, const SPIVec &qr, PetscReal tol=-1, const PetscInt max_iter=-1)
solve general eigenvalue problem of Ax = kBx and return a tuple of tie(PetscScalar alpha,...
SPIMat & real()
take the real part of the vector
SPIMat & H()
Hermitian Transpose the current mat.
PetscInt load(SPIMat &A, const std::string filename)
load matrix from filename from binary format (works with save(SPIMat,std::string) function
SPIMat operator%(const SPIMat &A, const SPIMat &B)
take the elementwise multiplication of each element in a matrix
SPIMat block(const Block2D< SPIMat > Blocks)
set block matrices using an input array of size rows*cols. Fills rows first
SPIMat & conj()
elemenwise conjugate current matrix
SPIMat operator/(const PetscScalar a)
Z = Y/a operation.
SPIMat acos(const SPIMat &A)
take the arccos of each element in a matrix
SPIMat & set(PetscInt m, PetscInt n, const PetscScalar v)
SPIMat operator*(const PetscScalar a, const SPIMat A)
a*A operation to be equivalent to A*a
std::tuple< PetscScalar, SPIVec > eig_init_right(const SPIMat &A, const SPIMat &B, const PetscScalar target, const SPIVec &qr, PetscReal tol=-1, const PetscInt max_iter=-1)
solve general eigenvalue problem of Ax = kBx and return a tuple of tie(PetscScalar alpha,...
SPIMat & operator=(const SPIMat &A)
Y=X with initialization of Y using MatConvert.
std::tuple< SPIMat, SPIMat > meshgrid(SPIVec &x, SPIVec &y)
SPIVec col(const PetscInt i)
get column vector
std::tuple< PetscScalar, SPIVec, SPIVec > eig(const SPIMat &A, const SPIMat &B, const PetscScalar target, const PetscReal tol=-1, const PetscInt max_iter=-1)
solve general eigenvalue problem of Ax = kBx and return a tuple of tie(PetscScalar alpha,...
SPIMat cos(const SPIMat &A)
take the cos of each element in a matrix
SPIMat & zero_row(const PetscInt row)
set a row to zero
SPIVec operator/(const SPIVec &b, const SPIMat &A)
Solve linear system, Ax=b using b/A notation.
SPIMat & set_col(const PetscInt col, const SPIVec &v)
std::tuple< std::vector< PetscReal >, std::vector< SPIVec >, std::vector< SPIVec > > svd(const SPIMat &A)
solve SVD problem of A=U*E*V^H for skinny A matrix
SPIMat zeros(const PetscInt m, const PetscInt n)
create, form, and return zeros matrix of size mxn
PetscInt cols
number of columns in mat
SPIMat & eye_rows(std::vector< PetscInt > rows)
set rows to zero and set main diagonal to 1