Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_Sparse3Tensor.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef STOKHOS_SPARSE3TENSOR_HPP
43 #define STOKHOS_SPARSE3TENSOR_HPP
44 
45 #include <ostream>
46 #include <map>
47 #include "Stokhos_SparseArray.hpp"
48 
49 namespace Stokhos {
50 
55  template <typename ordinal_type, typename value_type>
56  class Sparse3Tensor {
57 
58  private:
59 
60  typedef std::map<const ordinal_type, value_type> i_map;
61  typedef std::map<const ordinal_type, i_map> ji_map;
62  typedef std::map<const ordinal_type, ji_map> kji_map;
63 
64  typedef std::map<const ordinal_type, value_type> j_map;
65  typedef std::map<const ordinal_type, j_map> kj_map;
66  typedef std::map<const ordinal_type, kj_map> ikj_map;
67 
71 
75 
76  public:
77 
80 
83 
86 
89 
92 
95 
98 
101 
103  Sparse3Tensor();
104 
107 
110  const value_type& c);
111 
114  const value_type& c);
115 
117 
122  void fillComplete();
123 
125  bool fillCompleted() const;
126 
128  void print(std::ostream& os) const;
129 
132 
134  ordinal_type num_entries() const;
135 
138 
140  ordinal_type num_k() const;
141 
143  ordinal_type num_j(const k_iterator& k) const;
144 
146  ordinal_type num_i(const kj_iterator& j) const;
147 
149  k_iterator find_k(ordinal_type k) const;
150 
152  kj_iterator find_j(const k_iterator& k, ordinal_type j) const;
153 
155  kji_iterator find_i(const kj_iterator& j, ordinal_type i) const;
156 
158  k_iterator k_begin() const;
159 
161  k_iterator k_end() const;
162 
165 
167  k_reverse_iterator k_rend() const;
168 
170  kj_iterator j_begin(const k_iterator& k) const;
171 
173  kj_iterator j_end(const k_iterator& k) const;
174 
176  kj_iterator j_begin(const k_reverse_iterator& k) const;
177 
179  kj_iterator j_end(const k_reverse_iterator& k) const;
180 
182  kji_iterator i_begin(const kj_iterator& j) const;
183 
185  kji_iterator i_end(const kj_iterator& j) const;
186 
188 
191 
193  ordinal_type num_i() const;
194 
196  ordinal_type num_k(const i_iterator& i) const;
197 
199  ordinal_type num_j(const ik_iterator& k) const;
200 
202  i_iterator find_i(ordinal_type i) const;
203 
205  ik_iterator find_k(const i_iterator& i, ordinal_type k) const;
206 
208  ikj_iterator find_j(const ik_iterator& k, ordinal_type j) const;
209 
211  i_iterator i_begin() const;
212 
214  i_iterator i_end() const;
215 
218 
220  i_reverse_iterator i_rend() const;
221 
223  ik_iterator k_begin(const i_iterator& i) const;
224 
226  ik_iterator k_end(const i_iterator& i) const;
227 
229  ik_iterator k_begin(const i_reverse_iterator& i) const;
230 
232  ik_iterator k_end(const i_reverse_iterator& i) const;
233 
235  ikj_iterator j_begin(const ik_iterator& k) const;
236 
238  ikj_iterator j_end(const ik_iterator& k) const;
239 
241 
242  private:
243 
244  // Prohibit copying
246 
247  // Prohibit Assignment
249 
250  protected:
251 
254 
257 
260 
263 
265 
268 
271 
274 
276 
277  }; // class Sparse3Tensor
278 
282  template <typename ordinal_type, typename value_type>
283  std::ostream&
284  operator << (std::ostream& os,
286  Cijk.print(os);
287  return os;
288  }
289 
293  template <typename index_iterator, typename value_iterator>
296  return *it;
297  }
298 
302  template <typename index_iterator, typename value_iterator>
305  {
306  return *it;
307  }
308 
313  template <typename index_iterator, typename value_iterator>
316  return it.value();
317  }
318 
319 } // namespace Stokhos
320 
321 // Include template definitions
323 
324 #endif // STOKHOS_SPARSE3TENSOR_HPP
j_sparse_array::const_iterator ikj_iterator
Iterator for looping over j entries given i and k.
bool fill_completed
Indicate whether fillComplete() has been called.
SparseArray< ordinal_type, j_sparse_array > kj_sparse_array
Sparse3Tensor & operator=(const Sparse3Tensor &b)
k_iterator k_begin() const
Iterator pointing to first k entry.
SparseArrayIterator< index_iterator, value_iterator >::value_type index(const SparseArrayIterator< index_iterator, value_iterator > &it)
std::map< const ordinal_type, ji_map > kji_map
ordinal_type num_j(const k_iterator &k) const
Number of j entries in C(i,j,k) for given k.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
std::iterator_traits< value_iterator_type >::reference value_reference
ji_sparse_array::const_iterator kj_iterator
Iterator for looping over j entries given k.
ikj_sparse_array::const_iterator i_iterator
Iterator for looping over i entries.
ordinal_type num_k() const
Number of k entries in C(i,j,k)
kj_iterator j_begin(const k_iterator &k) const
Iterator pointing to first j entry for given k.
ikj_sparse_array::const_reverse_iterator i_reverse_iterator
Iterator for looping over i entries in reverse.
void fillComplete()
Signal all terms have been added.
std::map< const ordinal_type, kj_map > ikj_map
Container for a &quot;sparse&quot; array.
i_reverse_iterator i_rbegin() const
Reverse iterator pointing to last k entry.
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
Bi-directional iterator for traversing a sparse array.
Bi-directional reverse iterator for traversing a sparse array.
std::map< const ordinal_type, value_type > j_map
kji_sparse_array::const_iterator k_iterator
Iterator for looping over k entries.
ikj_sparse_array ikj_array
kji indices and values in Cijk (data structure for iterating)
SparseArrayReverseIterator< index_iterator, value_iterator >::value_type index(const SparseArrayReverseIterator< index_iterator, value_iterator > &it)
std::map< const ordinal_type, j_map > kj_map
std::ostream & operator<<(std::ostream &os, const ProductContainer< coeff_type > &vec)
SparseArray< ordinal_type, value_type > j_sparse_array
void add_term(ordinal_type i, ordinal_type j, ordinal_type k, const value_type &c)
Add new term for given (i,j,k)
i_reverse_iterator i_rend() const
Reverse iterator pointing to first k entry.
std::map< const ordinal_type, i_map > ji_map
SparseArray< ordinal_type, ji_sparse_array > kji_sparse_array
k_iterator k_end() const
Iterator pointing to last k entry.
k_iterator find_k(ordinal_type k) const
Return k iterator for given index k.
kji_sparse_array kji_array
kji indices and values in Cijk (data structure for iterating)
i_iterator i_begin() const
Iterator pointing to first k entry.
kj_sparse_array::const_iterator ik_iterator
Iterator for looping over k entries given i.
bool fillCompleted() const
Return whether fillComplete() has been called.
j_sparse_array::const_iterator kji_iterator
Iterator for looping over i entries given k and j.
SparseArray< ordinal_type, value_type > i_sparse_array
std::map< const ordinal_type, value_type > i_map
ikj_map ikj_data
ikj indices and values in Cijk (data structure for filling)
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
kji_iterator find_i(const kj_iterator &j, ordinal_type i) const
Return i iterator given j iterator and index i.
ordinal_type num_i() const
Number of i entries in C(i,j,k)
void print(std::ostream &os) const
Print tensor.
void sum_term(ordinal_type i, ordinal_type j, ordinal_type k, const value_type &c)
Add new term for given (i,j,k) and sum in if already there.
k_reverse_iterator k_rbegin() const
Reverse iterator pointing to last k entry.
SparseArray< ordinal_type, i_sparse_array > ji_sparse_array
value_type getValue(ordinal_type i, ordinal_type j, ordinal_type k) const
Get Cijk value for a given i, j, k indices.
value_reference value() const
Return value associated with iterator.
k_reverse_iterator k_rend() const
Reverse iterator pointing to first k entry.
i_iterator i_end() const
Iterator pointing to last k entry.
kj_iterator find_j(const k_iterator &k, ordinal_type j) const
Return j iterator given k iterator and index j.
kji_map kji_data
kji indices and values in Cijk (data structure for filling)
kji_sparse_array::const_reverse_iterator k_reverse_iterator
Iterator for looping over k entries in reverse.
SparseArray< ordinal_type, kj_sparse_array > ikj_sparse_array
ordinal_type num_entries() const
Return number of non-zero entries.