]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added tests for ::SolutionTransfer on p::s::Triangulations with artificial cells. 11733/head
authorMarc Fehling <marc.fehling@gmx.net>
Tue, 9 Feb 2021 00:21:35 +0000 (17:21 -0700)
committerMarc Fehling <mafehling.git@gmail.com>
Fri, 12 Feb 2021 20:24:08 +0000 (13:24 -0700)
tests/mpi/solution_transfer_07.cc [new file with mode: 0644]
tests/mpi/solution_transfer_07.with_mpi=true.mpirun=2.output [new file with mode: 0644]
tests/mpi/solution_transfer_08.cc [new file with mode: 0644]
tests/mpi/solution_transfer_08.with_mpi=true.mpirun=2.output [new file with mode: 0644]
tests/mpi/solution_transfer_09.cc [new file with mode: 0644]
tests/mpi/solution_transfer_09.with_mpi=true.mpirun=2.output [new file with mode: 0644]
tests/mpi/solution_transfer_10.cc [new file with mode: 0644]
tests/mpi/solution_transfer_10.with_mpi=true.mpirun=2.output [new file with mode: 0644]

diff --git a/tests/mpi/solution_transfer_07.cc b/tests/mpi/solution_transfer_07.cc
new file mode 100644 (file)
index 0000000..b3be482
--- /dev/null
@@ -0,0 +1,92 @@
+// ---------------------------------------------------------------------
+//
+// 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Verify that SolutionTransfer works on parallel shared Triangulation
+// objects with or without artificial cells.
+//
+// Test 'coarsening_and_refinement'.
+
+
+#include <deal.II/distributed/shared_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/vector.h>
+
+#include <deal.II/numerics/solution_transfer.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+test(const bool allow_artificial_cells)
+{
+  parallel::shared::Triangulation<dim> tria(MPI_COMM_WORLD,
+                                            Triangulation<dim>::none,
+                                            allow_artificial_cells);
+  GridGenerator::subdivided_hyper_cube(tria, 2);
+
+  FE_Q<dim>       fe(1);
+  DoFHandler<dim> dh(tria);
+  dh.distribute_dofs(fe);
+
+  tria.begin_active()->set_refine_flag();
+  tria.prepare_coarsening_and_refinement();
+
+  Vector<double> sol_old(dh.n_dofs());
+  sol_old = 1.;
+
+  SolutionTransfer<dim> soltrans(dh);
+  soltrans.prepare_for_coarsening_and_refinement(sol_old);
+
+  tria.execute_coarsening_and_refinement();
+  dh.distribute_dofs(fe);
+
+  Vector<double> sol_new(dh.n_dofs());
+  soltrans.interpolate(sol_old, sol_new);
+  for (unsigned int i = 0; i < sol_new.size(); ++i)
+    AssertThrow(sol_new[i] == 1., ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+int
+main(int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll                    log;
+
+  deallog.push("1d");
+  test<1>(false);
+  test<1>(true);
+  deallog.pop();
+  deallog.push("2d");
+  test<2>(false);
+  test<2>(true);
+  deallog.pop();
+  deallog.push("3d");
+  test<3>(false);
+  test<3>(true);
+  deallog.pop();
+}
diff --git a/tests/mpi/solution_transfer_07.with_mpi=true.mpirun=2.output b/tests/mpi/solution_transfer_07.with_mpi=true.mpirun=2.output
new file mode 100644 (file)
index 0000000..1f211b7
--- /dev/null
@@ -0,0 +1,15 @@
+
+DEAL:0:1d::OK
+DEAL:0:1d::OK
+DEAL:0:2d::OK
+DEAL:0:2d::OK
+DEAL:0:3d::OK
+DEAL:0:3d::OK
+
+DEAL:1:1d::OK
+DEAL:1:1d::OK
+DEAL:1:2d::OK
+DEAL:1:2d::OK
+DEAL:1:3d::OK
+DEAL:1:3d::OK
+
diff --git a/tests/mpi/solution_transfer_08.cc b/tests/mpi/solution_transfer_08.cc
new file mode 100644 (file)
index 0000000..09471e6
--- /dev/null
@@ -0,0 +1,92 @@
+// ---------------------------------------------------------------------
+//
+// 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Verify that SolutionTransfer works on parallel shared Triangulation
+// objects with or without artificial cells.
+//
+// Test 'pure_refinement'.
+
+
+#include <deal.II/distributed/shared_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/vector.h>
+
+#include <deal.II/numerics/solution_transfer.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+test(const bool allow_artificial_cells)
+{
+  parallel::shared::Triangulation<dim> tria(MPI_COMM_WORLD,
+                                            Triangulation<dim>::none,
+                                            allow_artificial_cells);
+  GridGenerator::subdivided_hyper_cube(tria, 2);
+
+  FE_Q<dim>       fe(1);
+  DoFHandler<dim> dh(tria);
+  dh.distribute_dofs(fe);
+
+  tria.begin_active()->set_refine_flag();
+  tria.prepare_coarsening_and_refinement();
+
+  Vector<double> sol_old(dh.n_dofs());
+  sol_old = 1.;
+
+  SolutionTransfer<dim> soltrans(dh);
+  soltrans.prepare_for_pure_refinement();
+
+  tria.execute_coarsening_and_refinement();
+  dh.distribute_dofs(fe);
+
+  Vector<double> sol_new(dh.n_dofs());
+  soltrans.refine_interpolate(sol_old, sol_new);
+  for (unsigned int i = 0; i < sol_new.size(); ++i)
+    AssertThrow(sol_new[i] == 1., ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+int
+main(int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll                    log;
+
+  deallog.push("1d");
+  test<1>(false);
+  test<1>(true);
+  deallog.pop();
+  deallog.push("2d");
+  test<2>(false);
+  test<2>(true);
+  deallog.pop();
+  deallog.push("3d");
+  test<3>(false);
+  test<3>(true);
+  deallog.pop();
+}
diff --git a/tests/mpi/solution_transfer_08.with_mpi=true.mpirun=2.output b/tests/mpi/solution_transfer_08.with_mpi=true.mpirun=2.output
new file mode 100644 (file)
index 0000000..1f211b7
--- /dev/null
@@ -0,0 +1,15 @@
+
+DEAL:0:1d::OK
+DEAL:0:1d::OK
+DEAL:0:2d::OK
+DEAL:0:2d::OK
+DEAL:0:3d::OK
+DEAL:0:3d::OK
+
+DEAL:1:1d::OK
+DEAL:1:1d::OK
+DEAL:1:2d::OK
+DEAL:1:2d::OK
+DEAL:1:3d::OK
+DEAL:1:3d::OK
+
diff --git a/tests/mpi/solution_transfer_09.cc b/tests/mpi/solution_transfer_09.cc
new file mode 100644 (file)
index 0000000..a1ee737
--- /dev/null
@@ -0,0 +1,110 @@
+// ---------------------------------------------------------------------
+//
+// 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Verify that SolutionTransfer yields the same result on parallel
+// shared Triangulation objects with and without artificial cells.
+//
+// Test 'coarsening_and_refinement'.
+
+
+#include <deal.II/base/function.h>
+#include <deal.II/base/function_lib.h>
+
+#include <deal.II/distributed/shared_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/vector.h>
+
+#include <deal.II/numerics/solution_transfer.h>
+#include <deal.II/numerics/vector_tools.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+Vector<double>
+refine_and_transfer(const Function<dim> &function, Triangulation<dim> &tria)
+{
+  FE_Q<dim>       fe(1);
+  DoFHandler<dim> dh(tria);
+  dh.distribute_dofs(fe);
+
+  tria.begin_active()->set_refine_flag();
+  tria.prepare_coarsening_and_refinement();
+
+  Vector<double> sol_old(dh.n_dofs());
+  VectorTools::interpolate(MappingQGeneric<dim>(1), dh, function, sol_old);
+
+  SolutionTransfer<dim> soltrans(dh);
+  soltrans.prepare_for_coarsening_and_refinement(sol_old);
+
+  tria.execute_coarsening_and_refinement();
+  dh.distribute_dofs(fe);
+
+  Vector<double> sol_new(dh.n_dofs());
+  soltrans.interpolate(sol_old, sol_new);
+
+  return sol_new;
+}
+
+
+template <int dim>
+void
+test(const Function<dim> &function)
+{
+  parallel::shared::Triangulation<dim> tria(MPI_COMM_WORLD,
+                                            Triangulation<dim>::none,
+                                            false);
+  parallel::shared::Triangulation<dim> tria_artificial(MPI_COMM_WORLD,
+                                                       Triangulation<dim>::none,
+                                                       true);
+  GridGenerator::subdivided_hyper_cube(tria, 2);
+  GridGenerator::subdivided_hyper_cube(tria_artificial, 2);
+
+  Vector<double> sol = refine_and_transfer(function, tria);
+  Vector<double> sol_artificial =
+    refine_and_transfer(function, tria_artificial);
+
+  AssertDimension(sol.size(), sol_artificial.size());
+  AssertThrow(sol == sol_artificial, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+int
+main(int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll                    log;
+
+  deallog.push("1d");
+  test<1>(Functions::CosineFunction<1>());
+  deallog.pop();
+  deallog.push("2d");
+  test<2>(Functions::CosineFunction<2>());
+  deallog.pop();
+  deallog.push("3d");
+  test<3>(Functions::CosineFunction<3>());
+  deallog.pop();
+}
diff --git a/tests/mpi/solution_transfer_09.with_mpi=true.mpirun=2.output b/tests/mpi/solution_transfer_09.with_mpi=true.mpirun=2.output
new file mode 100644 (file)
index 0000000..1b4e669
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL:0:1d::OK
+DEAL:0:2d::OK
+DEAL:0:3d::OK
+
+DEAL:1:1d::OK
+DEAL:1:2d::OK
+DEAL:1:3d::OK
+
diff --git a/tests/mpi/solution_transfer_10.cc b/tests/mpi/solution_transfer_10.cc
new file mode 100644 (file)
index 0000000..be62e2f
--- /dev/null
@@ -0,0 +1,110 @@
+// ---------------------------------------------------------------------
+//
+// 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Verify that SolutionTransfer yields the same result on parallel
+// shared Triangulation objects with and without artificial cells.
+//
+// Test 'pure_refinement'.
+
+
+#include <deal.II/base/function.h>
+#include <deal.II/base/function_lib.h>
+
+#include <deal.II/distributed/shared_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/vector.h>
+
+#include <deal.II/numerics/solution_transfer.h>
+#include <deal.II/numerics/vector_tools.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+Vector<double>
+refine_and_transfer(const Function<dim> &function, Triangulation<dim> &tria)
+{
+  FE_Q<dim>       fe(1);
+  DoFHandler<dim> dh(tria);
+  dh.distribute_dofs(fe);
+
+  tria.begin_active()->set_refine_flag();
+  tria.prepare_coarsening_and_refinement();
+
+  Vector<double> sol_old(dh.n_dofs());
+  VectorTools::interpolate(MappingQGeneric<dim>(1), dh, function, sol_old);
+
+  SolutionTransfer<dim> soltrans(dh);
+  soltrans.prepare_for_pure_refinement();
+
+  tria.execute_coarsening_and_refinement();
+  dh.distribute_dofs(fe);
+
+  Vector<double> sol_new(dh.n_dofs());
+  soltrans.refine_interpolate(sol_old, sol_new);
+
+  return sol_new;
+}
+
+
+template <int dim>
+void
+test(const Function<dim> &function)
+{
+  parallel::shared::Triangulation<dim> tria(MPI_COMM_WORLD,
+                                            Triangulation<dim>::none,
+                                            false);
+  parallel::shared::Triangulation<dim> tria_artificial(MPI_COMM_WORLD,
+                                                       Triangulation<dim>::none,
+                                                       true);
+  GridGenerator::subdivided_hyper_cube(tria, 2);
+  GridGenerator::subdivided_hyper_cube(tria_artificial, 2);
+
+  Vector<double> sol = refine_and_transfer(function, tria);
+  Vector<double> sol_artificial =
+    refine_and_transfer(function, tria_artificial);
+
+  AssertDimension(sol.size(), sol_artificial.size());
+  AssertThrow(sol == sol_artificial, ExcInternalError());
+
+  deallog << "OK" << std::endl;
+}
+
+
+int
+main(int argc, char **argv)
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+  MPILogInitAll                    log;
+
+  deallog.push("1d");
+  test<1>(Functions::CosineFunction<1>());
+  deallog.pop();
+  deallog.push("2d");
+  test<2>(Functions::CosineFunction<2>());
+  deallog.pop();
+  deallog.push("3d");
+  test<3>(Functions::CosineFunction<3>());
+  deallog.pop();
+}
diff --git a/tests/mpi/solution_transfer_10.with_mpi=true.mpirun=2.output b/tests/mpi/solution_transfer_10.with_mpi=true.mpirun=2.output
new file mode 100644 (file)
index 0000000..1b4e669
--- /dev/null
@@ -0,0 +1,9 @@
+
+DEAL:0:1d::OK
+DEAL:0:2d::OK
+DEAL:0:3d::OK
+
+DEAL:1:1d::OK
+DEAL:1:2d::OK
+DEAL:1:3d::OK
+

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.