Yes, I need the neighbour information of each cell to compute the boundary integration in the DG formulation. Therefore, I get the neighbouring cell in the loop of the active cell by using "const auto neighbor = cell->neighbor(face_n)"; (similar to step 30).
I am quite sure that the problem is what you are describing, thus it occurs only when I use the adaptative refinement.
{
const unsigned int dofs_per_cell = dof_handler.get_fe().dofs_per_cell;
std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
std::vector<types::global_dof_index> neighbor_dof_indices(dofs_per_cell);
const UpdateFlags update_flags = update_values | update_gradients |
update_quadrature_points |
update_JxW_values;
const UpdateFlags face_update_flags = update_values | update_quadrature_points | update_JxW_values |
update_normal_vectors;
const UpdateFlags neighbor_face_update_flags = update_values;
FEValues<dim> fe_values(mapping, fe, quadrature, update_flags);
FEFaceValues<dim> fe_face_values(mapping, fe, face_quadrature, face_update_flags);
FESubfaceValues<dim> fe_subface_values(mapping, fe, face_quadrature, face_update_flags);
FEFaceValues<dim> fe_face_neighbor(mapping, fe, face_quadrature,neighbor_face_update_flags);
FullMatrix<double> ui_vi_matrix(dofs_per_cell, dofs_per_cell); //matrix dominio
FullMatrix<double> ue_vi_matrix(dofs_per_cell, dofs_per_cell);
FullMatrix<double> ui_ve_matrix(dofs_per_cell, dofs_per_cell);
FullMatrix<double> ue_ve_matrix(dofs_per_cell, dofs_per_cell);
Vector<double> cell_vector(dofs_per_cell);
const FEValuesExtractors::Scalar verror(0);
const FEValuesExtractors::Scalar variable(1);
for (const auto &cell : dof_handler.active_cell_iterators())
{
fe_values.reinit(cell); ui_vi_matrix = 0; cell_vector = 0;
//--------------------------------------DOMAIN INTEGRATOR--------------------------------------------------------------------------
adv.assemble_cell_term(fe_values, ui_vi_matrix, cell_vector, verror, variable,cell, typecase);
cell->get_dof_indices(local_dof_indices);
for (unsigned int face_n = 0; face_n < GeometryInfo<dim>::faces_per_cell; ++face_n)
{
//-------------------------------------FACE AT THE EXTERNAL BOUNDARY-----------------------------------------------------------------------------
const auto face = cell->face(face_n);
if (face->at_boundary())
{
fe_face_values.reinit(cell, face_n);
adv.assemble_boundary_term(fe_face_values, ui_vi_matrix, cell_vector, verror, variable);
}
//-------------------------------------FACE AT THE INTERNAL BOUNDARY-----------------------------------------------------------------------------
else
{
const auto neighbor = cell->neighbor(face_n);
if ((dim > 1) && (cell->index() < neighbor->index()))
{
const unsigned int neighbor2 =cell->neighbor_face_no(face_n);
ue_vi_matrix = 0; ui_ve_matrix = 0; ue_ve_matrix = 0;
fe_face_values.reinit(cell, face_n);
fe_face_neighbor.reinit(neighbor, neighbor2);
adv.assemble_face_term(fe_face_values, fe_face_neighbor, ui_vi_matrix, ue_vi_matrix, ui_ve_matrix, ue_ve_matrix, verror, variable, typecase);
neighbor->get_dof_indices(neighbor_dof_indices);
// ---------------LOCAL ASSEMBLE ----------------------------------------------------------
for (unsigned int i = 0; i < dofs_per_cell; ++i)
for (unsigned int j = 0; j < dofs_per_cell; ++j)
{
system_matrix.add(local_dof_indices[i], neighbor_dof_indices[j], ue_vi_matrix(i, j));
system_matrix.add(neighbor_dof_indices[i], local_dof_indices[j], ui_ve_matrix(i, j));
system_matrix.add(neighbor_dof_indices[i], neighbor_dof_indices[j], ue_ve_matrix(i, j));
}
}
}
}
// ----------------------------------GLOBAL ASSEMBLE ----------------------------------------------------------
for (unsigned int i = 0; i < dofs_per_cell; ++i)
{for (unsigned int j = 0; j < dofs_per_cell; ++j)
{system_matrix.add(local_dof_indices[i],
local_dof_indices[j],
ui_vi_matrix(i, j));}
system_rhs(local_dof_indices[i]) += cell_vector(i);}
}
}