53 return Selection(
"DG_variant",
"Type of penalty term.")
54 .
add_value(non_symmetric,
"non-symmetric",
"non-symmetric weighted interior penalty DG method")
55 .
add_value(incomplete,
"incomplete",
"incomplete weighted interior penalty DG method")
56 .
add_value(symmetric,
"symmetric",
"symmetric weighted interior penalty DG method")
79 std::string equation_name = std::string(Model::ModelEqData::name()) +
"_DG";
80 return Model::get_input_type(
"DG",
"DG solver")
82 "Linear solver for MH problem.")
85 .make_field_descriptor_type(equation_name)),
87 "Input fields of the equation.")
89 "Variant of interior penalty discontinuous Galerkin method.")
91 "Polynomial order for finite element in DG method (order 0 is suitable if there is no diffusion/dispersion).")
93 EqData().output_fields.make_output_type(equation_name,
""),
94 IT::Default(
"{ \"fields\": [ " + Model::ModelEqData::default_output_field() +
"] }"),
95 "Setting of the field output.")
101 Input::register_class< TransportDG<Model>,
Mesh &,
const Input::Record>(std::string(Model::ModelEqData::name()) +
"_DG") +
109 unsigned int q_order;
111 q_order = 2*fe_order;
130 ds_ = std::make_shared<EqualOrderDiscreteSpace>(
mesh_, fe0_, fe1_, fe2_, fe3_);
131 dh_ = std::make_shared<DOFHandlerMultiDim>(*mesh_);
133 dh_->distribute_dofs(ds_,
true);
177 template<
class Model>
181 .
name(
"fracture_sigma")
183 "Coefficient of diffusive transfer through fractures (for each substance).")
191 "Penalty parameter influencing the discontinuity of the solution (for each substance). " 192 "Its default value 1 is sufficient in most cases. Higher value diminishes the inter-element jumps.")
211 template<
class Model>
213 : Model(init_mesh, in_rec),
227 data_.set_mesh(init_mesh);
236 Model::init_from_input(in_rec);
245 template<
class Model>
248 data_.set_components(Model::substances_.names());
252 gamma.resize(Model::n_substances());
253 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
254 gamma[sbi].resize(Model::mesh_->boundary_.size());
257 int qsize = max(
feo->
q<0>()->size(), max(
feo->
q<1>()->size(), max(
feo->
q<2>()->size(),
feo->
q<3>()->size())));
258 int max_edg_sides = max(Model::mesh_->max_edge_sides(1), max(Model::mesh_->max_edge_sides(2), Model::mesh_->max_edge_sides(3)));
260 ret_coef.resize(Model::n_substances());
263 ad_coef.resize(Model::n_substances());
264 dif_coef.resize(Model::n_substances());
265 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
273 for (
int sd=0; sd<max_edg_sides; sd++)
277 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
288 unsigned int output_vector_size= (rank==0)?
feo->
dh()->n_global_dofs():0;
289 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
295 data_.output_field.set_components(Model::substances_.names());
296 data_.output_field.set_mesh(*Model::mesh_);
299 data_.output_field.setup_components();
300 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
305 data_.output_field[sbi].set_field(Model::mesh_->region_db().get_region_set(
"ALL"), output_field_ptr, 0);
312 std::string petsc_default_opts;
313 if (
feo->
dh()->distr()->np() == 1)
314 petsc_default_opts =
"-ksp_type bcgs -pc_type ilu -pc_factor_levels 2 -ksp_diagonal_scale_fix -pc_factor_fill 6.0";
316 petsc_default_opts =
"-ksp_type bcgs -ksp_diagonal_scale_fix -pc_type asm -pc_asm_overlap 4 -sub_pc_type ilu -sub_pc_factor_levels 3 -sub_pc_factor_fill 6.0";
319 ls =
new LinSys*[Model::n_substances()];
324 mass_matrix.resize(Model::n_substances(),
nullptr);
325 rhs.resize(Model::n_substances(),
nullptr);
326 mass_vec.resize(Model::n_substances(),
nullptr);
327 ret_vec.resize(Model::n_substances(),
nullptr);
329 for (
unsigned int sbi = 0; sbi < Model::n_substances(); sbi++) {
336 solution_elem_[sbi] =
new double[Model::mesh_->get_el_ds()->lsize()];
343 Model::balance_->allocate(
feo->
dh()->distr()->lsize(),
344 max(
feo->
fe<1>()->n_dofs(), max(
feo->
fe<2>()->n_dofs(),
feo->
fe<3>()->n_dofs())));
349 template<
class Model>
354 if (
gamma.size() > 0) {
357 for (
unsigned int i=0; i<Model::n_substances(); i++)
389 template<
class Model>
392 VecScatter output_scatter;
393 VecScatterCreateToZero(
ls[0]->
get_solution(), &output_scatter, PETSC_NULL);
394 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
397 VecScatterBegin(output_scatter,
ls[sbi]->
get_solution(), (
output_vec[sbi]).get_data_petsc(), INSERT_VALUES, SCATTER_FORWARD);
398 VecScatterEnd(output_scatter,
ls[sbi]->
get_solution(), (
output_vec[sbi]).get_data_petsc(), INSERT_VALUES, SCATTER_FORWARD);
400 chkerr(VecScatterDestroy(&(output_scatter)));
406 template<
class Model>
410 data_.mark_input_times( *(Model::time_) );
412 std::stringstream ss;
420 for (
unsigned int sbi = 0; sbi < Model::n_substances(); sbi++)
427 for (
unsigned int sbi=0; sbi<Model::n_substances(); ++sbi)
429 Model::balance_->calculate_instant(Model::subst_idx[sbi],
ls[sbi]->
get_solution());
439 template<
class Model>
443 for (
unsigned int i=0; i<Model::n_substances(); i++)
459 for (
unsigned int i=0; i<Model::n_substances(); i++)
470 template<
class Model>
475 Model::time_->next_time();
476 Model::time_->view(
"TDG");
485 for (
unsigned int i=0; i<Model::n_substances(); i++)
492 for (
unsigned int i=0; i<Model::n_substances(); i++)
502 MatConvert(*(
ls_dt[i]->get_matrix() ), MATSAME, MAT_INITIAL_MATRIX, &
mass_matrix[i]);
505 MatCopy(*(
ls_dt[i]->get_matrix() ),
mass_matrix[i], DIFFERENT_NONZERO_PATTERN);
512 || Model::flux_changed)
516 for (
unsigned int i=0; i<Model::n_substances(); i++)
522 for (
unsigned int i=0; i<Model::n_substances(); i++)
527 MatConvert(*(
ls[i]->get_matrix() ), MATSAME, MAT_INITIAL_MATRIX, &
stiffness_matrix[i]);
536 || Model::flux_changed)
538 for (
unsigned int i=0; i<Model::n_substances(); i++)
545 for (
unsigned int i=0; i<Model::n_substances(); i++)
549 if (
rhs[i] ==
nullptr) VecDuplicate(*(
ls[i]->get_rhs() ), &
rhs[i]);
550 VecCopy(*(
ls[i]->get_rhs() ),
rhs[i]);
554 Model::flux_changed =
false;
575 for (
unsigned int i=0; i<Model::n_substances(); i++)
578 MatAXPY(m, 1./Model::time_->dt(),
mass_matrix[i], SUBSET_NONZERO_PATTERN);
581 VecDuplicate(
rhs[i], &w);
582 VecWAXPY(w, 1./Model::time_->dt(),
mass_vec[i],
rhs[i]);
601 template<
class Model>
605 for (
unsigned int i_cell=0; i_cell<Model::mesh_->get_el_ds()->lsize(); i_cell++)
613 n_dofs =
feo->
fe<1>()->n_dofs();
616 n_dofs =
feo->
fe<2>()->n_dofs();
619 n_dofs =
feo->
fe<3>()->n_dofs();
624 feo->
dh()->get_dof_indices(elem, dof_indices);
626 for (
unsigned int sbi=0; sbi<Model::n_substances(); ++sbi)
630 for (
unsigned int j=0; j<n_dofs; ++j)
631 solution_elem_[sbi][i_cell] +=
ls[sbi]->get_solution_array()[dof_indices[j]-
feo->
dh()->distr()->begin()];
641 template<
class Model>
654 Model::output_data();
657 for (
unsigned int sbi=0; sbi<Model::n_substances(); ++sbi)
658 Model::balance_->calculate_instant(Model::subst_idx[sbi],
ls[sbi]->
get_solution());
659 Model::balance_->output();
666 template<
class Model>
669 if (Model::balance_->cumulative())
671 for (
unsigned int sbi=0; sbi<Model::n_substances(); ++sbi)
673 Model::balance_->calculate_cumulative(Model::subst_idx[sbi],
ls[sbi]->
get_solution());
685 template<
class Model>
689 Model::balance_->start_mass_assembly(Model::subst_idx);
690 assemble_mass_matrix<1>();
691 assemble_mass_matrix<2>();
692 assemble_mass_matrix<3>();
693 Model::balance_->finish_mass_assembly(Model::subst_idx);
698 template<
class Model>
template<
unsigned int dim>
702 const unsigned int ndofs =
feo->
fe<dim>()->n_dofs(), qsize =
feo->
q<dim>()->size();
704 PetscScalar local_mass_matrix[ndofs*ndofs], local_retardation_balance_vector[ndofs];
708 for (
unsigned int i_cell=0; i_cell<Model::mesh_->get_el_ds()->lsize(); i_cell++)
711 if (cell->
dim() != dim)
continue;
714 feo->
dh()->get_dof_indices(cell, dof_indices);
719 for (
unsigned int sbi=0; sbi<Model::n_substances(); ++sbi)
722 for (
unsigned int i=0; i<ndofs; i++)
724 for (
unsigned int j=0; j<ndofs; j++)
726 local_mass_matrix[i*ndofs+j] = 0;
727 for (
unsigned int k=0; k<qsize; k++)
732 for (
unsigned int i=0; i<ndofs; i++)
734 local_mass_balance_vector[i] = 0;
735 local_retardation_balance_vector[i] = 0;
736 for (
unsigned int k=0; k<qsize; k++)
743 Model::balance_->add_mass_matrix_values(Model::subst_idx[sbi], cell.
region().
bulk_idx(), dof_indices, local_mass_balance_vector);
744 ls_dt[sbi]->
mat_set_values(ndofs, &(dof_indices[0]), ndofs, &(dof_indices[0]), local_mass_matrix);
745 VecSetValues(
ret_vec[sbi], ndofs, &(dof_indices[0]), local_retardation_balance_vector, ADD_VALUES);
753 template<
class Model>
758 assemble_volume_integrals<1>();
759 assemble_volume_integrals<2>();
760 assemble_volume_integrals<3>();
764 assemble_fluxes_boundary<1>();
765 assemble_fluxes_boundary<2>();
766 assemble_fluxes_boundary<3>();
770 assemble_fluxes_element_element<1>();
771 assemble_fluxes_element_element<2>();
772 assemble_fluxes_element_element<3>();
776 assemble_fluxes_element_side<1>();
777 assemble_fluxes_element_side<2>();
778 assemble_fluxes_element_side<3>();
785 template<
class Model>
786 template<
unsigned int dim>
793 const unsigned int ndofs =
feo->
fe<dim>()->n_dofs(), qsize =
feo->
q<dim>()->size();
797 PetscScalar local_matrix[ndofs*ndofs];
800 for (
unsigned int i_cell=0; i_cell<Model::mesh_->get_el_ds()->lsize(); i_cell++)
803 if (cell->
dim() != dim)
continue;
807 feo->
dh()->get_dof_indices(cell, dof_indices);
811 Model::compute_sources_sigma(fe_values.
point_list(), cell, sources_sigma);
814 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
816 for (
unsigned int i=0; i<ndofs; i++)
817 for (
unsigned int j=0; j<ndofs; j++)
818 local_matrix[i*ndofs+j] = 0;
820 for (
unsigned int k=0; k<qsize; k++)
822 for (
unsigned int i=0; i<ndofs; i++)
825 double ad_dot_grad_i = arma::dot(ad_coef[sbi][k], fe_values.
shape_grad(i,k));
827 for (
unsigned int j=0; j<ndofs; j++)
828 local_matrix[i*ndofs+j] += (arma::dot(Kt_grad_i, fe_values.
shape_grad(j,k))
833 ls[sbi]->
mat_set_values(ndofs, &(dof_indices[0]), ndofs, &(dof_indices[0]), local_matrix);
839 template<
class Model>
843 Model::balance_->start_source_assembly(Model::subst_idx);
847 Model::balance_->finish_source_assembly(Model::subst_idx);
851 template<
class Model>
852 template<
unsigned int dim>
857 const unsigned int ndofs =
feo->
fe<dim>()->n_dofs(), qsize =
feo->
q<dim>()->size();
862 PetscScalar local_rhs[ndofs];
867 for (
unsigned int i_cell=0; i_cell<Model::mesh_->get_el_ds()->lsize(); i_cell++)
870 if (cell->
dim() != dim)
continue;
873 feo->
dh()->get_dof_indices(cell, dof_indices);
875 Model::compute_source_coefficients(fe_values.
point_list(), cell, sources_conc, sources_density, sources_sigma);
878 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
880 fill_n(local_rhs, ndofs, 0);
881 local_source_balance_vector.assign(ndofs, 0);
882 local_source_balance_rhs.assign(ndofs, 0);
885 for (
unsigned int k=0; k<qsize; k++)
887 source = (sources_density[sbi][k] + sources_conc[sbi][k]*sources_sigma[sbi][k])*fe_values.
JxW(k);
889 for (
unsigned int i=0; i<ndofs; i++)
894 for (
unsigned int i=0; i<ndofs; i++)
896 for (
unsigned int k=0; k<qsize; k++)
897 local_source_balance_vector[i] -= sources_sigma[sbi][k]*fe_values.
shape_value(i,k)*fe_values.
JxW(k);
899 local_source_balance_rhs[i] += local_rhs[i];
901 Model::balance_->add_source_matrix_values(Model::subst_idx[sbi], cell.
region().
bulk_idx(), dof_indices, local_source_balance_vector);
902 Model::balance_->add_source_vec_values(Model::subst_idx[sbi], cell.
region().
bulk_idx(), dof_indices, local_source_balance_rhs);
909 template<
class Model>
910 template<
unsigned int dim>
916 const unsigned int ndofs =
feo->
fe<dim>()->n_dofs(), qsize =
feo->
q<dim-1>()->size(),
919 PetscScalar local_matrix[ndofs*ndofs];
922 double gamma_l, omega[2], transport_flux;
924 for (
unsigned int sid=0; sid<n_max_sides; sid++)
932 for (
unsigned int iedg=0; iedg<
feo->
dh()->n_loc_edges(); iedg++)
934 Edge *edg = &Model::mesh_->edges[
feo->
dh()->edge_index(iedg)];
937 for (
int sid=0; sid<edg->
n_sides; sid++)
940 feo->
dh()->get_dof_indices(cell, side_dof_indices[sid]);
941 fe_values[sid]->reinit(cell, edg->
side(sid)->
side_idx());
944 Model::compute_advection_diffusion_coefficients(fe_values[sid]->point_list(), side_velocity[sid], cell,
ad_coef_edg[sid],
dif_coef_edg[sid]);
945 dg_penalty[sid].resize(Model::n_substances());
946 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
951 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
954 for (
int sid=0; sid<edg->
n_sides; sid++)
957 for (
unsigned int k=0; k<qsize; k++)
958 fluxes[sid] += arma::dot(
ad_coef_edg[sid][sbi][k], fe_values[sid]->normal_vector(k))*fe_values[sid]->JxW(k);
962 for (
int s1=0; s1<edg->
n_sides; s1++)
964 for (
int s2=s1+1; s2<edg->
n_sides; s2++)
970 arma::vec3 nv = fe_values[s1]->normal_vector(0);
973 set_DG_parameters_edge(*edg, s1, s2, qsize,
dif_coef_edg[s1][sbi],
dif_coef_edg[s2][sbi], fluxes, fe_values[0]->normal_vector(0), dg_penalty[s1][sbi], dg_penalty[s2][sbi], gamma_l, omega, transport_flux);
979 #define AVERAGE(i,k,side_id) (fe_values[sd[side_id]]->shape_value(i,k)*0.5) 980 #define WAVERAGE(i,k,side_id) (arma::dot(dif_coef_edg[sd[side_id]][sbi][k]*fe_values[sd[side_id]]->shape_grad(i,k),nv)*omega[side_id]) 981 #define JUMP(i,k,side_id) ((side_id==0?1:-1)*fe_values[sd[side_id]]->shape_value(i,k)) 984 for (
int n=0; n<2; n++)
988 for (
int m=0; m<2; m++)
990 for (
unsigned int i=0; i<fe_values[sd[n]]->n_dofs(); i++)
991 for (
unsigned int j=0; j<fe_values[sd[m]]->n_dofs(); j++)
992 local_matrix[i*fe_values[sd[m]]->n_dofs()+j] = 0;
994 for (
unsigned int k=0; k<qsize; k++)
996 double flux_times_JxW = transport_flux*fe_values[0]->JxW(k);
997 double gamma_times_JxW = gamma_l*fe_values[0]->JxW(k);
999 for (
unsigned int i=0; i<fe_values[sd[n]]->n_dofs(); i++)
1001 double flux_JxW_jump_i = flux_times_JxW*
JUMP(i,k,n);
1002 double gamma_JxW_jump_i = gamma_times_JxW*
JUMP(i,k,n);
1003 double JxW_jump_i = fe_values[0]->JxW(k)*
JUMP(i,k,n);
1006 for (
unsigned int j=0; j<fe_values[sd[m]]->n_dofs(); j++)
1008 int index = i*fe_values[sd[m]]->n_dofs()+j;
1011 local_matrix[index] += flux_JxW_jump_i*
AVERAGE(j,k,m);
1014 local_matrix[index] += gamma_JxW_jump_i*
JUMP(j,k,m);
1017 local_matrix[index] -=
WAVERAGE(j,k,m)*JxW_jump_i;
1018 local_matrix[index] -=
JUMP(j,k,m)*JxW_var_wavg_i;
1022 ls[sbi]->
mat_set_values(fe_values[sd[n]]->n_dofs(), &(side_dof_indices[sd[n]][0]), fe_values[sd[m]]->n_dofs(), &(side_dof_indices[sd[m]][0]), local_matrix);
1033 for (
unsigned int i=0; i<n_max_sides; i++)
1035 delete fe_values[i];
1040 template<
class Model>
1041 template<
unsigned int dim>
1048 const unsigned int ndofs =
feo->
fe<dim>()->n_dofs(), qsize =
feo->
q<dim-1>()->size();
1050 PetscScalar local_matrix[ndofs*ndofs];
1057 for (
unsigned int iedg=0; iedg<
feo->
dh()->n_loc_edges(); iedg++)
1059 Edge *edg = &Model::mesh_->edges[
feo->
dh()->edge_index(iedg)];
1060 if (edg->
n_sides > 1)
continue;
1062 if (edg->
side(0)->
dim() != dim-1)
continue;
1064 if (edg->
side(0)->
cond() == NULL)
continue;
1068 feo->
dh()->get_dof_indices(cell, side_dof_indices);
1076 data_.cross_section.value_list(fe_values_side.
point_list(), cell, csection);
1078 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
1080 for (
unsigned int i=0; i<ndofs; i++)
1081 for (
unsigned int j=0; j<ndofs; j++)
1082 local_matrix[i*ndofs+j] = 0;
1086 double side_flux = 0;
1087 for (
unsigned int k=0; k<qsize; k++)
1088 side_flux += arma::dot(ad_coef[sbi][k], fe_values_side.
normal_vector(k))*fe_values_side.
JxW(k);
1089 double transport_flux = side_flux/side->
measure();
1096 transport_flux += gamma_l;
1100 for (
unsigned int k=0; k<qsize; k++)
1102 double flux_times_JxW;
1106 flux_times_JxW = csection[k]*robin_sigma[k]*fe_values_side.
JxW(k);
1111 flux_times_JxW = (transport_flux + csection[k]*robin_sigma[k])*fe_values_side.
JxW(k);
1116 flux_times_JxW = transport_flux*fe_values_side.
JxW(k);
1118 for (
unsigned int i=0; i<ndofs; i++)
1120 for (
unsigned int j=0; j<ndofs; j++)
1123 local_matrix[i*ndofs+j] += flux_times_JxW*fe_values_side.
shape_value(i,k)*fe_values_side.
shape_value(j,k);
1129 )*fe_values_side.
JxW(k);
1134 ls[sbi]->
mat_set_values(ndofs, &(side_dof_indices[0]), ndofs, &(side_dof_indices[0]), local_matrix);
1140 template<
class Model>
1141 template<
unsigned int dim>
1145 if (dim == 1)
return;
1156 const unsigned int ndofs =
feo->
fe<dim>()->n_dofs();
1157 const unsigned int qsize =
feo->
q<dim-1>()->size();
1158 int side_dof_indices[2*ndofs];
1160 unsigned int n_dofs[2], n_indices;
1164 PetscScalar local_matrix[4*ndofs*ndofs];
1165 double comm_flux[2][2];
1169 fv_sb[0] = &fe_values_vb;
1170 fv_sb[1] = &fe_values_side;
1173 for (
unsigned int inb=0; inb<
feo->
dh()->n_loc_nb(); inb++)
1175 Neighbour *nb = &Model::mesh_->vb_neighbours_[
feo->
dh()->nb_index(inb)];
1180 n_indices =
feo->
dh()->get_dof_indices(cell_sub, indices);
1181 for(
unsigned int i=0; i<n_indices; ++i) {
1182 side_dof_indices[i] = indices[i];
1184 fe_values_vb.
reinit(cell_sub);
1185 n_dofs[0] = fv_sb[0]->n_dofs();
1188 n_indices =
feo->
dh()->get_dof_indices(cell, indices);
1189 for(
unsigned int i=0; i<n_indices; ++i) {
1190 side_dof_indices[i+n_dofs[0]] = indices[i];
1193 n_dofs[1] = fv_sb[1]->n_dofs();
1197 element_id[0] = cell_sub.
idx();
1198 element_id[1] = cell.
idx();
1205 Model::compute_advection_diffusion_coefficients(fe_values_vb.
point_list(), velocity_higher, cell, ad_coef_edg[1],
dif_coef_edg[1]);
1206 data_.cross_section.value_list(fe_values_vb.
point_list(), cell_sub, csection_lower);
1207 data_.cross_section.value_list(fe_values_vb.
point_list(), cell, csection_higher);
1209 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
1211 for (
unsigned int i=0; i<n_dofs[0]+n_dofs[1]; i++)
1212 for (
unsigned int j=0; j<n_dofs[0]+n_dofs[1]; j++)
1213 local_matrix[i*(n_dofs[0]+n_dofs[1])+j] = 0;
1218 for (
unsigned int k=0; k<qsize; k++)
1229 2*csection_higher[k]*csection_higher[k]/(csection_lower[k]*csection_lower[k]);
1231 double transport_flux = arma::dot(ad_coef_edg[1][sbi][k], fe_values_side.
normal_vector(k));
1233 comm_flux[0][0] = (sigma-min(0.,transport_flux))*fv_sb[0]->JxW(k);
1234 comm_flux[0][1] = -(sigma-min(0.,transport_flux))*fv_sb[0]->JxW(k);
1235 comm_flux[1][0] = -(sigma+max(0.,transport_flux))*fv_sb[0]->JxW(k);
1236 comm_flux[1][1] = (sigma+max(0.,transport_flux))*fv_sb[0]->JxW(k);
1238 for (
int n=0; n<2; n++)
1240 if (!
feo->
dh()->el_is_local(element_id[n]))
continue;
1242 for (
unsigned int i=0; i<n_dofs[n]; i++)
1243 for (
int m=0; m<2; m++)
1244 for (
unsigned int j=0; j<n_dofs[m]; j++)
1245 local_matrix[(i+n*n_dofs[0])*(n_dofs[0]+n_dofs[1]) + m*n_dofs[0] + j] +=
1246 comm_flux[m][n]*fv_sb[m]->shape_value(j,k)*fv_sb[n]->shape_value(i,k);
1249 ls[sbi]->
mat_set_values(n_dofs[0]+n_dofs[1], side_dof_indices, n_dofs[0]+n_dofs[1], side_dof_indices, local_matrix);
1260 template<
class Model>
1264 Model::balance_->start_flux_assembly(Model::subst_idx);
1265 set_boundary_conditions<1>();
1266 set_boundary_conditions<2>();
1267 set_boundary_conditions<3>();
1268 Model::balance_->finish_flux_assembly(Model::subst_idx);
1273 template<
class Model>
1274 template<
unsigned int dim>
1281 const unsigned int ndofs =
feo->
fe<dim>()->n_dofs(), qsize =
feo->
q<dim-1>()->size();
1283 unsigned int loc_b=0;
1284 double local_rhs[ndofs];
1286 PetscScalar local_flux_balance_rhs;
1290 bc_ref_values(qsize);
1294 for (
unsigned int loc_el = 0; loc_el < Model::mesh_->get_el_ds()->lsize(); loc_el++)
1299 for (
unsigned int si=0; si<elm->
n_sides(); si++)
1302 if (edg->
n_sides > 1)
continue;
1304 if (edg->
side(0)->
cond() == NULL)
continue;
1306 if (edg->
side(0)->
dim() != dim-1)
1308 if (edg->
side(0)->
cond() !=
nullptr) ++loc_b;
1317 Model::get_bc_type(ele_acc, bc_type);
1326 feo->
dh()->get_dof_indices(cell, side_dof_indices);
1328 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
1330 fill_n(local_rhs, ndofs, 0);
1331 local_flux_balance_vector.assign(ndofs, 0);
1332 local_flux_balance_rhs = 0;
1336 data_.bc_dirichlet_value[sbi].value_list(fe_values_side.
point_list(), ele_acc, bc_values);
1338 double side_flux = 0;
1339 for (
unsigned int k=0; k<qsize; k++)
1341 double transport_flux = side_flux/side->
measure();
1345 for (
unsigned int k=0; k<qsize; k++)
1347 double bc_term = -transport_flux*bc_values[k]*fe_values_side.
JxW(k);
1348 for (
unsigned int i=0; i<ndofs; i++)
1349 local_rhs[i] += bc_term*fe_values_side.
shape_value(i,k);
1351 for (
unsigned int i=0; i<ndofs; i++)
1352 local_flux_balance_rhs -= local_rhs[i];
1356 for (
unsigned int k=0; k<qsize; k++)
1358 double bc_term =
gamma[sbi][side->
cond_idx()]*bc_values[k]*fe_values_side.
JxW(k);
1360 for (
unsigned int i=0; i<ndofs; i++)
1361 local_rhs[i] += bc_term*fe_values_side.
shape_value(i,k)
1362 + arma::dot(bc_grad,fe_values_side.
shape_grad(i,k));
1364 for (
unsigned int k=0; k<qsize; k++)
1366 for (
unsigned int i=0; i<ndofs; i++)
1373 if (Model::time_->tlevel() > 0)
1374 for (
unsigned int i=0; i<ndofs; i++)
1375 local_flux_balance_rhs -= local_rhs[i];
1379 Model::get_flux_bc_data(sbi, fe_values_side.
point_list(), ele_acc, bc_fluxes, bc_sigma, bc_ref_values);
1380 for (
unsigned int k=0; k<qsize; k++)
1382 double bc_term = csection[k]*(bc_sigma[k]*bc_ref_values[k]+bc_fluxes[k])*fe_values_side.
JxW(k);
1383 for (
unsigned int i=0; i<ndofs; i++)
1384 local_rhs[i] += bc_term*fe_values_side.
shape_value(i,k);
1387 for (
unsigned int i=0; i<ndofs; i++)
1389 for (
unsigned int k=0; k<qsize; k++)
1390 local_flux_balance_vector[i] += csection[k]*bc_sigma[k]*fe_values_side.
JxW(k)*fe_values_side.
shape_value(i,k);
1391 local_flux_balance_rhs -= local_rhs[i];
1396 Model::get_flux_bc_data(sbi, fe_values_side.
point_list(), ele_acc, bc_fluxes, bc_sigma, bc_ref_values);
1397 for (
unsigned int k=0; k<qsize; k++)
1399 double bc_term = csection[k]*(bc_sigma[k]*bc_ref_values[k]+bc_fluxes[k])*fe_values_side.
JxW(k);
1400 for (
unsigned int i=0; i<ndofs; i++)
1401 local_rhs[i] += bc_term*fe_values_side.
shape_value(i,k);
1404 for (
unsigned int i=0; i<ndofs; i++)
1406 for (
unsigned int k=0; k<qsize; k++)
1407 local_flux_balance_vector[i] += csection[k]*(arma::dot(
ad_coef[sbi][k], fe_values_side.
normal_vector(k)) + bc_sigma[k])*fe_values_side.
JxW(k)*fe_values_side.
shape_value(i,k);
1408 local_flux_balance_rhs -= local_rhs[i];
1413 for (
unsigned int k=0; k<qsize; k++)
1415 for (
unsigned int i=0; i<ndofs; i++)
1421 Model::balance_->add_flux_matrix_values(Model::subst_idx[sbi], loc_b, side_dof_indices, local_flux_balance_vector);
1422 Model::balance_->add_flux_vec_value(Model::subst_idx[sbi], loc_b, local_flux_balance_rhs);
1431 template<
class Model>
1432 template<
unsigned int dim>
1437 OLD_ASSERT(cell->
dim() == dim,
"Element dimension mismatch!");
1441 for (
unsigned int k=0; k<fv.
n_points(); k++)
1443 velocity[k].zeros();
1444 for (
unsigned int sid=0; sid<cell->
n_sides(); sid++)
1445 for (
unsigned int c=0; c<3; ++c)
1454 double h_max = 0, h_min = numeric_limits<double>::infinity();
1455 for (
unsigned int i=0; i<e->
n_nodes(); i++)
1456 for (
unsigned int j=i+1; j<e->
n_nodes(); j++)
1466 template<
class Model>
1475 const double alpha1,
1476 const double alpha2,
1479 double &transport_flux)
1483 double local_alpha = 0;
1495 for (
unsigned int i=0; i<s->n_nodes(); i++)
1496 for (
unsigned int j=i+1; j<s->n_nodes(); j++)
1497 h = max(h, s->node(i)->distance(*s->node(j).node()));
1505 double pflux = 0, nflux = 0;
1506 for (
int i=0; i<edg.
n_sides; i++)
1515 if (fluxes[s2] > 0 && fluxes[s1] < 0 && s1 < s2)
1516 transport_flux = fluxes[s1]*fabs(fluxes[s2]/pflux);
1517 else if (fluxes[s2] < 0 && fluxes[s1] > 0 && s1 < s2)
1518 transport_flux = fluxes[s1]*fabs(fluxes[s2]/nflux);
1520 transport_flux = fluxes[s1];
1524 gamma = 0.5*fabs(transport_flux);
1528 local_alpha = max(alpha1, alpha2);
1536 for (
int k=0; k<K_size; k++)
1537 delta[0] += dot(K1[k]*normal_vector,normal_vector);
1540 gamma += local_alpha/h*aniso1*aniso2*delta[0];
1546 for (
int k=0; k<K_size; k++)
1548 delta[0] += dot(K1[k]*normal_vector,normal_vector);
1549 delta[1] += dot(K2[k]*normal_vector,normal_vector);
1554 double delta_sum = delta[0] + delta[1];
1557 if (fabs(delta_sum) > 0)
1559 omega[0] = delta[1]/delta_sum;
1560 omega[1] = delta[0]/delta_sum;
1561 gamma += local_alpha/h*aniso1*aniso2*(delta[0]*delta[1]/delta_sum);
1564 for (
int i=0; i<2; i++) omega[i] = 0;
1573 template<
class Model>
1582 double delta = 0, h = 0;
1585 if (side->
dim() == 0)
1591 for (
unsigned int i=0; i<side->
n_nodes(); i++)
1592 for (
unsigned int j=i+1; j<side->
n_nodes(); j++)
1593 h = max(h, side->
node(i)->distance( *side->
node(j).node() ));
1597 for (
int k=0; k<K_size; k++)
1598 delta += dot(K[k]*normal_vector,normal_vector);
1608 template<
class Model>
1612 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
1613 ls[sbi]->start_allocation();
1614 prepare_initial_condition<1>();
1615 prepare_initial_condition<2>();
1616 prepare_initial_condition<3>();
1618 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
1619 ls[sbi]->start_add_assembly();
1620 prepare_initial_condition<1>();
1621 prepare_initial_condition<2>();
1622 prepare_initial_condition<3>();
1624 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
1632 template<
class Model>
1633 template<
unsigned int dim>
1638 const unsigned int ndofs =
feo->
fe<dim>()->n_dofs(), qsize =
feo->
q<dim>()->size();
1640 double matrix[ndofs*ndofs],
rhs[ndofs];
1643 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
1644 init_values[sbi].resize(qsize);
1646 for (
unsigned int i_cell=0; i_cell<Model::mesh_->get_el_ds()->lsize(); i_cell++)
1649 if (elem->
dim() != dim)
continue;
1651 feo->
dh()->get_dof_indices(elem, dof_indices);
1654 Model::compute_init_cond(fe_values.
point_list(), elem, init_values);
1656 for (
unsigned int sbi=0; sbi<Model::n_substances(); sbi++)
1658 for (
unsigned int i=0; i<ndofs; i++)
1661 for (
unsigned int j=0; j<ndofs; j++)
1662 matrix[i*ndofs+j] = 0;
1665 for (
unsigned int k=0; k<qsize; k++)
1667 double rhs_term = init_values[sbi][k]*fe_values.
JxW(k);
1669 for (
unsigned int i=0; i<ndofs; i++)
1671 for (
unsigned int j=0; j<ndofs; j++)
1677 ls[sbi]->
set_values(ndofs, &(dof_indices[0]), ndofs, &(dof_indices[0]), matrix, rhs);
1683 template<
class Model>
1686 el_4_loc = Model::mesh_->get_el_4_loc();
1687 el_ds = Model::mesh_->get_el_ds();
1691 template<
class Model>
1694 if (solution_changed)
1696 for (
unsigned int i_cell=0; i_cell<Model::mesh_->get_el_ds()->lsize(); i_cell++)
1700 unsigned int n_dofs;
1701 switch (elem->
dim())
1704 n_dofs =
feo->
fe<1>()->n_dofs();
1707 n_dofs =
feo->
fe<2>()->n_dofs();
1710 n_dofs =
feo->
fe<3>()->n_dofs();
1715 feo->
dh()->get_dof_indices(elem, dof_indices);
1717 for (
unsigned int sbi=0; sbi<Model::n_substances(); ++sbi)
1719 double old_average = 0;
1720 for (
unsigned int j=0; j<n_dofs; ++j)
1721 old_average +=
ls[sbi]->get_solution_array()[dof_indices[j]-
feo->
dh()->distr()->begin()];
1722 old_average /= n_dofs;
1724 for (
unsigned int j=0; j<n_dofs; ++j)
1725 ls[sbi]->get_solution_array()[dof_indices[j]-
feo->
dh()->distr()->begin()] +=
solution_elem_[sbi][i_cell] - old_average;
1730 for (
unsigned int sbi=0; sbi<Model::n_substances(); ++sbi)
1734 template<
class Model>
1737 return Model::mesh_->get_row_4_el();
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
const Edge * edge() const
Input::Record input_rec
Record with input specification.
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell...
double JxW(const unsigned int point_no)
Return the product of Jacobian determinant and the quadrature weight at given quadrature point...
static auto subdomain(Mesh &mesh) -> IndexField
void assemble_fluxes_element_element()
Assembles the fluxes between elements of the same dimension.
void set_sources()
Assembles the right hand side due to volume sources.
FiniteElement< dim > * fe()
void set_boundary_conditions()
Assembles the r.h.s. components corresponding to the Dirichlet boundary conditions.
void get_par_info(LongIdx *&el_4_loc, Distribution *&el_ds)
unsigned int n_nodes() const
Transformed quadrature weight for cell sides.
vector< VectorSeqDouble > output_vec
Array for storing the output solution data.
vector< double > mm_coef
Mass matrix coefficients.
unsigned int * boundary_idx_
void assemble_fluxes_element_side()
Assembles the fluxes between elements of different dimensions.
static constexpr Mask in_main_matrix
A field is part of main "stiffness matrix" of the equation.
void reinit(ElementAccessor< 3 > &cell, unsigned int sid)
Update cell-dependent data (gradients, Jacobians etc.)
Solver based on the original PETSc solver using MPIAIJ matrix and succesive Schur complement construc...
unsigned int side_idx() const
void calculate_concentration_matrix()
Transport with dispersion implemented using discontinuous Galerkin method.
FieldCommon & flags_add(FieldFlag::Flags::Mask mask)
double distance(const Node &n2) const
void set_from_input(const Input::Record in_rec) override
virtual void start_add_assembly()
void assemble_mass_matrix()
Assembles the mass matrix.
void output(TimeStep step)
virtual PetscErrorCode mat_zero_entries()
virtual void rhs_set_values(int nrow, int *rows, double *vals)=0
void update_solution() override
Computes the solution in one time instant.
int dg_variant
DG variant ((non-)symmetric/incomplete.
void prepare_initial_condition()
Assembles the auxiliary linear system to calculate the initial solution as L^2-projection of the pres...
Fields computed from the mesh data.
virtual void start_allocation()
void set_initial_condition()
Sets the initial condition.
Class FEValues calculates finite element data on the actual cells such as shape function values...
void chkerr(unsigned int ierr)
Replacement of new/delete operator in the spirit of xmalloc.
virtual void finish_assembly()=0
vector< vector< arma::vec3 > > ad_coef
Advection coefficients.
SideIter side(const unsigned int loc_index)
#define AVERAGE(i, k, side_id)
std::shared_ptr< DOFHandlerMultiDim > dh()
void assemble_stiffness_matrix()
Assembles the stiffness matrix.
vector< vector< vector< arma::mat33 > > > dif_coef_edg
Diffusion coefficients on edges.
Discontinuous Galerkin method for equation of transport with dispersion.
const Vec & get_solution(unsigned int sbi)
FieldCommon & units(const UnitSI &units)
Set basic units of the field.
ElementAccessor< 3 > element() const
vector< double > ret_sources_prev
MultiField< 3, FieldValue< 3 >::Scalar > dg_penalty
Penalty enforcing inter-element continuity of solution (for each substance).
static const Input::Type::Selection & get_dg_variant_selection_input_type()
Input type for the DG variant selection.
unsigned int n_points()
Returns the number of quadrature points.
EquationOutput output_fields
std::vector< Mat > mass_matrix
The mass matrix.
void calculate_cumulative_balance()
void assemble_fluxes_boundary()
Assembles the fluxes on the boundary.
static constexpr bool value
Symmetric Gauss-Legendre quadrature formulae on simplices.
#define WAVERAGE(i, k, side_id)
TransportDG(Mesh &init_mesh, const Input::Record in_rec)
Constructor.
vector< vector< double > > ret_coef
Retardation coefficient due to sorption.
arma::vec::fixed< spacedim > centre() const
Computes the barycenter.
arma::vec::fixed< spacedim > normal_vector(unsigned int point_no)
Returns the normal vector to a side at given quadrature point.
ElementAccessor< 3 > element()
void initialize() override
vector< vector< vector< arma::vec3 > > > ad_coef_edg
Advection coefficients on edges.
Transformed quadrature points.
void output_data()
Postprocesses the solution and writes to output file.
virtual PetscErrorCode set_rhs(Vec &rhs)
MultiField< 3, FieldValue< 3 >::Scalar > fracture_sigma
Transition parameter for diffusive transfer on fractures (for each substance).
vector< vector< arma::mat33 > > dif_coef
Diffusion coefficients.
FEObjects * feo
Finite element objects.
static constexpr Mask in_time_term
A field is part of time term of the equation.
FieldCommon & input_default(const string &input_default)
const Vec & get_solution()
Raviart-Thomas element of order 0.
Definitions of basic Lagrangean finite elements with polynomial shape functions.
static constexpr Mask equation_external_output
Match an output field, that can be also copy of other field.
Field< 3, FieldValue< 3 >::Scalar > subdomain
unsigned int n_sides() const
static auto region_id(Mesh &mesh) -> IndexField
#define START_TIMER(tag)
Starts a timer with specified tag.
std::vector< Vec > rhs
Vector of right hand side.
Field< 3, FieldValue< 3 >::Scalar > region_id
double elem_anisotropy(ElementAccessor< 3 > e)
unsigned int dg_order
Polynomial order of finite elements.
void output_vector_gather()
static constexpr Mask in_rhs
A field is part of the right hand side of the equation.
Shape function gradients.
FLOW123D_FORCE_LINK_IN_CHILD(concentrationTransportModel)
void set_solution(double *sol_array)
NodeAccessor< 3 > node(unsigned int i) const
double shape_value(const unsigned int function_no, const unsigned int point_no)
Return the value of the function_no-th shape function at the point_no-th quadrature point...
virtual PetscErrorCode rhs_zero_entries()
Discontinuous Galerkin method for equation of transport with dispersion.
double ** solution_elem_
Element averages of solution (the array is passed to reactions in operator splitting).
std::vector< Mat > stiffness_matrix
The stiffness matrix.
FieldCommon & description(const string &description)
void set_values(int nrow, int *rows, int ncol, int *cols, PetscScalar *mat_vals, PetscScalar *rhs_vals)
Set values in the system matrix and values in the right-hand side vector on corresponding rows...
EqData data_
Field data for model parameters.
bool allocation_done
Indicates whether matrices have been preallocated.
unsigned int cond_idx() const
std::vector< std::vector< double > > gamma
Penalty parameters.
static const Input::Type::Record & get_input_type()
Declare input record type for the equation TransportDG.
void initialize(std::shared_ptr< OutputTime > stream, Mesh *mesh, Input::Record in_rec, const TimeGovernor &tg)
Discontinuous Galerkin method for equation of transport with dispersion.
void update_after_reactions(bool solution_changed)
MappingP1< dim, 3 > * mapping()
std::vector< Vec > ret_vec
Auxiliary vectors for calculation of sources in balance due to retardation (e.g. sorption).
double shape_value_component(const unsigned int function_no, const unsigned int point_no, const unsigned int comp) const
Return the value of the function_no-th shape function at the point_no-th quadrature point...
vector< double > ret_sources
Temporary values of increments due to retardation (e.g. sorption)
bool set_time(const TimeStep &time, LimitSide limit_side)
arma::vec::fixed< spacedim > shape_grad(const unsigned int function_no, const unsigned int point_no)
Return the gradient of the function_no-th shape function at the point_no-th quadrature point...
unsigned int bulk_idx() const
Returns index of the region in the bulk set.
Definitions of particular quadrature rules on simplices.
#define WarningOut()
Macro defining 'warning' record of log.
FieldCommon & name(const string &name)
virtual SolveInfo solve()=0
#define END_TIMER(tag)
Ends a timer with specified tag.
Discontinuous Galerkin method for equation of transport with dispersion.
void calculate_velocity(const ElementAccessor< 3 > &cell, std::vector< arma::vec3 > &velocity, FEValuesBase< dim, 3 > &fv)
Calculates the velocity field on a given dim dimensional cell.
vector< arma::vec::fixed< spacedim > > & point_list()
Return coordinates of all quadrature points in the actual cell system.
static const Input::Type::Record & get_input_type()
virtual PetscErrorCode set_matrix(Mat &matrix, MatStructure str)
std::vector< Vec > mass_vec
Mass from previous time instant (necessary when coefficients of mass matrix change in time)...
void assemble_volume_integrals()
Assembles the volume integrals into the stiffness matrix.
virtual void mat_set_values(int nrow, int *rows, int ncol, int *cols, double *vals)=0
FieldCommon & flags(FieldFlag::Flags::Mask mask)
Base class for FEValues and FESideValues.
static UnitSI & dimensionless()
Returns dimensionless unit.
static bool print_message_table(ostream &stream, std::string equation_name)
~TransportDG()
Destructor.
unsigned int idx() const
Return local idx of element in boundary / bulk part of element vector.
LinSys ** ls
Linear algebra system for the transport equation.
FiniteElement< dim > * fe_rt()
void set_DG_parameters_edge(const Edge &edg, const int s1, const int s2, const int K_size, const std::vector< arma::mat33 > &K1, const std::vector< arma::mat33 > &K2, const std::vector< double > &fluxes, const arma::vec3 &normal_vector, const double alpha1, const double alpha2, double &gamma, double *omega, double &transport_flux)
Calculates the dispersivity (diffusivity) tensor from the velocity field.
SideIter side(const unsigned int i) const
LinSys ** ls_dt
Linear algebra system for the time derivative (actually it is used only for handling the matrix struc...
#define JUMP(i, k, side_id)
void set_DG_parameters_boundary(const SideIter side, const int K_size, const std::vector< arma::mat33 > &K, const double flux, const arma::vec3 &normal_vector, const double alpha, double &gamma)
Sets up parameters of the DG method on a given boundary edge.
Definitions of Raviart-Thomas finite elements.
ElementAccessor< 3 > element_accessor()
void zero_time_step() override
Initialize solution in the zero time.
FEObjects(Mesh *mesh_, unsigned int fe_order)
void reinit(ElementAccessor< 3 > &cell)
Update cell-dependent data (gradients, Jacobians etc.)
unsigned int n_nodes() const
Transformed quadrature weights.
Calculates finite element data on a side.
const Node * node(unsigned int ni) const