46 #include "Teuchos_FancyOStream.hpp"
47 #include "Teuchos_ArrayView.hpp"
48 #include "Teuchos_CommHelpers.hpp"
50 #include "Tpetra_Map.hpp"
51 #include "Tpetra_Vector.hpp"
52 #include "Tpetra_Import.hpp"
59 template <
typename LocalOrdinalT,
typename GlobalOrdinalT>
60 std::vector<Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > >
63 std::vector<Teuchos::RCP<const UniqueGlobalIndexer<LocalOrdinalT,GlobalOrdinalT> > > vec;
65 for(std::size_t blk=0;blk<ugis.size();blk++)
66 vec.push_back(ugis[blk]);
71 template <
typename LocalOrdinalT,
typename GlobalOrdinalT>
76 for(std::size_t blk=0;blk<ugis.size();blk++) {
77 fieldNum = ugis[blk]->getFieldNum(fieldName);
85 template <
typename LocalOrdinalT,
typename GlobalOrdinalT>
90 for(std::size_t blk=0;blk<ugis.size();blk++) {
91 fieldNum = ugis[blk]->getFieldNum(fieldName);
99 template <
typename LocalOrdinalT,
typename GlobalOrdinalT>
102 std::vector<int> & blockOffsets)
104 blockOffsets.resize(ugis.size()+1);
107 for(std::size_t blk=0;blk<ugis.size();blk++) {
108 blockOffsets[blk] = offset;
109 offset += ugis[blk]->getElementBlockGIDCount(blockId);
111 blockOffsets[ugis.size()] = offset;
114 template <
typename LocalOrdinalT,
typename GlobalOrdinalT>
117 std::vector<int> & blockOffsets)
119 blockOffsets.resize(ugis.size()+1);
122 for(std::size_t blk=0;blk<ugis.size();blk++) {
123 blockOffsets[blk] = offset;
124 offset += ugis[blk]->getElementBlockGIDCount(blockId);
126 blockOffsets[ugis.size()] = offset;
129 template <
typename LocalOrdinalT,
typename GlobalOrdinalT>
133 std::vector<GlobalOrdinalT> owned;
136 std::size_t myOwnedCount = owned.size();
138 std::size_t sum=0,min=0,max=0;
146 double dev2 = (double(myOwnedCount)-double(sum)/double(ugi.
getComm()->getSize()));
149 double variance = 0.0;
152 double mean = sum / double(ugi.
getComm()->getSize());
153 variance = variance / double(ugi.
getComm()->getSize());
156 std::stringstream ss;
157 ss <<
"Max, Min, Mean, StdDev = " << max <<
", " << min <<
", " << mean <<
", " << std::sqrt(variance);
162 template <
typename LocalOrdinalT,
typename GlobalOrdinalT>
166 std::vector<std::string> block_ids;
169 for(std::size_t b=0;b<block_ids.size();b++) {
171 const std::vector<LocalOrdinalT> & elements = ugi.
getElementBlock(block_ids[b]);
173 os <<
"Element Block: \"" << block_ids[b] <<
"\"" << std::endl;
176 for(std::size_t e=0;e<elements.size();e++) {
181 std::vector<GlobalOrdinalT> gids;
184 os <<
" local element id = " << elements[e] <<
", ";
187 for(std::size_t i=0;i<gids.size();i++)
188 os <<
" " << gids[i];
191 for(std::size_t i=0;i<gids.size();i++)
192 os <<
" " << lids[i];
198 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
202 typedef Tpetra::Map<int,GlobalOrdinalT,Node> Map;
203 typedef Tpetra::Vector<int,int,GlobalOrdinalT,Node> IntVector;
205 std::vector<GlobalOrdinalT> indices;
206 std::vector<std::string> blocks;
211 std::vector<int> fieldNumbers(indices.size(),-1);
218 for(std::size_t blk=0;blk<blocks.size();blk++) {
219 std::string blockId = blocks[blk];
221 const std::vector<LocalOrdinalT> & elements = ugi.
getElementBlock(blockId);
225 std::vector<GlobalOrdinalT> gids(fields.size());
226 for(std::size_t e=0;e<elements.size();e++) {
229 for(std::size_t f=0;f<fields.size();f++) {
230 int fieldNum = fields[f];
231 GlobalOrdinalT gid = gids[f];
232 std::size_t lid = ghostedMap->getLocalElement(gid);
234 fieldNumbers[lid] = fieldNum;
240 std::vector<GlobalOrdinalT> reducedIndices;
241 std::vector<int> reducedFieldNumbers;
242 for(std::size_t i=0;i<fieldNumbers.size();i++) {
243 if(fieldNumbers[i]>-1) {
244 reducedIndices.push_back(indices[i]);
245 reducedFieldNumbers.push_back(fieldNumbers[i]);
252 return Teuchos::rcp(
new IntVector(reducedMap,Teuchos::arrayViewFromVector(reducedFieldNumbers)));
255 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
257 std::vector<int> & fieldNumbers,
258 const Teuchos::RCP<
const Tpetra::Vector<int,int,GlobalOrdinalT,Node> > & reducedVec)
260 typedef Tpetra::Vector<int,int,GlobalOrdinalT,Node> IntVector;
264 fieldNumbers.resize(dest->getLocalLength());
265 dest->get1dCopy(Teuchos::arrayViewFromVector(fieldNumbers));
268 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
271 const Teuchos::RCP<
const Tpetra::Vector<int,int,GlobalOrdinalT,Node> > & reducedVec)
273 typedef Tpetra::Map<int,GlobalOrdinalT,Node> Map;
274 typedef Tpetra::Vector<int,int,GlobalOrdinalT,Node> IntVector;
275 typedef Tpetra::Import<int,GlobalOrdinalT,Node> Importer;
283 std::vector<GlobalOrdinalT> indices;
290 if(source==Teuchos::null)
291 source = buildGhostedFieldReducedVector<LocalOrdinalT,GlobalOrdinalT,Node>(ugi);
299 Importer importer(sourceMap,destMap);
301 dest->doImport(*source,importer,Tpetra::INSERT);
306 template <
typename ScalarT,
typename ArrayT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
309 const ArrayT & data,Tpetra::MultiVector<ScalarT,int,GlobalOrdinalT,Node> & dataVector)
311 typedef Tpetra::Map<int,GlobalOrdinalT,Node> Map;
314 "panzer::updateGhostedDataReducedVector: field name = \""+fieldName+
"\" is not in element block = \"" +blockId +
"\"!");
319 const std::vector<LocalOrdinalT> & elements = ugi.
getElementBlock(blockId);
323 "panzer::updateGhostedDataReducedVector: data cell dimension does not match up with block cell count");
325 int rank = data.rank();
329 std::vector<GlobalOrdinalT> gids;
330 for(std::size_t e=0;e<elements.size();e++) {
333 for(std::size_t f=0;f<fieldOffsets.size();f++) {
334 std::size_t localIndex = dataMap->getLocalElement(gids[fieldOffsets[f]]);
335 dataVector.replaceLocalValue(localIndex,0,data(e,f));
340 std::size_t entries = data.extent(2);
343 "panzer::updateGhostedDataReducedVector: number of columns in data vector inconsistent with data array");
346 std::vector<GlobalOrdinalT> gids;
347 for(std::size_t e=0;e<elements.size();e++) {
350 for(std::size_t f=0;f<fieldOffsets.size();f++) {
351 std::size_t localIndex = dataMap->getLocalElement(gids[fieldOffsets[f]]);
352 for(std::size_t v=0;v<entries;v++)
353 dataVector.replaceLocalValue(localIndex,v,data(e,f,v));
359 "panzer::updateGhostedDataReducedVector: data array rank must be 2 or 3");
364 template <
typename GlobalOrdinalT,
typename Node>
366 getFieldMap(
int fieldNum,
const Tpetra::Vector<int,int,GlobalOrdinalT,Node> & fieldTVector)
369 std::vector<int> fieldVector(fieldTVector.getLocalLength());
370 fieldTVector.get1dCopy(Teuchos::arrayViewFromVector(fieldVector));
372 std::vector<GlobalOrdinalT> mapVector;
373 for(std::size_t i=0;i<fieldVector.size();i++) {
374 if(fieldVector[i]==fieldNum)
375 mapVector.push_back(origMap->getGlobalElement(i));
379 =
Teuchos::rcp(
new Tpetra::Map<int,GlobalOrdinalT,Node>(
386 namespace orientation_helpers {
388 template <
typename GlobalOrdinalT>
390 const std::vector<GlobalOrdinalT> & topology,
392 std::vector<signed char> & orientation)
404 for(std::size_t e=0;e<topEdgeIndices.size();e++) {
406 const std::pair<int,int> nodes = topEdgeIndices[e];
409 GlobalOrdinalT v0 = topology[nodes.first];
410 GlobalOrdinalT v1 = topology[nodes.second];
413 signed char edgeOrientation = 1;
417 edgeOrientation = -1;
422 const std::vector<int> & edgeIndices = fieldPattern.
getSubcellIndices(edgeDim,e);
423 for(std::size_t s=0;s<edgeIndices.size();s++)
424 orientation[edgeIndices[s]] = edgeOrientation;
428 template <
typename GlobalOrdinalT>
430 const std::vector<GlobalOrdinalT> & topology,
432 std::vector<signed char> & orientation)
452 for(std::size_t f=0;f<topFaceIndices.size();f++) {
454 const std::vector<int> & nodes = topFaceIndices[f];
455 std::vector<GlobalOrdinalT> globals(nodes.size());
456 for(std::size_t n=0;n<nodes.size();n++)
457 globals[n] = topology[nodes[n]];
459 typename std::vector<GlobalOrdinalT>::const_iterator itr
460 = std::min_element(globals.begin(),globals.end());
463 "panzer::orientation_helpers::computeCellFaceOrientations: A face index array "
472 GlobalOrdinalT vbefore = itr==globals.begin() ? *(globals.end()-1) : *(itr-1);
473 GlobalOrdinalT vafter = (itr+1)==globals.end() ? *globals.begin() : *(itr+1);
493 signed char faceOrientation = 1;
495 faceOrientation = -1;
496 else if(vbefore>vafter)
502 const std::vector<int> & faceIndices = fieldPattern.
getSubcellIndices(faceDim,f);
503 for(std::size_t s=0;s<faceIndices.size();s++)
504 orientation[faceIndices[s]] = faceOrientation;
510 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
519 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
520 template <
typename ScalarT,
typename ArrayT>
527 int fieldNum = ugi_->getFieldNum(fieldName);
528 std::vector<std::string> blockIds;
529 ugi_->getElementBlockIds(blockIds);
532 int rank = data.begin()->second.rank();
537 numCols = data.begin()->second.extent(2);
540 "ArrayToFieldVector::getGhostedDataVector: data array must have rank 2 or 3. This array has rank " << rank <<
".");
549 if(gh_reducedFieldMaps_[fieldNum]==Teuchos::null) {
551 gh_reducedFieldMaps_[fieldNum] = reducedMap;
555 =
Teuchos::rcp(
new Tpetra::MultiVector<ScalarT,int,GlobalOrdinalT,Node>(reducedMap,numCols));
556 for(std::size_t b=0;b<blockIds.size();b++) {
557 std::string block = blockIds[b];
560 if(!ugi_->fieldInBlock(fieldName,block))
564 typename std::map<std::string,ArrayT>::const_iterator blockItr = data.find(block);
566 "ArrayToFieldVector::getDataVector: can not find block \""+block+
"\".");
568 const ArrayT & d = blockItr->second;
569 updateGhostedDataReducedVector<ScalarT,ArrayT,LocalOrdinalT,GlobalOrdinalT,Node>(fieldName,block,*ugi_,d,*finalReducedVec);
576 if(gh_fieldMaps_[fieldNum]==Teuchos::null) {
578 gh_fieldMaps_[fieldNum] = map;
582 =
Teuchos::rcp(
new Tpetra::MultiVector<ScalarT,int,GlobalOrdinalT,Node>(map,numCols));
585 Tpetra::Import<int,GlobalOrdinalT,Node> importer(reducedMap,map);
586 finalVec->doImport(*finalReducedVec,importer,Tpetra::INSERT);
591 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
592 template <
typename ScalarT,
typename ArrayT>
595 getDataVector(
const std::string & fieldName,
const std::map<std::string,ArrayT> & data)
const
598 if(fieldVector_==Teuchos::null)
599 buildFieldVector(*gh_fieldVector_);
602 = getGhostedDataVector<ScalarT,ArrayT>(fieldName,data);
605 int fieldNum = ugi_->getFieldNum(fieldName);
607 if(fieldMaps_[fieldNum]==Teuchos::null) {
609 fieldMaps_[fieldNum] = destMap;
613 =
Teuchos::rcp(
new Tpetra::MultiVector<ScalarT,int,GlobalOrdinalT,Node>(destMap,sourceVec->getNumVectors()));
616 Tpetra::Import<int,GlobalOrdinalT> importer(sourceVec->getMap(),destMap);
617 destVec->doImport(*sourceVec,importer,Tpetra::INSERT);
622 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
627 std::vector<GlobalOrdinalT> indices;
628 ugi_->getOwnedIndices(indices);
635 Tpetra::Import<int,GlobalOrdinalT> importer(source.getMap(),destMap);
636 localFieldVector->doImport(source,importer,Tpetra::INSERT);
638 fieldVector_ = localFieldVector;
641 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
649 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
654 if(fieldMaps_[fieldNum]==Teuchos::null) {
656 if(fieldVector_==Teuchos::null)
657 buildFieldVector(*gh_fieldVector_);
662 return fieldMaps_[fieldNum];
virtual bool fieldInBlock(const std::string &field, const std::string &block) const =0
const Kokkos::View< const LocalOrdinalT *, Kokkos::LayoutRight, PHX::Device > getElementLIDs(LocalOrdinalT localElmtId) const
virtual void getElementGIDs(LocalOrdinalT localElmtId, std::vector< GlobalOrdinalT > &gids, const std::string &blockIdHint="") const =0
Get the global IDs for a particular element. This function overwrites the gids variable.
int getFieldBlock(const std::string &fieldName, const std::vector< Teuchos::RCP< UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > &ugis)
virtual int getDimension() const =0
void computeCellEdgeOrientations(const std::vector< std::pair< int, int > > &topEdgeIndices, const std::vector< GlobalOrdinalT > &topology, const FieldPattern &fieldPattern, std::vector< signed char > &orientation)
virtual void getOwnedAndGhostedIndices(std::vector< GlobalOrdinalT > &indices) const =0
Get the set of owned and ghosted indices for this processor.
virtual void getElementBlockIds(std::vector< std::string > &elementBlockIds) const =0
void computeBlockOffsets(const std::string &blockId, const std::vector< Teuchos::RCP< UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > &ugis, std::vector< int > &blockOffsets)
Teuchos::RCP< Tpetra::MultiVector< ScalarT, int, GlobalOrdinalT, Node > > getGhostedDataVector(const std::string &fieldName, const std::map< std::string, ArrayT > &data) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void buildFieldVector(const Tpetra::Vector< int, int, GlobalOrdinalT, Node > &source) const
build unghosted field vector from ghosted field vector
Teuchos::RCP< const Tpetra::Map< int, GlobalOrdinalT, Node > > getFieldMap(const std::string &fieldName) const
virtual Teuchos::RCP< Teuchos::Comm< int > > getComm() const =0
virtual const std::vector< int > & getGIDFieldOffsets(const std::string &blockId, int fieldNum) const =0
Use the field pattern so that you can find a particular field in the GIDs array.
virtual int numberIds() const
Kokkos::View< const LO **, PHX::Device > lids
Teuchos::RCP< const Tpetra::Map< int, GlobalOrdinalT, Node > > getFieldMap(int fieldNum, const Tpetra::Vector< int, int, GlobalOrdinalT, Node > &fieldVector)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::vector< Teuchos::RCP< const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > nc2c_vector(const std::vector< Teuchos::RCP< UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > > &ugis)
void updateGhostedDataReducedVector(const std::string &fieldName, const std::string blockId, const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > &ugi, const ArrayT &data, Tpetra::MultiVector< ScalarT, int, GlobalOrdinalT, Node > &dataVector)
Teuchos::RCP< const Tpetra::Vector< int, int, GlobalOrdinalT, Node > > buildGhostedFieldVector(const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > &ugi, const Teuchos::RCP< const Tpetra::Vector< int, int, GlobalOrdinalT, Node > > &reducedVec=Teuchos::null)
std::string printUGILoadBalancingInformation(const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > &ugi)
Teuchos::RCP< const IntVector > gh_fieldVector_
ghosted reduced field vector
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
void printMeshTopology(std::ostream &os, const panzer::UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > &ugi)
Teuchos::RCP< Tpetra::Vector< int, int, GlobalOrdinalT, Node > > buildGhostedFieldReducedVector(const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > &ugi)
void computeCellFaceOrientations(const std::vector< std::pair< int, int > > &topEdgeIndices, const std::vector< GlobalOrdinalT > &topology, const FieldPattern &fieldPattern, std::vector< signed char > &orientation)
Teuchos::RCP< const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > ugi_
DOF mapping.
virtual int getFieldNum(const std::string &str) const =0
Get the number used for access to this field.
Tpetra::Map< int, GlobalOrdinalT, Node > Map
virtual const std::vector< int > & getSubcellIndices(int dim, int cellIndex) const =0
virtual const std::vector< int > & getBlockFieldNumbers(const std::string &blockId) const =0
virtual const std::vector< LocalOrdinalT > & getElementBlock(const std::string &blockId) const =0
#define TEUCHOS_ASSERT(assertion_test)
virtual void getOwnedIndices(std::vector< GlobalOrdinalT > &indices) const =0
Get the set of indices owned by this processor.
Teuchos::RCP< const IntVector > gh_reducedFieldVector_
Teuchos::RCP< Tpetra::MultiVector< ScalarT, int, GlobalOrdinalT, Node > > getDataVector(const std::string &fieldName, const std::map< std::string, ArrayT > &data) const
Tpetra::Vector< int, int, GlobalOrdinalT, Node > IntVector
ArrayToFieldVector()
Maps for each field (as needed)