]> https://gitweb.dealii.org/ - dealii.git/commitdiff
make distribute_local_to_global() work with std:: iterators 15318/head
authorJohannes Heinz <johannes.heinz@tuwien.ac.at>
Tue, 6 Jun 2023 16:14:22 +0000 (18:14 +0200)
committerJohannes Heinz <johannes.heinz@tuwien.ac.at>
Wed, 7 Jun 2023 10:13:57 +0000 (12:13 +0200)
doc/news/changes/minor/20230606Heinz [new file with mode: 0644]
include/deal.II/dofs/dof_accessor.templates.h
tests/dofs/dof_accessor_03.cc [new file with mode: 0644]
tests/dofs/dof_accessor_03.with_p4est=true.mpirun=1.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20230606Heinz b/doc/news/changes/minor/20230606Heinz
new file mode 100644 (file)
index 0000000..1f194f5
--- /dev/null
@@ -0,0 +1,3 @@
+Fixed: DoFCellAccessor::distribute_local_to_global() now works with std:: iterators.
+<br>
+(Johannes Heinz, 2022/06/06)
index dcbade4d6d5434ee1a537be4d832cd9bfe9de975..2cb00893b513228db4e30d6d2c1456d0493e972b 100644 (file)
@@ -2837,7 +2837,7 @@ DoFCellAccessor<dimension_, space_dimension_, level_dof_access>::
     *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 (file)
index 0000000..a03b9ff
--- /dev/null
@@ -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<T>::iterators
+
+#include <deal.II/base/mpi.h>
+
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/dofs/dof_handler.h>
+
+#include <deal.II/fe/fe_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+// #include <deal.II/grid/tria.h>
+
+#include <deal.II/lac/la_parallel_vector.h>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+template <int dim, typename Number>
+void
+do_test()
+{
+  // create triangulation
+  parallel::distributed::Triangulation<dim> tria(MPI_COMM_WORLD);
+  GridGenerator::hyper_cube(tria);
+  tria.refine_global(2);
+
+  FE_Q<dim>       fe_q(2);
+  DoFHandler<dim> dof_handler(tria);
+  dof_handler.distribute_dofs(fe_q);
+
+  LinearAlgebra::distributed::Vector<Number> vector1(dof_handler.n_dofs());
+  LinearAlgebra::distributed::Vector<Number> vector2(dof_handler.n_dofs());
+  std::vector<Number>                        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<Number> 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 (file)
index 0000000..3a8dc33
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL:0::OK 
+DEAL:0::

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.