Flow123d
master-d6c300039
|
Go to the documentation of this file.
33 return it::Record(
"Petsc",
"PETSc solver settings.\n It provides interface to various PETSc solvers. The convergence criteria is:\n"
35 "norm( res_i ) < max( norm( res_0 ) * r_tol, a_tol )\n"
37 "where ```res_i``` is the residuum vector after i-th iteration of the solver and ```res_0``` is the estimate of the norm of the initial residual. "
38 "If the initial guess of the solution is provided (usually only for transient equations) the residual of this estimate is used, "
39 "otherwise the norm of preconditioned RHS is used. "
40 "The default norm is (($L_2$)) norm of preconditioned residual: (($ P^{-1}(Ax-b)$)), usage of other norm may be prescribed using the 'option' key. "
41 "See also PETSc documentation for KSPSetNormType.")
44 "If not, we use the value 1.0e-7."),
45 "Residual tolerance relative to the initial error.")
47 "If not, we use the value 1.0e-11."),
48 "Absolute residual tolerance.")
50 "If not, we use the value 1000."),
51 "Maximum number of outer iterations of the linear solver.")
53 "If the string is left empty (by default), the internal default options is used.")
85 const char *petsc_dflt_opt;
100 petsc_dflt_opt=
"-ksp_type cg -ksp_diagonal_scale -ksp_diagonal_scale_fix -pc_type asm -pc_asm_type basic -pc_asm_overlap 4 -sub_pc_type icc -sub_pc_factor_levels 3 -sub_pc_factor_fill 6.0";
103 petsc_dflt_opt=
"-ksp_type bcgs -ksp_diagonal_scale -ksp_diagonal_scale_fix -pc_type asm -pc_asm_overlap 4 -sub_pc_type ilu -sub_pc_factor_levels 3 -sub_pc_factor_fill 6.0";
109 petsc_dflt_opt=
"-ksp_type cg -pc_type icc -pc_factor_levels 3 -ksp_diagonal_scale -ksp_diagonal_scale_fix -pc_factor_fill 6.0";
112 petsc_dflt_opt=
"-ksp_type bcgs -pc_type ilu -pc_factor_levels 5 -ksp_diagonal_scale -ksp_diagonal_scale_fix -pc_factor_fill 6.0";
116 LogOut().fmt(
"inserting petsc options: {}\n",
params_.c_str());
120 PetscOptionsInsertString(NULL,
params_.c_str());
122 MatSetOption(
matrix_, MAT_USE_INODES, PETSC_FALSE );
134 chkerr(QPTDualize(
system, MAT_INV_MONOLITHIC, MAT_REG_NONE));
153 QPSGetIterationNumber(
solver,&nits);
159 LogOut().fmt(
"convergence reason {}, number of iterations is {}\n",
reason, nits);
176 FilePath matFileName(text +
"_flow123d_matrix.m",FilePath::FileType::output_file);
177 FilePath rhsFileName(text +
"_flow123d_rhs.m",FilePath::FileType::output_file);
178 FilePath solFileName(text +
"_flow123d_sol.m",FilePath::FileType::output_file);
179 FilePath mat_ineqFileName(text +
"_flow123d_matrix_ineq.m",FilePath::FileType::output_file);
180 FilePath ineqFileName(text +
"_flow123d_ineq.m",FilePath::FileType::output_file);
182 PetscViewer myViewer;
185 PetscViewerASCIIOpen(
comm_,((
string)matFileName).c_str(),&myViewer);
186 PetscViewerSetFormat(myViewer,PETSC_VIEWER_ASCII_MATLAB);
188 PetscViewerDestroy(&myViewer);
191 WarningOut() <<
"PetscViewer: the matrix of LinSys is not set.\n";
193 if (
rhs_ != NULL ) {
194 PetscViewerASCIIOpen(
comm_,((
string)rhsFileName).c_str(),&myViewer);
195 PetscViewerSetFormat(myViewer,PETSC_VIEWER_ASCII_MATLAB);
196 VecView(
rhs_, myViewer );
197 PetscViewerDestroy(&myViewer);
200 WarningOut() <<
"PetscViewer: the rhs of LinSys is not set.\n";
203 PetscViewerASCIIOpen(
comm_,((
string)solFileName).c_str(),&myViewer);
204 PetscViewerSetFormat(myViewer,PETSC_VIEWER_ASCII_MATLAB);
206 PetscViewerDestroy(&myViewer);
209 WarningOut() <<
"PetscViewer: the solution of LinSys is not set.\n";
211 PetscViewerASCIIOpen(
comm_,((
string)mat_ineqFileName).c_str(),&myViewer);
212 PetscViewerSetFormat(myViewer,PETSC_VIEWER_ASCII_MATLAB);
214 PetscViewerDestroy(&myViewer);
217 WarningOut() <<
"PetscViewer: the inequality matrix of LinSys is not set.\n";
218 if (
ineq_ != NULL ) {
219 PetscViewerASCIIOpen(
comm_,((
string)ineqFileName).c_str(),&myViewer);
220 PetscViewerSetFormat(myViewer,PETSC_VIEWER_ASCII_MATLAB);
221 VecView(
ineq_, myViewer );
222 PetscViewerDestroy(&myViewer);
225 WarningOut() <<
"PetscViewer: the inequality vector of LinSys is not set.\n";
247 double residual_norm;
248 VecNorm(
residual_, NORM_2, &residual_norm);
249 return residual_norm;
unsigned int np() const
get num of processors
static const Input::Type::Record & get_input_type()
LinSys_PETSC::SolveInfo solve() override
std::string params_
command-line-like options for the PETSc solver
KSPConvergedReason reason
Dedicated class for storing path to input and output files.
void chkerr(unsigned int ierr)
Replacement of new/delete operator in the spirit of xmalloc.
Mat matrix_ineq_
PETSc matrix of inequality constraint.
double get_solution_precision() override
Mat matrix_
Petsc matrix of the problem.
static const int registrar
Registrar of class to factory.
LinSys_PERMON(const Distribution *rows_ds, const std::string ¶ms="")
void view(string text="") override
Vec solution_
PETSc vector constructed with vb array.
#define LogOut()
Macro defining 'log' record of log.
double a_tol_
absolute tolerance of linear solver
double solution_precision_
PERMON QP solvers and FETI.
double compute_residual() override
void set_inequality(Mat matrix_ineq, Vec ineq)
const Distribution * rows_ds_
final distribution of rows of MH matrix
double r_tol_
relative tolerance of linear solver
#define WarningOut()
Macro defining 'warning' record of log.
#define ADD_CALLS(n_calls)
Increase number of calls in actual timer.
static Input::Type::Abstract & get_input_type()
bool is_positive_definite()
Vec ineq_
PETSc vector of inequality constraint.
#define START_TIMER(tag)
Starts a timer with specified tag.
Vec rhs_
PETSc vector constructed with vx array.
unsigned int max_it_
maximum number of iterations of linear solver