00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__compressed_set_sparsity_pattern_h
00013 #define __deal2__compressed_set_sparsity_pattern_h
00014
00015
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/subscriptor.h>
00018 #include <deal.II/lac/exceptions.h>
00019
00020 #include <vector>
00021 #include <algorithm>
00022 #include <set>
00023
00024 DEAL_II_NAMESPACE_OPEN
00025
00026 template <typename number> class SparseMatrix;
00027
00106 class CompressedSetSparsityPattern : public Subscriptor
00107 {
00108 public:
00115 typedef std::set<unsigned int>::const_iterator row_iterator;
00116
00117
00128 CompressedSetSparsityPattern ();
00129
00146 CompressedSetSparsityPattern (const CompressedSetSparsityPattern &);
00147
00153 CompressedSetSparsityPattern (const unsigned int m,
00154 const unsigned int n);
00155
00160 CompressedSetSparsityPattern (const unsigned int n);
00161
00170 CompressedSetSparsityPattern & operator = (const CompressedSetSparsityPattern &);
00171
00180 void reinit (const unsigned int m,
00181 const unsigned int n);
00182
00192 void compress ();
00193
00201 bool empty () const;
00202
00209 unsigned int max_entries_per_row () const;
00210
00216 void add (const unsigned int i,
00217 const unsigned int j);
00218
00225 template <typename ForwardIterator>
00226 void add_entries (const unsigned int row,
00227 ForwardIterator begin,
00228 ForwardIterator end,
00229 const bool indices_are_sorted = false);
00230
00235 bool exists (const unsigned int i,
00236 const unsigned int j) const;
00237
00249 void symmetrize ();
00250
00260 void print (std::ostream &out) const;
00261
00285 void print_gnuplot (std::ostream &out) const;
00286
00292 unsigned int n_rows () const;
00293
00299 unsigned int n_cols () const;
00300
00304 unsigned int row_length (const unsigned int row) const;
00305
00312 row_iterator row_begin (const unsigned int row) const;
00313
00317 row_iterator row_end (const unsigned int row) const;
00318
00319
00328 unsigned int bandwidth () const;
00329
00335 unsigned int n_nonzero_elements () const;
00336
00352 static
00353 bool stores_only_added_elements ();
00354
00355 private:
00360 unsigned int rows;
00361
00366 unsigned int cols;
00367
00375 struct Line
00376 {
00377 std::set<unsigned int> entries;
00378
00382 Line ();
00383
00388 void add (const unsigned int col_num);
00389
00394 template <typename ForwardIterator>
00395 void add_entries (ForwardIterator begin,
00396 ForwardIterator end);
00397 };
00398
00399
00405 std::vector<Line> lines;
00406 };
00407
00409
00410
00411
00412 inline
00413 CompressedSetSparsityPattern::Line::Line ()
00414 {}
00415
00416
00417
00418 inline
00419 void
00420 CompressedSetSparsityPattern::Line::add (const unsigned int j)
00421 {
00422 entries.insert (j);
00423 }
00424
00425
00426
00427 template <typename ForwardIterator>
00428 inline
00429 void
00430 CompressedSetSparsityPattern::Line::add_entries (ForwardIterator begin,
00431 ForwardIterator end)
00432 {
00433 entries.insert (begin, end);
00434 }
00435
00436
00437
00438 inline
00439 unsigned int
00440 CompressedSetSparsityPattern::n_rows () const
00441 {
00442 return rows;
00443 }
00444
00445
00446
00447 inline
00448 unsigned int
00449 CompressedSetSparsityPattern::n_cols () const
00450 {
00451 return cols;
00452 }
00453
00454
00455
00456 inline
00457 void
00458 CompressedSetSparsityPattern::add (const unsigned int i,
00459 const unsigned int j)
00460 {
00461 Assert (i<rows, ExcIndexRange(i, 0, rows));
00462 Assert (j<cols, ExcIndexRange(j, 0, cols));
00463
00464 lines[i].add (j);
00465 }
00466
00467
00468
00469 template <typename ForwardIterator>
00470 inline
00471 void
00472 CompressedSetSparsityPattern::add_entries (const unsigned int row,
00473 ForwardIterator begin,
00474 ForwardIterator end,
00475 const bool )
00476 {
00477 Assert (row < rows, ExcIndexRange (row, 0, rows));
00478
00479 lines[row].add_entries (begin, end);
00480 }
00481
00482
00483
00484 inline
00485 unsigned int
00486 CompressedSetSparsityPattern::row_length (const unsigned int row) const
00487 {
00488 Assert (row < n_rows(), ExcIndexRange (row, 0, n_rows()));
00489
00490 return lines[row].entries.size();
00491 }
00492
00493
00494
00495 inline
00496 CompressedSetSparsityPattern::row_iterator
00497 CompressedSetSparsityPattern::row_begin (const unsigned int row) const
00498 {
00499 return (lines[row].entries.begin ());
00500 }
00501
00502
00503
00504 inline
00505 CompressedSetSparsityPattern::row_iterator
00506 CompressedSetSparsityPattern::row_end (const unsigned int row) const
00507 {
00508 return (lines[row].entries.end ());
00509 }
00510
00511
00512
00513 inline
00514 bool
00515 CompressedSetSparsityPattern::stores_only_added_elements ()
00516 {
00517 return true;
00518 }
00519
00520
00521 DEAL_II_NAMESPACE_CLOSE
00522
00523 #endif
00524