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"
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 
69 template <typename LocalOrdinalT,typename GlobalOrdinalT>
70 class BlockedDOFManager : public UniqueGlobalIndexer<LocalOrdinalT,std::pair<int,GlobalOrdinalT> > {
71 public:
72  typedef std::pair<int,GlobalOrdinalT> GlobalOrdinal;
73  typedef LocalOrdinalT LocalOrdinal;
74  typedef std::map<int,std::string>::const_iterator const_field_iterator;
75 
76  virtual ~BlockedDOFManager() {}
77 
79 
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(LocalOrdinalT localElmtId,std::vector<GlobalOrdinal> & gids,const std::string & blockIdHint="") const; // ?
154 
157  virtual void getElementOrientation(LocalOrdinalT localElmtId,std::vector<double> & gidsOrientation) const; // ?
158 
162  virtual const std::vector<int> & getGIDFieldOffsets(const std::string & blockId,int fieldNum) const; // ?
163 
178  virtual const std::pair<std::vector<int>,std::vector<int> > &
179  getGIDFieldOffsets_closure(const std::string & blockId,int fieldNum,int subcellDim,int subcellId) const; // ?
180 
187  virtual void
189  std::vector<GlobalOrdinal>& indices) const;
190 
197  virtual void
199  std::vector<GlobalOrdinal>& indices) const;
200 
207  virtual void
209  std::vector<GlobalOrdinal>& indices) const;
210 
216  virtual int
217  getNumOwned() const;
218 
224  virtual int
225  getNumGhosted() const;
226 
232  virtual int
233  getNumOwnedAndGhosted() const;
234 
237  virtual void ownedIndices(const std::vector<GlobalOrdinal> & indices,std::vector<bool> & isOwned) const; // ?
238 
240 
245  void setUseDOFManagerFEI(bool useFEI)
246  { useDOFManagerFEI_ = useFEI; }
247 
250  bool getUseDOFManagerFEI() const
251  {
252  return false;
253  }
254 
266  void setConnManager(const Teuchos::RCP<ConnManager<LocalOrdinalT,GlobalOrdinalT> > & connMngr,MPI_Comm mpiComm);
267 
268 
273  { return geomPattern_; }
274 
284 
297  void addField(const std::string & str,const Teuchos::RCP<const FieldPattern> & pattern);
298 
299  void addField(const std::string & blockId,const std::string & str,const Teuchos::RCP<const FieldPattern> & pattern);
300 
309  void setFieldOrder(const std::vector<std::vector<std::string> > & fieldOrder);
310 
314  int getNumFieldBlocks() const;
315 
318  void getFieldOrder(std::vector<std::vector<std::string> > & fieldOrder) const;
319 
320  void getFieldOrder(std::vector<std::string>& /* fieldOrder */) const { TEUCHOS_ASSERT(false); } // what???
321 
335  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & blockId, const std::string & fieldName) const; // ?
336 
344  int getNumFields() const; // ?
345 
349  { return connMngr_; }
350 
354  { return connMngr_; }
355 
357  { return getConnManager(); }
358 
365  virtual void buildGlobalUnknowns();
366 
383  virtual void buildGlobalUnknowns(const Teuchos::RCP<const FieldPattern> & geomPattern);
384 
392  virtual void buildGlobalUnknowns(const std::vector<Teuchos::RCP<UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > > & fieldBlockManagers);
393 
397  void printFieldInformation(std::ostream & os) const; // ?
398 
407  bool validFieldOrder(const std::vector<std::vector<std::string> > & fieldOrder_ut,const std::set<std::string> & fields) const;
408 
412  void registerFields(bool buildSubUGIs);
413 
416  bool fieldsRegistered() const
417  { return fieldsRegistered_; }
418 
422  const std::vector<Teuchos::RCP<UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > > &
424  { return fieldBlockManagers_; }
425 
429  inline int getMaxSubFieldNumber() const
430  { return maxSubFieldNum_; }
431 
436  int getFieldBlock(int fieldNum) const
437  { return fieldNumToFieldBlk_.find(fieldNum)->second; }
438 
443  int getBlockGIDOffset(const std::string & elementBlock,int fieldBlock) const
444  {
445  std::map<std::pair<std::string,int>,int>::const_iterator itr =
446  blockGIDOffset_.find(std::make_pair(elementBlock,fieldBlock));
447 
448  if(itr==blockGIDOffset_.end())
449  return -1;
450  else
451  return itr->second;
452  }
453 
457  { return requireOrientations_; }
458 
462  { requireOrientations_ = ro; }
463 
466  void enableTieBreak(bool useTieBreak)
467  { useTieBreak_ = useTieBreak; }
468 
474  virtual int getElementBlockGIDCount(const std::string & blockId) const;
475 
481  virtual int getElementBlockGIDCount(const std::size_t & blockIndex) const;
482 
483 protected:
484 
488  MPI_Comm mpiComm) const;
489 
493 
497 
500  int getElementBlockGIDCount(const Teuchos::RCP<UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > & indexer,const std::string & elementBlock) const;
501 
504  int getElementBlockGIDCount(const Teuchos::RCP<UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > & indexer,const std::size_t & blockIndex) const;
505 
508  void printFieldInformation(const Teuchos::RCP<UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > & indexer,std::ostream & os) const;
509 
515  void addFieldsToFieldBlockManager(const std::vector<std::string> & activeFields,
516  UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> & fieldBlockManager) const;
517 
523  void addFieldsToFieldBlockManager(const std::vector<std::string> & activeFields,
524  DOFManager<LocalOrdinalT,GlobalOrdinalT> & fieldBlockManager) const;
525 
526 
527  // computes connectivity
529 
531 
532  std::map<std::string,int> fieldStrToNum_;
534 
536  std::map<int,std::string> fieldNumToStr_;
537 
539  std::map<int,int> fieldNumToFieldBlk_;
540 
542  std::map<std::pair<std::string,std::string>,Teuchos::RCP<const FieldPattern> > fieldStringToPattern_;
543 
545  std::map<std::string,std::set<std::string> > blockIdToFieldStrings_;
546 
548  std::map<std::string,std::vector<int> > blockIdToFieldNumbers_;
549 
551  std::map<std::pair<std::string,int>,int> blockGIDOffset_;
552 
554 
555  // storage for fast lookups of GID ownership
556  std::unordered_set<GlobalOrdinal,panzer::pair_hash> ownedGIDHashTable_;
557 
558  std::vector<std::vector<std::string> > fieldOrder_;
559 
561 
564 
565  std::vector<Teuchos::RCP<UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > > fieldBlockManagers_;
566 
567  MPI_Comm mpiComm_;
569 
573  mutable std::map<std::string,std::map<int,std::vector<int> > > gidFieldOffsets_;
574 
575  struct LessThan
576  { bool operator()(const Teuchos::Tuple<int,3> & a,const Teuchos::Tuple<int,3> & b) const; };
577  typedef std::map<Teuchos::Tuple<int,3>, std::pair<std::vector<int>,std::vector<int> >,LessThan> TupleToVectorPairMap;
578 
582  mutable std::map<std::string,TupleToVectorPairMap> gidFieldOffsets_closure_;
583 
585 
588 };
589 
590 }
591 
592 #endif
int getFieldNum(const std::string &str) const
Get the number used for access to this field.
bool operator()(const Teuchos::Tuple< int, 3 > &a, const Teuchos::Tuple< int, 3 > &b) const
virtual bool fieldInBlock(const std::string &field, const std::string &block) const
std::pair< int, GlobalOrdinalT > GlobalOrdinal
Teuchos::RCP< const ConnManager< LocalOrdinalT, GlobalOrdinalT > > getConnManager() const
std::map< std::pair< std::string, int >, int > blockGIDOffset_
(element block,field block) ==&gt; gid offset
std::unordered_set< GlobalOrdinal, panzer::pair_hash > ownedGIDHashTable_
virtual int getNumGhosted() const
Get the number of indices ghosted for this processor.
void enableTieBreak(bool useTieBreak)
const std::string & getFieldString(int num) const
Get the string name associated with a field number.
std::map< int, int > fieldNumToFieldBlk_
field number ==&gt; field block
Teuchos::RCP< const FieldPattern > getGeometricFieldPattern() const
bool validFieldOrder(const std::vector< std::vector< std::string > > &fieldOrder_ut, const std::set< std::string > &fields) const
std::map< int, std::string >::const_iterator const_field_iterator
void getFieldOrder(std::vector< std::string > &) const
void setConnManager(const Teuchos::RCP< ConnManager< LocalOrdinalT, GlobalOrdinalT > > &connMngr, MPI_Comm mpiComm)
Set the connection manager and MPI_Comm objects.
virtual const std::vector< LocalOrdinal > & getElementBlock(const std::string &blockId) const
virtual const std::vector< int > & getBlockFieldNumbers(const std::string &block) const
bool getUseDOFManagerFEI() const
which DOF Manager is used internally?
void getElementGIDs(LocalOrdinalT localElmtId, std::vector< GlobalOrdinal > &gids, const std::string &blockIdHint="") const
Get the global IDs for a particular element. This function overwrites the gids variable.
void addField(const std::string &str, const Teuchos::RCP< const FieldPattern > &pattern)
Add a field to the DOF manager.
virtual int getNumOwned() const
Get the number of indices owned by this processor.
Teuchos::RCP< ConnManager< LocalOrdinalT, GlobalOrdinalT > > resetIndices()
Reset the indicies for this DOF manager.
virtual void getGhostedIndices(std::vector< GlobalOrdinal > &indices) const
Get the set of indices ghosted for this processor.
virtual void getElementOrientation(LocalOrdinalT localElmtId, std::vector< double > &gidsOrientation) const
Get a vector containg the orientation of the GIDs relative to the neighbors.
std::map< std::string, std::map< int, std::vector< int > > > gidFieldOffsets_
Teuchos::RCP< Teuchos::MpiComm< int > > communicator_
int getNumFields() const
How many fields are handled by this manager.
virtual Teuchos::RCP< const ConnManagerBase< LocalOrdinalT > > getConnManagerBase() const
Returns the connection manager currently being used.
virtual int getElementBlockGIDCount(const std::string &blockId) const
How any GIDs are associate with a particular element block.
void setUseDOFManagerFEI(bool useFEI)
Use the FEI DOF manager internally, or the standard version.
virtual void getOwnedAndGhostedIndices(std::vector< GlobalOrdinal > &indices) const
Get the set of owned and ghosted indices for this processor.
std::map< std::string, std::vector< int > > blockIdToFieldNumbers_
block ID ==&gt; field numbers
Teuchos::RCP< const FieldPattern > geomPattern_
std::map< std::string, int > fieldStrToNum_
field string ==&gt; field number
void printFieldInformation(std::ostream &os) const
virtual void getOwnedIndices(std::vector< GlobalOrdinal > &indices) const
Get the set of indices owned by this processor.
std::vector< Teuchos::RCP< UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > fieldBlockManagers_
std::map< std::string, std::set< std::string > > blockIdToFieldStrings_
block ID ==&gt; field strings
Teuchos::RCP< UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > buildNewIndexer(const Teuchos::RCP< ConnManager< LocalOrdinalT, GlobalOrdinalT > > &connManager, MPI_Comm mpiComm) const
virtual void getElementBlockIds(std::vector< std::string > &elementBlockIds) const
const std::vector< std::pair< int, LocalOrdinal > > &pid_and_lid const
const std::vector< Teuchos::RCP< UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > & getFieldDOFManagers() const
virtual int getNumOwnedAndGhosted() const
Get the number of owned and ghosted indices for this processor.
virtual void ownedIndices(const std::vector< GlobalOrdinal > &indices, std::vector< bool > &isOwned) const
int getFieldBlock(int fieldNum) const
void setFieldOrder(const std::vector< std::vector< std::string > > &fieldOrder)
std::map< int, std::string > fieldNumToStr_
field number ==&gt; field string
std::map< std::pair< std::string, std::string >, Teuchos::RCP< const FieldPattern > > fieldStringToPattern_
(block ID x field string) ==&gt; pattern
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...
virtual Teuchos::RCP< Teuchos::Comm< int > > getComm() const
std::map< std::string, TupleToVectorPairMap > gidFieldOffsets_closure_
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.
#define TEUCHOS_ASSERT(assertion_test)
int getBlockGIDOffset(const std::string &elementBlock, int fieldBlock) const
std::vector< std::vector< std::string > > fieldOrder_
Teuchos::RCP< ConnManager< LocalOrdinalT, GlobalOrdinalT > > getConnManager()
Teuchos::RCP< ConnManager< LocalOrdinalT, GlobalOrdinalT > > connMngr_
void getFieldOrder(std::vector< std::vector< std::string > > &fieldOrder) const
std::map< Teuchos::Tuple< int, 3 >, std::pair< std::vector< int >, std::vector< int > >, LessThan > TupleToVectorPairMap
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...
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 addFieldsToFieldBlockManager(const std::vector< std::string > &activeFields, UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > &fieldBlockManager) const