10 auto pwl_sdm = std::static_pointer_cast<
14 size_t num_nodes = fe_intgrl_values.NumNodes();
17 std::vector<double> D(num_nodes, 1.0);
18 std::vector<double> q(num_nodes, 1.0);
19 std::vector<double> siga(num_nodes, 0.0);
24 typedef std::vector<double> Row;
25 typedef std::vector<Row> Matrix;
28 std::vector<double> cell_rhs;
30 cell_matrix.resize(num_nodes, Row(num_nodes, 0.0));
31 cell_rhs.resize(num_nodes, 0.0);
33 std::vector<int64_t> dof_global_row_ind(num_nodes, -1);
34 std::vector<int64_t> dof_global_col_ind(num_nodes, -1);
37 for (
int i=0; i<num_nodes; i++)
39 dof_global_row_ind[i] = pwl_sdm->MapDOF(cell,i);
41 for (
int j=0; j<num_nodes; j++)
44 D[j]* fe_intgrl_values.IntV_gradShapeI_gradShapeJ(i, j) +
45 siga[j]* fe_intgrl_values.IntV_shapeI_shapeJ(i, j);
47 cell_matrix[i][j] = mat_entry;
51 cell_rhs[i] = q[i]* fe_intgrl_values.IntV_shapeI(i);
53 dof_global_col_ind = dof_global_row_ind;
58 std::vector<int> dirichlet_count(num_nodes, 0);
59 std::vector<double> dirichlet_value(num_nodes, 0.0);
60 for (
int f=0; f<cell.
faces_.size(); f++)
62 if (not cell.
faces_[f].has_neighbor_)
64 uint64_t ir_boundary_index = cell.
faces_[f].neighbor_id_;
65 auto ir_boundary_type =
boundaries_.at(ir_boundary_index)->type_;
69 auto& dirichlet_bndry =
72 int num_face_dofs = cell.
faces_[f].vertex_ids_.size();
73 for (
int fi=0; fi<num_face_dofs; fi++)
75 int i = fe_intgrl_values.FaceDofMapping(f,fi);
76 dirichlet_count[i] += 1;
77 dirichlet_value[i] += dirichlet_bndry.boundary_value;
86 std::cout << robin_bndry.a <<
" " << robin_bndry.b <<
" " << robin_bndry.f << std::endl;
88 int num_face_dofs = cell.
faces_[f].vertex_ids_.size();
89 for (
int fi=0; fi<num_face_dofs; fi++)
91 int i = fe_intgrl_values.FaceDofMapping(f,fi);
93 for (
int fj=0; fj<num_face_dofs; fj++)
95 int j = fe_intgrl_values.FaceDofMapping(f,fj);
97 double aij = robin_bndry.a* fe_intgrl_values.IntS_shapeI_shapeJ(f, i, j);
100 cell_matrix[i][j] += aij;
103 double aii = robin_bndry.f* fe_intgrl_values.IntS_shapeI(f, i);
104 aii /= robin_bndry.b;
106 cell_matrix[i][i] += aii;
116 for (
int i=0; i<num_nodes; ++i)
117 dirichlet_value[i] /= (dirichlet_count[i] > 0)? dirichlet_count[i] : 1;
119 for (
int i=0; i<num_nodes; ++i)
121 if (dirichlet_count[i] > 0)
123 cell_matrix[i].clear();
124 cell_matrix[i] = std::vector<double>(num_nodes, 0.0);
125 cell_matrix[i][i] = 1.0;
126 int ir = dof_global_col_ind[i];
127 MatSetValue(
A_, ir, ir, 1.0, ADD_VALUES);
128 dof_global_col_ind[i] = -1;
129 cell_rhs[i] = dirichlet_value[i];
133 for (
int j=0; j<num_nodes; ++j)
135 if (dirichlet_count[j] > 0)
137 cell_rhs[i] -= cell_matrix[i][j]*dirichlet_value[j];
138 cell_matrix[i][j] = 0.0;
145 std::vector<double> cell_matrix_cont(num_nodes * num_nodes, 0.0);
147 for (
int i=0; i<num_nodes; ++i)
148 for (
int j=0; j<num_nodes; ++j)
149 cell_matrix_cont[n++] = cell_matrix[i][j];
153 num_nodes, dof_global_row_ind.data(),
154 num_nodes, dof_global_col_ind.data(),
155 cell_matrix_cont.data(), ADD_VALUES);
158 num_nodes, dof_global_row_ind.data(),
159 cell_rhs.data(), ADD_VALUES);
163 dof_global_row_ind.data(),
164 dirichlet_value.data(), INSERT_VALUES);
std::map< uint64_t, UnitIntegralContainer > unit_integrals_
void CFEM_Assemble_A_and_b(chi_mesh::Cell &cell, int group=0)
void GetMaterialProperties(const chi_mesh::Cell &cell, int cell_dofs, std::vector< double > &diffCoeff, std::vector< double > &sourceQ, std::vector< double > &sigmaa, int group=0, int moment=0)
std::map< uint64_t, chi_diffusion::Boundary * > boundaries_
std::shared_ptr< chi_math::SpatialDiscretization > discretization_
std::vector< CellFace > faces_