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 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef __Panzer_TpetraLinearObjFactory_impl_hpp__
44 #define __Panzer_TpetraLinearObjFactory_impl_hpp__
45 
46 // Panzer
47 #include "Panzer_ConnManager.hpp"
48 #include "Panzer_EpetraVector_Write_GlobalEvaluationData.hpp" // JMG: Remove this eventually.
50 #include "Panzer_GlobalIndexer.hpp"
51 
52 // Thyra
53 #include "Thyra_TpetraVectorSpace.hpp"
54 #include "Thyra_TpetraLinearOp.hpp"
55 
56 // Tpetra
57 #include "Tpetra_MultiVector.hpp"
58 #include "Tpetra_Vector.hpp"
59 #include "Tpetra_CrsMatrix.hpp"
60 
61 namespace panzer {
62 
63 using Teuchos::RCP;
64 
65 // ************************************************************
66 // class TpetraLinearObjFactory
67 // ************************************************************
68 
69 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
72  const Teuchos::RCP<const GlobalIndexer> & gidProvider)
73  : comm_(comm), gidProvider_(gidProvider)
74 {
75  hasColProvider_ = colGidProvider_!=Teuchos::null;
76 
77  // build and register the gather/scatter evaluators with
78  // the base class.
79  this->buildGatherScatterEvaluators(*this);
80 }
81 
82 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
85  const Teuchos::RCP<const GlobalIndexer> & gidProvider,
86  const Teuchos::RCP<const GlobalIndexer> & colGidProvider)
87  : comm_(comm), gidProvider_(gidProvider), colGidProvider_(colGidProvider)
88 {
89  hasColProvider_ = colGidProvider_!=Teuchos::null;
90 
91  // build and register the gather/scatter evaluators with
92  // the base class.
93  this->buildGatherScatterEvaluators(*this);
94 }
95 
96 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
99 { }
100 
101 // LinearObjectFactory functions
103 
104 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
108 {
109  Teuchos::RCP<ContainerType> container = Teuchos::rcp(new ContainerType(getColMap(),getMap()));
110 
111  return container;
112 }
113 
114 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
118 {
119  Teuchos::RCP<ContainerType> container = Teuchos::rcp(new ContainerType(getGhostedMap(),getGhostedMap()));
120 
121  return container;
122 }
123 
124 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
125 void
128  LinearObjContainer & out,int mem) const
129 {
130  using Teuchos::is_null;
131  typedef LinearObjContainer LOC;
132 
133  const ContainerType & t_in = Teuchos::dyn_cast<const ContainerType>(in);
135 
136  // Operations occur if the GLOBAL container has the correct targets!
137  // Users set the GLOBAL continer arguments
138  if ( !is_null(t_in.get_x()) && !is_null(t_out.get_x()) && ((mem & LOC::X)==LOC::X))
139  globalToGhostTpetraVector(*t_in.get_x(),*t_out.get_x(),true);
140 
141  if ( !is_null(t_in.get_dxdt()) && !is_null(t_out.get_dxdt()) && ((mem & LOC::DxDt)==LOC::DxDt))
142  globalToGhostTpetraVector(*t_in.get_dxdt(),*t_out.get_dxdt(),true);
143 
144  if ( !is_null(t_in.get_f()) && !is_null(t_out.get_f()) && ((mem & LOC::F)==LOC::F))
145  globalToGhostTpetraVector(*t_in.get_f(),*t_out.get_f(),false);
146 }
147 
148 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
149 void
152  LinearObjContainer & out,int mem) const
153 {
154  using Teuchos::is_null;
155 
156  typedef LinearObjContainer LOC;
157 
158  const ContainerType & t_in = Teuchos::dyn_cast<const ContainerType>(in);
160 
161  // Operations occur if the GLOBAL container has the correct targets!
162  // Users set the GLOBAL continer arguments
163  if ( !is_null(t_in.get_x()) && !is_null(t_out.get_x()) && ((mem & LOC::X)==LOC::X))
164  ghostToGlobalTpetraVector(*t_in.get_x(),*t_out.get_x(),true);
165 
166  if ( !is_null(t_in.get_f()) && !is_null(t_out.get_f()) && ((mem & LOC::F)==LOC::F))
167  ghostToGlobalTpetraVector(*t_in.get_f(),*t_out.get_f(),false);
168 
169  if ( !is_null(t_in.get_A()) && !is_null(t_out.get_A()) && ((mem & LOC::Mat)==LOC::Mat))
170  ghostToGlobalTpetraMatrix(*t_in.get_A(),*t_out.get_A());
171 }
172 
173 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
174 void
176 ghostToGlobalTpetraVector(const Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & in,
177  Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & out, bool col) const
178 {
179  using Teuchos::RCP;
180 
181  // do the global distribution
182  RCP<ExportType> exporter = col ? getGhostedColExport() : getGhostedExport();
183  out.putScalar(0.0);
184  out.doExport(in,*exporter,Tpetra::ADD);
185 }
186 
187 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
188 void
190 ghostToGlobalTpetraMatrix(const Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & in,
191  Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & out) const
192 {
193  using Teuchos::RCP;
194 
195  // do the global distribution
196  RCP<ExportType> exporter = getGhostedExport();
197 
198  out.resumeFill();
199  out.setAllToScalar(0.0);
200  out.doExport(in,*exporter,Tpetra::ADD);
201  out.fillComplete(out.getDomainMap(),out.getRangeMap());
202 }
203 
204 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
205 void
207 globalToGhostTpetraVector(const Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & in,
208  Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & out, bool col) const
209 {
210  using Teuchos::RCP;
211 
212  // do the global distribution
213  RCP<ImportType> importer = col ? getGhostedColImport() : getGhostedImport();
214  out.putScalar(0.0);
215  out.doImport(in,*importer,Tpetra::INSERT);
216 }
217 
218 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
219 void
222  const LinearObjContainer & globalBCRows,
223  LinearObjContainer & ghostedObjs,
224  bool zeroVectorRows, bool adjustX) const
225 {
227 
228  const ContainerType & t_localBCRows = Teuchos::dyn_cast<const ContainerType>(localBCRows);
229  const ContainerType & t_globalBCRows = Teuchos::dyn_cast<const ContainerType>(globalBCRows);
230  ContainerType & t_ghosted = Teuchos::dyn_cast<ContainerType>(ghostedObjs);
231 
232  TEUCHOS_ASSERT(!Teuchos::is_null(t_localBCRows.get_f()));
233  TEUCHOS_ASSERT(!Teuchos::is_null(t_globalBCRows.get_f()));
234 
235  // pull out jacobian and vector
236  Teuchos::RCP<CrsMatrixType> A = t_ghosted.get_A();
237  Teuchos::RCP<VectorType> f = t_ghosted.get_f();
238  if(adjustX) f = t_ghosted.get_x();
239  Teuchos::ArrayRCP<double> f_array = f!=Teuchos::null ? f->get1dViewNonConst() : Teuchos::null;
240 
241  const VectorType & local_bcs = *(t_localBCRows.get_f());
242  const VectorType & global_bcs = *(t_globalBCRows.get_f());
243  Teuchos::ArrayRCP<const double> local_bcs_array = local_bcs.get1dView();
244  Teuchos::ArrayRCP<const double> global_bcs_array = global_bcs.get1dView();
245 
246  TEUCHOS_ASSERT(local_bcs_array.size()==global_bcs_array.size());
247  for(Ordinal i=0;i<local_bcs_array.size();i++) {
248  if(global_bcs_array[i]==0.0)
249  continue;
250 
251  if(local_bcs_array[i]==0.0 || zeroVectorRows) {
252  // this boundary condition was NOT set by this processor
253 
254  // if they exist put 0.0 in each entry
255  if(!Teuchos::is_null(f))
256  f_array[i] = 0.0;
257  if(!Teuchos::is_null(A)) {
258  std::size_t numEntries = 0;
259  std::size_t sz = A->getNumEntriesInLocalRow(i);
260  Teuchos::Array<LocalOrdinalT> indices(sz);
261  Teuchos::Array<double> values(sz);
262 
263  A->getLocalRowCopy(i,indices,values,numEntries);
264 
265  for(std::size_t c=0;c<numEntries;c++)
266  values[c] = 0.0;
267 
268  A->replaceLocalValues(i,indices,values);
269  }
270  }
271  else {
272  // this boundary condition was set by this processor
273 
274  double scaleFactor = global_bcs_array[i];
275 
276  // if they exist scale linear objects by scale factor
277  if(!Teuchos::is_null(f))
278  f_array[i] /= scaleFactor;
279  if(!Teuchos::is_null(A)) {
280  std::size_t numEntries = 0;
281  std::size_t sz = A->getNumEntriesInLocalRow(i);
282  Teuchos::Array<LocalOrdinalT> indices(sz);
283  Teuchos::Array<double> values(sz);
284 
285  A->getLocalRowCopy(i,indices,values,numEntries);
286 
287  for(std::size_t c=0;c<numEntries;c++)
288  values[c] /= scaleFactor;
289 
290  A->replaceLocalValues(i,indices,values);
291  }
292  }
293  }
294 }
295 
296 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
297 void
299 applyDirichletBCs(const LinearObjContainer & /* counter */,
300  LinearObjContainer & /* result */) const
301 {
302  TEUCHOS_ASSERT(false); // not yet implemented
303 }
304 
306 //
307 // buildReadOnlyDomainContainer()
308 //
310 template<typename Traits, typename ScalarT, typename LocalOrdinalT,
311  typename GlobalOrdinalT, typename NodeT>
315 {
316  using Teuchos::rcp;
317  using TVROGED = TpetraVector_ReadOnly_GlobalEvaluationData<ScalarT,
318  LocalOrdinalT, GlobalOrdinalT, NodeT>;
319  auto ged = rcp(new TVROGED);
320  ged->initialize(getGhostedImport(), getGhostedColMap(), getColMap());
321  return ged;
322 } // end of buildReadOnlyDomainContainer()
323 
325 //
326 // buildWriteDomainContainer()
327 //
329 template<typename Traits, typename ScalarT, typename LocalOrdinalT,
330  typename GlobalOrdinalT, typename NodeT>
334 {
335  using std::logic_error;
336  using Teuchos::rcp;
338  auto ged = rcp(new EVWGED);
339  TEUCHOS_TEST_FOR_EXCEPTION(true, logic_error, "NOT IMPLEMENTED YET")
340  return ged;
341 } // end of buildWriteDomainContainer()
342 
343 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
345 getComm() const
346 {
347  return *Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >(getTeuchosComm());
348 }
349 
351 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
355 {
356  if(domainSpace_==Teuchos::null) {
357  if(!hasColProvider_)
358  domainSpace_ = Thyra::tpetraVectorSpace<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getMap());
359  else
360  domainSpace_ = Thyra::tpetraVectorSpace<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getColMap());
361  }
362 
363  return domainSpace_;
364 }
365 
367 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
371 {
372  if(rangeSpace_==Teuchos::null)
373  rangeSpace_ = Thyra::tpetraVectorSpace<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getMap());
374 
375  return rangeSpace_;
376 }
377 
379 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
383 {
384  return Thyra::tpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getThyraRangeSpace(),getThyraDomainSpace(),getTpetraMatrix());
385 }
386 
387 // Functions for initalizing a container
389 
390 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
391 void
394 {
396  initializeContainer(mem,tloc);
397 }
398 
399 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
400 void
403 {
404  typedef LinearObjContainer LOC;
405 
406  loc.clear();
407 
408  if((mem & LOC::X) == LOC::X)
409  loc.set_x(getTpetraColVector());
410 
411  if((mem & LOC::DxDt) == LOC::DxDt)
412  loc.set_dxdt(getTpetraColVector());
413 
414  if((mem & LOC::F) == LOC::F)
415  loc.set_f(getTpetraVector());
416 
417  if((mem & LOC::Mat) == LOC::Mat)
418  loc.set_A(getTpetraMatrix());
419 }
420 
421 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
422 void
425 {
427  initializeGhostedContainer(mem,tloc);
428 }
429 
430 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
431 void
434 {
435  typedef LinearObjContainer LOC;
436 
437  loc.clear();
438 
439  if((mem & LOC::X) == LOC::X)
440  loc.set_x(getGhostedTpetraColVector());
441 
442  if((mem & LOC::DxDt) == LOC::DxDt)
443  loc.set_dxdt(getGhostedTpetraColVector());
444 
445  if((mem & LOC::F) == LOC::F) {
446  loc.set_f(getGhostedTpetraVector());
448  }
449 
450  if((mem & LOC::Mat) == LOC::Mat) {
451  loc.set_A(getGhostedTpetraMatrix());
453  }
454 }
455 
456 // "Get" functions
458 
459 // get the map from the matrix
460 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
463 getMap() const
464 {
465  if(map_==Teuchos::null) map_ = buildMap();
466 
467  return map_;
468 }
469 
470 // get the map from the matrix
471 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
474 getColMap() const
475 {
476  if(cMap_==Teuchos::null) cMap_ = buildColMap();
477 
478  return cMap_;
479 }
480 
481 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
485 {
486  if(ghostedMap_==Teuchos::null) ghostedMap_ = buildGhostedMap();
487 
488  return ghostedMap_;
489 }
490 
491 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
495 {
496  if(cGhostedMap_==Teuchos::null) cGhostedMap_ = buildGhostedColMap();
497 
498  return cGhostedMap_;
499 }
500 
501 // get the graph of the crs matrix
502 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
505 getGraph() const
506 {
507  if(graph_==Teuchos::null) graph_ = buildGraph();
508 
509  return graph_;
510 }
511 
512 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
516 {
517  if(ghostedGraph_==Teuchos::null) ghostedGraph_ = buildGhostedGraph();
518 
519  return ghostedGraph_;
520 }
521 
522 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
526 {
527  if(ghostedImporter_==Teuchos::null)
528  ghostedImporter_ = Teuchos::rcp(new ImportType(getMap(),getGhostedMap()));
529 
530  return ghostedImporter_;
531 }
532 
533 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
537 {
538  if(!hasColProvider_)
539  ghostedColImporter_ = getGhostedImport(); // they are the same in this case
540 
541  if(ghostedColImporter_==Teuchos::null)
542  ghostedColImporter_ = Teuchos::rcp(new ImportType(getColMap(),getGhostedColMap()));
543 
544  return ghostedColImporter_;
545 }
546 
547 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
551 {
552  if(ghostedExporter_==Teuchos::null)
553  ghostedExporter_ = Teuchos::rcp(new ExportType(getGhostedMap(),getMap()));
554 
555  return ghostedExporter_;
556 }
557 
558 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
562 {
563  if(!hasColProvider_)
564  ghostedColExporter_ = getGhostedExport(); // they are the same in this case
565 
566  if(ghostedColExporter_==Teuchos::null)
567  ghostedColExporter_ = Teuchos::rcp(new ExportType(getGhostedColMap(),getColMap()));
568 
569  return ghostedColExporter_;
570 }
571 
572 // "Build" functions
574 
575 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
578 buildMap() const
579 {
580  std::vector<GlobalOrdinalT> indices;
581 
582  // get the global indices
583  gidProvider_->getOwnedIndices(indices);
584 
586 }
587 
588 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
591 buildColMap() const
592 {
593  if(!hasColProvider_)
594  return buildMap();
595 
596  std::vector<GlobalOrdinalT> indices;
597 
598  // get the global indices
599  colGidProvider_->getOwnedIndices(indices);
600 
602 }
603 
604 // build the ghosted map
605 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
609 {
610  std::vector<GlobalOrdinalT> indices;
611 
612  // get the global indices
613  gidProvider_->getOwnedAndGhostedIndices(indices);
614 
616 }
617 
618 // build the ghosted map
619 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
623 {
624  if(!hasColProvider_)
625  return buildGhostedMap();
626 
627  std::vector<GlobalOrdinalT> indices;
628 
629  // get the global indices
630  colGidProvider_->getOwnedAndGhostedIndices(indices);
631 
633 }
634 
635 // get the graph of the crs matrix
636 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
639 buildGraph() const
640 {
641  using Teuchos::RCP;
642  using Teuchos::rcp;
643 
644  // build the map and allocate the space for the graph and
645  // grab the ghosted graph
646  RCP<MapType> rMap = getMap();
647  RCP<MapType> cMap = getColMap();
648  RCP<CrsGraphType> graph = rcp(new CrsGraphType(rMap,0));
649  RCP<CrsGraphType> oGraph = getGhostedGraph();
650 
651  // perform the communication to finish building graph
652  RCP<ExportType> exporter = getGhostedExport();
653  graph->doExport( *oGraph, *exporter, Tpetra::INSERT );
654  graph->fillComplete(cMap,rMap);
655 
656  return graph;
657 }
658 
659 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
663 {
664  // build the map and allocate the space for the graph
665  Teuchos::RCP<MapType> rMap = getGhostedMap();
666  Teuchos::RCP<MapType> cMap = getGhostedColMap();
667 
668  std::vector<std::string> elementBlockIds;
669  gidProvider_->getElementBlockIds(elementBlockIds);
670 
672  colGidProvider = hasColProvider_ ? colGidProvider_ : gidProvider_;
673  const Teuchos::RCP<const ConnManager> conn_mgr = colGidProvider->getConnManager();
674  const bool han = conn_mgr.is_null() ? false : conn_mgr->hasAssociatedNeighbors();
675 
676  // graph information about the mesh
677  // Count number of entries per graph row; needed for graph constructor
678  std::vector<size_t> nEntriesPerRow(rMap->getNodeNumElements(), 0);
679 
680  std::vector<std::string>::const_iterator blockItr;
681  for(blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
682  std::string blockId = *blockItr;
683 
684  // grab elements for this block
685  const std::vector<LocalOrdinalT> & elements = gidProvider_->getElementBlock(blockId);
686 
687  // get information about number of indicies
688  std::vector<GlobalOrdinalT> gids;
689  std::vector<GlobalOrdinalT> col_gids;
690 
691  // loop over the elemnts
692  for(std::size_t i=0;i<elements.size();i++) {
693  gidProvider_->getElementGIDs(elements[i],gids);
694 
695  colGidProvider->getElementGIDs(elements[i],col_gids);
696  if (han) {
697  const std::vector<LocalOrdinalT>& aes = conn_mgr->getAssociatedNeighbors(elements[i]);
698  for (typename std::vector<LocalOrdinalT>::const_iterator eit = aes.begin();
699  eit != aes.end(); ++eit) {
700  std::vector<GlobalOrdinalT> other_col_gids;
701  colGidProvider->getElementGIDs(*eit, other_col_gids);
702  col_gids.insert(col_gids.end(), other_col_gids.begin(), other_col_gids.end());
703  }
704  }
705 
706  for(std::size_t j=0;j<gids.size();j++){
707  LocalOrdinalT lid = rMap->getLocalElement(gids[j]);
708  nEntriesPerRow[lid] += col_gids.size();
709  }
710  }
711  }
712 
713  Teuchos::ArrayView<const size_t> nEntriesPerRowView(nEntriesPerRow);
715  nEntriesPerRowView,
716  Tpetra::StaticProfile));
717 
718  // Now insert entries into the graph
719  for(blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
720  std::string blockId = *blockItr;
721 
722  // grab elements for this block
723  const std::vector<LocalOrdinalT> & elements = gidProvider_->getElementBlock(blockId);
724 
725  // get information about number of indicies
726  std::vector<GlobalOrdinalT> gids;
727  std::vector<GlobalOrdinalT> col_gids;
728 
729  // loop over the elemnts
730  for(std::size_t i=0;i<elements.size();i++) {
731  gidProvider_->getElementGIDs(elements[i],gids);
732 
733  colGidProvider->getElementGIDs(elements[i],col_gids);
734  if (han) {
735  const std::vector<LocalOrdinalT>& aes = conn_mgr->getAssociatedNeighbors(elements[i]);
736  for (typename std::vector<LocalOrdinalT>::const_iterator eit = aes.begin();
737  eit != aes.end(); ++eit) {
738  std::vector<GlobalOrdinalT> other_col_gids;
739  colGidProvider->getElementGIDs(*eit, other_col_gids);
740  col_gids.insert(col_gids.end(), other_col_gids.begin(), other_col_gids.end());
741  }
742  }
743 
744  for(std::size_t j=0;j<gids.size();j++)
745  graph->insertGlobalIndices(gids[j],col_gids);
746  }
747  }
748 
749  // finish filling the graph
750  graph->fillComplete(cMap,rMap);
751 
752  return graph;
753 }
754 
755 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
759 {
760  Teuchos::RCP<const MapType> tMap = getGhostedMap();
761  return Teuchos::rcp(new VectorType(tMap));
762 }
763 
764 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
768 {
769  Teuchos::RCP<const MapType> tMap = getGhostedColMap();
770  return Teuchos::rcp(new VectorType(tMap));
771 }
772 
773 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
777 {
778  Teuchos::RCP<const MapType> tMap = getMap();
779  return Teuchos::rcp(new VectorType(tMap));
780 }
781 
782 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
786 {
787  Teuchos::RCP<const MapType> tMap = getColMap();
788  return Teuchos::rcp(new VectorType(tMap));
789 }
790 
791 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
795 {
796  Teuchos::RCP<CrsGraphType> tGraph = getGraph();
798  tMat->fillComplete(tMat->getDomainMap(),tMat->getRangeMap());
799 
800  return tMat;
801 }
802 
803 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
807 {
808  Teuchos::RCP<CrsGraphType> tGraph = getGhostedGraph();
810  tMat->fillComplete(tMat->getDomainMap(),tMat->getRangeMap());
811 
812  return tMat;
813 }
814 
815 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
819 {
820  return comm_;
821 }
822 
823 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
826 {
829  if(A!=Teuchos::null)
830  A->resumeFill();
831 }
832 
833 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT>
836 {
839  if(A!=Teuchos::null)
840  A->fillComplete(A->getDomainMap(),A->getRangeMap());
841 }
842 
843 }
844 
845 #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 Teuchos::RCP< WriteVector_GlobalEvaluationData > buildWriteDomainContainer() const
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