// @HEADER // ***************************************************************************** // Panzer: A partial differential equation assembly // engine for strongly coupled complex multiphysics systems // // Copyright 2011 NTESS and the Panzer contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #ifndef __Panzer_TpetraLinearObjFactory_decl_hpp__ #define __Panzer_TpetraLinearObjFactory_decl_hpp__ #include // Tpetra includes #include "Tpetra_Map.hpp" #include "Tpetra_CrsGraph.hpp" #include "Tpetra_CrsMatrix.hpp" #include "Tpetra_Import.hpp" #include "Tpetra_Export.hpp" #include "PanzerDiscFE_config.hpp" #include "Panzer_GlobalIndexer.hpp" #include "Panzer_LinearObjFactory.hpp" #include "Panzer_TpetraLinearObjContainer.hpp" #include "Panzer_ScatterResidual_Tpetra.hpp" #include "Panzer_ScatterDirichletResidual_Tpetra.hpp" #include "Panzer_GatherSolution_Tpetra.hpp" #include "Panzer_GatherTangent_Tpetra.hpp" #include "Panzer_GatherOrientation.hpp" #include "Panzer_CloneableEvaluator.hpp" #include "Panzer_ThyraObjFactory.hpp" #include"Panzer_NodeType.hpp" #include "Teuchos_RCP.hpp" #include "Teuchos_DefaultMpiComm.hpp" namespace panzer { template class TpetraLinearObjFactory : public LinearObjFactory , public ThyraObjFactory { public: typedef TpetraLinearObjContainer ContainerType; typedef Tpetra::Vector VectorType; typedef Tpetra::CrsMatrix CrsMatrixType; typedef Tpetra::CrsGraph CrsGraphType; typedef Tpetra::Map MapType; typedef Tpetra::Import ImportType; typedef Tpetra::Export ExportType; TpetraLinearObjFactory(const Teuchos::RCP > & comm, const Teuchos::RCP & gidProvider); TpetraLinearObjFactory(const Teuchos::RCP > & comm, const Teuchos::RCP & rowProvider, const Teuchos::RCP & colProvider); virtual ~TpetraLinearObjFactory(); /*************** Linear object factory methods *******************/ virtual void readVector(const std::string & /* identifier */, LinearObjContainer & /* loc */, int /* id */) const { TEUCHOS_ASSERT(false); } virtual void writeVector(const std::string & /* identifier */, const LinearObjContainer & /* loc */, int /* id */) const { TEUCHOS_ASSERT(false); } virtual Teuchos::RCP buildLinearObjContainer() const; virtual Teuchos::RCP buildPrimitiveLinearObjContainer() const { return buildLinearObjContainer(); } virtual Teuchos::RCP buildGhostedLinearObjContainer() const; virtual Teuchos::RCP buildPrimitiveGhostedLinearObjContainer() const { return buildGhostedLinearObjContainer(); } virtual void globalToGhostContainer(const LinearObjContainer & container, LinearObjContainer & ghostContainer,int) const; virtual void ghostToGlobalContainer(const LinearObjContainer & ghostContainer, LinearObjContainer & container,int) const; /** Adjust the residual vector and Jacobian matrix (if they exist) for applied * dirichlet conditions. The adjustment considers if a boundary condition was * set globally and locally and based on that result adjust the ghosted matrix * and residual vector so that when they are summed across processors they resulting * Dirichlet condition is correct. */ virtual void adjustForDirichletConditions(const LinearObjContainer & localBCRows, const LinearObjContainer & globalBCRows, LinearObjContainer & ghostedObjs, bool zeroVectorRows=false, bool adjustX=false) const; /** Adjust a vector by replacing selected rows with the value of the evaluated * dirichlet conditions. This is handled through the standard container mechanism. */ virtual void applyDirichletBCs(const LinearObjContainer & counter, LinearObjContainer & result) const; /** Build a GlobalEvaluationDataContainer that handles all domain communication. * This is used primarily for gather operations and hides the allocation and usage * of the ghosted vector from the user. */ virtual Teuchos::RCP buildReadOnlyDomainContainer() const; #ifdef PANZER_HAVE_EPETRA_STACK /** Build a GlobalEvaluationDataContainer that handles all domain communication. * This is used primarily for gather operations and hides the allocation and usage * of the ghosted vector from the user. */ virtual Teuchos::RCP buildWriteDomainContainer() const; #endif /** Acess to the MPI Comm used in constructing this LOF. */ virtual Teuchos::MpiComm getComm() const; //! Use preconstructed scatter evaluators template Teuchos::RCP buildScatter() const { return Teuchos::rcp(new ScatterResidual_Tpetra(gidProvider_)); } //! Use preconstructed gather evaluators template Teuchos::RCP buildGather() const { return Teuchos::rcp(new GatherSolution_Tpetra(gidProvider_)); } //! Use preconstructed gather evaluators template Teuchos::RCP buildGatherTangent() const { return Teuchos::rcp(new GatherTangent_Tpetra(gidProvider_)); } //! Use preconstructed gather evaluators template Teuchos::RCP buildGatherDomain() const { return Teuchos::rcp(new GatherSolution_Tpetra(gidProvider_)); } //! Use preconstructed gather evaluators template Teuchos::RCP buildGatherOrientation() const { return Teuchos::rcp(new GatherOrientation(gidProvider_)); } //! Use preconstructed dirichlet scatter evaluators template Teuchos::RCP buildScatterDirichlet() const { return Teuchos::rcp(new ScatterDirichletResidual_Tpetra(gidProvider_)); } /*************** From ThyraObjFactory *******************/ //! Get the domain space virtual Teuchos::RCP > getThyraDomainSpace() const; //! Get the range space virtual Teuchos::RCP > getThyraRangeSpace() const; //! Get a matrix operator virtual Teuchos::RCP > getThyraMatrix() const; /*************** Tpetra construction functions *******************/ Teuchos::RCP > getGhostedTpetraVector() const; Teuchos::RCP > getGhostedTpetraColVector() const; Teuchos::RCP > getTpetraVector() const; Teuchos::RCP > getTpetraColVector() const; Teuchos::RCP > getTpetraMatrix() const; Teuchos::RCP > getGhostedTpetraMatrix() const; /*************** Generic helper functions for container setup *******************/ /** Initialize container with a specific set of member values. * * \note This will overwrite everything in the container and zero out values * not requested. */ void initializeContainer(int,LinearObjContainer & loc) const; /** Initialize container with a specific set of member values. * * \note This will overwrite everything in the container and zero out values * not requested. */ void initializeContainer(int mem,TpetraLinearObjContainer & loc) const; /** Initialize container with a specific set of member values. * * \note This will overwrite everything in the container and zero out values * not requested. */ void initializeGhostedContainer(int,LinearObjContainer & loc) const; /** Initialize container with a specific set of member values. * * \note This will overwrite everything in the container and zero out values * not requested. */ void initializeGhostedContainer(int mem,TpetraLinearObjContainer & loc) const; /*************** Tpetra based methods *******************/ //! get the map from the matrix virtual const Teuchos::RCP > getMap() const; virtual const Teuchos::RCP > getColMap() const; //! get the ghosted map from the matrix virtual const Teuchos::RCP > getGhostedMap() const; virtual const Teuchos::RCP > getGhostedColMap() const; //! get the graph of the crs matrix virtual const Teuchos::RCP > getGraph() const; //! get the ghosted graph of the crs matrix virtual const Teuchos::RCP > getGhostedGraph() const; //! get importer for converting an overalapped object to a "normal" object virtual const Teuchos::RCP > getGhostedImport() const; virtual const Teuchos::RCP > getGhostedColImport() const; //! get exporter for converting an overalapped object to a "normal" object virtual const Teuchos::RCP > getGhostedExport() const; virtual const Teuchos::RCP > getGhostedColExport() const; //! get exporter for converting an overalapped object to a "normal" object virtual const Teuchos::RCP > getTeuchosComm() const; //! Get the domain global indexer this factory was created with. Teuchos::RCP getDomainGlobalIndexer() const { return gidProvider_; } //! Get the domain global indexer this factory was created with. Teuchos::RCP getRangeGlobalIndexer() const { return gidProvider_; } virtual void beginFill(LinearObjContainer & loc) const; virtual void endFill(LinearObjContainer & loc) const; protected: void ghostToGlobalTpetraVector(const Tpetra::Vector & in, Tpetra::Vector & out, bool col) const; void ghostToGlobalTpetraMatrix(const Tpetra::CrsMatrix & in, Tpetra::CrsMatrix & out) const; void globalToGhostTpetraVector(const Tpetra::Vector& in, Tpetra::Vector & out, bool col) const; // get the map from the matrix virtual const Teuchos::RCP > buildMap() const; virtual const Teuchos::RCP > buildColMap() const; virtual const Teuchos::RCP > buildGhostedMap() const; virtual const Teuchos::RCP > buildGhostedColMap() const; // get the graph of the crs matrix virtual const Teuchos::RCP > buildGraph() const; virtual const Teuchos::RCP > buildGhostedGraph() const; // storage for Tpetra graphs and maps Teuchos::RCP > comm_; mutable Teuchos::RCP > map_; mutable Teuchos::RCP > cMap_; mutable Teuchos::RCP > ghostedMap_; mutable Teuchos::RCP > cGhostedMap_; mutable Teuchos::RCP > graph_; mutable Teuchos::RCP > ghostedGraph_; mutable Teuchos::RCP ghostedImporter_; mutable Teuchos::RCP ghostedColImporter_; mutable Teuchos::RCP ghostedExporter_; mutable Teuchos::RCP ghostedColExporter_; Teuchos::RCP gidProvider_; Teuchos::RCP colGidProvider_; bool hasColProvider_; mutable Teuchos::RCP > rangeSpace_; mutable Teuchos::RCP > domainSpace_; }; } #endif