Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_SGEpetraLinearObjFactory_impl.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_SG_EPETRA_LINEAR_OBJ_FACTORY_IMPL_HPP
44 #define PANZER_SG_EPETRA_LINEAR_OBJ_FACTORY_IMPL_HPP
45 
46 #ifdef HAVE_STOKHOS
47 
48 #include "EpetraExt_BlockUtility.h"
49 #include "Epetra_LocalMap.h"
50 
51 namespace panzer {
52 
53 template <typename Traits,typename LocalOrdinalT>
57  const Teuchos::RCP<const EpetraExt::MultiComm> & globalMultiComm)
58  : epetraFact_(epetraFact), expansion_(expansion), globalMultiComm_(globalMultiComm)
59 {
60  // build and register the gather/scatter evaluators with
61  // the base class.
62  this->buildGatherScatterEvaluators(*this);
63 }
64 
65 template <typename Traits,typename LocalOrdinalT>
68 {
69 }
70 
71 template <typename Traits,typename LocalOrdinalT>
75 {
77  for(int i=0;i<expansion_->size();i++) {
79  Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(buildPrimitiveLinearObjContainer());
80  coeffContainers.push_back(eCont);
81  }
82 
83  return Teuchos::rcp(new SGEpetraLinearObjContainer(coeffContainers,expansion_));
84 }
85 
86 template <typename Traits,typename LocalOrdinalT>
90 {
91  return epetraFact_->buildLinearObjContainer();
92 }
93 
94 template <typename Traits,typename LocalOrdinalT>
98 {
100  for(int i=0;i<expansion_->size();i++) {
102  Teuchos::rcp_dynamic_cast<EpetraLinearObjContainer>(buildPrimitiveGhostedLinearObjContainer());
103  coeffContainers.push_back(eCont);
104  }
105 
106  return Teuchos::rcp(new SGEpetraLinearObjContainer(coeffContainers,expansion_));
107 }
108 
109 template <typename Traits,typename LocalOrdinalT>
113 {
114  return epetraFact_->buildGhostedLinearObjContainer();
115 }
116 
117 template <typename Traits,typename LocalOrdinalT>
118 void
120 ::globalToGhostContainer(const LinearObjContainer & container,LinearObjContainer & ghostContainer,int mem) const
121 {
122  bool completed = false;
123  try {
124  const SGEpetraLinearObjContainer & containerSG = dynamic_cast<const SGEpetraLinearObjContainer&>(container);
125  SGEpetraLinearObjContainer & ghostContainerSG = dynamic_cast<SGEpetraLinearObjContainer&>(ghostContainer);
126 
127  // simply iterate over each deterministic system and run global to ghost
130  for(inItr=containerSG.begin(),outItr=ghostContainerSG.begin();
131  inItr!=containerSG.end();inItr++,outItr++) {
132  epetraFact_->globalToGhostContainer(**inItr,**outItr,mem);
133  }
134 
135  completed = true;
136  }
137  catch(const std::bad_cast & bad_cast) { }
138 
139  // type was not a SGEpetraLinearObjContainer, try the Epetra type
140  if(!completed) {
141  // this had many perils, primarily that the exception will come
142  // from the epetra factory.
143  epetraFact_->globalToGhostContainer(container,ghostContainer,mem);
144  }
145 }
146 
147 template <typename Traits,typename LocalOrdinalT>
148 void
150 ::ghostToGlobalContainer(const LinearObjContainer & ghostContainer, LinearObjContainer & container,int mem) const
151 {
152  bool completed = false;
153  try {
154  SGEpetraLinearObjContainer & containerSG = dynamic_cast<SGEpetraLinearObjContainer&>(container);
155  const SGEpetraLinearObjContainer & ghostContainerSG = dynamic_cast<const SGEpetraLinearObjContainer&>(ghostContainer);
156 
157  // simply iterate over each deterministic system and run ghost to global
160  for(inItr=ghostContainerSG.begin(),outItr=containerSG.begin();
161  inItr!=ghostContainerSG.end();inItr++,outItr++) {
162  epetraFact_->ghostToGlobalContainer(**inItr,**outItr,mem);
163  }
164 
165  completed = true;
166  }
167  catch(const std::bad_cast & bad_cast) { }
168 
169  // type was not a SGEpetraLinearObjContainer, try the Epetra type
170  if(!completed) {
171  // this had many perils, primarily that the exception will come
172  // from the epetra factory.
173  epetraFact_->ghostToGlobalContainer(ghostContainer,container,mem);
174  }
175 }
176 
177 template <typename Traits,typename LocalOrdinalT>
180  const LinearObjContainer & globalBCRows,
181  LinearObjContainer & ghostedObjs,
182  bool zeroVectorRows, bool adjustX) const
183 {
184  bool completed = false;
185  try {
186  SGEpetraLinearObjContainer & ghostContainerSG = dynamic_cast<SGEpetraLinearObjContainer&>(ghostedObjs);
187 
188  // simply iterate over each deterministic system and run adjustForDirichlet
190  for(ghostObjsItr=ghostContainerSG.begin();ghostObjsItr!=ghostContainerSG.end();ghostObjsItr++)
191  epetraFact_->adjustForDirichletConditions(localBCRows,globalBCRows,**ghostObjsItr,zeroVectorRows);
192 
193  completed = true;
194  }
195  catch(const std::bad_cast & bad_cast) { }
196 
197  // type was not a SGEpetraLinearObjContainer, try the Epetra type
198  if(!completed) {
199  // this had many perils, primarily that the exception will come
200  // from the epetra factory.
201  epetraFact_->adjustForDirichletConditions(localBCRows,globalBCRows,ghostedObjs,zeroVectorRows);
202  }
203 }
204 
205 template <typename Traits,typename LocalOrdinalT>
208  LinearObjContainer & result) const
209 {
210  TEUCHOS_ASSERT(false); // not yet implemented
211 }
212 
213 template <typename Traits,typename LocalOrdinalT>
215 getComm() const
216 {
217  return epetraFact_->getComm();
218 }
219 
220 template <typename Traits,typename LocalOrdinalT>
223 {
224  bool completed = false;
225  try {
226  SGEpetraLinearObjContainer & eloc = dynamic_cast<SGEpetraLinearObjContainer&>(loc);
227 
229  for(itr=eloc.begin();itr!=eloc.end();++itr)
230  epetraFact_->initializeContainer(mem,**itr);
231 
232  completed = true;
233  }
234  catch(const std::bad_cast & bad_cast) { }
235 
236  // type was not a SGEpetraLinearObjContainer, try the Epetra type
237  if(!completed) {
238  // this has many perils, primarily that the exception will come
239  // from the epetra factory.
240  epetraFact_->initializeContainer(mem,loc);
241  }
242 }
243 
244 template <typename Traits,typename LocalOrdinalT>
245 void
248 {
249  bool completed = false;
250  try {
251  SGEpetraLinearObjContainer & eloc = dynamic_cast<SGEpetraLinearObjContainer&>(loc);
252 
254  for(itr=eloc.begin();itr!=eloc.end();++itr)
255  epetraFact_->initializeGhostedContainer(mem,**itr);
256 
257  completed = true;
258  }
259  catch(const std::bad_cast & bad_cast) { }
260 
261  // type was not a SGEpetraLinearObjContainer, try the Epetra type
262  if(!completed) {
263  // this has many perils, primarily that the exception will come
264  // from the epetra factory.
265  epetraFact_->initializeGhostedContainer(mem,loc);
266  }
267 }
268 
269 template <typename Traits,typename LocalOrdinalT>
272 {
273  Teuchos::RCP<const Epetra_Map> blockMap = getSGBlockMap();
274  Teuchos::RCP<Epetra_Map> epMap = epetraFact_->getMap();
275  return Teuchos::rcp(new Stokhos::EpetraVectorOrthogPoly(expansion_->getBasis(),blockMap,epMap,globalMultiComm_));
276 }
277 
278 template <typename Traits,typename LocalOrdinalT>
281 {
282  Teuchos::RCP<const Epetra_Map> blockMap = getSGBlockMap();
283  Teuchos::RCP<Epetra_Map> epMap = epetraFact_->getMap();
284  return Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(*epMap,*blockMap,*epetraFact_->getEpetraComm()));
285 }
286 
287 template <typename Traits,typename LocalOrdinalT>
290 {
291  if(sgBlockMap_==Teuchos::null)
292  sgBlockMap_ = Teuchos::rcp(new Epetra_LocalMap(expansion_->getBasis()->size(), 0, *epetraFact_->getEpetraComm()));
293  return sgBlockMap_;
294 }
295 
296 }
297 
298 #endif
299 
300 #endif
std::vector< Teuchos::RCP< EpetraLinearObjContainer > > CoeffVector
virtual void applyDirichletBCs(const LinearObjContainer &counter, LinearObjContainer &result) const
virtual Teuchos::MpiComm< int > getComm() const
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveLinearObjContainer() const
virtual void adjustForDirichletConditions(const LinearObjContainer &localBCRows, const LinearObjContainer &globalBCRows, LinearObjContainer &ghostedObjs, bool zeroVectorRows=false, bool adjustX=false) const
void initializeGhostedContainer(int mem, LinearObjContainer &loc) const
void initializeContainer(int mem, LinearObjContainer &loc) const
Teuchos::RCP< const Epetra_Map > getSGBlockMap() const
get the block map needed by Stokhos to describe the parallel layout of the SG unknowns ...
virtual Teuchos::RCP< LinearObjContainer > buildPrimitiveGhostedLinearObjContainer() const
virtual void ghostToGlobalContainer(const LinearObjContainer &ghostContainer, LinearObjContainer &container, int mem) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
SGEpetraLinearObjFactory(const Teuchos::RCP< EpetraLinearObjFactory< Traits, LocalOrdinalT > > &epetraFact, const Teuchos::RCP< Stokhos::OrthogPolyExpansion< int, double > > &expansion, const Teuchos::RCP< const EpetraExt::MultiComm > &globalMultiComm)
Teuchos::RCP< const Epetra_Map > getMap()
get the map from the matrix, this is the map for the solution vector
virtual Teuchos::RCP< LinearObjContainer > buildGhostedLinearObjContainer() const
virtual void globalToGhostContainer(const LinearObjContainer &container, LinearObjContainer &ghostContainer, int mem) const
virtual Teuchos::RCP< LinearObjContainer > buildLinearObjContainer() const
static Epetra_Map * GenerateBlockMap(const Epetra_BlockMap &BaseMap, const int *RowIndices, int num_indices, const Epetra_Comm &GlobalComm, int Offset=0)
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > getVectorOrthogPoly() const
Set orthog poly object, this serves as a template for converting vectors to block vectors...