Skip to content

Commit

Permalink
Coninue
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrum committed Dec 7, 2021
1 parent cc43200 commit dc00190
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 11 deletions.
4 changes: 4 additions & 0 deletions source/distributed/fully_distributed_tria.cc
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ namespace parallel
this->partitioner_distributed->partition(*this),
this->settings);

this->clear();
this->coarse_cell_id_to_coarse_cell_index_vector.clear();
this->coarse_cell_index_to_coarse_cell_id_vector.clear();

this->create_triangulation(construction_data);

this->signals.post_distributed_repartition();
Expand Down
9 changes: 6 additions & 3 deletions source/grid/tria.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11872,9 +11872,12 @@ Triangulation<dim, spacedim>::create_triangulation(
// boundary ids
for (auto pair : cell_info->boundary_ids)
{
Assert(cell->at_boundary(pair.first),
ExcMessage("Cell face is not on the boundary!"));
cell->face(pair.first)->set_boundary_id(pair.second);
// Assert(cell->at_boundary(pair.first),
// ExcMessage("Cell face is not on the boundary!"));
std::cout << "A" << std::endl;
if (cell->face(pair.first)->at_boundary())
cell->face(pair.first)->set_boundary_id(pair.second);
std::cout << "B" << std::endl;
}
}
}
Expand Down
21 changes: 13 additions & 8 deletions source/grid/tria_description.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ namespace TriangulationDescription
const auto comp = [](const auto &a, const auto &b) {
const double tolerance = 1e-10;

if (a.distance(b) < tolerance)
return false;

for (unsigned int i = 0; i < spacedim; ++i)
if (std::abs(a[i] - b[i]) > tolerance)
return a[i] < b[i];
Expand All @@ -191,15 +188,17 @@ namespace TriangulationDescription
else
map_i[p.first] = map[p.second];

for (auto cell : other.coarse_cells)
auto other_coarse_cells_copy = other.coarse_cells;

for (auto &cell : other_coarse_cells_copy)
{
for (auto &v : cell.vertices)
v = map_i[v];
}

this->coarse_cells.insert(this->coarse_cells.end(),
other.coarse_cells.begin(),
other.coarse_cells.end());
other_coarse_cells_copy.begin(),
other_coarse_cells_copy.end());
}
else
{
Expand Down Expand Up @@ -280,7 +279,13 @@ namespace TriangulationDescription
std::unique(this->coarse_cell_vertices.begin(),
this->coarse_cell_vertices.end(),
[](const auto &a, const auto &b) {
return a.first == b.first;
if (a.first == b.first)
{
Assert(a.second.distance(b.second) < 10e-8,
ExcInternalError());
return true;
}
return false;
}),
this->coarse_cell_vertices.end());
}
Expand Down Expand Up @@ -1083,7 +1088,7 @@ namespace TriangulationDescription
partition.get_mpi_communicator(),
dynamic_cast<
const parallel::fullydistributed::Triangulation<dim, spacedim> *>(
&tria) != nullptr);
&tria) == nullptr);

// remove redundant entries
description_merged.reduce();
Expand Down
153 changes: 153 additions & 0 deletions tests/fullydistributed_grids/repartitioning_08.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// ---------------------------------------------------------------------
//
// 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
// TriangulationDescription::Utilities::create_description_from_triangulation()
// with repartitioning capabilities.

#include <deal.II/base/mpi_consensus_algorithms.h>

#include <deal.II/distributed/fully_distributed_tria.h>
#include <deal.II/distributed/repartitioning_policy_tools.h>
#include <deal.II/distributed/tria.h>

#include <deal.II/fe/fe_q.h>

#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/grid_out.h>
#include <deal.II/grid/grid_tools.h>
#include <deal.II/grid/tria_description.h>

#include <deal.II/lac/la_parallel_vector.h>

#include <deal.II/numerics/data_out.h>

#include "./tests.h"

using namespace dealii;


template <int dim, int spacedim = dim>
class MyPolicy : public RepartitioningPolicyTools::Base<dim, spacedim>
{
public:
MyPolicy(const MPI_Comm &comm, const unsigned int direction)
: comm(comm)
, direction(direction)
{}

virtual LinearAlgebra::distributed::Vector<double>
partition(const Triangulation<dim, spacedim> &tria_in) const override
{
const auto tria =
dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
&tria_in);

Assert(tria, ExcNotImplemented());

LinearAlgebra::distributed::Vector<double> partition(
tria->global_active_cell_index_partitioner().lock());

const unsigned int n_partitions = Utilities::MPI::n_mpi_processes(comm);

for (const auto &cell :
tria_in.active_cell_iterators() | IteratorFilters::LocallyOwnedCell())
partition[cell->global_active_cell_index()] =
std::floor(cell->center()[direction] * n_partitions);

partition.update_ghost_values();

return partition;
}

private:
const MPI_Comm & comm;
const unsigned int direction;
};


template <int dim>
void
test(const MPI_Comm comm)
{
parallel::distributed::Triangulation<dim> tria(
comm,
Triangulation<dim>::none,
parallel::distributed::Triangulation<dim>::construct_multigrid_hierarchy);
GridGenerator::subdivided_hyper_cube(tria, 4);
tria.refine_global(2);

MyPolicy<dim> policy_0(comm, 0);
MyPolicy<dim> policy_1(comm, 1);

const auto partition_0 = policy_0.partition(tria);

const auto settings =
TriangulationDescription::Settings::construct_multigrid_hierarchy;

// repartition triangulation so that it has strided partitioning
const auto construction_data =
TriangulationDescription::Utilities::create_description_from_triangulation(
tria, partition_0, settings);

parallel::fullydistributed::Triangulation<dim> tria_pft(comm);
tria_pft.create_triangulation(construction_data);

{
FE_Q<dim> fe(2);
DoFHandler<dim> dof_handler(tria_pft);
dof_handler.distribute_dofs(fe);
dof_handler.distribute_mg_dofs();

// print statistics
print_statistics(tria_pft);
print_statistics(dof_handler);
}

GridOut go;
go.write_mesh_per_processor_as_vtu(tria_pft, "mesh_old");

tria_pft.set_partitioner(policy_1, settings);

tria_pft.repartition();

go.write_mesh_per_processor_as_vtu(tria_pft, "mesh_new");

{
FE_Q<dim> fe(2);
DoFHandler<dim> dof_handler(tria_pft);
dof_handler.distribute_dofs(fe);
dof_handler.distribute_mg_dofs();

// print statistics
print_statistics(tria_pft);
print_statistics(dof_handler);
}
}



int
main(int argc, char **argv)
{
Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1);
MPILogInitAll all;

MPI_Comm comm = MPI_COMM_WORLD;

test<2>(comm);
deallog.pop();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

DEAL:0::n_levels: 3
DEAL:0::n_cells: 136
DEAL:0::n_active_cells: 104
DEAL:0::
DEAL:0::n_dofs: 1089
DEAL:0::n_locally_owned_dofs: 297
DEAL:0::
DEAL:0::n_levels: 3
DEAL:0::n_cells: 136
DEAL:0::n_active_cells: 104
DEAL:0::
DEAL:0::n_dofs: 1089
DEAL:0::n_locally_owned_dofs: 297
DEAL:0::

DEAL:1::n_levels: 3
DEAL:1::n_cells: 188
DEAL:1::n_active_cells: 144
DEAL:1::
DEAL:1::n_dofs: 1089
DEAL:1::n_locally_owned_dofs: 264
DEAL:1::
DEAL:1::n_levels: 3
DEAL:1::n_cells: 188
DEAL:1::n_active_cells: 144
DEAL:1::
DEAL:1::n_dofs: 1089
DEAL:1::n_locally_owned_dofs: 264
DEAL:1::


DEAL:2::n_levels: 3
DEAL:2::n_cells: 188
DEAL:2::n_active_cells: 144
DEAL:2::
DEAL:2::n_dofs: 1089
DEAL:2::n_locally_owned_dofs: 264
DEAL:2::
DEAL:2::n_levels: 3
DEAL:2::n_cells: 188
DEAL:2::n_active_cells: 144
DEAL:2::
DEAL:2::n_dofs: 1089
DEAL:2::n_locally_owned_dofs: 264
DEAL:2::


DEAL:3::n_levels: 3
DEAL:3::n_cells: 136
DEAL:3::n_active_cells: 104
DEAL:3::
DEAL:3::n_dofs: 1089
DEAL:3::n_locally_owned_dofs: 264
DEAL:3::
DEAL:3::n_levels: 3
DEAL:3::n_cells: 136
DEAL:3::n_active_cells: 104
DEAL:3::
DEAL:3::n_dofs: 1089
DEAL:3::n_locally_owned_dofs: 264
DEAL:3::

0 comments on commit dc00190

Please sign in to comment.