Chi-Tech
diffusion.cc
Go to the documentation of this file.
1#include "diffusion.h"
2
5
6#include "chi_runtime.h"
7#include "chi_log.h"
8
9namespace lbs::acceleration
10{
11
12// ###################################################################
13/**Default constructor.*/
15 std::string text_name,
17 const chi_math::UnknownManager& uk_man,
18 std::map<uint64_t, BoundaryCondition> bcs,
19 MatID2XSMap map_mat_id_2_xs,
20 const std::vector<UnitCellMatrices>& unit_cell_matrices,
21 const bool verbose,
22 const bool requires_ghosts)
23 : text_name_(std::move(text_name)),
24 grid_(sdm.Grid()),
25 sdm_(sdm),
26 uk_man_(uk_man),
27 bcs_(std::move(bcs)),
28 mat_id_2_xs_map_(std::move(map_mat_id_2_xs)),
29 unit_cell_matrices_(unit_cell_matrices),
30 num_local_dofs_(static_cast<int64_t>(sdm_.GetNumLocalDOFs(uk_man_))),
31 num_global_dofs_(static_cast<int64_t>(sdm_.GetNumGlobalDOFs(uk_man_))),
32 A_(nullptr),
33 rhs_(nullptr),
34 ksp_(nullptr),
35 requires_ghosts_(requires_ghosts)
36{
37 options.verbose = verbose;
38}
39
40// ###################################################################
41/**Default destructor.*/
43{
44 MatDestroy(&A_);
45 VecDestroy(&rhs_);
46 KSPDestroy(&ksp_);
47}
48
49// ###################################################################
50/**Returns the assigned text name.*/
51std::string DiffusionSolver::TextName() const { return text_name_; }
52
53// ###################################################################
54/**Returns the right-hand side petsc vector.*/
55const Vec& DiffusionSolver::RHS() const { return rhs_; }
56
57// ###################################################################
58/**Returns the assigned unknown structure.*/
60{
61 return uk_man_;
62}
63
64// ###################################################################
65/**Returns the associated spatial discretization.*/
68{
69 return sdm_;
70}
71
72std::pair<size_t, size_t>
74{
75 return {sdm_.GetNumLocalDOFs(uk_man_), sdm_.GetNumGlobalDOFs(uk_man_)};
76}
77
78// ##################################################################
79/**Adds to the right-hand side without applying spatial discretization.*/
81 const std::vector<double>& values)
82{
83 typedef unsigned int uint;
84 typedef const int64_t cint64_t;
85 const size_t num_local_dofs = sdm_.GetNumLocalDOFs(uk_man_);
86
87 ChiInvalidArgumentIf(num_local_dofs != values.size(),
88 "Vector size mismatched with spatial discretization");
89
90 const size_t num_unknowns = uk_man_.NumberOfUnknowns();
91
92 for (const auto& cell : grid_.local_cells)
93 {
94 const auto& cell_mapping = sdm_.GetCellMapping(cell);
95
96 for (size_t i = 0; i < cell_mapping.NumNodes(); ++i)
97 {
98 for (size_t u = 0; u < num_unknowns; ++u)
99 {
100 for (uint c = 0; c < uk_man_.GetUnknown(u).NumComponents(); ++c)
101 {
102 cint64_t dof_map_local = sdm_.MapDOFLocal(cell, i, uk_man_, u, c);
103 cint64_t dof_map = sdm_.MapDOF(cell, i, uk_man_, u, c);
104
105 VecSetValue(rhs_, dof_map, values[dof_map_local], ADD_VALUES);
106 } // for component c
107 } // for unknown u
108 } // for node i
109 } // for cell
110
111 VecAssemblyBegin(rhs_);
112 VecAssemblyEnd(rhs_);
113}
114
115} // namespace lbs::acceleration
#define ChiInvalidArgumentIf(condition, message)
struct lbs::acceleration::DiffusionSolver::Options options
std::string TextName() const
Definition: diffusion.cc:51
const chi_math::SpatialDiscretization & sdm_
Definition: diffusion.h:39
const chi_math::UnknownManager & UnknownStructure() const
Definition: diffusion.cc:59
DiffusionSolver(std::string text_name, const chi_math::SpatialDiscretization &sdm, const chi_math::UnknownManager &uk_man, std::map< uint64_t, BoundaryCondition > bcs, MatID2XSMap map_mat_id_2_xs, const std::vector< UnitCellMatrices > &unit_cell_matrices, bool verbose, bool requires_ghosts)
Definition: diffusion.cc:14
void AddToRHS(const std::vector< double > &values)
Definition: diffusion.cc:80
const chi_math::UnknownManager uk_man_
Definition: diffusion.h:40
const chi_math::SpatialDiscretization & SpatialDiscretization() const
Definition: diffusion.cc:67
std::map< int, Multigroup_D_and_sigR > MatID2XSMap
Definition: diffusion.h:35
std::pair< size_t, size_t > GetNumPhiIterativeUnknowns()
Definition: diffusion.cc:73
const std::string text_name_
Definition: diffusion.h:37
struct _p_Vec * Vec
#define uint