23         cout << 
"The input file " << myfile << 
" is missing!" << endl;
 
   24         myfile = 
solveDir + 
"../conf/csr.fasp";
 
   27             cout << 
"The input file " << myfile << 
" is missing!" << endl;
 
   28             cout << 
"Using the default parameters of FASP" << endl;
 
   31             cout << 
"Using the input file " << myfile << endl;
 
   32             fasp_param_input(myfile.data(), &
inParam);
 
   36         fasp_param_input(myfile.data(), &
inParam);
 
   41 void ScalarFaspSolver::Allocate(
const vector<USI>& rowCapacity, 
const OCP_USI& maxDim,
 
   45     for (
OCP_USI n = 0; n < maxDim; n++) {
 
   46         nnz += rowCapacity[n];
 
   48     A = fasp_dcsr_create(maxDim, maxDim, nnz);
 
   51 void ScalarFaspSolver::InitParam()
 
   54     inParam.print_level = PRINT_MIN;
 
   58     inParam.solver_type  = SOLVER_VFGMRES;
 
   59     inParam.precond_type = PREC_AMG;
 
   60     inParam.stop_type    = STOP_REL_RES;
 
   78     inParam.SWZ_blksolver = SOLVER_DEFAULT;
 
   83     inParam.AMG_cycle_type          = V_CYCLE;
 
   84     inParam.AMG_smoother            = SMOOTHER_GS;
 
   85     inParam.AMG_smooth_order        = CF_ORDER;
 
   87     inParam.AMG_postsmooth_iter     = 1;
 
   95     inParam.AMG_coarse_scaling      = OFF;
 
   97     inParam.AMG_nl_amli_krylov_type = 2;
 
  100     inParam.AMG_coarsening_type      = 1;
 
  101     inParam.AMG_interpolation_type   = 1;
 
  103     inParam.AMG_strong_threshold     = 0.3;
 
  104     inParam.AMG_truncation_threshold = 0.2;
 
  105     inParam.AMG_aggressive_level     = 0;
 
  106     inParam.AMG_aggressive_path      = 1;
 
  109     inParam.AMG_aggregation_type   = PAIRWISE;
 
  110     inParam.AMG_quality_bound      = 8.0;
 
  112     inParam.AMG_strong_coupled     = 0.25;
 
  113     inParam.AMG_max_aggregation    = 9;
 
  114     inParam.AMG_tentative_smooth   = 0.67;
 
  115     inParam.AMG_smooth_filter      = ON;
 
  116     inParam.AMG_smooth_restriction = ON;
 
  119 void ScalarFaspSolver::AssembleMat(
const vector<vector<USI>>&     colId,
 
  120                                    const vector<vector<OCP_DBL>>& val,
 
  122                                    vector<OCP_DBL>& rhs, vector<OCP_DBL>& u)
 
  131     for (
OCP_USI i = 0; i < dim; i++) {
 
  132         nnz += colId[i].size();
 
  142     for (
OCP_USI i = 1; i < dim + 1; i++) {
 
  143         USI nnz_Row = colId[i - 1].size();
 
  144         A.IA[i]     = A.IA[i - 1] + nnz_Row;
 
  146         for (
USI j = 0; j < nnz_Row; j++) {
 
  147             A.JA[count]  = colId[i - 1][j];
 
  148             A.val[count] = val[i - 1][j];
 
  154 OCP_INT ScalarFaspSolver::Solve()
 
  164         const char* outputfile = 
"out/Solver.out";
 
  165         printf(
"Redirecting outputs to file: %s ...\n", outputfile);
 
  166         freopen(outputfile, 
"w", stdout); 
 
  170     if (solver_type >= 1 && solver_type <= 20) {
 
  173         if (precond_type == PREC_NULL) {
 
  174             status = fasp_solver_dcsr_krylov(&A, &b, &x, &
itParam);
 
  178         else if (precond_type == PREC_DIAG) {
 
  179             status = fasp_solver_dcsr_krylov_diag(&A, &b, &x, &
itParam);
 
  183         else if (precond_type == PREC_AMG || precond_type == PREC_FMG) {
 
  184             if (print_level > PRINT_NONE) fasp_param_amg_print(&
amgParam);
 
  189         else if (precond_type == PREC_ILU) {
 
  190             if (print_level > PRINT_NONE) fasp_param_ilu_print(&
iluParam);
 
  196             printf(
"### ERROR: Wrong preconditioner type %d!!!\n", precond_type);
 
  197             status = ERROR_SOLVER_PRECTYPE;
 
  203     else if (solver_type == SOLVER_AMG) {
 
  204         if (print_level > PRINT_NONE) fasp_param_amg_print(&
amgParam);
 
  205         fasp_solver_amg(&A, &b, &x, &
amgParam);
 
  209     else if (solver_type == SOLVER_FMG) {
 
  210         if (print_level > PRINT_NONE) fasp_param_amg_print(&
amgParam);
 
  211         fasp_solver_famg(&A, &b, &x, &
amgParam);
 
  215     else if (solver_type == SOLVER_MUMPS) {
 
  216         status = fasp_solver_mumps(&A, &b, &x, print_level);
 
  217         if (status >= 0) status = 1; 
 
  222     else if (solver_type == SOLVER_SUPERLU) {
 
  223         status = fasp_solver_superlu(&A, &b, &x, print_level);
 
  224         if (status >= 0) status = 1; 
 
  229     else if (solver_type == SOLVER_UMFPACK) {
 
  231         dCSRmat A_trans = fasp_dcsr_create(A.row, A.col, A.nnz);
 
  232         fasp_dcsr_transz(&A, NULL, &A_trans);
 
  233         fasp_dcsr_sort(&A_trans);
 
  234         status = fasp_solver_umfpack(&A_trans, &b, &x, print_level);
 
  235         fasp_dcsr_free(&A_trans);
 
  236         if (status >= 0) status = 1; 
 
  241     else if (solver_type == SOLVER_PARDISO) {
 
  243         status = fasp_solver_pardiso(&A, &b, &x, print_level);
 
  244         if (status >= 0) status = 1; 
 
  249         printf(
"### ERROR: Wrong solver type %d!!!\n", solver_type);
 
  250         status = ERROR_SOLVER_TYPE;
 
  254         printf(
"### ERROR: Solver failed! Exit status = %d.\n\n", status);
 
  257     if (output_type) fclose(stdout);
 
  261 void VectorFaspSolver::Allocate(
const vector<USI>& rowCapacity, 
const OCP_USI& maxDim,
 
  265     for (
OCP_USI n = 0; n < maxDim; n++) {
 
  266         nnz += rowCapacity[n];
 
  268     A     = fasp_dbsr_create(maxDim, maxDim, nnz, blockDim, 0);
 
  269     Asc   = fasp_dbsr_create(maxDim, maxDim, nnz, blockDim, 0);
 
  270     fsc   = fasp_dvec_create(maxDim * blockDim);
 
  271     order = fasp_ivec_create(maxDim);
 
  272     Dmat.resize(maxDim * blockDim * blockDim);
 
  275 void VectorFaspSolver::InitParam()
 
  278     inParam.print_level = PRINT_MIN;
 
  282     inParam.solver_type  = SOLVER_VFGMRES;
 
  285     inParam.stop_type    = STOP_REL_RES;
 
  303     inParam.SWZ_blksolver = SOLVER_DEFAULT;
 
  306     inParam.AMG_type                = CLASSIC_AMG;
 
  308     inParam.AMG_cycle_type          = V_CYCLE;
 
  309     inParam.AMG_smoother            = SMOOTHER_GS;
 
  310     inParam.AMG_smooth_order        = CF_ORDER;
 
  311     inParam.AMG_presmooth_iter      = 1;
 
  312     inParam.AMG_postsmooth_iter     = 1;
 
  320     inParam.AMG_coarse_scaling      = OFF; 
 
  322     inParam.AMG_nl_amli_krylov_type = 2;
 
  325     inParam.AMG_coarsening_type      = 1;
 
  326     inParam.AMG_interpolation_type   = 1;
 
  328     inParam.AMG_strong_threshold     = 0.3;
 
  329     inParam.AMG_truncation_threshold = 0.2;
 
  330     inParam.AMG_aggressive_level     = 0;
 
  331     inParam.AMG_aggressive_path      = 1;
 
  334     inParam.AMG_aggregation_type   = PAIRWISE;
 
  335     inParam.AMG_quality_bound      = 8.0;
 
  337     inParam.AMG_strong_coupled     = 0.25;
 
  338     inParam.AMG_max_aggregation    = 9;
 
  339     inParam.AMG_tentative_smooth   = 0.67;
 
  340     inParam.AMG_smooth_filter      = ON;
 
  341     inParam.AMG_smooth_restriction = ON;
 
  344 void VectorFaspSolver::AssembleMat(
const vector<vector<USI>>&     colId,
 
  345                                    const vector<vector<OCP_DBL>>& val,
 
  347                                    vector<OCP_DBL>& rhs, vector<OCP_DBL>& u)
 
  362     for (
OCP_USI i = 0; i < dim; i++) {
 
  363         nnz += colId[i].size();
 
  382     for (
OCP_USI i = 1; i < dim + 1; i++) {
 
  383         USI nnb_Row = colId[i - 1].size();
 
  384         A.IA[i]     = A.IA[i - 1] + nnb_Row;
 
  386         for (
USI j = 0; j < nnb_Row; j++) {
 
  387             A.JA[count] = colId[i - 1][j];
 
  390         size_row = nnb_Row * blockDim * blockDim;
 
  391         for (
USI k = 0; k < size_row; k++) {
 
  392             A.val[count2] = val[i - 1][k];
 
  399     for (
OCP_USI i = 0; i < nrow; i++) {
 
  400         if (!isfinite(b.val[i]))
 
  402         if (!isfinite(x.val[i]))
 
  406     for (
OCP_USI i = 0; i < A.NNZ; i++) {
 
  407         if (!isfinite(A.val[i]))
 
  414 OCP_INT VectorFaspSolver::Solve()
 
  426         const char* outputfile = 
"../output/test.out";
 
  427         printf(
"Redirecting outputs to file: %s ...\n", outputfile);
 
  428         freopen(outputfile, 
"w", stdout); 
 
  431     fasp_dvec_set(x.row, &x, 0);
 
  434     if (solver_type >= 1 && solver_type <= 10) {
 
  437         switch (precond_type) {
 
  439                 status = fasp_solver_dbsr_krylov(&A, &b, &x, &
itParam);
 
  442                 status = fasp_solver_dbsr_krylov_diag(&A, &b, &x, &
itParam);
 
  449                 Decoupling(&A, &b, &Asc, &fsc, &order, Dmat.data(), decoup_type);
 
  451                 status = fasp_solver_dbsr_krylov_FASP1_cuda_interface(
 
  454                 status = fasp_solver_dbsr_krylov_FASP1a(
 
  459                 Decoupling(&A, &b, &Asc, &fsc, &order, Dmat.data(), decoup_type);
 
  461                 status = fasp_solver_dbsr_krylov_FASP1_cuda_share_interface(
 
  464                 status = fasp_solver_dbsr_krylov_FASP1a_share_interface(
 
  469                 Decoupling(&A, &b, &Asc, &fsc, &order, Dmat.data(), decoup_type);
 
  470                 status = fasp_solver_dbsr_krylov_FASP2(
 
  474                 Decoupling(&A, &b, &Asc, &fsc, &order, Dmat.data(), decoup_type);
 
  475                 status = fasp_solver_dbsr_krylov_FASP3(
 
  479                 Decoupling(&A, &b, &Asc, &fsc, &order, Dmat.data(), decoup_type);
 
  481                 status = fasp_solver_dbsr_krylov_FASP4_cuda(
 
  484                 status = fasp_solver_dbsr_krylov_FASP4(
 
  489                 Decoupling(&A, &b, &Asc, &fsc, &order, Dmat.data(), decoup_type);
 
  491                 status = fasp_solver_dbsr_krylov_FASP4_cuda_share_interface(
 
  495                 status = fasp_solver_dbsr_krylov_FASP4_share_interface(
 
  501                 Decoupling(&A, &b, &Asc, &fsc, &order, Dmat.data(), decoup_type);
 
  502                 status = fasp_solver_dbsr_krylov_FASP5(
 
  507                 OCP_ABORT(
"Preconditioner type " + to_string(precond_type) +
 
  510         fill(Dmat.begin(), Dmat.end(), 0.0);
 
  514     else if (solver_type == SOLVER_MUMPS) {
 
  515         dCSRmat Acsr = fasp_format_dbsr_dcsr(&A);
 
  516         status       = fasp_solver_mumps(&Acsr, &b, &x, print_level);
 
  517         fasp_dcsr_free(&Acsr);
 
  518         if (status >= 0) status = 1; 
 
  523     else if (solver_type == SOLVER_SUPERLU) {
 
  524         dCSRmat Acsr = fasp_format_dbsr_dcsr(&A);
 
  525         status       = fasp_solver_superlu(&Acsr, &b, &x, print_level);
 
  526         fasp_dcsr_free(&Acsr);
 
  527         if (status >= 0) status = 1; 
 
  532     else if (solver_type == SOLVER_UMFPACK) {
 
  534         dCSRmat Acsr    = fasp_format_dbsr_dcsr(&A);
 
  535         dCSRmat A_trans = fasp_dcsr_create(Acsr.row, Acsr.col, Acsr.nnz);
 
  536         fasp_dcsr_transz(&Acsr, NULL, &A_trans);
 
  537         fasp_dcsr_sort(&A_trans);
 
  538         status = fasp_solver_umfpack(&A_trans, &b, &x, print_level);
 
  539         fasp_dcsr_free(&A_trans);
 
  540         fasp_dcsr_free(&Acsr);
 
  541         if (status >= 0) status = 1; 
 
  546     else if (solver_type == SOLVER_PARDISO) {
 
  547         dCSRmat Acsr = fasp_format_dbsr_dcsr(&A);
 
  548         fasp_dcsr_sort(&Acsr);
 
  549         status = fasp_solver_pardiso(&Acsr, &b, &x, print_level);
 
  550         fasp_dcsr_free(&Acsr);
 
  551         if (status >= 0) status = 1; 
 
  556         printf(
"### ERROR: Wrong solver type %d!!!\n", solver_type);
 
  557         status = ERROR_SOLVER_TYPE;
 
  560     if (print_level > PRINT_MIN) {
 
  562             cout << 
"\n### WARNING: Solver does not converge!\n" << endl;
 
  564             cout << 
"\nSolver converges successfully!\n" << endl;
 
  568     if (output_type) fclose(stdout);
 
Declaration of classes interfacing to the FASP solvers.
#define PC_BILU
BILU: block ILU preconditioner.
#define PC_FASP2
FASP2: MSP, experimental only.
#define PC_FASP3
FASP3: MSP, monolithic preconditioner.
#define PC_FASP5
FASP5: MSP, experimental only.
#define RESET_CONST
Sharing threshold for PC_FASP1_SHARE, PC_FASP4_SHARE.
#define PC_NULL
None: no preconditioner.
#define PC_FASP4
FASP4: MSP, default for FIM from 2015.
#define PC_DIAG
DIAG: diagonal preconditioner.
#define PC_FASP1_SHARE
Sharing setup stage for PC_FASP1, use with caution.
#define PC_FASP4_SHARE
Sharing setup stage for PC_FASP4, use with caution.
#define PC_FASP1
FASP1: MSP, default for FIM from 2020.
unsigned int USI
Generic unsigned integer.
unsigned int OCP_USI
Long unsigned integer.
#define OCP_ABORT(msg)
Abort if critical error happens.
AMG_param amgParam
Parameters for AMG method.
input_param inParam
Parameters from input files.
ILU_param iluParam
Parameters for ILU method.
string solveFile
Relative path of fasp file.
SWZ_param swzParam
Parameters for Schwarz method.
string solveDir
Current work dir.
ITS_param itParam
Parameters for iterative method.
void SetupParam(const string &dir, const string &file) override
Set FASP parameters.
virtual void InitParam()=0
Initialize the params for linear solvers.