Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_TpetraLinearObjFactory_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef __Panzer_TpetraLinearObjFactory_impl_hpp__
12 #define __Panzer_TpetraLinearObjFactory_impl_hpp__
13 
14 // Panzer
15 #include "Panzer_ConnManager.hpp"
16 #ifdef PANZER_HAVE_EPETRA_STACK
17 #include "Panzer_EpetraVector_Write_GlobalEvaluationData.hpp" // JMG: Remove this eventually.
18 #endif
20 #include "Panzer_GlobalIndexer.hpp"
21 
22 // Thyra
23 #include "Thyra_TpetraVectorSpace.hpp"
24 #include "Thyra_TpetraLinearOp.hpp"
25 
26 // Tpetra
27 #include "Tpetra_MultiVector.hpp"
28 #include "Tpetra_Vector.hpp"
29 #include "Tpetra_CrsMatrix.hpp"
30 
31 namespace panzer {
32 
33 using Teuchos::RCP;
34 
35 // ************************************************************
36 // class TpetraLinearObjFactory
37 // ************************************************************
38 
39 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
42  const Teuchos::RCP<const GlobalIndexer> & gidProvider)
43  : comm_(comm), gidProvider_(gidProvider)
44 {
45  hasColProvider_ = colGidProvider_!=Teuchos::null;
46 
47  // build and register the gather/scatter evaluators with
48  // the base class.
49  this->buildGatherScatterEvaluators(*this);
50 }
51 
52 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
55  const Teuchos::RCP<const GlobalIndexer> & gidProvider,
56  const Teuchos::RCP<const GlobalIndexer> & colGidProvider)
57  : comm_(comm), gidProvider_(gidProvider), colGidProvider_(colGidProvider)
58 {
59  hasColProvider_ = colGidProvider_!=Teuchos::null;
60 
61  // build and register the gather/scatter evaluators with
62  // the base class.
63  this->buildGatherScatterEvaluators(*this);
64 }
65 
66 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
69 { }
70 
71 // LinearObjectFactory functions
73 
74 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
78 {
79  Teuchos::RCP<ContainerType> container = Teuchos::rcp(new ContainerType(getColMap(),getMap()));
80 
81  return container;
82 }
83 
84 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
88 {
89  Teuchos::RCP<ContainerType> container = Teuchos::rcp(new ContainerType(getGhostedMap(),getGhostedMap()));
90 
91  return container;
92 }
93 
94 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
95 void
98  LinearObjContainer & out,int mem) const
99 {
100  using Teuchos::is_null;
101  typedef LinearObjContainer LOC;
102 
103  const ContainerType & t_in = Teuchos::dyn_cast<const ContainerType>(in);
105 
106  // Operations occur if the GLOBAL container has the correct targets!
107  // Users set the GLOBAL continer arguments
108  if ( !is_null(t_in.get_x()) && !is_null(t_out.get_x()) && ((mem & LOC::X)==LOC::X))
109  globalToGhostTpetraVector(*t_in.get_x(),*t_out.get_x(),true);
110 
111  if ( !is_null(t_in.get_dxdt()) && !is_null(t_out.get_dxdt()) && ((mem & LOC::DxDt)==LOC::DxDt))
112  globalToGhostTpetraVector(*t_in.get_dxdt(),*t_out.get_dxdt(),true);
113 
114  if ( !is_null(t_in.get_f()) && !is_null(t_out.get_f()) && ((mem & LOC::F)==LOC::F))
115  globalToGhostTpetraVector(*t_in.get_f(),*t_out.get_f(),false);
116 }
117 
118 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
119 void
122  LinearObjContainer & out,int mem) const
123 {
124  using Teuchos::is_null;
125 
126  typedef LinearObjContainer LOC;
127 
128  const ContainerType & t_in = Teuchos::dyn_cast<const ContainerType>(in);
130 
131  // Operations occur if the GLOBAL container has the correct targets!
132  // Users set the GLOBAL continer arguments
133  if ( !is_null(t_in.get_x()) && !is_null(t_out.get_x()) && ((mem & LOC::X)==LOC::X))
134  ghostToGlobalTpetraVector(*t_in.get_x(),*t_out.get_x(),true);
135 
136  if ( !is_null(t_in.get_f()) && !is_null(t_out.get_f()) && ((mem & LOC::F)==LOC::F))
137  ghostToGlobalTpetraVector(*t_in.get_f(),*t_out.get_f(),false);
138 
139  if ( !is_null(t_in.get_A()) && !is_null(t_out.get_A()) && ((mem & LOC::Mat)==LOC::Mat))
140  ghostToGlobalTpetraMatrix(*t_in.get_A(),*t_out.get_A());
141 }
142 
143 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
144 void
146 ghostToGlobalTpetraVector(const Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & in,
147  Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & out, bool col) const
148 {
149  using Teuchos::RCP;
150 
151  // do the global distribution
152  RCP<ExportType> exporter = col ? getGhostedColExport() : getGhostedExport();
153  out.putScalar(0.0);
154  out.doExport(in,*exporter,Tpetra::ADD);
155 }
156 
157 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
158 void
160 ghostToGlobalTpetraMatrix(const Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & in,
161  Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & out) const
162 {
163  using Teuchos::RCP;
164 
165  // do the global distribution
166  RCP<ExportType> exporter = getGhostedExport();
167 
168  out.resumeFill();
169  out.setAllToScalar(0.0);
170  out.doExport(in,*exporter,Tpetra::ADD);
171  out.fillComplete(out.getDomainMap(),out.getRangeMap());
172 }
173 
174 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
175 void
177 globalToGhostTpetraVector(const Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & in,
178  Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & out, bool col) const
179 {
180  using Teuchos::RCP;
181 
182  // do the global distribution
183  RCP<ImportType> importer = col ? getGhostedColImport() : getGhostedImport();
184  out.putScalar(0.0);
185  out.doImport(in,*importer,Tpetra::INSERT);
186 }
187 
188 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
189 void
192  const LinearObjContainer & globalBCRows,
193  LinearObjContainer & ghostedObjs,
194  bool zeroVectorRows, bool adjustX) const
195 {
197 
198  const ContainerType & t_localBCRows = Teuchos::dyn_cast<const ContainerType>(localBCRows);
199  const ContainerType & t_globalBCRows = Teuchos::dyn_cast<const ContainerType>(globalBCRows);
200  ContainerType & t_ghosted = Teuchos::dyn_cast<ContainerType>(ghostedObjs);
201 
202  TEUCHOS_ASSERT(!Teuchos::is_null(t_localBCRows.get_f()));
203  TEUCHOS_ASSERT(!Teuchos::is_null(t_globalBCRows.get_f()));
204 
205  // pull out jacobian and vector
206  Teuchos::RCP<CrsMatrixType> A = t_ghosted.get_A();
207  Teuchos::RCP<VectorType> f = t_ghosted.get_f();
208  if(adjustX) f = t_ghosted.get_x();
209  Teuchos::ArrayRCP<double> f_array = f!=Teuchos::null ? f->get1dViewNonConst() : Teuchos::null;
210 
211  const VectorType & local_bcs = *(t_localBCRows.get_f());
212  const VectorType & global_bcs = *(t_globalBCRows.get_f());
213  Teuchos::ArrayRCP<const double> local_bcs_array = local_bcs.get1dView();
214  Teuchos::ArrayRCP<const double> global_bcs_array = global_bcs.get1dView();
215 
216  TEUCHOS_ASSERT(local_bcs_array.size()==global_bcs_array.size());
217  for(Ordinal i=0;i<local_bcs_array.size();i++) {
218  if(global_bcs_array[i]==0.0)
219  continue;
220 
221  if(local_bcs_array[i]==0.0 || zeroVectorRows) {
222  // this boundary condition was NOT set by this processor
223 
224  // if they exist put 0.0 in each entry
225  if(!Teuchos::is_null(f))
226  f_array[i] = 0.0;
227  if(!Teuchos::is_null(A)) {
228  std::size_t numEntries = 0;
229  std::size_t sz = A->getNumEntriesInLocalRow(i);
230  typename CrsMatrixType::nonconst_local_inds_host_view_type indices("indices", sz);
231  typename CrsMatrixType::nonconst_values_host_view_type values("values", sz);
232 
233  A->getLocalRowCopy(i,indices,values,numEntries);
234 
235  for(std::size_t c=0;c<numEntries;c++)
236  values(c) = 0.0;
237 
238  A->replaceLocalValues(i,indices,values);
239  }
240  }
241  else {
242  // this boundary condition was set by this processor
243 
244  double scaleFactor = global_bcs_array[i];
245 
246  // if they exist scale linear objects by scale factor
247  if(!Teuchos::is_null(f))
248  f_array[i] /= scaleFactor;
249  if(!Teuchos::is_null(A)) {
250  std::size_t numEntries = 0;
251  std::size_t sz = A->getNumEntriesInLocalRow(i);
252  typename CrsMatrixType::nonconst_local_inds_host_view_type indices("indices", sz);
253  typename CrsMatrixType::nonconst_values_host_view_type values("values", sz);
254 
255  A->getLocalRowCopy(i,indices,values,numEntries);
256 
257  for(std::size_t c=0;c<numEntries;c++)
258  values(c) /= scaleFactor;
259 
260  A->replaceLocalValues(i,indices,values);
261  }
262  }
263  }
264 }
265 
266 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
267 void
269 applyDirichletBCs(const LinearObjContainer & /* counter */,
270  LinearObjContainer & /* result */) const
271 {
272  TEUCHOS_ASSERT(false); // not yet implemented
273 }
274 
276 //
277 // buildReadOnlyDomainContainer()
278 //
280 template<typename Traits, typename ScalarT, typename LocalOrdinalT,
281  typename GlobalOrdinalT, typename NodeT>
285 {
286  using Teuchos::rcp;
287  using TVROGED = TpetraVector_ReadOnly_GlobalEvaluationData<ScalarT,
288  LocalOrdinalT, GlobalOrdinalT, NodeT>;
289  auto ged = rcp(new TVROGED);
290  ged->initialize(getGhostedImport(), getGhostedColMap(), getColMap());
291  return ged;
292 } // end of buildReadOnlyDomainContainer()
293 
294 #ifdef PANZER_HAVE_EPETRA_STACK
295 //
297 // buildWriteDomainContainer()
298 //
300 template<typename Traits, typename ScalarT, typename LocalOrdinalT,
301  typename GlobalOrdinalT, typename NodeT>
305 {
306  using std::logic_error;
307  using Teuchos::rcp;
309  auto ged = rcp(new EVWGED);
310  TEUCHOS_TEST_FOR_EXCEPTION(true, logic_error, "NOT IMPLEMENTED YET")
311  return ged;
312 } // end of buildWriteDomainContainer()
313 #endif // PANZER_HAVE_EPETRA_STACK
314 
315 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
317 getComm() const
318 {
319  return *Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >(getTeuchosComm());
320 }
321 
323 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
327 {
328  if(domainSpace_==Teuchos::null) {
329  if(!hasColProvider_)
330  domainSpace_ = Thyra::tpetraVectorSpace<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getMap());
331  else
332  domainSpace_ = Thyra::tpetraVectorSpace<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getColMap());
333  }
334 
335  return domainSpace_;
336 }
337 
339 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
343 {
344  if(rangeSpace_==Teuchos::null)
345  rangeSpace_ = Thyra::tpetraVectorSpace<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getMap());
346 
347  return rangeSpace_;
348 }
349 
351 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
355 {
356  return Thyra::tpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getThyraRangeSpace(),getThyraDomainSpace(),getTpetraMatrix());
357 }
358 
359 // Functions for initalizing a container
361 
362 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
363 void
366 {
368  initializeContainer(mem,tloc);
369 }
370 
371 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
372 void
375 {
376  typedef LinearObjContainer LOC;
377 
378  loc.clear();
379 
380  if((mem & LOC::X) == LOC::X)
381  loc.set_x(getTpetraColVector());
382 
383  if((mem & LOC::DxDt) == LOC::DxDt)
384  loc.set_dxdt(getTpetraColVector());
385 
386  if((mem & LOC::F) == LOC::F)
387  loc.set_f(getTpetraVector());
388 
389  if((mem & LOC::Mat) == LOC::Mat)
390  loc.set_A(getTpetraMatrix());
391 }
392 
393 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
394 void
397 {
399  initializeGhostedContainer(mem,tloc);
400 }
401 
402 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
403 void
406 {
407  typedef LinearObjContainer LOC;
408 
409  loc.clear();
410 
411  if((mem & LOC::X) == LOC::X)
412  loc.set_x(getGhostedTpetraColVector());
413 
414  if((mem & LOC::DxDt) == LOC::DxDt)
415  loc.set_dxdt(getGhostedTpetraColVector());
416 
417  if((mem & LOC::F) == LOC::F) {
418  loc.set_f(getGhostedTpetraVector());
420  }
421 
422  if((mem & LOC::Mat) == LOC::Mat) {
423  loc.set_A(getGhostedTpetraMatrix());
425  }
426 }
427 
428 // "Get" functions
430 
431 // get the map from the matrix
432 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
435 getMap() const
436 {
437  if(map_==Teuchos::null) map_ = buildMap();
438 
439  return map_;
440 }
441 
442 // get the map from the matrix
443 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
446 getColMap() const
447 {
448  if(cMap_==Teuchos::null) cMap_ = buildColMap();
449 
450  return cMap_;
451 }
452 
453 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
457 {
458  if(ghostedMap_==Teuchos::null) ghostedMap_ = buildGhostedMap();
459 
460  return ghostedMap_;
461 }
462 
463 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
467 {
468  if(cGhostedMap_==Teuchos::null) cGhostedMap_ = buildGhostedColMap();
469 
470  return cGhostedMap_;
471 }
472 
473 // get the graph of the crs matrix
474 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
477 getGraph() const
478 {
479  if(graph_==Teuchos::null) graph_ = buildGraph();
480 
481  return graph_;
482 }
483 
484 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
488 {
489  if(ghostedGraph_==Teuchos::null) ghostedGraph_ = buildGhostedGraph();
490 
491  return ghostedGraph_;
492 }
493 
494 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
498 {
499  if(ghostedImporter_==Teuchos::null)
500  ghostedImporter_ = Teuchos::rcp(new ImportType(getMap(),getGhostedMap()));
501 
502  return ghostedImporter_;
503 }
504 
505 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
509 {
510  if(!hasColProvider_)
511  ghostedColImporter_ = getGhostedImport(); // they are the same in this case
512 
513  if(ghostedColImporter_==Teuchos::null)
514  ghostedColImporter_ = Teuchos::rcp(new ImportType(getColMap(),getGhostedColMap()));
515 
516  return ghostedColImporter_;
517 }
518 
519 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
523 {
524  if(ghostedExporter_==Teuchos::null)
525  ghostedExporter_ = Teuchos::rcp(new ExportType(getGhostedMap(),getMap()));
526 
527  return ghostedExporter_;
528 }
529 
530 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
534 {
535  if(!hasColProvider_)
536  ghostedColExporter_ = getGhostedExport(); // they are the same in this case
537 
538  if(ghostedColExporter_==Teuchos::null)
539  ghostedColExporter_ = Teuchos::rcp(new ExportType(getGhostedColMap(),getColMap()));
540 
541  return ghostedColExporter_;
542 }
543 
544 // "Build" functions
546 
547 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
550 buildMap() const
551 {
552  std::vector<GlobalOrdinalT> indices;
553 
554  // get the global indices
555  gidProvider_->getOwnedIndices(indices);
556 
558 }
559 
560 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
563 buildColMap() const
564 {
565  if(!hasColProvider_)
566  return buildMap();
567 
568  std::vector<GlobalOrdinalT> indices;
569 
570  // get the global indices
571  colGidProvider_->getOwnedIndices(indices);
572 
574 }
575 
576 // build the ghosted map
577 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
581 {
582  std::vector<GlobalOrdinalT> indices;
583 
584  // get the global indices
585  gidProvider_->getOwnedAndGhostedIndices(indices);
586 
588 }
589 
590 // build the ghosted map
591 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
595 {
596  if(!hasColProvider_)
597  return buildGhostedMap();
598 
599  std::vector<GlobalOrdinalT> indices;
600 
601  // get the global indices
602  colGidProvider_->getOwnedAndGhostedIndices(indices);
603 
605 }
606 
607 // get the graph of the crs matrix
608 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
611 buildGraph() const
612 {
613  using Teuchos::RCP;
614  using Teuchos::rcp;
615 
616  // build the map and allocate the space for the graph and
617  // grab the ghosted graph
618  RCP<MapType> rMap = getMap();
619  RCP<MapType> cMap = getColMap();
620  RCP<CrsGraphType> graph = rcp(new CrsGraphType(rMap,0));
621  RCP<CrsGraphType> oGraph = getGhostedGraph();
622 
623  // perform the communication to finish building graph
624  RCP<ExportType> exporter = getGhostedExport();
625  graph->doExport( *oGraph, *exporter, Tpetra::INSERT );
626  graph->fillComplete(cMap,rMap);
627 
628  return graph;
629 }
630 
631 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
635 {
636  // build the map and allocate the space for the graph
637  Teuchos::RCP<MapType> rMap = getGhostedMap();
638  Teuchos::RCP<MapType> cMap = getGhostedColMap();
639 
640  std::vector<std::string> elementBlockIds;
641  gidProvider_->getElementBlockIds(elementBlockIds);
642 
644  colGidProvider = hasColProvider_ ? colGidProvider_ : gidProvider_;
645  const Teuchos::RCP<const ConnManager> conn_mgr = colGidProvider->getConnManager();
646  const bool han = conn_mgr.is_null() ? false : conn_mgr->hasAssociatedNeighbors();
647 
648  // graph information about the mesh
649  // Count number of entries per graph row; needed for graph constructor
650  std::vector<size_t> nEntriesPerRow(rMap->getLocalNumElements(), 0);
651 
652  std::vector<std::string>::const_iterator blockItr;
653  for(blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
654  std::string blockId = *blockItr;
655 
656  // grab elements for this block
657  const std::vector<LocalOrdinalT> & elements = gidProvider_->getElementBlock(blockId);
658 
659  // get information about number of indicies
660  std::vector<GlobalOrdinalT> gids;
661  std::vector<GlobalOrdinalT> col_gids;
662 
663  // loop over the elemnts
664  for(std::size_t i=0;i<elements.size();i++) {
665  gidProvider_->getElementGIDs(elements[i],gids);
666 
667  colGidProvider->getElementGIDs(elements[i],col_gids);
668  if (han) {
669  const std::vector<LocalOrdinalT>& aes = conn_mgr->getAssociatedNeighbors(elements[i]);
670  for (typename std::vector<LocalOrdinalT>::const_iterator eit = aes.begin();
671  eit != aes.end(); ++eit) {
672  std::vector<GlobalOrdinalT> other_col_gids;
673  colGidProvider->getElementGIDs(*eit, other_col_gids);
674  col_gids.insert(col_gids.end(), other_col_gids.begin(), other_col_gids.end());
675  }
676  }
677 
678  for(std::size_t j=0;j<gids.size();j++){
679  LocalOrdinalT lid = rMap->getLocalElement(gids[j]);
680  nEntriesPerRow[lid] += col_gids.size();
681  }
682  }
683  }
684 
685  Teuchos::ArrayView<const size_t> nEntriesPerRowView(nEntriesPerRow);
687  nEntriesPerRowView));
688 
689  // Now insert entries into the graph
690  for(blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
691  std::string blockId = *blockItr;
692 
693  // grab elements for this block
694  const std::vector<LocalOrdinalT> & elements = gidProvider_->getElementBlock(blockId);
695 
696  // get information about number of indicies
697  std::vector<GlobalOrdinalT> gids;
698  std::vector<GlobalOrdinalT> col_gids;
699 
700  // loop over the elemnts
701  for(std::size_t i=0;i<elements.size();i++) {
702  gidProvider_->getElementGIDs(elements[i],gids);
703 
704  colGidProvider->getElementGIDs(elements[i],col_gids);
705  if (han) {
706  const std::vector<LocalOrdinalT>& aes = conn_mgr->getAssociatedNeighbors(elements[i]);
707  for (typename std::vector<LocalOrdinalT>::const_iterator eit = aes.begin();
708  eit != aes.end(); ++eit) {
709  std::vector<GlobalOrdinalT> other_col_gids;
710  colGidProvider->getElementGIDs(*eit, other_col_gids);
711  col_gids.insert(col_gids.end(), other_col_gids.begin(), other_col_gids.end());
712  }
713  }
714 
715  for(std::size_t j=0;j<gids.size();j++)
716  graph->insertGlobalIndices(gids[j],col_gids);
717  }
718  }
719 
720  // finish filling the graph
721  graph->fillComplete(cMap,rMap);
722 
723  return graph;
724 }
725 
726 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
730 {
731  Teuchos::RCP<const MapType> tMap = getGhostedMap();
732  return Teuchos::rcp(new VectorType(tMap));
733 }
734 
735 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
739 {
740  Teuchos::RCP<const MapType> tMap = getGhostedColMap();
741  return Teuchos::rcp(new VectorType(tMap));
742 }
743 
744 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
748 {
749  Teuchos::RCP<const MapType> tMap = getMap();
750  return Teuchos::rcp(new VectorType(tMap));
751 }
752 
753 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
757 {
758  Teuchos::RCP<const MapType> tMap = getColMap();
759  return Teuchos::rcp(new VectorType(tMap));
760 }
761 
762 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
766 {
767  Teuchos::RCP<CrsGraphType> tGraph = getGraph();
769  tMat->fillComplete(tMat->getDomainMap(),tMat->getRangeMap());
770 
771  return tMat;
772 }
773 
774 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
778 {
779  Teuchos::RCP<CrsGraphType> tGraph = getGhostedGraph();
781  tMat->fillComplete(tMat->getDomainMap(),tMat->getRangeMap());
782 
783  return tMat;
784 }
785 
786 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
790 {
791  return comm_;
792 }
793 
794 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
797 {
800  if(A!=Teuchos::null)
801  A->resumeFill();
802 }
803 
804 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
807 {
810  if(A!=Teuchos::null)
811  A->fillComplete(A->getDomainMap(),A->getRangeMap());
812 }
813 
814 }
815 
816 #endif // __Panzer_TpetraLinearObjFactory_impl_hpp__
virtual const Teuchos::RCP< Tpetra::Export< LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedExport() const
get exporter for converting an overalapped object to a &quot;normal&quot; object
virtual void globalToGhostContainer(const LinearObjContainer &container, LinearObjContainer &ghostContainer, int) const
Teuchos::RCP< Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > getTpetraVector() const
virtual const Teuchos::RCP< Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedColMap() const
const Teuchos::RCP< CrsMatrixType > get_A() const
virtual Teuchos::MpiComm< int > getComm() const
bool is_null(const boost::shared_ptr< T > &p)
virtual Teuchos::RCP< LinearObjContainer > buildGhostedLinearObjContainer() const
void initializeGhostedContainer(int, LinearObjContainer &loc) const
const Teuchos::RCP< VectorType > get_x() const
virtual Teuchos::RCP< ReadOnlyVector_GlobalEvaluationData > buildReadOnlyDomainContainer() const
Teuchos::RCP< Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedTpetraVector() const
virtual const Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinalT, GlobalOrdinalT, NodeT > > buildGhostedGraph() const
bool is_null(const std::shared_ptr< T > &p)
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getThyraDomainSpace() const
Get the domain space.
Teuchos::RCP< Tpetra::CrsMatrix< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > getTpetraMatrix() const
virtual const Teuchos::RCP< Tpetra::Import< LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedImport() const
get importer for converting an overalapped object to a &quot;normal&quot; object
const Teuchos::RCP< VectorType > get_dxdt() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void initializeContainer(int, LinearObjContainer &loc) const
Teuchos::RCP< Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > getTpetraColVector() const
T_To & dyn_cast(T_From &from)
virtual void endFill(LinearObjContainer &loc) const
size_type size() const
virtual const Teuchos::RCP< Tpetra::Import< LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedColImport() const
virtual void beginFill(LinearObjContainer &loc) const
Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > MapType
virtual const Teuchos::RCP< const Teuchos::Comm< int > > getTeuchosComm() const
get exporter for converting an overalapped object to a &quot;normal&quot; object
Tpetra::Import< LocalOrdinalT, GlobalOrdinalT, NodeT > ImportType
virtual const Teuchos::RCP< Tpetra::Export< LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedColExport() const
Teuchos::RCP< Tpetra::CrsMatrix< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedTpetraMatrix() const
virtual const Teuchos::RCP< Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > getColMap() const
virtual void adjustForDirichletConditions(const LinearObjContainer &localBCRows, const LinearObjContainer &globalBCRows, LinearObjContainer &ghostedObjs, bool zeroVectorRows=false, bool adjustX=false) const
virtual const std::vector< LocalOrdinal > & getAssociatedNeighbors(const LocalOrdinal &el) const =0
void globalToGhostTpetraVector(const Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > &in, Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > &out, bool col) const
void set_x(const Teuchos::RCP< VectorType > &in)
void ghostToGlobalTpetraMatrix(const Tpetra::CrsMatrix< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > &in, Tpetra::CrsMatrix< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > &out) const
Tpetra::Export< LocalOrdinalT, GlobalOrdinalT, NodeT > ExportType
Teuchos_Ordinal Ordinal
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Tpetra::CrsMatrix< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > CrsMatrixType
virtual Teuchos::RCP< LinearObjContainer > buildLinearObjContainer() const
virtual const Teuchos::RCP< Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedMap() const
get the ghosted map from the matrix
virtual const Teuchos::RCP< Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > buildColMap() const
virtual const Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinalT, GlobalOrdinalT, NodeT > > buildGraph() const
virtual Teuchos::RCP< const ConnManager > getConnManager() const =0
Returns the connection manager currently being used.
void set_dxdt(const Teuchos::RCP< VectorType > &in)
Teuchos::RCP< Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedTpetraColVector() const
virtual const Teuchos::RCP< Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > getMap() const
get the map from the matrix
This class provides a boundary exchange communication mechanism for vectors.
virtual const Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinalT, GlobalOrdinalT, NodeT > > getGraph() const
get the graph of the crs matrix
void set_A(const Teuchos::RCP< CrsMatrixType > &in)
TpetraLinearObjFactory(const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< const GlobalIndexer > &gidProvider)
void set_f(const Teuchos::RCP< VectorType > &in)
virtual const Teuchos::RCP< Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > buildMap() const
Teuchos::RCP< const GlobalIndexer > colGidProvider_
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getThyraRangeSpace() const
Get the range space.
virtual const Teuchos::RCP< Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > buildGhostedColMap() const
virtual void ghostToGlobalContainer(const LinearObjContainer &ghostContainer, LinearObjContainer &container, int) const
virtual void getElementGIDs(panzer::LocalOrdinal localElmtId, std::vector< panzer::GlobalOrdinal > &gids, const std::string &blockIdHint="") const =0
Get the global IDs for a particular element. This function overwrites the gids variable.
virtual bool hasAssociatedNeighbors() const =0
void buildGatherScatterEvaluators(const BuilderT &builder)
virtual Teuchos::RCP< Thyra::LinearOpBase< ScalarT > > getThyraMatrix() const
Get a matrix operator.
#define TEUCHOS_ASSERT(assertion_test)
void ghostToGlobalTpetraVector(const Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > &in, Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > &out, bool col) const
const Teuchos::RCP< VectorType > get_f() const
Tpetra::CrsGraph< LocalOrdinalT, GlobalOrdinalT, NodeT > CrsGraphType
Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > VectorType
virtual const Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedGraph() const
get the ghosted graph of the crs matrix
virtual const Teuchos::RCP< Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > buildGhostedMap() const
virtual void applyDirichletBCs(const LinearObjContainer &counter, LinearObjContainer &result) const
bool is_null() const