Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal error in SolutionTransfer #14189

Closed
bangerth opened this issue Aug 15, 2022 · 1 comment · Fixed by #14193
Closed

Internal error in SolutionTransfer #14189

bangerth opened this issue Aug 15, 2022 · 1 comment · Fixed by #14193
Labels
Milestone

Comments

@bangerth
Copy link
Member

bangerth commented Aug 15, 2022

This is a shrunk version of a test case provided by M. Baensch on the mailing list a couple of days ago:
https://groups.google.com/g/dealii/c/us2AK80OjUU/

#include <deal.II/distributed/tria.h>
#include <deal.II/distributed/solution_transfer.h>
#include <deal.II/distributed/grid_refinement.h>

#include <deal.II/dofs/dof_handler.h>
#include <deal.II/dofs/dof_tools.h>

#include <deal.II/fe/fe_dgq.h>
#include <deal.II/fe/fe_system.h>

#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/tria.h>
#include <deal.II/grid/tria_accessor.h>
#include <deal.II/grid/tria_iterator.h>

#include <deal.II/lac/la_parallel_vector.h>


using namespace dealii;

template <int dim>
class EulerProblem
{
public:
  EulerProblem();
  void make_grid_and_dofs();    
  void refine_grid();

private:
  parallel::distributed::Triangulation<dim> triangulation;

  FESystem<dim>        fe;
  DoFHandler<dim>      dof_handler;
  LinearAlgebra::distributed::Vector<double> solution;
};

  
template <int dim>
EulerProblem<dim>::EulerProblem()
: triangulation(MPI_COMM_WORLD)
  , fe(FE_DGQ<dim>(1), dim + 2)
  , dof_handler(triangulation)
{}



template <int dim>
void EulerProblem<dim>::make_grid_and_dofs()
{
  GridGenerator::channel_with_cylinder(
    triangulation, 0.03, 1, 0, true);
  dof_handler.distribute_dofs(fe);

  solution.reinit (dof_handler.n_dofs());
}


  
template <int dim>
void EulerProblem<dim>::refine_grid()
{
  const int max_h_level = 5;
  
  for (const auto &cell : dof_handler.active_cell_iterators())
    {
      cell->clear_coarsen_flag();
      cell->clear_refine_flag();
 
      if ((cell->level() < max_h_level) &&
          (cell->extent_in_direction(0) < 0.1))
        cell->set_refine_flag();
    }

  // see distributed::SolutionTransfer documentation for details
  parallel::distributed::SolutionTransfer<dim, LinearAlgebra::distributed::Vector<double>>	 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<double> solution;
  solution.reinit(locally_owned_dofs, MPI_COMM_WORLD);

  LinearAlgebra::distributed::Vector<double> 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);
}
  

int main(int argc, char **argv)
{
  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
  EulerProblem<2> euler_problem;
  euler_problem.make_grid_and_dofs();
  euler_problem.refine_grid();
}

It fails with this assertion:

--------------------------------------------------------
An error occurred in line <92> of file </home/bangerth/p/deal.II/1/dealii/source/distributed/solution_transfer.cc> in function
    std::vector<dealii::Vector<OtherNumber> > dealii::{anonymous}::unpack_dof_values(const boost::iterator_range<__gnu_cxx::__normal_iterator<const char*, std::vector<char, std::allocator<char> > > >&, unsigned int) [with value_type = double]
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.

Stacktrace:
-----------
#0  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: 
#1  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: dealii::parallel::distributed::SolutionTransfer<2, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>, 2>::unpack_callback(dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&, std::vector<dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>*, std::allocator<dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>*> >&, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>&)
#2  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: dealii::parallel::distributed::SolutionTransfer<2, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>, 2>::interpolate(std::vector<dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>*, std::allocator<dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>*> >&)::{lambda(dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&)#1}::operator()(dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&) const
#3  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: std::_Function_handler<void (dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&), dealii::parallel::distributed::SolutionTransfer<2, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>, 2>::interpolate(std::vector<dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>*, std::allocator<dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>*> >&)::{lambda(dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&)#1}>::_M_invoke(std::_Any_data const&, dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus&&, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&)
#4  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: std::function<void (dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&)>::operator()(dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&) const
#5  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: std::_Function_handler<void (dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus const&, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&), std::function<void (dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&)> >::_M_invoke(std::_Any_data const&, dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus const&, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&)
#6  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: std::function<void (dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus const&, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&)>::operator()(dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus const&, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&) const
#7  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: dealii::parallel::DistributedTriangulationBase<2, 2>::DataTransfer::unpack_data(std::vector<std::pair<dealii::TriaIterator<dealii::CellAccessor<2, 2> >, dealii::Triangulation<2, 2>::CellStatus>, std::allocator<std::pair<dealii::TriaIterator<dealii::CellAccessor<2, 2> >, dealii::Triangulation<2, 2>::CellStatus> > > const&, unsigned int, std::function<void (dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus const&, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&)> const&) const
#8  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: dealii::parallel::DistributedTriangulationBase<2, 2>::notify_ready_to_unpack(unsigned int, std::function<void (dealii::TriaIterator<dealii::CellAccessor<2, 2> > const&, dealii::Triangulation<2, 2>::CellStatus, boost::iterator_range<__gnu_cxx::__normal_iterator<char const*, std::vector<char, std::allocator<char> > > > const&)> const&)
#9  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: dealii::parallel::distributed::SolutionTransfer<2, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>, 2>::interpolate(std::vector<dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>*, std::allocator<dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>*> >&)
#10  /home/bangerth/p/deal.II/1/install/lib/libdeal_II.g.so.9.5.0-pre: dealii::parallel::distributed::SolutionTransfer<2, dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>, 2>::interpolate(dealii::LinearAlgebra::distributed::Vector<double, dealii::MemorySpace::Host>&)
#11  ./step-67: EulerProblem<2>::refine_grid()
#12  ./step-67: main

Unfortunately, I don't have the time to debug this now :-(

@bangerth bangerth added the Bug label Aug 15, 2022
@bangerth bangerth added this to the Release 9.5 milestone Aug 15, 2022
@tjhei
Copy link
Member

tjhei commented Aug 16, 2022

I see two calls to soltrans.prepare_for_coarsening_and_refinement. That can't be right. But we should have a better error message. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants