Stokhos Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
epetra
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
47
#include "
Stokhos_Sparse3Tensor.hpp
"
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
55
namespace
Stokhos
{
56
58
65
template
<
typename
ordinal_type,
typename
value_type>
66
Teuchos::RCP<Epetra_CrsGraph>
67
sparse3Tensor2CrsGraph
(
68
const
Stokhos::OrthogPolyBasis<ordinal_type,value_type>
& basis,
69
const
Stokhos::Sparse3Tensor<ordinal_type,value_type>
& Cijk,
70
const
Epetra_Comm
& comm)
71
{
72
typedef
Stokhos::Sparse3Tensor<ordinal_type,value_type>
Cijk_type
;
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>
115
sparse3Tensor2CrsGraph
(
116
const
Stokhos::Sparse3Tensor<ordinal_type,value_type>
& Cijk,
117
const
Epetra_BlockMap
& map)
118
{
119
typedef
Stokhos::Sparse3Tensor<ordinal_type,value_type>
Cijk_type
;
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
148
sparse3Tensor2MatrixMarket
(
149
const
Stokhos::OrthogPolyBasis<ordinal_type,value_type>
& basis,
150
const
Stokhos::Sparse3Tensor<ordinal_type,value_type>
& Cijk,
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
164
sparse3Tensor2MatrixMarket
(
165
const
Stokhos::Sparse3Tensor<ordinal_type,value_type>
& Cijk,
166
const
Epetra_BlockMap
& map,
167
const
std::string& file)
168
{
169
Teuchos::RCP<Epetra_CrsGraph> graph =
170
Stokhos::sparse3Tensor2CrsGraph
(Cijk, map);
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
Epetra_BlockMap.h
Epetra_Comm.h
Epetra_CrsGraph.h
Epetra_CrsMatrix.h
Copy
Copy
Epetra_LocalMap.h
j
j
Definition
Sacado_Fad_Exp_MP_Vector.hpp:527
Stokhos_Sparse3Tensor.hpp
Epetra_BlockMap
Epetra_Comm
Epetra_CrsGraph
Epetra_CrsMatrix
Epetra_CrsMatrix::FillComplete
int FillComplete(bool OptimizeDataStorage=true)
Epetra_CrsMatrix::PutScalar
int PutScalar(double ScalarConstant)
Epetra_LocalMap
Stokhos::OrthogPolyBasis
Abstract base class for multivariate orthogonal polynomials.
Definition
Stokhos_OrthogPolyBasis.hpp:74
Stokhos::OrthogPolyBasis::size
virtual ordinal_type size() const =0
Return total size of basis.
Stokhos::Cijk_type
Stokhos::ordinal_type
Stokhos::Sparse3Tensor
Data structure storing a sparse 3-tensor C(i,j,k) in a a compressed format.
Definition
Stokhos_Sparse3Tensor.hpp:56
Stokhos::Sparse3Tensor::k_begin
k_iterator k_begin() const
Iterator pointing to first k entry.
Definition
Stokhos_Sparse3TensorImp.hpp:287
Stokhos::Sparse3Tensor::j_begin
kj_iterator j_begin(const k_iterator &k) const
Iterator pointing to first j entry for given k.
Definition
Stokhos_Sparse3TensorImp.hpp:335
Stokhos::Sparse3Tensor::i_begin
kji_iterator i_begin(const kj_iterator &j) const
Iterator pointing to first i entry for given j and k.
Definition
Stokhos_Sparse3TensorImp.hpp:383
Stokhos::Sparse3Tensor::j_end
kj_iterator j_end(const k_iterator &k) const
Iterator pointing to last j entry for given k.
Definition
Stokhos_Sparse3TensorImp.hpp:347
Stokhos::Sparse3Tensor::i_end
kji_iterator i_end(const kj_iterator &j) const
Iterator pointing to last i entry for given j and k.
Definition
Stokhos_Sparse3TensorImp.hpp:395
Stokhos::Sparse3Tensor::index
SparseArrayIterator< index_iterator, value_iterator >::value_type index(const SparseArrayIterator< index_iterator, value_iterator > &it)
Definition
Stokhos_Sparse3Tensor.hpp:295
Stokhos::Sparse3Tensor::k_end
k_iterator k_end() const
Iterator pointing to last k entry.
Definition
Stokhos_Sparse3TensorImp.hpp:299
Stokhos
Top-level namespace for Stokhos classes and functions.
Definition
Stokhos_AbstractPreconditionerFactory.hpp:48
Stokhos::sparse3Tensor2CrsGraph
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.
Definition
Stokhos_Sparse3TensorUtilities.hpp:67
Stokhos::sparse3Tensor2MatrixMarket
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)
Definition
Stokhos_Sparse3TensorUtilities.hpp:148
Generated by
1.17.0