From: Denis Davydov Date: Fri, 25 Sep 2015 16:28:44 +0000 (+0200) Subject: extend parallel::shared::Triangulation to allow artifical cells X-Git-Tag: v8.4.0-rc2~273^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48922fc9e4b2b03e13169d8e3fdcf4a55b7b2a20;p=dealii.git extend parallel::shared::Triangulation to allow artifical cells --- diff --git a/include/deal.II/distributed/shared_tria.h b/include/deal.II/distributed/shared_tria.h index 33fcfc7c5a..d0aa299734 100644 --- a/include/deal.II/distributed/shared_tria.h +++ b/include/deal.II/distributed/shared_tria.h @@ -77,10 +77,17 @@ namespace parallel /** * Constructor. + * + * If @p allow_aritifical_cells is true, this class will behave + * similar to parallel::distributed::Triangulation in that there will be + * locally owned, ghost and artificial cells. + * + * Otherwise all non-locally owned cells are considered ghost. */ Triangulation (MPI_Comm mpi_communicator, const typename dealii::Triangulation::MeshSmoothing = - (dealii::Triangulation::none) ); + (dealii::Triangulation::none), + const bool allow_artificial_cells = false); /** * Destructor. @@ -106,6 +113,43 @@ namespace parallel const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata); + /** + * Return a vector of length Triangulation::n_active_cells() where each + * element stores the subdomain id of the owner of this cell. The elements + * of the vector are obviously the same as the subdomain ids for locally + * owned and ghost cells, but are also correct for artificial cells that + * do not store who the owner of the cell is in their subdomain_id field. + */ + const std::vector &get_true_subdomain_ids_of_cells() const; + + /** + * Return allow_artificial_cells , namely true if artificial cells are allowed. + */ + bool with_artificial_cells() const; + + private: + /** + * A flag to decide whether or not artificial cells are allowed. + */ + const bool allow_artificial_cells; + + /** + * This function calls GridTools::partition_triangulation () and if + * requested in the constructor of the class marks artificial cells. + */ + void partition(); + + /** + * A vector containing subdomain IDs of cells obtained by partitioning + * using METIS. In case allow_artificial_cells is false, this vector + * is consistent with IDs stored in cell->subdomain_id() of the triangulation + * class. When allow_artificial_cells is true, cells which are artificial + * will have cell->subdomain_id() == numbers::artificial; + * + * The original parition information is stored to allow using sequential + * DoF distribution and partitioning functions with semi-artificial cells. + */ + std::vector true_subdomain_ids_of_cells; }; } #else diff --git a/source/distributed/shared_tria.cc b/source/distributed/shared_tria.cc index 02d4c99951..9edc8f903f 100644 --- a/source/distributed/shared_tria.cc +++ b/source/distributed/shared_tria.cc @@ -24,9 +24,12 @@ #include #include #include +#include #include + + #include #include #include @@ -43,11 +46,61 @@ namespace parallel template Triangulation::Triangulation (MPI_Comm mpi_communicator, - const typename dealii::Triangulation::MeshSmoothing smooth_grid): - dealii::parallel::Triangulation(mpi_communicator,smooth_grid,false) + const typename dealii::Triangulation::MeshSmoothing smooth_grid, + const bool allow_artificial_cells): + dealii::parallel::Triangulation(mpi_communicator,smooth_grid,false), + allow_artificial_cells(allow_artificial_cells) { } + template + void Triangulation::partition() + { + dealii::GridTools::partition_triangulation (this->n_subdomains, *this); + + if (allow_artificial_cells) + { + true_subdomain_ids_of_cells.resize(this->n_active_cells()); + + // get halo layer of (ghost) cells + // parallel::shared::Triangulation:: + std_cxx11::function::active_cell_iterator &)> predicate + = IteratorFilters::SubdomainEqualTo(this->my_subdomain); + + const std::vector::active_cell_iterator> + active_halo_layer_vector = GridTools::compute_active_cell_halo_layer (*this, predicate); + std::set::active_cell_iterator> + active_halo_layer(active_halo_layer_vector.begin(), active_halo_layer_vector.end()); + + // loop over all cells and mark artificial: + typename parallel::shared::Triangulation::active_cell_iterator + cell = this->begin_active(), + endc = this->end(); + for (unsigned int index=0; cell != endc; cell++, index++) + { + // store original/true subdomain ids: + true_subdomain_ids_of_cells[index] = cell->subdomain_id(); + + if (cell->is_locally_owned() == false && + active_halo_layer.find(cell) == active_halo_layer.end()) + cell->set_subdomain_id(numbers::artificial_subdomain_id); + } + } + } + + template + bool + Triangulation::with_artificial_cells() const + { + return allow_artificial_cells; + } + + template + const std::vector & + Triangulation::get_true_subdomain_ids_of_cells() const + { + return true_subdomain_ids_of_cells; + } template Triangulation::~Triangulation () @@ -60,7 +113,7 @@ namespace parallel Triangulation::execute_coarsening_and_refinement () { dealii::Triangulation::execute_coarsening_and_refinement (); - dealii::GridTools::partition_triangulation (this->n_subdomains, *this); + partition(); this->update_number_cache (); } @@ -81,7 +134,7 @@ namespace parallel // cells AssertThrow (false, ExcInternalError()); } - dealii::GridTools::partition_triangulation (this->n_subdomains, *this); + partition(); this->update_number_cache (); } diff --git a/source/dofs/dof_handler_policy.cc b/source/dofs/dof_handler_policy.cc index 7dd0650180..4621cd2ac4 100644 --- a/source/dofs/dof_handler_policy.cc +++ b/source/dofs/dof_handler_policy.cc @@ -1068,14 +1068,45 @@ namespace internal distribute_dofs (DoFHandler &dof_handler, NumberCache &number_cache) const { + // If the underlying shared::Tria allows artifical cells, we need to do + // some tricks here to make Sequential algorithms play nicely. + // Namely, we first restore original partition (without artificial cells) + // and then turn artificial cells on at the end of this function. + const parallel::shared::Triangulation *tr = + (dynamic_cast*> (&dof_handler.get_tria ())); + Assert(tr != 0, ExcInternalError()); + typename parallel::shared::Triangulation::active_cell_iterator + cell = dof_handler.get_tria().begin_active(), + endc = dof_handler.get_tria().end(); + std::vector current_subdomain_ids(tr->n_active_cells()); + const std::vector &true_subdomain_ids = tr->get_true_subdomain_ids_of_cells(); + if (tr->with_artificial_cells()) + for (unsigned int index=0; cell != endc; cell++, index++) + { + current_subdomain_ids[index] = cell->subdomain_id(); + cell->set_subdomain_id(true_subdomain_ids[index]); + } + Sequential::distribute_dofs (dof_handler,number_cache); DoFRenumbering::subdomain_wise (dof_handler); + // dofrenumbering will reset subdomains, this is ugly but we need to do it again: + cell = tr->begin_active(); + if (tr->with_artificial_cells()) + for (unsigned int index=0; cell != endc; cell++, index++) + cell->set_subdomain_id(true_subdomain_ids[index]); + number_cache.locally_owned_dofs_per_processor = DoFTools::locally_owned_dofs_per_subdomain (dof_handler); number_cache.locally_owned_dofs = number_cache.locally_owned_dofs_per_processor[dof_handler.get_tria().locally_owned_subdomain()]; number_cache.n_locally_owned_dofs_per_processor.resize (number_cache.locally_owned_dofs_per_processor.size()); for (unsigned int i = 0; i < number_cache.n_locally_owned_dofs_per_processor.size(); i++) number_cache.n_locally_owned_dofs_per_processor[i] = number_cache.locally_owned_dofs_per_processor[i].n_elements(); number_cache.n_locally_owned_dofs = number_cache.n_locally_owned_dofs_per_processor[dof_handler.get_tria().locally_owned_subdomain()]; + + // restore current subdomain ids + cell = tr->begin_active(); + if (tr->with_artificial_cells()) + for (unsigned int index=0; cell != endc; cell++, index++) + cell->set_subdomain_id(current_subdomain_ids[index]); } template @@ -1105,6 +1136,23 @@ namespace internal (void)number_cache; Assert (false, ExcNotImplemented()); #else + // Similar to distribute_dofs() we need to have a special treatment in + // case artificial cells are present. + const parallel::shared::Triangulation *tr = + (dynamic_cast*> (&dof_handler.get_tria ())); + Assert(tr != 0, ExcInternalError()); + typename parallel::shared::Triangulation::active_cell_iterator + cell = dof_handler.get_tria().begin_active(), + endc = dof_handler.get_tria().end(); + std::vector current_subdomain_ids(tr->n_active_cells()); + const std::vector &true_subdomain_ids = tr->get_true_subdomain_ids_of_cells(); + if (tr->with_artificial_cells()) + for (unsigned int index=0; cell != endc; cell++, index++) + { + current_subdomain_ids[index] = cell->subdomain_id(); + cell->set_subdomain_id(true_subdomain_ids[index]); + } + std::vector global_gathered_numbers (dof_handler.n_dofs (), 0); // as we call DoFRenumbering::subdomain_wise (dof_handler) from distribute_dofs(), // we need to support sequential-like input. @@ -1117,9 +1165,6 @@ namespace internal { Assert(new_numbers.size() == dof_handler.locally_owned_dofs().n_elements(), ExcInternalError()); - const parallel::shared::Triangulation *tr = - (dynamic_cast*> (&dof_handler.get_tria ())); - Assert(tr != 0, ExcInternalError()); const unsigned int n_cpu = Utilities::MPI::n_mpi_processes (tr->get_communicator ()); std::vector gathered_new_numbers (dof_handler.n_dofs (), 0); Assert(Utilities::MPI::this_mpi_process (tr->get_communicator ()) == @@ -1208,6 +1253,12 @@ namespace internal number_cache.n_locally_owned_dofs = number_cache.n_locally_owned_dofs_per_processor[dof_handler.get_tria ().locally_owned_subdomain ()]; + + // restore artificial cells + cell = tr->begin_active(); + if (tr->with_artificial_cells()) + for (unsigned int index=0; cell != endc; cell++, index++) + cell->set_subdomain_id(current_subdomain_ids[index]); #endif } diff --git a/source/dofs/dof_tools.cc b/source/dofs/dof_tools.cc index 12665d0565..8e33837f4c 100644 --- a/source/dofs/dof_tools.cc +++ b/source/dofs/dof_tools.cc @@ -38,7 +38,7 @@ #include #include #include - +#include #include #include @@ -1144,6 +1144,25 @@ namespace DoFTools Assert(dof_handler.n_dofs() > 0, ExcMessage("Number of DoF is not positive. " "This could happen when the function is called before NumberCache is written.")); + + // In case this function is executed with parallel::shared::Triangulation + // with artifical cells, we need to take "true" subdomain IDs (i.e. without + // artificial cells). Otherwise we are good to use subdomain_id as stored + // in cell->subdomain_id(). + std::vector cell_owners (dof_handler.get_tria().n_active_cells()); + if (const parallel::shared::Triangulation *tr = + (dynamic_cast*> (&dof_handler.get_tria ()))) + { + cell_owners = tr->get_true_subdomain_ids_of_cells(); + } + else + { + for (typename DH::active_cell_iterator cell = dof_handler.begin_active(); + cell!= dof_handler.end(); cell++) + if (cell->is_locally_owned()) + cell_owners[cell->active_cell_index()] = cell->subdomain_id(); + } + // preset all values by an invalid value std::fill_n (subdomain_association.begin(), dof_handler.n_dofs(), numbers::invalid_subdomain_id); @@ -1162,11 +1181,7 @@ namespace DoFTools endc = dof_handler.end(); for (; cell!=endc; ++cell) { - Assert (cell->is_artificial() == false, - ExcMessage ("You can't call this function for meshes that " - "have artificial cells.")); - - const types::subdomain_id subdomain_id = cell->subdomain_id(); + const types::subdomain_id subdomain_id = cell_owners[cell->active_cell_index()]; const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell; local_dof_indices.resize (dofs_per_cell); cell->get_dof_indices (local_dof_indices); diff --git a/tests/sharedtria/dof_03.cc b/tests/sharedtria/dof_03.cc new file mode 100644 index 0000000000..9d557302e7 --- /dev/null +++ b/tests/sharedtria/dof_03.cc @@ -0,0 +1,150 @@ +// --------------------------------------------------------------------- +// $Id: dof_handler_number_cache.cc 31761 2013-11-22 14:42:37Z heister $ +// +// Copyright (C) 2008 - 2013, 2015 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. +// +// --------------------------------------------------------------------- + + + +// check number cache for shared_tria with artifical cells + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +template +void test() +{ + parallel::shared::Triangulation + triangulation (MPI_COMM_WORLD, + Triangulation::none, + /*artificial*/true); + + FESystem fe (FE_Q(3),2, + FE_DGQ(1),1); + + DoFHandler dof_handler (triangulation); + + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global (2); + + const unsigned int n_refinements[] = { 0, 4, 3, 2 }; + for (unsigned int i=0; i flags (triangulation.n_active_cells(), false); + for (unsigned int k=0; k::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + if (flags[index]) + cell->set_refine_flag(); + ++index; + } + + Assert (index <= triangulation.n_active_cells(), ExcInternalError()); + + // flag all other cells for coarsening + // (this should ensure that at least + // some of them will actually be + // coarsened) + index=0; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + if (!flags[index]) + cell->set_coarsen_flag(); + ++index; + } + + triangulation.execute_coarsening_and_refinement (); + dof_handler.distribute_dofs (fe); + + deallog + << "n_dofs: " << dof_handler.n_dofs() << std::endl + << "n_locally_owned_dofs: " << dof_handler.n_locally_owned_dofs() << std::endl; + + deallog << "n_locally_owned_dofs_per_processor: "; + std::vector v = dof_handler.n_locally_owned_dofs_per_processor(); + unsigned int sum = 0; + for (unsigned int i=0; i(); + deallog.pop(); + + deallog.push("3d"); + test<3>(); + deallog.pop(); +} diff --git a/tests/sharedtria/dof_03.with_metis=true.with_64bit_indices=off.mpirun=3.output b/tests/sharedtria/dof_03.with_metis=true.with_64bit_indices=off.mpirun=3.output new file mode 100644 index 0000000000..ccb18a2933 --- /dev/null +++ b/tests/sharedtria/dof_03.with_metis=true.with_64bit_indices=off.mpirun=3.output @@ -0,0 +1,50 @@ + +DEAL:0:2d::n_dofs: 818 +DEAL:0:2d::n_locally_owned_dofs: 301 +DEAL:0:2d::n_locally_owned_dofs_per_processor: 301 261 256 sum: 818 +DEAL:0:2d::n_dofs: 1754 +DEAL:0:2d::n_locally_owned_dofs: 578 +DEAL:0:2d::n_locally_owned_dofs_per_processor: 578 615 561 sum: 1754 +DEAL:0:2d::n_dofs: 3056 +DEAL:0:2d::n_locally_owned_dofs: 1011 +DEAL:0:2d::n_locally_owned_dofs_per_processor: 1011 1091 954 sum: 3056 +DEAL:0:3d::n_dofs: 13282 +DEAL:0:3d::n_locally_owned_dofs: 4484 +DEAL:0:3d::n_locally_owned_dofs_per_processor: 4484 4322 4476 sum: 13282 +DEAL:0:3d::n_dofs: 41826 +DEAL:0:3d::n_locally_owned_dofs: 13898 +DEAL:0:3d::n_locally_owned_dofs_per_processor: 13898 13950 13978 sum: 41826 + +DEAL:1:2d::n_dofs: 818 +DEAL:1:2d::n_locally_owned_dofs: 261 +DEAL:1:2d::n_locally_owned_dofs_per_processor: 301 261 256 sum: 818 +DEAL:1:2d::n_dofs: 1754 +DEAL:1:2d::n_locally_owned_dofs: 615 +DEAL:1:2d::n_locally_owned_dofs_per_processor: 578 615 561 sum: 1754 +DEAL:1:2d::n_dofs: 3056 +DEAL:1:2d::n_locally_owned_dofs: 1091 +DEAL:1:2d::n_locally_owned_dofs_per_processor: 1011 1091 954 sum: 3056 +DEAL:1:3d::n_dofs: 13282 +DEAL:1:3d::n_locally_owned_dofs: 4322 +DEAL:1:3d::n_locally_owned_dofs_per_processor: 4484 4322 4476 sum: 13282 +DEAL:1:3d::n_dofs: 41826 +DEAL:1:3d::n_locally_owned_dofs: 13950 +DEAL:1:3d::n_locally_owned_dofs_per_processor: 13898 13950 13978 sum: 41826 + + +DEAL:2:2d::n_dofs: 818 +DEAL:2:2d::n_locally_owned_dofs: 256 +DEAL:2:2d::n_locally_owned_dofs_per_processor: 301 261 256 sum: 818 +DEAL:2:2d::n_dofs: 1754 +DEAL:2:2d::n_locally_owned_dofs: 561 +DEAL:2:2d::n_locally_owned_dofs_per_processor: 578 615 561 sum: 1754 +DEAL:2:2d::n_dofs: 3056 +DEAL:2:2d::n_locally_owned_dofs: 954 +DEAL:2:2d::n_locally_owned_dofs_per_processor: 1011 1091 954 sum: 3056 +DEAL:2:3d::n_dofs: 13282 +DEAL:2:3d::n_locally_owned_dofs: 4476 +DEAL:2:3d::n_locally_owned_dofs_per_processor: 4484 4322 4476 sum: 13282 +DEAL:2:3d::n_dofs: 41826 +DEAL:2:3d::n_locally_owned_dofs: 13978 +DEAL:2:3d::n_locally_owned_dofs_per_processor: 13898 13950 13978 sum: 41826 + diff --git a/tests/sharedtria/dof_04.cc b/tests/sharedtria/dof_04.cc new file mode 100644 index 0000000000..1965b72001 --- /dev/null +++ b/tests/sharedtria/dof_04.cc @@ -0,0 +1,152 @@ +// --------------------------------------------------------------------- +// $Id: dof_handler_number_cache.cc 31761 2013-11-22 14:42:37Z heister $ +// +// Copyright (C) 2008 - 2013, 2015 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. +// +// --------------------------------------------------------------------- + + + +// check number cache for shared_tria with artifical cells and renumbering + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +template +void test() +{ + parallel::shared::Triangulation + triangulation (MPI_COMM_WORLD, + Triangulation::none, + /*artificial*/true); + + FESystem fe (FE_Q(3),2, + FE_DGQ(1),1); + + DoFHandler dof_handler (triangulation); + + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global (2); + + const unsigned int n_refinements[] = { 0, 4, 3, 2 }; + for (unsigned int i=0; i flags (triangulation.n_active_cells(), false); + for (unsigned int k=0; k::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + if (flags[index]) + cell->set_refine_flag(); + ++index; + } + + Assert (index <= triangulation.n_active_cells(), ExcInternalError()); + + // flag all other cells for coarsening + // (this should ensure that at least + // some of them will actually be + // coarsened) + index=0; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell) + { + if (!flags[index]) + cell->set_coarsen_flag(); + ++index; + } + + triangulation.execute_coarsening_and_refinement (); + dof_handler.distribute_dofs (fe); + DoFRenumbering::component_wise(dof_handler); + + deallog + << "n_dofs: " << dof_handler.n_dofs() << std::endl + << "n_locally_owned_dofs: " << dof_handler.n_locally_owned_dofs() << std::endl; + + deallog << "n_locally_owned_dofs_per_processor: "; + std::vector v = dof_handler.n_locally_owned_dofs_per_processor(); + unsigned int sum = 0; + for (unsigned int i=0; i(); + deallog.pop(); + + deallog.push("3d"); + test<3>(); + deallog.pop(); +} diff --git a/tests/sharedtria/dof_04.with_metis=true.with_64bit_indices=off.mpirun=3.output b/tests/sharedtria/dof_04.with_metis=true.with_64bit_indices=off.mpirun=3.output new file mode 100644 index 0000000000..40e7378f11 --- /dev/null +++ b/tests/sharedtria/dof_04.with_metis=true.with_64bit_indices=off.mpirun=3.output @@ -0,0 +1,50 @@ + +DEAL:0:2d::n_dofs: 818 +DEAL:0:2d::n_locally_owned_dofs: 289 +DEAL:0:2d::n_locally_owned_dofs_per_processor: 289 297 232 sum: 818 +DEAL:0:2d::n_dofs: 1754 +DEAL:0:2d::n_locally_owned_dofs: 578 +DEAL:0:2d::n_locally_owned_dofs_per_processor: 578 588 588 sum: 1754 +DEAL:0:2d::n_dofs: 3056 +DEAL:0:2d::n_locally_owned_dofs: 1023 +DEAL:0:2d::n_locally_owned_dofs_per_processor: 1023 1013 1020 sum: 3056 +DEAL:0:3d::n_dofs: 13282 +DEAL:0:3d::n_locally_owned_dofs: 4446 +DEAL:0:3d::n_locally_owned_dofs_per_processor: 4446 4386 4450 sum: 13282 +DEAL:0:3d::n_dofs: 41826 +DEAL:0:3d::n_locally_owned_dofs: 13862 +DEAL:0:3d::n_locally_owned_dofs_per_processor: 13862 14131 13833 sum: 41826 + +DEAL:1:2d::n_dofs: 818 +DEAL:1:2d::n_locally_owned_dofs: 297 +DEAL:1:2d::n_locally_owned_dofs_per_processor: 289 297 232 sum: 818 +DEAL:1:2d::n_dofs: 1754 +DEAL:1:2d::n_locally_owned_dofs: 588 +DEAL:1:2d::n_locally_owned_dofs_per_processor: 578 588 588 sum: 1754 +DEAL:1:2d::n_dofs: 3056 +DEAL:1:2d::n_locally_owned_dofs: 1013 +DEAL:1:2d::n_locally_owned_dofs_per_processor: 1023 1013 1020 sum: 3056 +DEAL:1:3d::n_dofs: 13282 +DEAL:1:3d::n_locally_owned_dofs: 4386 +DEAL:1:3d::n_locally_owned_dofs_per_processor: 4446 4386 4450 sum: 13282 +DEAL:1:3d::n_dofs: 41826 +DEAL:1:3d::n_locally_owned_dofs: 14131 +DEAL:1:3d::n_locally_owned_dofs_per_processor: 13862 14131 13833 sum: 41826 + + +DEAL:2:2d::n_dofs: 818 +DEAL:2:2d::n_locally_owned_dofs: 232 +DEAL:2:2d::n_locally_owned_dofs_per_processor: 289 297 232 sum: 818 +DEAL:2:2d::n_dofs: 1754 +DEAL:2:2d::n_locally_owned_dofs: 588 +DEAL:2:2d::n_locally_owned_dofs_per_processor: 578 588 588 sum: 1754 +DEAL:2:2d::n_dofs: 3056 +DEAL:2:2d::n_locally_owned_dofs: 1020 +DEAL:2:2d::n_locally_owned_dofs_per_processor: 1023 1013 1020 sum: 3056 +DEAL:2:3d::n_dofs: 13282 +DEAL:2:3d::n_locally_owned_dofs: 4450 +DEAL:2:3d::n_locally_owned_dofs_per_processor: 4446 4386 4450 sum: 13282 +DEAL:2:3d::n_dofs: 41826 +DEAL:2:3d::n_locally_owned_dofs: 13833 +DEAL:2:3d::n_locally_owned_dofs_per_processor: 13862 14131 13833 sum: 41826 + diff --git a/tests/sharedtria/tria_02.cc b/tests/sharedtria/tria_02.cc new file mode 100644 index 0000000000..16352122c3 --- /dev/null +++ b/tests/sharedtria/tria_02.cc @@ -0,0 +1,115 @@ +// --------------------------------------------------------------------- +// $Id: 3d_refinement_01.cc 31349 2013-10-20 19:07:06Z maier $ +// +// Copyright (C) 2008 - 2013, 2015 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. +// +// --------------------------------------------------------------------- + + +// create a shared tria mesh with artificial cells and refine it + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +template +void write_mesh (const parallel::shared::Triangulation &tria, + const char *filename_) +{ + DataOut data_out; + data_out.attach_triangulation (tria); + Vector subdomain (tria.n_active_cells()); + typename parallel::shared::Triangulation::active_cell_iterator it=tria.begin_active(); + for (unsigned int i=0; it!=tria.end(); ++it,++i) + subdomain(i) = it->subdomain_id(); + + data_out.add_data_vector (subdomain, "subdomain"); + + data_out.build_patches (); + const std::string filename = (filename_ + + Utilities::int_to_string + (tria.locally_owned_subdomain(), 4)); + { + std::ofstream output ((filename + ".vtu").c_str()); + data_out.write_vtu (output); + } +} + + + +template +void test() +{ + parallel::shared::Triangulation tr(MPI_COMM_WORLD, + Triangulation::none, + /*artificial*/true); + + + GridGenerator::hyper_cube(tr); + tr.refine_global(); + tr.begin_active()->set_refine_flag(); + tr.execute_coarsening_and_refinement (); + tr.begin_active()->set_refine_flag(); + tr.execute_coarsening_and_refinement (); + + deallog + << " locally_owned_subdomain(): " << tr.locally_owned_subdomain() << "\n" + << " n_active_cells: " << tr.n_active_cells() << "\n" + << " n_levels: " << tr.n_levels() << "\n" + << " n_global_levels: " << tr.n_global_levels() << "\n" + //<< " n_locally_owned_active_cells: " << tr.n_locally_owned_active_cells() << "\n" + //<< " n_global_active_cells: " << tr.n_global_active_cells() << "\n" + << std::endl; + + /*deallog << "n_locally_owned_active_cells_per_processor: "; + std::vector v = tr.n_locally_owned_active_cells_per_processor(); + for (unsigned int i=0;i::active_cell_iterator it=tr.begin_active(); + for (; it!=tr.end(); ++it) + { + deallog << (int) it->subdomain_id() << " "; + } + deallog << std::endl; + + const std::string filename = ("mesh_" + + Utilities::int_to_string(dim)+ + "D_"); + write_mesh(tr, filename.c_str()); +} + + +int main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll all; + + deallog.push("2d"); + test<2>(); + deallog.pop(); + deallog.push("3d"); + test<3>(); + deallog.pop(); +} diff --git a/tests/sharedtria/tria_02.with_metis=true.with_64bit_indices=off.mpirun=3.output b/tests/sharedtria/tria_02.with_metis=true.with_64bit_indices=off.mpirun=3.output new file mode 100644 index 0000000000..027bf51dc5 --- /dev/null +++ b/tests/sharedtria/tria_02.with_metis=true.with_64bit_indices=off.mpirun=3.output @@ -0,0 +1,41 @@ + +DEAL:0:2d:: locally_owned_subdomain(): 0 + n_active_cells: 10 + n_levels: 3 + n_global_levels: 3 + +DEAL:0:2d::subdomains: 1 1 0 0 0 0 2 -2 1 -2 +DEAL:0:3d:: locally_owned_subdomain(): 0 + n_active_cells: 22 + n_levels: 3 + n_global_levels: 3 + +DEAL:0:3d::subdomains: 2 0 2 0 2 0 -2 1 -2 2 -2 1 -2 2 1 1 1 0 1 0 0 0 + +DEAL:1:2d:: locally_owned_subdomain(): 1 + n_active_cells: 10 + n_levels: 3 + n_global_levels: 3 + +DEAL:1:2d::subdomains: 1 1 -2 0 0 0 2 2 1 2 +DEAL:1:3d:: locally_owned_subdomain(): 1 + n_active_cells: 22 + n_levels: 3 + n_global_levels: 3 + +DEAL:1:3d::subdomains: 2 0 2 0 -2 -2 1 1 2 2 2 1 2 2 1 1 1 0 1 0 0 0 + + +DEAL:2:2d:: locally_owned_subdomain(): 2 + n_active_cells: 10 + n_levels: 3 + n_global_levels: 3 + +DEAL:2:2d::subdomains: -2 1 -2 0 -2 0 2 2 1 2 +DEAL:2:3d:: locally_owned_subdomain(): 2 + n_active_cells: 22 + n_levels: 3 + n_global_levels: 3 + +DEAL:2:3d::subdomains: 2 0 2 0 2 0 1 1 2 2 2 1 2 2 1 -2 1 -2 1 -2 0 -2 +