* use blocks of different
* sizes.
*/
- BlockVector (unsigned int num_blocks = 0,
- unsigned int block_size = 0);
+ explicit BlockVector (unsigned int num_blocks = 0,
+ unsigned int block_size = 0);
/**
* Copy-Constructor. Dimension set to
* this function is the same as calling
* @p{reinit (V.size(), fast)}.
*/
- void reinit (const BlockVector<Number> &V,
+ template <typename Number2>
+ void reinit (const BlockVector<Number2> &V,
const bool fast=false);
/**
*/
friend class iterator;
friend class const_iterator;
+
+ template <typename Number2> friend class BlockVector;
};
template <typename Number>
-void BlockVector<Number>::reinit (const BlockVector<Number>& v,
+template <typename Number2>
+void BlockVector<Number>::reinit (const BlockVector<Number2>& v,
const bool fast)
{
block_indices = v.block_indices;
template <typename Number>
template<typename Number2>
BlockVector<Number>&
-BlockVector<Number>::operator = (const BlockVector< Number2>& v)
+BlockVector<Number>::operator = (const BlockVector<Number2>& v)
{
Assert (num_blocks == v.num_blocks,
ExcDimensionMismatch(num_blocks, v.num_blocks));
* set the damping parameter
* to one.
*/
- AdditionalData(double omega=1):
- omega(omega)
+ AdditionalData(double omega=1,
+ bool use_preconditioned_residual = true):
+ omega(omega),
+ use_preconditioned_residual(use_preconditioned_residual)
{};
/**
* Relaxation parameter.
*/
double omega;
+ /**
+ * Parameter for stopping criterion.
+ */
+ bool use_preconditioned_residual;
+
};
/**
* Implementation of the computation of
* the norm of the residual.
*/
- virtual double criterion();
+ virtual typename VECTOR::value_type criterion();
/**
* Temporary vectors, allocated through
* norm of the residual vector and thus
* the square root of the @p{res2} value.
*/
- double res;
+ typename VECTOR::value_type res;
};
// but do it in 2 steps
A.vmult(r,x);
r.sadd(-1.,1.,b);
- res=sqrt(r*r);
-
- conv = control().check (iter, criterion());
- if (conv != SolverControl::iterate)
- break;
+ if (!additional_data.use_preconditioned_residual)
+ {
+ res = r*r;
+// cout << '[' << res << ' ';
+ res=sqrt(res);
+// cout << res << ' ' << r.l1_norm() << ']';
+// r.print(cout);
+ conv = control().check (iter, criterion());
+ if (conv != SolverControl::iterate)
+ break;
+ }
+
precondition.vmult(d,r);
+ if (additional_data.use_preconditioned_residual)
+ {
+ res = d*d;
+// cout << '[' << res << ' ';
+ res=sqrt(res);
+// cout << res << ' ' << r.l1_norm() << ']';
+// r.print(cout);
+ conv = control().check (iter, criterion());
+ if (conv != SolverControl::iterate)
+ break;
+ }
x.add(additional_data.omega,d);
print_vectors(iter,x,r,d);
}
template<class VECTOR>
-inline double
+inline typename VECTOR::value_type
SolverRichardson<VECTOR>::criterion()
{
return res;
/**
* Copy-Constructor. Dimension set to
* that of V, all components are copied
- * from V
+ * from V.
+ *
+ * We would like to make this
+ * constructor explicit, but STL
+ * insists on using it implicitly.
*/
Vector (const Vector<Number>& V);
* Constructor. Set dimension to @p{n} and
* initialize all elements with zero.
*/
- Vector (const unsigned int n);
+ explicit Vector (const unsigned int n);
/**
* Initialize the vector with a
* this function is the same as calling
* @p{reinit (V.size(), fast)}.
*/
- void reinit (const Vector<Number> &V,
+ template <typename Number2>
+ void reinit (const Vector<Number2> &V,
const bool fast=false);
/**
* Pointer to the array of components.
*/
Number *val;
+
+ template <typename Number2> friend class Vector;
};
template <typename Number>
-void Vector<Number>::reinit (const Vector<Number>& v, const bool fast)
+template <typename Number2>
+void Vector<Number>::reinit (const Vector<Number2>& v, const bool fast)
{
reinit (v.size(), fast);
};
// explicit instantiations
template class BlockVector<double>;
+template BlockVector<double>& BlockVector<double>::operator=(
+ const BlockVector<float>&);
+template void BlockVector<double>::reinit(const BlockVector<double>&, bool);
+template void BlockVector<double>::reinit(const BlockVector<float>&, bool);
+
template class BlockVector<float>;
+template BlockVector<float>& BlockVector<float>::operator=(
+ const BlockVector<double>&);
+template void BlockVector<float>::reinit(const BlockVector<double>&, bool);
+template void BlockVector<float>::reinit(const BlockVector<float>&, bool);
namespace BlockVectorIterators
{
template Vector<double>& Vector<double>::operator=(const Vector<float>&);
template double Vector<double>::operator*(const Vector<float>&) const;
template double Vector<double>::operator*(const Vector<double>&) const;
+template void Vector<double>::reinit(const Vector<double>&, bool);
+template void Vector<double>::reinit(const Vector<float>&, bool);
template class Vector<float>;
template Vector<float>& Vector<float>::operator=(const Vector<double>&);
template float Vector<float>::operator*(const Vector<float>&) const;
template float Vector<float>::operator*(const Vector<double>&) const;
+template void Vector<float>::reinit(const Vector<double>&, bool);
+template void Vector<float>::reinit(const Vector<float>&, bool);
// see the .h file for why these functions are disabled.
// template Vector<float>::Vector (const Vector<double>& v);