Flow123d
Classes | Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | List of all members
LinSys_PETSC Class Reference

#include <linsys_PETSC.hh>

Inheritance diagram for LinSys_PETSC:
Inheritance graph
[legend]
Collaboration diagram for LinSys_PETSC:
Collaboration graph
[legend]

Classes

struct  PetscScalar2Double_
 

Public Member Functions

 LinSys_PETSC (const Distribution *rows_ds)
 
 LinSys_PETSC (LinSys_PETSC &other)
 
const Distributionget_ds ()
 
const Mat & get_matrix ()
 
const Vec & get_rhs ()
 
PetscErrorCode set_matrix (Mat &matrix, MatStructure str)
 
PetscErrorCode set_rhs (Vec &rhs)
 
PetscErrorCode mat_zero_entries ()
 
PetscErrorCode rhs_zero_entries ()
 
void start_allocation ()
 
void start_add_assembly ()
 
void start_insert_assembly ()
 
void mat_set_values (int nrow, int *rows, int ncol, int *cols, double *vals)
 
void rhs_set_values (int nrow, int *rows, double *vals)
 
void preallocate_values (int nrow, int *rows, int ncol, int *cols)
 
void preallocate_matrix ()
 
void finish_assembly ()
 
void finish_assembly (MatAssemblyType assembly_type)
 
void apply_constrains (double scalar=1.)
 
void set_initial_guess_nonzero (bool set_nonzero=true)
 
int solve ()
 
double get_absolute_accuracy ()
 
void get_whole_solution (std::vector< double > &globalSolution)
 
void view ()
 
void set_from_input (const Input::Record in_rec)
 
double get_solution_precision ()
 
 ~LinSys_PETSC ()
 
- Public Member Functions inherited from LinSys
 LinSys (const Distribution *rows_ds)
 
 LinSys (LinSys &other)
 
unsigned int size ()
 
unsigned int vec_lsize ()
 
void set_matrix_changed ()
 
void set_rhs_changed ()
 
bool is_matrix_changed ()
 
bool is_rhs_changed ()
 
const Vec & get_solution ()
 
void set_solution (double *sol_array)
 
double * get_solution_array ()
 
virtual void set_whole_solution (std::vector< double > &globalSolution)
 
void mat_set_value (int row, int col, double val)
 
void rhs_set_value (int row, double val)
 
void set_values (int nrow, int *rows, int ncol, int *cols, PetscScalar *mat_vals, PetscScalar *rhs_vals)
 Set values in the system matrix and values in the right-hand side vector on corresponding rows. More...
 
void set_values (std::vector< int > &row_dofs, std::vector< int > &col_dofs, const arma::mat &matrix, const arma::vec &rhs, const arma::vec &row_solution, const arma::vec &col_solution)
 
void add_constraint (int row, double value)
 
double get_residual_norm ()
 
double get_relative_accuracy ()
 
void set_symmetric (bool flag=true)
 
bool is_symmetric ()
 
void set_positive_definite (bool flag=true)
 
void set_negative_definite (bool flag=true)
 
bool is_positive_definite ()
 
bool is_negative_definite ()
 
bool is_new ()
 
bool is_preallocated ()
 
void set_spd_via_symmetric_general (bool flag=true)
 
bool is_spd_via_symmetric_general ()
 
virtual ~LinSys ()
 
 LinSys (unsigned int lsize, double *sol_array=NULL)
 
unsigned int size ()
 
unsigned int vec_lsize ()
 
const Distributionds ()
 
const Mat & get_matrix ()
 
const Vec & get_rhs ()
 
const Vec & get_solution ()
 
double * get_solution_array ()
 
void start_add_assembly ()
 
void start_insert_assembly ()
 
void partial_assembly ()
 
void finish_assembly ()
 
virtual void mat_set_values (int nrow, int *rows, int ncol, int *cols, PetscScalar *vals)=0
 
void mat_set_value (int row, int col, PetscScalar val)
 
void rhs_set_values (int nrow, int *rows, PetscScalar *vals)
 
void rhs_set_value (int row, PetscScalar val)
 
void set_values (int nrow, int *rows, int ncol, int *cols, PetscScalar *mat_vals, PetscScalar *rhs_vals, std::vector< bool > &constrains_row_mask=std::vector(0), double *constrain_values=NULL)
 
void add_constrain (int row, double value)
 
void apply_constrains (std::vector< Constrain > &constraints)
 
void set_symmetric (bool flag=true)
 
bool is_symmetric ()
 
void set_positive_definite (bool flag=true)
 
bool is_positive_definite ()
 
void view (std::ostream output_stream, int *output_mapping=NULL)
 
virtual ~LinSys ()
 

Static Public Attributes

static Input::Type::Record input_type
 
- Static Public Attributes inherited from LinSys
static Input::Type::AbstractRecord input_type
 

Protected Attributes

std::string params_
 command-line-like options for the PETSc solver More...
 
bool init_guess_nonzero
 flag for starting from nonzero guess More...
 
Mat matrix_
 Petsc matrix of the problem. More...
 
Vec rhs_
 PETSc vector constructed with vx array. More...
 
double * v_rhs_
 local RHS array pointing to Vec rhs_ More...
 
Vec on_vec_
 Vectors for counting non-zero entries in diagonal block. More...
 
Vec off_vec_
 Vectors for counting non-zero entries in off-diagonal block. More...
 
double solution_precision_
 
- Protected Attributes inherited from LinSys
double r_tol_
 
double a_tol_
 
int max_it_
 
MPI_Comm comm_
 
SetValuesMode status_
 Set value status of the linear system. More...
 
const unsigned lsize_
 local number of matrix rows (non-overlapping division of rows) More...
 
unsigned size_
 global number of matrix rows, i.e. problem size More...
 
const Distributionrows_ds_
 final distribution of rows of MH matrix More...
 
bool symmetric_
 
bool positive_definite_
 
bool negative_definite_
 
bool spd_via_symmetric_general_
 
bool matrix_changed_
 true if the matrix was changed since the last solve More...
 
bool rhs_changed_
 true if the right hand side was changed since the last solve More...
 
Vec solution_
 PETSc vector constructed with vb array. More...
 
double * v_solution_
 local solution array pointing into Vec solution_ More...
 
bool own_solution_
 Indicates if the solution array has been allocated by this class. More...
 
double residual_norm_
 local solution array pointing into Vec solution_ More...
 
ConstraintVec_ constraints_
 
std::vector< double > globalSolution_
 global solution in numbering for linear system More...
 
Input::Record in_rec_
 
Distribution vec_ds
 Distribution of continuous blocks of system rows among the processors. More...
 
bool symmetric
 Flag for the symmetric system. More...
 
bool positive_definite
 Flag for positive definite system. More...
 
bool own_solution
 Indicates if the solution array has been allocated by this class. More...
 
SetValuesMode status
 Set value status of the linear system. More...
 
Mat matrix
 Petsc matrix of the problem. More...
 
Vec rhs
 PETSc vector constructed with vx array. More...
 
Vec solution
 PETSc vector constructed with vb array. More...
 
double * v_rhs
 RHS vector. More...
 
double * v_solution
 Vector of solution. More...
 
int * subdomain_indices
 Remember indices which created mapping. More...
 
Mat local_matrix
 local matrix of subdomain (used in LinSys_MATIS) More...
 

Private Member Functions

template<typename T >
T * makePetscPointer_ (std::vector< T > &array)
 
void gatherSolution_ ()
 

Additional Inherited Members

- Public Types inherited from LinSys
enum  SetValuesMode {
  INSERT =INSERT_VALUES, ADD =ADD_VALUES, ALLOCATE, DONE,
  NONE, INSERT =INSERT_VALUES, ADD =ADD_VALUES, ALLOCATE,
  DONE, NONE
}
 
enum  SetValuesMode {
  INSERT =INSERT_VALUES, ADD =ADD_VALUES, ALLOCATE, DONE,
  NONE, INSERT =INSERT_VALUES, ADD =ADD_VALUES, ALLOCATE,
  DONE, NONE
}
 
enum  LinSysType { PETSC_MPIAIJ_preallocate_by_assembly, PETSC_MPIAIJ_assembly_by_triples, BDDC, PETSC_schur_complement }
 
- Public Attributes inherited from LinSys
LinSysType type
 Particular type of the linear system. More...
 
- Protected Types inherited from LinSys
typedef std::pair< unsigned,
double > 
Constraint_
 
typedef std::vector< Constraint_ConstraintVec_
 

Detailed Description

Definition at line 42 of file linsys_PETSC.hh.

Constructor & Destructor Documentation

LinSys_PETSC::LinSys_PETSC ( const Distribution rows_ds)

Definition at line 48 of file linsys_PETSC.cc.

LinSys_PETSC::LinSys_PETSC ( LinSys_PETSC other)

Copy constructor.

Definition at line 70 of file linsys_PETSC.cc.

LinSys_PETSC::~LinSys_PETSC ( )

Definition at line 414 of file linsys_PETSC.cc.

Member Function Documentation

void LinSys_PETSC::apply_constrains ( double  scalar = 1.)
virtual

Apply constrains to assembled matrix. Constrains are given by pairs: global row index, value. i.e. typedef pair<unsigned int, double> Constrain;

What is th meaning of ( const double factor ) form Cambridge code?

Implements LinSys.

Definition at line 249 of file linsys_PETSC.cc.

void LinSys_PETSC::finish_assembly ( )
virtual

Finish assembly of the whole system. For PETSC this should call MatEndAssembly with MAT_FINAL_ASSEMBLY

Implements LinSys.

Definition at line 224 of file linsys_PETSC.cc.

Here is the caller graph for this function:

void LinSys_PETSC::finish_assembly ( MatAssemblyType  assembly_type)

Definition at line 230 of file linsys_PETSC.cc.

void LinSys_PETSC::gatherSolution_ ( )
private

< large vector of global solution stored locally

< scatter for gathering local parts into large vector

Definition at line 424 of file linsys_PETSC.cc.

Here is the caller graph for this function:

double LinSys_PETSC::get_absolute_accuracy ( )
inlinevirtual

Returns information on absolute solver accuracy

Reimplemented from LinSys.

Definition at line 124 of file linsys_PETSC.hh.

const Distribution* LinSys_PETSC::get_ds ( )
inline

Returns whole Distribution class for distribution of the solution.

Definition at line 58 of file linsys_PETSC.hh.

const Mat& LinSys_PETSC::get_matrix ( )
inlinevirtual

Returns PETSC matrix (only for PETSC solvers)

If matrix is changed, method set_matrix_changed() must be called. Example: MatDiagonalSet(schur->get_matrix(), new_diagonal, ADD_VALUES); schur->set_matrix_changed();

Reimplemented from LinSys.

Definition at line 63 of file linsys_PETSC.hh.

Here is the caller graph for this function:

const Vec& LinSys_PETSC::get_rhs ( )
inlinevirtual

Returns RHS vector (only for PETSC solvers)

If vector is changed, method set_rhs_changed() must be called. Example: VecScale(schur->get_rhs(), -1.0); schur->set_rhs_changed();

Reimplemented from LinSys.

Definition at line 68 of file linsys_PETSC.hh.

Here is the caller graph for this function:

double LinSys_PETSC::get_solution_precision ( )
virtual

Get precision of solving

Implements LinSys.

Reimplemented in SchurComplement.

Definition at line 479 of file linsys_PETSC.cc.

Here is the caller graph for this function:

void LinSys_PETSC::get_whole_solution ( std::vector< double > &  globalSolution)
virtual

Returns whole solution vector.

Reimplemented from LinSys.

Definition at line 381 of file linsys_PETSC.cc.

template<typename T >
T* LinSys_PETSC::makePetscPointer_ ( std::vector< T > &  array)
inlineprivate

Definition at line 144 of file linsys_PETSC.hh.

Here is the caller graph for this function:

void LinSys_PETSC::mat_set_values ( int  nrow,
int *  rows,
int  ncol,
int *  cols,
double *  vals 
)
virtual

Assembly full rectangular submatrix into the system matrix. Should be virtual, implemented differently in particular solvers.

Implements LinSys.

Definition at line 124 of file linsys_PETSC.cc.

PetscErrorCode LinSys_PETSC::mat_zero_entries ( )
inlinevirtual

Clears entries of the matrix

Reimplemented from LinSys.

Definition at line 85 of file linsys_PETSC.hh.

void LinSys_PETSC::preallocate_matrix ( )
virtual

Protected methods used in preallocate_by_assembly solvers.

Implements LinSys.

Definition at line 178 of file linsys_PETSC.cc.

Here is the caller graph for this function:

void LinSys_PETSC::preallocate_values ( int  nrow,
int *  rows,
int  ncol,
int *  cols 
)
virtual

Protected methods used in preallocate_by_assembly solvers.

Implements LinSys.

Definition at line 160 of file linsys_PETSC.cc.

Here is the caller graph for this function:

void LinSys_PETSC::rhs_set_values ( int  nrow,
int *  rows,
double *  vals 
)
virtual

Set values of the system right-hand side. Should be virtual, implemented differently in particular solvers.

Implements LinSys.

Definition at line 143 of file linsys_PETSC.cc.

PetscErrorCode LinSys_PETSC::rhs_zero_entries ( )
inlinevirtual

Clears entries of the right-hand side

Reimplemented from LinSys.

Definition at line 91 of file linsys_PETSC.hh.

void LinSys_PETSC::set_from_input ( const Input::Record  in_rec)
virtual

Sets specific parameters of LinSys_PETSC defined by user in input file and used to calculate

Reimplemented from LinSys.

Definition at line 466 of file linsys_PETSC.cc.

Here is the caller graph for this function:

void LinSys_PETSC::set_initial_guess_nonzero ( bool  set_nonzero = true)

Definition at line 294 of file linsys_PETSC.cc.

PetscErrorCode LinSys_PETSC::set_matrix ( Mat &  matrix,
MatStructure  str 
)
inlinevirtual

Sets PETSC matrix (only for PETSC solvers)

Reimplemented from LinSys.

Definition at line 73 of file linsys_PETSC.hh.

PetscErrorCode LinSys_PETSC::set_rhs ( Vec &  rhs)
inlinevirtual

Sets RHS vector (only for PETSC solvers)

Reimplemented from LinSys.

Definition at line 79 of file linsys_PETSC.hh.

int LinSys_PETSC::solve ( )
virtual

Solve the system and return convergence reason.

Implements LinSys.

Reimplemented in SchurComplement.

Definition at line 300 of file linsys_PETSC.cc.

Here is the caller graph for this function:

void LinSys_PETSC::start_add_assembly ( )
virtual

Switch linear system into adding assembly. (the only one supported by triplets ??)

Reimplemented from LinSys.

Definition at line 88 of file linsys_PETSC.cc.

void LinSys_PETSC::start_allocation ( )
virtual

Switch linear system into allocating assembly. (only for PETSC_MPIAIJ_preallocate_by_assembly)

Reimplemented from LinSys.

Definition at line 79 of file linsys_PETSC.cc.

void LinSys_PETSC::start_insert_assembly ( )
virtual

Switch linear system into insert assembly. (not currently used)

Reimplemented from LinSys.

Definition at line 106 of file linsys_PETSC.cc.

void LinSys_PETSC::view ( )
virtual

Output the system in the Matlab format possibly with given ordering. Rather we shoud provide output operator <<, since it is more flexible.

Reimplemented from LinSys.

Definition at line 388 of file linsys_PETSC.cc.

Member Data Documentation

bool LinSys_PETSC::init_guess_nonzero
protected

flag for starting from nonzero guess

Definition at line 165 of file linsys_PETSC.hh.

it::Record LinSys_PETSC::input_type
static
Initial value:
= it::Record("Petsc", "Solver setting.")
.declare_key("a_tol", it::Double(0.0), it::Default("1.0e-9"), "Absolute residual tolerance.")
.declare_key("options", it::String(), it::Default(""), "Options passed to PETSC before creating KSP instead of default setting.")

Definition at line 46 of file linsys_PETSC.hh.

Mat LinSys_PETSC::matrix_
protected

Petsc matrix of the problem.

Definition at line 167 of file linsys_PETSC.hh.

Vec LinSys_PETSC::off_vec_
protected

Vectors for counting non-zero entries in off-diagonal block.

Definition at line 173 of file linsys_PETSC.hh.

Vec LinSys_PETSC::on_vec_
protected

Vectors for counting non-zero entries in diagonal block.

Definition at line 172 of file linsys_PETSC.hh.

std::string LinSys_PETSC::params_
protected

command-line-like options for the PETSc solver

Definition at line 163 of file linsys_PETSC.hh.

Vec LinSys_PETSC::rhs_
protected

PETSc vector constructed with vx array.

Definition at line 168 of file linsys_PETSC.hh.

double LinSys_PETSC::solution_precision_
protected

Definition at line 175 of file linsys_PETSC.hh.

double* LinSys_PETSC::v_rhs_
protected

local RHS array pointing to Vec rhs_

Definition at line 170 of file linsys_PETSC.hh.


The documentation for this class was generated from the following files: