13 template <
typename ordinal_type,
typename value_type>
20 template <
typename ordinal_type,
typename value_type>
27 "You can't call add_term() after calling fillComplete()!");
30 kji_data[k][
j][i] = c;
31 ikj_data[i][k][
j] = c;
34 template <
typename ordinal_type,
typename value_type>
41 "You can't call sum_term() after calling fillComplete()!");
44 kji_data[k][
j][i] += c;
45 ikj_data[i][k][
j] += c;
48 template <
typename ordinal_type,
typename value_type>
56 ikj_array.resize(ikj_data.size());
58 for (
typename ikj_map::const_iterator i_it = ikj_data.begin();
59 i_it != ikj_data.end(); ++i_it) {
60 ikj_array.indices[n] = i_it->first;
61 ikj_array.values[n].resize(i_it->second.size());
63 for (
typename kj_map::const_iterator k_it = i_it->second.begin();
64 k_it != i_it->second.end(); ++k_it) {
65 ikj_array.values[n].indices[l] = k_it->first;
66 ikj_array.values[n].values[l].resize(k_it->second.size());
68 for (
typename j_map::const_iterator j_it = k_it->second.begin();
69 j_it != k_it->second.end(); ++j_it) {
70 ikj_array.values[n].values[l].indices[m] = j_it->first;
71 ikj_array.values[n].values[l].values[m] = j_it->second;
79 kji_array.resize(kji_data.size());
81 for (
typename kji_map::const_iterator k_it = kji_data.begin();
82 k_it != kji_data.end(); ++k_it) {
83 kji_array.indices[n] = k_it->first;
84 kji_array.values[n].resize(k_it->second.size());
86 for (
typename ji_map::const_iterator j_it = k_it->second.begin();
87 j_it != k_it->second.end(); ++j_it) {
88 kji_array.values[n].indices[l] = j_it->first;
89 kji_array.values[n].values[l].resize(j_it->second.size());
91 for (
typename i_map::const_iterator i_it = j_it->second.begin();
92 i_it != j_it->second.end(); ++i_it) {
93 kji_array.values[n].values[l].indices[m] = i_it->first;
94 kji_array.values[n].values[l].values[m] = i_it->second;
105 fill_completed =
true;
108 template <
typename ordinal_type,
typename value_type>
113 return fill_completed;
116 template <
typename ordinal_type,
typename value_type>
123 "You must call fillComplete() before calling print()!");
129 os <<
"k = " << index(k)
130 <<
", j = " << index(
j)
131 <<
", i = " << index(i)
132 <<
", Cijk = " << value(i) << std::endl;
135 template <
typename ordinal_type,
typename value_type>
142 "You must call fillComplete() before calling getValue()!");
150 if (j_it == j_end(k_it))
154 if (i_it == i_end(j_it))
160 template <
typename ordinal_type,
typename value_type>
167 "You must call fillComplete() before calling num_entries()!");
171 for (
k_iterator k = k_begin(); k != k_end(); ++k)
179 template <
typename ordinal_type,
typename value_type>
186 "You must call fillComplete() before calling num_k()!");
188 return kji_array.size();
191 template <
typename ordinal_type,
typename value_type>
198 "You must call fillComplete() before calling num_j()!");
201 return k.
value().size();
204 template <
typename ordinal_type,
typename value_type>
211 "You must call fillComplete() before calling num_i()!");
213 return j.
value().size();
216 template <
typename ordinal_type,
typename value_type>
223 "You must call fillComplete() before calling find_k()!");
225 return kji_array.find(k);
228 template <
typename ordinal_type,
typename value_type>
235 "You must call fillComplete() before calling find_j()!");
237 return k.
value().find(j);
240 template <
typename ordinal_type,
typename value_type>
247 "You must call fillComplete() before calling find_i()!");
249 return j.
value().find(i);
252 template <
typename ordinal_type,
typename value_type>
259 "You must call fillComplete() before calling k_begin()!");
261 return kji_array.begin();
264 template <
typename ordinal_type,
typename value_type>
271 "You must call fillComplete() before calling k_end()!");
273 return kji_array.end();
276 template <
typename ordinal_type,
typename value_type>
283 "You must call fillComplete() before calling k_rbegin()!");
285 return kji_array.rbegin();
288 template <
typename ordinal_type,
typename value_type>
295 "You must call fillComplete() before calling k_rend()!");
297 return kji_array.rend();
300 template <
typename ordinal_type,
typename value_type>
307 "You must call fillComplete() before calling j_begin()!");
309 return k.
value().begin();
312 template <
typename ordinal_type,
typename value_type>
319 "You must call fillComplete() before calling j_end()!");
321 return k.
value().end();
324 template <
typename ordinal_type,
typename value_type>
331 "You must call fillComplete() before calling j_begin()!");
333 return k.
value().begin();
336 template <
typename ordinal_type,
typename value_type>
343 "You must call fillComplete() before calling j_end()!");
345 return k.
value().end();
348 template <
typename ordinal_type,
typename value_type>
355 "You must call fillComplete() before calling i_begin()!");
357 return j.
value().begin();
360 template <
typename ordinal_type,
typename value_type>
367 "You must call fillComplete() before calling i_end()!");
369 return j.
value().end();
372 template <
typename ordinal_type,
typename value_type>
379 "You must call fillComplete() before calling num_i()!");
381 return ikj_array.size();
384 template <
typename ordinal_type,
typename value_type>
391 "You must call fillComplete() before calling num_k()!");
393 return i.
value().size();
396 template <
typename ordinal_type,
typename value_type>
399 num_j(
const ik_iterator& k)
const
403 "You must call fillComplete() before calling num_j()!");
405 return k.value().size();
408 template <
typename ordinal_type,
typename value_type>
415 "You must call fillComplete() before calling find_i()!");
417 return ikj_array.find(i);
420 template <
typename ordinal_type,
typename value_type>
427 "You must call fillComplete() before calling find_k()!");
429 return i.
value().find(k);
432 template <
typename ordinal_type,
typename value_type>
439 "You must call fillComplete() before calling find_j()!");
441 return k.value().find(j);
444 template <
typename ordinal_type,
typename value_type>
451 "You must call fillComplete() before calling i_begin()!");
453 return ikj_array.begin();
456 template <
typename ordinal_type,
typename value_type>
463 "You must call fillComplete() before calling i_end()!");
465 return ikj_array.end();
468 template <
typename ordinal_type,
typename value_type>
475 "You must call fillComplete() before calling i_rbegin()!");
477 return ikj_array.rbegin();
480 template <
typename ordinal_type,
typename value_type>
487 "You must call fillComplete() before calling i_rend()!");
489 return ikj_array.rend();
492 template <
typename ordinal_type,
typename value_type>
499 "You must call fillComplete() before calling k_begin()!");
501 return i.
value().begin();
504 template <
typename ordinal_type,
typename value_type>
511 "You must call fillComplete() before calling k_end()!");
513 return i.
value().end();
516 template <
typename ordinal_type,
typename value_type>
523 "You must call fillComplete() before calling k_begin()!");
525 return i.
value().begin();
528 template <
typename ordinal_type,
typename value_type>
535 "You must call fillComplete() before calling k_end()!");
537 return i.
value().end();
540 template <
typename ordinal_type,
typename value_type>
543 j_begin(
const ik_iterator& k)
const
547 "You must call fillComplete() before calling j_begin()!");
549 return k.value().begin();
552 template <
typename ordinal_type,
typename value_type>
555 j_end(
const ik_iterator& k)
const
559 "You must call fillComplete() before calling j_end()!");
561 return k.value().end();
Sparse3Tensor()
Constructor.
k_iterator k_begin() const
Iterator pointing to first k entry.
ordinal_type num_j(const k_iterator &k) const
Number of j entries in C(i,j,k) for given k.
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void fillComplete()
Signal all terms have been added.
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.
void add_term(ordinal_type i, ordinal_type j, ordinal_type k, const value_type &c)
Add new term for given (i,j,k)
value_reference value() const
Return value associated with iterator.
i_reverse_iterator i_rend() const
Reverse iterator pointing to first k entry.
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.
i_iterator i_begin() const
Iterator pointing to first k entry.
bool fillCompleted() const
Return whether fillComplete() has been called.
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.
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.
ordinal_type num_entries() const
Return number of non-zero entries.