Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #include "Panzer_FieldType.hpp"
57 #include "Phalanx_KokkosDeviceTypes.hpp"
58 
59 #include "Teuchos_RCP.hpp"
60 
61 #include "Tpetra_Map.hpp"
62 #include "Tpetra_MultiVector.hpp"
63 
64 namespace panzer {
65 
66 
67 template <typename LocalOrdinalT, typename GlobalOrdinalT>
68 class DOFManager : public UniqueGlobalIndexer<LocalOrdinalT, GlobalOrdinalT> {
69 public:
70  typedef GlobalOrdinalT GO;
71  typedef LocalOrdinalT LO;
72 
73  virtual ~DOFManager() {}
74 
75  DOFManager();
76 
81  DOFManager(const Teuchos::RCP<ConnManager<LocalOrdinalT,GlobalOrdinalT> > & connMngr,MPI_Comm mpiComm);
82 
84  void setConnManager(const Teuchos::RCP<ConnManager<LO,GO> > & connMngr, MPI_Comm mpiComm);
85 
87  { return connMngr_; }
88 
90  { return getConnManager(); }
91 
105  int addField(const std::string & str, const Teuchos::RCP<const FieldPattern> & pattern,
107 
122  int addField(const std::string & blockID, const std::string & str,
123  const Teuchos::RCP<const FieldPattern> & pattern,
125 
139  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & name) const;
140 
154  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & blockId, const std::string & fieldName) const;
155 
162  void
164  std::vector<GlobalOrdinalT>& indices) const;
165 
172  void
174  std::vector<GlobalOrdinalT>& indices) const;
175 
182  void
184  std::vector<GlobalOrdinalT>& indices) const;
185 
191  int
192  getNumOwned() const;
193 
199  int
200  getNumGhosted() const;
201 
207  int
208  getNumOwnedAndGhosted() const;
209 
211  int getNumFields() const;
212 
216  const std::vector<int> & getGIDFieldOffsets(const std::string & blockID, int fieldNum) const;
217 
221  const Kokkos::View<const int*,PHX::Device> getGIDFieldOffsetsKokkos(const std::string & blockID, int fieldNum) const;
222 
224  void getElementGIDs(LO localElementID, std::vector<GO> & gids, const std::string & blockIdHint="") const;
225 
227  void buildGlobalUnknowns();
228 
230  void buildGlobalUnknowns(const Teuchos::RCP<const FieldPattern> & geomPattern);
231 
232  int getFieldNum(const std::string & string) const;
233 
235  { return communicator_; }
236 
238  { return ga_fp_; }
239 
240  void getElementBlockIds(std::vector<std::string> & elementBlockIds) const
241  { connMngr_->getElementBlockIds(elementBlockIds); }
242 
243  bool fieldInBlock(const std::string & field, const std::string & block) const;
244 
245  const std::vector<int> & getBlockFieldNumbers(const std::string & blockId) const;
246 
247 //************************************************************************
248 
261  const std::pair<std::vector<int>,std::vector<int> > &
262  getGIDFieldOffsets_closure(const std::string & blockId, int fieldNum, int subcellDim,int subcellId) const;
263 
265  const std::vector<LocalOrdinalT> & getElementBlock(const std::string & blockId) const
266  { return connMngr_->getElementBlock(blockId); }
267 
268  void ownedIndices(const std::vector<GlobalOrdinalT> & indices,std::vector<bool> & isOwned) const;
269 
270  void setFieldOrder(const std::vector<std::string> & fieldOrder );
271 
272  void getFieldOrder(std::vector<std::string> & fieldOrder) const;
273 
274  bool validFieldOrder(const std::vector<std::string> & proposed_fieldOrder);
275 
276  //TODO:this
278 
280  { return requireOrientations_; }
281 
283  { requireOrientations_ = ro; }
284 
287  void getElementOrientation(LocalOrdinalT localElmtId,std::vector<double> & gidsOrientation) const;
288 
289  const std::string & getFieldString(int num) const;
290 
300 
306  virtual int getElementBlockGIDCount(const std::string & blockId) const
307  { return getElementBlockGIDCount(blockIdToIndex(blockId)); }
308 
314  virtual int getElementBlockGIDCount(const std::size_t & blockIndex) const
315  { return elementBlockGIDCount_[blockIndex]; }
316 
320  void printFieldInformation(std::ostream & os) const;
321 
326  void enableTieBreak(bool enable)
327  { useTieBreak_ = enable; }
328 
334  void useNeighbors(bool flag)
335  { useNeighbors_ = flag; }
336 
337  // These functions are primarily for testing purposes
338  // they are not intended to be useful otherwise (thus they are not
339  // documented in the Doxygen style
340 
341  // Return the number of elemnts as measured by the count of GID arrays.
342  // note that this will include ghosted elements!
343  std::size_t getNumberElementGIDArrays() const
344  { return elementGIDs_.size(); }
345 
346 protected:
347 
351  runLocalRCMReordering(const Teuchos::RCP<const Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,panzer::TpetraNodeType> > &);
352 
356  std::size_t blockIdToIndex(const std::string & blockId) const;
357 
364  bool useOwned_;
366  public:
367  ElementBlockAccess(bool owned,const Teuchos::RCP<const ConnManager<LO,GO> > & connMngr)
368  : useOwned_(owned), connMngr_(connMngr) {}
369 
370  const std::vector<LO> & getElementBlock(const std::string & eBlock) const
371  {
372  if(useOwned_==true)
373  return connMngr_->getElementBlock(eBlock);
374  else
375  return connMngr_->getNeighborElementBlock(eBlock);
376  }
377  };
378 
384  buildOverlapMapFromElements(const ElementBlockAccess & access) const;
385 
390  buildTaggedMultiVector(const ElementBlockAccess & access);
391 
397  std::pair<Teuchos::RCP<Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> >,
399  buildGlobalUnknowns_GUN(const Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> & tagged_overlap_mv,
400  Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> & overlap_mv) const;
401 
402  void fillGIDsFromOverlappedMV(const ElementBlockAccess & access,
403  std::vector<std::vector< GO > > & elementGIDs,
404  const Tpetra::Map<LO,GO,panzer::TpetraNodeType> & overlapmap,
405  const Tpetra::MultiVector<GO,LO,GO,panzer::TpetraNodeType> & overlap_mv) const;
407 
410 
411  //Please note: AID=absolute ID. This is an attempt to remember that
412  // fieldPatterns_ is unchanging storage for FPs.
413  std::vector<Teuchos::RCP<const FieldPattern> > fieldPatterns_;
414  std::vector<FieldType> fieldTypes_; // FieldType for a Field Pattern. Use AID to access just like fieldPatterns_.
415  std::map<std::string,int> fieldNameToAID_;
416 
417  std::vector<std::string> blockOrder_; // To be got from the ConnManager.
418  std::map<std::string,int> blockNameToID_; // I'm not sure the above vector is needed, this might suffice.
419  std::vector<std::vector<int> > blockToAssociatedFP_; // each sub-vector is associated by
420  // a block, with ordering given in blockOrder_. ints refer to the order in fieldPatterns_;
421  std::vector<std::string> fieldStringOrder_;
422  std::vector<int> fieldAIDOrder_; // Both of these must be updated and edited together.
423  // The AID offers a simpler way to manage FPs internally.
424 
425  Teuchos::RCP<const panzer::FieldPattern> ga_fp_; // geometric aggregate field pattern
426  std::vector<Teuchos::RCP<panzer::FieldAggPattern> > fa_fps_; //Ordered by blockOrder_;
427 
428  std::vector<GO> owned_;
429  std::vector<GO> ghosted_;
430 
431  // Element GIDS ordered by LID.
432  std::vector<std::vector< GO > > elementGIDs_;
433 
434  // Mimics the functionality of the getElemenentBlockGIDCount in
435  // the original DOFManager. Indexed according to blockOrder_.
436  std::vector<int> elementBlockGIDCount_;
437 
439 
441 
443  std::vector<std::vector<signed char> > orientation_;
444 
447 };
448 
449 }
450 
451 #endif
int getNumOwned() const
Get the number of indices owned by this processor.
std::vector< GO > ghosted_
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< 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_
const Kokkos::View< const int *, PHX::Device > getGIDFieldOffsetsKokkos(const std::string &blockID, int fieldNum) const
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.
FieldType
The type of discretization to use for a field pattern.
std::vector< FieldType > fieldTypes_
virtual Teuchos::RCP< const ConnManagerBase< LocalOrdinalT > > getConnManagerBase() const
Returns the connection manager currently being used.
std::size_t getNumberElementGIDArrays() const
int getNumGhosted() const
Get the number of indices ghosted for this processor.
void ownedIndices(const std::vector< GlobalOrdinalT > &indices, std::vector< bool > &isOwned) const
Teuchos::RCP< ConnManager< LocalOrdinalT, GlobalOrdinalT > > resetIndices()
Reset the indices for this DOF manager.
int getNumOwnedAndGhosted() const
Get the number of owned and ghosted indices for this processor.
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
int addField(const std::string &str, const Teuchos::RCP< const FieldPattern > &pattern, const panzer::FieldType &type=panzer::FieldType::CG)
Add a field to the DOF manager.
void getGhostedIndices(std::vector< GlobalOrdinalT > &indices) const
Get the set of indices ghosted for this processor.
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
void setFieldOrder(const std::vector< std::string > &fieldOrder)
bool getOrientationsRequired() const
std::vector< std::vector< int > > blockToAssociatedFP_
Teuchos::RCP< const ConnManager< LO, GO > > connMngr_
void useNeighbors(bool flag)
void buildGlobalUnknowns()
builds the global unknowns array
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_
void getOwnedAndGhostedIndices(std::vector< GlobalOrdinalT > &indices) const
Get the set of owned and ghosted indices for this processor.
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< Tpetra::MultiVector< GO, LO, GO, panzer::TpetraNodeType > > buildTaggedMultiVector(const ElementBlockAccess &access)
Teuchos::RCP< const Tpetra::Map< LO, GO, panzer::TpetraNodeType > > runLocalRCMReordering(const Teuchos::RCP< const Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, panzer::TpetraNodeType > > &)
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...
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
Get the set of indices owned by this processor.
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.
std::vector< std::vector< signed char > > orientation_
std::vector< GO > owned_
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)