Dear community,
I am currently trying to implement h-adaptive mesh refinement into step-67 (by adding a refine_grid() functionality). As references I looked into
step-31,
step-33,
the previous question for step-59 and the distributed::SolutionTransfer documentation.
I tried to adapt the approach in the
SolutionTransfer documentation so that it matches what I see in the references.
Unfortunately, I get the following error:
-----------------
The violated condition was:
(data_range.size() % bytes_per_entry == 0)
Additional information:
This exception -- which is used in many places in the library -- usually indicates that some condition which the author of the code thought must be satisfied at a certain point in an algorithm, is not fulfilled. An example would be that the first part of an algorithm sorts elements of an array in ascending order, and a second part of the algorithm later encounters an element that is not larger than the previous one.
There is usually not very much you can do if you encounter such an exception since it indicates an error in deal.II, not in your own program. Try to come up with the smallest possible program that still demonstrates the error and contact the deal.II mailing lists with it to obtain help.
-----------------
The previous question basically achieved what I am trying to implement but the additional functionality that comes with step-59's setup_system() call takes care of all the interpolation etc.
I have the feeling that I misunderstood something in the documentation (for example replacing the interpolated_solution part. Would someone be able to tell me if I made a mistake with adapting the documentation to what I have.
Is there also some mistake on my part since I need another structure for LinearAlgebra::distributed::Vector (instead of the TrilinosWrappers vectors from the documentation)?
Any help would be much appreciated.
Best regards,
M. Bänsch
This is the code snippet:
template <int dim>
void EulerProblem<dim>::refine_grid()
{
...
some refinement criteria
...
// see distributed::SolutionTransfer documentation for details
parallel::distributed::SolutionTransfer<dim, LinearAlgebra::distributed::Vector<Number>> soltrans(dof_handler);
triangulation.prepare_coarsening_and_refinement();
soltrans.prepare_for_coarsening_and_refinement(solution);
triangulation.execute_coarsening_and_refinement();
dof_handler.distribute_dofs(fe);
IndexSet locally_owned_dofs, locally_relevant_dofs;
locally_owned_dofs = dof_handler.locally_owned_dofs();
DoFTools::extract_locally_relevant_dofs(dof_handler, locally_relevant_dofs);
LinearAlgebra::distributed::Vector<Number> solution;
solution.reinit(locally_owned_dofs, MPI_COMM_WORLD);
LinearAlgebra::distributed::Vector<Number> old_solution;
old_solution.reinit(locally_owned_dofs,
locally_relevant_dofs,
MPI_COMM_WORLD);
old_solution = solution;
soltrans.prepare_for_coarsening_and_refinement(old_solution);
solution.reinit(locally_owned_dofs, MPI_COMM_WORLD);
soltrans.interpolate(solution);
}