Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Xpetra_BlockReorderManager.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 // Tobias Wiesner (tawiesn@sandia.gov)
43 //
44 // ***********************************************************************
45 //
46 // @HEADER
47 #ifndef XPETRA_BLOCKREORDERMANAGER_HPP_
48 #define XPETRA_BLOCKREORDERMANAGER_HPP_
49 
50 #include <stack>
51 
52 #include <Teuchos_StrUtils.hpp>
53 
54 namespace Xpetra {
56 public:
58 
61 
64  children_(bmm.children_.size()) {
65  for(size_t i = 0; i < children_.size(); i++) children_[i] = bmm.children_[i]->Copy();
66  }
67 
69  virtual ~BlockReorderManager() { }
70 
72 
74  virtual Teuchos::RCP<BlockReorderManager> Copy() const {
75  return Teuchos::rcp(new BlockReorderManager(*this));
76  }
77 
79  virtual void SetNumBlocks( size_t sz ) {
80  children_.clear(); children_.resize(sz);
81  }
82 
84  virtual size_t GetNumBlocks() const {
85  return children_.size();
86  }
87 
89 
94  virtual void SetBlock(int blockIndex, int reorder);/* {
95  TEUCHOS_ASSERT(blockIndex < (int) children_.size());
96  Teuchos::RCP<BlockReorderManager> child = Teuchos::rcp(new BlockReorderLeaf(reorder));
97  children_[blockIndex] = child;
98  }*/
99 
101 
106  virtual void SetBlock(int blockIndex, const Teuchos::RCP<BlockReorderManager> & reorder);/* {
107  TEUCHOS_ASSERT(blockIndex < (int) children_.size());
108  children_[blockIndex] = reorder;
109  }*/
110 
112  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int blockIndex) {
113  TEUCHOS_ASSERT(blockIndex<(int) children_.size());
114 
115  if(children_[blockIndex]==Teuchos::null)
116  children_[blockIndex] = Teuchos::rcp(new BlockReorderManager());
117  return children_[blockIndex];
118  }
119 
121  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int blockIndex) const {
122  TEUCHOS_ASSERT(blockIndex<(int) children_.size());
123  return children_[blockIndex];
124  }
125 
127  virtual std::string toString() const {
128  // build the string by recursively calling each child
129  std::stringstream ss;
130  ss << "[";
131  for(size_t i = 0; i < children_.size(); i++) {
132  if(children_[i] == Teuchos::null)
133  ss << " <NULL> ";
134  else
135  ss << " " << children_[i]->toString() << " ";
136  }
137  ss << "]";
138  return ss.str();
139  }
140 
142  virtual int LargestIndex() const {
143  int max = 0;
144  for(size_t i = 0; i<children_.size(); i++) {
145  if(children_[i]!=Teuchos::null) {
146  int subMax = children_[i]->LargestIndex();
147  max = max > subMax ? max : subMax;
148  }
149  }
150  return max;
151  }
152 
153 protected:
155  std::vector<Teuchos::RCP<BlockReorderManager> > children_;
156 };
157 
159 public:
160  BlockReorderLeaf(int ind) : value_(ind) {}
162 
163  virtual Teuchos::RCP<BlockReorderManager> Copy() const {
164  return Teuchos::rcp(new BlockReorderLeaf(*this));
165  }
166 
167  virtual size_t GetNumBlocks() const { return 0; }
168  virtual void SetNumBlocks(size_t /* sz */) {}
169  virtual void SetBlock(int /* blockIndex */, int /* reorder */) { }
170  virtual void SetBlock(int /* blockIndex */, const Teuchos::RCP<BlockReorderManager> & /* reorder */) {}
171  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int /* blockIndex */) {
172  return Teuchos::null;
173  }
174  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int /* blockIndex */)const {
175  return Teuchos::null;
176  }
178  int GetIndex() const { return value_; }
179  virtual std::string toString() const {
180  std::stringstream ss; ss << value_; return ss.str();
181  }
182  virtual int LargestIndex() const { return value_; }
183 protected:
185  int value_;
186 
187 private:
188  BlockReorderLeaf() : value_(0) {}; // hidden from users
189 };
190 
191 
192 void tokenize(std::string srcInput,std::string whitespace,std::string prefer, std::vector<std::string> & tokens);
193 
194 // this function takes a set of tokens and returns the first "block", i.e. those
195 // values (including) brackets that correspond to the first block
196 std::vector<std::string>::const_iterator buildSubBlock(
197  std::vector<std::string>::const_iterator begin,
198  std::vector<std::string>::const_iterator end,
199  std::vector<std::string> & subBlock);
200 
201 // This function takes a tokenized vector and converts it to a block reorder manager
202 Teuchos::RCP<Xpetra::BlockReorderManager> blockedReorderFromTokens(const std::vector<std::string> & tokens);
203 
215 Teuchos::RCP<const Xpetra::BlockReorderManager> blockedReorderFromString(std::string reorder);
216 }
217 
218 #endif /* XPETRA_BLOCKREORDERMANAGER_HPP_ */
virtual ~BlockReorderManager()
empty destructor
std::vector< std::string >::const_iterator buildSubBlock(std::vector< std::string >::const_iterator begin, std::vector< std::string >::const_iterator end, std::vector< std::string > &subBlock)
virtual std::string toString() const
for sanities sake, print a readable string
virtual std::string toString() const
for sanities sake, print a readable string
virtual int LargestIndex() const
returns largest index in this BlockReorderManager class
virtual const Teuchos::RCP< const BlockReorderManager > GetBlock(int blockIndex) const
Get a particular block. If there is no block at this index location return a new one.
Teuchos::RCP< const Xpetra::BlockReorderManager > blockedReorderFromString(std::string reorder)
Convert a string to a block reorder manager object.
BlockReorderManager()
Basic empty constructor.
void tokenize(std::string srcInput, std::string whitespace, std::string prefer, std::vector< std::string > &tokens)
virtual const Teuchos::RCP< BlockReorderManager > GetBlock(int)
Get a particular block. If there is no block at this index location return a new one.
virtual int LargestIndex() const
returns largest index in this BlockReorderManager class
int GetIndex() const
Get the index that is stored in this block/leaf.
virtual size_t GetNumBlocks() const
Returns number of subblocks.
virtual size_t GetNumBlocks() const
Returns number of subblocks.
virtual void SetBlock(int blockIndex, int reorder)
Sets the subblock to a specific index value.
int value_
The value of the index for this leaf.
virtual const Teuchos::RCP< BlockReorderManager > GetBlock(int blockIndex)
Get a particular block. If there is no block at this index location return a new one.
Teuchos::RCP< Xpetra::BlockReorderManager > blockedReorderFromTokens(const std::vector< std::string > &tokens)
virtual void SetNumBlocks(size_t sz)
Sets number of subblocks.
virtual void SetBlock(int, int)
Sets the subblock to a specific index value.
BlockReorderManager(const BlockReorderManager &bmm)
Copy constructor.
virtual void SetNumBlocks(size_t)
Sets number of subblocks.
virtual void SetBlock(int, const Teuchos::RCP< BlockReorderManager > &)
Sets the subblock to a specific index value.
BlockReorderLeaf(const BlockReorderLeaf &brl)
virtual const Teuchos::RCP< const BlockReorderManager > GetBlock(int) const
Get a particular block. If there is no block at this index location return a new one.
std::vector< Teuchos::RCP< BlockReorderManager > > children_
definitions of the subblocks
virtual Teuchos::RCP< BlockReorderManager > Copy() const
returns copy of this object
virtual Teuchos::RCP< BlockReorderManager > Copy() const
returns copy of this object