Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
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 
102 
104  { return buildLinearObjContainer(); }
105 
107 
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 
138 
144 
147  virtual Teuchos::MpiComm<int> getComm() const;
148 
151 
154 
157 
159  template <typename EvalT>
161  { return Teuchos::rcp(new ScatterResidual_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_,colGidProvider_,useDiscreteAdjoint_)); }
162 
164  template <typename EvalT>
166  { return Teuchos::rcp(new GatherSolution_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_)); }
167 
169  template <typename EvalT>
171  { return Teuchos::rcp(new GatherTangent_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_)); }
172 
174  template <typename EvalT>
176  { if(colGidProvider_!=Teuchos::null)
177  return Teuchos::rcp(new GatherSolution_Epetra<EvalT,Traits,LocalOrdinalT,int>(colGidProvider_));
178  return Teuchos::rcp(new GatherSolution_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_)); }
179 
181  template <typename EvalT>
183  { return Teuchos::rcp(new GatherOrientation<EvalT,Traits,LocalOrdinalT,int>(gidProvider_)); }
184 
186  template <typename EvalT>
188  { return Teuchos::rcp(new ScatterDirichletResidual_Epetra<EvalT,Traits,LocalOrdinalT,int>(gidProvider_,colGidProvider_)); }
189 
190 /*************** Generic helper functions for container setup *******************/
191 
197  void initializeContainer(int,LinearObjContainer & loc) const;
198 
204  void initializeContainer(int mem,EpetraLinearObjContainer & loc) const;
205 
211  void initializeGhostedContainer(int,LinearObjContainer & loc) const;
212 
218  void initializeGhostedContainer(int mem,EpetraLinearObjContainer & loc) const;
219 
220 /*************** Epetra based methods *******************/
221 
223  virtual const Teuchos::RCP<Epetra_Map> getMap() const;
224 
226  const Teuchos::RCP<Epetra_Map> getMap(int) const { return getMap(); }
227 
229  virtual const Teuchos::RCP<Epetra_Map> getColMap() const;
230 
231  virtual const Teuchos::RCP<Epetra_Map> getColMap(int) const { return getColMap(); }
232 
234  virtual const Teuchos::RCP<Epetra_Map> getGhostedMap() const;
235 
237  virtual const Teuchos::RCP<Epetra_Map> getGhostedMap(int) const { return getGhostedMap(); }
238 
240  virtual const Teuchos::RCP<Epetra_Map> getGhostedColMap() const;
241 
242  virtual const Teuchos::RCP<Epetra_Map> getGhostedColMap(int) const { return getGhostedColMap(); }
243 
245  virtual const Teuchos::RCP<Epetra_CrsGraph> getGraph() const;
246 
248  const Teuchos::RCP<Epetra_CrsGraph> getGraph(int,int) const { return getGraph(); }
249 
251  virtual const Teuchos::RCP<Epetra_CrsGraph> getGhostedGraph() const;
252 
253  const Teuchos::RCP<Epetra_CrsGraph> getGhostedGraph(int,int) const { return getGhostedGraph(); }
254 
256  virtual const Teuchos::RCP<Epetra_Import> getGhostedImport() const;
257 
258  virtual const Teuchos::RCP<Epetra_Import> getGhostedImport(int ) const { return getGhostedImport(); }
259 
261  virtual const Teuchos::RCP<Epetra_Import> getGhostedColImport() const;
262 
264  virtual const Teuchos::RCP<Epetra_Export> getGhostedExport() const;
265 
267  virtual const Teuchos::RCP<Epetra_Export> getGhostedColExport() const;
268 
270  virtual const Teuchos::RCP<const Epetra_Comm> getEpetraComm() const;
271 
274  { return colGidProvider_!=Teuchos::null ? colGidProvider_ : gidProvider_; }
275 
278  { return gidProvider_; }
279 
280 protected:
281  Teuchos::RCP<Epetra_Vector> getGhostedEpetraVector() const;
282  Teuchos::RCP<Epetra_Vector> getGhostedEpetraColVector() const;
283  Teuchos::RCP<Epetra_Vector> getEpetraVector() const;
284  Teuchos::RCP<Epetra_Vector> getEpetraColVector() const;
287 
288  void ghostToGlobalEpetraVector(const Epetra_Vector & in,Epetra_Vector & out,bool col=false) const;
289  void ghostToGlobalEpetraMatrix(const Epetra_CrsMatrix & in,Epetra_CrsMatrix & out) const;
290  void globalToGhostEpetraVector(const Epetra_Vector & in,Epetra_Vector & out,bool col=false) const;
291 
292  // get the map from the matrix
293  virtual const Teuchos::RCP<Epetra_Map> buildMap() const;
294  virtual const Teuchos::RCP<Epetra_Map> buildColMap() const;
295  virtual const Teuchos::RCP<Epetra_Map> buildGhostedMap() const;
296  virtual const Teuchos::RCP<Epetra_Map> buildGhostedColMap() const;
297 
298  // get the graph of the crs matrix
299  virtual const Teuchos::RCP<Epetra_CrsGraph> buildGraph() const;
300  virtual const Teuchos::RCP<Epetra_CrsGraph> buildGhostedGraph(bool optimizeStorage) const;
301 
302  // this method by defaults calls getGhostedGraph, however if the column global indexer
303  // is filtered (i.e. a Filtered_UniqueGlobalIndexer) then the filtered columns are removed
304  // in the version of the graph return by this. Note if the column UGI is filtered, then their
305  // will be substantial computational cost including communication in this method.
307 
308  // storage for Epetra graphs and maps
310  mutable Teuchos::RCP<Epetra_Map> map_;
311  mutable Teuchos::RCP<Epetra_Map> cMap_;
312  mutable Teuchos::RCP<Epetra_Map> ghostedMap_;
313  mutable Teuchos::RCP<Epetra_Map> cGhostedMap_;
314  mutable Teuchos::RCP<Epetra_CrsGraph> graph_;
315  mutable Teuchos::RCP<Epetra_CrsGraph> ghostedGraph_;
316 
317  // import/exporter storage
318  mutable Teuchos::RCP<Epetra_Import> importer_, colImporter_;
319  mutable Teuchos::RCP<Epetra_Export> exporter_, colExporter_;
320 
321  bool hasColProvider_;
325 
328 
329  bool useDiscreteAdjoint_;
330 };
331 
332 }
333 
334 #else
335 
337 
338 namespace panzer {
339 
340 template <typename Traits,typename LocalOrdinalT>
342 
343 }
344 
345 #endif
346 
347 #endif
void initializeContainer(int, LinearObjContainer &loc) const
Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > getDomainGlobalIndexer() const
Get the domain global indexer object associated with this factory.
Teuchos::RCP< Thyra::LinearOpBase< double > > getThyraMatrix() const
Get a Thyra operator.
virtual const Teuchos::RCP< Epetra_Map > buildColMap(int i) const
Build the i-th owned column map from the owned indices of the i-th (column) global indexer...
Teuchos::RCP< Epetra_CrsMatrix > getEpetraMatrix(int i, int j) const
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveLinearObjContainer() const
virtual const Teuchos::RCP< Epetra_Export > getGhostedColExport(int j) const
get exporter for converting an overalapped object to a "normal" object
virtual const Teuchos::RCP< Epetra_Map > getGhostedColMap(int i) const
get the ghosted map from the matrix
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherDomain() const
Use preconstructed gather evaluators.
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > domainSpace_
Teuchos::RCP< panzer::CloneableEvaluator > buildScatter() const
Use preconstructed scatter evaluators.
virtual const Teuchos::RCP< Epetra_Map > buildGhostedMap(int i) const
Build the i-th ghosted map from the owned and ghosted indices of the i-th global indexer.
Teuchos::RCP< panzer::CloneableEvaluator > buildGather() const
Use preconstructed gather evaluators.
virtual void adjustForDirichletConditions(const LinearObjContainer &localBCRows, const LinearObjContainer &globalBCRows, LinearObjContainer &ghostedObjs, bool zeroVectorRows=false, bool adjustX=false) const
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > rangeSpace_
Teuchos::RCP< const panzer::UniqueGlobalIndexerBase > getRangeGlobalIndexer() const
Get the range global indexer object associated with this factory.
virtual const Teuchos::RCP< Epetra_CrsGraph > getGhostedGraph(int i, int j) const
get the ghosted graph of the crs matrix
virtual const Teuchos::RCP< Epetra_CrsGraph > buildGraph(int i, int j) const
virtual void ghostToGlobalContainer(const LinearObjContainer &ghostContainer, LinearObjContainer &container, int) const
Teuchos::RCP< Epetra_CrsMatrix > getGhostedEpetraMatrix(int i, int j) const
virtual const Teuchos::RCP< Epetra_CrsGraph > buildFilteredGhostedGraph(int i, int j) const
BlockedEpetraLinearObjFactory< Traits, LocalOrdinalT > EpetraLinearObjFactory
virtual const Teuchos::RCP< Epetra_Map > getMap(int i) const
get the map from the matrix
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Teuchos::OpaqueWrapper< MPI_Comm > > rawMpiComm_
virtual const Teuchos::RCP< Epetra_CrsGraph > buildGhostedGraph(int i, int j, bool optimizeStorage) const
virtual const Teuchos::RCP< Epetra_Import > getGhostedImport(int i) const
get importer for converting an overalapped object to a "normal" object
virtual const Teuchos::RCP< const Epetra_Comm > getEpetraComm() const
get exporter for converting an overalapped object to a "normal" object
void ghostToGlobalEpetraMatrix(int blockRow, const Epetra_CrsMatrix &in, Epetra_CrsMatrix &out) const
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherTangent() const
Use preconstructed gather evaluators.
virtual void globalToGhostContainer(const LinearObjContainer &container, LinearObjContainer &ghostContainer, int) const
virtual const Teuchos::RCP< Epetra_Import > getGhostedColImport(int i) const
get importer for converting an overalapped object to a "normal" object
void ghostToGlobalEpetraVector(int i, const Epetra_Vector &in, Epetra_Vector &out, bool col) const
virtual const Teuchos::RCP< Epetra_Map > getColMap(int i) const
get the map from the matrix
Teuchos::RCP< panzer::CloneableEvaluator > buildScatterDirichlet() const
Use preconstructed dirichlet scatter evaluators.
virtual const Teuchos::RCP< Epetra_CrsGraph > getGraph(int i, int j) const
get the graph of the crs matrix
virtual const Teuchos::RCP< Epetra_Export > getGhostedExport(int j) const
get exporter for converting an overalapped object to a "normal" object
Teuchos::RCP< const Teuchos::Comm< int > > comm
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > getThyraDomainSpace() const
Get the domain vector space (x and dxdt)
virtual const Teuchos::RCP< Epetra_Map > getGhostedMap(int i) const
get the ghosted map from the matrix
virtual void writeVector(const std::string &identifier, const LinearObjContainer &loc, int id) const
Teuchos::RCP< const Thyra::VectorSpaceBase< double > > getThyraRangeSpace() const
Get the range vector space (f)
virtual Teuchos::RCP< LinearObjContainer > buildGhostedLinearObjContainer() const
virtual Teuchos::RCP< ReadOnlyVector_GlobalEvaluationData > buildReadOnlyDomainContainer() const
virtual Teuchos::RCP< LinearObjContainer > buildLinearObjContainer() const
void globalToGhostEpetraVector(int i, const Epetra_Vector &in, Epetra_Vector &out, bool col) const
virtual Teuchos::RCP< WriteVector_GlobalEvaluationData > buildWriteDomainContainer() const
virtual void readVector(const std::string &identifier, LinearObjContainer &loc, int id) const
virtual const Teuchos::RCP< Epetra_Map > buildMap(int i) const
Build the i-th owned map from the owned indices of the i-th global indexer.
void initializeGhostedContainer(int, LinearObjContainer &loc) const
virtual void applyDirichletBCs(const LinearObjContainer &counter, LinearObjContainer &result) const
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveGhostedLinearObjContainer() const
Teuchos::RCP< panzer::CloneableEvaluator > buildGatherOrientation() const
Use preconstructed gather evaluators.