Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
compressed_set_sparsity_pattern.h
1 // ---------------------------------------------------------------------
2 // @f$Id: compressed_set_sparsity_pattern.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2001 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__compressed_set_sparsity_pattern_h
18 #define __deal2__compressed_set_sparsity_pattern_h
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/subscriptor.h>
23 #include <deal.II/lac/exceptions.h>
24 
25 #include <vector>
26 #include <algorithm>
27 #include <set>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 template <typename number> class SparseMatrix;
32 
112 {
113 public:
118 
125  typedef std::set<size_type>::const_iterator row_iterator;
126 
127 
139 
157 
164  const size_type n);
165 
171 
181 
190  void reinit (const size_type m,
191  const size_type n);
192 
202  void compress ();
203 
211  bool empty () const;
212 
220 
226  void add (const size_type i,
227  const size_type j);
228 
235  template <typename ForwardIterator>
236  void add_entries (const size_type row,
237  ForwardIterator begin,
238  ForwardIterator end,
239  const bool indices_are_sorted = false);
240 
245  bool exists (const size_type i,
246  const size_type j) const;
247 
259  void symmetrize ();
260 
270  void print (std::ostream &out) const;
271 
295  void print_gnuplot (std::ostream &out) const;
296 
302  size_type n_rows () const;
303 
309  size_type n_cols () const;
310 
314  size_type row_length (const size_type row) const;
315 
322  row_iterator row_begin (const size_type row) const;
323 
327  row_iterator row_end (const size_type row) const;
328 
329 
338  size_type bandwidth () const;
339 
345  size_type n_nonzero_elements () const;
346 
362  static
364 
365 private:
371 
377 
385  struct Line
386  {
387  std::set<size_type> entries;
388 
392  Line ();
393 
398  void add (const size_type col_num);
399 
404  template <typename ForwardIterator>
405  void add_entries (ForwardIterator begin,
406  ForwardIterator end);
407  };
408 
409 
415  std::vector<Line> lines;
416 };
417 
419 /*---------------------- Inline functions -----------------------------------*/
420 
421 
422 inline
424 {}
425 
426 
427 
428 inline
429 void
431 {
432  entries.insert (j);
433 }
434 
435 
436 
437 template <typename ForwardIterator>
438 inline
439 void
441  ForwardIterator end)
442 {
443  entries.insert (begin, end);
444 }
445 
446 
447 
448 inline
451 {
452  return rows;
453 }
454 
455 
456 
457 inline
460 {
461  return cols;
462 }
463 
464 
465 
466 inline
467 void
469  const size_type j)
470 {
471  Assert (i<rows, ExcIndexRangeType<size_type>(i, 0, rows));
472  Assert (j<cols, ExcIndexRangeType<size_type>(j, 0, cols));
473 
474  lines[i].add (j);
475 }
476 
477 
478 
479 template <typename ForwardIterator>
480 inline
481 void
483  ForwardIterator begin,
484  ForwardIterator end,
485  const bool /*indices_are_sorted*/)
486 {
487  Assert (row < rows, ExcIndexRangeType<size_type> (row, 0, rows));
488 
489  lines[row].add_entries (begin, end);
490 }
491 
492 
493 
494 inline
497 {
498  Assert (row < n_rows(), ExcIndexRangeType<size_type> (row, 0, n_rows()));
499 
500  return lines[row].entries.size();
501 }
502 
503 
504 
505 inline
508 {
509  return (lines[row].entries.begin ());
510 }
511 
512 
513 
514 inline
517 {
518  return (lines[row].entries.end ());
519 }
520 
521 
522 
523 inline
524 bool
526 {
527  return true;
528 }
529 
530 
531 DEAL_II_NAMESPACE_CLOSE
532 
533 #endif
row_iterator row_begin(const size_type row) const
void add_entries(ForwardIterator begin, ForwardIterator end)
void print(std::ostream &out) const
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_sorted=false)
void add(const size_type i, const size_type j)
size_type bandwidth() const
size_type max_entries_per_row() const
unsigned int global_dof_index
Definition: types.h:100
#define Assert(cond, exc)
Definition: exceptions.h:299
row_iterator row_end(const size_type row) const
size_type row_length(const size_type row) const
size_type n_nonzero_elements() const
void reinit(const size_type m, const size_type n)
void print_gnuplot(std::ostream &out) const
bool exists(const size_type i, const size_type j) const
std::set< size_type >::const_iterator row_iterator
CompressedSetSparsityPattern & operator=(const CompressedSetSparsityPattern &)