52 #ifndef _ZOLTAN2_MODELHELPERS_HPP_
53 #define _ZOLTAN2_MODELHELPERS_HPP_
59 template <
typename User>
60 RCP<Tpetra::CrsMatrix<int,
61 typename MeshAdapter<User>::lno_t,
62 typename MeshAdapter<User>::gno_t,
63 typename MeshAdapter<User>::node_t> >
65 const RCP<
const Comm<int> > comm,
73 typedef int nonzero_t;
74 typedef Tpetra::CrsMatrix<nonzero_t,lno_t,gno_t,node_t> sparse_matrix_type;
75 typedef Tpetra::Map<lno_t, gno_t, node_t> map_type;
77 const GST dummy = Teuchos::OrdinalTraits<GST>::invalid ();
80 if (ia->availAdjs(sourcetarget, through)) {
88 const offset_t *offsets=NULL;
89 const gno_t *adjacencyIds=NULL;
90 ia->getAdjsView(sourcetarget, through, offsets, adjacencyIds);
92 const gno_t *Ids=NULL;
93 ia->getIDsViewOf(sourcetarget, Ids);
95 const gno_t *throughIds=NULL;
96 ia->getIDsViewOf(through, throughIds);
98 size_t LocalNumIDs = ia->getLocalNumOf(sourcetarget);
104 RCP<const map_type> sourcetargetMapG;
105 RCP<const map_type> throughMapG;
108 size_t LocalNumOfThrough = ia->getLocalNumOf(through);
113 min[0] = std::numeric_limits<gno_t>::max();
114 for (
size_t i = 0; i < LocalNumIDs; ++i) {
115 if (Ids[i] < min[0]) {
118 size_t ncols = offsets[i+1] - offsets[i];
119 if (ncols > maxcols) maxcols = ncols;
123 min[1] = std::numeric_limits<gno_t>::max();
124 for (
size_t i = 0; i < LocalNumOfThrough; ++i) {
125 if (throughIds[i] < min[1]) {
126 min[1] = throughIds[i];
131 Teuchos::reduceAll<int, gno_t>(*comm, Teuchos::REDUCE_MIN, 2, min, gmin);
134 ArrayView<const gno_t> sourceTargetGIDs(Ids, LocalNumIDs);
135 sourcetargetMapG = rcp(
new map_type(dummy,
136 sourceTargetGIDs, gmin[0], comm));
150 ArrayView<const gno_t> throughGIDs(throughIds, LocalNumOfThrough);
151 throughMapG = rcp (
new map_type(dummy,
152 throughGIDs, gmin[1], comm));
155 RCP<const map_type> oneToOneTMap =
156 Tpetra::createOneToOne<lno_t, gno_t, node_t>(throughMapG);
162 RCP<sparse_matrix_type> adjsMatrix;
165 adjsMatrix = rcp (
new sparse_matrix_type (sourcetargetMapG,
168 Array<nonzero_t> justOneA(maxcols, 1);
169 ArrayView<const gno_t> adjacencyIdsAV(adjacencyIds, offsets[LocalNumIDs]);
171 for (
size_t localElement=0; localElement<LocalNumIDs; ++localElement){
173 size_t ncols = offsets[localElement+1] - offsets[localElement];
174 adjsMatrix->insertGlobalValues(Ids[localElement],
175 adjacencyIdsAV(offsets[localElement], ncols),
180 adjsMatrix->fillComplete (oneToOneTMap,
181 adjsMatrix->getRowMap());
184 RCP<sparse_matrix_type> secondAdjs =
185 rcp (
new sparse_matrix_type(adjsMatrix->getRowMap(),0));
186 Tpetra::MatrixMatrix::Multiply(*adjsMatrix,
false,*adjsMatrix,
190 return RCP<sparse_matrix_type>();
193 template <
typename User>
196 const RCP<
const Comm<int> > comm,
207 typedef int nonzero_t;
208 typedef Tpetra::CrsMatrix<nonzero_t,lno_t,gno_t,node_t> sparse_matrix_type;
213 size_t LocalNumIDs = ia->getLocalNumOf(sourcetarget);
214 lno_t *start =
new lno_t [LocalNumIDs+1];
216 if (secondAdjs!=RCP<sparse_matrix_type>()) {
217 Array<gno_t> Indices;
218 Array<nonzero_t> Values;
222 gno_t
const *Ids=NULL;
223 ia->getIDsViewOf(sourcetarget, Ids);
225 std::vector<gno_t> adj;
227 for (
size_t localElement=0; localElement<LocalNumIDs; ++localElement){
228 start[localElement] = nadj;
229 const gno_t globalRow = Ids[localElement];
230 size_t NumEntries = secondAdjs->getNumEntriesInGlobalRow (globalRow);
231 Indices.resize (NumEntries);
232 Values.resize (NumEntries);
233 secondAdjs->getGlobalRowCopy (globalRow,Indices(),Values(),NumEntries);
235 for (
size_t j = 0; j < NumEntries; ++j) {
236 if(globalRow != Indices[j]) {
237 adj.push_back(Indices[j]);
244 start[LocalNumIDs] = nadj;
246 gno_t *adj_ =
new gno_t [nadj];
248 for (
size_t i=0; i < nadj; i++) {
252 offsets = arcp<offset_t>(start, 0, LocalNumIDs+1,
true);
253 adjacencyIds = arcp<gno_t>(adj_, 0, nadj,
true);
257 for (
size_t i = 0; i <= LocalNumIDs; i++)
260 offsets = arcp<offset_t>(start, 0, LocalNumIDs+1,
true);
261 adjacencyIds = Teuchos::null;
RCP< Tpetra::CrsMatrix< int, typename MeshAdapter< User >::lno_t, typename MeshAdapter< User >::gno_t, typename MeshAdapter< User >::node_t > > get2ndAdjsMatFromAdjs(const Teuchos::RCP< const MeshAdapter< User > > &ia, const RCP< const Comm< int > > comm, Zoltan2::MeshEntityType sourcetarget, Zoltan2::MeshEntityType through)
void get2ndAdjsViewFromAdjs(const Teuchos::RCP< const MeshAdapter< User > > &ia, const RCP< const Comm< int > > comm, Zoltan2::MeshEntityType sourcetarget, Zoltan2::MeshEntityType through, Teuchos::ArrayRCP< typename MeshAdapter< User >::offset_t > &offsets, Teuchos::ArrayRCP< typename MeshAdapter< User >::gno_t > &adjacencyIds)
InputTraits< User >::gno_t gno_t
Defines the MeshAdapter interface.
MeshAdapter defines the interface for mesh input.
InputTraits< User >::lno_t lno_t
MeshEntityType
Enumerate entity types for meshes: Regions, Faces, Edges, or Vertices.
Tpetra::global_size_t global_size_t
InputTraits< User >::offset_t offset_t