20 for (
const auto& cell : grid.local_cells)
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();
27 const auto& D = xs->DiffusionCoefficient();
28 const auto& sigma_r = xs->SigmaRemoval();
31 double collapsed_D=0.,collapsed_sig_a=0.;
35 collapsed_D = xstg.collapsed_D;
36 collapsed_sig_a = xstg.collapsed_sig_a;
39 std::vector<VecDbl> rhs_cell;
42 rhs_cell[g].resize(num_nodes, 0.0);
44 std::vector<MatDbl> Acell;
47 Acell[g].resize(num_nodes,
VecDbl(num_nodes, 0.0));
49 for (
size_t i=0; i<num_nodes; ++i)
51 for (
size_t j=0; j<num_nodes; ++j)
53 double entry_mij = 0.0;
54 double entry_kij = 0.0;
55 for (
size_t qp : qp_data.QuadraturePointIndices())
57 entry_mij += qp_data.ShapeValue(i, qp) *
58 qp_data.ShapeValue(j, qp) *
61 entry_kij += qp_data.ShapeGrad(i, qp).Dot(qp_data.ShapeGrad(j, qp)) *
65 Acell[g][i][j] = entry_mij * sigma_r[g] + entry_kij * D[g];
68 Acell[
num_groups_][i][j] = entry_mij * collapsed_sig_a
69 + entry_kij * collapsed_D;
71 double entry_rhsi = 0.0;
72 for (
size_t qp : qp_data.QuadraturePointIndices())
73 entry_rhsi += qp_data.ShapeValue(i, qp) * qp_data.JxW(qp);
75 rhs_cell[g][i] = entry_rhsi * (qext->source_value_g_[g]);
79 const size_t num_faces = cell.faces_.size();
80 for (
size_t f=0; f<num_faces; ++f)
82 const auto& face = cell.faces_[f];
84 if (face.has_neighbor_)
continue;
92 const auto qp_face_data =
93 cell_mapping.MakeSurfaceQuadraturePointData(f);
94 const size_t num_face_nodes = face.vertex_ids_.size();
96 auto& aval = bndry.mg_values_[0];
97 auto& bval = bndry.mg_values_[1];
98 auto& fval = bndry.mg_values_[2];
101 aval.push_back(0.25);
110 if (std::fabs(bval[g]) < 1e-8)
111 throw std::logic_error(
"if b=0, this is a Dirichlet BC, not a Robin BC");
118 if (std::fabs(aval[g]) > 1.0e-8)
121 for (
size_t fi=0; fi<num_face_nodes; ++fi)
123 const uint i = cell_mapping.MapFaceNode(f,fi);
125 double entry_rhsi = 0.0;
126 for (
size_t qp : qp_face_data.QuadraturePointIndices() )
127 entry_rhsi += qp_face_data.ShapeValue(i, qp) * qp_face_data.JxW(qp);
129 rhs_cell[g][i] += fval[g] / bval[g] * entry_rhsi;
131 for (
size_t fj=0; fj<num_face_nodes; ++fj)
133 const uint j = cell_mapping.MapFaceNode(f,fj);
134 double entry_aij = 0.0;
135 for (
size_t qp : qp_face_data.QuadraturePointIndices())
136 entry_aij += qp_face_data.ShapeValue(i, qp)
137 * qp_face_data.ShapeValue(j, qp)
138 * qp_face_data.JxW(qp);
139 Acell[g][i][j] += aval[g] / bval[g] * entry_aij;
148 std::vector<int64_t> imap(num_nodes, 0);
149 for (
size_t i=0; i<num_nodes; ++i)
150 imap[i] = sdm.MapDOF(cell, i);
154 for (
size_t i=0; i<num_nodes; ++i)
155 VecSetValue(
bext_[g], imap[i], rhs_cell[g][i], ADD_VALUES);
158 for (
size_t i=0; i<num_nodes; ++i)
159 for (
size_t j=0; j<num_nodes; ++j)
160 MatSetValue(
A_[g], imap[i], imap[j], Acell[g][i][j], ADD_VALUES);
168 VecAssemblyBegin(
bext_[g]);
169 VecAssemblyEnd(
bext_[g]);
173 MatAssemblyBegin(
A_[g], MAT_FINAL_ASSEMBLY);
174 MatAssemblyEnd(
A_[g], MAT_FINAL_ASSEMBLY);
std::vector< double > VecDbl
LogStream Log(LOG_LVL level=LOG_0)
std::map< int, TwoGridCollapsedInfo > map_mat_id_2_tginfo
std::map< int, std::shared_ptr< chi_physics::MultiGroupXS > > matid_to_xs_map
chi_mesh::MeshContinuumPtr grid_ptr_
std::vector< Boundary > boundaries_
std::map< int, std::shared_ptr< chi_physics::IsotropicMultiGrpSource > > matid_to_src_map
chi_math::SDMPtr sdm_ptr_