Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_DOFManagerFEI_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_DOFManagerFEI_decl_hpp__
44 #define __Panzer_DOFManagerFEI_decl_hpp__
45 
46 #include "PanzerDofMgr_config.hpp"
47 
48 #ifdef PANZER_HAVE_FEI
49 
50 #include <map>
51 
52 // FEI includes
53 #include "fei_base.hpp"
54 #include "fei_Factory.hpp"
55 
56 #ifdef HAVE_MPI
57  #include "mpi.h"
58 #endif
59 
60 #include "Panzer_FieldPattern.hpp"
62 #include "Panzer_ConnManager.hpp"
64 #include "Panzer_HashUtils.hpp"
65 
66 #include "Teuchos_RCP.hpp"
68 
69 #include <unordered_set>
70 
71 namespace panzer {
72 
73 template <typename LocalOrdinalT,typename GlobalOrdinalT>
74 class DOFManagerFEI : public UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> {
75 public:
76  typedef GlobalOrdinalT GlobalOrdinal;
77  typedef LocalOrdinalT LocalOrdinal;
78  typedef std::map<int,std::string>::const_iterator const_field_iterator;
79 
80  virtual ~DOFManagerFEI() {}
81 
82  DOFManagerFEI();
83 
88  DOFManagerFEI(const Teuchos::RCP<ConnManager<LocalOrdinalT,GlobalOrdinalT> > & connMngr,MPI_Comm mpiComm);
89 
101  void setConnManager(const Teuchos::RCP<ConnManager<LocalOrdinalT,GlobalOrdinalT> > & connMngr,MPI_Comm mpiComm);
102 
105  virtual Teuchos::RCP<Teuchos::Comm<int> > getComm() const
106  { return communicator_; }
107 
111  Teuchos::RCP<const FieldPattern> getGeometricFieldPattern() const
112  { return geomPattern_; }
113 
114 
124 
137  void addField(const std::string & str,const Teuchos::RCP<const FieldPattern> & pattern);
138 
139  void addField(const std::string & blockId,const std::string & str,const Teuchos::RCP<const FieldPattern> & pattern);
140 
149  void setFieldOrder(const std::vector<int> & fieldOrder);
150 
159  void setFieldOrder(const std::vector<std::string> & fieldOrder);
160 
163  void getFieldOrder(std::vector<int> & fieldOrder) const;
164 
167  void getFieldOrder(std::vector<std::string> & fieldOrder) const;
168 
182  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & blockId, int fieldNum) const;
183 
197  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & blockId, const std::string & fieldName) const;
198 
213  int getFieldNum(const std::string & str) const;
214 
224  const std::string & getFieldString(int num) const
225  { return intToFieldStr_.find(num)->second; }
226 
234  int getNumFields() const;
235 
239  { return connMngr_; }
240 
241  virtual Teuchos::RCP<const ConnManagerBase<LocalOrdinalT> > getConnManagerBase() const
242  { return getConnManager(); }
243 
250  virtual void buildGlobalUnknowns();
251 
268  virtual void buildGlobalUnknowns(const Teuchos::RCP<const FieldPattern> & geomPattern);
269 
274  virtual void buildUnknownsOrientation();
275 
279  void printFieldInformation(std::ostream & os) const;
280 
282  //{@
283 
286  virtual void getElementBlockIds(std::vector<std::string> & elementBlockIds) const
287  { getConnManager()->getElementBlockIds(elementBlockIds); }
288 
291  virtual const std::vector<int> & getBlockFieldNumbers(const std::string & block) const
292  { return fieldAggPattern_.find(block)->second->fieldIds(); }
293 
296  virtual bool fieldInBlock(const std::string & field, const std::string & block) const
297  { return fieldStringToPattern_.find(std::make_pair(block,field))->second != Teuchos::null; }
298 
306  virtual const std::vector<LocalOrdinal> & getElementBlock(const std::string & blockId) const
307  { return getConnManager()->getElementBlock(blockId); }
308 
312  void getElementGIDs(LocalOrdinalT localElmtId,std::vector<GlobalOrdinalT> & gids,const std::string & blockIdHint="") const;
313 
316  virtual void getElementOrientation(LocalOrdinalT localElmtId,std::vector<double> & gidsOrientation) const;
317 
321  const std::vector<int> & getGIDFieldOffsets(const std::string & blockId,int fieldNum) const
322  { return fieldAggPattern_.find(blockId)->second->localOffsets(fieldNum); }
323 
338  const std::pair<std::vector<int>,std::vector<int> > &
339  getGIDFieldOffsets_closure(const std::string & blockId,int fieldNum,int subcellDim,int subcellId) const
340  { return fieldAggPattern_.find(blockId)->second->localOffsets_closure(fieldNum,subcellDim,subcellId); }
341 
343 
348  const_field_iterator beginFieldIter() const
349  { return intToFieldStr_.begin(); }
350 
355  const_field_iterator endFieldIter() const
356  { return intToFieldStr_.end(); }
357 
360  virtual void getOwnedIndices(std::vector<GlobalOrdinalT> & indices) const;
361 
365  virtual void getOwnedAndSharedIndices(std::vector<GlobalOrdinalT> & indices) const;
366 
369  virtual void ownedIndices(const std::vector<GlobalOrdinalT> & indices,std::vector<bool> & isOwned) const;
370 
373  const std::set<int> & getFields(const std::string & blockId) const
374  { return blockToField_.find(blockId)->second; }
375 
384  bool validFieldOrder(const std::vector<std::string> & fieldOrder_ut,const std::set<std::string> & fields) const;
385 
389  void registerFields();
390 
393  virtual int getElementBlockGIDCount(const std::string & blockId) const
394  { return getElementBlockGIDCount(blockIdToIndex(blockId)); }
395 
398  virtual int getElementBlockGIDCount(const std::size_t & blockIndex) const
399  { int cnt = matrixGraph_->getConnectivityNumIndices(blockIndex);
400  if(cnt<0)
401  return 0;
402  return cnt;
403  }
404 
407  bool getOrientationsRequired() const
408  { return requireOrientations_; }
409 
412  void setOrientationsRequired(bool ro)
413  { requireOrientations_ = ro; }
414 
415 protected:
416 
420  void getOrderedBlock(const std::vector<std::string> & fieldOrder,
421  const std::string & blockId,
422  std::vector<int> & orderedBlock) const;
423 
427  std::size_t blockIdToIndex(const std::string & blockId) const;
428 
431  const std::map<std::string,std::size_t> & blockIdToIndexMap() const;
432 
434  bool buildPattern(const std::vector<std::string> & fieldOrder,
435  const std::string & blockId);
436 
437  // computes connectivity
439 
441 
442  std::map<std::string,int> fieldStrToInt_;
444  std::map<int,std::string> intToFieldStr_;
445 
447  std::map<std::pair<std::string,std::string>,Teuchos::RCP<const FieldPattern> > fieldStringToPattern_;
448 
450  std::map<std::pair<std::string,int>,Teuchos::RCP<const FieldPattern> > fieldIntToPattern_;
451 
453  std::map<std::string,Teuchos::RCP<FieldAggPattern> > fieldAggPattern_;
454 
456  std::map<std::string,std::set<int> > blockToField_; // help define the pattern
458 
459  // FEI based DOF management stuff
460  Teuchos::RCP<fei::Factory> feiFactory_;
461  fei::SharedPtr<fei::VectorSpace> vectorSpace_;
462  fei::SharedPtr<fei::MatrixGraph> matrixGraph_;
463 
464  // map from a field to a vector of local element IDs
465  std::map<int,std::vector<int> > field2ElmtIDs_;
466 
467  // storage for fast lookups of GID ownership
468  std::unordered_set<GlobalOrdinal> ownedGIDHashTable_;
469 
470  // maps blockIds to indices
471  mutable Teuchos::RCP<std::map<std::string,std::size_t> > blockIdToIndex_;
472 
473  std::vector<std::string> fieldOrder_;
474 
475  // counters
476  int nodeType_;
477  int edgeType_;
478  int numFields_;
479  std::vector<int> patternNum_;
480 
481  bool fieldsRegistered_;
482 
484  Teuchos::RCP<Teuchos::MpiComm<int> > communicator_;
485 
486  bool requireOrientations_;
487  // this vector will be # of local elements, by number of GIDs on element block
488  std::vector<std::vector<char> > orientation_; // we are using chars here
489  // to minimize storage and also
490  // we need only to store +/-1
491 };
492 
493 }
494 
495 #endif
496 #endif
PHX::MDField< const ScalarT, Cell, IP > field