Improved: All matrix (and some vector) classes now check whether
diff --git a/deal.II/lac/include/lac/block_vector.h b/deal.II/lac/include/lac/block_vector.h
index 495e127337..c90d7675ba 100644
--- a/deal.II/lac/include/lac/block_vector.h
+++ b/deal.II/lac/include/lac/block_vector.h
@@ -187,7 +187,14 @@ class BlockVector : public BlockVectorBase >
BlockVector &
operator= (const BlockVector &V);
- /**
+ /**
+ * Copy a regular vector into a
+ * block vector.
+ */
+ BlockVector &
+ operator= (const Vector &V);
+
+ /**
* Reinitialize the BlockVector to
* contain num_blocks blocks of
* size block_size each.
@@ -443,6 +450,17 @@ BlockVector::operator = (const BlockVector &v)
+template
+inline
+BlockVector &
+BlockVector::operator = (const Vector &v)
+{
+ BaseClass::operator = (v);
+ return *this;
+}
+
+
+
template
template
inline
diff --git a/deal.II/lac/include/lac/block_vector_base.h b/deal.II/lac/include/lac/block_vector_base.h
index eb97e4bad4..7e46c5c323 100644
--- a/deal.II/lac/include/lac/block_vector_base.h
+++ b/deal.II/lac/include/lac/block_vector_base.h
@@ -806,6 +806,13 @@ class BlockVectorBase
BlockVectorBase &
operator= (const BlockVectorBase &V);
+ /**
+ * Copy operator from non-block
+ * vectors to block vectors.
+ */
+ BlockVectorBase &
+ operator = (const VectorType &v);
+
/**
* Check for equality of two block vector
* types. This operation is only allowed
@@ -2067,6 +2074,7 @@ void BlockVectorBase::equ (const value_type a,
}
+
template
BlockVectorBase&
BlockVectorBase::operator = (const value_type s)
@@ -2090,9 +2098,8 @@ BlockVectorBase::operator = (const BlockVectorBase& v)
ExcDimensionMismatch(n_blocks(), v.n_blocks()));
for (unsigned int i=0;i::operator = (const BlockVectorBase &v)
+template
+BlockVectorBase&
+BlockVectorBase::operator = (const VectorType &v)
+{
+ Assert (size() == v.size(),
+ ExcDimensionMismatch(size(), v.size()));
+
+ unsigned int index_v = 0;
+ for (unsigned int b=0;b
template
inline
diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h
index 4f2fcf7912..c02041b365 100644
--- a/deal.II/lac/include/lac/vector.h
+++ b/deal.II/lac/include/lac/vector.h
@@ -34,6 +34,10 @@ namespace PETScWrappers
template class LAPACKFullMatrix;
+template class BlockVector;
+
+
+
/*! @addtogroup Vectors
*@{
*/
@@ -307,6 +311,13 @@ class Vector :
template
Vector & operator= (const Vector &v);
+ /**
+ * Copy operator for assigning a
+ * block vector to a regular
+ * vector.
+ */
+ Vector & operator= (const BlockVector &v);
+
#ifdef DEAL_II_USE_PETSC
/**
* Another copy operator: copy the values
diff --git a/deal.II/lac/include/lac/vector.templates.h b/deal.II/lac/include/lac/vector.templates.h
index dc188728ae..887c02bafb 100644
--- a/deal.II/lac/include/lac/vector.templates.h
+++ b/deal.II/lac/include/lac/vector.templates.h
@@ -15,6 +15,7 @@
#include
+#include
#ifdef DEAL_II_USE_PETSC
# include
@@ -672,7 +673,7 @@ void Vector::ratio (const Vector &a, const Vector &b)
template
-Vector&
+Vector &
Vector::operator = (const Vector& v)
{
if (v.vec_size != vec_size)
@@ -687,7 +688,7 @@ Vector::operator = (const Vector& v)
template
template
-Vector&
+Vector &
Vector::operator = (const Vector& v)
{
if (v.size() != vec_size)
@@ -700,6 +701,23 @@ Vector::operator = (const Vector& v)
+template
+Vector &
+Vector::operator = (const BlockVector& v)
+{
+ if (v.size() != vec_size)
+ reinit (v.size(), true);
+
+ unsigned int this_index = 0;
+ for (unsigned int b=0; b
diff --git a/tests/lac/Makefile b/tests/lac/Makefile
index beaca1e4f3..91fe46527d 100644
--- a/tests/lac/Makefile
+++ b/tests/lac/Makefile
@@ -24,10 +24,11 @@ tests_x = vector-vector \
full_matrix householder tridiagonal_matrix \
sparsity_pattern sparse_matrices matrices \
block_sparsity_pattern_01 \
- block_vector block_vector_iterator block_matrices \
+ block_vector block_vector_* block_matrices \
matrix_lib matrix_out \
solver eigen \
- sparse_ilu sparse_ilu_t lapack lapack_fill block_minres
+ sparse_ilu sparse_ilu_t lapack lapack_fill block_minres \
+ amg_*
# from above list of regular expressions, generate the real set of
diff --git a/tests/lac/block_vector_vector_assign.cc b/tests/lac/block_vector_vector_assign.cc
new file mode 100644
index 0000000000..032de9f8d6
--- /dev/null
+++ b/tests/lac/block_vector_vector_assign.cc
@@ -0,0 +1,110 @@
+//--------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2006 by the deal.II authors
+//
+// This file is subject to QPL and may not be distributed
+// without copyright and license information. Please refer
+// to the file deal.II/doc/license.html for the text and
+// further information on this license.
+//
+//--------------------------------------------------------------------
+
+// check assignment between block vectors and regular vectors
+
+#include "../tests.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+template
+bool operator == (const Vector1 &v1,
+ const Vector2 &v2)
+{
+ if (v1.size() != v2.size())
+ return false;
+ for (unsigned int i=0; i ivector(4);
+ ivector[0] = 2;
+ ivector[1] = 4;
+ ivector[2] = 3;
+ ivector[3] = 5;
+
+ BlockVector v1(ivector);
+ Vector v2(v1.size());
+
+ for (unsigned int i=0; i v3 (ivector);
+ v3 = v2;
+ Assert (v3==v2, ExcInternalError());
+ Assert (v3==v1, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+
+
+int main ()
+{
+ std::ofstream logfile("block_vector_vector_assign/output");
+ logfile.setf(std::ios::fixed);
+ logfile.precision(3);
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ try
+ {
+ test ();
+ }
+ catch (std::exception &e)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Exception on processing: " << e.what() << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ // abort
+ return 2;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ // abort
+ return 3;
+ };
+
+
+ return 0;
+}
+
diff --git a/tests/lac/block_vector_vector_assign/cmp/generic b/tests/lac/block_vector_vector_assign/cmp/generic
new file mode 100644
index 0000000000..0fd8fc12f0
--- /dev/null
+++ b/tests/lac/block_vector_vector_assign/cmp/generic
@@ -0,0 +1,2 @@
+
+DEAL::OK