# include <deal.II/base/config.h>
+# include <deal.II/base/point.h>
# include <deal.II/base/subscriptor.h>
# ifdef DEAL_II_WITH_PETSC
*
* @ingroup PETScWrappers
*/
+ template <int dim>
class PreconditionBDDC : public PreconditionBase
{
public:
* Constructor. Note that BDDC offers a lot more options to set
* than what is exposed here.
*/
- AdditionalData(const bool use_vertices = true,
- const bool use_edges = false,
- const bool use_faces = false,
- const bool symmetric = false,
- const unsigned int coords_cdim = 0,
- const types::global_dof_index coords_n = 0,
- const PetscReal * coords_data = nullptr);
+ AdditionalData(const bool use_vertices = true,
+ const bool use_edges = false,
+ const bool use_faces = false,
+ const bool symmetric = false,
+ std::vector<Point<dim>> coords = {});
+
/**
* This flag sets the use of degrees of freedom in the vertices of the
* subdomains as primal variables for the creation of the coarse space.
*/
bool symmetric;
- /**
- * Set the number of coordinates that each DoF has, i.e. 2 in 2D and 3 in
- * 3D.
- */
- unsigned int coords_cdim;
-
- /**
- * Set the number of degrees of freedom that the problem has.
- */
- types::global_dof_index coords_n;
-
/**
* Set the location of each DoF. This helps in improving the definition of
* the vertices for unstructured meshes.
*/
- const PetscReal *coords_data;
+ const std::vector<Point<dim>> coords;
};
/**
} // namespace PETScWrappers
-
DEAL_II_NAMESPACE_CLOSE
# include <deal.II/lac/petsc_matrix_base.h>
# include <deal.II/lac/petsc_vector.h>
-# include <vector>
+# include <petscis.h>
+# include <petscistypes.h>
-# include "petscis.h"
-# include "petscistypes.h"
+# include <vector>
DEAL_II_NAMESPACE_OPEN
// forward declaration
*/
template <typename SparsityPatternType>
void
- reinit_IS(const IndexSet & local_rows,
- const IndexSet & local_active_rows,
- const IndexSet & local_columns,
- const IndexSet & local_active_columns,
- const SparsityPatternType &sparsity_pattern,
- const MPI_Comm & communicator);
+ reinit(const IndexSet & local_rows,
+ const IndexSet & local_active_rows,
+ const IndexSet & local_columns,
+ const IndexSet & local_active_columns,
+ const SparsityPatternType &sparsity_pattern,
+ const MPI_Comm & communicator);
/**
* Return a reference to the MPI communicator object in use with this
*/
template <typename SparsityPatternType>
void
- do_reinit_IS(const IndexSet & local_rows,
- const IndexSet & local_active_rows,
- const IndexSet & local_columns,
- const IndexSet & local_active_columns,
- const SparsityPatternType &sparsity_pattern);
+ do_reinit(const IndexSet & local_rows,
+ const IndexSet & local_active_rows,
+ const IndexSet & local_columns,
+ const IndexSet & local_active_columns,
+ const SparsityPatternType &sparsity_pattern);
// To allow calling protected prepare_add() and prepare_set().
friend class BlockMatrixBase<SparseMatrix>;
template <typename SparsityPatternType>
void
- SparseMatrix::reinit_IS(const IndexSet & local_rows,
- const IndexSet & local_active_rows,
- const IndexSet & local_columns,
- const IndexSet & local_active_columns,
- const SparsityPatternType &sparsity_pattern,
- const MPI_Comm & communicator)
+ SparseMatrix::reinit(const IndexSet & local_rows,
+ const IndexSet & local_active_rows,
+ const IndexSet & local_columns,
+ const IndexSet & local_active_columns,
+ const SparsityPatternType &sparsity_pattern,
+ const MPI_Comm & communicator)
{
this->communicator = communicator;
const PetscErrorCode ierr = destroy_matrix(matrix);
AssertThrow(ierr == 0, ExcPETScError(ierr));
- do_reinit_IS(local_rows,
- local_active_rows,
- local_columns,
- local_active_columns,
- sparsity_pattern);
+ do_reinit(local_rows,
+ local_active_rows,
+ local_columns,
+ local_active_columns,
+ sparsity_pattern);
}
// BDDC
template <typename SparsityPatternType>
void
- SparseMatrix::do_reinit_IS(const IndexSet & local_rows,
- const IndexSet & local_active_rows,
- const IndexSet & local_columns,
- const IndexSet & local_active_columns,
- const SparsityPatternType &sparsity_pattern)
+ SparseMatrix::do_reinit(const IndexSet & local_rows,
+ const IndexSet & local_active_rows,
+ const IndexSet & local_columns,
+ const IndexSet & local_active_columns,
+ const SparsityPatternType &sparsity_pattern)
{
Assert(sparsity_pattern.n_rows() == local_rows.size(),
ExcMessage(
IndexSet::size_type n_local_active_rows = local_active_rows.n_elements();
IndexSet::size_type n_local_active_cols =
local_active_columns.n_elements();
- std::vector<int> idx_glob_row(n_local_active_rows);
- std::vector<int> idx_glob_col(n_local_active_cols);
- unsigned int k;
- for (k = 0; k < n_local_active_rows; ++k)
+ std::vector<PetscInt> idx_glob_row(n_local_active_rows);
+ std::vector<PetscInt> idx_glob_col(n_local_active_cols);
+ for (IndexSet::size_type k = 0; k < n_local_active_rows; ++k)
{
idx_glob_row[k] = local_active_rows.nth_index_in_set(k);
}
- for (k = 0; k < n_local_active_cols; ++k)
+ for (IndexSet::size_type k = 0; k < n_local_active_cols; ++k)
{
idx_glob_col[k] = local_active_columns.nth_index_in_set(k);
}
const DynamicSparsityPattern &);
template void
- SparseMatrix::reinit_IS(const IndexSet &,
+ SparseMatrix::reinit(const IndexSet &,
+ const IndexSet &,
+ const IndexSet &,
+ const IndexSet &,
+ const SparsityPattern &,
+ const MPI_Comm &);
+ template void
+ SparseMatrix::reinit(const IndexSet &,
+ const IndexSet &,
+ const IndexSet &,
+ const IndexSet &,
+ const DynamicSparsityPattern &,
+ const MPI_Comm &);
+
+ template void
+ SparseMatrix::do_reinit(const IndexSet &,
const IndexSet &,
const IndexSet &,
const IndexSet &,
- const SparsityPattern &,
- const MPI_Comm &);
+ const SparsityPattern &);
template void
- SparseMatrix::reinit_IS(const IndexSet &,
+ SparseMatrix::do_reinit(const IndexSet &,
const IndexSet &,
const IndexSet &,
const IndexSet &,
- const DynamicSparsityPattern &,
- const MPI_Comm &);
-
- template void
- SparseMatrix::do_reinit_IS(const IndexSet &,
- const IndexSet &,
- const IndexSet &,
- const IndexSet &,
- const SparsityPattern &);
- template void
- SparseMatrix::do_reinit_IS(const IndexSet &,
- const IndexSet &,
- const IndexSet &,
- const IndexSet &,
- const DynamicSparsityPattern &);
+ const DynamicSparsityPattern &);
# endif
/* ----------------- PreconditionBDDC -------------------- */
- PreconditionBDDC::AdditionalData::AdditionalData(
+ template <int dim>
+ PreconditionBDDC<dim>::AdditionalData::AdditionalData(
const bool use_vertices,
const bool use_edges,
const bool use_faces,
const bool symmetric,
- const unsigned int coords_cdim,
- const types::global_dof_index coords_n,
- const PetscReal * coords_data)
+ const std::vector<Point<dim>> coords)
: use_vertices(use_vertices)
, use_edges(use_edges)
, use_faces(use_faces)
, symmetric(symmetric)
- , coords_cdim(coords_cdim)
- , coords_n(coords_n)
- , coords_data(coords_data)
+ , coords(coords)
{}
- PreconditionBDDC::PreconditionBDDC(const MPI_Comm comm,
- const AdditionalData &additional_data_)
+ template <int dim>
+ PreconditionBDDC<dim>::PreconditionBDDC(
+ const MPI_Comm comm,
+ const AdditionalData &additional_data_)
{
additional_data = additional_data_;
initialize();
}
- PreconditionBDDC::PreconditionBDDC(const MatrixBase & matrix,
- const AdditionalData &additional_data)
+ template <int dim>
+ PreconditionBDDC<dim>::PreconditionBDDC(const MatrixBase & matrix,
+ const AdditionalData &additional_data)
{
initialize(matrix, additional_data);
}
+
+ template <int dim>
void
- PreconditionBDDC::initialize()
+ PreconditionBDDC<dim>::initialize()
{
PetscErrorCode ierr = PCSetType(pc, const_cast<char *>(PCBDDC));
AssertThrow(ierr == 0, ExcPETScError(ierr));
additional_data.coords_data)
{
set_option_value("-pc_bddc_corner_selection", "true");
+ // Convert coords vector to PETSc data array
+ std::vector<PetscReal> coords_petsc(additional_data.coords.size() *
+ dim);
+ for (unsigned int i = 0, j = 0; i < additional_data.coords.size(); ++i)
+ {
+ for (j = 0; j < dim; ++j)
+ coords_petsc[dim * i + j] = additional_data.coords[i][j];
+ }
+
ierr = PCSetCoordinates(pc,
- additional_data.coords_cdim,
- additional_data.coords_n,
- (PetscReal *)additional_data.coords_data);
+ dim,
+ additional_data.coords.size(),
+ coords_petsc.data());
AssertThrow(ierr == 0, ExcPETScError(ierr));
}
else
AssertThrow(ierr == 0, ExcPETScError(ierr));
}
+ template <int dim>
void
- PreconditionBDDC::initialize(const MatrixBase & matrix_,
- const AdditionalData &additional_data_)
+ PreconditionBDDC<dim>::initialize(const MatrixBase & matrix_,
+ const AdditionalData &additional_data_)
{
clear();
{
// get rid of old matrix and generate a
// new one
- const PetscErrorCode ierr = destroy_matrix(matrix);
+ const PetscErrorCode ierr = MatDestroy(&matrix);
AssertThrow(ierr == 0, ExcPETScError(ierr));
do_reinit(m, n, row_lengths, is_symmetric);