Chi-Tech
mgd_02c_asemble_rhs_tg.cc
Go to the documentation of this file.
2
6
7#include "chi_runtime.h"
8#include "chi_log.h"
9
10//========================================================== Solve 1g problem
12{
13 if (verbose > 2) Chi::log.Log() << "\nAssemblying RHS for two-grid ";
14
15 VecSet(b_, 0.0);
16
17 const auto& sdm = *sdm_ptr_;
18 // compute inscattering term
19 for (const auto& cell : grid_ptr_->local_cells)
20 {
21 const auto &cell_mapping = sdm.GetCellMapping(cell);
22 const auto qp_data = cell_mapping.MakeVolumetricQuadraturePointData();
23 const size_t num_nodes = cell_mapping.NumNodes();
24
25 const auto &S = matid_to_xs_map.at(cell.material_id_)->TransferMatrix(0);
26
27 for (unsigned g = last_fast_group_; g < num_groups_; ++g)
28 {
29 for (const auto &[row_g, gprime, sigma_sm]: S.Row(g)) {
30 if (gprime > g) // the upper part for the residual of two-grid accel
31 {
32 const double *xlocal;
33 const double *xlocal_old;
34 VecGetArrayRead(x_[gprime], &xlocal);
35 VecGetArrayRead(x_old_[gprime], &xlocal_old);
36
37 for (size_t i = 0; i < num_nodes; ++i) {
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 const int64_t jmap = sdm.MapDOFLocal(cell, j);
43
44 // get flux at node j
45 const double delta_flxj_gp = xlocal[jmap] - xlocal_old[jmap];
46 for (size_t qp: qp_data.QuadraturePointIndices())
47 inscatter_g += sigma_sm * delta_flxj_gp *
48 qp_data.ShapeValue(i, qp) * qp_data.ShapeValue(j, qp) *
49 qp_data.JxW(qp);
50 }//for j
51 // add inscattering value to vector
52 VecSetValue(b_, imap, inscatter_g, ADD_VALUES);
53 }//for i
54 VecRestoreArrayRead(x_[gprime] , &xlocal);
55 VecRestoreArrayRead(x_old_[gprime], &xlocal_old);
56 }//if gp!=g
57 }// for gprime
58 }// for g
59 }//for cell
60
61 VecAssemblyBegin(b_);
62 VecAssemblyEnd(b_);
63// VecView(b, PETSC_VIEWER_STDERR_WORLD);
64// chi::Exit(1234);
65
66}
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream Log(LOG_LVL level=LOG_0)
Definition: chi_log.cc:35
void Assemble_RHS_TwoGrid(int64_t iverbose)
std::vector< Vec > x_
std::vector< Vec > x_old_
std::map< int, std::shared_ptr< chi_physics::MultiGroupXS > > matid_to_xs_map
chi_mesh::MeshContinuumPtr grid_ptr_
chi_math::SDMPtr sdm_ptr_