From: Johannes Heinz Date: Tue, 6 Jun 2023 16:14:22 +0000 (+0200) Subject: make distribute_local_to_global() work with std:: iterators X-Git-Tag: v9.5.0-rc1~145^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F15318%2Fhead;p=dealii.git make distribute_local_to_global() work with std:: iterators --- diff --git a/doc/news/changes/minor/20230606Heinz b/doc/news/changes/minor/20230606Heinz new file mode 100644 index 0000000000..1f194f539b --- /dev/null +++ b/doc/news/changes/minor/20230606Heinz @@ -0,0 +1,3 @@ +Fixed: DoFCellAccessor::distribute_local_to_global() now works with std:: iterators. +
+(Johannes Heinz, 2022/06/06) diff --git a/include/deal.II/dofs/dof_accessor.templates.h b/include/deal.II/dofs/dof_accessor.templates.h index dcbade4d6d..2cb00893b5 100644 --- a/include/deal.II/dofs/dof_accessor.templates.h +++ b/include/deal.II/dofs/dof_accessor.templates.h @@ -2837,7 +2837,7 @@ DoFCellAccessor:: *this, dof_indices, this->active_fe_index()); // distribute cell vector - global_destination.add(n_dofs, dof_indices.data(), local_source_begin); + global_destination.add(n_dofs, dof_indices.data(), &(*local_source_begin)); } diff --git a/tests/dofs/dof_accessor_03.cc b/tests/dofs/dof_accessor_03.cc new file mode 100644 index 0000000000..a03b9fff32 --- /dev/null +++ b/tests/dofs/dof_accessor_03.cc @@ -0,0 +1,83 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2021 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Test DoFCellAccessor::distribute_local_to_global() works with +// std::vector::iterators + +#include + +#include + +#include + +#include + +#include +// #include + +#include + +#include "../tests.h" + +using namespace dealii; + +template +void +do_test() +{ + // create triangulation + parallel::distributed::Triangulation tria(MPI_COMM_WORLD); + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + + FE_Q fe_q(2); + DoFHandler dof_handler(tria); + dof_handler.distribute_dofs(fe_q); + + LinearAlgebra::distributed::Vector vector1(dof_handler.n_dofs()); + LinearAlgebra::distributed::Vector vector2(dof_handler.n_dofs()); + std::vector std_vector(fe_q.dofs_per_cell); + std::iota(std_vector.begin(), std_vector.end(), Number{1}); + for (const auto &cell : dof_handler.active_cell_iterators()) + { + Vector dealii_vector(std_vector.begin(), std_vector.end()); + cell->distribute_local_to_global(dealii_vector.begin(), + dealii_vector.end(), + vector1); + + cell->distribute_local_to_global(std_vector.begin(), + std_vector.end(), + vector2); + } + + // check if both vectors are the same + vector1.add(Number{-1.0}, vector2); + assert(vector1.l2_norm() < 1e-12); + + deallog << "OK " << std::endl; + deallog << std::endl; +} + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll all; + deallog.precision(8); + + do_test<2, double>(); + + return 0; +} diff --git a/tests/dofs/dof_accessor_03.with_p4est=true.mpirun=1.output b/tests/dofs/dof_accessor_03.with_p4est=true.mpirun=1.output new file mode 100644 index 0000000000..3a8dc33699 --- /dev/null +++ b/tests/dofs/dof_accessor_03.with_p4est=true.mpirun=1.output @@ -0,0 +1,3 @@ + +DEAL:0::OK +DEAL:0::