Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_BlockedDOFManager.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_BlockedDOFManager_hpp__
44 #define __Panzer_BlockedDOFManager_hpp__
45 
46 #include <map>
47 #include <set>
48 
49 #ifdef HAVE_MPI
50  #include <mpi.h>
51 #endif
52 
53 #include "PanzerDofMgr_config.hpp"
54 #include "Panzer_FieldPattern.hpp"
56 #include "Panzer_ConnManager.hpp"
57 #include "Panzer_GlobalIndexer.hpp"
58 #include "Panzer_DOFManager.hpp"
59 #include "Panzer_NodeType.hpp"
60 #include "Panzer_HashUtils.hpp"
61 
62 #include "Teuchos_RCP.hpp"
64 
65 #include <unordered_set>
66 
67 namespace panzer {
68 
70 public:
71  // typedef std::pair<int,GlobalOrdinalT> GlobalOrdinal;
72  using GlobalOrdinal = panzer::GlobalOrdinal;
73  using LocalOrdinal = panzer::LocalOrdinal;
74  using const_field_iterator = std::map<int,std::string>::const_iterator;
75 
76  virtual ~BlockedDOFManager() {}
77 
79 
84  BlockedDOFManager(const Teuchos::RCP<ConnManager> & connMngr,MPI_Comm mpiComm);
85 
89 
90 
94  { return communicator_; }
95 
110  int getFieldNum(const std::string & str) const; // ?
111 
125  const std::string & getFieldString(int num) const;
126 
129  virtual void getElementBlockIds(std::vector<std::string> & elementBlockIds) const
130  { getConnManager()->getElementBlockIds(elementBlockIds); }
131 
134  virtual bool fieldInBlock(const std::string & field, const std::string & block) const; // ?
135 
143  virtual const std::vector<LocalOrdinal> & getElementBlock(const std::string & blockId) const // ?
144  { return getConnManager()->getElementBlock(blockId); }
145 
148  virtual const std::vector<int> & getBlockFieldNumbers(const std::string & block) const; // ?
149 
153  void getElementGIDs(panzer::LocalOrdinal localElmtId,std::vector<GlobalOrdinal> & gids,const std::string & blockIdHint="") const; // ?
154 
168  void getElementGIDsPair(panzer::LocalOrdinal localElmtId,std::vector<std::pair<int,GlobalOrdinal>> & gids,const std::string & blockIdHint="") const;
169 
172  virtual void getElementOrientation(panzer::LocalOrdinal localElmtId,std::vector<double> & gidsOrientation) const; // ?
173 
177  virtual const std::vector<int> & getGIDFieldOffsets(const std::string & blockId,int fieldNum) const; // ?
178 
193  virtual const std::pair<std::vector<int>,std::vector<int> > &
194  getGIDFieldOffsets_closure(const std::string & blockId,int fieldNum,int subcellDim,int subcellId) const; // ?
195 
202  virtual void getOwnedIndices(std::vector<GlobalOrdinal>& indices) const;
203 
210  virtual void
211  getGhostedIndices(std::vector<GlobalOrdinal>& indices) const;
212 
219  virtual void
220  getOwnedAndGhostedIndices(std::vector<GlobalOrdinal>& indices) const;
221 
222  // For backwards compatibility with Epetra. Will be deprecated.
223  void getElementGIDsAsInt(panzer::LocalOrdinal localElmtId,std::vector<int> & gids,const std::string & blockIdHint="") const;
224  virtual void getOwnedIndicesAsInt(std::vector<int>& indices) const;
225  virtual void getGhostedIndicesAsInt(std::vector<int>& indices) const;
226  virtual void getOwnedAndGhostedIndicesAsInt(std::vector<int>& indices) const;
227 
233  virtual int
234  getNumOwned() const;
235 
241  virtual int
242  getNumGhosted() const;
243 
249  virtual int
250  getNumOwnedAndGhosted() const;
251 
254  virtual void ownedIndices(const std::vector<GlobalOrdinal> & indices,std::vector<bool> & isOwned) const; // ?
255 
257 
262  void setUseDOFManagerFEI(bool useFEI)
263  { useDOFManagerFEI_ = useFEI; }
264 
267  bool getUseDOFManagerFEI() const
268  {
269  return false;
270  }
271 
283  void setConnManager(const Teuchos::RCP<ConnManager> & connMngr,MPI_Comm mpiComm);
284 
285 
290  { return geomPattern_; }
291 
301 
314  void addField(const std::string & str,const Teuchos::RCP<const FieldPattern> & pattern);
315 
316  void addField(const std::string & blockId,const std::string & str,const Teuchos::RCP<const FieldPattern> & pattern);
317 
326  void setFieldOrder(const std::vector<std::vector<std::string> > & fieldOrder);
327 
331  int getNumFieldBlocks() const;
332 
335  void getFieldOrder(std::vector<std::vector<std::string> > & fieldOrder) const;
336 
337  void getFieldOrder(std::vector<std::string>& /* fieldOrder */) const { TEUCHOS_ASSERT(false); } // what???
338 
352  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & blockId, const std::string & fieldName) const; // ?
353 
361  int getNumFields() const; // ?
362 
366  { return connMngr_; }
367 
371  { return connMngr_; }
372 
379  virtual void buildGlobalUnknowns();
380 
397  virtual void buildGlobalUnknowns(const Teuchos::RCP<const FieldPattern> & geomPattern);
398 
406  virtual void buildGlobalUnknowns(const std::vector<Teuchos::RCP<GlobalIndexer>> & fieldBlockManagers);
407 
411  void printFieldInformation(std::ostream & os) const; // ?
412 
421  bool validFieldOrder(const std::vector<std::vector<std::string> > & fieldOrder_ut,const std::set<std::string> & fields) const;
422 
426  void registerFields(bool buildSubUGIs);
427 
430  bool fieldsRegistered() const
431  { return fieldsRegistered_; }
432 
436  const std::vector<Teuchos::RCP<GlobalIndexer>> &
438  { return fieldBlockManagers_; }
439 
443  inline int getMaxSubFieldNumber() const
444  { return maxSubFieldNum_; }
445 
450  int getFieldBlock(int fieldNum) const
451  { return fieldNumToFieldBlk_.find(fieldNum)->second; }
452 
457  int getBlockGIDOffset(const std::string & elementBlock,int fieldBlock) const
458  {
459  std::map<std::pair<std::string,int>,int>::const_iterator itr =
460  blockGIDOffset_.find(std::make_pair(elementBlock,fieldBlock));
461 
462  if(itr==blockGIDOffset_.end())
463  return -1;
464  else
465  return itr->second;
466  }
467 
471  { return requireOrientations_; }
472 
476  { requireOrientations_ = ro; }
477 
480  void enableTieBreak(bool useTieBreak)
481  { useTieBreak_ = useTieBreak; }
482 
488  virtual int getElementBlockGIDCount(const std::string & blockId) const;
489 
495  virtual int getElementBlockGIDCount(const std::size_t & blockIndex) const;
496 
497 protected:
498 
502  MPI_Comm mpiComm) const;
503 
506  void setOrientationsRequired(const Teuchos::RCP<GlobalIndexer> & indexer,bool required) const;
507 
510  void buildGlobalUnknowns(const Teuchos::RCP<GlobalIndexer> & indexer,const Teuchos::RCP<const FieldPattern> & geomPattern) const;
511 
514  int getElementBlockGIDCount(const Teuchos::RCP<GlobalIndexer> & indexer,const std::string & elementBlock) const;
515 
518  int getElementBlockGIDCount(const Teuchos::RCP<GlobalIndexer> & indexer,const std::size_t & blockIndex) const;
519 
522  void printFieldInformation(const Teuchos::RCP<GlobalIndexer> & indexer,std::ostream & os) const;
523 
529  void addFieldsToFieldBlockManager(const std::vector<std::string> & activeFields,
530  GlobalIndexer & fieldBlockManager) const;
531 
537  void addFieldsToFieldBlockManager(const std::vector<std::string> & activeFields,
538  DOFManager & fieldBlockManager) const;
539 
540  // computes connectivity
542 
544 
545  std::map<std::string,int> fieldStrToNum_;
547 
549  std::map<int,std::string> fieldNumToStr_;
550 
552  std::map<int,int> fieldNumToFieldBlk_;
553 
555  std::map<std::pair<std::string,std::string>,Teuchos::RCP<const FieldPattern> > fieldStringToPattern_;
556 
558  std::map<std::string,std::set<std::string> > blockIdToFieldStrings_;
559 
561  std::map<std::string,std::vector<int> > blockIdToFieldNumbers_;
562 
564  std::map<std::pair<std::string,int>,int> blockGIDOffset_;
565 
567 
568  // storage for fast lookups of GID ownership
569  //std::unordered_set<GlobalOrdinal,panzer::pair_hash> ownedGIDHashTable_;
570 
571  std::vector<std::vector<std::string> > fieldOrder_;
572 
574 
577 
578  std::vector<Teuchos::RCP<GlobalIndexer>> fieldBlockManagers_;
579 
580  MPI_Comm mpiComm_;
582 
586  mutable std::map<std::string,std::map<int,std::vector<int> > > gidFieldOffsets_;
587 
588  struct LessThan
589  { bool operator()(const Teuchos::Tuple<int,3> & a,const Teuchos::Tuple<int,3> & b) const; };
590  typedef std::map<Teuchos::Tuple<int,3>, std::pair<std::vector<int>,std::vector<int> >,LessThan> TupleToVectorPairMap;
591 
595  mutable std::map<std::string,TupleToVectorPairMap> gidFieldOffsets_closure_;
596 
598 
601 };
602 
603 }
604 
605 #endif
virtual const std::vector< int > & getGIDFieldOffsets(const std::string &blockId, int fieldNum) const
Use the field pattern so that you can find a particular field in the GIDs array.
void setUseDOFManagerFEI(bool useFEI)
Use the FEI DOF manager internally, or the standard version.
virtual void getGhostedIndices(std::vector< GlobalOrdinal > &indices) const
Get the set of indices ghosted for this processor.
virtual const std::vector< LocalOrdinal > & getElementBlock(const std::string &blockId) const
void enableTieBreak(bool useTieBreak)
std::map< std::string, TupleToVectorPairMap > gidFieldOffsets_closure_
bool operator()(const Teuchos::Tuple< int, 3 > &a, const Teuchos::Tuple< int, 3 > &b) const
Teuchos::RCP< GlobalIndexer > buildNewIndexer(const Teuchos::RCP< ConnManager > &connManager, MPI_Comm mpiComm) const
void getFieldOrder(std::vector< std::vector< std::string > > &fieldOrder) const
Teuchos::RCP< const FieldPattern > getFieldPattern(const std::string &blockId, const std::string &fieldName) const
Find a field pattern stored for a particular block and field number. This will retrive the pattern ad...
int getFieldNum(const std::string &str) const
Get the number used for access to this field.
virtual void getOwnedIndices(std::vector< GlobalOrdinal > &indices) const
Get the set of indices owned by this processor.
const std::vector< Teuchos::RCP< GlobalIndexer > > & getFieldDOFManagers() const
virtual void getElementOrientation(panzer::LocalOrdinal localElmtId, std::vector< double > &gidsOrientation) const
Get a vector containg the orientation of the GIDs relative to the neighbors.
std::vector< Teuchos::RCP< GlobalIndexer > > fieldBlockManagers_
virtual int getNumGhosted() const
Get the number of indices ghosted for this processor.
int getNumFields() const
How many fields are handled by this manager.
virtual bool fieldInBlock(const std::string &field, const std::string &block) const
Teuchos::RCP< ConnManager > getConnManager()
virtual void ownedIndices(const std::vector< GlobalOrdinal > &indices, std::vector< bool > &isOwned) const
std::map< int, std::string >::const_iterator const_field_iterator
virtual const std::vector< int > & getBlockFieldNumbers(const std::string &block) const
std::map< std::string, std::set< std::string > > blockIdToFieldStrings_
block ID ==&gt; field strings
std::map< int, int > fieldNumToFieldBlk_
field number ==&gt; field block
void setConnManager(const Teuchos::RCP< ConnManager > &connMngr, MPI_Comm mpiComm)
Set the connection manager and MPI_Comm objects.
virtual void getOwnedAndGhostedIndices(std::vector< GlobalOrdinal > &indices) const
Get the set of owned and ghosted indices for this processor.
const std::string & getFieldString(int num) const
Get the string name associated with a field number.
virtual void getElementBlockIds(std::vector< std::string > &elementBlockIds) const
bool validFieldOrder(const std::vector< std::vector< std::string > > &fieldOrder_ut, const std::set< std::string > &fields) const
int getBlockGIDOffset(const std::string &elementBlock, int fieldBlock) const
void getElementGIDs(panzer::LocalOrdinal localElmtId, std::vector< GlobalOrdinal > &gids, const std::string &blockIdHint="") const
Get the global IDs for a particular element. This function overwrites the gids variable.
virtual void getOwnedIndicesAsInt(std::vector< int > &indices) const
Get the set of indices owned by this processor.
std::map< std::string, std::map< int, std::vector< int > > > gidFieldOffsets_
Teuchos::RCP< const ConnManager > getConnManager() const
Teuchos::RCP< ConnManager > resetIndices()
Reset the indicies for this DOF manager.
void getElementGIDsPair(panzer::LocalOrdinal localElmtId, std::vector< std::pair< int, GlobalOrdinal >> &gids, const std::string &blockIdHint="") const
Get the global IDs for a particular element. This function overwrites the gids variable.
std::map< std::string, int > fieldStrToNum_
field string ==&gt; field number
Teuchos::RCP< Teuchos::MpiComm< int > > communicator_
virtual Teuchos::RCP< Teuchos::Comm< int > > getComm() const
virtual int getNumOwned() const
Get the number of indices owned by this processor.
std::vector< std::vector< std::string > > fieldOrder_
void printFieldInformation(std::ostream &os) const
void getElementGIDsAsInt(panzer::LocalOrdinal localElmtId, std::vector< int > &gids, const std::string &blockIdHint="") const
Get the global IDs for a particular element. This function overwrites the gids variable.
virtual int getElementBlockGIDCount(const std::string &blockId) const
How any GIDs are associate with a particular element block.
virtual void getGhostedIndicesAsInt(std::vector< int > &indices) const
Get the set of indices ghosted for this processor.
Teuchos::RCP< const FieldPattern > geomPattern_
void getFieldOrder(std::vector< std::string > &) const
std::map< std::pair< std::string, int >, int > blockGIDOffset_
(element block,field block) ==&gt; gid offset
virtual const std::pair< std::vector< int >, std::vector< int > > & getGIDFieldOffsets_closure(const std::string &blockId, int fieldNum, int subcellDim, int subcellId) const
Use the field pattern so that you can find a particular field in the GIDs array. This version lets yo...
void addField(const std::string &str, const Teuchos::RCP< const FieldPattern > &pattern)
Add a field to the DOF manager.
void registerFields(bool buildSubUGIs)
std::map< std::string, std::vector< int > > blockIdToFieldNumbers_
block ID ==&gt; field numbers
bool getUseDOFManagerFEI() const
which DOF Manager is used internally?
std::map< Teuchos::Tuple< int, 3 >, std::pair< std::vector< int >, std::vector< int > >, LessThan > TupleToVectorPairMap
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we&#39;ll contribute, or in which we&#39;ll store, the result of computing this integral...
int getFieldBlock(int fieldNum) const
Teuchos::RCP< ConnManager > connMngr_
void setFieldOrder(const std::vector< std::vector< std::string > > &fieldOrder)
void addFieldsToFieldBlockManager(const std::vector< std::string > &activeFields, GlobalIndexer &fieldBlockManager) const
virtual int getNumOwnedAndGhosted() const
Get the number of owned and ghosted indices for this processor.
std::map< std::pair< std::string, std::string >, Teuchos::RCP< const FieldPattern > > fieldStringToPattern_
(block ID x field string) ==&gt; pattern
const std::vector< std::pair< int, LocalOrdinal > > &pid_and_lid const
std::map< int, std::string > fieldNumToStr_
field number ==&gt; field string
Teuchos::RCP< const FieldPattern > getGeometricFieldPattern() const
#define TEUCHOS_ASSERT(assertion_test)
virtual void getOwnedAndGhostedIndicesAsInt(std::vector< int > &indices) const
Get the set of owned and ghosted indices for this processor.