SparseLibrary  Version 1.6.0
BlockCRS.hpp
1 /*
2  * Copyright (c) 2007-2014, A. N. Yzelman, Utrecht University 2007-2011;
3  * KU Leuven 2011-2014.
4  * R. H. Bisseling, Utrecht University 2007-2014.
5  *
6  * This file is part of the Sparse Library.
7  *
8  * This library was developed under supervision of Prof. dr. Rob H. Bisseling at
9  * Utrecht University, from 2007 until 2011. From 2011-2014, development continued
10  * at KU Leuven, where Prof. dr. Dirk Roose contributed significantly to the ideas
11  * behind the newer parts of the library code.
12  *
13  * The Sparse Library is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by the
15  * Free Software Foundation, either version 3 of the License, or (at your
16  * option) any later version.
17  *
18  * The Sparse Library is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with the Sparse Library. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 
28 /*
29  * File created by:
30  * A. N. Yzelman, Dept. of Mathematics, Utrecht University, 2010.
31  */
32 
33 
34 #ifndef _H_BLOCKCRS
35 #define _H_BLOCKCRS
36 
37 #include "BlockOrderer.hpp"
38 
40 template< typename T >
41 class BlockCRS: public BlockOrderer< T > {
42  protected:
43 
45  virtual void pre_readout ( const unsigned long int index ) {
46  //switch between internal nodes and external nodes
47  if( this->tree->isLeaf( index ) ) {
48  //immediately add everything in range
49  this->output->push_back( this->items[ index ] );
50  if( this->datatype != NULL )
51  this->datatype->push_back( NORMAL_DS );
52  }
53  }
54 
56  virtual void in_readout ( const unsigned long int index ) {
57  //skip leaf node
58  if( this->tree->isLeaf( index ) ) return;
59  //initialise
60  typename std::vector< Triplet< T > >::iterator it = this->items[ index ].begin();
61  std::vector< Triplet< T > > cur1;
62  std::vector< Triplet< T > > cur2;
63  std::vector< Triplet< T > > cur3;
64  std::vector< Triplet< T > > cur4;
65  std::vector< Triplet< T > > cur5;
66  std::vector< Triplet< T > > rep;
67  //loop over this node's triplets
68  for( ; it != this->items[ index ].end(); ++it ) {
69  //now the 3 vertical separators (incl middle) in row order
70  if( this->upper_vertical( index, *it ) )
71  cur1.push_back( *it );
72  else if( this->left_horizontal( index, *it ) )
73  cur2.push_back( *it );
74  else if( this->middle( index, *it ) )
75  cur3.push_back( *it );
76  else if( this->right_horizontal( index, *it ) )
77  cur4.push_back( *it );
78  else if( this->lower_vertical( index, *it ) )
79  cur5.push_back( *it );
80  else
81  rep.push_back( *it );
82  }
83  if( cur1.size() + cur2.size() + cur3.size() + cur4.size() + cur5.size() > 0 )
84  this->items[ index ] = rep; //replace with smaller vector
85  this->output->push_back( cur1 );
86  this->output->push_back( cur2 );
87  this->output->push_back( cur3 );
88  this->output->push_back( cur4 );
89  this->output->push_back( cur5 );
90  if( this->datatype != NULL ) {
91  this->datatype->push_back( VERTICAL_DS );
92  this->datatype->push_back( HORIZONTAL_DS );
93  this->datatype->push_back( NORMAL_DS );
94  this->datatype->push_back( HORIZONTAL_DS );
95  this->datatype->push_back( VERTICAL_DS );
96  }
97  }
98 
100  virtual void post_readout( const unsigned long int index ) {
101  return; //do nothing
102  }
103 
104  public:
105  //(de)constructor of superclass gets called automagically
106 };
107 
108 #endif
109 
Induces a block order by fully traversing an SBDTree.
Definition: BlockOrderer.hpp:48
SBDTree * tree
The SBD tree to order the blocks of.
Definition: BlockOrderer.hpp:53
Codes the CRS block order.
Definition: BlockCRS.hpp:41
char isLeaf(const unsigned long int index)
Whether the given node is a leaf node.
Definition: SBDTree.cpp:214
virtual void in_readout(const unsigned long int index)
Infix operations during SBD tree traversal.
Definition: BlockCRS.hpp:56
virtual void pre_readout(const unsigned long int index)
Prefix operations during SBD tree traversal.
Definition: BlockCRS.hpp:45
bool left_horizontal(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:203
bool upper_vertical(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:221
virtual void post_readout(const unsigned long int index)
Postfix operations during SBD tree traversal.
Definition: BlockCRS.hpp:100
bool right_horizontal(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:212
bool lower_vertical(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:230
std::vector< std::vector< Triplet< T > > > * output
Output structure after SBD readout (series of blocks in the correct order).
Definition: BlockOrderer.hpp:197
bool middle(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:239
std::vector< signed char > * datatype
The data type of each block.
Definition: BlockOrderer.hpp:200
std::vector< Triplet< T > > * items
Nonzero storage at each node.
Definition: BlockOrderer.hpp:194