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,
63 typename MeshAdapter<User>::node_t> >
65 const RCP<
const Comm<int> > comm,
68 typedef typename MeshAdapter<User>::gno_t gno_t;
69 typedef typename MeshAdapter<User>::lno_t lno_t;
72 typedef int nonzero_t;
73 typedef Tpetra::CrsMatrix<nonzero_t,lno_t,gno_t,node_t> sparse_matrix_type;
74 typedef Tpetra::Map<lno_t, gno_t, node_t> map_type;
76 const GST
INVALID = Teuchos::OrdinalTraits<GST>::invalid ();
79 if (ia->availAdjs(sourcetarget, through)) {
80 using Tpetra::DefaultPlatform;
88 const lno_t *offsets=NULL;
89 const gno_t *adjacencyIds=NULL;
90 ia->getAdjsView(sourcetarget, through, offsets, adjacencyIds);
92 gno_t
const *Ids=NULL;
93 ia->getIDsViewOf(sourcetarget, Ids);
95 gno_t
const *throughIds=NULL;
96 ia->getIDsViewOf(through, throughIds);
98 size_t LocalNumIDs = ia->getLocalNumOf(sourcetarget);
104 Array<gno_t> sourcetargetGIDs;
105 Array<gno_t> throughGIDs;
106 RCP<const map_type> sourcetargetMapG;
107 RCP<const map_type> throughMapG;
110 size_t LocalNumOfThrough = ia->getLocalNumOf(through);
113 sourcetargetGIDs.resize (LocalNumIDs);
114 throughGIDs.resize (LocalNumOfThrough);
116 min[0] = as<gno_t> (Ids[0]);
117 for (
size_t i = 0; i < LocalNumIDs; ++i) {
118 sourcetargetGIDs[i] = as<gno_t> (Ids[i]);
120 if (sourcetargetGIDs[i] < min[0]) {
121 min[0] = sourcetargetGIDs[i];
126 min[1] = as<gno_t> (throughIds[0]);
127 for (
size_t i = 0; i < LocalNumOfThrough; ++i) {
128 throughGIDs[i] = as<gno_t> (throughIds[i]);
130 if (throughGIDs[i] < min[1]) {
131 min[1] = throughGIDs[i];
136 Teuchos::reduceAll<int, gno_t>(*comm, Teuchos::REDUCE_MIN, 2, min, gmin);
139 sourcetargetMapG = rcp(
new map_type(
141 sourcetargetGIDs(), gmin[0], comm));
155 throughMapG = rcp (
new map_type(INVALID,
156 throughGIDs, gmin[1], comm));
159 RCP<const map_type> oneToOneTMap =
160 Tpetra::createOneToOne<lno_t, gno_t, node_t>(throughMapG);
166 RCP<sparse_matrix_type> adjsMatrix;
169 adjsMatrix = rcp (
new sparse_matrix_type (sourcetargetMapG,
172 nonzero_t justOne = 1;
173 ArrayView<nonzero_t> justOneAV = Teuchos::arrayView (&justOne, 1);
175 for (
size_t localElement=0; localElement<LocalNumIDs; ++localElement){
178 gno_t globalRowT = as<gno_t> (Ids[localElement]);
183 for (lno_t j=offsets[localElement]; j<offsets[localElement+1]; ++j){
184 gno_t globalCol = as<gno_t> (adjacencyIds[j]);
186 ArrayView<gno_t> globalColAV = Teuchos::arrayView (&globalCol,1);
189 adjsMatrix->insertGlobalValues(globalRowT,globalColAV,justOneAV);
194 adjsMatrix->fillComplete (oneToOneTMap,
195 adjsMatrix->getRowMap());
198 RCP<sparse_matrix_type> secondAdjs =
199 rcp (
new sparse_matrix_type(adjsMatrix->getRowMap(),0));
200 Tpetra::MatrixMatrix::Multiply(*adjsMatrix,
false,*adjsMatrix,
204 return RCP<sparse_matrix_type>();
207 template <
typename User>
209 const RCP<
const Comm<int> > comm,
212 const typename MeshAdapter<User>::lno_t *&offsets,
213 const typename MeshAdapter<User>::gno_t *&adjacencyIds)
215 typedef typename MeshAdapter<User>::gno_t gno_t;
216 typedef typename MeshAdapter<User>::lno_t lno_t;
219 typedef int nonzero_t;
220 typedef Tpetra::CrsMatrix<nonzero_t,lno_t,gno_t,node_t> sparse_matrix_type;
224 if (secondAdjs!=RCP<sparse_matrix_type>()) {
225 Array<gno_t> Indices;
226 Array<nonzero_t> Values;
230 gno_t
const *Ids=NULL;
231 ia->getIDsViewOf(sourcetarget, Ids);
233 gno_t
const *throughIds=NULL;
234 ia->getIDsViewOf(through, throughIds);
237 size_t LocalNumIDs = ia->getLocalNumOf(sourcetarget);
238 lno_t *start =
new lno_t [LocalNumIDs+1];
239 std::vector<gno_t> adj;
241 for (
size_t localElement=0; localElement<LocalNumIDs; ++localElement){
242 start[localElement] = nadj;
243 const gno_t globalRow = Ids[localElement];
244 size_t NumEntries = secondAdjs->getNumEntriesInGlobalRow (globalRow);
245 Indices.resize (NumEntries);
246 Values.resize (NumEntries);
247 secondAdjs->getGlobalRowCopy (globalRow,Indices(),Values(),NumEntries);
249 for (
size_t j = 0; j < NumEntries; ++j) {
250 if(globalRow != Indices[j]) {
251 adj.push_back(Indices[j]);
258 start[LocalNumIDs] = nadj;
260 gno_t *adj_ =
new gno_t [nadj];
262 for (
size_t i=0; i < nadj; i++) {
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)
InputTraits< User >::gno_t gno_t
Defines the MeshAdapter interface.
MeshAdapter defines the interface for mesh input.
void get2ndAdjsViewFromAdjs(const Teuchos::RCP< const MeshAdapter< User > > &ia, const RCP< const Comm< int > > comm, Zoltan2::MeshEntityType sourcetarget, Zoltan2::MeshEntityType through, const typename MeshAdapter< User >::lno_t *&offsets, const typename MeshAdapter< User >::gno_t *&adjacencyIds)
MeshEntityType
Enumerate entity types for meshes: Regions, Faces, Edges, or Vertices.