]> https://gitweb.dealii.org/ - dealii.git/commitdiff
size() return the global size of ReadWriteVector. The local size is given by the...
authorBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 14 Sep 2015 19:48:02 +0000 (14:48 -0500)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 14 Sep 2015 19:48:02 +0000 (14:48 -0500)
include/deal.II/lac/read_write_vector.h
include/deal.II/lac/read_write_vector.templates.h
tests/lac/readwritevector_assignement.cc

index 1e05d5132ff6eb9bee57f3e6d753b3c1b9215e32..44bfa02a056cc3cc12f0d5b958b83f482a6c4f86 100644 (file)
@@ -204,10 +204,17 @@ namespace LinearAlgebra
     ReadWriteVector<Number> &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 <tt>vector<></tt> class of
      * the C++ standard library by returning iterators to the start and end
      * of the <i>locally stored</i> elements of this vector.
-     *
-     * It holds that end() - begin() == size().
      */
     iterator begin ();
 
@@ -451,7 +456,7 @@ namespace LinearAlgebra
   ReadWriteVector<Number> &
   ReadWriteVector<Number>::operator= (const ReadWriteVector<Number> &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<Number> &
   ReadWriteVector<Number>::operator= (const ReadWriteVector<Number2> &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 <typename Number>
   inline
   typename ReadWriteVector<Number>::size_type
-  ReadWriteVector<Number>::size () const
+  ReadWriteVector<Number>::size() const
+  {
+    return stored_elements.size();
+  }
+
+
+
+  template <typename Number>
+  inline
+  typename ReadWriteVector<Number>::size_type
+  ReadWriteVector<Number>::n_elements() const
   {
     return stored_elements.n_elements();
   }
@@ -520,7 +535,7 @@ namespace LinearAlgebra
   typename ReadWriteVector<Number>::iterator
   ReadWriteVector<Number>::end ()
   {
-    return &val[this->size()];
+    return &val[this->n_elements()];
   }
 
 
@@ -530,7 +545,7 @@ namespace LinearAlgebra
   typename ReadWriteVector<Number>::const_iterator
   ReadWriteVector<Number>::end () const
   {
-    return &val[this->size()];
+    return &val[this->n_elements()];
   }
 
 
@@ -609,7 +624,7 @@ namespace LinearAlgebra
   Number
   ReadWriteVector<Number>::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<Number>::local_element (const size_type local_index)
   {
-    AssertIndexRange (local_index, this->size());
+    AssertIndexRange (local_index, this->n_elements());
 
     return val[local_index];
   }
index 2e0dea9cb8398a2addd3b13b0900988cea4aedde..550c772ea8f0b60d6d457d0ae8a0015578d11f95 100644 (file)
@@ -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<Number>::reinit (const ReadWriteVector<Number2> &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<size_type> off_proc_indices(readwrite_indices.size());
@@ -240,7 +240,7 @@ namespace LinearAlgebra
   ReadWriteVector<Number>::memory_consumption () const
   {
     std::size_t memory = sizeof(*this);
-    memory += sizeof (Number) * static_cast<std::size_t>(this->size());
+    memory += sizeof (Number) * static_cast<std::size_t>(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; i<this->size(); ++i)
+    for (unsigned int i=0; i<this->n_elements(); ++i)
       out << val[i] << std::endl;
     out << std::flush;
 
index 893e021dae35ada2e5eb938ba7bfe38e4690aebf..0d647dcc95421aab33d73426edfeecb901de8893 100644 (file)
@@ -33,13 +33,13 @@ void test()
   is.add_range(10,15);
   LinearAlgebra::ReadWriteVector<double> double_vector(is);
   LinearAlgebra::ReadWriteVector<float> float_vector(float_size);
-  deallog << "double_size " << double_vector.size() <<std::endl;
-  deallog << "float_size " << float_vector.size() <<std::endl;
+  deallog << "double_size " << double_vector.n_elements() <<std::endl;
+  deallog << "float_size " << float_vector.n_elements() <<std::endl;
 
   double_vector = 0.;
-  for (unsigned int i=0; i<double_vector.size(); ++i)
+  for (unsigned int i=0; i<double_vector.n_elements(); ++i)
     double_vector.local_element(i) += i;
-  for (unsigned int i=0; i<float_vector.size(); ++i)
+  for (unsigned int i=0; i<float_vector.n_elements(); ++i)
     float_vector[i] = i;
 
   double_vector.print(deallog.get_file_stream());
@@ -51,7 +51,7 @@ void test()
   LinearAlgebra::ReadWriteVector<double> double_vector2(double_vector);
   double_vector2.print(deallog.get_file_stream());
 
-  for (unsigned int i=0; i<double_vector.size(); ++i)
+  for (unsigned int i=0; i<double_vector.n_elements(); ++i)
     double_vector2.local_element(i) += i;
   double_vector = double_vector2;
   double_vector.print(deallog.get_file_stream());

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.