* element in the <i>i</i>th
* row. This function throws an
* error if the matrix is not
- * quadratic (see
- * ChunkSparsityPattern::optimize_diagonal()).
+ * quadratic.
*
* This function is considerably
* faster than the operator()(),
number ChunkSparseMatrix<number>::diag_element (const unsigned int i) const
{
Assert (cols != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(), ExcNotQuadratic());
+ Assert (m() == n(), ExcNotQuadratic());
Assert (i<m(), ExcInvalidIndex1(i));
// Use that the first element in each row
number &ChunkSparseMatrix<number>::diag_element (const unsigned int i)
{
Assert (cols != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(), ExcNotQuadratic());
+ Assert (m() == n(), ExcNotQuadratic());
Assert (i<m(), ExcInvalidIndex1(i));
// Use that the first element in each row
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
Assert (dst.size() == n(), ExcDimensionMismatch (dst.size(), n()));
Assert (src.size() == n(), ExcDimensionMismatch (src.size(), n()));
// which is much clearer...
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
Assert (dst.size() == n(), ExcDimensionMismatch (dst.size(), n()));
Assert (src.size() == n(), ExcDimensionMismatch (src.size(), n()));
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
dst = src;
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
dst = src;
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
-
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
Assert (m() == dst.size(), ExcDimensionMismatch(m(),dst.size()));
Assert (false, ExcNotImplemented());
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
-
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
Assert (m() == dst.size(), ExcDimensionMismatch(m(),dst.size()));
Assert (false, ExcNotImplemented());
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
Assert (m() == dst.size(), ExcDimensionMismatch(m(),dst.size()));
Assert (m() == permutation.size(),
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
Assert (m() == dst.size(), ExcDimensionMismatch(m(),dst.size()));
Assert (m() == permutation.size(),
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
Assert (m() == v.size(), ExcDimensionMismatch(m(),v.size()));
Assert (m() == b.size(), ExcDimensionMismatch(m(),b.size()));
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
Assert (m() == v.size(), ExcDimensionMismatch(m(),v.size()));
Assert (m() == b.size(), ExcDimensionMismatch(m(),b.size()));
{
Assert (cols != 0, ExcNotInitialized());
Assert (val != 0, ExcNotInitialized());
- Assert (cols->optimize_diagonal(),
- typename ChunkSparsityPattern::ExcDiagonalNotOptimized());
+ Assert (m() == n(), ExcMessage("This operation is only valid on square matrices."));
Assert (m() == dst.size(), ExcDimensionMismatch(m(),dst.size()));
* @arg n number of columns
* @arg max_per_row maximum
* number of nonzero entries per row
- *
- * @arg optimize_diagonal store
- * diagonal entries first in row;
- * see optimize_diagonal(). This
- * takes effect for quadratic
- * matrices only.
+ */
+ ChunkSparsityPattern (const unsigned int m,
+ const unsigned int n,
+ const unsigned int max_chunks_per_row,
+ const unsigned int chunk_size);
+
+ /**
+ * @deprecated This constructor is deprecated. Use the version
+ * without the last argument
*/
ChunkSparsityPattern (const unsigned int m,
const unsigned int n,
const unsigned int max_chunks_per_row,
const unsigned int chunk_size,
- const bool optimize_diagonal = true);
+ const bool optimize_diagonal) DEAL_II_DEPRECATED;
/**
* Initialize a rectangular
* number of nonzero entries for
* each row. This vector must
* have one entry for each row.
- *
- * @arg optimize_diagonal store
- * diagonal entries first in row;
- * see optimize_diagonal(). This
- * takes effect for quadratic
- * matrices only.
+ */
+ ChunkSparsityPattern (const unsigned int m,
+ const unsigned int n,
+ const std::vector<unsigned int> &row_lengths,
+ const unsigned int chunk_size);
+
+ /**
+ * @deprecated This constructor is deprecated. Use the version
+ * without the last argument
*/
ChunkSparsityPattern (const unsigned int m,
const unsigned int n,
const std::vector<unsigned int> &row_lengths,
const unsigned int chunk_size,
- const bool optimize_diagonal = true);
+ const bool optimize_diagonal) DEAL_II_DEPRECATED;
/**
* Initialize a quadratic matrix
* number of nonzero entries for
* each row. This vector must
* have one entry for each row.
- *
- * @arg optimize_diagonal store
- * diagonal entries first in row;
- * see optimize_diagonal().
+ */
+ ChunkSparsityPattern (const unsigned int m,
+ const std::vector<unsigned int> &row_lengths,
+ const unsigned int chunk_size);
+
+ /**
+ * @deprecated This constructor is deprecated. Use the version
+ * without the last argument
*/
ChunkSparsityPattern (const unsigned int m,
const std::vector<unsigned int> &row_lengths,
const unsigned int chunk_size,
- const bool optimize_diagonal = true);
+ const bool optimize_diagonal) DEAL_II_DEPRECATED;
/**
* Destructor.
* operations to the other
* <tt>reinit</tt> function.
*/
+ void reinit (const unsigned int m,
+ const unsigned int n,
+ const unsigned int max_per_row,
+ const unsigned int chunk_size);
+
+ /**
+ * @deprecated This function is deprecated. Use the function
+ * without the last argument
+ */
void reinit (const unsigned int m,
const unsigned int n,
const unsigned int max_per_row,
const unsigned int chunk_size,
- const bool optimize_diagonal = true);
+ const bool optimize_diagonal) DEAL_II_DEPRECATED;
/**
* Reallocate memory for a matrix
* of the heap.
*
* If the number of rows equals
- * the number of columns and the
- * last parameter is true,
+ * the number of columns then
* diagonal elements are stored
* first in each row to allow
* optimized access in relaxation
* methods of SparseMatrix.
*/
+ void reinit (const unsigned int m,
+ const unsigned int n,
+ const std::vector<unsigned int> &row_lengths,
+ const unsigned int chunk_size);
+
+ /**
+ * @deprecated This function is deprecated. Use the function
+ * without the last argument
+ */
void reinit (const unsigned int m,
const unsigned int n,
const std::vector<unsigned int> &row_lengths,
const unsigned int chunk_size,
- const bool optimize_diagonal = true);
+ const bool optimize_diagonal) DEAL_II_DEPRECATED;
/**
* Same as above, but with a
* VectorSlice argument instead.
*/
+ void reinit (const unsigned int m,
+ const unsigned int n,
+ const VectorSlice<const std::vector<unsigned int> > &row_lengths,
+ const unsigned int chunk_size);
+
+ /**
+ * @deprecated This function is deprecated. Use the function
+ * without the last argument
+ */
void reinit (const unsigned int m,
const unsigned int n,
const VectorSlice<const std::vector<unsigned int> > &row_lengths,
const unsigned int chunk_size,
- const bool optimize_diagonal = true);
+ const bool optimize_diagonal) DEAL_II_DEPRECATED;
/**
* This function compresses the sparsity
* pairs.
*/
template <typename ForwardIterator>
+ void copy_from (const unsigned int n_rows,
+ const unsigned int n_cols,
+ const ForwardIterator begin,
+ const ForwardIterator end,
+ const unsigned int chunk_size);
+
+ /**
+ * @deprecated This function is deprecated. Use the function
+ * without the last argument
+ */
+ template <typename ForwardIterator>
void copy_from (const unsigned int n_rows,
const unsigned int n_cols,
const ForwardIterator begin,
const ForwardIterator end,
const unsigned int chunk_size,
- const bool optimize_diagonal = true);
+ const bool optimize_diagonal) DEAL_II_DEPRECATED;
/**
* Copy data from an object of type
* compressed mode afterwards.
*/
template <typename SparsityType>
+ void copy_from (const SparsityType &csp,
+ const unsigned int chunk_size);
+
+ /**
+ * @deprecated This function is deprecated. Use the function
+ * without the last argument
+ */
+ template <typename SparsityType>
void copy_from (const SparsityType &csp,
const unsigned int chunk_size,
- const bool optimize_diagonal = true);
+ const bool optimize_diagonal) DEAL_II_DEPRECATED;
/**
* Take a full matrix and use its
* compressed mode afterwards.
*/
template <typename number>
+ void copy_from (const FullMatrix<number> &matrix,
+ const unsigned int chunk_size);
+
+ /**
+ * @deprecated This function is deprecated. Use the function
+ * without the last argument
+ */
+ template <typename number>
void copy_from (const FullMatrix<number> &matrix,
const unsigned int chunk_size,
- const bool optimize_diagonal = true);
+ const bool optimize_diagonal) DEAL_II_DEPRECATED;
/**
* Return whether the object is empty. It
bool is_compressed () const;
/**
- * Determine whether the matrix
- * uses special convention for
- * quadratic matrices.
- *
- * A return value <tt>true</tt> means
- * that diagonal elements are stored
- * first in each row. A number of
- * functions in this class and the
- * library in general, for example
- * relaxation methods like Jacobi() and
- * SOR(), require this to make their
- * operations more efficient, since they
- * need to quickly access the diagonal
- * elements and do not have to search for
- * them if they are the first element of
- * each row. A side effect of this scheme
- * is that each row contains at least one
- * element, even if the row is empty
- * (i.e. the diagonal element exists, but
- * has value zero).
- *
- * A return value <tt>false</tt> means
- * that diagonal elements are stored
- * anywhere in the row, or not at all. In
- * particular, a row or even the whole
- * matrix may be empty. This can be used
- * if you have block matrices where the
- * off-diagonal blocks are quadratic but
- * are never used for operations like the
- * ones mentioned above. In this case,
- * some memory can be saved by not using
- * the diagonal storage optimization.
- */
- bool optimize_diagonal () const;
-
- /**
- * Return whether this object stores only
- * those entries that have been added
- * explicitly, or if the sparsity pattern
- * contains elements that have been added
- * through other means (implicitly) while
- * building it. For the current class,
- * the result is false because we store
- * entire chunks, not individual
- * elements, and adding one entry to the
- * sparsity pattern requires also adding
- * all the other elements of a chunk. The
- * only exception is if
- * <code>chunk_size==1</code>, the
- * sparsity pattern is nonsymmetric or
- * optimize_diag has been set to false.
- *
- * This function mainly serves the
- * purpose of describing the current
- * class in cases where several kinds of
- * sparsity patterns can be passed as
+ * Determine whether the matrix uses the special convention for quadratic
+ * matrices that the diagonal entries are stored first in each row.
+ *
+ * @deprecated The function always returns true if the matrix is
+ * square and false if it is not.
+ */
+ bool optimize_diagonal () const DEAL_II_DEPRECATED;
+
+ /**
+ * Return whether this object stores only those entries that have been added
+ * explicitly, or if the sparsity pattern contains elements that have been
+ * added through other means (implicitly) while building it. For the current
+ * class, the result is true if and only if it is square because it then
+ * unconditionally stores the diagonal entries whether they have been added explicitly or not.
+ *
+ * This function mainly serves the purpose of describing the current class
+ * in cases where several kinds of sparsity patterns can be passed as
* template arguments.
*/
bool stores_only_added_elements () const;
* Exception
*/
DeclException0 (ExcInvalidConstructorCall);
- /**
- * This exception is thrown if
- * the matrix does not follow the
- * convention of storing diagonal
- * elements first in row. Refer
- * to
- * SparityPattern::optimize_diagonal()
- * for more information.
- */
- DeclException0 (ExcDiagonalNotOptimized);
/**
* Exception
*/
const ForwardIterator begin,
const ForwardIterator end,
const unsigned int chunk_size,
- const bool optimize_diag)
+ const bool)
+{
+ copy_from (n_rows, n_cols, begin, end, chunk_size);
+}
+
+
+
+template <typename ForwardIterator>
+void
+ChunkSparsityPattern::copy_from (const unsigned int n_rows,
+ const unsigned int n_cols,
+ const ForwardIterator begin,
+ const ForwardIterator end,
+ const unsigned int chunk_size)
{
Assert (static_cast<unsigned int>(std::distance (begin, end)) == n_rows,
ExcIteratorRange (std::distance (begin, end), n_rows));
// bother to check whether that
// diagonal entry is in a certain
// row or not
- const bool is_square = optimize_diag && (n_rows == n_cols);
+ const bool is_square = (n_rows == n_cols);
std::vector<unsigned int> row_lengths;
row_lengths.reserve(n_rows);
for (ForwardIterator i=begin; i!=end; ++i)
Assert (s.rows == 0, ExcInvalidConstructorCall());
Assert (s.cols == 0, ExcInvalidConstructorCall());
- reinit (0,0,0,0, false);
+ reinit (0,0,0,0);
}
const unsigned int n,
const unsigned int max_per_row,
const unsigned int chunk_size,
- const bool optimize_diag)
+ const bool)
{
Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
- reinit (m,n,max_per_row, chunk_size, optimize_diag);
+ reinit (m,n,max_per_row, chunk_size);
+}
+
+
+ChunkSparsityPattern::ChunkSparsityPattern (const unsigned int m,
+ const unsigned int n,
+ const unsigned int max_per_row,
+ const unsigned int chunk_size)
+{
+ Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
+
+ reinit (m,n,max_per_row, chunk_size);
}
{
Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
- reinit (m, n, row_lengths, chunk_size, optimize_diag);
+ reinit (m, n, row_lengths, chunk_size);
+}
+
+
+
+ChunkSparsityPattern::ChunkSparsityPattern (
+ const unsigned int m,
+ const unsigned int n,
+ const std::vector<unsigned int> &row_lengths,
+ const unsigned int chunk_size)
+{
+ Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
+
+ reinit (m, n, row_lengths, chunk_size);
}
const unsigned int max_per_row,
const unsigned int chunk_size)
{
- reinit (n, n, max_per_row, chunk_size, true);
+ reinit (n, n, max_per_row, chunk_size);
}
{
Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
- reinit (m, m, row_lengths, chunk_size, optimize_diag);
+ reinit (m, m, row_lengths, chunk_size);
+}
+
+
+
+ChunkSparsityPattern::ChunkSparsityPattern (
+ const unsigned int m,
+ const std::vector<unsigned int> &row_lengths,
+ const unsigned int chunk_size)
+{
+ Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
+
+ reinit (m, m, row_lengths, chunk_size);
}
const unsigned int n,
const unsigned int max_per_row,
const unsigned int chunk_size,
- const bool optimize_diag)
+ const bool)
+{
+ reinit (m, n, max_per_row, chunk_size);
+}
+
+
+void
+ChunkSparsityPattern::reinit (const unsigned int m,
+ const unsigned int n,
+ const unsigned int max_per_row,
+ const unsigned int chunk_size)
{
Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
// simply map this function to the
// other @p{reinit} function
const std::vector<unsigned int> row_lengths (m, max_per_row);
- reinit (m, n, row_lengths, chunk_size, optimize_diag);
+ reinit (m, n, row_lengths, chunk_size);
}
const unsigned int n,
const VectorSlice<const std::vector<unsigned int> > &row_lengths,
const unsigned int chunk_size,
- const bool optimize_diag)
+ const bool)
+{
+ reinit (m, n, row_lengths, chunk_size);
+}
+
+
+void
+ChunkSparsityPattern::reinit (
+ const unsigned int m,
+ const unsigned int n,
+ const VectorSlice<const std::vector<unsigned int> > &row_lengths,
+ const unsigned int chunk_size)
{
Assert (row_lengths.size() == m, ExcInvalidNumber (m));
Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
sparsity_pattern.reinit (m_chunks,
n_chunks,
- chunk_row_lengths,
- optimize_diag);
+ chunk_row_lengths);
}
void
ChunkSparsityPattern::copy_from (const SparsityType &csp,
const unsigned int chunk_size,
- const bool optimize_diag)
+ const bool)
+{
+ copy_from (csp, chunk_size);
+}
+
+
+template <typename SparsityType>
+void
+ChunkSparsityPattern::copy_from (const SparsityType &csp,
+ const unsigned int chunk_size)
{
Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
reinit (csp.n_rows(), csp.n_cols(),
entries_per_row,
- chunk_size, optimize_diag);
+ chunk_size);
// then actually fill it
for (unsigned int row = 0; row<csp.n_rows(); ++row)
void ChunkSparsityPattern::copy_from (const FullMatrix<number> &matrix,
const unsigned int chunk_size,
const bool optimize_diag)
+{
+ copy_from (matrix, chunk_size);
+}
+
+
+template <typename number>
+void ChunkSparsityPattern::copy_from (const FullMatrix<number> &matrix,
+ const unsigned int chunk_size)
{
Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
reinit (matrix.m(), matrix.n(),
entries_per_row,
- chunk_size, optimize_diag);
+ chunk_size);
// then actually fill it
for (unsigned int row=0; row<matrix.m(); ++row)
const unsigned int n,
const std::vector<unsigned int> &row_lengths,
const unsigned int chunk_size,
- const bool optimize_diag)
+ const bool)
+{
+ reinit (m, n, row_lengths, chunk_size);
+}
+
+
+void
+ChunkSparsityPattern::reinit (
+ const unsigned int m,
+ const unsigned int n,
+ const std::vector<unsigned int> &row_lengths,
+ const unsigned int chunk_size)
{
Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
- reinit(m, n, make_slice(row_lengths), chunk_size, optimize_diag);
+ reinit(m, n, make_slice(row_lengths), chunk_size);
}