Panzer  Version of the Day
Panzer_EpetraLinearObjFactory_decl.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_EpetraLinearObjFactory_decl_hpp__
44 #define __Panzer_EpetraLinearObjFactory_decl_hpp__
45 
46 #define PANZER_USE_BLOCKED_EPETRA_LOF
47 
48 #ifndef PANZER_USE_BLOCKED_EPETRA_LOF
49 #include <map>
50 
51 // Epetra includes
52 #include "Epetra_Map.h"
53 #include "Epetra_CrsGraph.h"
54 #include "Epetra_Import.h"
55 #include "Epetra_Export.h"
56 
57 #include "PanzerDiscFE_config.hpp"
61 #include "Panzer_ScatterResidual_Epetra.hpp"
62 #include "Panzer_ScatterDirichletResidual_Epetra.hpp"
63 #include "Panzer_GatherSolution_Epetra.hpp"
64 #include "Panzer_GatherTangent_Epetra.hpp"
65 #include "Panzer_GatherOrientation.hpp"
68 
69 #include "Teuchos_RCP.hpp"
70 #include "Teuchos_DefaultMpiComm.hpp"
71 
72 namespace panzer {
73 
74 template <typename Traits,typename LocalOrdinalT>
75 class EpetraLinearObjFactory : public LinearObjFactory<Traits>
76  , public ThyraObjFactory<double> {
77 public:
78 
79  EpetraLinearObjFactory(const Teuchos::RCP<const Teuchos::MpiComm<int> > & comm,
80  const Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,int> > & gidProvider,
81  bool useDiscreteAdjoint=false);
82 
83  EpetraLinearObjFactory(const Teuchos::RCP<const Teuchos::MpiComm<int> > & comm,
84  const Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,int> > & rowProvider,
85  const Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,int> > & colProvider,
86  bool useDiscreteAdjoint=false);
87 
91  EpetraLinearObjFactory(const Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,int> > & rowProvider);
92 
93  virtual ~EpetraLinearObjFactory();
94 
95 /*************** Linear object factory methods *******************/
96 
97  virtual void readVector(const std::string & identifier,LinearObjContainer & loc,int id) const;
98 
99  virtual void writeVector(const std::string & identifier,const LinearObjContainer & loc,int id) const;
100 
101  virtual Teuchos::RCP<LinearObjContainer> buildLinearObjContainer() const;
102 
103  virtual Teuchos::RCP<LinearObjContainer> buildPrimitiveLinearObjContainer() const
104  { return buildLinearObjContainer(); }
105 
106  virtual Teuchos::RCP<LinearObjContainer> buildGhostedLinearObjContainer() const;
107 
108  virtual Teuchos::RCP<LinearObjContainer> buildPrimitiveGhostedLinearObjContainer() const
109  { return buildGhostedLinearObjContainer(); }
110 
111  virtual void globalToGhostContainer(const LinearObjContainer & container,
112  LinearObjContainer & ghostContainer,int) const;
113  virtual void ghostToGlobalContainer(const LinearObjContainer & ghostContainer,
114  LinearObjContainer & container,int) const;
115 
122  virtual void adjustForDirichletConditions(const LinearObjContainer & localBCRows,
123  const LinearObjContainer & globalBCRows,
124  LinearObjContainer & ghostedObjs,
125  bool zeroVectorRows=false, bool adjustX=false) const;
126 
130  virtual void applyDirichletBCs(const LinearObjContainer & counter,
131  LinearObjContainer & result) const;
132 
137  virtual Teuchos::RCP<ReadOnlyVector_GlobalEvaluationData> buildDomainContainer() const;
138 
141  virtual Teuchos::MpiComm<int> getComm() const;
142 
144  Teuchos::RCP<const Thyra::VectorSpaceBase<double> > getThyraDomainSpace() const;
145 
147  Teuchos::RCP<const Thyra::VectorSpaceBase<double> > getThyraRangeSpace() const;
148 
150  Teuchos::RCP<Thyra::LinearOpBase<double> > getThyraMatrix() const;
151 
153  template <typename EvalT>
154  Teuchos::RCP<panzer::CloneableEvaluator> buildScatter() const
155  { return Teuchos::rcp(new ScatterResidual_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_,colGidProvider_,useDiscreteAdjoint_)); }
156 
158  template <typename EvalT>
159  Teuchos::RCP<panzer::CloneableEvaluator > buildGather() const
160  { return Teuchos::rcp(new GatherSolution_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_)); }
161 
163  template <typename EvalT>
164  Teuchos::RCP<panzer::CloneableEvaluator > buildGatherTangent() const
165  { return Teuchos::rcp(new GatherTangent_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_)); }
166 
168  template <typename EvalT>
169  Teuchos::RCP<panzer::CloneableEvaluator > buildGatherDomain() const
170  { if(colGidProvider_!=Teuchos::null)
171  return Teuchos::rcp(new GatherSolution_Epetra<EvalT,Traits,LocalOrdinalT,int>(colGidProvider_));
172  return Teuchos::rcp(new GatherSolution_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_)); }
173 
175  template <typename EvalT>
176  Teuchos::RCP<panzer::CloneableEvaluator > buildGatherOrientation() const
177  { return Teuchos::rcp(new GatherOrientation<EvalT,Traits,LocalOrdinalT,int>(gidProvider_)); }
178 
180  template <typename EvalT>
181  Teuchos::RCP<panzer::CloneableEvaluator> buildScatterDirichlet() const
182  { return Teuchos::rcp(new ScatterDirichletResidual_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_,colGidProvider_)); }
183 
184 /*************** Generic helper functions for container setup *******************/
185 
191  void initializeContainer(int,LinearObjContainer & loc) const;
192 
198  void initializeContainer(int mem,EpetraLinearObjContainer & loc) const;
199 
205  void initializeGhostedContainer(int,LinearObjContainer & loc) const;
206 
212  void initializeGhostedContainer(int mem,EpetraLinearObjContainer & loc) const;
213 
214 /*************** Epetra based methods *******************/
215 
217  virtual const Teuchos::RCP<Epetra_Map> getMap() const;
218 
220  const Teuchos::RCP<Epetra_Map> getMap(int) const { return getMap(); }
221 
223  virtual const Teuchos::RCP<Epetra_Map> getColMap() const;
224 
225  virtual const Teuchos::RCP<Epetra_Map> getColMap(int) const { return getColMap(); }
226 
228  virtual const Teuchos::RCP<Epetra_Map> getGhostedMap() const;
229 
231  virtual const Teuchos::RCP<Epetra_Map> getGhostedMap(int) const { return getGhostedMap(); }
232 
234  virtual const Teuchos::RCP<Epetra_Map> getGhostedColMap() const;
235 
236  virtual const Teuchos::RCP<Epetra_Map> getGhostedColMap(int) const { return getGhostedColMap(); }
237 
239  virtual const Teuchos::RCP<Epetra_CrsGraph> getGraph() const;
240 
242  const Teuchos::RCP<Epetra_CrsGraph> getGraph(int,int) const { return getGraph(); }
243 
245  virtual const Teuchos::RCP<Epetra_CrsGraph> getGhostedGraph() const;
246 
247  const Teuchos::RCP<Epetra_CrsGraph> getGhostedGraph(int,int) const { return getGhostedGraph(); }
248 
250  virtual const Teuchos::RCP<Epetra_Import> getGhostedImport() const;
251 
252  virtual const Teuchos::RCP<Epetra_Import> getGhostedImport(int ) const { return getGhostedImport(); }
253 
255  virtual const Teuchos::RCP<Epetra_Import> getGhostedColImport() const;
256 
258  virtual const Teuchos::RCP<Epetra_Export> getGhostedExport() const;
259 
261  virtual const Teuchos::RCP<Epetra_Export> getGhostedColExport() const;
262 
264  virtual const Teuchos::RCP<const Epetra_Comm> getEpetraComm() const;
265 
267  Teuchos::RCP<const panzer::UniqueGlobalIndexerBase> getDomainGlobalIndexer() const
268  { return colGidProvider_!=Teuchos::null ? colGidProvider_ : gidProvider_; }
269 
271  Teuchos::RCP<const panzer::UniqueGlobalIndexerBase> getRangeGlobalIndexer() const
272  { return gidProvider_; }
273 
274 protected:
275  Teuchos::RCP<Epetra_Vector> getGhostedEpetraVector() const;
276  Teuchos::RCP<Epetra_Vector> getGhostedEpetraColVector() const;
277  Teuchos::RCP<Epetra_Vector> getEpetraVector() const;
278  Teuchos::RCP<Epetra_Vector> getEpetraColVector() const;
279  Teuchos::RCP<Epetra_CrsMatrix> getEpetraMatrix() const;
280  Teuchos::RCP<Epetra_CrsMatrix> getGhostedEpetraMatrix() const;
281 
282  void ghostToGlobalEpetraVector(const Epetra_Vector & in,Epetra_Vector & out,bool col=false) const;
283  void ghostToGlobalEpetraMatrix(const Epetra_CrsMatrix & in,Epetra_CrsMatrix & out) const;
284  void globalToGhostEpetraVector(const Epetra_Vector & in,Epetra_Vector & out,bool col=false) const;
285 
286  // get the map from the matrix
287  virtual const Teuchos::RCP<Epetra_Map> buildMap() const;
288  virtual const Teuchos::RCP<Epetra_Map> buildColMap() const;
289  virtual const Teuchos::RCP<Epetra_Map> buildGhostedMap() const;
290  virtual const Teuchos::RCP<Epetra_Map> buildGhostedColMap() const;
291 
292  // get the graph of the crs matrix
293  virtual const Teuchos::RCP<Epetra_CrsGraph> buildGraph() const;
294  virtual const Teuchos::RCP<Epetra_CrsGraph> buildGhostedGraph(bool optimizeStorage) const;
295 
296  // this method by defaults calls getGhostedGraph, however if the column global indexer
297  // is filtered (i.e. a Filtered_UniqueGlobalIndexer) then the filtered columns are removed
298  // in the version of the graph return by this. Note if the column UGI is filtered, then their
299  // will be substantial computational cost including communication in this method.
300  virtual const Teuchos::RCP<Epetra_CrsGraph> buildFilteredGhostedGraph() const;
301 
302  // storage for Epetra graphs and maps
303  Teuchos::RCP<const Epetra_Comm> comm_;
304  mutable Teuchos::RCP<Epetra_Map> map_;
305  mutable Teuchos::RCP<Epetra_Map> cMap_;
306  mutable Teuchos::RCP<Epetra_Map> ghostedMap_;
307  mutable Teuchos::RCP<Epetra_Map> cGhostedMap_;
308  mutable Teuchos::RCP<Epetra_CrsGraph> graph_;
309  mutable Teuchos::RCP<Epetra_CrsGraph> ghostedGraph_;
310 
311  // import/exporter storage
312  mutable Teuchos::RCP<Epetra_Import> importer_, colImporter_;
313  mutable Teuchos::RCP<Epetra_Export> exporter_, colExporter_;
314 
315  bool hasColProvider_;
316  Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,int> > gidProvider_;
317  Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,int> > colGidProvider_;
318  Teuchos::RCP<const Teuchos::OpaqueWrapper<MPI_Comm> > rawMpiComm_;
319 
320  mutable Teuchos::RCP<const Thyra::VectorSpaceBase<double> > rangeSpace_;
321  mutable Teuchos::RCP<const Thyra::VectorSpaceBase<double> > domainSpace_;
322 
323  bool useDiscreteAdjoint_;
324 };
325 
326 }
327 
328 #else
329 
331 
332 namespace panzer {
333 
334 template <typename Traits,typename LocalOrdinalT>
336 
337 }
338 
339 #endif
340 
341 #endif
void ghostToGlobalEpetraVector(int i, const Epetra_Vector &in, Epetra_Vector &out, bool col) const
virtual Teuchos::RCP< LinearObjContainer > buildGhostedLinearObjContainer() const
virtual const Teuchos::RCP< Epetra_Map > buildMap(int i) const
Teuchos::RCP< Epetra_CrsMatrix > getGhostedEpetraMatrix(int i, int j) const
virtual const Teuchos::RCP< Epetra_Export > getGhostedExport(int j) const
get exporter for converting an overalapped object to a "normal" object
Teuchos::RCP< Thyra::LinearOpBase< double > > getThyraMatrix() const
Get a Thyra operator.
virtual void readVector(const std::string &identifier, LinearObjContainer &loc, int id) const
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > domainSpace_
virtual void ghostToGlobalContainer(const LinearObjContainer &ghostContainer, LinearObjContainer &container, int) const
virtual const Teuchos::RCP< Epetra_Map > buildColMap(int i) const
void globalToGhostEpetraVector(int i, const Epetra_Vector &in, Epetra_Vector &out, bool col) const
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveLinearObjContainer() const
virtual const Teuchos::RCP< Epetra_CrsGraph > buildGhostedGraph(int i, int j, bool optimizeStorage) const
virtual Teuchos::RCP< ReadOnlyVector_GlobalEvaluationData > buildDomainContainer() const
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > getThyraRangeSpace() const
Get the range vector space (f)
virtual const Teuchos::RCP< Epetra_Map > getMap(int i) const
get the map from the matrix
void ghostToGlobalEpetraMatrix(int blockRow, const Epetra_CrsMatrix &in, Epetra_CrsMatrix &out) const
virtual const Teuchos::RCP< Epetra_Import > getGhostedImport(int i) const
get importer for converting an overalapped object to a "normal" object
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > rangeSpace_
virtual const Teuchos::RCP< Epetra_CrsGraph > getGhostedGraph(int i, int j) const
get the ghosted graph of the crs matrix
Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > getDomainGlobalIndexer() const
Get the domain global indexer object associated with this factory.
virtual const Teuchos::RCP< Epetra_CrsGraph > buildFilteredGhostedGraph(int i, int j) const
virtual const Teuchos::RCP< Epetra_Map > getColMap(int i) const
get the map from the matrix
virtual void applyDirichletBCs(const LinearObjContainer &counter, LinearObjContainer &result) const
Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > getRangeGlobalIndexer() const
Get the range global indexer object associated with this factory.
BlockedEpetraLinearObjFactory< Traits, LocalOrdinalT > EpetraLinearObjFactory
virtual Teuchos::RCP< LinearObjContainer > buildLinearObjContainer() const
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherTangent() const
Use preconstructed gather evaluators.
Teuchos::RCP< const Teuchos::OpaqueWrapper< MPI_Comm > > rawMpiComm_
virtual void adjustForDirichletConditions(const LinearObjContainer &localBCRows, const LinearObjContainer &globalBCRows, LinearObjContainer &ghostedObjs, bool zeroVectorRows=false, bool adjustX=false) const
virtual const Teuchos::RCP< const Epetra_Comm > getEpetraComm() const
get exporter for converting an overalapped object to a "normal" object
Teuchos::RCP< panzer::CloneableEvaluator > buildScatterDirichlet() const
Use preconstructed dirichlet scatter evaluators.
void initializeGhostedContainer(int, LinearObjContainer &loc) const
virtual const Teuchos::RCP< Epetra_Map > getGhostedMap(int i) const
get the ghosted map from the matrix
Teuchos::RCP< Epetra_CrsMatrix > getEpetraMatrix(int i, int j) const
Teuchos::RCP< panzer::CloneableEvaluator > buildScatter() const
Use preconstructed scatter evaluators.
virtual const Teuchos::RCP< Epetra_CrsGraph > buildGraph(int i, int j) const
void initializeContainer(int, LinearObjContainer &loc) const
virtual const Teuchos::RCP< Epetra_Map > buildGhostedMap(int i) const
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherOrientation() const
Use preconstructed gather evaluators.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > getThyraDomainSpace() const
Get the domain vector space (x and dxdt)
Teuchos::RCP< const Teuchos::Comm< int > > comm
virtual const Teuchos::RCP< Epetra_Import > getGhostedColImport(int i) const
get importer for converting an overalapped object to a "normal" object
virtual const Teuchos::RCP< Epetra_CrsGraph > getGraph(int i, int j) const
get the graph of the crs matrix
virtual void writeVector(const std::string &identifier, const LinearObjContainer &loc, int id) const
virtual void globalToGhostContainer(const LinearObjContainer &container, LinearObjContainer &ghostContainer, int) const
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherDomain() const
Use preconstructed gather evaluators.
virtual const Teuchos::RCP< Epetra_Map > getGhostedColMap(int i) const
get the ghosted map from the matrix
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveGhostedLinearObjContainer() const
Teuchos::RCP< panzer::CloneableEvaluator > buildGather() const
Use preconstructed gather evaluators.
virtual const Teuchos::RCP< Epetra_Export > getGhostedColExport(int j) const
get exporter for converting an overalapped object to a "normal" object