16#define DefaultBCDirichlet BoundaryCondition{BCType::DIRICHLET,{0,0,0}}
24 const std::string fname =
"lbs::acceleration::DiffusionMIPSolver::"
25 "AssembleAand_b_wQpoints";
26 if (
A_ ==
nullptr or
rhs_ ==
nullptr or
ksp_ ==
nullptr)
27 throw std::logic_error(fname +
": Some or all PETSc elements are null. "
28 "Check that Initialize has been called.");
42 const size_t num_faces = cell.faces_.size();
44 const size_t num_nodes = cell_mapping.
NumNodes();
45 const auto cc_nodes = cell_mapping.GetNodeLocations();
46 const auto qp_data = cell_mapping.MakeVolumetricQuadraturePointData();
51 for (
size_t g=0; g<num_groups; ++g)
54 const double Dg = xs.Dg[g];
55 const double sigr_g = xs.sigR[g];
57 std::vector<double> qg(num_nodes, 0.0);
58 for (
size_t j=0; j<num_nodes; j++)
62 for (
size_t i=0; i<num_nodes; i++)
65 double entry_rhs_i = 0.0;
66 for (
size_t j=0; j<num_nodes; j++)
69 double entry_aij = 0.0;
70 for (
size_t qp : qp_data.QuadraturePointIndices())
73 qp_data.ShapeGrad(i, qp).Dot(qp_data.ShapeGrad(j, qp)) *
77 qp_data.ShapeValue(i, qp) * qp_data.ShapeValue(j, qp) *
80 if (source_function.empty())
83 qp_data.ShapeValue(i, qp) * qp_data.ShapeValue(j, qp) *
86 MatSetValue(
A_, imap, jmap, entry_aij, ADD_VALUES);
89 if (not source_function.empty())
91 for (
size_t qp : qp_data.QuadraturePointIndices())
94 qp_data.ShapeValue(i, qp) *
98 VecSetValue(
rhs_, imap, entry_rhs_i, ADD_VALUES);
102 for (
size_t f=0; f<num_faces; ++f)
104 const auto& face = cell.faces_[f];
105 const auto& n_f = face.normal_;
106 const size_t num_face_nodes = cell_mapping.NumFaceNodes(f);
107 const auto fqp_data = cell_mapping.MakeSurfaceQuadraturePointData(f);
113 if (face.has_neighbor_)
115 const auto& adj_cell =
grid_.
cells[face.neighbor_id_];
118 const size_t acf = Grid::MapCellFace(cell, adj_cell, f);
122 const double adj_Dg = adj_xs.Dg[g];
134 for (
size_t fi=0; fi<num_face_nodes; ++fi)
136 const int i = cell_mapping.MapFaceNode(f,fi);
139 for (
size_t fj=0; fj<num_face_nodes; ++fj)
141 const int jm = cell_mapping.MapFaceNode(f,fj);
148 for (
size_t qp : fqp_data.QuadraturePointIndices())
150 fqp_data.ShapeValue(i,qp) * fqp_data.ShapeValue(jm,qp) *
153 MatSetValue(
A_, imap, jmmap, aij, ADD_VALUES);
154 MatSetValue(
A_, imap, jpmap, -aij, ADD_VALUES);
163 for (
int i=0; i<num_nodes; i++)
167 for (
int fj=0; fj<num_face_nodes; fj++)
169 const int jm = cell_mapping.MapFaceNode(f,fj);
176 for (
size_t qp : fqp_data.QuadraturePointIndices())
178 fqp_data.ShapeValue(jm, qp) * fqp_data.ShapeGrad(i, qp) *
180 const double aij = -0.5*Dg*n_f.
Dot(vec_aij);
182 MatSetValue(
A_, imap, jmmap, aij, ADD_VALUES);
183 MatSetValue(
A_, imap, jpmap, -aij, ADD_VALUES);
188 for (
int fi=0; fi<num_face_nodes; fi++)
190 const int im = cell_mapping.MapFaceNode(f,fi);
196 for (
int j=0; j<num_nodes; j++)
201 for (
size_t qp : fqp_data.QuadraturePointIndices())
203 fqp_data.ShapeValue(im, qp) * fqp_data.ShapeGrad(j, qp) *
205 const double aij = -0.5*Dg*n_f.
Dot(vec_aij);
207 MatSetValue(
A_, immap, jmap, aij, ADD_VALUES);
208 MatSetValue(
A_, ipmap, jmap, -aij, ADD_VALUES);
216 if (
bcs_.count(face.neighbor_id_) > 0)
217 bc =
bcs_.at(face.neighbor_id_);
221 const double bc_value = bc.values[0];
233 for (
size_t fi=0; fi<num_face_nodes; ++fi)
235 const int i = cell_mapping.MapFaceNode(f,fi);
238 for (
size_t fj=0; fj<num_face_nodes; ++fj)
240 const int jm = cell_mapping.MapFaceNode(f,fj);
244 for (
size_t qp : fqp_data.QuadraturePointIndices())
246 fqp_data.ShapeValue(i, qp) * fqp_data.ShapeValue(jm, qp) *
248 double aij_bc_value = aij*bc_value;
250 if (not solution_function.empty())
253 for (
size_t qp : fqp_data.QuadraturePointIndices())
256 fqp_data.QPointXYZ(qp)) *
257 fqp_data.ShapeValue(i, qp) * fqp_data.ShapeValue(jm, qp) *
261 MatSetValue(
A_ , imap, jmmap, aij, ADD_VALUES);
262 VecSetValue(
rhs_, imap, aij_bc_value, ADD_VALUES);
271 for (
size_t i=0; i<num_nodes; i++)
275 for (
size_t j=0; j<num_nodes; j++)
280 for (
size_t qp : fqp_data.QuadraturePointIndices())
282 fqp_data.ShapeValue(j, qp) * fqp_data.ShapeGrad(i, qp) *
284 fqp_data.ShapeValue(i, qp) * fqp_data.ShapeGrad(j, qp) *
286 const double aij = -Dg*n_f.
Dot(vec_aij);
288 double aij_bc_value = aij*bc_value;
290 if (not solution_function.empty())
293 for (
size_t qp : fqp_data.QuadraturePointIndices())
296 fqp_data.QPointXYZ(qp)) *
297 (fqp_data.ShapeValue(j, qp) * fqp_data.ShapeGrad(i, qp) *
299 fqp_data.ShapeValue(i, qp) * fqp_data.ShapeGrad(j, qp) *
301 aij_bc_value = -Dg*n_f.Dot(vec_aij_mms);
304 MatSetValue(
A_, imap, jmap, aij, ADD_VALUES);
305 VecSetValue(
rhs_, imap, aij_bc_value, ADD_VALUES);
311 const double aval = bc.values[0];
312 const double bval = bc.values[1];
313 const double fval = bc.values[2];
315 if (std::fabs(bval) < 1.0e-12)
continue;
317 for (
size_t fi=0; fi<num_face_nodes; fi++)
319 const int i = cell_mapping.MapFaceNode(f,fi);
322 if (std::fabs(aval) >= 1.0e-12)
324 for (
size_t fj=0; fj<num_face_nodes; fj++)
326 const int j = cell_mapping.MapFaceNode(f,fj);
330 for (
size_t qp : fqp_data.QuadraturePointIndices())
331 aij += fqp_data.ShapeValue(i,qp) * fqp_data.ShapeValue(j,qp) *
335 MatSetValue(
A_, ir , jr, aij, ADD_VALUES);
339 if (std::fabs(fval) >= 1.0e-12)
341 double rhs_val = 0.0;
342 for (
size_t qp : fqp_data.QuadraturePointIndices())
343 rhs_val += fqp_data.ShapeValue(i,qp) * fqp_data.JxW(qp);
344 rhs_val *= (fval/bval);
346 VecSetValue(
rhs_, ir, rhs_val, ADD_VALUES);
356 MatAssemblyBegin(
A_, MAT_FINAL_ASSEMBLY);
357 MatAssemblyEnd(
A_, MAT_FINAL_ASSEMBLY);
358 VecAssemblyBegin(
rhs_);
359 VecAssemblyEnd(
rhs_);
363 PetscBool symmetry = PETSC_FALSE;
364 MatIsSymmetric(
A_, 1.0e-6, &symmetry);
365 if (symmetry == PETSC_FALSE)
366 throw std::logic_error(fname +
":Symmetry check failed");
static chi::Timer program_timer
static chi::Console & console
LogStream Log(LOG_LVL level=LOG_0)
lua_State *& GetConsoleState()
std::string GetTimeString() const
const std::vector< chi_mesh::Vector3 > & GetNodeLocations() const
const CellMapping & GetCellMapping(const chi_mesh::Cell &cell) const
virtual int64_t MapDOF(const chi_mesh::Cell &cell, unsigned int node, const UnknownManager &unknown_manager, unsigned int unknown_id, unsigned int component) const =0
virtual int64_t MapDOFLocal(const chi_mesh::Cell &cell, unsigned int node, const UnknownManager &unknown_manager, unsigned int unknown_id, unsigned int component) const =0
std::vector< Unknown > unknowns_
LocalCellHandler local_cells
void AssembleAand_b_wQpoints(const std::vector< double > &q_vector)
int MapFaceNodeDisc(const chi_mesh::Cell &cur_cell, const chi_mesh::Cell &adj_cell, const std::vector< chi_mesh::Vector3 > &cc_node_locs, const std::vector< chi_mesh::Vector3 > &ac_node_locs, size_t ccf, size_t acf, size_t ccfi, double epsilon=1.0e-12)
double HPerpendicular(const chi_mesh::Cell &cell, unsigned int f)
static double CallLuaXYZFunction(lua_State *L, const std::string &lua_func_name, const chi_mesh::Vector3 &xyz)
struct lbs::acceleration::DiffusionSolver::Options options
const chi_math::SpatialDiscretization & sdm_
const chi_math::UnknownManager uk_man_
const chi_mesh::MeshContinuum & grid_
const std::map< uint64_t, BoundaryCondition > bcs_
const MatID2XSMap mat_id_2_xs_map_
#define DefaultBCDirichlet
Vector3 Dot(const chi_mesh::TensorRank2Dim3 &that) const
std::string source_lua_function
for mms
std::string ref_solution_lua_function
for mms
bool verbose
Verbosity flag.
bool perform_symmetry_check
For debugging only (very expensive)