Skip to content

Commit

Permalink
Merge pull request #15784 from peterrum/MGTransferMG
Browse files Browse the repository at this point in the history
Replace MGTransferMG usages in tests/matrix_free
  • Loading branch information
kronbichler committed Jul 25, 2023
2 parents aafd08c + b668d97 commit f803f67
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 592 deletions.
52 changes: 16 additions & 36 deletions tests/matrix_free/multigrid_dg_periodic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <deal.II/multigrid/mg_matrix.h>
#include <deal.II/multigrid/mg_smoother.h>
#include <deal.II/multigrid/mg_tools.h>
#include <deal.II/multigrid/mg_transfer.h>
#include <deal.II/multigrid/mg_transfer_matrix_free.h>
#include <deal.II/multigrid/multigrid.h>

#include <deal.II/numerics/vector_tools.h>
Expand Down Expand Up @@ -165,6 +165,12 @@ class LaplaceOperator : public Subscriptor
return inverse_diagonal_entries;
}

const std::shared_ptr<const Utilities::MPI::Partitioner> &
get_vector_partitioner() const
{
return data.get_vector_partitioner();
}


private:
void
Expand Down Expand Up @@ -493,38 +499,6 @@ class MGCoarseIterative



template <typename LAPLACEOPERATOR>
class MGTransferMF
: public MGTransferPrebuilt<
LinearAlgebra::distributed::Vector<typename LAPLACEOPERATOR::value_type>>
{
public:
MGTransferMF(const MGLevelObject<LAPLACEOPERATOR> &laplace)
: laplace_operator(laplace){};

/**
* Overload copy_to_mg from MGTransferPrebuilt
*/
template <int dim, class InVector, int spacedim>
void
copy_to_mg(const DoFHandler<dim, spacedim> & mg_dof,
MGLevelObject<LinearAlgebra::distributed::Vector<
typename LAPLACEOPERATOR::value_type>> &dst,
const InVector & src) const
{
for (unsigned int level = dst.min_level(); level <= dst.max_level();
++level)
laplace_operator[level].initialize_dof_vector(dst[level]);
MGTransferPrebuilt<LinearAlgebra::distributed::Vector<
typename LAPLACEOPERATOR::value_type>>::copy_to_mg(mg_dof, dst, src);
}

private:
const MGLevelObject<LAPLACEOPERATOR> &laplace_operator;
};



template <int dim, typename number>
void
do_test(const DoFHandler<dim> &dof, const unsigned int n_q_points_1d)
Expand Down Expand Up @@ -581,16 +555,22 @@ do_test(const DoFHandler<dim> &dof, const unsigned int n_q_points_1d)
}
mg_smoother.initialize(mg_matrices, smoother_data);

MGTransferMF<LevelMatrixType> mg_transfer(mg_matrices);
mg_transfer.build(dof);
std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>> partitioners;
for (unsigned int level = mg_matrices.min_level();
level <= mg_matrices.max_level();
++level)
partitioners.push_back(mg_matrices[level].get_vector_partitioner());

MGTransferMatrixFree<dim, double> mg_transfer;
mg_transfer.build(dof, partitioners);

mg::Matrix<LinearAlgebra::distributed::Vector<double>> mg_matrix(mg_matrices);

Multigrid<LinearAlgebra::distributed::Vector<double>> mg(
mg_matrix, mg_coarse, mg_transfer, mg_smoother, mg_smoother);
PreconditionMG<dim,
LinearAlgebra::distributed::Vector<double>,
MGTransferMF<LevelMatrixType>>
MGTransferMatrixFree<dim, double>>
preconditioner(dof, mg, mg_transfer);

{
Expand Down
34 changes: 0 additions & 34 deletions tests/matrix_free/multigrid_dg_sip_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -500,40 +500,6 @@ class MGCoarseIterative



template <int dim, typename LAPLACEOPERATOR>
class MGTransferMF
: public MGTransferMatrixFree<dim, typename LAPLACEOPERATOR::value_type>
{
public:
MGTransferMF(const MGLevelObject<LAPLACEOPERATOR> &laplace,
const MGConstrainedDoFs & mg_constrained_dofs)
: MGTransferMatrixFree<dim, typename LAPLACEOPERATOR::value_type>(
mg_constrained_dofs)
, laplace_operator(laplace){};

/**
* Overload copy_to_mg from MGTransferPrebuilt
*/
template <class InVector, int spacedim>
void
copy_to_mg(const DoFHandler<dim, spacedim> & mg_dof_handler,
MGLevelObject<LinearAlgebra::distributed::Vector<
typename LAPLACEOPERATOR::value_type>> &dst,
const InVector & src) const
{
for (unsigned int level = dst.min_level(); level <= dst.max_level();
++level)
laplace_operator[level].initialize_dof_vector(dst[level]);
MGTransferMatrixFree<dim, typename LAPLACEOPERATOR::value_type>::copy_to_mg(
mg_dof_handler, dst, src);
}

private:
const MGLevelObject<LAPLACEOPERATOR> &laplace_operator;
};



template <int dim, typename number>
void
do_test(const DoFHandler<dim> &dof, const unsigned n_q_points_1d)
Expand Down
53 changes: 15 additions & 38 deletions tests/matrix_free/multigrid_dg_sip_02.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ class LaplaceOperator : public Subscriptor
return inverse_diagonal_entries;
}

const std::shared_ptr<const Utilities::MPI::Partitioner> &
get_vector_partitioner() const
{
return data.get_vector_partitioner();
}


private:
void
Expand Down Expand Up @@ -408,40 +414,6 @@ class MGCoarseIterative



template <int dim, typename LAPLACEOPERATOR>
class MGTransferMF
: public MGTransferMatrixFree<dim, typename LAPLACEOPERATOR::value_type>
{
public:
MGTransferMF(const MGLevelObject<LAPLACEOPERATOR> &laplace,
const MGConstrainedDoFs & mg_constrained_dofs)
: MGTransferMatrixFree<dim, typename LAPLACEOPERATOR::value_type>(
mg_constrained_dofs)
, laplace_operator(laplace){};

/**
* Overload copy_to_mg from MGTransferPrebuilt
*/
template <class InVector, int spacedim>
void
copy_to_mg(const DoFHandler<dim, spacedim> & mg_dof_handler,
MGLevelObject<LinearAlgebra::distributed::Vector<
typename LAPLACEOPERATOR::value_type>> &dst,
const InVector & src) const
{
for (unsigned int level = dst.min_level(); level <= dst.max_level();
++level)
laplace_operator[level].initialize_dof_vector(dst[level]);
MGTransferMatrixFree<dim, typename LAPLACEOPERATOR::value_type>::copy_to_mg(
mg_dof_handler, dst, src);
}

private:
const MGLevelObject<LAPLACEOPERATOR> &laplace_operator;
};



template <int dim, typename number>
void
do_test(const DoFHandler<dim> &dof, const unsigned int n_q_points_1d)
Expand Down Expand Up @@ -503,17 +475,22 @@ do_test(const DoFHandler<dim> &dof, const unsigned int n_q_points_1d)
mg_constrained_dofs.initialize(dof);
mg_constrained_dofs.make_zero_boundary_constraints(dof, {0});

MGTransferMF<dim, LevelMatrixType> mg_transfer(mg_matrices,
mg_constrained_dofs);
mg_transfer.build(dof);
std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>> partitioners;
for (unsigned int level = mg_matrices.min_level();
level <= mg_matrices.max_level();
++level)
partitioners.push_back(mg_matrices[level].get_vector_partitioner());

MGTransferMatrixFree<dim, double> mg_transfer(mg_constrained_dofs);
mg_transfer.build(dof, partitioners);

mg::Matrix<LinearAlgebra::distributed::Vector<double>> mg_matrix(mg_matrices);

Multigrid<LinearAlgebra::distributed::Vector<double>> mg(
mg_matrix, mg_coarse, mg_transfer, mg_smoother, mg_smoother);
PreconditionMG<dim,
LinearAlgebra::distributed::Vector<double>,
MGTransferMF<dim, LevelMatrixType>>
MGTransferMatrixFree<dim, double>>
preconditioner(dof, mg, mg_transfer);

{
Expand Down
51 changes: 16 additions & 35 deletions tests/matrix_free/parallel_multigrid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <deal.II/multigrid/mg_matrix.h>
#include <deal.II/multigrid/mg_smoother.h>
#include <deal.II/multigrid/mg_tools.h>
#include <deal.II/multigrid/mg_transfer.h>
#include <deal.II/multigrid/mg_transfer_matrix_free.h>
#include <deal.II/multigrid/multigrid.h>

#include <deal.II/numerics/vector_tools.h>
Expand Down Expand Up @@ -196,6 +196,12 @@ class LaplaceOperator : public Subscriptor
return inverse_diagonal_entries;
}

const std::shared_ptr<const Utilities::MPI::Partitioner> &
get_vector_partitioner() const
{
return data.get_vector_partitioner();
}


private:
void
Expand Down Expand Up @@ -274,37 +280,6 @@ class LaplaceOperator : public Subscriptor



template <typename MatrixType>
class MGTransferPrebuiltMF
: public MGTransferPrebuilt<LinearAlgebra::distributed::Vector<double>>
{
public:
MGTransferPrebuiltMF(const MGLevelObject<MatrixType> &laplace)
: laplace_operator(laplace){};

/**
* Overload copy_to_mg from MGTransferPrebuilt to get the vectors compatible
* with MatrixFree and bypass the crude initialization in MGTransferPrebuilt
*/
template <int dim, class InVector, int spacedim>
void
copy_to_mg(const DoFHandler<dim, spacedim> & mg_dof,
MGLevelObject<LinearAlgebra::distributed::Vector<double>> &dst,
const InVector &src) const
{
for (unsigned int level = dst.min_level(); level <= dst.max_level();
++level)
laplace_operator[level].initialize_dof_vector(dst[level]);
MGTransferPrebuilt<LinearAlgebra::distributed::Vector<double>>::copy_to_mg(
mg_dof, dst, src);
}

private:
const MGLevelObject<MatrixType> &laplace_operator;
};



template <typename MatrixType, typename Number>
class MGCoarseIterative
: public MGCoarseGridBase<LinearAlgebra::distributed::Vector<Number>>
Expand Down Expand Up @@ -375,8 +350,14 @@ do_test(const DoFHandler<dim> &dof)
mg_matrices[level].initialize(mapping, dof, dirichlet_boundaries, level);
}

MGTransferPrebuiltMF<LevelMatrixType> mg_transfer(mg_matrices);
mg_transfer.build(dof);
std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>> partitioners;
for (unsigned int level = mg_matrices.min_level();
level <= mg_matrices.max_level();
++level)
partitioners.push_back(mg_matrices[level].get_vector_partitioner());

MGTransferMatrixFree<dim, double> mg_transfer;
mg_transfer.build(dof, partitioners);

MGCoarseIterative<LevelMatrixType, number> mg_coarse;
mg_coarse.initialize(mg_matrices[0]);
Expand Down Expand Up @@ -411,7 +392,7 @@ do_test(const DoFHandler<dim> &dof)
mg_matrix, mg_coarse, mg_transfer, mg_smoother, mg_smoother);
PreconditionMG<dim,
LinearAlgebra::distributed::Vector<double>,
MGTransferPrebuiltMF<LevelMatrixType>>
MGTransferMatrixFree<dim, double>>
preconditioner(dof, mg, mg_transfer);

{
Expand Down
56 changes: 16 additions & 40 deletions tests/matrix_free/parallel_multigrid_adaptive_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#include <deal.II/multigrid/mg_matrix.h>
#include <deal.II/multigrid/mg_smoother.h>
#include <deal.II/multigrid/mg_tools.h>
#include <deal.II/multigrid/mg_transfer.h>
#include <deal.II/multigrid/mg_transfer_matrix_free.h>
#include <deal.II/multigrid/multigrid.h>

#include <deal.II/numerics/vector_tools.h>
Expand Down Expand Up @@ -304,6 +304,12 @@ class LaplaceOperator : public Subscriptor
return inverse_diagonal_entries;
}

const std::shared_ptr<const Utilities::MPI::Partitioner> &
get_vector_partitioner() const
{
return data.get_vector_partitioner();
}


private:
void
Expand Down Expand Up @@ -426,42 +432,6 @@ class MGInterfaceMatrix : public Subscriptor



template <typename LAPLACEOPERATOR>
class MGTransferMF
: public MGTransferPrebuilt<LinearAlgebra::distributed::Vector<double>>
{
public:
MGTransferMF(const MGLevelObject<LAPLACEOPERATOR> &laplace,
const MGConstrainedDoFs & mg_constrained_dofs)
: MGTransferPrebuilt<LinearAlgebra::distributed::Vector<double>>(
mg_constrained_dofs)
, laplace_operator(laplace)
{}

/**
* Overload copy_to_mg from MGTransferPrebuilt to get the vectors compatible
* with MatrixFree and bypass the crude vector initialization in
* MGTransferPrebuilt
*/
template <int dim, class InVector, int spacedim>
void
copy_to_mg(const DoFHandler<dim, spacedim> &mg_dof_handler,
MGLevelObject<LinearAlgebra::distributed::Vector<double>> &dst,
const InVector &src) const
{
for (unsigned int level = dst.min_level(); level <= dst.max_level();
++level)
laplace_operator[level].initialize_dof_vector(dst[level]);
MGTransferPrebuilt<LinearAlgebra::distributed::Vector<double>>::copy_to_mg(
mg_dof_handler, dst, src);
}

private:
const MGLevelObject<LAPLACEOPERATOR> &laplace_operator;
};



template <typename MatrixType, typename Number>
class MGCoarseIterative
: public MGCoarseGridBase<LinearAlgebra::distributed::Vector<Number>>
Expand Down Expand Up @@ -560,8 +530,14 @@ do_test(const DoFHandler<dim> &dof)
++level)
mg_interface_matrices[level].initialize(mg_matrices[level]);

MGTransferMF<LevelMatrixType> mg_transfer(mg_matrices, mg_constrained_dofs);
mg_transfer.build(dof);
std::vector<std::shared_ptr<const Utilities::MPI::Partitioner>> partitioners;
for (unsigned int level = mg_matrices.min_level();
level <= mg_matrices.max_level();
++level)
partitioners.push_back(mg_matrices[level].get_vector_partitioner());

MGTransferMatrixFree<dim, double> mg_transfer(mg_constrained_dofs);
mg_transfer.build(dof, partitioners);

MGCoarseIterative<LevelMatrixType, number> mg_coarse;
mg_coarse.initialize(mg_matrices[0]);
Expand Down Expand Up @@ -599,7 +575,7 @@ do_test(const DoFHandler<dim> &dof)
mg.set_edge_matrices(mg_interface, mg_interface);
PreconditionMG<dim,
LinearAlgebra::distributed::Vector<double>,
MGTransferMF<LevelMatrixType>>
MGTransferMatrixFree<dim, double>>
preconditioner(dof, mg, mg_transfer);

{
Expand Down

0 comments on commit f803f67

Please sign in to comment.