42 #ifndef PANZER_UNIQUEGLOBALINDEXER_EPETRAUTILITIES_IMPL_HPP
43 #define PANZER_UNIQUEGLOBALINDEXER_EPETRAUTILITIES_IMPL_HPP
48 #include "Teuchos_FancyOStream.hpp"
49 #include "Teuchos_ArrayView.hpp"
50 #include "Teuchos_CommHelpers.hpp"
52 #include "Epetra_Map.h"
53 #include "Epetra_IntVector.h"
54 #include "Epetra_MultiVector.h"
55 #include "Epetra_Import.h"
56 #include "Epetra_MpiComm.h"
67 template <
typename LocalOrdinalT,
typename GlobalOrdinalT>
74 std::vector<GlobalOrdinalT> indices;
75 std::vector<std::string> blocks;
80 std::vector<int> fieldNumbers(indices.size(),-1);
84 if (mpiComm != Teuchos::null)
88 =
Teuchos::rcp(
new Map(-1, static_cast<int>(indices.size()), Teuchos::arrayViewFromVector(indices).getRawPtr(),
92 for(std::size_t blk=0;blk<blocks.size();blk++) {
93 std::string blockId = blocks[blk];
95 const std::vector<LocalOrdinalT> & elements = ugi.
getElementBlock(blockId);
99 std::vector<GlobalOrdinalT> gids(fields.size());
100 for(std::size_t e=0;e<elements.size();e++) {
103 for(std::size_t f=0;f<fields.size();f++) {
104 int fieldNum = fields[f];
105 GlobalOrdinalT gid = gids[f];
106 std::size_t lid = ghostedMap->LID(gid);
108 fieldNumbers[lid] = fieldNum;
114 std::vector<GlobalOrdinalT> reducedIndices;
115 std::vector<int> reducedFieldNumbers;
116 for(std::size_t i=0;i<fieldNumbers.size();i++) {
117 if(fieldNumbers[i]>-1) {
118 reducedIndices.push_back(indices[i]);
119 reducedFieldNumbers.push_back(fieldNumbers[i]);
124 =
Teuchos::rcp(
new Map(-1, static_cast<int>(reducedIndices.size()), Teuchos::arrayViewFromVector(reducedIndices).getRawPtr(),
126 return Teuchos::rcp(
new IntVector(
Copy,*reducedMap,Teuchos::arrayViewFromVector(reducedFieldNumbers).getRawPtr()));
129 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
131 std::vector<int> & fieldNumbers,
138 fieldNumbers.resize(dest->MyLength());
143 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
158 std::vector<GlobalOrdinalT> indices;
163 if (mpiComm != Teuchos::null)
166 destMap =
Teuchos::rcp(
new Map(-1, static_cast<int>(indices.size()), Teuchos::arrayViewFromVector(indices).getRawPtr(),
171 if(source==Teuchos::null)
172 source = buildGhostedFieldReducedVectorEpetra<LocalOrdinalT,GlobalOrdinalT>(ugi);
180 Importer importer(*destMap,*sourceMap);
182 dest->Import(*source,importer,
Insert);
187 template <
typename ScalarT,
typename ArrayT,
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
195 "panzer::updateGhostedDataReducedVector: field name = \""+fieldName+
"\" is not in element block = \"" +blockId +
"\"!");
200 const std::vector<LocalOrdinalT> & elements = ugi.
getElementBlock(blockId);
204 "panzer::updateGhostedDataReducedVector: data cell dimension does not match up with block cell count");
206 int rank = data.rank();
210 std::vector<GlobalOrdinalT> gids;
211 for(std::size_t e=0;e<elements.size();e++) {
214 for(std::size_t f=0;f<fieldOffsets.size();f++) {
215 std::size_t localIndex = dataMap->LID(gids[fieldOffsets[f]]);
216 dataVector.ReplaceMyValue(localIndex,0,data(e,f));
221 std::size_t entries = data.extent(2);
224 "panzer::updateGhostedDataReducedVector: number of columns in data vector inconsistent with data array");
227 std::vector<GlobalOrdinalT> gids;
228 for(std::size_t e=0;e<elements.size();e++) {
231 for(std::size_t f=0;f<fieldOffsets.size();f++) {
232 std::size_t localIndex = dataMap->LID(gids[fieldOffsets[f]]);
233 for(std::size_t v=0;v<entries;v++)
234 dataVector.ReplaceMyValue(localIndex,v,data(e,f,v));
240 "panzer::updateGhostedDataReducedVector: data array rank must be 2 or 3");
244 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
253 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
254 template <
typename ScalarT,
typename ArrayT>
261 int fieldNum = ugi_->getFieldNum(fieldName);
262 std::vector<std::string> blockIds;
263 ugi_->getElementBlockIds(blockIds);
266 int rank = data.begin()->second.rank();
271 numCols = data.begin()->second.extent(2);
274 "ArrayToFieldVectorEpetra::getGhostedDataVector: data array must have rank 2 or 3. This array has rank " << rank <<
".");
283 if(gh_reducedFieldMaps_[fieldNum]==Teuchos::null) {
285 gh_reducedFieldMaps_[fieldNum] = reducedMap;
290 for(std::size_t b=0;b<blockIds.size();b++) {
291 std::string block = blockIds[b];
294 if(!ugi_->fieldInBlock(fieldName,block))
298 typename std::map<std::string,ArrayT>::const_iterator blockItr = data.find(block);
300 "ArrayToFieldVectorEpetra::getDataVector: can not find block \""+block+
"\".");
302 const ArrayT & d = blockItr->second;
303 updateGhostedDataReducedVectorEpetra<ScalarT,ArrayT,LocalOrdinalT,GlobalOrdinalT,Node>(fieldName,block,*ugi_,d,*finalReducedVec);
310 if(gh_fieldMaps_[fieldNum]==Teuchos::null) {
312 gh_fieldMaps_[fieldNum] = map;
320 finalVec->Import(*finalReducedVec,importer,
Insert);
325 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
326 template <
typename ScalarT,
typename ArrayT>
329 getDataVector(
const std::string & fieldName,
const std::map<std::string,ArrayT> & data)
const
332 if(fieldVector_==Teuchos::null)
333 buildFieldVector(*gh_fieldVector_);
336 = getGhostedDataVector<ScalarT,ArrayT>(fieldName,data);
339 int fieldNum = ugi_->getFieldNum(fieldName);
341 if(fieldMaps_[fieldNum]==Teuchos::null) {
343 fieldMaps_[fieldNum] = destMap;
351 destVec->Import(*sourceVec,importer,
Insert);
356 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
361 std::vector<GlobalOrdinalT> indices;
362 ugi_->getOwnedIndices(indices);
366 if (mpiComm != Teuchos::null)
371 Teuchos::arrayViewFromVector(indices).getRawPtr(),
378 localFieldVector->Import(source,importer,
Insert);
380 fieldVector_ = localFieldVector;
383 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
391 template <
typename LocalOrdinalT,
typename GlobalOrdinalT,
typename Node>
396 if(fieldMaps_[fieldNum]==Teuchos::null) {
398 if(fieldVector_==Teuchos::null)
399 buildFieldVector(*gh_fieldVector_);
404 return fieldMaps_[fieldNum];
virtual bool fieldInBlock(const std::string &field, const std::string &block) const =0
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.
void buildFieldVector(const Epetra_IntVector &source) const
build unghosted field vector from ghosted field vector
Teuchos::RCP< Epetra_MultiVector > getDataVector(const std::string &fieldName, const std::map< std::string, ArrayT > &data) const
Teuchos::RCP< const IntVector > gh_reducedFieldVector_
ArrayToFieldVectorEpetra()
Maps for each field (as needed)
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
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual Teuchos::RCP< Teuchos::Comm< int > > getComm() const =0
Teuchos::RCP< Epetra_MultiVector > getGhostedDataVector(const std::string &fieldName, const std::map< std::string, ArrayT > &data) const
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.
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)
Teuchos::RCP< Epetra_IntVector > buildGhostedFieldReducedVectorEpetra(const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > &ugi)
void updateGhostedDataReducedVectorEpetra(const std::string &fieldName, const std::string blockId, const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > &ugi, const ArrayT &data, Epetra_MultiVector &dataVector)
Teuchos::RCP< const Epetra_BlockMap > getFieldMapEpetra(int fieldNum, const Epetra_IntVector &fieldTVector)
Teuchos::RCP< const Epetra_IntVector > buildGhostedFieldVectorEpetra(const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > &ugi, const Teuchos::RCP< const Epetra_IntVector > &reducedVec=Teuchos::null)
Teuchos::RCP< const IntVector > gh_fieldVector_
ghosted reduced field vector
virtual int getFieldNum(const std::string &str) const =0
Get the number used for access to this field.
Teuchos::RCP< const UniqueGlobalIndexer< LocalOrdinalT, GlobalOrdinalT > > ugi_
DOF mapping.
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)
Teuchos::RCP< const Epetra_Map > getFieldMap(const std::string &fieldName) const