* @<double@></tt>; others can be generated in application programs (see the
* section on @ref Instantiations in the manual).
*
- * @author Essentially everyone who has ever worked on deal.II, 1994-2004
+ * @author Essentially everyone who has ever worked on deal.II, 1994-2007
*/
template <typename number>
class SparseMatrix : public virtual Subscriptor
*/
typedef number value_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 numbers::NumberTraits<number>::real_type real_type;
+
/**
* Typedef of an STL conforming iterator
* class walking over all the nonzero
* nodal values of the finite
* element function.
*
- * Obviously, the matrix needs to
- * be quadratic for this operation.
+ * Obviously, the matrix needs to be
+ * quadratic for this operation, and for
+ * the result to actually be a norm it
+ * also needs to be either real symmetric
+ * or complex hermitian.
+ *
+ * The underlying template types of both
+ * this matrix and the given vector
+ * should either both be real or
+ * complex-valued, but not mixed, for
+ * this function to make sense.
*/
template <typename somenumber>
somenumber matrix_norm_square (const Vector<somenumber> &v) const;
template <typename somenumber>
somenumber matrix_scalar_product (const Vector<somenumber> &u,
const Vector<somenumber> &v) const;
+
/**
* Compute the residual of an
* equation <i>Mx=b</i>, where
* $|Mv|_1\leq |M|_1 |v|_1$.
* (cf. Haemmerlin-Hoffmann : Numerische Mathematik)
*/
- number l1_norm () const;
+ real_type l1_norm () const;
/**
* Return the linfty-norm of the
* $|Mv|_infty \leq |M|_infty |v|_infty$.
* (cf. Haemmerlin-Hoffmann : Numerische Mathematik)
*/
- number linfty_norm () const;
+ real_type linfty_norm () const;
/**
* Return the frobenius norm of the
* sum of squares of all entries in the
* matrix.
*/
- number frobenius_norm () const;
+ real_type frobenius_norm () const;
//@}
/**
* @name Preconditioning methods
#include <base/thread_management.h>
#include <base/multithread_info.h>
+
DEAL_II_NAMESPACE_OPEN
while (val_ptr != val_end_of_row)
s += *val_ptr++ * v(*colnum_ptr++);
- sum += s* v(row);
- };
+ sum += v(row) * numbers::NumberTraits<somenumber>::conjugate(s);
+ }
return sum;
- };
+ }
}
while (val_ptr != val_end_of_row)
s += *val_ptr++ * v(*colnum_ptr++);
- sum += s* v(row);
- };
+ sum += v(row) * numbers::NumberTraits<somenumber>::conjugate(s);
+ }
+
*partial_sum = sum;
}
while (val_ptr != val_end_of_row)
s += *val_ptr++ * v(*colnum_ptr++);
- sum += s* u(row);
- };
+ sum += u(row) * numbers::NumberTraits<somenumber>::conjugate(s);
+ }
return sum;
- };
+ }
}
while (val_ptr != val_end_of_row)
s += *val_ptr++ * v(*colnum_ptr++);
- sum += s* u(row);
- };
+ sum += u(row) * numbers::NumberTraits<somenumber>::conjugate(s);
+ }
+
*partial_sum = sum;
}
template <typename number>
-number SparseMatrix<number>::l1_norm () const
+typename SparseMatrix<number>::real_type
+SparseMatrix<number>::l1_norm () const
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Vector<number> column_sums(n());
+ Vector<real_type> column_sums(n());
const unsigned int n_rows = m();
for (unsigned int row=0; row<n_rows; ++row)
for (unsigned int j=cols->rowstart[row]; j<cols->rowstart[row+1] ; ++j)
- column_sums(cols->colnums[j]) += std::fabs(val[j]);
+ column_sums(cols->colnums[j]) += numbers::NumberTraits<number>::abs(val[j]);
return column_sums.linfty_norm();
}
template <typename number>
-number SparseMatrix<number>::linfty_norm () const
+typename SparseMatrix<number>::real_type
+SparseMatrix<number>::linfty_norm () const
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
const number *val_ptr = &val[cols->rowstart[0]];
- number sum, max=0;
+ real_type max=0;
const unsigned int n_rows = m();
for (unsigned int row=0; row<n_rows; ++row)
{
- sum=0;
+ real_type sum = 0;
const number *const val_end_of_row = &val[cols->rowstart[row+1]];
while (val_ptr != val_end_of_row)
- sum += std::fabs(*val_ptr++);
+ sum += numbers::NumberTraits<number>::abs(*val_ptr++);
if (sum > max)
max = sum;
}
template <typename number>
-number SparseMatrix<number>::frobenius_norm () const
+typename SparseMatrix<number>::real_type
+SparseMatrix<number>::frobenius_norm () const
{
// simply add up all entries in the
// sparsity pattern, without taking any
// reference to rows or columns
- number norm_sqr = 0;
+ real_type norm_sqr = 0;
const unsigned int n_rows = m();
for (const number *ptr = &val[0];
ptr != &val[cols->rowstart[n_rows]]; ++ptr)
- norm_sqr += *ptr * *ptr;
+ norm_sqr += numbers::NumberTraits<number>::abs_square(*ptr);
return std::sqrt (norm_sqr);
}
//---------------------------- sparse_matrix.inst.in ---------------------------
+// real instantiations
+
for (S : REAL_SCALARS)
{
template class SparseMatrix<S>;
template void SparseMatrix<S1>::
Tvmult_add (V1<S2> &, const V2<S3> &) const;
}
+
+
+
+// complex instantiations
+
+// for (S : COMPLEX_SCALARS)
+// {
+// template class SparseMatrix<S>;
+// }
+
+
+
+// for (S1, S2 : COMPLEX_SCALARS)
+// {
+// template SparseMatrix<S1> &
+// SparseMatrix<S1>::copy_from<S2> (const SparseMatrix<S2> &);
+
+// template
+// void SparseMatrix<S1>::copy_from<S2> (const FullMatrix<S2> &);
+
+// template void SparseMatrix<S1>::add<S2> (const S1,
+// const SparseMatrix<S2> &);
+// }
+
+
+// for (S1, S2 : COMPLEX_SCALARS)
+// {
+// template S2
+// SparseMatrix<S1>::
+// matrix_norm_square<S2> (const Vector<S2> &) const;
+
+// template S2
+// SparseMatrix<S1>::
+// matrix_scalar_product<S2> (const Vector<S2> &,
+// const Vector<S2> &) const;
+
+// template S2 SparseMatrix<S1>::
+// residual<S2> (Vector<S2> &,
+// const Vector<S2> &,
+// const Vector<S2> &) const;
+
+// template void SparseMatrix<S1>::
+// precondition_SSOR<S2> (Vector<S2> &,
+// const Vector<S2> &,
+// const S1) const;
+
+// template void SparseMatrix<S1>::
+// precondition_SOR<S2> (Vector<S2> &,
+// const Vector<S2> &,
+// const S1) const;
+
+// template void SparseMatrix<S1>::
+// precondition_TSOR<S2> (Vector<S2> &,
+// const Vector<S2> &,
+// const S1) const;
+
+// template void SparseMatrix<S1>::
+// precondition_Jacobi<S2> (Vector<S2> &,
+// const Vector<S2> &,
+// const S1) const;
+
+// template void SparseMatrix<S1>::
+// SOR<S2> (Vector<S2> &,
+// const S1) const;
+// template void SparseMatrix<S1>::
+// TSOR<S2> (Vector<S2> &,
+// const S1) const;
+// template void SparseMatrix<S1>::
+// SSOR<S2> (Vector<S2> &,
+// const S1) const;
+// template void SparseMatrix<S1>::
+// PSOR<S2> (Vector<S2> &,
+// const std::vector<unsigned int>&,
+// const std::vector<unsigned int>&,
+// const S1) const;
+// template void SparseMatrix<S1>::
+// TPSOR<S2> (Vector<S2> &,
+// const std::vector<unsigned int>&,
+// const std::vector<unsigned int>&,
+// const S1) const;
+// template void SparseMatrix<S1>::
+// SOR_step<S2> (Vector<S2> &,
+// const Vector<S2> &,
+// const S1) const;
+// template void SparseMatrix<S1>::
+// TSOR_step<S2> (Vector<S2> &,
+// const Vector<S2> &,
+// const S1) const;
+// template void SparseMatrix<S1>::
+// SSOR_step<S2> (Vector<S2> &,
+// const Vector<S2> &,
+// const S1) const;
+// }
+
+
+// for (S1, S2, S3 : COMPLEX_SCALARS;
+// V1, V2 : DEAL_II_VEC_TEMPLATES)
+// {
+// template void SparseMatrix<S1>::
+// vmult (V1<S2> &, const V2<S3> &) const;
+// template void SparseMatrix<S1>::
+// Tvmult (V1<S2> &, const V2<S3> &) const;
+// template void SparseMatrix<S1>::
+// vmult_add (V1<S2> &, const V2<S3> &) const;
+// template void SparseMatrix<S1>::
+// Tvmult_add (V1<S2> &, const V2<S3> &) const;
+// }