45 using namespace Input::Type;
49 =
Selection(
"DG_variant",
"Type of penalty term.")
50 .
add_value(non_symmetric,
"non-symmetric",
"non-symmetric weighted interior penalty DG method")
51 .
add_value(incomplete,
"incomplete",
"incomplete weighted interior penalty DG method")
52 .
add_value(symmetric,
"symmetric",
"symmetric weighted interior penalty DG method");
57 .
add_value(inflow,
"inflow",
"Dirichlet BC on inflow and homogeneous Neumann BC on outflow.")
64 Model::ModelEqData::get_output_selection_input_type(
"DG",
"DG solver")
65 .copy_values(EqData().make_output_field_selection(
"").close())
70 = Model::get_input_type(
"DG",
"DG solver")
72 "Linear solver for MH problem.")
75 "Variant of interior penalty discontinuous Galerkin method.")
77 "Polynomial order for finite element in DG method (order 0 is suitable if there is no diffusion/dispersion).")
78 .declare_key(
"output_fields",
Array(EqData::output_selection),
79 Default(Model::ModelEqData::default_output_field()),
80 "List of fields to write to output file.");
120 xprintf(
PrgErr,
"Unsupported polynomial order %d for finite elements in TransportDG ", fe_order);
140 dh_->distribute_dofs(*fe1_, *fe2_, *fe3_);
186 template<
class Model>
190 .
name(
"fracture_sigma")
192 "Coefficient of diffusive transfer through fractures (for each substance).")
200 "Penalty parameter influencing the discontinuity of the solution (for each substance). "
201 "Its default value 1 is sufficient in most cases. Higher value diminishes the inter-element jumps.")
209 "Boundary condition type, possible values: inflow, dirichlet, neumann, robin.")
217 .
description(
"Flux in Neumann boundary condition.")
222 .
name(
"bc_robin_sigma")
223 .
description(
"Conductivity coefficient in Robin boundary condition.")
232 template<
class Model>
239 static_assert(std::is_base_of<AdvectionDiffusionModel, Model>::value,
"");
255 data_.set_mesh(init_mesh);
267 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
275 int qsize = max(
feo->
q<0>()->size(), max(
feo->
q<1>()->size(), max(
feo->
q<2>()->size(),
feo->
q<3>()->size())));
280 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
287 for (
int sd=0; sd<max_edg_sides; sd++)
291 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
302 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
312 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
330 for (
unsigned int sbi = 0; sbi <
n_subst_; sbi++) {
340 template<
class Model>
346 if (feo->dh()->el_ds()->myp() == 0)
348 for (
unsigned int i=0; i<
n_subst_; i++)
350 VecDestroy(&output_vec[i]);
351 delete[] output_solution[i];
355 for (
unsigned int i=0; i<
n_subst_; i++)
358 MatDestroy(&stiffness_matrix[i]);
362 delete[] stiffness_matrix;
369 delete output_stream;
373 template<
class Model>
377 VecScatter output_scatter;
379 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
382 ISCreateBlock(PETSC_COMM_SELF, ls[sbi]->size(), 1, idx, PETSC_COPY_VALUES, &is);
383 VecScatterCreate(ls[sbi]->get_solution(), is, output_vec[sbi], PETSC_NULL, &output_scatter);
384 VecScatterBegin(output_scatter, ls[sbi]->get_solution(), output_vec[sbi], INSERT_VALUES, SCATTER_FORWARD);
385 VecScatterEnd(output_scatter, ls[sbi]->get_solution(), output_vec[sbi], INSERT_VALUES, SCATTER_FORWARD);
386 VecScatterDestroy(&(output_scatter));
393 template<
class Model>
396 data_.set_time(*
time_);
399 set_initial_condition();
400 for (
unsigned int sbi = 0; sbi <
n_subst_; sbi++)
401 ( (
LinSys_PETSC *)ls[sbi] )->set_initial_guess_nonzero();
407 template<
class Model>
416 data_.set_time(*
time_);
420 if (!allocation_done)
423 ls_dt->start_allocation();
424 assemble_mass_matrix();
428 for (
unsigned int i=0; i<
n_subst_; i++)
430 ls[i]->start_allocation();
431 stiffness_matrix[i] = NULL;
434 assemble_stiffness_matrix();
436 set_boundary_conditions();
438 allocation_done =
true;
444 ls_dt->start_add_assembly();
445 ls_dt->mat_zero_entries();
446 assemble_mass_matrix();
447 ls_dt->finish_assembly();
448 mass_matrix = *(ls_dt->get_matrix());
452 if (stiffness_matrix[0] == NULL
454 || Model::flux_changed)
458 for (
unsigned int i=0; i<
n_subst_; i++)
460 ls[i]->start_add_assembly();
461 ls[i]->mat_zero_entries();
463 assemble_stiffness_matrix();
464 for (
unsigned int i=0; i<
n_subst_; i++)
466 ls[i]->finish_assembly();
468 if (stiffness_matrix[i] == NULL)
469 MatConvert(*( ls[i]->get_matrix() ), MATSAME, MAT_INITIAL_MATRIX, &stiffness_matrix[i]);
471 MatCopy(*( ls[i]->get_matrix() ), stiffness_matrix[i], DIFFERENT_NONZERO_PATTERN);
478 || Model::flux_changed)
480 for (
unsigned int i=0; i<
n_subst_; i++)
482 ls[i]->start_add_assembly();
483 ls[i]->rhs_zero_entries();
486 set_boundary_conditions();
487 for (
unsigned int i=0; i<
n_subst_; i++)
489 ls[i]->finish_assembly();
491 VecDuplicate(*( ls[i]->get_rhs() ), &rhs[i]);
492 VecCopy(*( ls[i]->get_rhs() ), rhs[i]);
496 Model::flux_changed =
false;
517 for (
unsigned int i=0; i<
n_subst_; i++)
519 MatConvert(stiffness_matrix[i], MATSAME, MAT_INITIAL_MATRIX, &m);
520 MatAXPY(m, 1./
time_->
dt(), mass_matrix, SUBSET_NONZERO_PATTERN);
521 ls[i]->set_matrix(m, DIFFERENT_NONZERO_PATTERN);
523 VecDuplicate(rhs[i], &y);
524 VecDuplicate(rhs[i], &w);
525 MatMult(mass_matrix, ls[i]->get_solution(), y);
526 VecWAXPY(w, 1./
time_->
dt(), y, rhs[i]);
544 template<
class Model>
551 Model::flux_changed =
true;
556 template<
class Model>
564 output_vector_gather();
566 data_.output(output_stream);
567 output_stream->write_time_frame();
576 template<
class Model>
580 assemble_mass_matrix<1>();
581 assemble_mass_matrix<2>();
582 assemble_mass_matrix<3>();
587 template<
class Model>
template<
unsigned int dim>
591 const unsigned int ndofs = feo->fe<dim>()->n_dofs(), qsize = feo->q<dim>()->size();
592 unsigned int dof_indices[ndofs];
593 PetscScalar local_mass_matrix[ndofs*ndofs];
596 for (
unsigned int i_cell=0; i_cell<feo->dh()->el_ds()->lsize(); i_cell++)
599 if (cell->dim() != dim)
continue;
601 fe_values.reinit(cell);
602 feo->dh()->get_dof_indices(cell, dof_indices);
605 Model::compute_mass_matrix_coefficient(fe_values.point_list(), ele_acc, mm_coef);
608 for (
unsigned int i=0; i<ndofs; i++)
610 for (
unsigned int j=0; j<ndofs; j++)
612 local_mass_matrix[i*ndofs+j] = 0;
613 for (
unsigned int k=0; k<qsize; k++)
614 local_mass_matrix[i*ndofs+j] += mm_coef[k]*fe_values.shape_value(j,k)*fe_values.shape_value(i,k)*fe_values.JxW(k);
618 ls_dt->mat_set_values(ndofs, (
int *)dof_indices, ndofs, (
int *)dof_indices, local_mass_matrix);
625 template<
class Model>
630 assemble_volume_integrals<1>();
631 assemble_volume_integrals<2>();
632 assemble_volume_integrals<3>();
636 assemble_fluxes_boundary<1>();
637 assemble_fluxes_boundary<2>();
638 assemble_fluxes_boundary<3>();
642 assemble_fluxes_element_element<1>();
643 assemble_fluxes_element_element<2>();
644 assemble_fluxes_element_element<3>();
648 assemble_fluxes_element_side<1>();
649 assemble_fluxes_element_side<2>();
650 assemble_fluxes_element_side<3>();
657 template<
class Model>
658 template<
unsigned int dim>
661 FEValues<dim,3> fv_rt(*feo->mapping<dim>(), *feo->q<dim>(), *feo->fe_rt<dim>(),
663 FEValues<dim,3> fe_values(*feo->mapping<dim>(), *feo->q<dim>(), *feo->fe<dim>(),
665 const unsigned int ndofs = feo->fe<dim>()->n_dofs(), qsize = feo->q<dim>()->size();
666 unsigned int dof_indices[ndofs];
669 PetscScalar local_matrix[ndofs*ndofs];
672 for (
unsigned int i_cell=0; i_cell<feo->dh()->el_ds()->lsize(); i_cell++)
675 if (cell->dim() != dim)
continue;
680 feo->dh()->get_dof_indices(cell, dof_indices);
682 calculate_velocity(cell, velocity, fv_rt);
683 Model::compute_advection_diffusion_coefficients(fe_values.
point_list(), velocity, ele_acc, ad_coef, dif_coef);
684 Model::compute_sources_sigma(fe_values.
point_list(), ele_acc, sources_sigma);
687 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
689 for (
unsigned int i=0; i<ndofs; i++)
690 for (
unsigned int j=0; j<ndofs; j++)
691 local_matrix[i*ndofs+j] = 0;
693 for (
unsigned int k=0; k<qsize; k++)
695 for (
unsigned int i=0; i<ndofs; i++)
698 double ad_dot_grad_i = arma::dot(ad_coef[sbi][k], fe_values.
shape_grad(i,k));
700 for (
unsigned int j=0; j<ndofs; j++)
701 local_matrix[i*ndofs+j] += (arma::dot(Kt_grad_i, fe_values.
shape_grad(j,k))
706 ls[sbi]->mat_set_values(ndofs, (
int *)dof_indices, ndofs, (
int *)dof_indices, local_matrix);
712 template<
class Model>
722 template<
class Model>
723 template<
unsigned int dim>
726 FEValues<dim,3> fe_values(*feo->mapping<dim>(), *feo->q<dim>(), *feo->fe<dim>(),
728 const unsigned int ndofs = feo->fe<dim>()->n_dofs(), qsize = feo->q<dim>()->size();
732 unsigned int dof_indices[ndofs];
733 PetscScalar local_rhs[ndofs];
737 for (
unsigned int i_cell=0; i_cell<feo->dh()->el_ds()->lsize(); i_cell++)
740 if (cell->dim() != dim)
continue;
742 fe_values.reinit(cell);
743 feo->dh()->get_dof_indices(cell, dof_indices);
745 Model::compute_source_coefficients(fe_values.point_list(), cell->element_accessor(), sources_conc, sources_density, sources_sigma);
748 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
750 for (
unsigned int i=0; i<ndofs; i++)
754 for (
unsigned int k=0; k<qsize; k++)
756 source = (sources_density[k][sbi] + sources_conc[k][sbi]*sources_sigma[k][sbi])*fe_values.JxW(k);
758 for (
unsigned int i=0; i<ndofs; i++)
759 local_rhs[i] += source*fe_values.shape_value(i,k);
761 ls[sbi]->rhs_set_values(ndofs, (
int *)dof_indices, local_rhs);
768 template<
class Model>
769 template<
unsigned int dim>
775 const unsigned int ndofs = feo->fe<dim>()->n_dofs(), qsize = feo->q<dim-1>()->size(),
776 n_max_sides = ad_coef_edg.size();
778 PetscScalar local_matrix[ndofs*ndofs];
781 double gamma_l, omega[2], transport_flux;
783 for (
unsigned int sid=0; sid<n_max_sides; sid++)
785 side_dof_indices.push_back(
new unsigned int[ndofs]);
786 fe_values.push_back(
new FESideValues<dim,3>(*feo->mapping<dim>(), *feo->q<dim-1>(), *feo->fe<dim>(),
791 for (
unsigned int iedg=0; iedg<feo->dh()->n_loc_edges(); iedg++)
796 for (
int sid=0; sid<edg->
n_sides; sid++)
800 feo->dh()->get_dof_indices(cell, side_dof_indices[sid]);
801 fe_values[sid]->reinit(cell, edg->
side(sid)->
el_idx());
803 calculate_velocity(cell, side_velocity[sid], fsv_rt);
804 Model::compute_advection_diffusion_coefficients(fe_values[sid]->point_list(), side_velocity[sid], ele_acc, ad_coef_edg[sid], dif_coef_edg[sid]);
805 dg_penalty[sid] = data_.dg_penalty.value(cell->centre(), ele_acc);
809 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
812 for (
int sid=0; sid<edg->
n_sides; sid++)
815 for (
unsigned int k=0; k<qsize; k++)
816 fluxes[sid] += arma::dot(ad_coef_edg[sid][sbi][k], fe_values[sid]->normal_vector(k))*fe_values[sid]->JxW(k);
820 for (
int s1=0; s1<edg->
n_sides; s1++)
822 for (
int s2=s1+1; s2<edg->
n_sides; s2++)
828 arma::vec3 nv = fe_values[s1]->normal_vector(0);
831 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);
837 #define AVERAGE(i,k,side_id) (fe_values[sd[side_id]]->shape_value(i,k)*0.5)
838 #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])
839 #define JUMP(i,k,side_id) ((side_id==0?1:-1)*fe_values[sd[side_id]]->shape_value(i,k))
842 for (
int n=0; n<2; n++)
846 for (
int m=0; m<2; m++)
848 for (
unsigned int i=0; i<fe_values[sd[n]]->n_dofs(); i++)
849 for (
unsigned int j=0; j<fe_values[sd[m]]->n_dofs(); j++)
850 local_matrix[i*fe_values[sd[m]]->n_dofs()+j] = 0;
852 for (
unsigned int k=0; k<qsize; k++)
854 double flux_times_JxW = transport_flux*fe_values[0]->JxW(k);
855 double gamma_times_JxW = gamma_l*fe_values[0]->JxW(k);
857 for (
unsigned int i=0; i<fe_values[sd[n]]->n_dofs(); i++)
859 double flux_JxW_jump_i = flux_times_JxW*
JUMP(i,k,n);
860 double gamma_JxW_jump_i = gamma_times_JxW*
JUMP(i,k,n);
861 double JxW_jump_i = fe_values[0]->JxW(k)*
JUMP(i,k,n);
862 double JxW_var_wavg_i = fe_values[0]->JxW(k)*
WAVERAGE(i,k,n)*dg_variant;
864 for (
unsigned int j=0; j<fe_values[sd[m]]->n_dofs(); j++)
866 int index = i*fe_values[sd[m]]->n_dofs()+j;
869 local_matrix[index] += flux_JxW_jump_i*
AVERAGE(j,k,m);
872 local_matrix[index] += gamma_JxW_jump_i*
JUMP(j,k,m);
875 local_matrix[index] -=
WAVERAGE(j,k,m)*JxW_jump_i;
876 local_matrix[index] -=
JUMP(j,k,m)*JxW_var_wavg_i;
880 ls[sbi]->mat_set_values(fe_values[sd[n]]->n_dofs(), (
int *)side_dof_indices[sd[n]], fe_values[sd[m]]->n_dofs(), (
int *)side_dof_indices[sd[m]], local_matrix);
891 for (
unsigned int i=0; i<n_max_sides; i++)
894 delete[] side_dof_indices[i];
899 template<
class Model>
900 template<
unsigned int dim>
903 FESideValues<dim,3> fe_values_side(*feo->mapping<dim>(), *feo->q<dim-1>(), *feo->fe<dim>(),
907 const unsigned int ndofs = feo->fe<dim>()->n_dofs(), qsize = feo->q<dim-1>()->size();
908 unsigned int side_dof_indices[ndofs];
909 PetscScalar local_matrix[ndofs*ndofs];
912 arma::vec dg_penalty;
916 for (
unsigned int iedg=0; iedg<feo->dh()->n_loc_edges(); iedg++)
919 if (edg->
n_sides > 1)
continue;
921 if (edg->
side(0)->
dim() != dim-1)
continue;
923 if (edg->
side(0)->
cond() == NULL)
continue;
928 feo->dh()->get_dof_indices(cell, side_dof_indices);
932 calculate_velocity(cell, side_velocity, fsv_rt);
933 Model::compute_advection_diffusion_coefficients(fe_values_side.
point_list(), side_velocity, ele_acc, ad_coef, dif_coef);
934 dg_penalty = data_.dg_penalty.value(cell->centre(), ele_acc);
938 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
940 for (
unsigned int i=0; i<ndofs; i++)
941 for (
unsigned int j=0; j<ndofs; j++)
942 local_matrix[i*ndofs+j] = 0;
946 double side_flux = 0;
947 for (
unsigned int k=0; k<qsize; k++)
948 side_flux += arma::dot(ad_coef[sbi][k], fe_values_side.
normal_vector(k))*fe_values_side.
JxW(k);
949 double transport_flux = side_flux/side->
measure();
951 if ((bc_type[sbi] == EqData::dirichlet) || (bc_type[sbi] == EqData::inflow ))
954 set_DG_parameters_boundary(side, qsize, dif_coef[sbi], transport_flux, fe_values_side.
normal_vector(0), dg_penalty[sbi], gamma_l);
955 gamma[sbi][side->
cond_idx()] = gamma_l;
956 if (bc_type[sbi] == EqData::dirichlet || side_flux < -mh_dh->precision())
957 transport_flux += gamma_l;
961 for (
unsigned int k=0; k<qsize; k++)
963 double flux_times_JxW;
964 if (bc_type[sbi] == EqData::robin)
965 flux_times_JxW = (transport_flux + robin_sigma[k][sbi])*fe_values_side.
JxW(k);
967 flux_times_JxW = transport_flux*fe_values_side.
JxW(k);
969 for (
unsigned int i=0; i<ndofs; i++)
970 for (
unsigned int j=0; j<ndofs; j++)
973 local_matrix[i*ndofs+j] += flux_times_JxW*fe_values_side.
shape_value(i,k)*fe_values_side.
shape_value(j,k);
976 if (bc_type[sbi] == EqData::dirichlet || (bc_type[sbi] == EqData::inflow && side_flux < -mh_dh->precision()))
979 )*fe_values_side.
JxW(k);
982 ls[sbi]->mat_set_values(ndofs, (
int *)side_dof_indices, ndofs, (
int *)side_dof_indices, local_matrix);
988 template<
class Model>
989 template<
unsigned int dim>
993 if (dim == 1)
return;
994 FEValues<dim-1,3> fe_values_vb(*feo->mapping<dim-1>(), *feo->q<dim-1>(), *feo->
fe<dim-1>(),
1000 FEValues<dim-1,3> fv_rt(*feo->mapping<dim-1>(), *feo->q<dim-1>(), *feo->fe_rt<dim-1>(),
1004 const unsigned int ndofs = feo->fe<dim>()->n_dofs();
1005 const unsigned int qsize = feo->q<dim-1>()->size();
1006 unsigned int side_dof_indices[2*ndofs], n_dofs[2];
1009 vector<double> csection_lower(qsize), csection_higher(qsize), mm_coef_lower(qsize), mm_coef_higher(qsize);
1010 PetscScalar local_matrix[4*ndofs*ndofs];
1011 double comm_flux[2][2];
1015 fv_sb[0] = &fe_values_vb;
1016 fv_sb[1] = &fe_values_side;
1019 for (
unsigned int inb=0; inb<feo->dh()->n_loc_nb(); inb++)
1026 feo->dh()->get_dof_indices(cell_sub, side_dof_indices);
1027 fe_values_vb.
reinit(cell_sub);
1028 n_dofs[0] = fv_sb[0]->n_dofs();
1031 feo->dh()->get_dof_indices(cell, side_dof_indices+n_dofs[0]);
1033 n_dofs[1] = fv_sb[1]->n_dofs();
1037 element_id[0] = cell_sub.
index();
1038 element_id[1] = cell.
index();
1042 calculate_velocity(cell, velocity_higher, fsv_rt);
1043 calculate_velocity(cell_sub, velocity_lower, fv_rt);
1044 Model::compute_advection_diffusion_coefficients(fe_values_vb.
point_list(), velocity_lower, cell_sub->element_accessor(), ad_coef_edg[0], dif_coef_edg[0]);
1045 Model::compute_advection_diffusion_coefficients(fe_values_vb.
point_list(), velocity_higher, cell->element_accessor(), ad_coef_edg[1], dif_coef_edg[1]);
1046 Model::compute_mass_matrix_coefficient(fe_values_vb.
point_list(), cell_sub->element_accessor(), mm_coef_lower);
1047 Model::compute_mass_matrix_coefficient(fe_values_vb.
point_list(), cell->element_accessor(), mm_coef_higher);
1048 data_.cross_section.value_list(fe_values_vb.
point_list(), cell_sub->element_accessor(), csection_lower);
1049 data_.cross_section.value_list(fe_values_vb.
point_list(), cell->element_accessor(), csection_higher);
1050 data_.fracture_sigma.value_list(fe_values_vb.
point_list(), cell_sub->element_accessor(), frac_sigma);
1052 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
1054 for (
unsigned int i=0; i<n_dofs[0]+n_dofs[1]; i++)
1055 for (
unsigned int j=0; j<n_dofs[0]+n_dofs[1]; j++)
1056 local_matrix[i*(n_dofs[0]+n_dofs[1])+j] = 0;
1059 for (
unsigned int k=0; k<qsize; k++)
1069 double sigma = frac_sigma[k][sbi]*arma::dot(dif_coef_edg[0][sbi][k]*fe_values_side.
normal_vector(k),fe_values_side.
normal_vector(k))*
1070 2*csection_higher[k]*csection_higher[k]/(csection_lower[k]*csection_lower[k]);
1073 double transport_flux = arma::dot(ad_coef_edg[1][sbi][k], fe_values_side.
normal_vector(k));
1074 double por_lower_over_higher = mm_coef_lower[k]*csection_higher[k]/(mm_coef_higher[k]*csection_lower[k]);
1076 comm_flux[0][0] = (sigma-min(0.,transport_flux*por_lower_over_higher))*fv_sb[0]->JxW(k);
1077 comm_flux[0][1] = -(sigma-min(0.,transport_flux*por_lower_over_higher))*fv_sb[0]->JxW(k);
1078 comm_flux[1][0] = -(sigma+max(0.,transport_flux))*fv_sb[0]->JxW(k);
1079 comm_flux[1][1] = (sigma+max(0.,transport_flux))*fv_sb[0]->JxW(k);
1081 for (
int n=0; n<2; n++)
1083 if (!feo->dh()->el_is_local(element_id[n]))
continue;
1085 for (
unsigned int i=0; i<n_dofs[n]; i++)
1086 for (
int m=0; m<2; m++)
1087 for (
unsigned int j=0; j<n_dofs[m]; j++)
1088 local_matrix[(i+n*n_dofs[0])*(n_dofs[0]+n_dofs[1]) + m*n_dofs[0] + j] +=
1089 comm_flux[m][n]*fv_sb[m]->shape_value(j,k)*fv_sb[n]->shape_value(i,k);
1092 ls[sbi]->mat_set_values(n_dofs[0]+n_dofs[1], (
int *)side_dof_indices, n_dofs[0]+n_dofs[1], (
int *)side_dof_indices, local_matrix);
1103 template<
class Model>
1107 set_boundary_conditions<1>();
1108 set_boundary_conditions<2>();
1109 set_boundary_conditions<3>();
1114 template<
class Model>
1115 template<
unsigned int dim>
1118 FESideValues<dim,3> fe_values_side(*feo->mapping<dim>(), *feo->q<dim-1>(), *feo->fe<dim>(),
1122 const unsigned int ndofs = feo->fe<dim>()->n_dofs(), qsize = feo->q<dim-1>()->size();
1123 unsigned int side_dof_indices[ndofs];
1124 double local_rhs[ndofs];
1129 for (
unsigned int iedg=0; iedg<feo->dh()->n_loc_edges(); iedg++)
1132 if (edg->
n_sides > 1)
continue;
1133 if (edg->
side(0)->
dim() != dim-1)
continue;
1135 if (edg->
side(0)->
cond() == NULL)
continue;
1141 arma::uvec bc_type = data_.bc_type.value(side->
cond()->
element()->
centre(), ele_acc);
1143 fe_values_side.reinit(cell, side->
el_idx());
1144 fsv_rt.reinit(cell, side->
el_idx());
1145 calculate_velocity(cell, velocity, fsv_rt);
1147 Model::compute_advection_diffusion_coefficients(fe_values_side.point_list(), velocity, side->
element()->element_accessor(), ad_coef, dif_coef);
1148 Model::compute_dirichlet_bc(fe_values_side.point_list(), ele_acc, bc_values);
1149 data_.bc_flux.value_list(fe_values_side.point_list(), ele_acc, bc_fluxes);
1150 data_.bc_robin_sigma.value_list(fe_values_side.point_list(), ele_acc, bc_sigma);
1152 feo->dh()->get_dof_indices(cell, side_dof_indices);
1154 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
1156 for (
unsigned int i=0; i<ndofs; i++) local_rhs[i] = 0;
1158 for (
unsigned int k=0; k<qsize; k++)
1164 || (bc_type[sbi] == EqData::dirichlet))
1166 bc_term = gamma[sbi][side->
cond_idx()]*bc_values[k][sbi]*fe_values_side.JxW(k);
1167 bc_grad = -bc_values[k][sbi]*fe_values_side.JxW(k)*dg_variant*(arma::trans(dif_coef[sbi][k])*fe_values_side.normal_vector(k));
1169 else if (bc_type[sbi] == EqData::neumann)
1171 bc_term = bc_fluxes[k][sbi]*fe_values_side.JxW(k);
1173 else if (bc_type[sbi] == EqData::robin)
1175 bc_term = bc_sigma[k][sbi]*bc_values[k][sbi]*fe_values_side.JxW(k);
1178 for (
unsigned int i=0; i<ndofs; i++)
1179 local_rhs[i] += bc_term*fe_values_side.shape_value(i,k)
1180 + arma::dot(bc_grad,fe_values_side.shape_grad(i,k));
1182 ls[sbi]->rhs_set_values(ndofs, (
int *)side_dof_indices, local_rhs);
1194 template<
class Model>
1195 template<
unsigned int dim>
1199 for (
unsigned int i=0; i<cell->n_nodes(); i++)
1200 node_nums[cell->node[i]] = i;
1204 for (
unsigned int k=0; k<fv.
n_points(); k++)
1206 velocity[k].zeros();
1207 for (
unsigned int sid=0; sid<cell->n_sides(); sid++)
1209 if (cell->side(sid)->dim() != dim-1)
continue;
1210 int num = dim*(dim+1)/2;
1211 for (
unsigned int i=0; i<cell->side(sid)->n_nodes(); i++)
1212 num -= node_nums[cell->side(sid)->node(i)];
1222 template<
class Model>
1231 const double alpha1,
1232 const double alpha2,
1235 double &transport_flux)
1239 double local_alpha = 0;
1251 for (
unsigned int i=0; i<s->n_nodes(); i++)
1252 for (
unsigned int j=i+1; j<s->n_nodes(); j++)
1253 h = max(h, s->node(i)->distance(*s->node(j)));
1257 double pflux = 0, nflux = 0;
1258 for (
int i=0; i<edg.
n_sides; i++)
1267 if (fluxes[s2] > 0 && fluxes[s1] < 0 && s1 < s2)
1268 transport_flux = fluxes[s1]*fabs(fluxes[s2]/pflux);
1269 else if (fluxes[s2] < 0 && fluxes[s1] > 0 && s1 < s2)
1270 transport_flux = fluxes[s1]*fabs(fluxes[s2]/nflux);
1272 transport_flux = fluxes[s1];
1276 gamma = 0.5*fabs(transport_flux);
1280 local_alpha = max(alpha1, alpha2);
1288 for (
int k=0; k<K_size; k++)
1289 delta[0] += dot(K1[k]*normal_vector,normal_vector);
1292 gamma += local_alpha/h*(delta[0]);
1298 for (
int k=0; k<K_size; k++)
1300 delta[0] += dot(K1[k]*normal_vector,normal_vector);
1301 delta[1] += dot(K2[k]*normal_vector,normal_vector);
1306 double delta_sum = delta[0] + delta[1];
1310 omega[0] = delta[1]/delta_sum;
1311 omega[1] = delta[0]/delta_sum;
1312 gamma += local_alpha/h*(delta[0]*delta[1]/delta_sum);
1315 for (
int i=0; i<2; i++) omega[i] = 0;
1324 template<
class Model>
1333 double delta = 0, h = 0;
1336 if (side->
dim() == 0)
1342 for (
unsigned int i=0; i<side->
n_nodes(); i++)
1343 for (
unsigned int j=i+1; j<side->
n_nodes(); j++)
1348 for (
int k=0; k<K_size; k++)
1349 delta += dot(K[k]*normal_vector,normal_vector);
1352 gamma = 0.5*fabs(flux) + alpha/h*delta;
1359 template<
class Model>
1363 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
1364 ls[sbi]->start_allocation();
1365 prepare_initial_condition<1>();
1366 prepare_initial_condition<2>();
1367 prepare_initial_condition<3>();
1369 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
1370 ls[sbi]->start_add_assembly();
1371 prepare_initial_condition<1>();
1372 prepare_initial_condition<2>();
1373 prepare_initial_condition<3>();
1375 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
1377 ls[sbi]->finish_assembly();
1383 template<
class Model>
1384 template<
unsigned int dim>
1387 FEValues<dim,3> fe_values(*feo->mapping<dim>(), *feo->q<dim>(), *feo->fe<dim>(),
1389 const unsigned int ndofs = feo->fe<dim>()->n_dofs(), qsize = feo->q<dim>()->size();
1390 unsigned int dof_indices[ndofs];
1391 double matrix[ndofs*ndofs], rhs[ndofs];
1394 for (
unsigned int k=0; k<qsize; k++)
1395 init_values[k].resize(n_subst_);
1397 for (
unsigned int i_cell=0; i_cell<feo->dh()->el_ds()->lsize(); i_cell++)
1400 if (elem->dim() != dim)
continue;
1403 feo->dh()->get_dof_indices(elem, dof_indices);
1406 Model::compute_init_cond(fe_values.
point_list(), ele_acc, init_values);
1408 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
1410 for (
unsigned int i=0; i<ndofs; i++)
1413 for (
unsigned int j=0; j<ndofs; j++)
1414 matrix[i*ndofs+j] = 0;
1417 for (
unsigned int k=0; k<qsize; k++)
1419 double rhs_term = init_values[k](sbi)*fe_values.
JxW(k);
1421 for (
unsigned int i=0; i<ndofs; i++)
1423 for (
unsigned int j=0; j<ndofs; j++)
1429 ls[sbi]->set_values(ndofs, (
int *)dof_indices, ndofs, (
int *)dof_indices, matrix, rhs);
1435 template<
class Model>
1438 calc_fluxes<1>(bcd_balance, bcd_plus_balance, bcd_minus_balance);
1439 calc_fluxes<2>(bcd_balance, bcd_plus_balance, bcd_minus_balance);
1440 calc_fluxes<3>(bcd_balance, bcd_plus_balance, bcd_minus_balance);
1443 template<
class Model>
1444 template<
unsigned int dim>
1451 const unsigned int ndofs = feo->fe<dim>()->n_dofs(), qsize = feo->q<dim-1>()->size();
1452 unsigned int dof_indices[ndofs];
1457 for (
unsigned int k=0; k<qsize; k++)
1458 bc_values[k].resize(n_subst_);
1460 for (
unsigned int iedg=0; iedg<feo->dh()->n_loc_edges(); iedg++)
1463 if (edg->
n_sides > 1)
continue;
1464 if (edg->
side(0)->
dim() != dim-1)
continue;
1466 if (edg->
side(0)->
cond() == NULL)
continue;
1475 fe_values.reinit(cell, side->
el_idx());
1476 fsv_rt.reinit(cell, side->
el_idx());
1477 feo->dh()->get_dof_indices(cell, dof_indices);
1478 calculate_velocity(cell, side_velocity, fsv_rt);
1479 Model::compute_advection_diffusion_coefficients(fe_values.point_list(), side_velocity, ele_acc, ad_coef, dif_coef);
1480 Model::compute_dirichlet_bc(fe_values.point_list(), side->
cond()->
element_accessor(), bc_values);
1483 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
1485 double mass_flux = 0;
1486 double water_flux = 0;
1487 for (
unsigned int k=0; k<qsize; k++)
1488 water_flux += arma::dot(ad_coef[sbi][k], fe_values.normal_vector(k))*fe_values.JxW(k);
1489 water_flux /= side->
measure();
1491 for (
unsigned int k=0; k<qsize; k++)
1495 for (
unsigned int i=0; i<ndofs; i++)
1497 conc += fe_values.shape_value(i,k)*ls[sbi]->get_solution_array()[dof_indices[i]-feo->dh()->loffset()];
1498 conc_grad += fe_values.shape_grad(i,k)*ls[sbi]->get_solution_array()[dof_indices[i]-feo->dh()->loffset()];
1502 mass_flux += water_flux*conc*fe_values.JxW(k);
1504 if (bc_type[sbi] == EqData::dirichlet || (bc_type[sbi] == EqData::inflow && water_flux*side->
measure() < -
mh_dh->
precision()))
1507 mass_flux -= arma::dot(dif_coef[sbi][k]*conc_grad,fe_values.normal_vector(k))*fe_values.JxW(k);
1510 mass_flux -= gamma[sbi][side->
cond_idx()]*(bc_values[k][sbi] - conc)*fe_values.JxW(k);
1514 bcd_balance[sbi][bc_region_idx] += mass_flux;
1515 if (mass_flux >= 0) bcd_plus_balance[sbi][bc_region_idx] += mass_flux;
1516 else bcd_minus_balance[sbi][bc_region_idx] += mass_flux;
1522 template<
class Model>
1525 calc_elem_sources<1>(mass, src_balance);
1526 calc_elem_sources<2>(mass, src_balance);
1527 calc_elem_sources<3>(mass, src_balance);
1530 template<
class Model>
1531 template<
unsigned int dim>
1534 FEValues<dim,3> fe_values(*feo->mapping<dim>(), *feo->q<dim>(), *feo->fe<dim>(),
1536 const unsigned int ndofs = feo->fe<dim>()->n_dofs(), qsize = feo->q<dim>()->size();
1537 unsigned int dof_indices[ndofs];
1541 double mass_sum, sources_sum, conc, conc_diff;
1543 for (
unsigned int i_cell=0; i_cell<feo->dh()->el_ds()->lsize(); i_cell++)
1546 if (elem->dim() != dim)
continue;
1548 Region r = elem->element_accessor().region();
1550 unsigned int region_idx = r.
bulk_idx();
1553 fe_values.reinit(elem);
1554 feo->dh()->get_dof_indices(elem, dof_indices);
1556 Model::compute_mass_matrix_coefficient(fe_values.point_list(), ele_acc, mm_coef);
1557 Model::compute_source_coefficients(fe_values.point_list(), ele_acc, sources_conc, sources_density, sources_sigma);
1559 for (
unsigned int sbi=0; sbi<
n_subst_; sbi++)
1564 for (
unsigned int k=0; k<qsize; k++)
1567 for (
unsigned int i=0; i<ndofs; i++)
1568 conc += fe_values.shape_value(i,k)*ls[sbi]->get_solution_array()[dof_indices[i]-feo->dh()->loffset()];
1570 mass_sum += mm_coef[k]*conc*fe_values.JxW(k);
1572 conc_diff = sources_conc[k][sbi] - conc;
1573 sources_sum += (sources_density[k][sbi] + conc_diff*sources_sigma[k][sbi])*fe_values.JxW(k);
1576 mass[sbi][region_idx] += mass_sum;
1577 src_balance[sbi][region_idx] += sources_sum;
static Input::Type::Selection output_selection
void calculate(double time)
Class MappingP1 implements the affine transformation of the unit cell onto the actual cell...
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.
void set_boundary_conditions()
Assembles the r.h.s. components corresponding to the Dirichlet boundary conditions.
Transformed quadrature weight for cell sides.
vector< double > mm_coef
Mass matrix coefficients.
Header: The functions for all outputs.
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.
Solver based on the original PETSc solver using MPIAIJ matrix and succesive Schur complement construc...
Input::Record output_rec
Record with output specification.
static constexpr Mask allow_output
The field can output. Is part of generated output selection. (default on)
Transport with dispersion implemented using discontinuous Galerkin method.
FieldCommon & flags_add(FieldFlag::Flags::Mask mask)
double distance(const Node &n2) const
void assemble_mass_matrix()
Assembles the mass matrix.
double fix_dt_until_mark()
Fixing time step until fixed time mark.
OutputTime * output_stream
void next_time()
Proceed to the next time according to current estimated time step.
void update_solution() override
Computes the solution in one time instant.
const double JxW(const unsigned int point_no)
Return the product of Jacobian determinant and the quadrature weight at given quadrature point...
const arma::vec::fixed< spacedim > normal_vector(unsigned int point_no)
Returns the normal vector to a side at given quadrature point.
TimeMark::Type type_output()
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...
RegionSet get_region_set(const string &set_name) const
const MH_DofHandler * mh_dh
MassBalance * mass_balance_
object for calculation and writing the mass balance to file.
void set_initial_condition()
Sets the initial condition.
Class FEValues calculates finite element data on the actual cells such as shape function values...
bool is_current(const TimeMark::Type &mask) const
vector< vector< arma::vec3 > > ad_coef
Advection coefficients.
static Input::Type::Record input_type
const RegionDB & region_db() const
void set_from_input(const Input::Record in_rec)
#define AVERAGE(i, k, side_id)
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.
vector< Boundary > boundary_
Basic time management functionality for unsteady (and steady) solvers (class Equation).
FieldCommon & units(const UnitSI &units)
Set basic units of the field.
const 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...
static TimeMarks & marks()
MassBalance * mass_balance()
Specification of transport model interface.
void view(const char *name="") const
void assemble_fluxes_boundary()
Assembles the fluxes on the boundary.
Symmetric Gauss-Legendre quadrature formulae on simplices.
#define WAVERAGE(i, k, side_id)
const unsigned int n_points()
Returns the number of quadrature points.
unsigned int boundary_idx() const
Returns index of the region in the boundary set.
TransportDG(Mesh &init_mesh, const Input::Record &in_rec)
Constructor.
vector< double * > output_solution
Array for storing the output solution data.
vector< vector< vector< arma::vec3 > > > ad_coef_edg
Advection coefficients on edges.
Discontinuous Lagrangean finite element on dim dimensional simplex.
Transformed quadrature points.
void output_data()
Postprocesses the solution and writes to output file.
static OutputTime * create_output_stream(const Input::Record &in_rec)
This method write all registered data to output streams.
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)
Raviart-Thomas element of order 0.
Definitions of basic Lagrangean finite elements with polynomial shape functions.
FieldCommon & input_selection(const Input::Type::Selection *element_selection)
Mat mass_matrix
The mass matrix.
#define START_TIMER(tag)
Starts a timer with specified tag.
FiniteElement< dim, spacedim > * fe
The used finite element.
Provides the numbering of the finite element degrees of freedom on the computational mesh...
Mat * stiffness_matrix
The stiffness matrix.
void output(double time)
Write computed fields to file.
Field< 3, FieldValue< 3 >::Vector > fracture_sigma
Transition parameter for diffusive transfer on fractures (for each substance).
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.
unsigned int n_subst_
Number of transported substances.
Affine mapping between reference and actual cell.
Shape function gradients.
void mark_output_times(const TimeGovernor &tg)
Vec * rhs
Vector of right hand side.
void set_solution(double *sol_array)
BCField< 3, FieldValue< 3 >::Vector > bc_flux
Flux in Neumann or Robin b.c.
static Input::Type::Selection bc_type_selection
DOFHandlerMultiDim * dh()
LinSys * ls_dt
Linear algebra system for the time derivative (actually it is used only for handling the matrix struc...
Discontinuous Galerkin method for equation of transport with dispersion.
const vector< arma::vec::fixed< spacedim > > & point_list()
Return coordinates of all quadrature points in the actual cell system.
std::vector< string > subst_names_
Names of transported substances.
void output_data() override
Write computed fields.
vector< Neighbour > vb_neighbours_
double side_flux(const Side &side) const
temporary replacement for DofHandler accessor, flux through given side
const arma::vec::fixed< spacedim > shape_vector(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...
FieldCommon & description(const string &description)
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.
unsigned int max_edge_sides(unsigned int dim) const
Discontinuous Galerkin method for equation of transport with dispersion.
ElementFullIter element() const
void calc_fluxes(vector< vector< double > > &bcd_balance, vector< vector< double > > &bcd_plus_balance, vector< vector< double > > &bcd_minus_balance)
Calculates flux through boundary of each region.
void add_admissible_field_names(const Input::Array &in_array, const Input::Type::Selection &in_sel)
Registers names of output fields that can be written using this stream.
arma::vec3 centre() const
void reinit(ElementFullIter &cell, unsigned int sid)
Update cell-dependent data (gradients, Jacobians etc.)
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...
BCField< 3, FieldValue< 3 >::EnumVector > bc_type
Type of boundary condition (see also BC_Type)
void reinit(ElementFullIter &cell)
Update cell-dependent data (gradients, Jacobians etc.)
std::vector< Edge > edges
Vector of MH edges, this should not be part of the geometrical mesh.
FullIter full_iter(Iter it)
unsigned int bulk_idx() const
Returns index of the region in the bulk set.
Abstract linear system class.
Definitions of particular quadrature rules on simplices.
FieldCommon & name(const string &name)
void calc_elem_sources(vector< vector< double > > &mass, vector< vector< double > > &src_balance)
Calculates volume sources for each region.
vector< Vec > output_vec
Vector of solution data.
Calculates finite element data on the actual cell.
#define END_TIMER(tag)
Ends a timer with specified tag.
Discontinuous Galerkin method for equation of transport with dispersion.
virtual void set_velocity_field(const MH_DofHandler &dh)
Updates the velocity field which determines some coefficients of the transport equation.
mixed-hybrid model of linear Darcy flow, possibly unsteady.
unsigned int el_idx() const
unsigned int n_substances() override
Returns number of trnasported substances.
void assemble_volume_integrals()
Assembles the volume integrals into the stiffness matrix.
bool is_valid() const
Returns false if the region has undefined/invalid value.
Abstract class for the description of a general finite element on a reference simplex in dim dimensio...
Base class for FEValues and FESideValues.
Class for representation SI units of Fields.
const Node * node(unsigned int i) const
void calculate_velocity(const ElementFullIter &cell, std::vector< arma::vec3 > &velocity, FEValuesBase< dim, 3 > &fv)
Calculates the velocity field on a given dim dimensional cell.
Distribution * distr() const
Mapping< dim, 3 > * mapping()
static UnitSI & dimensionless()
Returns dimensionless unit.
~TransportDG()
Destructor.
LinSys ** ls
Linear algebra system for the transport equation.
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)
Sets up some parameters of the DG method for two sides of an edge.
SideIter side(const unsigned int i) const
Field< 3, FieldValue< 3 >::Vector > dg_penalty
Penalty enforcing inter-element continuity of solution (for each substance).
#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.
const unsigned int n_global_dofs() const
Getter for the number of all mesh dofs required by the given finite element.
BCField< 3, FieldValue< 3 >::Vector > bc_robin_sigma
Transition coefficient in Robin b.c.
ElementAccessor< 3 > element_accessor()
void zero_time_step() override
Initialize solution in the zero time.
FEObjects(Mesh *mesh_, unsigned int fe_order)
ElementVector element
Vector of elements of the mesh.
unsigned int n_nodes() const
Transformed quadrature weights.
Calculates finite element data on a side.