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 // Xpetra: A linear algebra interface package
4 //
5 // Copyright 2012 NTESS and the Xpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef XPETRA_BLOCKREORDERMANAGER_HPP_
11 #define XPETRA_BLOCKREORDERMANAGER_HPP_
12 
13 #include <stack>
14 
15 #include <Teuchos_StrUtils.hpp>
16 
17 namespace Xpetra {
19  public:
21 
24  : children_(0) {}
25 
28  : children_(bmm.children_.size()) {
29  for (size_t i = 0; i < children_.size(); i++) children_[i] = bmm.children_[i]->Copy();
30  }
31 
33  virtual ~BlockReorderManager() {}
34 
36 
38  virtual Teuchos::RCP<BlockReorderManager> Copy() const {
39  return Teuchos::rcp(new BlockReorderManager(*this));
40  }
41 
43  virtual void SetNumBlocks(size_t sz) {
44  children_.clear();
45  children_.resize(sz);
46  }
47 
49  virtual size_t GetNumBlocks() const {
50  return children_.size();
51  }
52 
54 
59  virtual void SetBlock(int blockIndex, int reorder); /* {
60  TEUCHOS_ASSERT(blockIndex < (int) children_.size());
61  Teuchos::RCP<BlockReorderManager> child = Teuchos::rcp(new BlockReorderLeaf(reorder));
62  children_[blockIndex] = child;
63  }*/
64 
66 
71  virtual void SetBlock(int blockIndex, const Teuchos::RCP<BlockReorderManager>& reorder); /* {
72  TEUCHOS_ASSERT(blockIndex < (int) children_.size());
73  children_[blockIndex] = reorder;
74  }*/
75 
77  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int blockIndex) {
78  TEUCHOS_ASSERT(blockIndex < (int)children_.size());
79 
80  if (children_[blockIndex] == Teuchos::null)
81  children_[blockIndex] = Teuchos::rcp(new BlockReorderManager());
82  return children_[blockIndex];
83  }
84 
86  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int blockIndex) const {
87  TEUCHOS_ASSERT(blockIndex < (int)children_.size());
88  return children_[blockIndex];
89  }
90 
92  virtual std::string toString() const {
93  // build the string by recursively calling each child
94  std::stringstream ss;
95  ss << "[";
96  for (size_t i = 0; i < children_.size(); i++) {
97  if (children_[i] == Teuchos::null)
98  ss << " <NULL> ";
99  else
100  ss << " " << children_[i]->toString() << " ";
101  }
102  ss << "]";
103  return ss.str();
104  }
105 
107  virtual int LargestIndex() const {
108  int max = 0;
109  for (size_t i = 0; i < children_.size(); i++) {
110  if (children_[i] != Teuchos::null) {
111  int subMax = children_[i]->LargestIndex();
112  max = max > subMax ? max : subMax;
113  }
114  }
115  return max;
116  }
117 
118  protected:
120  std::vector<Teuchos::RCP<BlockReorderManager> > children_;
121 };
122 
124  public:
126  : value_(ind) {}
128  : value_(brl.value_) {}
129 
130  virtual Teuchos::RCP<BlockReorderManager> Copy() const {
131  return Teuchos::rcp(new BlockReorderLeaf(*this));
132  }
133 
134  virtual size_t GetNumBlocks() const { return 0; }
135  virtual void SetNumBlocks(size_t /* sz */) {}
136  virtual void SetBlock(int /* blockIndex */, int /* reorder */) {}
137  virtual void SetBlock(int /* blockIndex */, const Teuchos::RCP<BlockReorderManager>& /* reorder */) {}
138  virtual const Teuchos::RCP<BlockReorderManager> GetBlock(int /* blockIndex */) {
139  return Teuchos::null;
140  }
141  virtual const Teuchos::RCP<const BlockReorderManager> GetBlock(int /* blockIndex */) const {
142  return Teuchos::null;
143  }
145  int GetIndex() const { return value_; }
146  virtual std::string toString() const {
147  std::stringstream ss;
148  ss << value_;
149  return ss.str();
150  }
151  virtual int LargestIndex() const { return value_; }
152 
153  protected:
155  int value_;
156 
157  private:
159  : value_(0){}; // hidden from users
160 };
161 
162 void tokenize(std::string srcInput, std::string whitespace, std::string prefer, std::vector<std::string>& tokens);
163 
164 // this function takes a set of tokens and returns the first "block", i.e. those
165 // values (including) brackets that correspond to the first block
166 std::vector<std::string>::const_iterator buildSubBlock(
167  std::vector<std::string>::const_iterator begin,
168  std::vector<std::string>::const_iterator end,
169  std::vector<std::string>& subBlock);
170 
171 // This function takes a tokenized vector and converts it to a block reorder manager
172 Teuchos::RCP<Xpetra::BlockReorderManager> blockedReorderFromTokens(const std::vector<std::string>& tokens);
173 
185 Teuchos::RCP<const Xpetra::BlockReorderManager> blockedReorderFromString(std::string reorder);
186 } // namespace Xpetra
187 
188 #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