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.");
40 const size_t num_faces = cell.faces_.size();
42 const size_t num_nodes = cell_mapping.
NumNodes();
43 const auto qp_data = cell_mapping.MakeVolumetricQuadraturePointData();
49 for (
size_t g=0; g<num_groups; ++g)
52 const double Dg = xs.Dg[g];
54 std::vector<double> qg(num_nodes, 0.0);
55 for (
size_t j=0; j<num_nodes; j++)
59 for (
size_t i=0; i<num_nodes; i++)
62 double entry_rhs_i = 0.0;
63 if (source_function.empty())
64 for (
size_t j=0; j<num_nodes; j++)
66 for (
size_t qp : qp_data.QuadraturePointIndices())
70 qp_data.ShapeValue(i, qp) * qp_data.ShapeValue(j, qp) *
76 for (
size_t qp : qp_data.QuadraturePointIndices())
79 qp_data.ShapeValue(i, qp) *
83 VecSetValue(
rhs_, imap, entry_rhs_i, ADD_VALUES);
87 for (
size_t f=0; f<num_faces; ++f)
89 const auto& face = cell.faces_[f];
90 const auto& n_f = face.normal_;
91 const size_t num_face_nodes = cell_mapping.NumFaceNodes(f);
92 const auto fqp_data = cell_mapping.MakeSurfaceQuadraturePointData(f);
96 if (not face.has_neighbor_)
99 if (
bcs_.count(face.neighbor_id_) > 0)
100 bc =
bcs_.at(face.neighbor_id_);
104 const double bc_value = bc.values[0];
116 for (
size_t fi=0; fi<num_face_nodes; ++fi)
118 const int i = cell_mapping.MapFaceNode(f,fi);
121 for (
size_t fj=0; fj<num_face_nodes; ++fj)
123 const int jm = cell_mapping.MapFaceNode(f,fj);
126 for (
size_t qp : fqp_data.QuadraturePointIndices())
128 fqp_data.ShapeValue(i, qp) * fqp_data.ShapeValue(jm, qp) *
130 double aij_bc_value = aij*bc_value;
132 if (not solution_function.empty())
135 for (
size_t qp : fqp_data.QuadraturePointIndices())
138 fqp_data.QPointXYZ(qp)) *
139 fqp_data.ShapeValue(i, qp) * fqp_data.ShapeValue(jm, qp) *
143 VecSetValue(
rhs_, imap, aij_bc_value, ADD_VALUES);
152 for (
size_t i=0; i<num_nodes; i++)
156 for (
size_t j=0; j<num_nodes; j++)
159 for (
size_t qp : fqp_data.QuadraturePointIndices())
161 fqp_data.ShapeValue(j, qp) * fqp_data.ShapeGrad(i, qp) *
163 fqp_data.ShapeValue(i, qp) * fqp_data.ShapeGrad(j, qp) *
165 const double aij = -Dg*n_f.
Dot(vec_aij);
167 double aij_bc_value = aij*bc_value;
169 if (not solution_function.empty())
172 for (
size_t qp : fqp_data.QuadraturePointIndices())
175 fqp_data.QPointXYZ(qp)) *
176 (fqp_data.ShapeValue(j, qp) * fqp_data.ShapeGrad(i, qp) *
178 fqp_data.ShapeValue(i, qp) * fqp_data.ShapeGrad(j, qp) *
180 aij_bc_value = -Dg*n_f.Dot(vec_aij_mms);
183 VecSetValue(
rhs_, imap, aij_bc_value, ADD_VALUES);
189 const double bval = bc.values[1];
190 const double fval = bc.values[2];
192 if (std::fabs(bval) < 1.0e-12)
continue;
194 for (
size_t fi=0; fi<num_face_nodes; fi++)
196 const int i = cell_mapping.MapFaceNode(f,fi);
199 if (std::fabs(fval) >= 1.0e-12)
201 double rhs_val = 0.0;
202 for (
size_t qp : fqp_data.QuadraturePointIndices())
203 rhs_val += fqp_data.ShapeValue(i,qp) * fqp_data.JxW(qp);
204 rhs_val *= (fval/bval);
206 VecSetValue(
rhs_, ir, rhs_val, ADD_VALUES);
215 VecAssemblyBegin(
rhs_);
216 VecAssemblyEnd(
rhs_);
static chi::Timer program_timer
static chi::Console & console
LogStream Log(LOG_LVL level=LOG_0)
lua_State *& GetConsoleState()
std::string GetTimeString() 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
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)
void Assemble_b_wQpoints(const std::vector< double > &q_vector)
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.