<commit_before>#ifndef BART_SRC_TEST_HELPERS_MPI_TEST_FIXTURE_H_
#define BART_SRC_TEST_HELPERS_MPI_TEST_FIXTURE_H_

#include <deal.II/base/mpi.h>
#include <deal.II/dofs/dof_tools.h>
#include <deal.II/dofs/dof_handler.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_tools.h>
#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/petsc_parallel_sparse_matrix.h>

namespace bart {

namespace testing {

template <int dim>
 class MPI_TestFixture {
  protected:
   MPI_TestFixture()
   : triangulation_(MPI_COMM_WORLD,
                    typename dealii::Triangulation<2>::MeshSmoothing(
                        dealii::Triangulation<2>::smoothing_on_refinement |
                            dealii::Triangulation<2>::smoothing_on_coarsening)),
     dof_handler_(triangulation_),
     fe_(1) {};

   void SetUpDealii();

   using Cell = typename dealii::DoFHandler<dim>::active_cell_iterator;
   dealii::ConstraintMatrix constraint_matrix_;
   dealii::parallel::distributed::Triangulation<dim> triangulation_;
   dealii::DoFHandler<dim> dof_handler_;
   dealii::FE_Q<dim> fe_;
   dealii::IndexSet locally_relevant_dofs;
   dealii::IndexSet locally_owned_dofs_;
   std::vector<Cell> cells_;

   dealii::PETScWrappers::MPI::SparseMatrix matrix_1, matrix_2, matrix_3;
};

template <int dim>
inline void MPI_TestFixture<dim>::SetUpDealii() {
  dealii::GridGenerator::hyper_cube(triangulation_, 0, 1);
  dof_handler_.distribute_dofs(fe_);
  dealii::DoFTools::extract_locally_relevant_dofs(dof_handler_,
                                                  locally_relevant_dofs);
  locally_owned_dofs_ = dof_handler_.locally_owned_dofs();

  for (auto cell = dof_handler_.begin_active(); cell != dof_handler_.end(); ++ cell) {
    if (cell->is_locally_owned())
      cells_.push_back(cell);
  }

  constraint_matrix_.clear();
  constraint_matrix_.reinit(locally_relevant_dofs);
  dealii::DoFTools::make_hanging_node_constraints(dof_handler_,
                                                  constraint_matrix_);
  constraint_matrix_.close();

  dealii::DynamicSparsityPattern dsp(locally_relevant_dofs);
  dealii::DoFTools::make_sparsity_pattern(dof_handler_, dsp,
                                          constraint_matrix_, false);
  dealii::SparsityTools::distribute_sparsity_pattern(
      dsp,
      dof_handler_.n_locally_owned_dofs_per_processor(),<commit_msg>added type deduction to MPI_TestFixture so it uses a regular triangulation for 1D<commit_after>#ifndef BART_SRC_TEST_HELPERS_MPI_TEST_FIXTURE_H_
#define BART_SRC_TEST_HELPERS_MPI_TEST_FIXTURE_H_

#include <deal.II/base/mpi.h>
#include <deal.II/dofs/dof_tools.h>
#include <deal.II/dofs/dof_handler.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_tools.h>
#include <deal.II/grid/tria.h>
#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/lac/petsc_parallel_sparse_matrix.h>

namespace bart {

namespace testing {

template <int dim>
struct TriangulationType {
  using type = dealii::parallel::distributed::Triangulation<dim>;
};

template <>
struct TriangulationType<1> {
  using type = dealii::Triangulation<1>;
};

template struct TriangulationType<2>;
template struct TriangulationType<3>;

template <int dim>
 class MPI_TestFixture {
  public:
   MPI_TestFixture();
   void SetUpDealii();

   using Cell = typename dealii::DoFHandler<dim>::active_cell_iterator;
   dealii::ConstraintMatrix constraint_matrix_;
   typename TriangulationType<dim>::type triangulation_;
   dealii::DoFHandler<dim> dof_handler_;
   dealii::FE_Q<dim> fe_;
   dealii::IndexSet locally_relevant_dofs;
   dealii::IndexSet locally_owned_dofs_;
   std::vector<Cell> cells_;

   dealii::PETScWrappers::MPI::SparseMatrix matrix_1, matrix_2, matrix_3;
};

template <int dim>
inline MPI_TestFixture<dim>::MPI_TestFixture()
    : triangulation_(MPI_COMM_WORLD,
                     typename dealii::Triangulation<dim>::MeshSmoothing(
                         dealii::Triangulation<dim>::smoothing_on_refinement |
                             dealii::Triangulation<dim>::smoothing_on_coarsening)),
      dof_handler_(triangulation_),
      fe_(1) {}

template <>
inline MPI_TestFixture<1>::MPI_TestFixture()
    : triangulation_(typename dealii::Triangulation<1>::MeshSmoothing(
    dealii::Triangulation<1>::smoothing_on_refinement |
        dealii::Triangulation<1>::smoothing_on_coarsening)),
      dof_handler_(triangulation_),
      fe_(1) {}

template <int dim>
inline void MPI_TestFixture<dim>::SetUpDealii() {
  dealii::GridGenerator::hyper_cube(triangulation_, 0, 1);
  dof_handler_.distribute_dofs(fe_);
  dealii::DoFTools::extract_locally_relevant_dofs(dof_handler_,
                                                  locally_relevant_dofs);
  locally_owned_dofs_ = dof_handler_.locally_owned_dofs();

  for (auto cell = dof_handler_.begin_active(); cell != dof_handler_.end(); ++ cell) {
    if (cell->is_locally_owned())
      cells_.push_back(cell);
  }

  constraint_matrix_.clear();
  constraint_matrix_.reinit(locally_relevant_dofs);
  dealii::DoFTools::make_hanging_node_constraints(dof_handler_,
                                                  constraint_matrix_);
  constraint_matrix_.close();

  dealii::DynamicSparsityPattern dsp(locally_relevant_dofs);
  dealii::DoFTools::make_sparsity_pattern(dof_handler_, dsp,
                                          constraint_matrix_, false);
  dealii::SparsityTools::distribute_sparsity_pattern(
      dsp,
      dof_handler_.n_locally_owned_dofs_per_processor(),
{'fraction_non_alphanumeric': 0.11089562764456981, 'fraction_numerical': 0.004407616361071932, 'mean_word_length': 4.2772093023255815, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '912183', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1898, 'n_words': 252}