Chi-Tech
diffusion_01_initialize.cc
Go to the documentation of this file.
1#include "diffusion.h"
2
4
7
8#include "chi_runtime.h"
9#include "chi_log.h"
10
11// ###################################################################
12/**Initializes the diffusion solver. This involves creating the
13 * sparse matrix with the appropriate sparsity pattern. Creating the
14 * RHS vector. Creating the KSP solver. Setting the very specialized parameters
15 * for Hypre's BooomerAMG. Note: `PCSetFromOptions` and
16 * `KSPSetFromOptions` are called at the end. Therefore, any number of
17 * additional PETSc options can be passed via the commandline.*/
19{
20 if (options.verbose)
21 Chi::log.Log() << text_name_ << ": Initializing PETSc items";
22
23 if (options.verbose)
25 << ": Global number of DOFs=" << num_global_dofs_;
26
28 Chi::log.Log() << "Sparsity pattern";
30 //============================================= Create Matrix
31 std::vector<int64_t> nodal_nnz_in_diag;
32 std::vector<int64_t> nodal_nnz_off_diag;
33 sdm_.BuildSparsityPattern(nodal_nnz_in_diag, nodal_nnz_off_diag, uk_man_);
35 Chi::log.Log() << "Done Sparsity pattern";
37 A_ =
40 A_, nodal_nnz_in_diag, nodal_nnz_off_diag);
42 Chi::log.Log() << "Done matrix creation";
44
45 //============================================= Create RHS
46 if (not requires_ghosts_)
47 rhs_ =
49 else
53 static_cast<int64_t>(sdm_.GetNumGhostDOFs(uk_man_)),
55
57 Chi::log.Log() << "Done vector creation";
59
60 //============================================= Create KSP
61 KSPCreate(PETSC_COMM_WORLD, &ksp_);
62 KSPSetOptionsPrefix(ksp_, text_name_.c_str());
63 KSPSetType(ksp_, KSPCG);
64
65 KSPSetTolerances(
67
68 //============================================= Set Pre-conditioner
69 PC pc;
70 KSPGetPC(ksp_, &pc);
71 // PCSetType(pc, PCGAMG);
72 PCSetType(pc, PCHYPRE);
73
74 PCHYPRESetType(pc, "boomeramg");
75 std::vector<std::string> pc_options = {
76 "pc_hypre_boomeramg_agg_nl 1",
77 "pc_hypre_boomeramg_P_max 4",
78 "pc_hypre_boomeramg_grid_sweeps_coarse 1",
79 "pc_hypre_boomeramg_max_levels 25",
80 "pc_hypre_boomeramg_relax_type_all symmetric-SOR/Jacobi",
81 "pc_hypre_boomeramg_coarsen_type HMIS",
82 "pc_hypre_boomeramg_interp_type ext+i"};
83
85 pc_options.emplace_back("pc_hypre_boomeramg_strong_threshold 0.6");
87 pc_options.emplace_back("pc_hypre_boomeramg_strong_threshold 0.8");
88
89 for (const auto& option : pc_options)
90 PetscOptionsInsertString(nullptr, ("-" + text_name_ + option).c_str());
91
92 PetscOptionsInsertString(nullptr, options.additional_options_string.c_str());
93
94 PCSetFromOptions(pc);
95 KSPSetFromOptions(ksp_);
96}
static chi::ChiLog & log
Definition: chi_runtime.h:81
static chi::MPI_Info & mpi
Definition: chi_runtime.h:78
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
void Barrier() const
Definition: mpi_info.cc:38
virtual std::vector< int64_t > GetGhostDOFIndices(const UnknownManager &unknown_manager) const =0
virtual void BuildSparsityPattern(std::vector< int64_t > &nodal_nnz_in_diag, std::vector< int64_t > &nodal_nnz_off_diag, const UnknownManager &unknown_manager) const =0
virtual size_t GetNumGhostDOFs(const UnknownManager &unknown_manager) const =0
MeshAttributes Attributes() const
struct lbs::acceleration::DiffusionSolver::Options options
const chi_math::SpatialDiscretization & sdm_
Definition: diffusion.h:39
const chi_math::UnknownManager uk_man_
Definition: diffusion.h:40
const chi_mesh::MeshContinuum & grid_
Definition: diffusion.h:38
const std::string text_name_
Definition: diffusion.h:37
void InitMatrixSparsity(Mat &A, const std::vector< int64_t > &nodal_nnz_in_diag, const std::vector< int64_t > &nodal_nnz_off_diag)
Vec CreateVectorWithGhosts(int64_t local_size, int64_t global_size, int64_t nghosts, const std::vector< int64_t > &ghost_indices)
Mat CreateSquareMatrix(int64_t local_size, int64_t global_size)
Vec CreateVector(int64_t local_size, int64_t global_size)
@ DIMENSION_2
Definition: chi_mesh.h:73
@ DIMENSION_3
Definition: chi_mesh.h:74
double residual_tolerance
Residual tol. relative to rhs.
Definition: diffusion.h:60