From: Bruno Turcksin Date: Mon, 14 Sep 2015 19:48:02 +0000 (-0500) Subject: size() return the global size of ReadWriteVector. The local size is given by the... X-Git-Tag: v8.4.0-rc2~379^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71996673e2b5594f66d8e87754e43b7ca04b6cf6;p=dealii.git size() return the global size of ReadWriteVector. The local size is given by the function n_elements(). --- diff --git a/include/deal.II/lac/read_write_vector.h b/include/deal.II/lac/read_write_vector.h index 1e05d5132f..44bfa02a05 100644 --- a/include/deal.II/lac/read_write_vector.h +++ b/include/deal.II/lac/read_write_vector.h @@ -204,10 +204,17 @@ namespace LinearAlgebra ReadWriteVector &operator = (const Number s); /** - * Returns the size of the vector, equal to number of elements in - * the vector. + * Returns the size of the vector. + * + * Note that the result is not equal to the number of element stored locally. + * The latter information is returned by n_elements() + */ + size_type size() const; + + /** + * Return the number of elements stored locally. */ - size_type size () const; + size_type n_elements() const; /** * Return the IndexSet that stores the indices of the elements stored. @@ -218,8 +225,6 @@ namespace LinearAlgebra * Make the @p ReadWriteVector class a bit like the vector<> class of * the C++ standard library by returning iterators to the start and end * of the locally stored elements of this vector. - * - * It holds that end() - begin() == size(). */ iterator begin (); @@ -451,7 +456,7 @@ namespace LinearAlgebra ReadWriteVector & ReadWriteVector::operator= (const ReadWriteVector &in_vector) { - resize_val(in_vector.size()); + resize_val(in_vector.n_elements()); stored_elements = in_vector.get_stored_elements(); std::copy(in_vector.begin(),in_vector.end(),begin()); @@ -466,7 +471,7 @@ namespace LinearAlgebra ReadWriteVector & ReadWriteVector::operator= (const ReadWriteVector &in_vector) { - resize_val(in_vector.size()); + resize_val(in_vector.n_elements()); stored_elements = in_vector.get_stored_elements(); std::copy(in_vector.begin(),in_vector.end(),begin()); @@ -478,7 +483,17 @@ namespace LinearAlgebra template inline typename ReadWriteVector::size_type - ReadWriteVector::size () const + ReadWriteVector::size() const + { + return stored_elements.size(); + } + + + + template + inline + typename ReadWriteVector::size_type + ReadWriteVector::n_elements() const { return stored_elements.n_elements(); } @@ -520,7 +535,7 @@ namespace LinearAlgebra typename ReadWriteVector::iterator ReadWriteVector::end () { - return &val[this->size()]; + return &val[this->n_elements()]; } @@ -530,7 +545,7 @@ namespace LinearAlgebra typename ReadWriteVector::const_iterator ReadWriteVector::end () const { - return &val[this->size()]; + return &val[this->n_elements()]; } @@ -609,7 +624,7 @@ namespace LinearAlgebra Number ReadWriteVector::local_element (const size_type local_index) const { - AssertIndexRange (local_index, this->size()); + AssertIndexRange (local_index, this->n_elements()); return val[local_index]; } @@ -621,7 +636,7 @@ namespace LinearAlgebra Number & ReadWriteVector::local_element (const size_type local_index) { - AssertIndexRange (local_index, this->size()); + AssertIndexRange (local_index, this->n_elements()); return val[local_index]; } diff --git a/include/deal.II/lac/read_write_vector.templates.h b/include/deal.II/lac/read_write_vector.templates.h index 2e0dea9cb8..550c772ea8 100644 --- a/include/deal.II/lac/read_write_vector.templates.h +++ b/include/deal.II/lac/read_write_vector.templates.h @@ -58,7 +58,7 @@ namespace LinearAlgebra const bool fast) { // check whether we need to reallocate - resize_val (size); + resize_val(size); stored_elements = complete_index_set(size); @@ -75,7 +75,7 @@ namespace LinearAlgebra ReadWriteVector::reinit (const ReadWriteVector &v, const bool fast) { - resize_val (v.size()); + resize_val(v.n_elements()); stored_elements = v.get_stored_elements(); @@ -191,7 +191,7 @@ namespace LinearAlgebra #ifdef DEAL_II_WITH_MPI // Copy the off-processor elements if necessary - if (intersection_size != size()) + if (intersection_size != n_elements()) { Epetra_BlockMap source_map = trilinos_vec.trilinos_vector().Map(); std::vector off_proc_indices(readwrite_indices.size()); @@ -240,7 +240,7 @@ namespace LinearAlgebra ReadWriteVector::memory_consumption () const { std::size_t memory = sizeof(*this); - memory += sizeof (Number) * static_cast(this->size()); + memory += sizeof (Number) * static_cast(this->n_elements()); memory += stored_elements.memory_consumption(); @@ -268,7 +268,7 @@ namespace LinearAlgebra out << "IndexSet: "; stored_elements.print(out); out << std::endl; - for (unsigned int i=0; isize(); ++i) + for (unsigned int i=0; in_elements(); ++i) out << val[i] << std::endl; out << std::flush; diff --git a/tests/lac/readwritevector_assignement.cc b/tests/lac/readwritevector_assignement.cc index 893e021dae..0d647dcc95 100644 --- a/tests/lac/readwritevector_assignement.cc +++ b/tests/lac/readwritevector_assignement.cc @@ -33,13 +33,13 @@ void test() is.add_range(10,15); LinearAlgebra::ReadWriteVector double_vector(is); LinearAlgebra::ReadWriteVector float_vector(float_size); - deallog << "double_size " << double_vector.size() < double_vector2(double_vector); double_vector2.print(deallog.get_file_stream()); - for (unsigned int i=0; i