Panzer  Version of the Day
Panzer_DOFManager.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_DOFManager_hpp__
44 #define __Panzer_DOFManager_hpp__
45 #include <map>
46 
47 #include "mpi.h"
48 
49 #include "PanzerDofMgr_config.hpp"
50 #include "Panzer_FieldPattern.hpp"
53 #include "Panzer_ConnManager.hpp"
55 #include "Panzer_NodeType.hpp"
56 
57 #include "Teuchos_RCP.hpp"
58 
59 #include "Tpetra_Map.hpp"
60 #include "Tpetra_MultiVector.hpp"
61 
62 namespace panzer {
63 
64 
65 template <typename LocalOrdinalT, typename GlobalOrdinalT>
66 class DOFManager : public UniqueGlobalIndexer<LocalOrdinalT, GlobalOrdinalT> {
67 public:
68  typedef GlobalOrdinalT GO;
69  typedef LocalOrdinalT LO;
70 
71  virtual ~DOFManager() {}
72 
73  DOFManager();
74 
79  DOFManager(const Teuchos::RCP<ConnManager<LocalOrdinalT,GlobalOrdinalT> > & connMngr,MPI_Comm mpiComm);
80 
82  void setConnManager(const Teuchos::RCP<ConnManager<LO,GO> > & connMngr, MPI_Comm mpiComm);
83 
84  Teuchos::RCP<ConnManager<LO,GO> > getConnManager() const
85  { return connMngr_; }
86 
87  virtual Teuchos::RCP<const ConnManagerBase<LocalOrdinalT> > getConnManagerBase() const
88  { return getConnManager(); }
89 
102  int addField(const std::string & str, const Teuchos::RCP<const FieldPattern> & pattern);
103 
105  int addField(const std::string & blockID, const std::string & str, const Teuchos::RCP<const FieldPattern> & pattern);
106 
107 
121  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & name) const;
122 
136  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & blockId, const std::string & fieldName) const;
137 
138  void getOwnedIndices(std::vector<GlobalOrdinalT> & indices) const;
139  void getOwnedAndGhostedIndices(std::vector<GlobalOrdinalT> & indices) const;
140 
142  int getNumFields() const;
143 
147  const std::vector<int> & getGIDFieldOffsets(const std::string & blockID, int fieldNum) const;
148 
150  void getElementGIDs(LO localElementID, std::vector<GO> & gids, const std::string & blockIdHint="") const;
151 
153  void buildGlobalUnknowns();
154 
156  void buildGlobalUnknowns(const Teuchos::RCP<const FieldPattern> & geomPattern);
157 
158  int getFieldNum(const std::string & string) const;
159 
160  Teuchos::RCP<Teuchos::Comm<int> > getComm() const
161  { return communicator_; }
162 
163  Teuchos::RCP<const FieldPattern> getGeometricFieldPattern() const
164  { return ga_fp_; }
165 
166  void getElementBlockIds(std::vector<std::string> & elementBlockIds) const
167  { connMngr_->getElementBlockIds(elementBlockIds); }
168 
169  bool fieldInBlock(const std::string & field, const std::string & block) const;
170 
171  const std::vector<int> & getBlockFieldNumbers(const std::string & blockId) const;
172 
173 //************************************************************************
174 
187  const std::pair<std::vector<int>,std::vector<int> > &
188  getGIDFieldOffsets_closure(const std::string & blockId, int fieldNum, int subcellDim,int subcellId) const;
189 
191  const std::vector<LocalOrdinalT> & getElementBlock(const std::string & blockId) const
192  { return connMngr_->getElementBlock(blockId); }
193 
194  void ownedIndices(const std::vector<GlobalOrdinalT> & indices,std::vector<bool> & isOwned) const;
195 
196  void setFieldOrder(const std::vector<std::string> & fieldOrder );
197 
198  void getFieldOrder(std::vector<std::string> & fieldOrder) const;
199 
200  bool validFieldOrder(const std::vector<std::string> & proposed_fieldOrder);
201 
202  //TODO:this
204 
206  { return requireOrientations_; }
207 
209  { requireOrientations_ = ro; }
210 
213  void getElementOrientation(LocalOrdinalT localElmtId,std::vector<double> & gidsOrientation) const;
214 
215  const std::string & getFieldString(int num) const;
216 
225  Teuchos::RCP<ConnManager<LocalOrdinalT,GlobalOrdinalT> > resetIndices();
226 
232  virtual int getElementBlockGIDCount(const std::string & blockId) const
233  { return getElementBlockGIDCount(blockIdToIndex(blockId)); }
234 
240  virtual int getElementBlockGIDCount(const std::size_t & blockIndex) const
241  { return elementBlockGIDCount_[blockIndex]; }
242 
246  void printFieldInformation(std::ostream & os) const;
247 
252  void enableTieBreak(bool enable)
253  { useTieBreak_ = enable; }
254 
260  void useNeighbors(bool flag)
261  { useNeighbors_ = flag; }
262 
263  // These functions are primarily for testing purposes
264  // they are not intended to be useful otherwise (thus they are not
265  // documented in the Doxygen style
266 
267  // Return the number of elemnts as measured by the count of GID arrays.
268  // note that this will include ghosted elements!
269  std::size_t getNumberElementGIDArrays() const
270  { return elementGIDs_.size(); }
271 
272 protected:
273 
276  Teuchos::RCP<const Tpetra::Map<LO,GO,panzer::TpetraNodeType> >
277  runLocalRCMReordering(const Teuchos::RCP<const Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,panzer::TpetraNodeType> > &);
278 
282  std::size_t blockIdToIndex(const std::string & blockId) const;
283 
290  bool useOwned_;
291  Teuchos::RCP<const ConnManager<LO,GO> > connMngr_;
292  public:
293  ElementBlockAccess(bool owned,const Teuchos::RCP<const ConnManager<LO,GO> > & connMngr)
294  : useOwned_(owned), connMngr_(connMngr) {}
295 
296  const std::vector<LO> & getElementBlock(const std::string & eBlock) const
297  {
298  if(useOwned_==true)
299  return connMngr_->getElementBlock(eBlock);
300  else
301  return connMngr_->getNeighborElementBlock(eBlock);
302  }
303  };
304 
309  Teuchos::RCP<const Tpetra::Map<LO,GO,panzer::TpetraNodeType> >
310  buildOverlapMapFromElements(const ElementBlockAccess & access) const;
311 
315  Teuchos::RCP<Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> >
316  buildTaggedMultiVector(const ElementBlockAccess & access);
317 
323  std::pair<Teuchos::RCP<Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> >,
324  Teuchos::RCP<Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> > >
325  buildGlobalUnknowns_GUN(const Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> & tagged_overlap_mv,
326  Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> & overlap_mv) const;
327 
328  void fillGIDsFromOverlappedMV(const ElementBlockAccess & access,
329  std::vector<std::vector< GO > > & elementGIDs,
330  const Tpetra::Map<LO,GO,panzer::TpetraNodeType> & overlapmap,
331  const Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> & overlap_mv) const;
333 
334  Teuchos::RCP<ConnManager<LO,GO> > connMngr_;
335  Teuchos::RCP<Teuchos::Comm<int> > communicator_;
336 
337  //Please note: AID=absolute ID. This is an attempt to remember that
338  // fieldPatterns_ is unchanging storage for FPs.
339  std::vector<Teuchos::RCP<const FieldPattern> > fieldPatterns_;
340  std::map<std::string,int> fieldNameToAID_;
341 
342  std::vector<std::string> blockOrder_; // To be got from the ConnManager.
343  std::map<std::string,int> blockNameToID_; // I'm not sure the above vector is needed, this might suffice.
344  std::vector<std::vector<int> > blockToAssociatedFP_; // each sub-vector is associated by
345  // a block, with ordering given in blockOrder_. ints refer to the order in fieldPatterns_;
346  std::vector<std::string> fieldStringOrder_;
347  std::vector<int> fieldAIDOrder_; // Both of these must be updated and edited together.
348  // The AID offers a simpler way to manage FPs internally.
349 
350  Teuchos::RCP<const panzer::FieldPattern> ga_fp_; // geometric aggregate field pattern
351  std::vector<Teuchos::RCP<panzer::FieldAggPattern> > fa_fps_; //Ordered by blockOrder_;
352 
353  std::vector<GO> owned_;
354  std::vector<GO> ghosted_;
355 
356  // Element GIDS ordered by LID.
357  std::vector<std::vector< GO > > elementGIDs_;
358 
359  // Mimics the functionality of the getElemenentBlockGIDCount in
360  // the original DOFManager. Indexed according to blockOrder_.
361  std::vector<int> elementBlockGIDCount_;
362 
364 
366 
368  std::vector<std::vector<char> > orientation_;
369 
372 };
373 
374 }
375 
376 #endif
const std::vector< int > & getBlockFieldNumbers(const std::string &blockId) const
int getFieldNum(const std::string &string) const
Get the number used for access to this field.
ElementBlockAccess(bool owned, const Teuchos::RCP< const ConnManager< LO, GO > > &connMngr)
void getElementGIDs(LO localElementID, std::vector< GO > &gids, const std::string &blockIdHint="") const
get associated GIDs for a given local element
const std::string & getFieldString(int num) const
Reverse lookup of the field string from a field number.
void fillGIDsFromOverlappedMV(const ElementBlockAccess &access, std::vector< std::vector< GO > > &elementGIDs, const Tpetra::Map< LO, GO, panzer::TpetraNodeType > &overlapmap, const Tpetra::MultiVector< GO, LO, GO, panzer::TpetraNodeType > &overlap_mv) const
Teuchos::RCP< const ConnManager< LO, GO > > connMngr_
void getElementBlockIds(std::vector< std::string > &elementBlockIds) const
void useNeighbors(bool flag)
std::map< std::string, int > blockNameToID_
void setOrientationsRequired(bool ro)
std::vector< std::vector< char > > orientation_
void setConnManager(const Teuchos::RCP< ConnManager< LO, GO > > &connMngr, MPI_Comm mpiComm)
Adds a Connection Manager that will be associated with this DOFManager.
const std::vector< int > & getGIDFieldOffsets(const std::string &blockID, int fieldNum) const
Teuchos::RCP< const Tpetra::Map< LO, GO, panzer::TpetraNodeType > > buildOverlapMapFromElements(const ElementBlockAccess &access) const
PHX::MDField< ScalarT > vector
const std::vector< LO > & getElementBlock(const std::string &eBlock) const
Teuchos::RCP< Teuchos::Comm< int > > communicator_
bool getOrientationsRequired() const
const std::vector< LocalOrdinalT > & getElementBlock(const std::string &blockId) const
Get the owned element block.
Teuchos::RCP< ConnManager< LocalOrdinalT, GlobalOrdinalT > > resetIndices()
Reset the indices for this DOF manager.
std::vector< GO > owned_
std::size_t blockIdToIndex(const std::string &blockId) const
Teuchos::RCP< const FieldPattern > getFieldPattern(const std::string &name) const
Find a field pattern stored for a particular block and field number. This will retrive the pattern ad...
Teuchos::RCP< const FieldPattern > getGeometricFieldPattern() const
void setFieldOrder(const std::vector< std::string > &fieldOrder)
std::vector< int > elementBlockGIDCount_
virtual Teuchos::RCP< const ConnManagerBase< LocalOrdinalT > > getConnManagerBase() const
Returns the connection manager currently being used.
void getOwnedAndGhostedIndices(std::vector< GlobalOrdinalT > &indices) const
Teuchos::RCP< ConnManager< LO, GO > > getConnManager() const
std::vector< GO > ghosted_
Teuchos::RCP< const Tpetra::Map< LO, GO, panzer::TpetraNodeType > > runLocalRCMReordering(const Teuchos::RCP< const Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, panzer::TpetraNodeType > > &)
int addField(const std::string &str, const Teuchos::RCP< const FieldPattern > &pattern)
Add a field to the DOF manager.
std::vector< std::vector< GO > > elementGIDs_
void buildGlobalUnknowns()
builds the global unknowns array
PHX::MDField< const ScalarT, Cell, IP > field
Teuchos::RCP< const panzer::FieldPattern > ga_fp_
bool validFieldOrder(const std::vector< std::string > &proposed_fieldOrder)
std::vector< int > fieldAIDOrder_
std::vector< Teuchos::RCP< const FieldPattern > > fieldPatterns_
Teuchos::RCP< Teuchos::Comm< int > > getComm() const
void getFieldOrder(std::vector< std::string > &fieldOrder) const
void getOwnedIndices(std::vector< GlobalOrdinalT > &indices) const
std::map< std::string, int > fieldNameToAID_
void enableTieBreak(bool enable)
Teuchos::RCP< ConnManager< LO, GO > > connMngr_
std::pair< Teuchos::RCP< Tpetra::MultiVector< GO, LO, GO, panzer::TpetraNodeType > >, Teuchos::RCP< Tpetra::MultiVector< GO, LO, GO, panzer::TpetraNodeType > > > buildGlobalUnknowns_GUN(const Tpetra::MultiVector< GO, LO, GO, panzer::TpetraNodeType > &tagged_overlap_mv, Tpetra::MultiVector< GO, LO, GO, panzer::TpetraNodeType > &overlap_mv) const
Teuchos::RCP< Tpetra::MultiVector< GO, LO, GO, panzer::TpetraNodeType > > buildTaggedMultiVector(const ElementBlockAccess &access)
void printFieldInformation(std::ostream &os) const
virtual int getElementBlockGIDCount(const std::string &blockId) const
How any GIDs are associate with a particular element block.
std::vector< Teuchos::RCP< panzer::FieldAggPattern > > fa_fps_
void getElementOrientation(LocalOrdinalT localElmtId, std::vector< double > &gidsOrientation) const
Get a vector containg the orientation of the GIDs relative to the neighbors.
int getNumFields() const
gets the number of fields
bool fieldInBlock(const std::string &field, const std::string &block) const
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...
std::size_t getNumberElementGIDArrays() const
std::vector< std::string > fieldStringOrder_
std::vector< std::vector< int > > blockToAssociatedFP_
std::vector< std::string > blockOrder_
void ownedIndices(const std::vector< GlobalOrdinalT > &indices, std::vector< bool > &isOwned) const
virtual int getElementBlockGIDCount(const std::size_t &blockIndex) const
How any GIDs are associate with a particular element block.