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  : children_(0) {}
62 
65  : children_(bmm.children_.size()) {
66  for (size_t i = 0; i < children_.size(); i++) children_[i] = bmm.children_[i]->Copy();
67  }
68 
70  virtual ~BlockReorderManager() {}
71 
73 
75  virtual Teuchos::RCP<BlockReorderManager> Copy() const {
76  return Teuchos::rcp(new BlockReorderManager(*this));
77  }
78 
80  virtual void SetNumBlocks(size_t sz) {
81  children_.clear();
82  children_.resize(sz);
83  }
84 
86  virtual size_t GetNumBlocks() const {
87  return children_.size();
88  }
89 
91 
96  virtual void SetBlock(int blockIndex, int reorder); /* {
97  TEUCHOS_ASSERT(blockIndex < (int) children_.size());
98  Teuchos::RCP<BlockReorderManager> child = Teuchos::rcp(new BlockReorderLeaf(reorder));
99  children_[blockIndex] = child;
100  }*/
101 
103 
108  virtual void SetBlock(int blockIndex, const Teuchos::RCP<BlockReorderManager>& reorder); /* {
109  TEUCHOS_ASSERT(blockIndex < (int) children_.size());
110  children_[blockIndex] = reorder;
111  }*/
112 
114  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int blockIndex) {
115  TEUCHOS_ASSERT(blockIndex < (int)children_.size());
116 
117  if (children_[blockIndex] == Teuchos::null)
118  children_[blockIndex] = Teuchos::rcp(new BlockReorderManager());
119  return children_[blockIndex];
120  }
121 
123  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int blockIndex) const {
124  TEUCHOS_ASSERT(blockIndex < (int)children_.size());
125  return children_[blockIndex];
126  }
127 
129  virtual std::string toString() const {
130  // build the string by recursively calling each child
131  std::stringstream ss;
132  ss << "[";
133  for (size_t i = 0; i < children_.size(); i++) {
134  if (children_[i] == Teuchos::null)
135  ss << " <NULL> ";
136  else
137  ss << " " << children_[i]->toString() << " ";
138  }
139  ss << "]";
140  return ss.str();
141  }
142 
144  virtual int LargestIndex() const {
145  int max = 0;
146  for (size_t i = 0; i < children_.size(); i++) {
147  if (children_[i] != Teuchos::null) {
148  int subMax = children_[i]->LargestIndex();
149  max = max > subMax ? max : subMax;
150  }
151  }
152  return max;
153  }
154 
155  protected:
157  std::vector<Teuchos::RCP<BlockReorderManager> > children_;
158 };
159 
161  public:
163  : value_(ind) {}
165  : value_(brl.value_) {}
166 
167  virtual Teuchos::RCP<BlockReorderManager> Copy() const {
168  return Teuchos::rcp(new BlockReorderLeaf(*this));
169  }
170 
171  virtual size_t GetNumBlocks() const { return 0; }
172  virtual void SetNumBlocks(size_t /* sz */) {}
173  virtual void SetBlock(int /* blockIndex */, int /* reorder */) {}
174  virtual void SetBlock(int /* blockIndex */, const Teuchos::RCP<BlockReorderManager>& /* reorder */) {}
175  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int /* blockIndex */) {
176  return Teuchos::null;
177  }
178  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int /* blockIndex */) const {
179  return Teuchos::null;
180  }
182  int GetIndex() const { return value_; }
183  virtual std::string toString() const {
184  std::stringstream ss;
185  ss << value_;
186  return ss.str();
187  }
188  virtual int LargestIndex() const { return value_; }
189 
190  protected:
192  int value_;
193 
194  private:
196  : value_(0){}; // hidden from users
197 };
198 
199 void tokenize(std::string srcInput, std::string whitespace, std::string prefer, std::vector<std::string>& tokens);
200 
201 // this function takes a set of tokens and returns the first "block", i.e. those
202 // values (including) brackets that correspond to the first block
203 std::vector<std::string>::const_iterator buildSubBlock(
204  std::vector<std::string>::const_iterator begin,
205  std::vector<std::string>::const_iterator end,
206  std::vector<std::string>& subBlock);
207 
208 // This function takes a tokenized vector and converts it to a block reorder manager
209 Teuchos::RCP<Xpetra::BlockReorderManager> blockedReorderFromTokens(const std::vector<std::string>& tokens);
210 
222 Teuchos::RCP<const Xpetra::BlockReorderManager> blockedReorderFromString(std::string reorder);
223 } // namespace Xpetra
224 
225 #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