43 #ifndef __Panzer_TpetraLinearObjFactory_impl_hpp__
44 #define __Panzer_TpetraLinearObjFactory_impl_hpp__
53 #include "Thyra_TpetraVectorSpace.hpp"
54 #include "Thyra_TpetraLinearOp.hpp"
57 #include "Tpetra_MultiVector.hpp"
58 #include "Tpetra_Vector.hpp"
59 #include "Tpetra_CrsMatrix.hpp"
69 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
73 : comm_(comm), gidProvider_(gidProvider)
82 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
87 : comm_(comm), gidProvider_(gidProvider), colGidProvider_(colGidProvider)
96 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
104 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
114 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
124 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
139 globalToGhostTpetraVector(*t_in.
get_x(),*t_out.get_x(),
true);
142 globalToGhostTpetraVector(*t_in.
get_dxdt(),*t_out.get_dxdt(),
true);
145 globalToGhostTpetraVector(*t_in.
get_f(),*t_out.get_f(),
false);
148 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
164 ghostToGlobalTpetraVector(*t_in.
get_x(),*t_out.get_x(),
true);
167 ghostToGlobalTpetraVector(*t_in.
get_f(),*t_out.get_f(),
false);
170 ghostToGlobalTpetraMatrix(*t_in.
get_A(),*t_out.get_A());
173 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
177 Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & out,
bool col)
const
182 RCP<ExportType> exporter = col ? getGhostedColExport() : getGhostedExport();
184 out.doExport(in,*exporter,Tpetra::ADD);
187 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
191 Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & out)
const
199 out.setAllToScalar(0.0);
200 out.doExport(in,*exporter,Tpetra::ADD);
201 out.fillComplete(out.getDomainMap(),out.getRangeMap());
204 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
208 Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> & out,
bool col)
const
213 RCP<ImportType> importer = col ? getGhostedColImport() : getGhostedImport();
215 out.doImport(in,*importer,Tpetra::INSERT);
218 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
224 bool zeroVectorRows,
bool adjustX)
const
238 if(adjustX) f = t_ghosted.get_x();
242 const VectorType & global_bcs = *(t_globalBCRows.get_f());
247 for(Ordinal i=0;i<local_bcs_array.
size();i++) {
248 if(global_bcs_array[i]==0.0)
251 if(local_bcs_array[i]==0.0 || zeroVectorRows) {
258 std::size_t numEntries = 0;
259 std::size_t sz = A->getNumEntriesInLocalRow(i);
263 A->getLocalRowCopy(i,indices,values,numEntries);
265 for(std::size_t c=0;c<numEntries;c++)
268 A->replaceLocalValues(i,indices,values);
274 double scaleFactor = global_bcs_array[i];
278 f_array[i] /= scaleFactor;
280 std::size_t numEntries = 0;
281 std::size_t sz = A->getNumEntriesInLocalRow(i);
285 A->getLocalRowCopy(i,indices,values,numEntries);
287 for(std::size_t c=0;c<numEntries;c++)
288 values[c] /= scaleFactor;
290 A->replaceLocalValues(i,indices,values);
296 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
310 template<
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
311 typename GlobalOrdinalT,
typename NodeT>
318 LocalOrdinalT, GlobalOrdinalT, NodeT>;
319 auto ged =
rcp(
new TVROGED);
320 ged->initialize(getGhostedImport(), getGhostedColMap(), getColMap());
329 template<
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
330 typename GlobalOrdinalT,
typename NodeT>
335 using std::logic_error;
338 auto ged =
rcp(
new EVWGED);
343 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
351 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
356 if(domainSpace_==Teuchos::null) {
358 domainSpace_ = Thyra::tpetraVectorSpace<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getMap());
360 domainSpace_ = Thyra::tpetraVectorSpace<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getColMap());
367 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
372 if(rangeSpace_==Teuchos::null)
373 rangeSpace_ = Thyra::tpetraVectorSpace<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getMap());
379 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
384 return Thyra::tpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(getThyraRangeSpace(),getThyraDomainSpace(),getTpetraMatrix());
390 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
396 initializeContainer(mem,tloc);
399 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
408 if((mem & LOC::X) == LOC::X)
409 loc.
set_x(getTpetraColVector());
411 if((mem & LOC::DxDt) == LOC::DxDt)
414 if((mem & LOC::F) == LOC::F)
415 loc.
set_f(getTpetraVector());
417 if((mem & LOC::Mat) == LOC::Mat)
418 loc.
set_A(getTpetraMatrix());
421 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
427 initializeGhostedContainer(mem,tloc);
430 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
439 if((mem & LOC::X) == LOC::X)
440 loc.
set_x(getGhostedTpetraColVector());
442 if((mem & LOC::DxDt) == LOC::DxDt)
443 loc.
set_dxdt(getGhostedTpetraColVector());
445 if((mem & LOC::F) == LOC::F) {
446 loc.
set_f(getGhostedTpetraVector());
450 if((mem & LOC::Mat) == LOC::Mat) {
451 loc.
set_A(getGhostedTpetraMatrix());
460 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
465 if(map_==Teuchos::null) map_ = buildMap();
471 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
476 if(cMap_==Teuchos::null) cMap_ = buildColMap();
481 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
486 if(ghostedMap_==Teuchos::null) ghostedMap_ = buildGhostedMap();
491 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
496 if(cGhostedMap_==Teuchos::null) cGhostedMap_ = buildGhostedColMap();
502 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
507 if(graph_==Teuchos::null) graph_ = buildGraph();
512 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
517 if(ghostedGraph_==Teuchos::null) ghostedGraph_ = buildGhostedGraph();
519 return ghostedGraph_;
522 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
527 if(ghostedImporter_==Teuchos::null)
530 return ghostedImporter_;
533 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
539 ghostedColImporter_ = getGhostedImport();
541 if(ghostedColImporter_==Teuchos::null)
544 return ghostedColImporter_;
547 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
552 if(ghostedExporter_==Teuchos::null)
555 return ghostedExporter_;
558 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
564 ghostedColExporter_ = getGhostedExport();
566 if(ghostedColExporter_==Teuchos::null)
569 return ghostedColExporter_;
575 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
580 std::vector<GlobalOrdinalT> indices;
583 gidProvider_->getOwnedIndices(indices);
588 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
596 std::vector<GlobalOrdinalT> indices;
599 colGidProvider_->getOwnedIndices(indices);
605 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
610 std::vector<GlobalOrdinalT> indices;
613 gidProvider_->getOwnedAndGhostedIndices(indices);
619 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
625 return buildGhostedMap();
627 std::vector<GlobalOrdinalT> indices;
630 colGidProvider_->getOwnedAndGhostedIndices(indices);
636 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
653 graph->doExport( *oGraph, *exporter, Tpetra::INSERT );
654 graph->fillComplete(cMap,rMap);
659 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
669 std::vector<std::string> elementBlockIds;
670 gidProvider_->getElementBlockIds(elementBlockIds);
673 colGidProvider = hasColProvider_ ? colGidProvider_ : gidProvider_;
675 const bool han = conn_mgr.
is_null() ?
false : conn_mgr->hasAssociatedNeighbors();
678 std::vector<std::string>::const_iterator blockItr;
679 for(blockItr=elementBlockIds.begin();blockItr!=elementBlockIds.end();++blockItr) {
680 std::string blockId = *blockItr;
683 const std::vector<LocalOrdinalT> & elements = gidProvider_->getElementBlock(blockId);
686 std::vector<GlobalOrdinalT> gids;
687 std::vector<GlobalOrdinalT> col_gids;
690 for(std::size_t i=0;i<elements.size();i++) {
691 gidProvider_->getElementGIDs(elements[i],gids);
693 colGidProvider->getElementGIDs(elements[i],col_gids);
695 const std::vector<LocalOrdinalT>& aes = conn_mgr->getAssociatedNeighbors(elements[i]);
696 for (
typename std::vector<LocalOrdinalT>::const_iterator eit = aes.begin();
697 eit != aes.end(); ++eit) {
698 std::vector<GlobalOrdinalT> other_col_gids;
699 colGidProvider->getElementGIDs(*eit, other_col_gids);
700 col_gids.insert(col_gids.end(), other_col_gids.begin(), other_col_gids.end());
704 for(std::size_t j=0;j<gids.size();j++)
705 graph->insertGlobalIndices(gids[j],col_gids);
710 graph->fillComplete(cMap,rMap);
715 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
724 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
733 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
742 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
751 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
758 tMat->fillComplete(tMat->getDomainMap(),tMat->getRangeMap());
763 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
770 tMat->fillComplete(tMat->getDomainMap(),tMat->getRangeMap());
775 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
783 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
793 template <
typename Traits,
typename ScalarT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename NodeT>
800 A->fillComplete(A->getDomainMap(),A->getRangeMap());
805 #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 "normal" 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
void clear()
Wipe out stored data.
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 "normal" 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
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 "normal" 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
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_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
void setRequiresDirichletAdjustment(bool b)
TpetraLinearObjFactory(const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > &gidProvider)
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
Teuchos::RCP< const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > colGidProvider_
virtual const Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinalT, GlobalOrdinalT, NodeT > > buildGraph() const
void set_dxdt(const Teuchos::RCP< VectorType > &in)
Teuchos::RCP< Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > getGhostedTpetraColVector() const
virtual ~TpetraLinearObjFactory()
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)
void set_f(const Teuchos::RCP< VectorType > &in)
virtual const Teuchos::RCP< Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > buildMap() const
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
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