Flow123d  DF_patch_fe_data_tables-b828b90
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Static Private Attributes | 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 Types

typedef LinSys FactoryBaseType
 
- Public Types inherited from LinSys
enum  SetValuesMode {
  INSERT =INSERT_VALUES , ADD =ADD_VALUES , ALLOCATE , DONE ,
  NONE
}
 

Public Member Functions

 LinSys_PETSC (const Distribution *rows_ds, const std::string &params="")
 
 LinSys_PETSC (LinSys_PETSC &other)
 
void set_tolerances (double r_tol, double a_tol, double d_tol, unsigned int max_it) override
 
const Distributionget_ds ()
 
const Mat * get_matrix () override
 
const Vec * get_rhs () override
 
PetscErrorCode set_matrix (Mat &matrix, MatStructure str) override
 
PetscErrorCode set_rhs (Vec &rhs) override
 
PetscErrorCode mat_zero_entries () override
 
PetscErrorCode rhs_zero_entries () override
 
void start_allocation () override
 
void start_add_assembly () override
 
void start_insert_assembly () override
 
void mat_set_values (int nrow, int *rows, int ncol, int *cols, double *vals) override
 
void rhs_set_values (int nrow, int *rows, double *vals) override
 
void preallocate_values (int nrow, int *rows, int ncol, int *cols)
 
void preallocate_matrix ()
 
void finish_assembly () override
 
void finish_assembly (MatAssemblyType assembly_type)
 
void apply_constrains (double scalar=1.) override
 
void set_initial_guess_nonzero (bool set_nonzero=true)
 
LinSys::SolveInfo solve () override
 
double get_absolute_accuracy () override
 
void view (string text="") override
 
void set_from_input (const Input::Record in_rec) override
 
double get_solution_precision () override
 
double compute_residual () override
 
 ~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 (Vec sol_vec)
 
void set_solution (double *sol_array)
 
void set_solution ()
 
double * get_solution_array ()
 
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_local_system (LocalSystem &local)
 
void set_local_system (LocalSystem &local, const std::vector< LongIdx > &local_to_global_map)
 
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 ()
 

Static Public Member Functions

static const Input::Type::Recordget_input_type ()
 
- Static Public Member Functions inherited from LinSys
static Input::Type::Abstractget_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...
 
Vec residual_
 
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_
 
KSP system
 
KSPConvergedReason reason
 
- Protected Attributes inherited from LinSys
double r_tol_
 relative tolerance of linear solver More...
 
double a_tol_
 absolute tolerance of linear solver More...
 
double d_tol_
 tolerance for divergence of linear solver More...
 
unsigned int max_it_
 maximum number of iterations of linear solver More...
 
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_vec_
 Indicates if the solution vector has been allocated by this class. 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_
 

Private Member Functions

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

Static Private Attributes

static const int registrar = LinSys_PETSC::get_input_type().size()
 Registrar of class to factory. More...
 

Additional Inherited Members

- Protected Types inherited from LinSys
typedef std::pair< unsigned, double > Constraint_
 
typedef std::vector< Constraint_ConstraintVec_
 
- Static Protected Attributes inherited from LinSys
static constexpr double default_r_tol_ = 1e-7
 
static constexpr double default_a_tol_ = 1e-11
 
static constexpr double default_d_tol_ = 10000
 
static constexpr unsigned int default_max_it_ = 1000
 

Detailed Description

Definition at line 43 of file linsys_PETSC.hh.

Member Typedef Documentation

◆ FactoryBaseType

Definition at line 47 of file linsys_PETSC.hh.

Constructor & Destructor Documentation

◆ LinSys_PETSC() [1/2]

LinSys_PETSC::LinSys_PETSC ( const Distribution rows_ds,
const std::string &  params = "" 
)

Definition at line 64 of file linsys_PETSC.cc.

◆ LinSys_PETSC() [2/2]

LinSys_PETSC::LinSys_PETSC ( LinSys_PETSC other)

Copy constructor.

Definition at line 84 of file linsys_PETSC.cc.

◆ ~LinSys_PETSC()

LinSys_PETSC::~LinSys_PETSC ( )

Definition at line 464 of file linsys_PETSC.cc.

Member Function Documentation

◆ apply_constrains()

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

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 291 of file linsys_PETSC.cc.

◆ compute_residual()

double LinSys_PETSC::compute_residual ( )
overridevirtual

Explicitly compute residual and its norm for current solution.

Implements LinSys.

Reimplemented in SchurComplement.

Definition at line 493 of file linsys_PETSC.cc.

Here is the caller graph for this function:

◆ finish_assembly() [1/2]

void LinSys_PETSC::finish_assembly ( )
overridevirtual

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

Implements LinSys.

Definition at line 261 of file linsys_PETSC.cc.

Here is the caller graph for this function:

◆ finish_assembly() [2/2]

void LinSys_PETSC::finish_assembly ( MatAssemblyType  assembly_type)

Definition at line 267 of file linsys_PETSC.cc.

◆ get_absolute_accuracy()

double LinSys_PETSC::get_absolute_accuracy ( )
inlineoverridevirtual

Returns information on absolute solver accuracy

Reimplemented from LinSys.

Definition at line 131 of file linsys_PETSC.hh.

◆ get_ds()

const Distribution* LinSys_PETSC::get_ds ( )
inline

Returns whole Distribution class for distribution of the solution.

Definition at line 64 of file linsys_PETSC.hh.

◆ get_input_type()

const it::Record & LinSys_PETSC::get_input_type ( )
static

Definition at line 32 of file linsys_PETSC.cc.

Here is the caller graph for this function:

◆ get_matrix()

const Mat* LinSys_PETSC::get_matrix ( )
inlineoverridevirtual

Returns PETSC matrix (only for PETSC solvers)

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

Reimplemented from LinSys.

Definition at line 69 of file linsys_PETSC.hh.

Here is the caller graph for this function:

◆ get_rhs()

const Vec* LinSys_PETSC::get_rhs ( )
inlineoverridevirtual

Returns RHS vector (only for PETSC solvers)

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

Reimplemented from LinSys.

Definition at line 74 of file linsys_PETSC.hh.

Here is the caller graph for this function:

◆ get_solution_precision()

double LinSys_PETSC::get_solution_precision ( )
overridevirtual

Get precision of solving

Implements LinSys.

Reimplemented in SchurComplement.

Definition at line 487 of file linsys_PETSC.cc.

Here is the caller graph for this function:

◆ makePetscPointer_()

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

Definition at line 154 of file linsys_PETSC.hh.

Here is the caller graph for this function:

◆ mat_set_values()

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

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

Implements LinSys.

Definition at line 156 of file linsys_PETSC.cc.

◆ mat_zero_entries()

PetscErrorCode LinSys_PETSC::mat_zero_entries ( )
inlineoverridevirtual

Clears entries of the matrix

Reimplemented from LinSys.

Definition at line 91 of file linsys_PETSC.hh.

◆ preallocate_matrix()

void LinSys_PETSC::preallocate_matrix ( )

Definition at line 208 of file linsys_PETSC.cc.

Here is the caller graph for this function:

◆ preallocate_values()

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

Definition at line 190 of file linsys_PETSC.cc.

Here is the caller graph for this function:

◆ rhs_set_values()

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

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

Implements LinSys.

Definition at line 173 of file linsys_PETSC.cc.

◆ rhs_zero_entries()

PetscErrorCode LinSys_PETSC::rhs_zero_entries ( )
inlineoverridevirtual

Clears entries of the right-hand side

Reimplemented from LinSys.

Definition at line 98 of file linsys_PETSC.hh.

◆ set_from_input()

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

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

Reimplemented from LinSys.

Reimplemented in SchurComplement.

Definition at line 475 of file linsys_PETSC.cc.

Here is the caller graph for this function:

◆ set_initial_guess_nonzero()

void LinSys_PETSC::set_initial_guess_nonzero ( bool  set_nonzero = true)

Definition at line 336 of file linsys_PETSC.cc.

◆ set_matrix()

PetscErrorCode LinSys_PETSC::set_matrix ( Mat &  ,
MatStructure   
)
inlineoverridevirtual

Sets PETSC matrix (only for PETSC solvers)

Reimplemented from LinSys.

Definition at line 79 of file linsys_PETSC.hh.

◆ set_rhs()

PetscErrorCode LinSys_PETSC::set_rhs ( Vec &  )
inlineoverridevirtual

Sets RHS vector (only for PETSC solvers)

Reimplemented from LinSys.

Definition at line 85 of file linsys_PETSC.hh.

◆ set_tolerances()

void LinSys_PETSC::set_tolerances ( double  r_tol,
double  a_tol,
double  d_tol,
unsigned int  max_it 
)
overridevirtual

Set relative tolerance, absolute tolerance, and maximum number of iterations of the linear solver.

For each of these three parameters we first look for the value at user input if not set we use the value provided to this method and finally the default values are set by the call of this method in the constructor.

Implements LinSys.

Reimplemented in SchurComplement.

Definition at line 93 of file linsys_PETSC.cc.

Here is the caller graph for this function:

◆ solve()

LinSys::SolveInfo LinSys_PETSC::solve ( )
overridevirtual

Solve the system and return convergence reason.

Implements LinSys.

Reimplemented in SchurComplement.

Definition at line 342 of file linsys_PETSC.cc.

Here is the caller graph for this function:

◆ start_add_assembly()

void LinSys_PETSC::start_add_assembly ( )
overridevirtual

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

Reimplemented from LinSys.

Definition at line 120 of file linsys_PETSC.cc.

◆ start_allocation()

void LinSys_PETSC::start_allocation ( )
overridevirtual

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

Reimplemented from LinSys.

Definition at line 111 of file linsys_PETSC.cc.

◆ start_insert_assembly()

void LinSys_PETSC::start_insert_assembly ( )
overridevirtual

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

Reimplemented from LinSys.

Definition at line 138 of file linsys_PETSC.cc.

◆ view()

void LinSys_PETSC::view ( string  = "")
overridevirtual

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 428 of file linsys_PETSC.cc.

Member Data Documentation

◆ init_guess_nonzero

bool LinSys_PETSC::init_guess_nonzero
protected

flag for starting from nonzero guess

Definition at line 173 of file linsys_PETSC.hh.

◆ matrix_

Mat LinSys_PETSC::matrix_
protected

Petsc matrix of the problem.

Definition at line 175 of file linsys_PETSC.hh.

◆ off_vec_

Vec LinSys_PETSC::off_vec_
protected

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

Definition at line 182 of file linsys_PETSC.hh.

◆ on_vec_

Vec LinSys_PETSC::on_vec_
protected

Vectors for counting non-zero entries in diagonal block.

Definition at line 181 of file linsys_PETSC.hh.

◆ params_

std::string LinSys_PETSC::params_
protected

command-line-like options for the PETSc solver

Definition at line 171 of file linsys_PETSC.hh.

◆ reason

KSPConvergedReason LinSys_PETSC::reason
protected

Definition at line 188 of file linsys_PETSC.hh.

◆ registrar

const int LinSys_PETSC::registrar = LinSys_PETSC::get_input_type().size()
staticprivate

Registrar of class to factory.

Definition at line 150 of file linsys_PETSC.hh.

◆ residual_

Vec LinSys_PETSC::residual_
protected

Definition at line 177 of file linsys_PETSC.hh.

◆ rhs_

Vec LinSys_PETSC::rhs_
protected

PETSc vector constructed with vx array.

Definition at line 176 of file linsys_PETSC.hh.

◆ solution_precision_

double LinSys_PETSC::solution_precision_
protected

Definition at line 185 of file linsys_PETSC.hh.

◆ system

KSP LinSys_PETSC::system
protected

Definition at line 187 of file linsys_PETSC.hh.

◆ v_rhs_

double* LinSys_PETSC::v_rhs_
protected

local RHS array pointing to Vec rhs_

Definition at line 179 of file linsys_PETSC.hh.


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