Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_DOFManager_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_DOFManager_decl_hpp__
44 #define __Panzer_DOFManager_decl_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 
85  { return connMngr_; }
86 
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 
140  void getOwnedAndSharedIndices(std::vector<GlobalOrdinalT> & indices) const;
141 
143  int getNumFields() const;
144 
148  const std::vector<int> & getGIDFieldOffsets(const std::string & blockID, int fieldNum) const;
149 
151  void getElementGIDs(LO localElementID, std::vector<GO> & gids, const std::string & blockIdHint="") const;
152 
154  void buildGlobalUnknowns();
155 
157  void buildGlobalUnknowns(const Teuchos::RCP<const FieldPattern> & geomPattern);
158 
159  int getFieldNum(const std::string & string) const;
160 
162  { return communicator_; }
163 
165  { return ga_fp_; }
166 
167  void getElementBlockIds(std::vector<std::string> & elementBlockIds) const
168  { connMngr_->getElementBlockIds(elementBlockIds); }
169 
170  bool fieldInBlock(const std::string & field, const std::string & block) const;
171 
172  const std::vector<int> & getBlockFieldNumbers(const std::string & blockId) const;
173 
174 //************************************************************************
175 
188  const std::pair<std::vector<int>,std::vector<int> > &
189  getGIDFieldOffsets_closure(const std::string & blockId, int fieldNum, int subcellDim,int subcellId) const;
190 
192  const std::vector<LocalOrdinalT> & getElementBlock(const std::string & blockId) const
193  { return connMngr_->getElementBlock(blockId); }
194 
195  void ownedIndices(const std::vector<GlobalOrdinalT> & indices,std::vector<bool> & isOwned) const;
196 
197  void setFieldOrder(const std::vector<std::string> & fieldOrder );
198 
199  void getFieldOrder(std::vector<std::string> & fieldOrder) const;
200 
201  bool validFieldOrder(const std::vector<std::string> & proposed_fieldOrder);
202 
203  //TODO:this
205 
207  { return requireOrientations_; }
208 
210  { requireOrientations_ = ro; }
211 
214  void getElementOrientation(LocalOrdinalT localElmtId,std::vector<double> & gidsOrientation) const;
215 
216  const std::string & getFieldString(int num) const;
217 
227 
233  virtual int getElementBlockGIDCount(const std::string & blockId) const
234  { return getElementBlockGIDCount(blockIdToIndex(blockId)); }
235 
241  virtual int getElementBlockGIDCount(const std::size_t & blockIndex) const
242  { return elementBlockGIDCount_[blockIndex]; }
243 
247  void printFieldInformation(std::ostream & os) const;
248 
253  void enableTieBreak(bool enable)
254  { useTieBreak_ = enable; }
255 
262  void enableGhosting(bool enable)
263  { buildGhosted_ = enable; }
264 
265  // These functions are primarily for testing purposes
266  // they are not intended to be useful otherwise (thus they are not
267  // documented in the Doxygen style
268 
269  // Return the number of elemnts as measured by the count of GID arrays.
270  // note that this will include ghosted elements!
271  std::size_t getNumberElementGIDArrays() const
272  { return elementGIDs_.size(); }
273 
274 protected:
275 
279  runLocalRCMReordering(const Teuchos::RCP<const Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,panzer::TpetraNodeType> > &);
280 
284  std::size_t blockIdToIndex(const std::string & blockId) const;
285 
292  bool useOwned_;
294  public:
295  ElementBlockAccess(bool owned,const Teuchos::RCP<const ConnManager<LO,GO> > & connMngr)
296  : useOwned_(owned), connMngr_(connMngr) {}
297 
298  const std::vector<LO> & getElementBlock(const std::string & eBlock) const
299  {
300  if(useOwned_==true)
301  return connMngr_->getElementBlock(eBlock);
302  else
303  return connMngr_->getNeighborElementBlock(eBlock);
304  }
305  };
306 
312  buildOverlapMapFromElements(const ElementBlockAccess & access) const;
313 
314  void fillGIDsFromOverlappedMV(const ElementBlockAccess & access,
315  std::vector<std::vector< GO > > & elementGIDs,
316  const Tpetra::Map<LO,GO,panzer::TpetraNodeType> & overlapmap,
317  const Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> & overlap_mv) const;
319 
322 
323  //Please note: AID=absolute ID. This is an attempt to remember that
324  // fieldPatterns_ is unchanging storage for FPs.
325  std::vector<Teuchos::RCP<const FieldPattern> > fieldPatterns_;
326  std::map<std::string,int> fieldNameToAID_;
327 
328  std::vector<std::string> blockOrder_; // To be got from the ConnManager.
329  std::map<std::string,int> blockNameToID_; // I'm not sure the above vector is needed, this might suffice.
330  std::vector<std::vector<int> > blockToAssociatedFP_; // each sub-vector is associated by
331  // a block, with ordering given in blockOrder_. ints refer to the order in fieldPatterns_;
332  std::vector<std::string> fieldStringOrder_;
333  std::vector<int> fieldAIDOrder_; // Both of these must be updated and edited together.
334  // The AID offers a simpler way to manage FPs internally.
335 
336  Teuchos::RCP<const panzer::FieldPattern> ga_fp_; // geometric aggregate field pattern
337  std::vector<Teuchos::RCP<panzer::FieldAggPattern> > fa_fps_; //Ordered by blockOrder_;
338 
339  std::vector<GO> owned_;
340  std::vector<GO> owned_and_ghosted_;
341 
342  // Element GIDS ordered by LID.
343  std::vector<std::vector< GO > > elementGIDs_;
344 
345  // Mimics the functionality of the getElemenentBlockGIDCount in
346  // the original DOFManager. Indexed according to blockOrder_.
347  std::vector<int> elementBlockGIDCount_;
348 
350 
352 
354  std::vector<std::vector<char> > orientation_;
355 
358 };
359 
360 }
361 
362 #endif
std::vector< std::string > fieldStringOrder_
virtual int getElementBlockGIDCount(const std::string &blockId) const
How any GIDs are associate with a particular element block.
ElementBlockAccess(bool owned, const Teuchos::RCP< const ConnManager< LO, GO > > &connMngr)
void getFieldOrder(std::vector< std::string > &fieldOrder) const
Teuchos::RCP< const panzer::FieldPattern > ga_fp_
const std::vector< int > & getBlockFieldNumbers(const std::string &blockId) const
virtual int getElementBlockGIDCount(const std::size_t &blockIndex) const
How any GIDs are associate with a particular element block.
const std::vector< int > & getGIDFieldOffsets(const std::string &blockID, int fieldNum) const
Teuchos::RCP< const FieldPattern > getGeometricFieldPattern() const
std::vector< std::vector< char > > orientation_
std::vector< Teuchos::RCP< panzer::FieldAggPattern > > fa_fps_
void setConnManager(const Teuchos::RCP< ConnManager< LO, GO > > &connMngr, MPI_Comm mpiComm)
Adds a Connection Manager that will be associated with this DOFManager.
void printFieldInformation(std::ostream &os) const
Teuchos::RCP< ConnManager< LO, GO > > connMngr_
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, int > blockNameToID_
const std::vector< LocalOrdinalT > & getElementBlock(const std::string &blockId) const
Get the owned element block.
PHX::MDField< ScalarT > vector
virtual Teuchos::RCP< const ConnManagerBase< LocalOrdinalT > > getConnManagerBase() const
Returns the connection manager currently being used.
std::size_t getNumberElementGIDArrays() const
void ownedIndices(const std::vector< GlobalOrdinalT > &indices, std::vector< bool > &isOwned) const
Teuchos::RCP< ConnManager< LocalOrdinalT, GlobalOrdinalT > > resetIndices()
Reset the indicies for this DOF manager.
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...
void getElementGIDs(LO localElementID, std::vector< GO > &gids, const std::string &blockIdHint="") const
get associated GIDs for a given local element
void setFieldOrder(const std::vector< std::string > &fieldOrder)
bool getOrientationsRequired() const
std::vector< std::vector< int > > blockToAssociatedFP_
Teuchos::RCP< const ConnManager< LO, GO > > connMngr_
int addField(const std::string &str, const Teuchos::RCP< const FieldPattern > &pattern)
Add a field to the DOF manager.
void enableGhosting(bool enable)
void buildGlobalUnknowns()
builds the global unknowns array
void getOwnedAndSharedIndices(std::vector< GlobalOrdinalT > &indices) const
PHX::MDField< const ScalarT, Cell, IP > field
bool validFieldOrder(const std::vector< std::string > &proposed_fieldOrder)
std::vector< int > fieldAIDOrder_
std::map< std::string, int > fieldNameToAID_
Teuchos::RCP< const Tpetra::Map< LO, GO, panzer::TpetraNodeType > > buildOverlapMapFromElements(const ElementBlockAccess &access) const
std::vector< std::vector< GO > > elementGIDs_
Teuchos::RCP< Teuchos::Comm< int > > communicator_
void setOrientationsRequired(bool ro)
std::vector< int > elementBlockGIDCount_
const std::string & getFieldString(int num) const
Reverse lookup of the field string from a field number.
std::vector< Teuchos::RCP< const FieldPattern > > fieldPatterns_
Teuchos::RCP< const Tpetra::Map< LO, GO, panzer::TpetraNodeType > > runLocalRCMReordering(const Teuchos::RCP< const Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, panzer::TpetraNodeType > > &)
bool fieldInBlock(const std::string &field, const std::string &block) const
void getElementBlockIds(std::vector< std::string > &elementBlockIds) const
void getOwnedIndices(std::vector< GlobalOrdinalT > &indices) const
Teuchos::RCP< ConnManager< LO, GO > > getConnManager() const
int getNumFields() const
gets the number of fields
std::size_t blockIdToIndex(const std::string &blockId) 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...
int getFieldNum(const std::string &string) const
Get the number used for access to this field.
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
std::vector< std::string > blockOrder_
const std::vector< LO > & getElementBlock(const std::string &eBlock) const
Teuchos::RCP< Teuchos::Comm< int > > getComm() const
void enableTieBreak(bool enable)
std::vector< GO > owned_and_ghosted_