Chi-Tech
mgd_02a_asemble_rhs_g.cc
Go to the documentation of this file.
2#include "chi_runtime.h"
3#include "chi_log.h"
6
7//========================================================== Solve 1g problem
8void mg_diffusion::Solver::Assemble_RHS(const unsigned int g,
9 const int64_t verbose)
10{
11 if (verbose > 2)
12 Chi::log.Log() << "\nAssemblying RHS for group " + std::to_string(g);
13
14 // copy the external source vector for group g into b
15 VecSet(b_, 0.0);
16 VecCopy(bext_[g], b_);
17
18 const auto& sdm = *mg_diffusion::Solver::sdm_ptr_;
19 // compute inscattering term
20 for (const auto& cell : mg_diffusion::Solver::grid_ptr_->local_cells)
21 {
22 const auto& cell_mapping = sdm.GetCellMapping(cell);
23 const auto qp_data = cell_mapping.MakeVolumetricQuadraturePointData();
24 const size_t num_nodes = cell_mapping.NumNodes();
25
26 const auto& xs = matid_to_xs_map.at(cell.material_id_);
27 const auto& S = xs->TransferMatrix(0);
28
29 for (const auto& [row_g, gprime, sigma_sm] : S.Row(g))
30 {
31 if (gprime != g) // g and row_g are the same, maybe different int types
32 {
33 const double* xlocal;
34 VecGetArrayRead(x_[gprime], &xlocal);
35
36 for (size_t i=0; i<num_nodes; ++i)
37 {
38 const int64_t imap = sdm.MapDOF(cell,i);
39 double inscatter_g = 0.0;
40
41 for (size_t j = 0; j < num_nodes; ++j)
42 {
43 const int64_t jmap = sdm.MapDOFLocal(cell, j);
44
45 // get flux at node j
46 const double flxj_gp = xlocal[jmap];
47 for (size_t qp: qp_data.QuadraturePointIndices())
48 inscatter_g += sigma_sm * flxj_gp *
49 qp_data.ShapeValue(i, qp) * qp_data.ShapeValue(j, qp) *
50 qp_data.JxW(qp);
51 }//for j
52 // add inscattering value to vector
53 VecSetValue(b_, imap, inscatter_g, ADD_VALUES);
54 }//for i
55 VecRestoreArrayRead(x_[gprime], &xlocal);
56 }//if gp!=g
57 }// for gprime
58 }//for cell
59
60 VecAssemblyBegin(b_);
61 VecAssemblyEnd(b_);
62
63}
64
65// cout << "b=bext["<<g<<"]+inscattering\n";
66// VecView(b, PETSC_VIEWER_STDERR_WORLD);
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
std::vector< Vec > x_
std::map< int, std::shared_ptr< chi_physics::MultiGroupXS > > matid_to_xs_map
chi_mesh::MeshContinuumPtr grid_ptr_
chi_math::SDMPtr sdm_ptr_
std::vector< Vec > bext_
void Assemble_RHS(unsigned int g, int64_t iverbose)