17 {
"residual_tolerance", 1.0e-2},
18 {
"verbose_level" , int64_t (0) },
19 {
"thermal_flux_tolerance", 1.0e-2},
20 {
"max_thermal_iters" , int64_t(500)},
21 {
"do_two_grid" ,
false}
28 for (
uint g=0; g < num_groups_; ++g)
31 VecDestroy(&bext_[g]);
36 if (last_fast_group_ < num_groups_)
38 VecDestroy(&thermal_dphi_);
39 for (
uint g=last_fast_group_; g < num_groups_; ++g)
40 VecDestroy(&x_old_[g]);
45 VecDestroy(&x_[num_groups_]);
46 MatDestroy(&A_[num_groups_]);
55 << TextName() <<
": Initializing CFEM Multigroup Diffusion solver ";
59 const auto& grid = *grid_ptr_;
60 if (grid_ptr_ ==
nullptr)
61 throw std::logic_error(std::string(__PRETTY_FUNCTION__) +
64 Chi::log.
Log() <<
"Global num cells: " << grid.GetGlobalNumberOfCells();
67 std::set<int> unique_material_ids;
68 int invalid_mat_cell_count = 0;
69 for (
auto& cell : grid.local_cells)
71 unique_material_ids.insert(cell.material_id_);
72 if (cell.material_id_ < 0)
73 ++invalid_mat_cell_count;
75 const auto& ghost_cell_ids = grid.cells.GetGhostGlobalIDs();
76 for (uint64_t cell_id : ghost_cell_ids)
78 const auto& cell = grid.cells[cell_id];
79 unique_material_ids.insert(cell.material_id_);
80 if (cell.material_id_ < 0)
81 ++invalid_mat_cell_count;
84 if (invalid_mat_cell_count>0)
87 <<
"Number of invalid material cells: " << invalid_mat_cell_count;
94 auto globl_unique_bndry_ids = grid.GetDomainUniqueBoundaryIDs();
99 const auto& sdm = *sdm_ptr_;
101 const auto& OneDofPerNode = sdm.UNITARY_UNKNOWN_MANAGER;
102 num_local_dofs_ = sdm.GetNumLocalDOFs(OneDofPerNode);
103 num_globl_dofs_ = sdm.GetNumGlobalDOFs(OneDofPerNode);
105 Chi::log.
Log() <<
"Num local DOFs: " << num_local_dofs_;
106 Chi::log.
Log() <<
"Num globl DOFs: " << num_globl_dofs_;
109 const auto n =
static_cast<int64_t
>(num_local_dofs_);
110 const auto N =
static_cast<int64_t
>(num_globl_dofs_);
112 std::vector<int64_t> nodal_nnz_in_diag;
113 std::vector<int64_t> nodal_nnz_off_diag;
114 sdm.BuildSparsityPattern(nodal_nnz_in_diag,nodal_nnz_off_diag, OneDofPerNode);
116 unsigned int i_two_grid = do_two_grid_ ? 1 : 0;
119 A_.resize(num_groups_ + i_two_grid,
nullptr);
120 x_.resize(num_groups_ + i_two_grid,
nullptr);
121 bext_.resize(num_groups_,
nullptr);
123 auto ghost_dof_indices = sdm.GetGhostDOFIndices(OneDofPerNode);
125 for (
uint g=0; g < num_groups_; ++g)
129 static_cast<int64_t
>(ghost_dof_indices.size()),
140 VecDuplicate(bext_.front(), &b_);
142 if (last_fast_group_ < num_groups_)
144 VecDuplicate(x_.front(), &thermal_dphi_);
145 x_old_.resize(num_groups_,
nullptr);
146 for (
uint g=0; g < num_groups_; ++g)
148 VecDuplicate(x_.front(), &x_old_[g]);
149 VecSet(x_old_[g], 0.0);
159 VecDuplicate(x_.front(), &x_[num_groups_]);
175 if (field_functions_.empty())
179 std::string solver_name;
180 if (not TextName().empty()) solver_name = TextName() +
"-";
183 int dummy = snprintf(buff,4,
"%03d",g);
185 std::string text_name = solver_name +
"Flux_g" + std::string(buff);
188 auto initial_field_function =
189 std::make_shared<chi_physics::FieldFunctionGridBased>(
194 field_functions_.push_back(initial_field_function);
static std::vector< chi_physics::FieldFunctionPtr > field_function_stack
static chi::Timer program_timer
LogStream Log(LOG_LVL level=LOG_0)
LogStream LogAllWarning()
std::string GetTimeString() const
static std::shared_ptr< PieceWiseLinearContinuous > New(const chi_mesh::MeshContinuum &grid, QuadratureOrder q_order=QuadratureOrder::SECOND, CoordinateSystemType cs_type=CoordinateSystemType::CARTESIAN)
chi_mesh::MeshContinuumPtr & GetGrid() const
void Initialize_Materials(std::set< int > &material_ids)
Solver(const std::string &in_solver_name)
void Compute_TwoGrid_VolumeFractions()
void Set_BCs(const std::vector< uint64_t > &globl_unique_bndry_ids)
void Initialize() override
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)
MeshHandler & GetCurrentHandler()