Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_BlockedTpetraLinearObjFactory.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_BlockedTpetraLinearObjFactory_hpp__
12#define __Panzer_BlockedTpetraLinearObjFactory_hpp__
13
14#include <map>
15
16// Tpetra includes
17#include "Tpetra_Map.hpp"
18#include "Tpetra_CrsGraph.hpp"
19#include "Tpetra_Import.hpp"
20#include "Tpetra_Export.hpp"
21
22#include "PanzerDiscFE_config.hpp"
30#include "Panzer_HashUtils.hpp" // for pair_hash
31
32#include "Panzer_GatherOrientation.hpp"
38
39#include "Thyra_BlockedLinearOpBase.hpp"
40#include "Thyra_ProductVectorBase.hpp"
41
42#include "Teuchos_RCP.hpp"
43#include "Teuchos_DefaultMpiComm.hpp"
44#include "Teuchos_OpaqueWrapper.hpp"
45
46namespace panzer {
47
48template <typename Traits,typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT=panzer::TpetraNodeType>
50 , public ThyraObjFactory<double> {
51public:
53 typedef Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> VectorType;
54 typedef Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> CrsMatrixType;
55 typedef Tpetra::Operator<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> OperatorType;
56 typedef Tpetra::CrsGraph<LocalOrdinalT,GlobalOrdinalT,NodeT> CrsGraphType;
57 typedef Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> MapType;
58 typedef Tpetra::Import<LocalOrdinalT,GlobalOrdinalT,NodeT> ImportType;
59 typedef Tpetra::Export<LocalOrdinalT,GlobalOrdinalT,NodeT> ExportType;
60
61 typedef Thyra::TpetraVector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> ThyraVector;
62 typedef Thyra::TpetraLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> ThyraLinearOp;
63
64
65 BlockedTpetraLinearObjFactory(const Teuchos::RCP<const Teuchos::MpiComm<int> > & comm,
66 const Teuchos::RCP<const BlockedDOFManager> & gidProvider);
67
72 BlockedTpetraLinearObjFactory(const Teuchos::RCP<const Teuchos::MpiComm<int> > & comm,
73 const std::vector<Teuchos::RCP<const panzer::GlobalIndexer>> & gidProviders);
74
76
77/*************** Linear object factory methods *******************/
78
79 virtual void readVector(const std::string & /* identifier */, LinearObjContainer & /* loc */, int /* id */) const
80 { TEUCHOS_ASSERT(false); }
81
82 virtual void writeVector(const std::string & /* identifier */, const LinearObjContainer & /* loc */, int /* id */) const
83 { TEUCHOS_ASSERT(false); }
84
85 virtual Teuchos::RCP<LinearObjContainer> buildLinearObjContainer() const;
86
87 virtual Teuchos::RCP<LinearObjContainer> buildPrimitiveLinearObjContainer() const
88 { return buildLinearObjContainer(); }
89
90 virtual Teuchos::RCP<LinearObjContainer> buildGhostedLinearObjContainer() const;
91
92 virtual Teuchos::RCP<LinearObjContainer> buildPrimitiveGhostedLinearObjContainer() const
94
95 virtual void globalToGhostContainer(const LinearObjContainer & container,
96 LinearObjContainer & ghostContainer,int) const;
97 virtual void ghostToGlobalContainer(const LinearObjContainer & ghostContainer,
98 LinearObjContainer & container,int) const;
99
106 virtual void adjustForDirichletConditions(const LinearObjContainer & localBCRows,
107 const LinearObjContainer & globalBCRows,
108 LinearObjContainer & ghostedObjs,
109 bool zeroVectorRows=false, bool adjustX = false) const;
110
114 virtual void applyDirichletBCs(const LinearObjContainer & counter,
115 LinearObjContainer & result) const;
116
121 virtual Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData> buildReadOnlyDomainContainer() const;
122
123#ifdef PANZER_HAVE_EPETRA_STACK
128 virtual Teuchos::RCP<WriteVector_GlobalEvaluationData> buildWriteDomainContainer() const;
129#endif
130
132
134 template <typename EvalT>
135 Teuchos::RCP<panzer::CloneableEvaluator> buildScatter() const
137
139 template <typename EvalT>
140 Teuchos::RCP<panzer::CloneableEvaluator > buildGather() const
142
144 template <typename EvalT>
145 Teuchos::RCP<panzer::CloneableEvaluator > buildGatherTangent() const
147
149 template <typename EvalT>
150 Teuchos::RCP<panzer::CloneableEvaluator > buildGatherDomain() const
152
154 template <typename EvalT>
155 Teuchos::RCP<panzer::CloneableEvaluator > buildGatherOrientation() const
156 { return Teuchos::rcp(new GatherOrientation<EvalT,Traits,LocalOrdinalT,GlobalOrdinalT>(nc2c_vector(blockedDOFManager_->getFieldDOFManagers()))); }
157
159 template <typename EvalT>
160 Teuchos::RCP<panzer::CloneableEvaluator> buildScatterDirichlet() const
162
163/*************** Generic helper functions for container setup *******************/
164
170 void initializeContainer(int,LinearObjContainer & loc) const;
171
177 void initializeContainer(int mem,BTLOC & loc) const;
178
185
191 void initializeGhostedContainer(int mem,BTLOC & loc) const;
192
193/*************** Thyra based methods *******************/
194
196 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > getThyraDomainSpace() const;
197
199 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > getThyraRangeSpace() const;
200
202 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > getThyraDomainSpace(int blk) const;
203
205 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > getThyraRangeSpace(int blk) const;
206
208 Teuchos::RCP<Thyra::VectorBase<ScalarT> > getThyraDomainVector() const;
209
211 Teuchos::RCP<Thyra::VectorBase<ScalarT> > getThyraRangeVector() const;
212
214 Teuchos::RCP<Thyra::LinearOpBase<ScalarT> > getThyraMatrix() const;
215
216 // and now the ghosted versions
217
219 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > getGhostedThyraDomainSpace() const;
220
222 Teuchos::RCP<const Thyra::VectorSpaceBase<ScalarT> > getGhostedThyraRangeSpace() const;
223
225 Teuchos::RCP<Thyra::VectorBase<ScalarT> > getGhostedThyraDomainVector() const;
226
228 Teuchos::RCP<Thyra::VectorBase<ScalarT> > getGhostedThyraRangeVector() const;
229
231 Teuchos::RCP<Thyra::BlockedLinearOpBase<ScalarT> > getGhostedThyraMatrix() const;
232
233/*************** Tpetra based methods *******************/
234
236 virtual Teuchos::RCP<const MapType> getMap(int i) const;
237
239 virtual Teuchos::RCP<const MapType> getGhostedMap(int i) const;
240
242 virtual Teuchos::RCP<const CrsGraphType> getGraph(int i,int j) const;
243
245 virtual Teuchos::RCP<const CrsGraphType> getGhostedGraph(int i,int j) const;
246
248 virtual Teuchos::RCP<const ImportType> getGhostedImport(int i) const;
249
251 virtual Teuchos::RCP<const ExportType> getGhostedExport(int j) const;
252
253 Teuchos::RCP<CrsMatrixType> getTpetraMatrix(int i,int j) const;
254 Teuchos::RCP<CrsMatrixType> getGhostedTpetraMatrix(int i,int j) const;
255
256 Teuchos::RCP<VectorType> getTpetraDomainVector(int i) const;
257 Teuchos::RCP<VectorType> getGhostedTpetraDomainVector(int i) const;
258
259 Teuchos::RCP<VectorType> getTpetraRangeVector(int i) const;
260 Teuchos::RCP<VectorType> getGhostedTpetraRangeVector(int i) const;
261
263 int getBlockRowCount() const;
264
266 int getBlockColCount() const;
267
269 void addExcludedPair(int rowBlock,int colBlock);
270
272 void addExcludedPairs(const std::vector<std::pair<int,int> > & exPairs);
273
274 virtual void beginFill(LinearObjContainer & loc) const;
275 virtual void endFill(LinearObjContainer & loc) const;
276
277 Teuchos::RCP<const panzer::BlockedDOFManager> getGlobalIndexer() const
278 { return blockedDOFManager_; }
279
281 Teuchos::RCP<const panzer::GlobalIndexer> getDomainGlobalIndexer() const
282 { return blockProvider_; }
283
285 Teuchos::RCP<const panzer::GlobalIndexer> getRangeGlobalIndexer() const
286 { return blockProvider_; }
287
288protected:
289/*************** Generic methods/members *******************/
290
291 // Get the global indexer associated with a particular block
292 Teuchos::RCP<const GlobalIndexer> getGlobalIndexer(int i) const;
293
295 void makeRoomForBlocks(std::size_t blockCnt);
296
297 Teuchos::RCP<const GlobalIndexer> blockProvider_;
298 Teuchos::RCP<const BlockedDOFManager> blockedDOFManager_;
299 std::vector<Teuchos::RCP<const GlobalIndexer> > gidProviders_;
300
301 // which block entries are ignored
302 std::unordered_set<std::pair<int,int>,panzer::pair_hash> excludedPairs_;
303
304/*************** Thyra based methods/members *******************/
305
306 void ghostToGlobalThyraVector(const Teuchos::RCP<const Thyra::VectorBase<ScalarT> > & in,
307 const Teuchos::RCP<Thyra::VectorBase<ScalarT> > & out) const;
309 void globalToGhostThyraVector(const Teuchos::RCP<const Thyra::VectorBase<ScalarT> > & in,
310 const Teuchos::RCP<Thyra::VectorBase<ScalarT> > & out) const;
311
312 mutable Teuchos::RCP<Thyra::ProductVectorSpaceBase<ScalarT> > rangeSpace_;
313 mutable Teuchos::RCP<Thyra::ProductVectorSpaceBase<ScalarT> > domainSpace_;
314
315 mutable Teuchos::RCP<Thyra::ProductVectorSpaceBase<ScalarT> > ghostedRangeSpace_;
316 mutable Teuchos::RCP<Thyra::ProductVectorSpaceBase<ScalarT> > ghostedDomainSpace_;
317
318/*************** Tpetra based methods/members *******************/
319
320 void adjustForDirichletConditions(const VectorType & local_bcs,
321 const VectorType & global_bcs,
322 const Teuchos::Ptr<VectorType> & f,
323 const Teuchos::Ptr<CrsMatrixType> & A,
324 bool zeroVectorRows) const;
325
326 void ghostToGlobalTpetraVector(int i,const VectorType & in,VectorType & out) const;
327 void ghostToGlobalTpetraMatrix(int blockRow,const CrsMatrixType & in,CrsMatrixType & out) const;
328 void globalToGhostTpetraVector(int i,const VectorType & in,VectorType & out) const;
329
330 // get the map from the matrix
331 virtual Teuchos::RCP<const MapType> buildTpetraMap(int i) const;
332 virtual Teuchos::RCP<const MapType> buildTpetraGhostedMap(int i) const;
333
334 // get the graph of the crs matrix
335 virtual Teuchos::RCP<const CrsGraphType> buildTpetraGraph(int i,int j) const;
336 virtual Teuchos::RCP<const CrsGraphType> buildTpetraGhostedGraph(int i,int j) const;
337
338 // storage for Tpetra graphs and maps
339 Teuchos::RCP<const Teuchos::MpiComm<int> > comm_;
340 mutable std::vector<Teuchos::RCP<const MapType> > maps_;
341 mutable std::vector<Teuchos::RCP<const MapType> > ghostedMaps_;
342 mutable std::unordered_map<std::pair<int,int>,Teuchos::RCP<const CrsGraphType>,panzer::pair_hash> graphs_ ;
343 mutable std::unordered_map<std::pair<int,int>,Teuchos::RCP<const CrsGraphType>,panzer::pair_hash> ghostedGraphs_;
344
345 mutable std::vector<Teuchos::RCP<const ImportType> > importers_;
346 mutable std::vector<Teuchos::RCP<const ExportType> > exporters_;
347};
348
349}
350
351#endif
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing.
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherDomain() const
Use preconstructed gather evaluators.
Teuchos::RCP< const panzer::GlobalIndexer > getRangeGlobalIndexer() const
Get the range unique global indexer this factory was created with.
Tpetra::Operator< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > OperatorType
Teuchos::RCP< Thyra::VectorBase< ScalarT > > getThyraRangeVector() const
Get a range vector.
virtual void adjustForDirichletConditions(const LinearObjContainer &localBCRows, const LinearObjContainer &globalBCRows, LinearObjContainer &ghostedObjs, bool zeroVectorRows=false, bool adjustX=false) const
Teuchos::RCP< panzer::CloneableEvaluator > buildGather() const
Use preconstructed gather evaluators.
virtual void applyDirichletBCs(const LinearObjContainer &counter, LinearObjContainer &result) const
void ghostToGlobalThyraVector(const Teuchos::RCP< const Thyra::VectorBase< ScalarT > > &in, const Teuchos::RCP< Thyra::VectorBase< ScalarT > > &out) const
Teuchos::RCP< const panzer::GlobalIndexer > getDomainGlobalIndexer() const
Get the domain unique global indexer this factory was created with.
std::vector< Teuchos::RCP< const GlobalIndexer > > gidProviders_
void initializeGhostedContainer(int, LinearObjContainer &loc) const
Teuchos::RCP< Thyra::VectorBase< ScalarT > > getThyraDomainVector() const
Get a domain vector.
Teuchos::RCP< const Teuchos::MpiComm< int > > comm_
std::vector< Teuchos::RCP< const MapType > > ghostedMaps_
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getGhostedThyraDomainSpace() const
Get the domain vector space (x and dxdt)
Teuchos::RCP< const BlockedDOFManager > blockedDOFManager_
virtual Teuchos::RCP< const CrsGraphType > getGhostedGraph(int i, int j) const
get the ghosted graph of the crs matrix
virtual Teuchos::RCP< const MapType > getMap(int i) const
get the map from the matrix
Teuchos::RCP< panzer::CloneableEvaluator > buildScatterDirichlet() const
Use preconstructed dirichlet scatter evaluators.
virtual void ghostToGlobalContainer(const LinearObjContainer &ghostContainer, LinearObjContainer &container, int) const
virtual void globalToGhostContainer(const LinearObjContainer &container, LinearObjContainer &ghostContainer, int) const
std::vector< Teuchos::RCP< const ExportType > > exporters_
virtual Teuchos::RCP< const MapType > buildTpetraGhostedMap(int i) const
virtual Teuchos::RCP< const MapType > buildTpetraMap(int i) const
virtual Teuchos::RCP< const CrsGraphType > buildTpetraGraph(int i, int j) const
Teuchos::RCP< VectorType > getGhostedTpetraRangeVector(int i) const
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getThyraDomainSpace() const
Get the domain vector space (x and dxdt)
void makeRoomForBlocks(std::size_t blockCnt)
Allocate the space in the std::vector objects so we can fill with appropriate Tpetra data.
Teuchos::RCP< Thyra::VectorBase< ScalarT > > getGhostedThyraRangeVector() const
Get a range vector.
virtual Teuchos::RCP< ReadOnlyVector_GlobalEvaluationData > buildReadOnlyDomainContainer() const
std::unordered_map< std::pair< int, int >, Teuchos::RCP< const CrsGraphType >, panzer::pair_hash > graphs_
Tpetra::CrsGraph< LocalOrdinalT, GlobalOrdinalT, NodeT > CrsGraphType
Teuchos::RCP< panzer::CloneableEvaluator > buildScatter() const
Use preconstructed scatter evaluators.
Tpetra::Export< LocalOrdinalT, GlobalOrdinalT, NodeT > ExportType
virtual Teuchos::RCP< const CrsGraphType > buildTpetraGhostedGraph(int i, int j) const
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.
Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > VectorType
Teuchos::RCP< VectorType > getGhostedTpetraDomainVector(int i) const
Teuchos::RCP< Thyra::ProductVectorSpaceBase< ScalarT > > ghostedDomainSpace_
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getGhostedThyraRangeSpace() const
Get the range vector space (f)
std::unordered_map< std::pair< int, int >, Teuchos::RCP< const CrsGraphType >, panzer::pair_hash > ghostedGraphs_
virtual void writeVector(const std::string &, const LinearObjContainer &, int) const
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherOrientation() const
Use preconstructed gather evaluators.
Teuchos::RCP< CrsMatrixType > getTpetraMatrix(int i, int j) const
virtual Teuchos::RCP< LinearObjContainer > buildGhostedLinearObjContainer() const
std::vector< Teuchos::RCP< const MapType > > maps_
void globalToGhostThyraVector(const Teuchos::RCP< const Thyra::VectorBase< ScalarT > > &in, const Teuchos::RCP< Thyra::VectorBase< ScalarT > > &out) const
virtual Teuchos::RCP< LinearObjContainer > buildLinearObjContainer() const
void globalToGhostTpetraVector(int i, const VectorType &in, VectorType &out) const
virtual void readVector(const std::string &, LinearObjContainer &, int) const
void addExcludedPair(int rowBlock, int colBlock)
exclude a block pair from the matrix
std::vector< Teuchos::RCP< const ImportType > > importers_
void ghostToGlobalTpetraVector(int i, const VectorType &in, VectorType &out) const
void ghostToGlobalThyraMatrix(const Thyra::LinearOpBase< ScalarT > &in, Thyra::LinearOpBase< ScalarT > &out) const
void ghostToGlobalTpetraMatrix(int blockRow, const CrsMatrixType &in, CrsMatrixType &out) const
std::unordered_set< std::pair< int, int >, panzer::pair_hash > excludedPairs_
Tpetra::CrsMatrix< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > CrsMatrixType
Teuchos::RCP< Thyra::ProductVectorSpaceBase< ScalarT > > domainSpace_
Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > MapType
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > getThyraRangeSpace() const
Get the range vector space (f)
Thyra::TpetraLinearOp< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > ThyraLinearOp
Teuchos::RCP< CrsMatrixType > getGhostedTpetraMatrix(int i, int j) const
Teuchos::RCP< Thyra::ProductVectorSpaceBase< ScalarT > > ghostedRangeSpace_
virtual Teuchos::RCP< const ImportType > getGhostedImport(int i) const
get importer for converting an overalapped object to a "normal" object
Teuchos::RCP< Thyra::ProductVectorSpaceBase< ScalarT > > rangeSpace_
Tpetra::Import< LocalOrdinalT, GlobalOrdinalT, NodeT > ImportType
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveLinearObjContainer() const
BlockedTpetraLinearObjContainer< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > BTLOC
void addExcludedPairs(const std::vector< std::pair< int, int > > &exPairs)
exclude a vector of pairs from the matrix
virtual Teuchos::RCP< const ExportType > getGhostedExport(int j) const
get exporter for converting an overalapped object to a "normal" object
Thyra::TpetraVector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > ThyraVector
Teuchos::RCP< Thyra::LinearOpBase< ScalarT > > getThyraMatrix() const
Get a Thyra operator.
Teuchos::RCP< Thyra::VectorBase< ScalarT > > getGhostedThyraDomainVector() const
Get a domain vector.
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveGhostedLinearObjContainer() const
virtual Teuchos::RCP< const CrsGraphType > getGraph(int i, int j) const
get the graph of the crs matrix
Teuchos::RCP< const panzer::BlockedDOFManager > getGlobalIndexer() const
Teuchos::RCP< Thyra::BlockedLinearOpBase< ScalarT > > getGhostedThyraMatrix() const
Get a Thyra operator.
Gathers orientations per field from the global indexer and stores them in the field manager.
Gathers solution values from the Newton solution vector into the nodal fields of the field manager.
Gathers tangent vectors dx/dp for computing df/dx*dx/dp + df/dp into the nodal fields of the field ma...
Pushes residual values into the residual vector for a Newton-based solve.
Pushes residual values into the residual vector for a Newton-based solve.
std::vector< Teuchos::RCP< const GlobalIndexer > > nc2c_vector(const std::vector< Teuchos::RCP< GlobalIndexer > > &ugis)