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"
54 #include "Panzer_GlobalIndexer.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 class DOFManager : public GlobalIndexer {
67 public:
68 
69  virtual ~DOFManager() {}
70 
71  DOFManager();
72 
77  DOFManager(const Teuchos::RCP<ConnManager> & connMngr, MPI_Comm mpiComm);
78 
80  void setConnManager(const Teuchos::RCP<ConnManager> & connMngr, MPI_Comm mpiComm);
81 
83  { return connMngr_; }
84 
98  int addField(const std::string & str, const Teuchos::RCP<const FieldPattern> & pattern,
100 
115  int addField(const std::string & blockID, const std::string & str,
116  const Teuchos::RCP<const FieldPattern> & pattern,
118 
132  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & name) const;
133 
147  Teuchos::RCP<const FieldPattern> getFieldPattern(const std::string & blockId, const std::string & fieldName) const;
148 
155  void getOwnedIndices(std::vector<panzer::GlobalOrdinal>& indices) const;
156 
163  void getGhostedIndices(std::vector<panzer::GlobalOrdinal>& indices) const;
164 
171  void getOwnedAndGhostedIndices(std::vector<panzer::GlobalOrdinal>& indices) const;
172 
173  // Epetra specifiic interfaces. Will be deprecated.
174  void getElementGIDsAsInt(panzer::LocalOrdinal localElementID, std::vector<int> & gids, const std::string & blockIdHint="") const;
175  void getOwnedIndicesAsInt(std::vector<int>& indices) const;
176  void getGhostedIndicesAsInt(std::vector<int>& indices) const;
177  void getOwnedAndGhostedIndicesAsInt(std::vector<int>& indices) const;
178 
184  int
185  getNumOwned() const;
186 
192  int
193  getNumGhosted() const;
194 
200  int
201  getNumOwnedAndGhosted() const;
202 
204  int getNumFields() const;
205 
209  const std::vector<int> & getGIDFieldOffsets(const std::string & blockID, int fieldNum) const;
210 
214  const Kokkos::View<const int*,PHX::Device> getGIDFieldOffsetsKokkos(const std::string & blockID, int fieldNum) const;
215 
217  void getElementGIDs(panzer::LocalOrdinal localElementID, std::vector<panzer::GlobalOrdinal> & gids, const std::string & blockIdHint="") const;
218 
220  void buildGlobalUnknowns();
221 
223  void buildGlobalUnknowns(const Teuchos::RCP<const FieldPattern> & geomPattern);
224 
225  int getFieldNum(const std::string & string) const;
226 
228  { return communicator_; }
229 
231  { return ga_fp_; }
232 
233  void getElementBlockIds(std::vector<std::string> & elementBlockIds) const
234  { connMngr_->getElementBlockIds(elementBlockIds); }
235 
236  bool fieldInBlock(const std::string & field, const std::string & block) const;
237 
238  const std::vector<int> & getBlockFieldNumbers(const std::string & blockId) const;
239 
240 //************************************************************************
241 
254  const std::pair<std::vector<int>,std::vector<int> > &
255  getGIDFieldOffsets_closure(const std::string & blockId, int fieldNum, int subcellDim,int subcellId) const;
256 
258  const std::vector<panzer::LocalOrdinal> & getElementBlock(const std::string & blockId) const
259  { return connMngr_->getElementBlock(blockId); }
260 
261  void ownedIndices(const std::vector<panzer::GlobalOrdinal> & indices,std::vector<bool> & isOwned) const;
262 
263  void setFieldOrder(const std::vector<std::string> & fieldOrder );
264 
265  void getFieldOrder(std::vector<std::string> & fieldOrder) const;
266 
267  bool validFieldOrder(const std::vector<std::string> & proposed_fieldOrder);
268 
269  //TODO:this
271 
273  { return requireOrientations_; }
274 
276  { requireOrientations_ = ro; }
277 
280  void getElementOrientation(panzer::LocalOrdinal localElmtId,std::vector<double> & gidsOrientation) const;
281 
282  const std::string & getFieldString(int num) const;
283 
293 
299  virtual int getElementBlockGIDCount(const std::string & blockId) const
300  { return getElementBlockGIDCount(blockIdToIndex(blockId)); }
301 
307  virtual int getElementBlockGIDCount(const std::size_t & blockIndex) const
308  { return elementBlockGIDCount_[blockIndex]; }
309 
313  void printFieldInformation(std::ostream & os) const;
314 
319  void enableTieBreak(bool enable)
320  { useTieBreak_ = enable; }
321 
327  void useNeighbors(bool flag)
328  { useNeighbors_ = flag; }
329 
330  // These functions are primarily for testing purposes
331  // they are not intended to be useful otherwise (thus they are not
332  // documented in the Doxygen style
333 
334  // Return the number of elemnts as measured by the count of GID arrays.
335  // note that this will include ghosted elements!
336  std::size_t getNumberElementGIDArrays() const
337  { return elementGIDs_.size(); }
338 
339 protected:
340 
344  runLocalRCMReordering(const Teuchos::RCP<const Tpetra::Map<panzer::LocalOrdinal,panzer::GlobalOrdinal,panzer::TpetraNodeType> > &);
345 
349  std::size_t blockIdToIndex(const std::string & blockId) const;
350 
357  bool useOwned_;
359  public:
361  : useOwned_(owned), connMngr_(connMngr) {}
362 
363  const std::vector<panzer::LocalOrdinal> & getElementBlock(const std::string & eBlock) const
364  {
365  if(useOwned_==true)
366  return connMngr_->getElementBlock(eBlock);
367  else
368  return connMngr_->getNeighborElementBlock(eBlock);
369  }
370  };
371 
377  buildOverlapMapFromElements(const ElementBlockAccess & access) const;
378 
383  buildTaggedMultiVector(const ElementBlockAccess & access);
384 
390  std::pair<Teuchos::RCP<Tpetra::MultiVector<panzer::GlobalOrdinal,panzer::LocalOrdinal,panzer::GlobalOrdinal,panzer::TpetraNodeType> >,
392  buildGlobalUnknowns_GUN(const Tpetra::MultiVector<panzer::GlobalOrdinal,panzer::LocalOrdinal,panzer::GlobalOrdinal,panzer::TpetraNodeType> & tagged_overlap_mv,
393  Tpetra::MultiVector<panzer::GlobalOrdinal,panzer::LocalOrdinal,panzer::GlobalOrdinal,panzer::TpetraNodeType> & overlap_mv) const;
394 
395  void fillGIDsFromOverlappedMV(const ElementBlockAccess & access,
396  std::vector<std::vector< panzer::GlobalOrdinal > > & elementGIDs,
397  const Tpetra::Map<panzer::LocalOrdinal,panzer::GlobalOrdinal,panzer::TpetraNodeType> & overlapmap,
398  const Tpetra::MultiVector<panzer::GlobalOrdinal,panzer::LocalOrdinal,panzer::GlobalOrdinal,panzer::TpetraNodeType> & overlap_mv) const;
400 
403 
404  //Please note: AID=absolute ID. This is an attempt to remember that
405  // fieldPatterns_ is unchanging storage for FPs.
406  std::vector<Teuchos::RCP<const FieldPattern> > fieldPatterns_;
407  std::vector<FieldType> fieldTypes_; // FieldType for a Field Pattern. Use AID to access just like fieldPatterns_.
408  std::map<std::string,int> fieldNameToAID_;
409 
410  std::vector<std::string> blockOrder_; // Get this from the ConnManager.
411  std::map<std::string,int> blockNameToID_; // I'm not sure the above vector is needed, this might suffice.
412  std::vector<std::vector<int> > blockToAssociatedFP_; // each sub-vector is associated by
413  // a block, with ordering given in blockOrder_. ints refer to the order in fieldPatterns_;
414  std::vector<std::string> fieldStringOrder_;
415  std::vector<int> fieldAIDOrder_; // Both of these must be updated and edited together.
416  // The AID offers a simpler way to manage FPs internally.
417 
418  Teuchos::RCP<const panzer::FieldPattern> ga_fp_; // geometric aggregate field pattern
419  std::vector<Teuchos::RCP<panzer::FieldAggPattern> > fa_fps_; //Ordered by blockOrder_;
420 
421  std::vector<panzer::GlobalOrdinal> owned_;
422  std::vector<panzer::GlobalOrdinal> ghosted_;
423 
424  // Element GIDS ordered by LID.
425  std::vector<std::vector< panzer::GlobalOrdinal > > elementGIDs_;
426 
427  // Mimics the functionality of the getElemenentBlockGIDCount in
428  // the original DOFManager. Indexed according to blockOrder_.
429  std::vector<int> elementBlockGIDCount_;
430 
432 
434 
436  std::vector<std::vector<signed char> > orientation_;
437 
440 };
441 
442 }
443 
444 #endif
std::vector< std::vector< int > > blockToAssociatedFP_
bool fieldInBlock(const std::string &field, const std::string &block) const
int getNumFields() const
gets the number of fields
virtual int getElementBlockGIDCount(const std::string &blockId) const
How any GIDs are associate with a particular element block.
bool getOrientationsRequired() const
int getNumOwnedAndGhosted() const
Get the number of owned and ghosted indices for this processor.
void getElementBlockIds(std::vector< std::string > &elementBlockIds) const
void setFieldOrder(const std::vector< std::string > &fieldOrder)
std::vector< Teuchos::RCP< panzer::FieldAggPattern > > fa_fps_
const std::vector< panzer::LocalOrdinal > & getElementBlock(const std::string &eBlock) const
Teuchos::RCP< const Tpetra::Map< panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > > buildOverlapMapFromElements(const ElementBlockAccess &access) const
const Kokkos::View< const int *, PHX::Device > getGIDFieldOffsetsKokkos(const std::string &blockID, int fieldNum) const
std::vector< std::vector< panzer::GlobalOrdinal > > elementGIDs_
void getOwnedIndices(std::vector< panzer::GlobalOrdinal > &indices) const
Get the set of indices owned by this processor.
void enableTieBreak(bool enable)
Teuchos::RCP< Tpetra::MultiVector< panzer::GlobalOrdinal, panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > > buildTaggedMultiVector(const ElementBlockAccess &access)
void useNeighbors(bool flag)
FieldType
The type of discretization to use for a field pattern.
ElementBlockAccess(bool owned, const Teuchos::RCP< const ConnManager > &connMngr)
Teuchos::RCP< ConnManager > resetIndices()
Reset the indices for this DOF manager.
void buildGlobalUnknowns()
builds the global unknowns array
Teuchos::RCP< const panzer::FieldPattern > ga_fp_
void getFieldOrder(std::vector< std::string > &fieldOrder) const
void setOrientationsRequired(bool ro)
void getGhostedIndicesAsInt(std::vector< int > &indices) const
Get the set of indices ghosted for this processor.
const std::vector< int > & getGIDFieldOffsets(const std::string &blockID, int fieldNum) const
std::vector< int > fieldAIDOrder_
void setConnManager(const Teuchos::RCP< ConnManager > &connMngr, MPI_Comm mpiComm)
Adds a Connection Manager that will be associated with this DOFManager.
std::map< std::string, int > fieldNameToAID_
std::vector< int > elementBlockGIDCount_
Teuchos::RCP< Teuchos::Comm< int > > communicator_
Teuchos::RCP< const ConnManager > getConnManager() const
Returns the connection manager currently being used.
Teuchos::RCP< const FieldPattern > getGeometricFieldPattern() const
void printFieldInformation(std::ostream &os) const
std::vector< Teuchos::RCP< const FieldPattern > > fieldPatterns_
std::pair< Teuchos::RCP< Tpetra::MultiVector< panzer::GlobalOrdinal, panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > >, Teuchos::RCP< Tpetra::MultiVector< panzer::GlobalOrdinal, panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > > > buildGlobalUnknowns_GUN(const Tpetra::MultiVector< panzer::GlobalOrdinal, panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > &tagged_overlap_mv, Tpetra::MultiVector< panzer::GlobalOrdinal, panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > &overlap_mv) const
Teuchos::RCP< const Tpetra::Map< panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > > runLocalRCMReordering(const Teuchos::RCP< const Tpetra::Map< panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > > &)
void getOwnedIndicesAsInt(std::vector< int > &indices) const
Get the set of indices owned by this processor.
void fillGIDsFromOverlappedMV(const ElementBlockAccess &access, std::vector< std::vector< panzer::GlobalOrdinal > > &elementGIDs, const Tpetra::Map< panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > &overlapmap, const Tpetra::MultiVector< panzer::GlobalOrdinal, panzer::LocalOrdinal, panzer::GlobalOrdinal, panzer::TpetraNodeType > &overlap_mv) const
int getNumGhosted() const
Get the number of indices ghosted for this processor.
std::vector< panzer::GlobalOrdinal > owned_
void ownedIndices(const std::vector< panzer::GlobalOrdinal > &indices, std::vector< bool > &isOwned) const
std::vector< std::string > blockOrder_
std::vector< panzer::GlobalOrdinal > ghosted_
Teuchos::RCP< Teuchos::Comm< int > > getComm() const
std::size_t blockIdToIndex(const std::string &blockId) const
Teuchos::RCP< ConnManager > connMngr_
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...
void buildLocalIdsFromOwnedAndGhostedElements()
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.
const std::string & getFieldString(int num) const
Reverse lookup of the field string from a field number.
void getGhostedIndices(std::vector< panzer::GlobalOrdinal > &indices) const
Get the set of indices ghosted for this processor.
std::vector< std::string > fieldStringOrder_
void getElementGIDsAsInt(panzer::LocalOrdinal localElementID, std::vector< int > &gids, const std::string &blockIdHint="") const
Get the global IDs for a particular element. This function overwrites the gids variable.
int getNumOwned() const
Get the number of indices owned by this processor.
Teuchos::RCP< const ConnManager > connMngr_
void getOwnedAndGhostedIndicesAsInt(std::vector< int > &indices) const
Get the set of owned and ghosted indices for this processor.
void getElementOrientation(panzer::LocalOrdinal localElmtId, std::vector< double > &gidsOrientation) const
Get a vector containg the orientation of the GIDs relative to the neighbors.
const std::vector< int > & getBlockFieldNumbers(const std::string &blockId) const
void getOwnedAndGhostedIndices(std::vector< panzer::GlobalOrdinal > &indices) const
Get the set of owned and ghosted indices for this processor.
std::size_t getNumberElementGIDArrays() const
bool validFieldOrder(const std::vector< std::string > &proposed_fieldOrder)
std::vector< std::vector< signed char > > orientation_
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.
virtual int getElementBlockGIDCount(const std::size_t &blockIndex) const
How any GIDs are associate with a particular element block.
const std::vector< panzer::LocalOrdinal > & getElementBlock(const std::string &blockId) const
Get the owned element block.
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(panzer::LocalOrdinal localElementID, std::vector< panzer::GlobalOrdinal > &gids, const std::string &blockIdHint="") const
get associated GIDs for a given local element
std::vector< FieldType > fieldTypes_
std::map< std::string, int > blockNameToID_