Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_Sparse3TensorUtilities.hpp
Go to the documentation of this file.
1// $Id$
2// $Source$
3// @HEADER
4// ***********************************************************************
5//
6// Stokhos Package
7// Copyright (2009) Sandia Corporation
8//
9// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
10// license for use of this work by or on behalf of the U.S. Government.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38//
39// Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
40//
41// ***********************************************************************
42// @HEADER
43
44#ifndef STOKHOS_SPARSE_3_TENSOR_UTILITIES_HPP
45#define STOKHOS_SPARSE_3_TENSOR_UTILITIES_HPP
46
48#include "Epetra_Comm.h"
49#include "Epetra_CrsGraph.h"
50#include "Epetra_BlockMap.h"
51#include "Epetra_LocalMap.h"
52#include "Epetra_CrsMatrix.h"
53#include "EpetraExt_RowMatrixOut.h"
54
55namespace Stokhos {
56
58
65 template <typename ordinal_type, typename value_type>
66 Teuchos::RCP<Epetra_CrsGraph>
70 const Epetra_Comm& comm)
71 {
73
74 // Number of stochastic rows
75 ordinal_type num_rows = basis.size();
76
77 // Replicated local map
78 Epetra_LocalMap map(num_rows, 0, comm);
79
80 // Graph to be created
81 Teuchos::RCP<Epetra_CrsGraph> graph =
82 Teuchos::rcp(new Epetra_CrsGraph(Copy, map, 0));
83
84 // Loop over Cijk entries including a non-zero in the graph at
85 // indices (i,j) if there is any k for which Cijk is non-zero
86 for (typename Cijk_type::k_iterator k_it=Cijk.k_begin();
87 k_it!=Cijk.k_end(); ++k_it) {
88 for (typename Cijk_type::kj_iterator j_it = Cijk.j_begin(k_it);
89 j_it != Cijk.j_end(k_it); ++j_it) {
90 ordinal_type j = index(j_it);
91 for (typename Cijk_type::kji_iterator i_it = Cijk.i_begin(j_it);
92 i_it != Cijk.i_end(j_it); ++i_it) {
93 ordinal_type i = index(i_it);
94 graph->InsertGlobalIndices(i, 1, &j);
95 }
96 }
97 }
98
99 // Sort, remove redundencies, transform to local, ...
100 graph->FillComplete();
101
102 return graph;
103 }
104
106
113 template <typename ordinal_type, typename value_type>
114 Teuchos::RCP<Epetra_CrsGraph>
117 const Epetra_BlockMap& map)
118 {
120
121 // Graph to be created
122 Teuchos::RCP<Epetra_CrsGraph> graph =
123 Teuchos::rcp(new Epetra_CrsGraph(Copy, map, 0));
124
125 // Loop over Cijk entries including a non-zero in the graph at
126 // indices (i,j) if there is any k for which Cijk is non-zero
127 for (typename Cijk_type::k_iterator k_it=Cijk.k_begin();
128 k_it!=Cijk.k_end(); ++k_it) {
129 for (typename Cijk_type::kj_iterator j_it = Cijk.j_begin(k_it);
130 j_it != Cijk.j_end(k_it); ++j_it) {
131 ordinal_type j = index(j_it);
132 for (typename Cijk_type::kji_iterator i_it = Cijk.i_begin(j_it);
133 i_it != Cijk.i_end(j_it); ++i_it) {
134 ordinal_type i = index(i_it);
135 graph->InsertGlobalIndices(i, 1, &j);
136 }
137 }
138 }
139
140 // Sort, remove redundencies, transform to local, ...
141 graph->FillComplete();
142
143 return graph;
144 }
145
146 template <typename ordinal_type, typename value_type>
147 void
151 const Epetra_Comm& comm,
152 const std::string& file)
153 {
154 Teuchos::RCP<Epetra_CrsGraph> graph =
155 Stokhos::sparse3Tensor2CrsGraph(basis, Cijk, comm);
156 Epetra_CrsMatrix mat(Copy, *graph);
157 mat.FillComplete();
158 mat.PutScalar(1.0);
159 EpetraExt::RowMatrixToMatrixMarketFile(file.c_str(), mat);
160 }
161
162 template <typename ordinal_type, typename value_type>
163 void
166 const Epetra_BlockMap& map,
167 const std::string& file)
168 {
169 Teuchos::RCP<Epetra_CrsGraph> graph =
171 Epetra_CrsMatrix mat(Copy, *graph);
172 mat.FillComplete();
173 mat.PutScalar(1.0);
174 EpetraExt::RowMatrixToMatrixMarketFile(file.c_str(), mat);
175 }
176
177} // namespace Stokhos
178
179#endif // SPARSE_3_TENSOR_UTILITIES_HPP
Copy
int FillComplete(bool OptimizeDataStorage=true)
int PutScalar(double ScalarConstant)
Abstract base class for multivariate orthogonal polynomials.
virtual ordinal_type size() const =0
Return total size of basis.
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
k_iterator k_begin() const
Iterator pointing to first k entry.
kji_iterator i_begin(const kj_iterator &j) const
Iterator pointing to first i entry for given j and k.
kj_iterator j_begin(const k_iterator &k) const
Iterator pointing to first j entry for given k.
kji_iterator i_end(const kj_iterator &j) const
Iterator pointing to last i entry for given j and k.
k_iterator k_end() const
Iterator pointing to last k entry.
Top-level namespace for Stokhos classes and functions.
Teuchos::RCP< Epetra_CrsGraph > sparse3Tensor2CrsGraph(const Stokhos::OrthogPolyBasis< ordinal_type, value_type > &basis, const Stokhos::Sparse3Tensor< ordinal_type, value_type > &Cijk, const Epetra_Comm &comm)
Build an Epetra_CrsGraph from a sparse 3 tensor.
void sparse3Tensor2MatrixMarket(const Stokhos::OrthogPolyBasis< ordinal_type, value_type > &basis, const Stokhos::Sparse3Tensor< ordinal_type, value_type > &Cijk, const Epetra_Comm &comm, const std::string &file)