]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix locally_owned_dofs_per_subdomain
authorTimo Heister <timo.heister@gmail.com>
Sun, 31 Jul 2016 13:27:21 +0000 (15:27 +0200)
committerTimo Heister <timo.heister@gmail.com>
Mon, 1 Aug 2016 08:25:52 +0000 (10:25 +0200)
DoFTools::locally_owned_dofs_per_subdomain would wrongly trigger an Assertion if running with a dealii::Triangulation (not a shared one) and with more than one MPI rank. This is now fixed.

source/dofs/dof_tools.cc
tests/mpi/locally_owned_dofs_per_subdomain_02.cc [new file with mode: 0644]
tests/mpi/locally_owned_dofs_per_subdomain_02.mpirun=2.output [new file with mode: 0644]

index 251e0d641edfbf3cb694814a0138f062cb0de840..738da85a2d2d0da369b0c1acec0830bff7b62057 100644 (file)
@@ -1149,7 +1149,8 @@ namespace DoFTools
       = (dynamic_cast<const parallel::Triangulation<DoFHandlerType::dimension,DoFHandlerType::space_dimension> *>
          (&dof_handler.get_triangulation()) == 0
          ?
-         1
+         (1+*std::max_element (subdomain_association.begin (),
+                               subdomain_association.end ()))
          :
          Utilities::MPI::n_mpi_processes
          (dynamic_cast<const parallel::Triangulation<DoFHandlerType::dimension,DoFHandlerType::space_dimension> *>
diff --git a/tests/mpi/locally_owned_dofs_per_subdomain_02.cc b/tests/mpi/locally_owned_dofs_per_subdomain_02.cc
new file mode 100644 (file)
index 0000000..b02a062
--- /dev/null
@@ -0,0 +1,60 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// Test DoFTools::locally_owned_dofs_per_subdomain (for a standard Triangulation)
+
+#include "../tests.h"
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/dofs/dof_tools.h>
+#include <deal.II/grid/grid_tools.h>
+
+
+template <int dim>
+void test ()
+{
+  Triangulation<dim> triangulation;
+  GridGenerator::hyper_cube(triangulation, -1.0, 1.0);
+  triangulation.refine_global(1);
+
+  const unsigned int nproc = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD);
+
+  GridTools::partition_triangulation (nproc,
+                                      triangulation);
+
+  FE_Q<dim> fe(1);
+  DoFHandler<dim> dof_handler (triangulation);
+  dof_handler.distribute_dofs(fe);
+
+  std::vector<IndexSet> locally_owned_dofs_per_proc = DoFTools::locally_owned_dofs_per_subdomain(dof_handler);
+
+  for (unsigned int p=0; p<nproc; ++p)
+    {
+      deallog << "proc " << p << ": " << std::endl;
+      locally_owned_dofs_per_proc[p].print(deallog.get_file_stream());
+    }
+}
+
+int main (int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads());
+
+  MPILogInitAll all;
+
+  test<2>();
+}
diff --git a/tests/mpi/locally_owned_dofs_per_subdomain_02.mpirun=2.output b/tests/mpi/locally_owned_dofs_per_subdomain_02.mpirun=2.output
new file mode 100644 (file)
index 0000000..ffe0b4d
--- /dev/null
@@ -0,0 +1,11 @@
+
+DEAL:0::proc 0: 
+{[0,1], [4,5]}
+DEAL:0::proc 1: 
+{[2,3], [6,8]}
+
+DEAL:1::proc 0: 
+{[0,1], [4,5]}
+DEAL:1::proc 1: 
+{[2,3], [6,8]}
+

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.