Panzer  Version of the Day
Panzer_BlockedTpetraLinearObjFactory.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_BlockedTpetraLinearObjFactory_hpp__
44 #define __Panzer_BlockedTpetraLinearObjFactory_hpp__
45 
46 #include <map>
47 
48 // Tpetra includes
49 #include "Tpetra_Map.hpp"
50 #include "Tpetra_CrsGraph.hpp"
51 #include "Tpetra_Import.hpp"
52 #include "Tpetra_Export.hpp"
53 
54 #include "PanzerDiscFE_config.hpp"
62 #include "Panzer_HashUtils.hpp" // for pair_hash
63 
64 #include "Panzer_GatherOrientation.hpp"
70 
71 #include "Thyra_BlockedLinearOpBase.hpp"
72 #include "Thyra_ProductVectorBase.hpp"
73 
74 #include "Teuchos_RCP.hpp"
76 #include "Teuchos_OpaqueWrapper.hpp"
77 
78 namespace panzer {
79 
80 template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT=panzer::TpetraNodeType>
82  , public ThyraObjFactory<double> {
83 public:
85  typedef Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> VectorType;
86  typedef Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> CrsMatrixType;
87  typedef Tpetra::Operator<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> OperatorType;
88  typedef Tpetra::CrsGraph<LocalOrdinalT,GlobalOrdinalT,NodeT> CrsGraphType;
89  typedef Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> MapType;
90  typedef Tpetra::Import<LocalOrdinalT,GlobalOrdinalT,NodeT> ImportType;
91  typedef Tpetra::Export<LocalOrdinalT,GlobalOrdinalT,NodeT> ExportType;
92 
93  typedef Thyra::TpetraVector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> ThyraVector;
94  typedef Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> ThyraLinearOp;
95 
96 
97  BlockedTpetraLinearObjFactory(const Teuchos::RCP<const Teuchos::MpiComm<int> > & comm,
99 
101 
102 /*************** Linear object factory methods *******************/
103 
104  virtual void readVector(const std::string & identifier,LinearObjContainer & loc,int id) const
105  { TEUCHOS_ASSERT(false); }
106 
107  virtual void writeVector(const std::string & identifier,const LinearObjContainer & loc,int id) const
108  { TEUCHOS_ASSERT(false); }
109 
111 
113  { return buildLinearObjContainer(); }
114 
116 
118  { return buildGhostedLinearObjContainer(); }
119 
120  virtual void globalToGhostContainer(const LinearObjContainer & container,
121  LinearObjContainer & ghostContainer,int) const;
122  virtual void ghostToGlobalContainer(const LinearObjContainer & ghostContainer,
123  LinearObjContainer & container,int) const;
124 
131  virtual void adjustForDirichletConditions(const LinearObjContainer & localBCRows,
132  const LinearObjContainer & globalBCRows,
133  LinearObjContainer & ghostedObjs,
134  bool zeroVectorRows=false, bool adjustX = false) const;
135 
139  virtual void applyDirichletBCs(const LinearObjContainer & counter,
140  LinearObjContainer & result) const;
141 
147 
148  Teuchos::MpiComm<int> getComm() const;
149 
151  template <typename EvalT>
154 
156  template <typename EvalT>
159 
161  template <typename EvalT>
164 
166  template <typename EvalT>
169 
171  template <typename EvalT>
174 
176  template <typename EvalT>
179 
180 /*************** Generic helper functions for container setup *******************/
181 
187  void initializeContainer(int,LinearObjContainer & loc) const;
188 
194  void initializeContainer(int mem,BTLOC & loc) const;
195 
201  void initializeGhostedContainer(int,LinearObjContainer & loc) const;
202 
208  void initializeGhostedContainer(int mem,BTLOC & loc) const;
209 
210 /*************** Thyra based methods *******************/
211 
214 
217 
220 
223 
226 
227  // and now the ghosted versions
228 
231 
234 
237 
240 
243 
244 /*************** Tpetra based methods *******************/
245 
247  virtual Teuchos::RCP<const MapType> getMap(int i) const;
248 
250  virtual Teuchos::RCP<const MapType> getGhostedMap(int i) const;
251 
253  virtual Teuchos::RCP<const CrsGraphType> getGraph(int i,int j) const;
254 
256  virtual Teuchos::RCP<const CrsGraphType> getGhostedGraph(int i,int j) const;
257 
260 
263 
264  Teuchos::RCP<CrsMatrixType> getTpetraMatrix(int i,int j) const;
266 
268  int getBlockRowCount() const;
269 
271  int getBlockColCount() const;
272 
274  void addExcludedPair(int rowBlock,int colBlock);
275 
277  void addExcludedPairs(const std::vector<std::pair<int,int> > & exPairs);
278 
279  virtual void beginFill(LinearObjContainer & loc) const;
280  virtual void endFill(LinearObjContainer & loc) const;
281 
283  { return blockedDOFManager_; }
284 
287  { return blockProvider_; }
288 
291  { return blockProvider_; }
292 
293 protected:
294 /*************** Generic methods/members *******************/
295 
296  // Get the global indexer associated with a particular block
298 
300  void makeRoomForBlocks(std::size_t blockCnt);
301 
304  std::vector<Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > > gidProviders_;
305 
306  // which block entries are ignored
307  std::unordered_set<std::pair<int,int>,panzer::pair_hash> excludedPairs_;
308 
309 /*************** Thyra based methods/members *******************/
310 
312  const Teuchos::RCP<Thyra::VectorBase<ScalarT> > & out) const;
315  const Teuchos::RCP<Thyra::VectorBase<ScalarT> > & out) const;
316 
319 
322 
323 /*************** Tpetra based methods/members *******************/
324 
325  void adjustForDirichletConditions(const VectorType & local_bcs,
326  const VectorType & global_bcs,
327  const Teuchos::Ptr<VectorType> & f,
328  const Teuchos::Ptr<CrsMatrixType> & A,
329  bool zeroVectorRows) const;
330 
331  void ghostToGlobalTpetraVector(int i,const VectorType & in,VectorType & out) const;
332  void ghostToGlobalTpetraMatrix(int blockRow,const CrsMatrixType & in,CrsMatrixType & out) const;
333  void globalToGhostTpetraVector(int i,const VectorType & in,VectorType & out) const;
334 
335  // get the map from the matrix
336  virtual Teuchos::RCP<const MapType> buildTpetraMap(int i) const;
338 
339  // get the graph of the crs matrix
340  virtual Teuchos::RCP<const CrsGraphType> buildTpetraGraph(int i,int j) const;
342 
343  // storage for Tpetra graphs and maps
345  mutable std::vector<Teuchos::RCP<const MapType> > maps_;
346  mutable std::vector<Teuchos::RCP<const MapType> > ghostedMaps_;
347  mutable std::unordered_map<std::pair<int,int>,Teuchos::RCP<const CrsGraphType>,panzer::pair_hash> graphs_ ;
348  mutable std::unordered_map<std::pair<int,int>,Teuchos::RCP<const CrsGraphType>,panzer::pair_hash> ghostedGraphs_;
349 
350  mutable std::vector<Teuchos::RCP<const ImportType> > importers_;
351  mutable std::vector<Teuchos::RCP<const ExportType> > exporters_;
352 };
353 
354 }
355 
356 #endif
BlockedTpetraLinearObjContainer< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > BTLOC
std::vector< Teuchos::RCP< const ImportType > > importers_
virtual void applyDirichletBCs(const LinearObjContainer &counter, LinearObjContainer &result) const
Thyra::TpetraVector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > ThyraVector
void ghostToGlobalTpetraMatrix(int blockRow, const CrsMatrixType &in, CrsMatrixType &out) const
Pushes residual values into the residual vector for a Newton-based solve.
Teuchos::RCP< const panzer::BlockedDOFManager< int, GlobalOrdinalT > > getGlobalIndexer() const
virtual Teuchos::RCP< const MapType > buildTpetraMap(int i) const
Thyra::TpetraLinearOp< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > ThyraLinearOp
virtual Teuchos::RCP< const ExportType > getGhostedExport(int j) const
get exporter for converting an overalapped object to a "normal" object
Teuchos::RCP< const BlockedDOFManager< LocalOrdinalT, GlobalOrdinalT > > blockedDOFManager_
std::vector< Teuchos::RCP< const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > gidProviders_
virtual Teuchos::RCP< const MapType > buildTpetraGhostedMap(int i) const
virtual Teuchos::RCP< const ImportType > getGhostedImport(int i) const
get importer for converting an overalapped object to a "normal" object
std::vector< Teuchos::RCP< const ExportType > > exporters_
Tpetra::Import< LocalOrdinalT, GlobalOrdinalT, NodeT > ImportType
Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > getRangeGlobalIndexer() const
Get the range unique global indexer this factory was created with.
virtual Teuchos::RCP< const CrsGraphType > buildTpetraGraph(int i, int j) const
virtual Teuchos::RCP< LinearObjContainer > buildLinearObjContainer() const
Teuchos::RCP< Thyra::LinearOpBase< ScalarT > > getThyraMatrix() const
Get a Thyra operator.
virtual void adjustForDirichletConditions(const LinearObjContainer &localBCRows, const LinearObjContainer &globalBCRows, LinearObjContainer &ghostedObjs, bool zeroVectorRows=false, bool adjustX=false) const
std::vector< Teuchos::RCP< const MapType > > maps_
virtual void globalToGhostContainer(const LinearObjContainer &container, LinearObjContainer &ghostContainer, int) const
PHX::MDField< ScalarT > vector
virtual Teuchos::RCP< LinearObjContainer > buildGhostedLinearObjContainer() const
Teuchos::RCP< const Teuchos::MpiComm< int > > comm_
Teuchos::RCP< Thyra::BlockedLinearOpBase< ScalarT > > getGhostedThyraMatrix() const
Get a Thyra operator.
void initializeGhostedContainer(int, LinearObjContainer &loc) const
Teuchos::RCP< panzer::CloneableEvaluator > buildScatter() const
Use preconstructed scatter evaluators.
Tpetra::CrsGraph< LocalOrdinalT, GlobalOrdinalT, NodeT > CrsGraphType
virtual Teuchos::RCP< const MapType > getMap(int i) const
get the map from the matrix
Gathers solution values from the Newton solution vector into the nodal fields of the field manager...
virtual Teuchos::RCP< const CrsGraphType > getGraph(int i, int j) const
get the graph of the crs matrix
Teuchos::RCP< Thyra::ProductVectorSpaceBase< ScalarT > > rangeSpace_
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveGhostedLinearObjContainer() const
std::unordered_map< std::pair< int, int >, Teuchos::RCP< const CrsGraphType >, panzer::pair_hash > ghostedGraphs_
void globalToGhostThyraVector(const Teuchos::RCP< const Thyra::VectorBase< ScalarT > > &in, const Teuchos::RCP< Thyra::VectorBase< ScalarT > > &out) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< Thyra::ProductVectorSpaceBase< ScalarT > > ghostedDomainSpace_
Tpetra::Export< LocalOrdinalT, GlobalOrdinalT, NodeT > ExportType
Teuchos::RCP< Thyra::VectorBase< ScalarT > > getGhostedThyraRangeVector() const
Get a range vector.
std::vector< Teuchos::RCP< const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > nc2c_vector(const std::vector< Teuchos::RCP< UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > &ugis)
void ghostToGlobalTpetraVector(int i, const VectorType &in, VectorType &out) const
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getGhostedThyraDomainSpace() const
Get the domain vector space (x and dxdt)
virtual void readVector(const std::string &identifier, LinearObjContainer &loc, int id) const
std::unordered_map< std::pair< int, int >, Teuchos::RCP< const CrsGraphType >, panzer::pair_hash > graphs_
Teuchos::RCP< Thyra::VectorBase< ScalarT > > getThyraRangeVector() const
Get a range vector.
virtual Teuchos::RCP< const CrsGraphType > getGhostedGraph(int i, int j) const
get the ghosted graph of the crs matrix
std::unordered_set< std::pair< int, int >, panzer::pair_hash > excludedPairs_
void makeRoomForBlocks(std::size_t blockCnt)
Allocate the space in the std::vector objects so we can fill with appropriate Tpetra data...
Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > VectorType
Teuchos::RCP< Thyra::VectorBase< ScalarT > > getThyraDomainVector() const
Get a domain vector.
Tpetra::CrsMatrix< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > CrsMatrixType
Tpetra::Operator< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > OperatorType
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveLinearObjContainer() const
virtual Teuchos::RCP< ReadOnlyVector_GlobalEvaluationData > buildDomainContainer() const
Teuchos::RCP< Thyra::VectorBase< ScalarT > > getGhostedThyraDomainVector() const
Get a domain vector.
Teuchos::RCP< const UniqueGlobalIndexer< LocalOrdinalT, std::pair< int, GlobalOrdinalT > > > blockProvider_
Teuchos::RCP< Thyra::ProductVectorSpaceBase< ScalarT > > domainSpace_
void addExcludedPairs(const std::vector< std::pair< int, int > > &exPairs)
exclude a vector of pairs from the matrix
virtual void ghostToGlobalContainer(const LinearObjContainer &ghostContainer, LinearObjContainer &container, int) const
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getThyraRangeSpace() const
Get the range vector space (f)
void addExcludedPair(int rowBlock, int colBlock)
exclude a block pair from the matrix
virtual Teuchos::RCP< const MapType > getGhostedMap(int i) const
get the ghosted map from the matrix
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherTangent() const
Use preconstructed gather evaluators.
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherOrientation() const
Use preconstructed gather evaluators.
void globalToGhostTpetraVector(int i, const VectorType &in, VectorType &out) const
Teuchos::RCP< const Teuchos::Comm< int > > comm
Teuchos::RCP< panzer::CloneableEvaluator > buildGather() const
Use preconstructed gather evaluators.
BlockedTpetraLinearObjFactory(const Teuchos::RCP< const Teuchos::MpiComm< int > > &comm, const Teuchos::RCP< const BlockedDOFManager< LocalOrdinalT, GlobalOrdinalT > > &gidProvider)
Teuchos::RCP< Thyra::ProductVectorSpaceBase< ScalarT > > ghostedRangeSpace_
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getThyraDomainSpace() const
Get the domain vector space (x and dxdt)
Pushes residual values into the residual vector for a Newton-based solve.
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getGhostedThyraRangeSpace() const
Get the range vector space (f)
Gathers orientations per field from the global indexer and stores them in the field manager...
#define TEUCHOS_ASSERT(assertion_test)
Gathers tangent vectors dx/dp for computing df/dx*dx/dp + df/dp into the nodal fields of the field ma...
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherDomain() const
Use preconstructed gather evaluators.
void ghostToGlobalThyraVector(const Teuchos::RCP< const Thyra::VectorBase< ScalarT > > &in, const Teuchos::RCP< Thyra::VectorBase< ScalarT > > &out) const
virtual void writeVector(const std::string &identifier, const LinearObjContainer &loc, int id) const
void initializeContainer(int, LinearObjContainer &loc) const
std::vector< Teuchos::RCP< const MapType > > ghostedMaps_
Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > getDomainGlobalIndexer() const
Get the domain unique global indexer this factory was created with.
void ghostToGlobalThyraMatrix(const Thyra::LinearOpBase< ScalarT > &in, Thyra::LinearOpBase< ScalarT > &out) const
Teuchos::RCP< CrsMatrixType > getGhostedTpetraMatrix(int i, int j) const
Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > MapType
virtual Teuchos::RCP< const CrsGraphType > buildTpetraGhostedGraph(int i, int j) const
Teuchos::RCP< panzer::CloneableEvaluator > buildScatterDirichlet() const
Use preconstructed dirichlet scatter evaluators.
Teuchos::RCP< CrsMatrixType > getTpetraMatrix(int i, int j) const