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 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef __Panzer_BlockedDOFManager_hpp__
12 #define __Panzer_BlockedDOFManager_hpp__
13 
14 #include <map>
15 #include <set>
16 
17 #ifdef HAVE_MPI
18  #include <mpi.h>
19 #endif
20 
21 #include "PanzerDofMgr_config.hpp"
22 #include "Panzer_FieldPattern.hpp"
24 #include "Panzer_ConnManager.hpp"
25 #include "Panzer_GlobalIndexer.hpp"
26 #include "Panzer_DOFManager.hpp"
27 #include "Panzer_NodeType.hpp"
28 #include "Panzer_HashUtils.hpp"
29 
30 #include "Teuchos_RCP.hpp"
32 
33 #include <unordered_set>
34 
35 namespace panzer {
36 
38 public:
39  // typedef std::pair<int,GlobalOrdinalT> GlobalOrdinal;
40  using GlobalOrdinal = panzer::GlobalOrdinal;
41  using LocalOrdinal = panzer::LocalOrdinal;
42  using const_field_iterator = std::map<int,std::string>::const_iterator;
43 
44  virtual ~BlockedDOFManager() {}
45 
47 
52  BlockedDOFManager(const Teuchos::RCP<ConnManager> & connMngr,MPI_Comm mpiComm);
53 
57 
58 
62  { return communicator_; }
63 
78  int getFieldNum(const std::string & str) const; // ?
79 
93  const std::string & getFieldString(int num) const;
94 
97  virtual void getElementBlockIds(std::vector<std::string> & elementBlockIds) const
98  { getConnManager()->getElementBlockIds(elementBlockIds); }
99 
102  virtual bool fieldInBlock(const std::string & field, const std::string & block) const; // ?
103 
111  virtual const std::vector<LocalOrdinal> & getElementBlock(const std::string & blockId) const // ?
112  { return getConnManager()->getElementBlock(blockId); }
113 
116  virtual const std::vector<int> & getBlockFieldNumbers(const std::string & block) const; // ?
117 
121  void getElementGIDs(panzer::LocalOrdinal localElmtId,std::vector<GlobalOrdinal> & gids,const std::string & blockIdHint="") const; // ?
122 
136  void getElementGIDsPair(panzer::LocalOrdinal localElmtId,std::vector<std::pair<int,GlobalOrdinal>> & gids,const std::string & blockIdHint="") const;
137 
140  virtual void getElementOrientation(panzer::LocalOrdinal localElmtId,std::vector<double> & gidsOrientation) const; // ?
141 
145  virtual const std::vector<int> & getGIDFieldOffsets(const std::string & blockId,int fieldNum) const; // ?
146 
161  virtual const std::pair<std::vector<int>,std::vector<int> > &
162  getGIDFieldOffsets_closure(const std::string & blockId,int fieldNum,int subcellDim,int subcellId) const; // ?
163 
170  virtual void getOwnedIndices(std::vector<GlobalOrdinal>& indices) const;
171 
178  virtual void
179  getGhostedIndices(std::vector<GlobalOrdinal>& indices) const;
180 
187  virtual void
188  getOwnedAndGhostedIndices(std::vector<GlobalOrdinal>& indices) const;
189 
190  // For backwards compatibility with Epetra. Will be deprecated.
191  void getElementGIDsAsInt(panzer::LocalOrdinal localElmtId,std::vector<int> & gids,const std::string & blockIdHint="") const;
192  virtual void getOwnedIndicesAsInt(std::vector<int>& indices) const;
193  virtual void getGhostedIndicesAsInt(std::vector<int>& indices) const;
194  virtual void getOwnedAndGhostedIndicesAsInt(std::vector<int>& indices) const;
195 
201  virtual int
202  getNumOwned() const;
203 
209  virtual int
210  getNumGhosted() const;
211 
217  virtual int
218  getNumOwnedAndGhosted() const;
219 
222  virtual void ownedIndices(const std::vector<GlobalOrdinal> & indices,std::vector<bool> & isOwned) const; // ?
223 
225 
230  void setUseDOFManagerFEI(bool useFEI)
231  { useDOFManagerFEI_ = useFEI; }
232 
235  bool getUseDOFManagerFEI() const
236  {
237  return false;
238  }
239 
251  void setConnManager(const Teuchos::RCP<ConnManager> & connMngr,MPI_Comm mpiComm);
252 
253 
258  { return geomPattern_; }
259 
269 
282  void addField(const std::string & str,const Teuchos::RCP<const FieldPattern> & pattern);
283 
284  void addField(const std::string & blockId,const std::string & str,const Teuchos::RCP<const FieldPattern> & pattern);
285 
294  void setFieldOrder(const std::vector<std::vector<std::string> > & fieldOrder);
295 
299  int getNumFieldBlocks() const;
300 
303  void getFieldOrder(std::vector<std::vector<std::string> > & fieldOrder) const;
304 
305  void getFieldOrder(std::vector<std::string>& /* fieldOrder */) const { TEUCHOS_ASSERT(false); } // what???
306 
320  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & blockId, const std::string & fieldName) const; // ?
321 
329  int getNumFields() const; // ?
330 
334  { return connMngr_; }
335 
339  { return connMngr_; }
340 
347  virtual void buildGlobalUnknowns();
348 
365  virtual void buildGlobalUnknowns(const Teuchos::RCP<const FieldPattern> & geomPattern);
366 
374  virtual void buildGlobalUnknowns(const std::vector<Teuchos::RCP<GlobalIndexer>> & fieldBlockManagers);
375 
379  void printFieldInformation(std::ostream & os) const; // ?
380 
389  bool validFieldOrder(const std::vector<std::vector<std::string> > & fieldOrder_ut,const std::set<std::string> & fields) const;
390 
394  void registerFields(bool buildSubUGIs);
395 
398  bool fieldsRegistered() const
399  { return fieldsRegistered_; }
400 
404  const std::vector<Teuchos::RCP<GlobalIndexer>> &
406  { return fieldBlockManagers_; }
407 
411  inline int getMaxSubFieldNumber() const
412  { return maxSubFieldNum_; }
413 
418  int getFieldBlock(int fieldNum) const
419  { return fieldNumToFieldBlk_.find(fieldNum)->second; }
420 
425  int getBlockGIDOffset(const std::string & elementBlock,int fieldBlock) const
426  {
427  std::map<std::pair<std::string,int>,int>::const_iterator itr =
428  blockGIDOffset_.find(std::make_pair(elementBlock,fieldBlock));
429 
430  if(itr==blockGIDOffset_.end())
431  return -1;
432  else
433  return itr->second;
434  }
435 
439  { return requireOrientations_; }
440 
444  { requireOrientations_ = ro; }
445 
448  void enableTieBreak(bool useTieBreak)
449  { useTieBreak_ = useTieBreak; }
450 
456  virtual int getElementBlockGIDCount(const std::string & blockId) const;
457 
463  virtual int getElementBlockGIDCount(const std::size_t & blockIndex) const;
464 
465 protected:
466 
470  MPI_Comm mpiComm) const;
471 
474  void setOrientationsRequired(const Teuchos::RCP<GlobalIndexer> & indexer,bool required) const;
475 
478  void buildGlobalUnknowns(const Teuchos::RCP<GlobalIndexer> & indexer,const Teuchos::RCP<const FieldPattern> & geomPattern) const;
479 
482  int getElementBlockGIDCount(const Teuchos::RCP<GlobalIndexer> & indexer,const std::string & elementBlock) const;
483 
486  int getElementBlockGIDCount(const Teuchos::RCP<GlobalIndexer> & indexer,const std::size_t & blockIndex) const;
487 
490  void printFieldInformation(const Teuchos::RCP<GlobalIndexer> & indexer,std::ostream & os) const;
491 
497  void addFieldsToFieldBlockManager(const std::vector<std::string> & activeFields,
498  GlobalIndexer & fieldBlockManager) const;
499 
505  void addFieldsToFieldBlockManager(const std::vector<std::string> & activeFields,
506  DOFManager & fieldBlockManager) const;
507 
508  // computes connectivity
510 
512 
513  std::map<std::string,int> fieldStrToNum_;
515 
517  std::map<int,std::string> fieldNumToStr_;
518 
520  std::map<int,int> fieldNumToFieldBlk_;
521 
523  std::map<std::pair<std::string,std::string>,Teuchos::RCP<const FieldPattern> > fieldStringToPattern_;
524 
526  std::map<std::string,std::set<std::string> > blockIdToFieldStrings_;
527 
529  std::map<std::string,std::vector<int> > blockIdToFieldNumbers_;
530 
532  std::map<std::pair<std::string,int>,int> blockGIDOffset_;
533 
535 
536  // storage for fast lookups of GID ownership
537  //std::unordered_set<GlobalOrdinal,panzer::pair_hash> ownedGIDHashTable_;
538 
539  std::vector<std::vector<std::string> > fieldOrder_;
540 
542 
545 
546  std::vector<Teuchos::RCP<GlobalIndexer>> fieldBlockManagers_;
547 
548  MPI_Comm mpiComm_;
550 
554  mutable std::map<std::string,std::map<int,std::vector<int> > > gidFieldOffsets_;
555 
556  struct LessThan
557  { bool operator()(const Teuchos::Tuple<int,3> & a,const Teuchos::Tuple<int,3> & b) const; };
558  typedef std::map<Teuchos::Tuple<int,3>, std::pair<std::vector<int>,std::vector<int> >,LessThan> TupleToVectorPairMap;
559 
563  mutable std::map<std::string,TupleToVectorPairMap> gidFieldOffsets_closure_;
564 
566 
569 };
570 
571 }
572 
573 #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.