From 31288d2e65914d776f4ff668670b7ec54d6ab1f8 Mon Sep 17 00:00:00 2001 From: Bruno Turcksin Date: Tue, 8 Mar 2016 17:00:51 -0500 Subject: [PATCH] Do not require C++11 --- include/deal.II/base/std_cxx11/shared_ptr.h | 5 +++ include/deal.II/lac/la_vector.h | 41 ++++++++++--------- include/deal.II/lac/la_vector.templates.h | 2 +- include/deal.II/lac/read_write_vector.h | 26 ++++++------ .../deal.II/lac/read_write_vector.templates.h | 32 +++++++-------- .../trilinos_epetra_communication_pattern.h | 2 +- include/deal.II/lac/trilinos_epetra_vector.h | 3 +- include/deal.II/lac/vector_space_vector.h | 3 +- .../trilinos_epetra_communication_pattern.cc | 3 +- source/lac/trilinos_epetra_vector.cc | 14 +++---- tests/trilinos/epetra_vector_01.cc | 3 +- tests/trilinos/epetra_vector_02.cc | 1 + 12 files changed, 71 insertions(+), 64 deletions(-) diff --git a/include/deal.II/base/std_cxx11/shared_ptr.h b/include/deal.II/base/std_cxx11/shared_ptr.h index 4c90c75221..07ac73cc70 100644 --- a/include/deal.II/base/std_cxx11/shared_ptr.h +++ b/include/deal.II/base/std_cxx11/shared_ptr.h @@ -27,6 +27,8 @@ namespace std_cxx11 { using std::shared_ptr; using std::enable_shared_from_this; + using std::make_shared; + using std::dynamic_pointer_cast; } DEAL_II_NAMESPACE_CLOSE @@ -34,11 +36,14 @@ DEAL_II_NAMESPACE_CLOSE #include #include +#include DEAL_II_NAMESPACE_OPEN namespace std_cxx11 { using boost::shared_ptr; using boost::enable_shared_from_this; + using boost::make_shared; + using boost::dynamic_pointer_cast; } DEAL_II_NAMESPACE_CLOSE diff --git a/include/deal.II/lac/la_vector.h b/include/deal.II/lac/la_vector.h index 1cfb6cb4e3..86b23bf715 100644 --- a/include/deal.II/lac/la_vector.h +++ b/include/deal.II/lac/la_vector.h @@ -110,88 +110,89 @@ namespace LinearAlgebra /** * Multiply the entire vector by a fixed factor. */ - virtual Vector &operator*= (const Number factor) override; + virtual Vector &operator*= (const Number factor); /** * Divide the entire vector by a fixed factor. */ - virtual Vector &operator/= (const Number factor) override; + virtual Vector &operator/= (const Number factor); /** * Add the vector @p V to the present one. */ - virtual Vector &operator+= (const VectorSpaceVector &V) override; + virtual Vector &operator+= (const VectorSpaceVector &V); /** * Substract the vector @p V from the present one. */ - virtual Vector &operator-= (const VectorSpaceVector &V) override; + virtual Vector &operator-= (const VectorSpaceVector &V); /** * Return the scalar product of two vectors. */ - virtual Number operator* (const VectorSpaceVector &V) const override; + virtual Number operator* (const VectorSpaceVector &V) const; /** * This function is not implemented and will throw an exception. */ virtual void import(const ReadWriteVector &V, VectorOperation::values operation, - std::shared_ptr communication_pattern = nullptr) override; + std_cxx11::shared_ptr + communication_pattern = NULL); /** * Add @p a to all components. Note that @p a is a scalar not a vector. */ - virtual void add(const Number a) override; + virtual void add(const Number a); /** * Simple addition of a multiple of a vector, i.e. *this += a*V. */ - virtual void add(const Number a, const VectorSpaceVector &V) override; + virtual void add(const Number a, const VectorSpaceVector &V); /** * Multiple addition of a multiple of a vector, i.e. *this += * a*V+b*W. */ virtual void add(const Number a, const VectorSpaceVector &V, - const Number b, const VectorSpaceVector &W) override; + const Number b, const VectorSpaceVector &W); /** * Scaling and simple addition of a multiple of a vector, i.e. *this = * s*(*this)+a*V. */ virtual void sadd(const Number s, const Number a, - const VectorSpaceVector &V) override; + const VectorSpaceVector &V); /** * Scale each element of this vector by the corresponding element in the * argument. This function is mostly meant to simulate multiplication (and * immediate re-assignement) by a diagonal scaling matrix. */ - virtual void scale(const VectorSpaceVector &scaling_factors) override; + virtual void scale(const VectorSpaceVector &scaling_factors); /** * Assignement *this = a*V. */ - virtual void equ(const Number a, const VectorSpaceVector &V) override; + virtual void equ(const Number a, const VectorSpaceVector &V); /** * Return the l1 norm of the vector (i.e., the sum of the * absolute values of all entries). */ - virtual typename VectorSpaceVector::real_type l1_norm() const override; + virtual typename VectorSpaceVector::real_type l1_norm() const; /** * Return the l2 norm of the vector (i.e., the square root of * the sum of the square of all entries among all processors). */ - virtual typename VectorSpaceVector::real_type l2_norm() const override; + virtual typename VectorSpaceVector::real_type l2_norm() const; /** * Return the maximum norm of the vector (i.e., the maximum absolute value * among all entries and among all processors). */ - virtual typename VectorSpaceVector::real_type linfty_norm() const override; + virtual typename VectorSpaceVector::real_type linfty_norm() const; /** * Perform a combined operation of a vector addition and a subsequent @@ -204,13 +205,13 @@ namespace LinearAlgebra */ virtual Number add_and_dot(const Number a, const VectorSpaceVector &V, - const VectorSpaceVector &W) override; + const VectorSpaceVector &W); /** * Return the global size of the vector, equal to the sum of the number of * locally owned indices among all processors. */ - virtual size_type size() const override; + virtual size_type size() const; /** * Return an index set that describes which elements of this vector are @@ -223,7 +224,7 @@ namespace LinearAlgebra * vec.locally_owned_elements() == complete_index_set(vec.size()) * @endcode */ - virtual dealii::IndexSet locally_owned_elements() const override; + virtual dealii::IndexSet locally_owned_elements() const; /** * Prints the vector to the output stream @p out. @@ -231,7 +232,7 @@ namespace LinearAlgebra virtual void print(std::ostream &out, const unsigned int precision=3, const bool scientific=true, - const bool across=true) const override; + const bool across=true) const; /** * Write the vector en bloc to a file. This is done in a binary mode, so * the output is neither readable by humans nor (probably) by other @@ -255,7 +256,7 @@ namespace LinearAlgebra /** * Returns the memory consumption of this class in bytes. */ - virtual std::size_t memory_consumption() const override; + virtual std::size_t memory_consumption() const; /** * Attempt to perform an operation between two incompatible vector types. diff --git a/include/deal.II/lac/la_vector.templates.h b/include/deal.II/lac/la_vector.templates.h index 1544a5f06e..de99473af3 100644 --- a/include/deal.II/lac/la_vector.templates.h +++ b/include/deal.II/lac/la_vector.templates.h @@ -117,7 +117,7 @@ namespace LinearAlgebra template void Vector::import(const ReadWriteVector &, VectorOperation::values , - std::shared_ptr) + std_cxx11::shared_ptr) { AssertThrow(false, ExcMessage("This function is not implemented.")); } diff --git a/include/deal.II/lac/read_write_vector.h b/include/deal.II/lac/read_write_vector.h index ef38613f2d..b8459a0573 100644 --- a/include/deal.II/lac/read_write_vector.h +++ b/include/deal.II/lac/read_write_vector.h @@ -233,7 +233,7 @@ namespace LinearAlgebra */ void import(const PETScWrappers::MPI::Vector &petsc_vec, VectorOperation::values operation, - std::shared_ptr communication_pattern = nullptr); + std_cxx11::shared_ptr communication_pattern = NULL); #endif #ifdef DEAL_II_WITH_TRILINOS @@ -247,7 +247,7 @@ namespace LinearAlgebra */ void import(const TrilinosWrappers::MPI::Vector &trilinos_vec, VectorOperation::values operation, - std::shared_ptr communication_pattern = nullptr); + std_cxx11::shared_ptr communication_pattern = NULL); /** * Imports all the elements present in the vector's IndexSet from the input @@ -259,7 +259,7 @@ namespace LinearAlgebra */ void import(const EpetraWrappers::Vector &epetra_vec, VectorOperation::values operation, - std::shared_ptr communication_pattern = nullptr); + std_cxx11::shared_ptr communication_pattern = NULL); #endif /** @@ -454,7 +454,7 @@ namespace LinearAlgebra const IndexSet &locally_owned_elements, VectorOperation::values operation, const MPI_Comm &mpi_comm, - std::shared_ptr communication_pattern); + std_cxx11::shared_ptr communication_pattern); #endif /** @@ -497,7 +497,7 @@ namespace LinearAlgebra * CommunicationPattern for the communication between the * source_stored_elements IndexSet and the current vector. */ - std::shared_ptr comm_pattern; + std_cxx11::shared_ptr comm_pattern; /** * Pointer to the array of local elements of this vector. @@ -517,8 +517,8 @@ namespace LinearAlgebra inline ReadWriteVector::ReadWriteVector () : - comm_pattern(nullptr), - val(nullptr) + comm_pattern(NULL), + val(NULL) {} @@ -528,8 +528,8 @@ namespace LinearAlgebra ReadWriteVector::ReadWriteVector (const ReadWriteVector &v) : Subscriptor(), - comm_pattern(nullptr), - val(nullptr) + comm_pattern(NULL), + val(NULL) { this->operator=(v); } @@ -540,8 +540,8 @@ namespace LinearAlgebra inline ReadWriteVector::ReadWriteVector (const size_type size) : - comm_pattern(nullptr), - val(nullptr) + comm_pattern(NULL), + val(NULL) { reinit (size, false); } @@ -552,8 +552,8 @@ namespace LinearAlgebra inline ReadWriteVector::ReadWriteVector (const IndexSet &locally_stored_indices) : - comm_pattern(nullptr), - val(nullptr) + comm_pattern(NULL), + val(NULL) { reinit (locally_stored_indices); } diff --git a/include/deal.II/lac/read_write_vector.templates.h b/include/deal.II/lac/read_write_vector.templates.h index 6da4a67284..4b5fbad696 100644 --- a/include/deal.II/lac/read_write_vector.templates.h +++ b/include/deal.II/lac/read_write_vector.templates.h @@ -39,13 +39,13 @@ namespace LinearAlgebra { if (new_alloc_size == 0) { - if (val != nullptr) + if (val != NULL) free(val); - val = nullptr; + val = NULL; } else { - if (val != nullptr) + if (val != NULL) free(val); Utilities::System::posix_memalign ((void **)&val, 64, sizeof(Number)*new_alloc_size); @@ -71,7 +71,7 @@ namespace LinearAlgebra // reset the communication patter source_stored_elements.clear(); - comm_pattern = nullptr; + comm_pattern = NULL; } @@ -91,7 +91,7 @@ namespace LinearAlgebra // reset the communication patter source_stored_elements.clear(); - comm_pattern = nullptr; + comm_pattern = NULL; } @@ -112,7 +112,7 @@ namespace LinearAlgebra // reset the communication patter source_stored_elements.clear(); - comm_pattern = nullptr; + comm_pattern = NULL; } @@ -180,13 +180,13 @@ namespace LinearAlgebra const IndexSet &source_elements, VectorOperation::values operation, const MPI_Comm &mpi_comm, - std::shared_ptr communication_pattern) + std_cxx11::shared_ptr communication_pattern) { std_cxx11::shared_ptr epetra_comm_pattern; // If no communication pattern is given, create one. Otherwise, use the one // given. - if (communication_pattern == nullptr) + if (communication_pattern == NULL) { // The first time import is called, we create a communication pattern. // Check if the communication pattern already exists and if it can be @@ -195,20 +195,20 @@ namespace LinearAlgebra (source_elements == source_stored_elements)) { epetra_comm_pattern = - std::dynamic_pointer_cast (comm_pattern); - if (epetra_comm_pattern == nullptr) - epetra_comm_pattern = std::make_shared( + std_cxx11::dynamic_pointer_cast (comm_pattern); + if (epetra_comm_pattern == NULL) + epetra_comm_pattern = std_cxx11::make_shared( create_epetra_comm_pattern(source_elements, mpi_comm)); } else - epetra_comm_pattern = std::make_shared( + epetra_comm_pattern = std_cxx11::make_shared( create_epetra_comm_pattern(source_elements, mpi_comm)); } else { - epetra_comm_pattern = std::dynamic_pointer_cast ( + epetra_comm_pattern = std_cxx11::dynamic_pointer_cast ( communication_pattern); - AssertThrow(epetra_comm_pattern != nullptr, + AssertThrow(epetra_comm_pattern != NULL, ExcMessage(std::string("The communication pattern is not of type ") + "LinearAlgebra::EpetraWrappers::CommunicationPattern.")); } @@ -238,7 +238,7 @@ namespace LinearAlgebra void ReadWriteVector::import(const TrilinosWrappers::MPI::Vector &trilinos_vec, VectorOperation::values operation, - std::shared_ptr communication_pattern) + std_cxx11::shared_ptr communication_pattern) { import(trilinos_vec.trilinos_vector(), trilinos_vec.locally_owned_elements(), operation, trilinos_vec.get_mpi_communicator(), communication_pattern); @@ -250,7 +250,7 @@ namespace LinearAlgebra void ReadWriteVector::import(const LinearAlgebra::EpetraWrappers::Vector &trilinos_vec, VectorOperation::values operation, - std::shared_ptr communication_pattern) + std_cxx11::shared_ptr communication_pattern) { import(trilinos_vec.trilinos_vector(), trilinos_vec.locally_owned_elements(), operation, trilinos_vec.get_mpi_communicator(), communication_pattern); diff --git a/include/deal.II/lac/trilinos_epetra_communication_pattern.h b/include/deal.II/lac/trilinos_epetra_communication_pattern.h index d25f9187d1..9846515776 100644 --- a/include/deal.II/lac/trilinos_epetra_communication_pattern.h +++ b/include/deal.II/lac/trilinos_epetra_communication_pattern.h @@ -60,7 +60,7 @@ namespace LinearAlgebra /** * Return the underlying MPI communicator. */ - const MPI_Comm &get_mpi_communicator() const override; + const MPI_Comm &get_mpi_communicator() const; /** * Return the underlying Epetra_Import object. diff --git a/include/deal.II/lac/trilinos_epetra_vector.h b/include/deal.II/lac/trilinos_epetra_vector.h index 2a29f1100b..e974863ae1 100644 --- a/include/deal.II/lac/trilinos_epetra_vector.h +++ b/include/deal.II/lac/trilinos_epetra_vector.h @@ -101,8 +101,7 @@ namespace LinearAlgebra */ virtual void import(const ReadWriteVector &V, VectorOperation::values operation, - std::shared_ptr communication_pattern = nullptr) - override; + std_cxx11::shared_ptr communication_pattern = NULL); /** * Multiply the entire vector by a fixed factor. diff --git a/include/deal.II/lac/vector_space_vector.h b/include/deal.II/lac/vector_space_vector.h index 8ccab81807..15cc4b7cd3 100644 --- a/include/deal.II/lac/vector_space_vector.h +++ b/include/deal.II/lac/vector_space_vector.h @@ -19,6 +19,7 @@ #include #include #include +#include DEAL_II_NAMESPACE_OPEN @@ -79,7 +80,7 @@ namespace LinearAlgebra */ virtual void import(const ReadWriteVector &V, VectorOperation::values operation, - std::shared_ptr communication_pattern = nullptr) = 0; + std_cxx11::shared_ptr communication_pattern = NULL) = 0; /** * Return the scalar product of two vectors. diff --git a/source/lac/trilinos_epetra_communication_pattern.cc b/source/lac/trilinos_epetra_communication_pattern.cc index 992d2d9c68..d84ff99456 100644 --- a/source/lac/trilinos_epetra_communication_pattern.cc +++ b/source/lac/trilinos_epetra_communication_pattern.cc @@ -20,6 +20,7 @@ #ifdef DEAL_II_WITH_MPI #include +#include #include "Epetra_Map.h" DEAL_II_NAMESPACE_OPEN @@ -41,7 +42,7 @@ namespace LinearAlgebra const IndexSet &read_write_vector_index_set, const MPI_Comm &communicator) { - comm = std::make_shared(communicator); + comm = std_cxx11::make_shared(communicator); Epetra_Map vector_space_vector_map = vector_space_vector_index_set.make_trilinos_map(*comm, false); diff --git a/source/lac/trilinos_epetra_vector.cc b/source/lac/trilinos_epetra_vector.cc index 7a8d8ae163..953173f275 100644 --- a/source/lac/trilinos_epetra_vector.cc +++ b/source/lac/trilinos_epetra_vector.cc @@ -34,7 +34,7 @@ namespace LinearAlgebra Vector::Vector() : vector(new Epetra_FEVector(Epetra_Map(0,0,0,Utilities::Trilinos::comm_self()))), - epetra_comm_pattern(nullptr) + epetra_comm_pattern(NULL) {} @@ -42,7 +42,7 @@ namespace LinearAlgebra Vector::Vector(const Vector &V) : vector(new Epetra_FEVector(V.trilinos_vector())), - epetra_comm_pattern(nullptr) + epetra_comm_pattern(NULL) {} @@ -51,7 +51,7 @@ namespace LinearAlgebra const MPI_Comm &communicator) : vector(new Epetra_FEVector(parallel_partitioner.make_trilinos_map(communicator,false))), - epetra_comm_pattern(nullptr) + epetra_comm_pattern(NULL) {} @@ -101,11 +101,11 @@ namespace LinearAlgebra void Vector::import(const ReadWriteVector &V, VectorOperation::values operation, - std::shared_ptr communication_pattern) + std_cxx11::shared_ptr communication_pattern) { // If no communication pattern is given, create one. Otherwsie, use the // one given. - if (communication_pattern == nullptr) + if (communication_pattern == NULL) { // The first time import is called, a communication pattern is created. // Check if the communication pattern already exists and if it can be @@ -121,8 +121,8 @@ namespace LinearAlgebra else { epetra_comm_pattern = - std::dynamic_pointer_cast (communication_pattern); - AssertThrow(epetra_comm_pattern != nullptr, + std_cxx11::dynamic_pointer_cast (communication_pattern); + AssertThrow(epetra_comm_pattern != NULL, ExcMessage(std::string("The communication pattern is not of type ") + "LinearAlgebra::EpetraWrappers::CommunicationPattern.")); } diff --git a/tests/trilinos/epetra_vector_01.cc b/tests/trilinos/epetra_vector_01.cc index 1192ef5382..42132a1f45 100644 --- a/tests/trilinos/epetra_vector_01.cc +++ b/tests/trilinos/epetra_vector_01.cc @@ -22,8 +22,7 @@ #include #include -// Check LinearAlgebra::EpetraWrappers::Vector assignement and the operator -// overloading. +// Check LinearAlgebra::EpetraWrappers::Vector assignement and import void test() diff --git a/tests/trilinos/epetra_vector_02.cc b/tests/trilinos/epetra_vector_02.cc index 437e11284c..e0c5eb1fc6 100644 --- a/tests/trilinos/epetra_vector_02.cc +++ b/tests/trilinos/epetra_vector_02.cc @@ -22,6 +22,7 @@ #include #include +// Check LinearAlgebra::EpetraWrappers::Vector add and sadd. void test() { -- 2.39.5