From: Daniel Arndt Date: Sat, 10 Feb 2018 16:01:45 +0000 (+0100) Subject: Use make_unique/shared in lac X-Git-Tag: v9.0.0-rc1~425^2~8 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f45466e00f78f0ca3004e3d85d93c4355f20c735;p=dealii.git Use make_unique/shared in lac --- diff --git a/include/deal.II/lac/chunk_sparse_matrix.templates.h b/include/deal.II/lac/chunk_sparse_matrix.templates.h index e10ed1afc0..2ae00343c0 100644 --- a/include/deal.II/lac/chunk_sparse_matrix.templates.h +++ b/include/deal.II/lac/chunk_sparse_matrix.templates.h @@ -463,7 +463,7 @@ ChunkSparseMatrix::reinit (const ChunkSparsityPattern &sparsity) chunk_size * chunk_size; if (N > max_len || max_len == 0) { - val.reset (new number[N]); + val = std_cxx14::make_unique(N); max_len = N; } @@ -1615,7 +1615,7 @@ ChunkSparseMatrix::block_read (std::istream &in) AssertThrow (c == '[', ExcIO()); // reallocate space - val.reset (new number[max_len]); + val = std_cxx14::make_unique(max_len); // then read data in.read (reinterpret_cast(val.get()), diff --git a/include/deal.II/lac/la_parallel_vector.templates.h b/include/deal.II/lac/la_parallel_vector.templates.h index ea7369deee..04e95f50f6 100644 --- a/include/deal.II/lac/la_parallel_vector.templates.h +++ b/include/deal.II/lac/la_parallel_vector.templates.h @@ -18,6 +18,7 @@ #include +#include #include #include #include @@ -76,7 +77,7 @@ namespace LinearAlgebra values.reset(); allocated_size = 0; } - thread_loop_partitioner.reset(new ::dealii::parallel::internal::TBBPartitioner()); + thread_loop_partitioner = std::make_shared<::dealii::parallel::internal::TBBPartitioner>(); } @@ -95,7 +96,7 @@ namespace LinearAlgebra import_data.reset (); // set partitioner to serial version - partitioner.reset (new Utilities::MPI::Partitioner (size)); + partitioner = std::make_shared (size); // set entries to zero if so requested if (omit_zeroing_entries == false) @@ -540,7 +541,7 @@ namespace LinearAlgebra // allocate import_data in case it is not set up yet if (import_data == nullptr && partitioner->n_import_indices() > 0) - import_data.reset (new Number[partitioner->n_import_indices()]); + import_data = std_cxx14::make_unique(partitioner->n_import_indices()); partitioner->import_from_ghosted_array_start (operation, counter, @@ -595,7 +596,7 @@ namespace LinearAlgebra // allocate import_data in case it is not set up yet if (import_data == nullptr && partitioner->n_import_indices() > 0) - import_data.reset (new Number[partitioner->n_import_indices()]); + import_data = std_cxx14::make_unique(partitioner->n_import_indices()); partitioner->export_to_ghosted_array_start (counter, @@ -654,9 +655,8 @@ namespace LinearAlgebra ghost_indices.subtract_set(locally_owned_elem); IndexSet local_indices(V.get_stored_elements()); local_indices.subtract_set(ghost_indices); - comm_pattern.reset(new Utilities::MPI::Partitioner(local_indices, - ghost_indices, - get_mpi_communicator())); + comm_pattern = std::make_shared + (local_indices, ghost_indices, get_mpi_communicator()); } else { diff --git a/include/deal.II/lac/lapack_full_matrix.h b/include/deal.II/lac/lapack_full_matrix.h index a629d5d9a3..f837d6d49c 100644 --- a/include/deal.II/lac/lapack_full_matrix.h +++ b/include/deal.II/lac/lapack_full_matrix.h @@ -834,13 +834,13 @@ private: * The matrix U in the singular value decomposition * USVT. */ - std::shared_ptr > svd_u; + std::unique_ptr > svd_u; /** * The matrix VT in the singular value decomposition * USVT. */ - std::shared_ptr > svd_vt; + std::unique_ptr > svd_vt; /** * Thread mutex. diff --git a/include/deal.II/lac/petsc_solver.h b/include/deal.II/lac/petsc_solver.h index 7f17f92f58..edf0319fd3 100644 --- a/include/deal.II/lac/petsc_solver.h +++ b/include/deal.II/lac/petsc_solver.h @@ -240,7 +240,7 @@ namespace PETScWrappers * Pointer to an object that stores the solver context. This is recreated * in the main solver routine if necessary. */ - std::shared_ptr solver_data; + std::unique_ptr solver_data; #ifdef DEAL_II_WITH_SLEPC /** @@ -984,7 +984,7 @@ namespace PETScWrappers PC pc; }; - std::shared_ptr solver_data; + std::unique_ptr solver_data; /** * Flag specifies whether matrix being factorized is symmetric or not. It diff --git a/include/deal.II/lac/precondition.h b/include/deal.II/lac/precondition.h index be3d2e73db..b16962f794 100644 --- a/include/deal.II/lac/precondition.h +++ b/include/deal.II/lac/precondition.h @@ -1878,7 +1878,7 @@ namespace internal preconditioner->m() != matrix.m()) { if (preconditioner.get() == nullptr) - preconditioner.reset(new DiagonalMatrix()); + preconditioner = std::make_shared>(); Assert(preconditioner->m() == 0, ExcMessage("Preconditioner appears to be initialized but not sized correctly")); diff --git a/include/deal.II/lac/read_write_vector.templates.h b/include/deal.II/lac/read_write_vector.templates.h index 0f27e74517..3681e45644 100644 --- a/include/deal.II/lac/read_write_vector.templates.h +++ b/include/deal.II/lac/read_write_vector.templates.h @@ -57,7 +57,7 @@ namespace LinearAlgebra if (val != nullptr) free(val); val = nullptr; - thread_loop_partitioner.reset(new parallel::internal::TBBPartitioner()); + thread_loop_partitioner = std::make_shared(); } else { @@ -66,7 +66,7 @@ namespace LinearAlgebra Utilities::System::posix_memalign ((void **)&val, 64, sizeof(Number)*new_alloc_size); if (new_alloc_size >= 4*dealii::internal::Vector::minimum_parallel_grain_size) - thread_loop_partitioner.reset(new parallel::internal::TBBPartitioner()); + thread_loop_partitioner = std::make_shared(); } } @@ -241,9 +241,10 @@ namespace LinearAlgebra std::shared_ptr comm_pattern; if (communication_pattern.get() == nullptr) { - comm_pattern.reset(new Utilities::MPI::Partitioner(vec.locally_owned_elements(), - get_stored_elements(), - vec.get_mpi_communicator())); + comm_pattern = std::make_shared + (vec.locally_owned_elements(), + get_stored_elements(), + vec.get_mpi_communicator()); } else { @@ -524,8 +525,8 @@ namespace LinearAlgebra source_stored_elements = source_index_set; EpetraWrappers::CommunicationPattern epetra_comm_pattern( source_stored_elements, stored_elements, mpi_comm); - comm_pattern.reset(new EpetraWrappers::CommunicationPattern( - source_stored_elements, stored_elements, mpi_comm)); + comm_pattern = std::make_shared + (source_stored_elements, stored_elements, mpi_comm); return epetra_comm_pattern; } diff --git a/include/deal.II/lac/sparse_matrix.templates.h b/include/deal.II/lac/sparse_matrix.templates.h index 1d3ebf7c86..065d93e8bf 100644 --- a/include/deal.II/lac/sparse_matrix.templates.h +++ b/include/deal.II/lac/sparse_matrix.templates.h @@ -253,7 +253,7 @@ SparseMatrix::reinit (const SparsityPattern &sparsity) const std::size_t N = cols->n_nonzero_elements(); if (N > max_len || max_len == 0) { - val.reset (new number[N]); + val = std_cxx14::make_unique(N); max_len = N; } @@ -1982,7 +1982,7 @@ SparseMatrix::block_read (std::istream &in) AssertThrow (c == '[', ExcIO()); // reallocate space - val.reset (new number[max_len]); + val = std_cxx14::make_unique (max_len); // then read data in.read (reinterpret_cast(val.get()), diff --git a/include/deal.II/lac/sparsity_pattern.h b/include/deal.II/lac/sparsity_pattern.h index d5258bf0b1..362706e5cf 100644 --- a/include/deal.II/lac/sparsity_pattern.h +++ b/include/deal.II/lac/sparsity_pattern.h @@ -19,6 +19,7 @@ #include #include +#include #include // boost::serialization::make_array used to be in array.hpp, but was @@ -31,7 +32,6 @@ #endif #include -#include #include #include #include @@ -1442,8 +1442,8 @@ SparsityPattern::load (Archive &ar, const unsigned int) ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed &store_diagonal_first_in_row; - rowstart.reset (new std::size_t[max_dim + 1]); - colnums.reset (new size_type[max_vec_len]); + rowstart = std_cxx14::make_unique(max_dim + 1); + colnums = std_cxx14::make_unique(max_vec_len); ar &boost::serialization::make_array(rowstart.get(), max_dim + 1); ar &boost::serialization::make_array(colnums.get(), max_vec_len); diff --git a/include/deal.II/lac/trilinos_epetra_communication_pattern.h b/include/deal.II/lac/trilinos_epetra_communication_pattern.h index 64695e3116..943df6d0ae 100644 --- a/include/deal.II/lac/trilinos_epetra_communication_pattern.h +++ b/include/deal.II/lac/trilinos_epetra_communication_pattern.h @@ -78,7 +78,7 @@ namespace LinearAlgebra /** * Shared pointer to the Epetra_Import object used. */ - std::shared_ptr import; + std::unique_ptr import; }; } // end of namespace EpetraWrappers } // end of namespace LinearAlgebra diff --git a/include/deal.II/lac/trilinos_epetra_vector.h b/include/deal.II/lac/trilinos_epetra_vector.h index e0389cea35..db1fcab2ed 100644 --- a/include/deal.II/lac/trilinos_epetra_vector.h +++ b/include/deal.II/lac/trilinos_epetra_vector.h @@ -323,7 +323,7 @@ namespace LinearAlgebra /** * Pointer to the actual Epetra vector object. */ - std::shared_ptr vector; + std::unique_ptr vector; /** * IndexSet of the elements of the last imported vector. diff --git a/include/deal.II/lac/trilinos_solver.h b/include/deal.II/lac/trilinos_solver.h index 3701b06aa9..83581ecd15 100644 --- a/include/deal.II/lac/trilinos_solver.h +++ b/include/deal.II/lac/trilinos_solver.h @@ -321,13 +321,13 @@ namespace TrilinosWrappers * side vector and the solution vector, which is passed down to the * Trilinos solver. */ - std::shared_ptr linear_problem; + std::unique_ptr linear_problem; /** * A structure that contains a Trilinos object that can query the linear * solver and determine whether the convergence criterion have been met. */ - std::shared_ptr status_test; + std::unique_ptr status_test; /** * A structure that contains the Trilinos solver and preconditioner @@ -719,13 +719,13 @@ namespace TrilinosWrappers * side vector and the solution vector, which is passed down to the * Trilinos solver. */ - std::shared_ptr linear_problem; + std::unique_ptr linear_problem; /** * A structure that contains the Trilinos solver and preconditioner * objects. */ - std::shared_ptr solver; + std::unique_ptr solver; /** * Store a copy of the flags for this particular solver. diff --git a/include/deal.II/lac/trilinos_sparse_matrix.h b/include/deal.II/lac/trilinos_sparse_matrix.h index 82ca8b2dfa..6e41ef4752 100644 --- a/include/deal.II/lac/trilinos_sparse_matrix.h +++ b/include/deal.II/lac/trilinos_sparse_matrix.h @@ -36,6 +36,7 @@ # include # include +# include # include # include # include @@ -48,8 +49,6 @@ # include # endif -class Epetra_Export; - DEAL_II_NAMESPACE_OPEN // forward declarations @@ -2008,26 +2007,26 @@ namespace TrilinosWrappers * Pointer to the user-supplied Epetra Trilinos mapping of the matrix * columns that assigns parts of the matrix to the individual processes. */ - std::shared_ptr column_space_map; + std::unique_ptr column_space_map; /** * A sparse matrix object in Trilinos to be used for finite element based * problems which allows for assembling into non-local elements. The * actual type, a sparse matrix, is set in the constructor. */ - std::shared_ptr matrix; + std::unique_ptr matrix; /** * A sparse matrix object in Trilinos to be used for collecting the non- * local elements if the matrix was constructed from a Trilinos sparsity * pattern with the respective option. */ - std::shared_ptr nonlocal_matrix; + std::unique_ptr nonlocal_matrix; /** * An export object used to communicate the nonlocal matrix. */ - std::shared_ptr nonlocal_matrix_exporter; + std::unique_ptr nonlocal_matrix_exporter; /** * Trilinos doesn't allow to mix additions to matrix entries and diff --git a/include/deal.II/lac/trilinos_sparsity_pattern.h b/include/deal.II/lac/trilinos_sparsity_pattern.h index 5c7c852584..bfec6fe149 100644 --- a/include/deal.II/lac/trilinos_sparsity_pattern.h +++ b/include/deal.II/lac/trilinos_sparsity_pattern.h @@ -1164,14 +1164,14 @@ namespace TrilinosWrappers * Pointer to the user-supplied Epetra Trilinos mapping of the matrix * columns that assigns parts of the matrix to the individual processes. */ - std::shared_ptr column_space_map; + std::unique_ptr column_space_map; /** * A sparsity pattern object in Trilinos to be used for finite element * based problems which allows for adding non-local elements to the * pattern. */ - std::shared_ptr graph; + std::unique_ptr graph; /** * A sparsity pattern object for the non-local part of the sparsity @@ -1179,7 +1179,7 @@ namespace TrilinosWrappers * when the particular constructor or reinit method with writable_rows * argument is set */ - std::shared_ptr nonlocal_graph; + std::unique_ptr nonlocal_graph; friend class TrilinosWrappers::SparseMatrix; friend class SparsityPatternIterators::Accessor; diff --git a/include/deal.II/lac/trilinos_vector.h b/include/deal.II/lac/trilinos_vector.h index 7f7ce9ffee..ddbe5f058d 100644 --- a/include/deal.II/lac/trilinos_vector.h +++ b/include/deal.II/lac/trilinos_vector.h @@ -1242,14 +1242,14 @@ namespace TrilinosWrappers * that is in fact distributed among multiple processors. The object * requires an existing Epetra_Map for storing data when setting it up. */ - std::shared_ptr vector; + std::unique_ptr vector; /** * A vector object in Trilinos to be used for collecting the non-local * elements if the vector was constructed with an additional IndexSet * describing ghost elements. */ - std::shared_ptr nonlocal_vector; + std::unique_ptr nonlocal_vector; /** * An IndexSet storing the indices this vector owns exclusively. diff --git a/include/deal.II/lac/vector.h b/include/deal.II/lac/vector.h index 1f90cde46e..755cbc52c9 100644 --- a/include/deal.II/lac/vector.h +++ b/include/deal.II/lac/vector.h @@ -883,7 +883,7 @@ public: /** * Return dimension of the vector. */ - std::size_t size () const; + size_type size () const; /** * Return whether the vector contains only elements with value zero. This @@ -1031,7 +1031,8 @@ Vector::Vector (const size_type n) template inline -std::size_t Vector::size () const +typename Vector::size_type +Vector::size () const { return vec_size; } diff --git a/include/deal.II/lac/vector.templates.h b/include/deal.II/lac/vector.templates.h index dfd1c2c57e..393817135f 100644 --- a/include/deal.II/lac/vector.templates.h +++ b/include/deal.II/lac/vector.templates.h @@ -264,7 +264,7 @@ void Vector::reinit (const size_type n, { values.reset(); max_vec_size = vec_size = 0; - thread_loop_partitioner.reset(new parallel::internal::TBBPartitioner()); + thread_loop_partitioner = std::make_shared(); return; } @@ -281,7 +281,7 @@ void Vector::reinit (const size_type n, // only reset the partitioner if we actually expect a significant vector // size if (vec_size >= 4*internal::Vector::minimum_parallel_grain_size) - thread_loop_partitioner.reset(new parallel::internal::TBBPartitioner()); + thread_loop_partitioner = std::make_shared(); } if (omit_zeroing_entries == false) @@ -298,7 +298,7 @@ void Vector::grow_or_shrink (const size_type n) { values.reset(); max_vec_size = vec_size = 0; - thread_loop_partitioner.reset(new parallel::internal::TBBPartitioner()); + thread_loop_partitioner = std::make_shared(); return; } @@ -316,7 +316,7 @@ void Vector::grow_or_shrink (const size_type n) // only reset the partitioner if we actually expect a significant vector // size if (vec_size >= 4*internal::Vector::minimum_parallel_grain_size) - thread_loop_partitioner.reset(new parallel::internal::TBBPartitioner()); + thread_loop_partitioner = std::make_shared(); } // pad with zeroes diff --git a/source/lac/lapack_full_matrix.cc b/source/lac/lapack_full_matrix.cc index afb761b880..592557b2b5 100644 --- a/source/lac/lapack_full_matrix.cc +++ b/source/lac/lapack_full_matrix.cc @@ -973,8 +973,8 @@ LAPACKFullMatrix::compute_svd() std::fill(wr.begin(), wr.end(), 0.); ipiv.resize(8*mm); - svd_u.reset (new LAPACKFullMatrix(mm,mm)); - svd_vt.reset (new LAPACKFullMatrix(nn,nn)); + svd_u = std_cxx14::make_unique>(mm,mm); + svd_vt = std_cxx14::make_unique>(nn,nn); number *const mu = &svd_u->values[0]; number *const mvt = &svd_vt->values[0]; types::blas_int info = 0; diff --git a/source/lac/petsc_matrix_base.cc b/source/lac/petsc_matrix_base.cc index c0fb61120b..11f5b54f41 100644 --- a/source/lac/petsc_matrix_base.cc +++ b/source/lac/petsc_matrix_base.cc @@ -62,8 +62,8 @@ namespace PETScWrappers // iterator for an empty line (what // would it point to?) Assert (ncols != 0, ExcInternalError()); - colnum_cache.reset (new std::vector (colnums, colnums+ncols)); - value_cache.reset (new std::vector (values, values+ncols)); + colnum_cache = std::make_shared> (colnums, colnums+ncols); + value_cache = std::make_shared> (values, values+ncols); // and finally restore the matrix ierr = MatRestoreRow(*matrix, this->a_row, &ncols, &colnums, &values); diff --git a/source/lac/petsc_solver.cc b/source/lac/petsc_solver.cc index dae6985fac..a6363a9c61 100644 --- a/source/lac/petsc_solver.cc +++ b/source/lac/petsc_solver.cc @@ -15,6 +15,7 @@ #include +#include #include #ifdef DEAL_II_WITH_PETSC @@ -66,7 +67,7 @@ namespace PETScWrappers // is necessary if (solver_data.get() == nullptr) { - solver_data.reset (new SolverData()); + solver_data = std_cxx14::make_unique(); PetscErrorCode ierr = KSPCreate (mpi_communicator, &solver_data->ksp); AssertThrow (ierr == 0, ExcPETScError(ierr)); @@ -202,7 +203,7 @@ namespace PETScWrappers { PetscErrorCode ierr; - solver_data.reset (new SolverData()); + solver_data = std_cxx14::make_unique(); ierr = KSPCreate (mpi_communicator, &solver_data->ksp); AssertThrow (ierr == 0, ExcPETScError(ierr)); @@ -698,7 +699,7 @@ namespace PETScWrappers */ if (solver_data.get() == 0) { - solver_data.reset (new SolverDataMUMPS ()); + solver_data = std_cxx14::make_unique(); /** * creates the default KSP context and puts it in the location diff --git a/source/lac/scalapack.cc b/source/lac/scalapack.cc index 1fbe23f489..f2878a4bb9 100644 --- a/source/lac/scalapack.cc +++ b/source/lac/scalapack.cc @@ -1014,7 +1014,7 @@ void ScaLAPACKMatrix::save_serial(const char *filename, * Create a 1x1 column grid which will be used to initialize * an effectively serial ScaLAPACK matrix to gather the contents from the current object */ - std::shared_ptr column_grid = std::make_shared(this->grid->mpi_communicator,1,1); + const auto column_grid = std::make_shared(this->grid->mpi_communicator,1,1); const int MB=n_rows, NB=n_columns; ScaLAPACKMatrix tmp(n_rows,n_columns,column_grid,MB,NB); @@ -1096,7 +1096,7 @@ void ScaLAPACKMatrix::save_parallel(const char *filename, * * Create a 1xn_processes column grid */ - std::shared_ptr column_grid = std::make_shared(this->grid->mpi_communicator,1,n_mpi_processes); + const auto column_grid = std::make_shared(this->grid->mpi_communicator,1,n_mpi_processes); const int MB=n_rows, NB=std::ceil(n_columns/n_mpi_processes); ScaLAPACKMatrix tmp(n_rows,n_columns,column_grid,MB,NB); @@ -1228,7 +1228,7 @@ void ScaLAPACKMatrix::load_serial(const char *filename) * Therefore, one process has all the data and can write it to a file */ //create a 1xP column grid with P being the number of MPI processes - std::shared_ptr one_grid = std::make_shared(this->grid->mpi_communicator,1,1); + const auto one_grid = std::make_shared(this->grid->mpi_communicator,1,1); const int MB=n_rows, NB=n_columns; ScaLAPACKMatrix tmp(n_rows,n_columns,one_grid,MB,NB); @@ -1313,7 +1313,7 @@ void ScaLAPACKMatrix::load_parallel(const char *filename) * Therefore, the processes hold contiguous chunks of the matrix, which they can write to the file */ //create a 1xP column grid with P being the number of MPI processes - std::shared_ptr column_grid = std::make_shared(this->grid->mpi_communicator,1,n_mpi_processes); + const auto column_grid = std::make_shared(this->grid->mpi_communicator,1,n_mpi_processes); const int MB=n_rows, NB=std::ceil(n_columns/n_mpi_processes); ScaLAPACKMatrix tmp(n_rows,n_columns,column_grid,MB,NB); diff --git a/source/lac/sparsity_pattern.cc b/source/lac/sparsity_pattern.cc index 5eb16da606..57663b5ff2 100644 --- a/source/lac/sparsity_pattern.cc +++ b/source/lac/sparsity_pattern.cc @@ -14,6 +14,7 @@ // --------------------------------------------------------------------- +#include #include #include #include @@ -294,7 +295,7 @@ SparsityPattern::reinit (const size_type m, { vec_len = 1; max_vec_len = vec_len; - colnums.reset (new size_type[max_vec_len]); + colnums = std_cxx14::make_unique (max_vec_len); } max_row_length = (row_lengths.size() == 0 ? @@ -315,14 +316,14 @@ SparsityPattern::reinit (const size_type m, if (rows > max_dim) { max_dim = rows; - rowstart.reset (new std::size_t[max_dim+1]); + rowstart = std_cxx14::make_unique (max_dim+1); } // allocate memory for the column numbers if necessary if (vec_len > max_vec_len) { max_vec_len = vec_len; - colnums.reset (new size_type[max_vec_len]); + colnums = std_cxx14::make_unique (max_vec_len); } // set the rowstart array @@ -974,8 +975,8 @@ SparsityPattern::block_read (std::istream &in) AssertThrow (c == '[', ExcIO()); // reallocate space - rowstart.reset (new std::size_t[max_dim+1]); - colnums.reset (new size_type[max_vec_len]); + rowstart = std_cxx14::make_unique (max_dim+1); + colnums = std_cxx14::make_unique (max_vec_len); // then read data in.read (reinterpret_cast(rowstart.get()), diff --git a/source/lac/trilinos_epetra_communication_pattern.cc b/source/lac/trilinos_epetra_communication_pattern.cc index 86c106cb07..a8bfc261a9 100644 --- a/source/lac/trilinos_epetra_communication_pattern.cc +++ b/source/lac/trilinos_epetra_communication_pattern.cc @@ -13,6 +13,7 @@ // // --------------------------------------------------------------------- +#include #include #ifdef DEAL_II_WITH_TRILINOS @@ -57,7 +58,7 @@ namespace LinearAlgebra // Target map is read_write_vector_map // Source map is vector_space_vector_map. This map must have uniquely // owned GID. - import.reset(new Epetra_Import(read_write_vector_map, vector_space_vector_map)); + import = std_cxx14::make_unique(read_write_vector_map, vector_space_vector_map); } diff --git a/source/lac/trilinos_epetra_vector.cc b/source/lac/trilinos_epetra_vector.cc index 48328fb1a5..be51e77e2f 100644 --- a/source/lac/trilinos_epetra_vector.cc +++ b/source/lac/trilinos_epetra_vector.cc @@ -13,6 +13,7 @@ // // --------------------------------------------------------------------- +#include #include #ifdef DEAL_II_WITH_TRILINOS @@ -22,6 +23,7 @@ #include #include +#include #include @@ -65,7 +67,7 @@ namespace LinearAlgebra { Epetra_Map input_map = parallel_partitioner.make_trilinos_map(communicator,false); if (vector->Map().SameAs(input_map)==false) - vector.reset(new Epetra_FEVector(input_map)); + vector = std_cxx14::make_unique(input_map); else if (omit_zeroing_entries==false) { const int ierr = vector->PutScalar(0.); @@ -110,7 +112,7 @@ namespace LinearAlgebra (void) ierr; } else - vector.reset(new Epetra_FEVector(V.trilinos_vector())); + vector = std_cxx14::make_unique(V.trilinos_vector()); } return *this; @@ -594,8 +596,8 @@ namespace LinearAlgebra const MPI_Comm &mpi_comm) { source_stored_elements = source_index_set; - epetra_comm_pattern.reset(new CommunicationPattern(locally_owned_elements(), - source_index_set, mpi_comm)); + epetra_comm_pattern = std::make_shared + (locally_owned_elements(), source_index_set, mpi_comm); } } } diff --git a/source/lac/trilinos_precondition.cc b/source/lac/trilinos_precondition.cc index ffca23affc..bd8eefe151 100644 --- a/source/lac/trilinos_precondition.cc +++ b/source/lac/trilinos_precondition.cc @@ -671,7 +671,7 @@ namespace TrilinosWrappers const AdditionalData &additional_data) { preconditioner.reset (); - preconditioner.reset (new Ifpack_Chebyshev (&matrix.trilinos_matrix())); + preconditioner = std::make_shared (&matrix.trilinos_matrix()); Ifpack_Chebyshev *ifpack = static_cast (preconditioner.get()); diff --git a/source/lac/trilinos_precondition_ml.cc b/source/lac/trilinos_precondition_ml.cc index f65ed6a18c..2f7b9dd0a9 100644 --- a/source/lac/trilinos_precondition_ml.cc +++ b/source/lac/trilinos_precondition_ml.cc @@ -220,8 +220,8 @@ namespace TrilinosWrappers const Teuchos::ParameterList &ml_parameters) { preconditioner.reset (); - preconditioner.reset (new ML_Epetra::MultiLevelPreconditioner - (matrix, ml_parameters)); + preconditioner = std::make_shared + (matrix, ml_parameters); } @@ -241,11 +241,12 @@ namespace TrilinosWrappers // equidistributed map; avoid // storing the nonzero // elements. - vector_distributor.reset (new Epetra_Map(static_cast(n_rows), - 0, communicator)); + vector_distributor = std::make_shared + (static_cast(n_rows), + 0, communicator); if (trilinos_matrix.get() == nullptr) - trilinos_matrix.reset (new SparseMatrix()); + trilinos_matrix = std::make_shared(); trilinos_matrix->reinit (*vector_distributor, *vector_distributor, deal_ii_sparse_matrix, drop_tolerance, true, diff --git a/source/lac/trilinos_precondition_muelu.cc b/source/lac/trilinos_precondition_muelu.cc index ed5484cb46..a8d05eb3d2 100644 --- a/source/lac/trilinos_precondition_muelu.cc +++ b/source/lac/trilinos_precondition_muelu.cc @@ -230,7 +230,7 @@ namespace TrilinosWrappers // MueLu::EpetraOperator is just a wrapper around a "standard" // Epetra_Operator. - preconditioner.reset(new MueLu::EpetraOperator(hierarchy)); + preconditioner = std::make_shared(hierarchy); } @@ -250,11 +250,12 @@ namespace TrilinosWrappers // equidistributed map; avoid // storing the nonzero // elements. - vector_distributor.reset (new Epetra_Map(static_cast(n_rows), - 0, communicator)); + vector_distributor = std::make_shared + (static_cast(n_rows), + 0, communicator); if (trilinos_matrix.get() == nullptr) - trilinos_matrix.reset (new SparseMatrix()); + trilinos_matrix = std::make_shared(); trilinos_matrix->reinit (*vector_distributor, *vector_distributor, deal_ii_sparse_matrix, drop_tolerance, true, diff --git a/source/lac/trilinos_solver.cc b/source/lac/trilinos_solver.cc index 0c3b7ae206..664f57ec34 100644 --- a/source/lac/trilinos_solver.cc +++ b/source/lac/trilinos_solver.cc @@ -18,6 +18,7 @@ #ifdef DEAL_II_WITH_TRILINOS # include +# include # include # include # include @@ -80,14 +81,12 @@ namespace TrilinosWrappers const MPI::Vector &b, const PreconditionBase &preconditioner) { - linear_problem.reset(); - // We need an Epetra_LinearProblem object to let the AztecOO solver know // about the matrix and vectors. - linear_problem.reset - (new Epetra_LinearProblem(const_cast(&A.trilinos_matrix()), - &x.trilinos_vector(), - const_cast(&b.trilinos_vector()))); + linear_problem = std_cxx14::make_unique + (const_cast(&A.trilinos_matrix()), + &x.trilinos_vector(), + const_cast(&b.trilinos_vector())); do_solve(preconditioner); } @@ -102,14 +101,12 @@ namespace TrilinosWrappers const MPI::Vector &b, const PreconditionBase &preconditioner) { - linear_problem.reset(); - // We need an Epetra_LinearProblem object to let the AztecOO solver know // about the matrix and vectors. - linear_problem.reset - (new Epetra_LinearProblem(const_cast(&A), - &x.trilinos_vector(), - const_cast(&b.trilinos_vector()))); + linear_problem = std_cxx14::make_unique + (const_cast(&A), + &x.trilinos_vector(), + const_cast(&b.trilinos_vector())); do_solve(preconditioner); } @@ -124,14 +121,12 @@ namespace TrilinosWrappers const MPI::Vector &b, const Epetra_Operator &preconditioner) { - linear_problem.reset(); - // We need an Epetra_LinearProblem object to let the AztecOO solver know // about the matrix and vectors. - linear_problem.reset - (new Epetra_LinearProblem(const_cast(&A), - &x.trilinos_vector(), - const_cast(&b.trilinos_vector()))); + linear_problem = std_cxx14::make_unique + (const_cast(&A), + &x.trilinos_vector(), + const_cast(&b.trilinos_vector())); do_solve(preconditioner); } @@ -146,14 +141,12 @@ namespace TrilinosWrappers const Epetra_MultiVector &b, const PreconditionBase &preconditioner) { - linear_problem.reset(); - // We need an Epetra_LinearProblem object to let the AztecOO solver know // about the matrix and vectors. - linear_problem.reset - (new Epetra_LinearProblem(const_cast(&A), - &x, - const_cast(&b))); + linear_problem = std_cxx14::make_unique + (const_cast(&A), + &x, + const_cast(&b)); do_solve(preconditioner); } @@ -168,14 +161,12 @@ namespace TrilinosWrappers const Epetra_MultiVector &b, const Epetra_Operator &preconditioner) { - linear_problem.reset(); - // We need an Epetra_LinearProblem object to let the AztecOO solver know // about the matrix and vectors. - linear_problem.reset - (new Epetra_LinearProblem(const_cast(&A), - &x, - const_cast(&b))); + linear_problem = std_cxx14::make_unique + (const_cast(&A), + &x, + const_cast(&b)); do_solve(preconditioner); } @@ -188,8 +179,6 @@ namespace TrilinosWrappers const dealii::Vector &b, const PreconditionBase &preconditioner) { - linear_problem.reset(); - // In case we call the solver with deal.II vectors, we create views of the // vectors in Epetra format. Assert (x.size() == A.n(), @@ -206,9 +195,9 @@ namespace TrilinosWrappers // We need an Epetra_LinearProblem object to let the AztecOO solver know // about the matrix and vectors. - linear_problem.reset (new Epetra_LinearProblem - (const_cast(&A.trilinos_matrix()), - &ep_x, &ep_b)); + linear_problem = std_cxx14::make_unique + (const_cast(&A.trilinos_matrix()), + &ep_x, &ep_b); do_solve(preconditioner); } @@ -221,14 +210,12 @@ namespace TrilinosWrappers const dealii::Vector &b, const PreconditionBase &preconditioner) { - linear_problem.reset(); - Epetra_Vector ep_x (View, A.OperatorDomainMap(), x.begin()); Epetra_Vector ep_b (View, A.OperatorRangeMap(), const_cast(b.begin())); // We need an Epetra_LinearProblem object to let the AztecOO solver know // about the matrix and vectors. - linear_problem.reset (new Epetra_LinearProblem(&A,&ep_x, &ep_b)); + linear_problem = std_cxx14::make_unique(&A,&ep_x, &ep_b); do_solve(preconditioner); } @@ -241,8 +228,6 @@ namespace TrilinosWrappers const dealii::LinearAlgebra::distributed::Vector &b, const PreconditionBase &preconditioner) { - linear_problem.reset(); - // In case we call the solver with deal.II vectors, we create views of the // vectors in Epetra format. AssertDimension (static_cast(x.local_size()), @@ -255,9 +240,9 @@ namespace TrilinosWrappers // We need an Epetra_LinearProblem object to let the AztecOO solver know // about the matrix and vectors. - linear_problem.reset (new Epetra_LinearProblem - (const_cast(&A.trilinos_matrix()), - &ep_x, &ep_b)); + linear_problem = std_cxx14::make_unique + (const_cast(&A.trilinos_matrix()), + &ep_x, &ep_b); do_solve(preconditioner); } @@ -270,8 +255,6 @@ namespace TrilinosWrappers const dealii::LinearAlgebra::distributed::Vector &b, const PreconditionBase &preconditioner) { - linear_problem.reset(); - AssertDimension (static_cast(x.local_size()), A.OperatorDomainMap().NumMyElements()); AssertDimension (static_cast(b.local_size()), @@ -282,7 +265,7 @@ namespace TrilinosWrappers // We need an Epetra_LinearProblem object to let the AztecOO solver know // about the matrix and vectors. - linear_problem.reset (new Epetra_LinearProblem(&A,&ep_x, &ep_b)); + linear_problem = std_cxx14::make_unique(&A,&ep_x, &ep_b); do_solve(preconditioner); } @@ -306,7 +289,7 @@ namespace TrilinosWrappers class TrilinosReductionControl : public AztecOO_StatusTest { public: - TrilinosReductionControl (const double &max_steps, + TrilinosReductionControl (const int &max_steps, const double &tolerance, const double &reduction, const Epetra_LinearProblem &linear_problem); @@ -368,15 +351,15 @@ namespace TrilinosWrappers private: double initial_residual; double current_residual; - std::shared_ptr status_test_collection; - std::shared_ptr status_test_max_steps; - std::shared_ptr status_test_abs_tol; - std::shared_ptr status_test_rel_tol; + std::unique_ptr status_test_collection; + std::unique_ptr status_test_max_steps; + std::unique_ptr status_test_abs_tol; + std::unique_ptr status_test_rel_tol; }; TrilinosReductionControl::TrilinosReductionControl( - const double &max_steps, + const int &max_steps, const double &tolerance, const double &reduction, const Epetra_LinearProblem &linear_problem ) @@ -386,23 +369,23 @@ namespace TrilinosWrappers { // Consider linear problem converged if any of the collection // of criterion are met - status_test_collection.reset( - new AztecOO_StatusTestCombo (AztecOO_StatusTestCombo::OR) ); + status_test_collection = std_cxx14::make_unique + (AztecOO_StatusTestCombo::OR); // Maximum number of iterations - status_test_max_steps.reset( - new AztecOO_StatusTestMaxIters(max_steps) ); + Assert (max_steps >=0, ExcInternalError()); + status_test_max_steps = std_cxx14::make_unique(max_steps); status_test_collection->AddStatusTest(*status_test_max_steps); Assert(linear_problem.GetRHS()->NumVectors() == 1, ExcMessage("RHS multivector holds more than one vector")); // Residual norm is below some absolute value - status_test_abs_tol.reset( - new AztecOO_StatusTestResNorm(*linear_problem.GetOperator(), - *(linear_problem.GetLHS()->operator()(0)), - *(linear_problem.GetRHS()->operator()(0)), - tolerance) ); + status_test_abs_tol = std_cxx14::make_unique + (*linear_problem.GetOperator(), + *(linear_problem.GetLHS()->operator()(0)), + *(linear_problem.GetRHS()->operator()(0)), + tolerance); status_test_abs_tol->DefineResForm(AztecOO_StatusTestResNorm::Explicit, AztecOO_StatusTestResNorm::TwoNorm); status_test_abs_tol->DefineScaleForm(AztecOO_StatusTestResNorm::None, @@ -410,11 +393,11 @@ namespace TrilinosWrappers status_test_collection->AddStatusTest(*status_test_abs_tol); // Residual norm, scaled by some initial value, is below some threshold - status_test_rel_tol.reset( - new AztecOO_StatusTestResNorm(*linear_problem.GetOperator(), - *(linear_problem.GetLHS()->operator()(0)), - *(linear_problem.GetRHS()->operator()(0)), - reduction) ); + status_test_rel_tol = std_cxx14::make_unique + (*linear_problem.GetOperator(), + *(linear_problem.GetLHS()->operator()(0)), + *(linear_problem.GetRHS()->operator()(0)), + reduction); status_test_rel_tol->DefineResForm(AztecOO_StatusTestResNorm::Explicit, AztecOO_StatusTestResNorm::TwoNorm); status_test_rel_tol->DefineScaleForm(AztecOO_StatusTestResNorm::NormOfInitRes, @@ -484,11 +467,11 @@ namespace TrilinosWrappers if (const ReductionControl* const reduction_control = dynamic_cast(&solver_control)) { - status_test.reset(new internal::TrilinosReductionControl( - reduction_control->max_steps(), - reduction_control->tolerance(), - reduction_control->reduction(), - *linear_problem) ); + status_test = std_cxx14::make_unique + (reduction_control->max_steps(), + reduction_control->tolerance(), + reduction_control->reduction(), + *linear_problem); solver.SetStatusTest(status_test.get()); } } @@ -727,7 +710,7 @@ namespace TrilinosWrappers { // We need an Epetra_LinearProblem object to let the Amesos solver know // about the matrix and vectors. - linear_problem.reset (new Epetra_LinearProblem ()); + linear_problem = std_cxx14::make_unique(); // Assign the matrix operator to the Epetra_LinearProblem object linear_problem->SetOperator(const_cast(&A.trilinos_matrix())); @@ -740,8 +723,6 @@ namespace TrilinosWrappers ConditionalOStream verbose_cout (std::cout, additional_data.output_solver_details); - solver.reset(); - // Next allocate the Amesos solver, this is done in two steps, first we // create a solver Factory and and generate with that the concrete Amesos // solver, if possible. @@ -836,8 +817,6 @@ namespace TrilinosWrappers ConditionalOStream verbose_cout (std::cout, additional_data.output_solver_details); - solver.reset (); - // Next allocate the Amesos solver, this is done in two steps, first we // create a solver Factory and and generate with that the concrete Amesos // solver, if possible. @@ -885,10 +864,10 @@ namespace TrilinosWrappers { // We need an Epetra_LinearProblem object to let the Amesos solver know // about the matrix and vectors. - linear_problem.reset - (new Epetra_LinearProblem(const_cast(&A.trilinos_matrix()), - &x.trilinos_vector(), - const_cast(&b.trilinos_vector()))); + linear_problem = std_cxx14::make_unique + (const_cast(&A.trilinos_matrix()), + &x.trilinos_vector(), + const_cast(&b.trilinos_vector())); do_solve(); } @@ -914,9 +893,9 @@ namespace TrilinosWrappers // We need an Epetra_LinearProblem object to let the Amesos solver know // about the matrix and vectors. - linear_problem.reset (new Epetra_LinearProblem - (const_cast(&A.trilinos_matrix()), - &ep_x, &ep_b)); + linear_problem = std_cxx14::make_unique + (const_cast(&A.trilinos_matrix()), + &ep_x, &ep_b); do_solve(); } @@ -937,9 +916,9 @@ namespace TrilinosWrappers // We need an Epetra_LinearProblem object to let the Amesos solver know // about the matrix and vectors. - linear_problem.reset (new Epetra_LinearProblem - (const_cast(&A.trilinos_matrix()), - &ep_x, &ep_b)); + linear_problem = std_cxx14::make_unique + (const_cast(&A.trilinos_matrix()), + &ep_x, &ep_b); do_solve(); } diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index fa7fedc32d..48ed68b1bb 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -34,6 +34,7 @@ # include #include +#include DEAL_II_NAMESPACE_OPEN @@ -119,8 +120,8 @@ namespace TrilinosWrappers TrilinosWrappers::types::int_type colnums = matrix->n(); if (value_cache.get() == nullptr) { - value_cache.reset (new std::vector (matrix->n())); - colnum_cache.reset (new std::vector (matrix->n())); + value_cache = std::make_shared>(matrix->n()); + colnum_cache = std::make_shared>(matrix->n()); } else { @@ -427,17 +428,16 @@ namespace TrilinosWrappers if (needs_deep_copy) { - column_space_map.reset (new Epetra_Map (rhs.domain_partitioner())); + column_space_map = std_cxx14::make_unique(rhs.domain_partitioner()); // release memory before reallocation - matrix.reset (); - matrix.reset (new Epetra_FECrsMatrix(*rhs.matrix)); + matrix = std_cxx14::make_unique(*rhs.matrix); matrix->FillComplete(*column_space_map, matrix->RowMap()); } if (rhs.nonlocal_matrix.get() != nullptr) - nonlocal_matrix.reset(new Epetra_CrsMatrix(Copy, rhs.nonlocal_matrix->Graph())); + nonlocal_matrix = std_cxx14::make_unique(Copy, rhs.nonlocal_matrix->Graph()); } @@ -452,10 +452,10 @@ namespace TrilinosWrappers const Epetra_Map &input_col_map, const SparsityPatternType &sparsity_pattern, const bool exchange_data, - std::shared_ptr &column_space_map, - std::shared_ptr &matrix, - std::shared_ptr &nonlocal_matrix, - std::shared_ptr &nonlocal_matrix_exporter) + std::unique_ptr &column_space_map, + std::unique_ptr &matrix, + std::unique_ptr &nonlocal_matrix, + std::unique_ptr &nonlocal_matrix_exporter) { // release memory before reallocation matrix.reset(); @@ -470,7 +470,7 @@ namespace TrilinosWrappers static_cast(TrilinosWrappers::n_global_elements(input_col_map))); } - column_space_map.reset (new Epetra_Map (input_col_map)); + column_space_map = std_cxx14::make_unique(input_col_map); // if we want to exchange data, build a usual Trilinos sparsity pattern // and let that handle the exchange. otherwise, manually create a @@ -481,8 +481,8 @@ namespace TrilinosWrappers SparsityPattern trilinos_sparsity; trilinos_sparsity.reinit (input_row_map, input_col_map, sparsity_pattern, exchange_data); - matrix.reset (new Epetra_FECrsMatrix - (Copy, trilinos_sparsity.trilinos_sparsity_pattern(), false)); + matrix = std_cxx14::make_unique + (Copy, trilinos_sparsity.trilinos_sparsity_pattern(), false); return; } @@ -508,13 +508,13 @@ namespace TrilinosWrappers // col_map that tells how the domain dofs of the matrix will be // distributed). for only one processor, we can directly assign the // columns as well. Compare this with bug # 4123 in the Sandia Bugzilla. - std::shared_ptr graph; + std::unique_ptr graph; if (input_row_map.Comm().NumProc() > 1) - graph.reset (new Epetra_CrsGraph (Copy, input_row_map, - n_entries_per_row.data(), true)); + graph = std_cxx14::make_unique(Copy, input_row_map, + n_entries_per_row.data(), true); else - graph.reset (new Epetra_CrsGraph (Copy, input_row_map, input_col_map, - n_entries_per_row.data(), true)); + graph = std_cxx14::make_unique(Copy, input_row_map, input_col_map, + n_entries_per_row.data(), true); // This functions assumes that the sparsity pattern sits on all // processors (completely). The parallel version uses an Epetra graph @@ -552,7 +552,7 @@ namespace TrilinosWrappers (void)n_global_cols; // And now finally generate the matrix. - matrix.reset (new Epetra_FECrsMatrix(Copy, *graph, false)); + matrix = std_cxx14::make_unique(Copy, *graph, false); } @@ -588,10 +588,10 @@ namespace TrilinosWrappers const Epetra_Map &input_col_map, const DynamicSparsityPattern &sparsity_pattern, const bool exchange_data, - std::shared_ptr &column_space_map, - std::shared_ptr &matrix, - std::shared_ptr &nonlocal_matrix, - std::shared_ptr &nonlocal_matrix_exporter) + std::unique_ptr &column_space_map, + std::unique_ptr &matrix, + std::unique_ptr &nonlocal_matrix, + std::unique_ptr &nonlocal_matrix_exporter) { matrix.reset(); nonlocal_matrix.reset(); @@ -602,7 +602,7 @@ namespace TrilinosWrappers AssertDimension (sparsity_pattern.n_cols(), static_cast(TrilinosWrappers::n_global_elements(input_col_map))); - column_space_map.reset (new Epetra_Map (input_col_map)); + column_space_map = std_cxx14::make_unique(input_col_map); IndexSet relevant_rows (sparsity_pattern.row_index_set()); // serial case @@ -655,21 +655,21 @@ namespace TrilinosWrappers (ghost_rows.size()>0)?(ghost_rows.data()):nullptr, 0, input_row_map.Comm()); - std::shared_ptr graph; - std::shared_ptr nonlocal_graph; + std::unique_ptr graph; + std::unique_ptr nonlocal_graph; if (input_row_map.Comm().NumProc() > 1) { - graph.reset (new Epetra_CrsGraph (Copy, input_row_map, - (n_entries_per_row.size()>0)?(n_entries_per_row.data()):nullptr, - exchange_data ? false : true)); + graph = std_cxx14::make_unique(Copy, input_row_map, + (n_entries_per_row.size()>0)?(n_entries_per_row.data()):nullptr, + exchange_data ? false : true); if (have_ghost_rows == true) - nonlocal_graph.reset (new Epetra_CrsGraphMod (off_processor_map, - n_entries_per_ghost_row.data())); + nonlocal_graph = std_cxx14::make_unique(off_processor_map, + n_entries_per_ghost_row.data()); } else - graph.reset (new Epetra_CrsGraph (Copy, input_row_map, input_col_map, - (n_entries_per_row.size()>0)?(n_entries_per_row.data()):nullptr, - true)); + graph = std_cxx14::make_unique(Copy, input_row_map, input_col_map, + (n_entries_per_row.size()>0)?(n_entries_per_row.data()):nullptr, + true); // now insert the indices, select between the right matrix std::vector row_indices; @@ -718,7 +718,7 @@ namespace TrilinosWrappers Assert (ierr==0, ExcTrilinosError(ierr)); } - nonlocal_matrix.reset (new Epetra_CrsMatrix(Copy, *nonlocal_graph)); + nonlocal_matrix = std_cxx14::make_unique(Copy, *nonlocal_graph); } graph->FillComplete(input_col_map, input_row_map); @@ -727,7 +727,7 @@ namespace TrilinosWrappers AssertDimension (sparsity_pattern.n_cols(),static_cast( TrilinosWrappers::n_global_cols(*graph))); - matrix.reset (new Epetra_FECrsMatrix(Copy, *graph, false)); + matrix = std_cxx14::make_unique(Copy, *graph, false); } } @@ -818,13 +818,13 @@ namespace TrilinosWrappers nonlocal_matrix_exporter.reset(); // reinit with a (parallel) Trilinos sparsity pattern. - column_space_map.reset (new Epetra_Map - (sparsity_pattern.domain_partitioner())); - matrix.reset (new Epetra_FECrsMatrix - (Copy, sparsity_pattern.trilinos_sparsity_pattern(), false)); + column_space_map = std_cxx14::make_unique + (sparsity_pattern.domain_partitioner()); + matrix = std_cxx14::make_unique + (Copy, sparsity_pattern.trilinos_sparsity_pattern(), false); if (sparsity_pattern.nonlocal_graph.get() != nullptr) - nonlocal_matrix.reset (new Epetra_CrsMatrix(Copy, *sparsity_pattern.nonlocal_graph)); + nonlocal_matrix = std_cxx14::make_unique(Copy, *sparsity_pattern.nonlocal_graph); else nonlocal_matrix.reset (); @@ -840,15 +840,15 @@ namespace TrilinosWrappers if (this == &sparse_matrix) return; - column_space_map.reset (new Epetra_Map (sparse_matrix.domain_partitioner())); + column_space_map = std_cxx14::make_unique(sparse_matrix.domain_partitioner()); matrix.reset (); nonlocal_matrix_exporter.reset(); - matrix.reset (new Epetra_FECrsMatrix - (Copy, sparse_matrix.trilinos_sparsity_pattern(), false)); + matrix = std_cxx14::make_unique + (Copy, sparse_matrix.trilinos_sparsity_pattern(), false); if (sparse_matrix.nonlocal_matrix != nullptr) - nonlocal_matrix.reset (new Epetra_CrsMatrix - (Copy, sparse_matrix.nonlocal_matrix->Graph())); + nonlocal_matrix = std_cxx14::make_unique + (Copy, sparse_matrix.nonlocal_matrix->Graph()); else nonlocal_matrix.reset(); @@ -1010,14 +1010,14 @@ namespace TrilinosWrappers Assert (input_matrix.Filled()==true, ExcMessage("Input CrsMatrix has not called FillComplete()!")); - column_space_map.reset (new Epetra_Map (input_matrix.DomainMap())); + column_space_map = std_cxx14::make_unique(input_matrix.DomainMap()); const Epetra_CrsGraph *graph = &input_matrix.Graph(); nonlocal_matrix.reset(); nonlocal_matrix_exporter.reset(); matrix.reset (); - matrix.reset (new Epetra_FECrsMatrix(Copy, *graph, false)); + matrix = std_cxx14::make_unique(Copy, *graph, false); matrix->FillComplete (*column_space_map, input_matrix.RangeMap(), true); @@ -1068,8 +1068,8 @@ namespace TrilinosWrappers // processor must have set the correct entry nonlocal_matrix->FillComplete(*column_space_map, matrix->RowMap()); if (nonlocal_matrix_exporter.get() == nullptr) - nonlocal_matrix_exporter.reset - (new Epetra_Export(nonlocal_matrix->RowMap(), matrix->RowMap())); + nonlocal_matrix_exporter = std_cxx14::make_unique + (nonlocal_matrix->RowMap(), matrix->RowMap()); ierr = matrix->Export(*nonlocal_matrix, *nonlocal_matrix_exporter, mode); AssertThrow(ierr == 0, ExcTrilinosError(ierr)); ierr = matrix->FillComplete(*column_space_map, matrix->RowMap()); @@ -1097,9 +1097,9 @@ namespace TrilinosWrappers // When we clear the matrix, reset // the pointer and generate an // empty matrix. - column_space_map.reset (new Epetra_Map (0, 0, - Utilities::Trilinos::comm_self())); - matrix.reset (new Epetra_FECrsMatrix(View, *column_space_map, 0)); + column_space_map = std_cxx14::make_unique + (0, 0, Utilities::Trilinos::comm_self()); + matrix = std_cxx14::make_unique(View, *column_space_map, 0); nonlocal_matrix.reset(); nonlocal_matrix_exporter.reset(); diff --git a/source/lac/trilinos_sparsity_pattern.cc b/source/lac/trilinos_sparsity_pattern.cc index 7e95a9700d..381e103d59 100644 --- a/source/lac/trilinos_sparsity_pattern.cc +++ b/source/lac/trilinos_sparsity_pattern.cc @@ -48,8 +48,7 @@ namespace TrilinosWrappers // otherwise first flush Trilinos caches sparsity_pattern->compress (); - colnum_cache.reset (new std::vector (sparsity_pattern->row_length(this->a_row))); - + colnum_cache = std::make_shared >(sparsity_pattern->row_length(this->a_row)); if (colnum_cache->size() > 0) { @@ -81,13 +80,13 @@ namespace TrilinosWrappers // interface. SparsityPattern::SparsityPattern () { - column_space_map.reset(new Epetra_Map (TrilinosWrappers::types::int_type(0), - TrilinosWrappers::types::int_type(0), - Utilities::Trilinos::comm_self())); - graph.reset (new Epetra_FECrsGraph(View, - *column_space_map, - *column_space_map, - 0)); + column_space_map = std_cxx14::make_unique (TrilinosWrappers::types::int_type(0), + TrilinosWrappers::types::int_type(0), + Utilities::Trilinos::comm_self()); + graph = std_cxx14::make_unique(View, + *column_space_map, + *column_space_map, + 0); graph->FillComplete(); } @@ -259,9 +258,9 @@ namespace TrilinosWrappers reinit_sp (const Epetra_Map &row_map, const Epetra_Map &col_map, const size_type n_entries_per_row, - std::shared_ptr &column_space_map, - std::shared_ptr &graph, - std::shared_ptr &nonlocal_graph) + std::unique_ptr &column_space_map, + std::unique_ptr &graph, + std::unique_ptr &nonlocal_graph) { Assert(row_map.IsOneToOne(), ExcMessage("Row map must be 1-to-1, i.e., no overlap between " @@ -272,7 +271,7 @@ namespace TrilinosWrappers nonlocal_graph.reset(); graph.reset (); - column_space_map.reset (new Epetra_Map (col_map)); + column_space_map = std_cxx14::make_unique(col_map); // for more than one processor, need to specify only row map first and // let the matrix entries decide about the column map (which says which @@ -283,19 +282,17 @@ namespace TrilinosWrappers // require building a non-local graph which gives us thread-safe // initialization. if (row_map.Comm().NumProc() > 1) - graph.reset (new Epetra_FECrsGraph(Copy, row_map, - n_entries_per_row, false - // TODO: Check which new Trilinos - // version supports this... Remember - // to change tests/trilinos/assemble_matrix_parallel_07 - // too. - //#if DEAL_II_TRILINOS_VERSION_GTE(11,14,0) - //, true - //#endif - )); + graph = std_cxx14::make_unique + (Copy, row_map, n_entries_per_row, false + // TODO: Check which new Trilinos version supports this... + // Remember to change tests/trilinos/assemble_matrix_parallel_07, too. +//#if DEAL_II_TRILINOS_VERSION_GTE(11,14,0) +// , true +//#endif + ); else - graph.reset (new Epetra_FECrsGraph(Copy, row_map, col_map, - n_entries_per_row, false)); + graph = std_cxx14::make_unique + (Copy, row_map, col_map, n_entries_per_row, false); } @@ -304,9 +301,9 @@ namespace TrilinosWrappers reinit_sp (const Epetra_Map &row_map, const Epetra_Map &col_map, const std::vector &n_entries_per_row, - std::shared_ptr &column_space_map, - std::shared_ptr &graph, - std::shared_ptr &nonlocal_graph) + std::unique_ptr &column_space_map, + std::unique_ptr &graph, + std::unique_ptr &nonlocal_graph) { Assert(row_map.IsOneToOne(), ExcMessage("Row map must be 1-to-1, i.e., no overlap between " @@ -321,28 +318,24 @@ namespace TrilinosWrappers AssertDimension (n_entries_per_row.size(), static_cast(TrilinosWrappers::n_global_elements(row_map))); - column_space_map.reset (new Epetra_Map (col_map)); + column_space_map = std_cxx14::make_unique(col_map); std::vector local_entries_per_row(TrilinosWrappers::max_my_gid(row_map)- TrilinosWrappers::min_my_gid(row_map)); for (unsigned int i=0; i 1) - graph.reset(new Epetra_FECrsGraph(Copy, row_map, - local_entries_per_row.data(), - false - // TODO: Check which new Trilinos - // version supports this... Remember - // to change tests/trilinos/assemble_matrix_parallel_07 - // too. - //#if DEAL_II_TRILINOS_VERSION_GTE(11,14,0) - //, true - //#endif - )); + graph = std_cxx14::make_unique + (Copy, row_map, local_entries_per_row.data(), false + // TODO: Check which new Trilinos version supports this... + // Remember to change tests/trilinos/assemble_matrix_parallel_07, too. +//#if DEAL_II_TRILINOS_VERSION_GTE(11,14,0) +// , true +//#endif + ); else - graph.reset(new Epetra_FECrsGraph(Copy, row_map, col_map, - local_entries_per_row.data(), - false)); + graph = std_cxx14::make_unique + (Copy, row_map, col_map, local_entries_per_row.data(), false); } @@ -353,9 +346,9 @@ namespace TrilinosWrappers const Epetra_Map &col_map, const SparsityPatternType &sp, const bool exchange_data, - std::shared_ptr &column_space_map, - std::shared_ptr &graph, - std::shared_ptr &nonlocal_graph) + std::unique_ptr &column_space_map, + std::unique_ptr &graph, + std::unique_ptr &nonlocal_graph) { nonlocal_graph.reset (); graph.reset (); @@ -365,7 +358,7 @@ namespace TrilinosWrappers AssertDimension (sp.n_cols(), static_cast(TrilinosWrappers::n_global_elements(col_map))); - column_space_map.reset (new Epetra_Map (col_map)); + column_space_map = std_cxx14::make_unique(col_map); Assert (row_map.LinearMap() == true, ExcMessage ("This function only works if the row map is contiguous.")); @@ -380,13 +373,13 @@ namespace TrilinosWrappers n_entries_per_row[row-first_row] = static_cast(sp.row_length(row)); if (row_map.Comm().NumProc() > 1) - graph.reset(new Epetra_FECrsGraph(Copy, row_map, - n_entries_per_row.data(), - false)); + graph = std_cxx14::make_unique(Copy, row_map, + n_entries_per_row.data(), + false); else - graph.reset (new Epetra_FECrsGraph(Copy, row_map, col_map, - n_entries_per_row.data(), - false)); + graph = std_cxx14::make_unique(Copy, row_map, col_map, + n_entries_per_row.data(), + false); AssertDimension (sp.n_rows(), static_cast(n_global_rows(*graph))); @@ -580,7 +573,7 @@ namespace TrilinosWrappers { Epetra_Map nonlocal_map = nonlocal_partitioner.make_trilinos_map(communicator, true); - nonlocal_graph.reset(new Epetra_CrsGraph(Copy, nonlocal_map, 0)); + nonlocal_graph = std_cxx14::make_unique(Copy, nonlocal_map, 0); } else Assert(nonlocal_partitioner.n_elements() == 0, ExcInternalError()); @@ -660,11 +653,11 @@ namespace TrilinosWrappers void SparsityPattern::copy_from (const SparsityPattern &sp) { - column_space_map.reset (new Epetra_Map (*sp.column_space_map)); - graph.reset (new Epetra_FECrsGraph(*sp.graph)); + column_space_map = std_cxx14::make_unique(*sp.column_space_map); + graph = std_cxx14::make_unique(*sp.graph); if (sp.nonlocal_graph.get()!=nullptr) - nonlocal_graph.reset(new Epetra_CrsGraph(*sp.nonlocal_graph)); + nonlocal_graph = std_cxx14::make_unique(*sp.nonlocal_graph); else nonlocal_graph.reset(); } @@ -692,11 +685,11 @@ namespace TrilinosWrappers // When we clear the matrix, reset // the pointer and generate an // empty sparsity pattern. - column_space_map.reset (new Epetra_Map (TrilinosWrappers::types::int_type(0), - TrilinosWrappers::types::int_type(0), - Utilities::Trilinos::comm_self())); - graph.reset (new Epetra_FECrsGraph(View, *column_space_map, - *column_space_map, 0)); + column_space_map = std_cxx14::make_unique(TrilinosWrappers::types::int_type(0), + TrilinosWrappers::types::int_type(0), + Utilities::Trilinos::comm_self()); + graph = std_cxx14::make_unique(View, *column_space_map, + *column_space_map, 0); graph->FillComplete(); nonlocal_graph.reset(); diff --git a/source/lac/trilinos_vector.cc b/source/lac/trilinos_vector.cc index 9533693354..5ff9112060 100644 --- a/source/lac/trilinos_vector.cc +++ b/source/lac/trilinos_vector.cc @@ -18,6 +18,7 @@ #ifdef DEAL_II_WITH_TRILINOS # include +# include # include # include # include @@ -85,7 +86,7 @@ namespace TrilinosWrappers Vector() { has_ghosts = v.has_ghosts; - vector.reset(new Epetra_FEVector(*v.vector)); + vector = std_cxx14::make_unique(*v.vector); owned_elements = v.owned_elements; } @@ -110,9 +111,8 @@ namespace TrilinosWrappers ExcDimensionMismatch (parallel_partitioner.size(), TrilinosWrappers::n_global_elements(v.vector->Map()))); - vector.reset (new Epetra_FEVector - (parallel_partitioner.make_trilinos_map(communicator, - true))); + vector = std_cxx14::make_unique + (parallel_partitioner.make_trilinos_map(communicator, true)); reinit (v, false, true); } @@ -140,7 +140,7 @@ namespace TrilinosWrappers #endif has_ghosts = false; - vector.reset (new Epetra_FEVector(map)); + vector = std_cxx14::make_unique(map); last_action = Zero; } @@ -156,7 +156,7 @@ namespace TrilinosWrappers Epetra_Map map = parallel_partitioner.make_trilinos_map (communicator, true); - vector.reset (new Epetra_FEVector(map)); + vector = std_cxx14::make_unique(map); has_ghosts = vector->Map().UniqueGIDs()==false; @@ -210,7 +210,7 @@ namespace TrilinosWrappers #endif if (!same_communicators || vector->Map().SameAs(v.vector->Map()) == false) { - vector.reset (new Epetra_FEVector(v.vector->Map())); + vector = std_cxx14::make_unique(v.vector->Map()); has_ghosts = v.has_ghosts; last_action = Zero; owned_elements = v.owned_elements; @@ -299,14 +299,7 @@ namespace TrilinosWrappers Epetra_Map new_map (v.size(), n_elements, global_ids.data(), 0, v.block(0).vector_partitioner().Comm()); - std::shared_ptr actual_vec; - if ( import_data == true ) - actual_vec.reset (new Epetra_FEVector (new_map)); - else - { - vector.reset (new Epetra_FEVector (new_map)); - actual_vec = vector; - } + auto actual_vec = std_cxx14::make_unique(new_map); TrilinosScalar *entries = (*actual_vec)[0]; for (size_type block=0; block(&(vector->Comm())); @@ -355,7 +350,7 @@ namespace TrilinosWrappers parallel_partitioner.add_indices(ghost_entries); Epetra_Map map = parallel_partitioner.make_trilinos_map (communicator, true); - vector.reset (new Epetra_FEVector(map)); + vector = std_cxx14::make_unique(map); } else { @@ -366,7 +361,7 @@ namespace TrilinosWrappers "its parallel partitioning")); if (vector->Map().SameAs(map)==false) - vector.reset (new Epetra_FEVector(map)); + vector = std_cxx14::make_unique(map); else { const int ierr = vector->PutScalar(0.); @@ -380,7 +375,7 @@ namespace TrilinosWrappers { Epetra_Map nonlocal_map = nonlocal_entries.make_trilinos_map(communicator, true); - nonlocal_vector.reset(new Epetra_MultiVector(nonlocal_map, 1)); + nonlocal_vector = std_cxx14::make_unique(nonlocal_map, 1); } } @@ -442,7 +437,7 @@ namespace TrilinosWrappers { *vector = *v.vector; if (v.nonlocal_vector.get() != nullptr) - nonlocal_vector.reset(new Epetra_MultiVector(v.nonlocal_vector->Map(), 1)); + nonlocal_vector = std_cxx14::make_unique(v.nonlocal_vector->Map(), 1); last_action = Zero; } // Second case: vectors have the same global @@ -458,14 +453,14 @@ namespace TrilinosWrappers // size. else { - vector.reset (new Epetra_FEVector(*v.vector)); + vector = std_cxx14::make_unique(*v.vector); last_action = Zero; has_ghosts = v.has_ghosts; owned_elements = v.owned_elements; } if (v.nonlocal_vector.get() != nullptr) - nonlocal_vector.reset(new Epetra_MultiVector(v.nonlocal_vector->Map(), 1)); + nonlocal_vector = std_cxx14::make_unique(v.nonlocal_vector->Map(), 1); return *this; } @@ -513,11 +508,7 @@ namespace TrilinosWrappers "which is not allowed.")); if (vector->Map().SameAs(m.trilinos_matrix().ColMap()) == false) - { - vector.reset (new Epetra_FEVector( - m.trilinos_matrix().ColMap() - )); - } + vector = std_cxx14::make_unique(m.trilinos_matrix().ColMap()); Epetra_Import data_exchange (vector->Map(), v.vector->Map()); const int ierr = vector->Import(*v.vector, data_exchange, Insert);