// $Id$
// Version: $Name$
//
-// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
* class.
*/
typedef typename BaseClass::value_type value_type;
+ typedef typename BaseClass::real_type real_type;
typedef typename BaseClass::pointer pointer;
typedef typename BaseClass::const_pointer const_pointer;
typedef typename BaseClass::reference reference;
// $Id$
// Version: $Name$
//
-// Copyright (C) 2004, 2005, 2006 by the deal.II authors
+// Copyright (C) 2004, 2005, 2006, 2007 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
* @author Wolfgang Bangerth, Guido Kanschat, 1999, 2000, 2001, 2002, 2004
*/
template <class VectorType>
-class BlockVectorBase
- : public Subscriptor
+class BlockVectorBase : public Subscriptor
{
public:
/**
typedef std::size_t size_type;
+ /**
+ * Declare a type that has holds
+ * real-valued numbers with the
+ * same precision as the template
+ * argument to this class. If the
+ * template argument of this
+ * class is a real data type,
+ * then real_type equals the
+ * template argument. If the
+ * template argument is a
+ * std::complex type then
+ * real_type equals the type
+ * underlying the complex
+ * numbers.
+ *
+ * This typedef is used to
+ * represent the return type of
+ * norms.
+ */
+ typedef typename BlockType::real_type real_type;
+
/**
* Default constructor.
*/
/**
* Return square of the $l_2$-norm.
*/
- value_type norm_sqr () const;
+ real_type norm_sqr () const;
/**
* Return the mean value of the elements
* Return the $l_1$-norm of the vector,
* i.e. the sum of the absolute values.
*/
- value_type l1_norm () const;
+ real_type l1_norm () const;
/**
* Return the $l_2$-norm of the vector,
* i.e. the square root of the sum of
* the squares of the elements.
*/
- value_type l2_norm () const;
+ real_type l2_norm () const;
/**
* Return the maximum absolute value of
* the elements of this vector, which is
* the $l_\infty$-norm of a vector.
*/
- value_type linfty_norm () const;
+ real_type linfty_norm () const;
/**
* Return whether the vector contains only
template <class VectorType>
-typename BlockVectorBase<VectorType>::value_type
+typename BlockVectorBase<VectorType>::real_type
BlockVectorBase<VectorType>::norm_sqr () const
{
- value_type sum = 0.;
+ real_type sum = 0.;
for (unsigned int i=0;i<n_blocks();++i)
sum += components[i].norm_sqr();
template <class VectorType>
-typename BlockVectorBase<VectorType>::value_type
+typename BlockVectorBase<VectorType>::real_type
BlockVectorBase<VectorType>::l1_norm () const
{
- value_type sum = 0.;
+ real_type sum = 0.;
for (unsigned int i=0;i<n_blocks();++i)
sum += components[i].l1_norm();
template <class VectorType>
-typename BlockVectorBase<VectorType>::value_type
+typename BlockVectorBase<VectorType>::real_type
BlockVectorBase<VectorType>::l2_norm () const
{
return std::sqrt(norm_sqr());
template <class VectorType>
-typename BlockVectorBase<VectorType>::value_type
+typename BlockVectorBase<VectorType>::real_type
BlockVectorBase<VectorType>::linfty_norm () const
{
- value_type sum = 0.;
+ real_type sum = 0.;
for (unsigned int i=0;i<n_blocks();++i)
{
value_type newval = components[i].linfty_norm();
// $Id$
// Version: $Name$
//
-// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors
+// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
DEAL_II_NAMESPACE_OPEN
-// explicit instantiations
+// explicit instantiations for real data types
template class BlockVector<double>;
template class BlockVector<float>;
template void BlockVector<float>::reinit<float>(const BlockVector<float>&,
const bool);
+// explicit instantiations for complex data types
+template class BlockVector<std::complex<double> >;
+template class BlockVector<std::complex<float> >;
+
+#ifndef DEAL_II_EXPLICIT_CONSTRUCTOR_BUG
+template BlockVector<std::complex<double> >::BlockVector (const BlockVector<std::complex<float> > &);
+template BlockVector<std::complex<float> >::BlockVector (const BlockVector<std::complex<double> > &);
+#endif
+
+template void BlockVector<std::complex<double> >::reinit<std::complex<double> >(const BlockVector<std::complex<double> >&,
+ const bool);
+template void BlockVector<std::complex<double> >::reinit<std::complex<float> >(const BlockVector<std::complex<float> >&,
+ const bool);
+
+template void BlockVector<std::complex<float> >::reinit<std::complex<double> >(const BlockVector<std::complex<double> >&,
+ const bool);
+template void BlockVector<std::complex<float> >::reinit<std::complex<float> >(const BlockVector<std::complex<float> >&,
+ const bool);
+
DEAL_II_NAMESPACE_CLOSE
############################################################
tests_x = vector-vector \
- full_matrix householder \
- tridiagonal_matrix tridiagonal_matrix_sym \
- sparsity_pattern sparse_matrices matrices \
+ full_matrix \
+ householder \
+ tridiagonal_matrix \
+ tridiagonal_matrix_sym \
+ sparsity_pattern \
+ sparse_matrices matrices \
block_sparsity_pattern_01 \
- block_indices block_vector block_vector_* block_matrices \
- matrix_lib matrix_out pointer_matrix pointer_matrix_vector \
- solver eigen filtered_matrix \
- sparse_ilu sparse_ilu_t lapack_fill block_minres \
- identity_matrix* trace \
+ block_indices \
+ block_vector \
+ block_vector_* \
+ block_matrices \
+ matrix_lib \
+ matrix_out \
+ pointer_matrix \
+ pointer_matrix_vector \
+ solver \
+ eigen \
+ filtered_matrix \
+ sparse_ilu \
+ sparse_ilu_t \
+ lapack_fill \
+ block_minres \
+ identity_matrix* \
+ trace \
print_formatted_* \
- bicgstab_early
+ bicgstab_early \
+ complex*
# from above list of regular expressions, generate the real set of
--- /dev/null
+//--------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007 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.
+//
+//--------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <lac/block_sparsity_pattern.h>
+#include <lac/block_sparse_matrix.h>
+#include <lac/block_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+#include <list>
+
+void test ()
+{
+ deallog.push("BlockIndices");
+
+ std::vector<unsigned int> ivector(4);
+ ivector[0] = 3;
+ ivector[1] = 0;
+ ivector[2] = 1;
+ ivector[3] = 2;
+
+ const std::vector<unsigned int> vector_indices(ivector);
+
+ BlockIndices i1(ivector);
+ BlockIndices i2 = i1;
+ BlockIndices i3;
+ // no output expected here
+ deallog.push("empty constructor");
+ for (unsigned int i=0 ; i<i3.size() ; ++i)
+ deallog << i << '\t' << i3.local_to_global(i,0) << std::endl;
+ for (unsigned int i=0 ; i<i3.total_size() ; ++i)
+ deallog << i
+ << '\t' << i3.global_to_local(i).first
+ << '\t' << i3.global_to_local(i).second
+ << std::endl;
+ deallog.pop();
+
+
+ i3.reinit(ivector);
+
+ deallog.push("global->local");
+
+ unsigned int n = i1.total_size();
+ for (unsigned int i=0;i<n;++i)
+ {
+ deallog << i
+ << '\t' << i1.global_to_local(i).first
+ << '\t' << i1.global_to_local(i).second
+ << '\t' << i2.global_to_local(i).first
+ << '\t' << i2.global_to_local(i).second
+ << '\t' << i3.global_to_local(i).first
+ << '\t' << i3.global_to_local(i).second
+ << std::endl;
+ }
+
+ deallog.pop();
+
+ deallog.push("local->global");
+ for (unsigned int i=0 ; i<i1.size() ; ++i)
+ for (unsigned int j=0 ; j<ivector[i] ; ++j)
+ deallog << i << '\t' << j << '\t'
+ << i1.local_to_global(i,j) << std::endl;
+
+ deallog.pop();
+
+ deallog.push("reinit");
+
+ ivector.insert(ivector.begin(), 5);
+ i1.reinit(ivector);
+ n = i1.total_size();
+ for (unsigned int i=0;i<n;++i)
+ {
+ deallog << i
+ << '\t' << i1.global_to_local(i).first
+ << '\t' << i1.global_to_local(i).second
+ << std::endl;
+ }
+ deallog << "---" << std::endl;
+
+ ivector.erase(ivector.begin());
+ ivector.erase(ivector.begin());
+ ivector.erase(ivector.begin());
+ i1.reinit(ivector);
+ n = i1.total_size();
+ for (unsigned int i=0;i<n;++i)
+ {
+ deallog << i
+ << '\t' << i1.global_to_local(i).first
+ << '\t' << i1.global_to_local(i).second
+ << std::endl;
+ }
+ deallog.pop();
+
+ deallog.pop ();
+ deallog.push("BlockVector");
+ // initialization by an iterator
+ // range. first for real-valued
+ // arguments in a complex-valued
+ // vector
+ {
+ deallog.push ("Constructor with iterators");
+ double array[] = { 0, 1, 2, 3, 4, 5 };
+ BlockVector<std::complex<double> > v1(vector_indices, &array[0], &array[6]);
+ for (unsigned int i=0; i<v1.size(); ++i)
+ deallog << v1(i) << ' ';
+ deallog << std::endl;
+
+ // same test, but do not initialize
+ // from double*'s, but from
+ // std::list iterators.
+ std::list<double> l(&array[0], &array[6]);
+ BlockVector<std::complex<double> > v2(vector_indices, l.begin(), l.end());
+ for (unsigned int i=0; i<v2.n_blocks(); ++i)
+ for (unsigned int j=0;j<v2.block(i).size();++j)
+ deallog << i << '\t' << j << '\t' <<v2.block(i)(j) << std::endl;
+
+ deallog.pop();
+
+ deallog.push("reinit block");
+ v2.block(1).reinit(5);
+ v2.collect_sizes();
+ for (unsigned int i=0; i<v2.size(); ++i)
+ deallog << v2(i) << ' ';
+ deallog << std::endl;
+ deallog.pop ();
+ }
+
+ // now the same with complex-valued
+ // arguments
+ {
+ deallog.push ("Constructor with iterators");
+ std::complex<double> array[] = { std::complex<double>(0,1),
+ std::complex<double>(1,2),
+ std::complex<double>(2,3),
+ std::complex<double>(3,4),
+ std::complex<double>(4,5),
+ std::complex<double>(5,6) };
+ BlockVector<std::complex<double> > v1(vector_indices, &array[0], &array[6]);
+ for (unsigned int i=0; i<v1.size(); ++i)
+ deallog << v1(i) << ' ';
+ deallog << std::endl;
+
+ // same test, but do not initialize
+ // from double*'s, but from
+ // std::list iterators.
+ std::list<std::complex<double> > l(&array[0], &array[6]);
+ BlockVector<std::complex<double> > v2(vector_indices, l.begin(), l.end());
+ for (unsigned int i=0; i<v2.n_blocks(); ++i)
+ for (unsigned int j=0;j<v2.block(i).size();++j)
+ deallog << i << '\t' << j << '\t' <<v2.block(i)(j) << std::endl;
+
+ deallog.pop();
+
+ deallog.push("reinit block");
+ v2.block(1).reinit(5);
+ v2.collect_sizes();
+ for (unsigned int i=0; i<v2.size(); ++i)
+ deallog << v2(i) << ' ';
+ deallog << std::endl; deallog.pop ();
+ }
+
+ deallog.pop ();
+}
+
+
+
+
+int main ()
+{
+ std::ofstream logfile("complex_block_vector/output");
+ logfile.setf(std::ios::fixed);
+ logfile.precision(3);
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ // do the same weird stuff as in
+ // tests/base/reference.cc
+#if __GNUC__ != 2
+ std::basic_streambuf<char> *old_cerr_buf = std::cerr.rdbuf();
+#else
+ streambuf *old_cerr_buf = std::cerr.rdbuf();
+#endif
+ std::cerr.rdbuf(logfile.rdbuf());
+
+ 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 0;
+ }
+ catch (...)
+ {
+ std::cerr << std::endl << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ std::cerr << "Unknown exception!" << std::endl
+ << "Aborting!" << std::endl
+ << "----------------------------------------------------"
+ << std::endl;
+ // abort
+ return 0;
+ };
+
+ std::cerr.rdbuf(old_cerr_buf);
+}
+
--- /dev/null
+
+DEAL:BlockIndices:global->local::0 0 0 0 0 0 0
+DEAL:BlockIndices:global->local::1 0 1 0 1 0 1
+DEAL:BlockIndices:global->local::2 0 2 0 2 0 2
+DEAL:BlockIndices:global->local::3 2 0 2 0 2 0
+DEAL:BlockIndices:global->local::4 3 0 3 0 3 0
+DEAL:BlockIndices:global->local::5 3 1 3 1 3 1
+DEAL:BlockIndices:local->global::0 0 0
+DEAL:BlockIndices:local->global::0 1 1
+DEAL:BlockIndices:local->global::0 2 2
+DEAL:BlockIndices:local->global::2 0 3
+DEAL:BlockIndices:local->global::3 0 4
+DEAL:BlockIndices:local->global::3 1 5
+DEAL:BlockIndices:reinit::0 0 0
+DEAL:BlockIndices:reinit::1 0 1
+DEAL:BlockIndices:reinit::2 0 2
+DEAL:BlockIndices:reinit::3 0 3
+DEAL:BlockIndices:reinit::4 0 4
+DEAL:BlockIndices:reinit::5 1 0
+DEAL:BlockIndices:reinit::6 1 1
+DEAL:BlockIndices:reinit::7 1 2
+DEAL:BlockIndices:reinit::8 3 0
+DEAL:BlockIndices:reinit::9 4 0
+DEAL:BlockIndices:reinit::10 4 1
+DEAL:BlockIndices:reinit::---
+DEAL:BlockIndices:reinit::0 0 0
+DEAL:BlockIndices:reinit::1 1 0
+DEAL:BlockIndices:reinit::2 1 1
+DEAL:BlockVector:Constructor with iterators::(0.000,0.000) (1.000,0.000) (2.000,0.000) (3.000,0.000) (4.000,0.000) (5.000,0.000)
+DEAL:BlockVector:Constructor with iterators::0 0 (0.000,0.000)
+DEAL:BlockVector:Constructor with iterators::0 1 (1.000,0.000)
+DEAL:BlockVector:Constructor with iterators::0 2 (2.000,0.000)
+DEAL:BlockVector:Constructor with iterators::2 0 (3.000,0.000)
+DEAL:BlockVector:Constructor with iterators::3 0 (4.000,0.000)
+DEAL:BlockVector:Constructor with iterators::3 1 (5.000,0.000)
+DEAL:BlockVector:reinit block::(0.000,0.000) (1.000,0.000) (2.000,0.000) (0.000,0.000) (0.000,0.000) (0.000,0.000) (0.000,0.000) (0.000,0.000) (3.000,0.000) (4.000,0.000) (5.000,0.000)
+DEAL:BlockVector:Constructor with iterators::(0.000,1.000) (1.000,2.000) (2.000,3.000) (3.000,4.000) (4.000,5.000) (5.000,6.000)
+DEAL:BlockVector:Constructor with iterators::0 0 (0.000,1.000)
+DEAL:BlockVector:Constructor with iterators::0 1 (1.000,2.000)
+DEAL:BlockVector:Constructor with iterators::0 2 (2.000,3.000)
+DEAL:BlockVector:Constructor with iterators::2 0 (3.000,4.000)
+DEAL:BlockVector:Constructor with iterators::3 0 (4.000,5.000)
+DEAL:BlockVector:Constructor with iterators::3 1 (5.000,6.000)
+DEAL:BlockVector:reinit block::(0.000,1.000) (1.000,2.000) (2.000,3.000) (0.000,0.000) (0.000,0.000) (0.000,0.000) (0.000,0.000) (0.000,0.000) (3.000,4.000) (4.000,5.000) (5.000,6.000)
--- /dev/null
+
+DEAL:BlockIndices:global->local::0 0 0 0 0 0 0
+DEAL:BlockIndices:global->local::1 0 1 0 1 0 1
+DEAL:BlockIndices:global->local::2 0 2 0 2 0 2
+DEAL:BlockIndices:global->local::3 2 0 2 0 2 0
+DEAL:BlockIndices:global->local::4 3 0 3 0 3 0
+DEAL:BlockIndices:global->local::5 3 1 3 1 3 1
+DEAL:BlockIndices:local->global::0 0 0
+DEAL:BlockIndices:local->global::0 1 1
+DEAL:BlockIndices:local->global::0 2 2
+DEAL:BlockIndices:local->global::2 0 3
+DEAL:BlockIndices:local->global::3 0 4
+DEAL:BlockIndices:local->global::3 1 5
+DEAL:BlockIndices:reinit::0 0 0
+DEAL:BlockIndices:reinit::1 0 1
+DEAL:BlockIndices:reinit::2 0 2
+DEAL:BlockIndices:reinit::3 0 3
+DEAL:BlockIndices:reinit::4 0 4
+DEAL:BlockIndices:reinit::5 1 0
+DEAL:BlockIndices:reinit::6 1 1
+DEAL:BlockIndices:reinit::7 1 2
+DEAL:BlockIndices:reinit::8 3 0
+DEAL:BlockIndices:reinit::9 4 0
+DEAL:BlockIndices:reinit::10 4 1
+DEAL:BlockIndices:reinit::---
+DEAL:BlockIndices:reinit::0 0 0
+DEAL:BlockIndices:reinit::1 1 0
+DEAL:BlockIndices:reinit::2 1 1
+DEAL:BlockIndices::Range
+--------------------------------------------------------
+An error occurred in file <block_indices.h> in function
+ (not available)
+The violated condition was:
+ i<total_size()
+The name and call sequence of the exception was:
+ ExcIndexRange(i, 0, total_size())
+Additional Information:
+Index 3 is not in [0,3[
+--------------------------------------------------------
+DEAL:BlockIndices::Abort!!!
+--------------------------------------------------------
+An error occurred in file <block_indices.h> in function
+ (not available)
+The violated condition was:
+ index < start_indices[block+1]-start_indices[block]
+The name and call sequence of the exception was:
+ ExcIndexRange (index, 0, start_indices[block+1]-start_indices[block])
+Additional Information:
+Index 2 is not in [0,2[
+--------------------------------------------------------
+DEAL:BlockIndices::Abort!!!
+--------------------------------------------------------
+An error occurred in file <block_indices.h> in function
+ (not available)
+The violated condition was:
+ block < n_blocks
+The name and call sequence of the exception was:
+ ExcIndexRange(block, 0, n_blocks)
+Additional Information:
+Index 2 is not in [0,2[
+--------------------------------------------------------
+DEAL:BlockIndices::Abort!!!
+DEAL:BlockVector:Constructor with iterators::0.000 1.000 2.000 3.000 4.000 5.000
+DEAL:BlockVector:Constructor with iterators::0 0 0.000
+DEAL:BlockVector:Constructor with iterators::0 1 1.000
+DEAL:BlockVector:Constructor with iterators::0 2 2.000
+DEAL:BlockVector:Constructor with iterators::2 0 3.000
+DEAL:BlockVector:Constructor with iterators::3 0 4.000
+DEAL:BlockVector:Constructor with iterators::3 1 5.000
+DEAL:BlockVector:reinit block::0.000 1.000 2.000 0.000 0.000 0.000 0.000 0.000 3.000 4.000 5.000
--- /dev/null
+//--------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007 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.
+//
+//--------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include <base/logstream.h>
+#include <lac/block_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <numeric>
+#include <utility>
+#include <cmath>
+
+template <typename number>
+bool operator == (const BlockVector<number> &v1,
+ const BlockVector<number> &v2)
+{
+ if (v1.size() != v2.size())
+ return false;
+ for (unsigned int i=0; i<v1.size(); ++i)
+ if (v1(i) != v2(i))
+ return false;
+ return true;
+}
+
+
+void test ()
+{
+ std::vector<unsigned int> ivector(4);
+ ivector[0] = 2;
+ ivector[1] = 4;
+ ivector[2] = 3;
+ ivector[3] = 5;
+
+ // Check 1: initialization via
+ // iterators
+ if (true)
+ {
+ BlockVector<std::complex<double> > v1(ivector);
+ BlockVector<std::complex<double> > v2(ivector);
+
+ // initialize first vector with
+ // simple loop
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = std::complex<double>(i,i+1);
+ // initialize other vector
+ // through iterators
+ BlockVector<std::complex<double> >::iterator p2 = v2.begin();
+ for (unsigned int i=0; i<v1.size(); ++i, ++p2)
+ *p2 = std::complex<double>(i,i+1);
+ Assert (p2==v2.end(), ExcInternalError());
+
+ // check that the two vectors are equal
+ deallog << "Check 1: " << (v1==v2 ? "true" : "false") << std::endl;
+ };
+
+ // Check 1: initialization via
+ // iterators
+ if (true)
+ {
+ BlockVector<std::complex<double> > v1(ivector);
+
+ // initialize first vector with
+ // simple loop
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = std::complex<double>(i,i+1);
+ // initialize other vector
+ // through iterators into first
+ // vector
+ BlockVector<std::complex<double> > v2(ivector, v1.begin(), v1.end());
+ // check that the two vectors are equal
+ deallog << "Check 2: " << (v1==v2 ? "true" : "false") << std::endl;
+ };
+
+ // Check 3: loop forward and back
+ // and check that things are the
+ // same
+ if (true)
+ {
+ BlockVector<std::complex<double> > v1(ivector);
+ // initialize first vector with
+ // simple loop
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = std::complex<double>(i,i+1);
+
+ BlockVector<std::complex<double> >::iterator p1 = v1.begin();
+ for (unsigned int i=0; i<v1.size(); ++i, ++p1)
+ Assert (*p1 == std::complex<double>(i,i+1), ExcInternalError());
+
+ Assert (p1 == v1.end(), ExcInternalError());
+
+ // move back into allowable
+ // region
+ --p1;
+
+ // check backwards
+ for (unsigned int i=0; i<v1.size(); ++i, --p1)
+ Assert (*p1 == std::complex<double>(v1.size()-i-1, v1.size()-i), ExcInternalError());
+
+ // if we came thus far,
+ // everything is alright
+ deallog << "Check 3: true" << std::endl;
+ };
+
+
+ // Check 4: same, but this time
+ // with const iterators
+ if (true)
+ {
+ BlockVector<std::complex<double> > v1(ivector);
+ // initialize first vector with
+ // simple loop
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = i;
+
+ BlockVector<std::complex<double> >::const_iterator p1 = v1.begin();
+ for (unsigned int i=0; i<v1.size(); ++i, ++p1)
+ Assert (*p1 == std::complex<double>(i,0), ExcInternalError());
+
+ Assert (p1 == v1.end(), ExcInternalError());
+
+ // move back into allowable
+ // region
+ --p1;
+
+ // check backwards
+ for (unsigned int i=0; i<v1.size(); ++i, --p1)
+ {
+ const std::complex<double> val = *p1;
+ const std::complex<double> ref(v1.size()-i-1);
+ Assert (val==ref, ExcInternalError());
+ };
+
+ // if we came thus far,
+ // everything is alright
+ deallog << "Check 4: true" << std::endl;
+ };
+
+ // Checks 5-14: use some standard
+ // algorithms
+ if (true)
+ {
+ BlockVector<std::complex<double> > v1(ivector);
+ // initialize first vector with
+ // simple loop
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = i;
+
+ // check std::distance
+ // algorithm
+ deallog << "Check 5: "
+ << (std::distance (v1.begin(), v1.end()) ==
+ static_cast<signed int>(v1.size()) ?
+ "true" : "false")
+ << std::endl;
+
+ // check std::copy
+ BlockVector<std::complex<double> > v2(ivector);
+ std::copy (v1.begin(), v1.end(), v2.begin());
+ deallog << "Check 6: " << (v1 == v2 ? "true" : "false") << std::endl;
+
+ // check std::transform
+ std::transform (v1.begin(), v1.end(), v2.begin(),
+ std::bind2nd (std::multiplies<std::complex<double> >(),
+ 2.0));
+ v2.scale (std::complex<double>(1./2.));
+ deallog << "Check 7: " << (v1 == v2 ? "true" : "false") << std::endl;
+
+
+ // check operators +/-, +=/-=
+ deallog << "Check 8: "
+ << (std::distance(v1.begin(), v1.begin()+3) == 3 ?
+ "true" : "false")
+ << std::endl;
+ deallog << "Check 9: "
+ << (std::distance(v1.end()-6, v1.end()) == 6 ?
+ "true" : "false")
+ << std::endl;
+ deallog << "Check 10: "
+ << (std::distance(v1.begin(), v1.end()) == (signed)v1.size() ?
+ "true" : "false")
+ << std::endl;
+ deallog << "Check 11: "
+ << (std::distance(v1.begin(), (v1.begin()+=7)) == 7 ?
+ "true" : "false")
+ << std::endl;
+ deallog << "Check 12: "
+ << (std::distance((v1.end()-=4), v1.end()) == 4 ?
+ "true" : "false")
+ << std::endl;
+
+ // check advance
+ BlockVector<std::complex<double> >::iterator p2 = v1.begin();
+ std::advance (p2, v1.size());
+ deallog << "Check 13: " << (p2 == v1.end() ? "true" : "false") << std::endl;
+
+ BlockVector<std::complex<double> >::const_iterator p3 = v1.begin();
+ std::advance (p3, v1.size());
+ deallog << "Check 14: " << (p3 == v1.end() ? "true" : "false") << std::endl;
+ };
+
+ // Check 15: initialization through
+ // iterators
+ if (true)
+ {
+ BlockVector<std::complex<double> > v1(ivector);
+ // initialize first vector with
+ // simple loop
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = i;
+
+ // initialize a normal vector
+ // from it
+ Vector<std::complex<double> > v2(v1.begin(), v1.end());
+
+ // and reverse way
+ BlockVector<std::complex<double> > v3(ivector, v2.begin(), v2.end());
+ deallog << "Check 15: " << (v1==v3 ? "true" : "false") << std::endl;
+ };
+
+ // Check 16: initialization through
+ // iterators. variant with one
+ // constant object
+ if (true)
+ {
+ BlockVector<std::complex<double> > v1(ivector);
+ // initialize first vector with
+ // simple loop
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = i;
+
+ // initialize a normal vector
+ // from it
+ const Vector<std::complex<double> > v2(v1.begin(), v1.end());
+
+ // and reverse way
+ BlockVector<std::complex<double> > v3(ivector, v2.begin(), v2.end());
+ deallog << "Check 16: " << (v1==v3 ? "true" : "false") << std::endl;
+ };
+
+ // Check 17: initialization through
+ // iterators. variant with two
+ // constant object
+ if (true)
+ {
+ BlockVector<std::complex<double> > v1(ivector);
+ // initialize first vector with
+ // simple loop
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = i;
+
+ // initialize a normal vector
+ // from it
+ const Vector<std::complex<double> > v2(v1.begin(), v1.end());
+
+ // and reverse way
+ const BlockVector<std::complex<double> > v3(ivector, v2.begin(), v2.end());
+ deallog << "Check 17: " << (v1==v3 ? "true" : "false") << std::endl;
+ };
+
+ // Check 18: initialization through
+ // iterators. variant with three
+ // constant object
+ if (true)
+ {
+ BlockVector<std::complex<double> > v0(ivector);
+ // initialize first vector with
+ // simple loop
+ for (unsigned int i=0; i<v0.size(); ++i)
+ v0(i) = i;
+
+ const BlockVector<std::complex<double> > v1 = v0;
+
+ // initialize a normal vector
+ // from it
+ const Vector<std::complex<double> > v2(v1.begin(), v1.end());
+
+ // and reverse way
+ const BlockVector<std::complex<double> > v3(ivector, v2.begin(), v2.end());
+ deallog << "Check 18: " << (v1==v3 ? "true" : "false") << std::endl;
+ };
+
+ // Check 19: operator[]
+ if (true)
+ {
+ BlockVector<std::complex<double> > v1(ivector);
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = i;
+
+ for (unsigned int i=0; i<v1.size(); ++i)
+ {
+ const BlockVector<std::complex<double> >::iterator p = (v1.begin()+i);
+ for (unsigned int j=0; j<v1.size(); ++j)
+ Assert (p[(signed)j-(signed)i] == std::complex<double>(j), ExcInternalError());
+ };
+
+ // if we came thus far,
+ // everything is alright
+ deallog << "Check 19: true" << std::endl;
+ };
+}
+
+
+
+
+
+int main ()
+{
+ std::ofstream logfile("complex_block_vector_iterator/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;
+}
+
--- /dev/null
+
+DEAL::Check 1: true
+DEAL::Check 2: true
+DEAL::Check 3: true
+DEAL::Check 4: true
+DEAL::Check 5: true
+DEAL::Check 6: true
+DEAL::Check 7: true
+DEAL::Check 8: true
+DEAL::Check 9: true
+DEAL::Check 10: true
+DEAL::Check 11: true
+DEAL::Check 12: true
+DEAL::Check 13: true
+DEAL::Check 14: true
+DEAL::Check 15: true
+DEAL::Check 16: true
+DEAL::Check 17: true
+DEAL::Check 18: true
+DEAL::Check 19: true
--- /dev/null
+//--------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2006, 2007 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 <base/logstream.h>
+#include <lac/block_vector.h>
+#include <fstream>
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <numeric>
+#include <utility>
+#include <cmath>
+
+template <typename Vector1, typename Vector2>
+bool operator == (const Vector1 &v1,
+ const Vector2 &v2)
+{
+ if (v1.size() != v2.size())
+ return false;
+ for (unsigned int i=0; i<v1.size(); ++i)
+ if (v1(i) != v2(i))
+ return false;
+ return true;
+}
+
+
+void test ()
+{
+ std::vector<unsigned int> ivector(4);
+ ivector[0] = 2;
+ ivector[1] = 4;
+ ivector[2] = 3;
+ ivector[3] = 5;
+
+ BlockVector<std::complex<double> > v1(ivector);
+ Vector<std::complex<double> > v2(v1.size());
+
+ for (unsigned int i=0; i<v1.size(); ++i)
+ v1(i) = 1+i*i;
+
+ v2 = v1;
+ Assert (v1==v2, ExcInternalError());
+
+ BlockVector<std::complex<double> > v3 (ivector);
+ v3 = v2;
+ Assert (v3==v2, ExcInternalError());
+ Assert (v3==v1, ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+
+
+int main ()
+{
+ std::ofstream logfile("complex_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;
+}
+
--- /dev/null
+
+DEAL::OK