14 #include "Teuchos_FancyOStream.hpp"
15 #include "Teuchos_ArrayView.hpp"
16 #include "Teuchos_CommHelpers.hpp"
18 #include "Tpetra_Map.hpp"
19 #include "Tpetra_Vector.hpp"
20 #include "Tpetra_Import.hpp"
22 #include "Kokkos_DynRankView.hpp"
29 template <
typename ScalarT,
typename ArrayT>
32 const ArrayT & data,Tpetra::MultiVector<ScalarT,int,panzer::GlobalOrdinal,panzer::TpetraNodeType> & dataVector)
34 typedef Tpetra::Map<int,panzer::GlobalOrdinal,panzer::TpetraNodeType> Map;
37 "panzer::updateGhostedDataReducedVector: field name = \""+fieldName+
"\" is not in element block = \"" +blockId +
"\"!");
42 const std::vector<panzer::LocalOrdinal> & elements = ugi.
getElementBlock(blockId);
46 "panzer::updateGhostedDataReducedVector: data cell dimension does not match up with block cell count");
48 int rank = data.rank();
49 auto dataVector_host = dataVector.getLocalViewHost(Tpetra::Access::ReadWrite);
50 auto data_host = Kokkos::create_mirror_view(data);
51 Kokkos::deep_copy(data_host,data);
55 std::vector<panzer::GlobalOrdinal> gids;
56 for(std::size_t e=0;e<elements.size();e++) {
59 for(std::size_t f=0;f<fieldOffsets.size();f++) {
60 std::size_t localIndex = dataMap->getLocalElement(gids[fieldOffsets[f]]);
61 dataVector_host(localIndex,0) = data_host(e,f);
66 std::size_t entries = data.extent(2);
69 "panzer::updateGhostedDataReducedVector: number of columns in data vector inconsistent with data array");
72 std::vector<panzer::GlobalOrdinal> gids;
73 for(std::size_t e=0;e<elements.size();e++) {
76 for(std::size_t f=0;f<fieldOffsets.size();f++) {
77 std::size_t localIndex = dataMap->getLocalElement(gids[fieldOffsets[f]]);
78 for(std::size_t v=0;v<entries;v++)
79 dataVector_host(localIndex,v) = data_host(e,f,v);
85 "panzer::updateGhostedDataReducedVector: data array rank must be 2 or 3");
88 template <
typename ScalarT,
typename ArrayT>
94 int fieldNum =
ugi_->getFieldNum(fieldName);
95 std::vector<std::string> blockIds;
96 ugi_->getElementBlockIds(blockIds);
99 int rank = data.begin()->second.rank();
104 numCols = data.begin()->second.extent(2);
107 "ArrayToFieldVector::getGhostedDataVector: data array must have rank 2 or 3. This array has rank " << rank <<
".");
122 =
Teuchos::rcp(
new Tpetra::MultiVector<ScalarT,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(reducedMap,numCols));
123 for(std::size_t b=0;b<blockIds.size();b++) {
124 std::string block = blockIds[b];
127 if(!
ugi_->fieldInBlock(fieldName,block))
131 typename std::map<std::string,ArrayT>::const_iterator blockItr = data.find(block);
133 "ArrayToFieldVector::getDataVector: can not find block \""+block+
"\".");
135 const ArrayT & d = blockItr->second;
136 updateGhostedDataReducedVector<ScalarT,ArrayT>(fieldName,block,*
ugi_,d,*finalReducedVec);
149 =
Teuchos::rcp(
new Tpetra::MultiVector<ScalarT,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(map,numCols));
152 Tpetra::Import<int,panzer::GlobalOrdinal,panzer::TpetraNodeType> importer(reducedMap,map);
153 finalVec->doImport(*finalReducedVec,importer,Tpetra::INSERT);
154 PHX::Device::execution_space().fence();
159 template <
typename ScalarT,
typename ArrayT>
168 = getGhostedDataVector<ScalarT,ArrayT>(fieldName,data);
171 int fieldNum =
ugi_->getFieldNum(fieldName);
179 =
Teuchos::rcp(
new Tpetra::MultiVector<ScalarT,int,panzer::GlobalOrdinal,panzer::TpetraNodeType>(destMap,sourceVec->getNumVectors()));
182 Tpetra::Import<int,panzer::GlobalOrdinal,panzer::TpetraNodeType> importer(sourceVec->getMap(),destMap);
183 destVec->doImport(*sourceVec,importer,Tpetra::INSERT);
184 PHX::Device::execution_space().fence();
std::map< int, Teuchos::RCP< const Map > > fieldMaps_
(unghosted) field vector (as needed)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::map< int, Teuchos::RCP< const Map > > gh_fieldMaps_
Maps for each field (as needed)
Teuchos::RCP< const IntVector > gh_reducedFieldVector_
virtual const std::vector< panzer::LocalOrdinal > & getElementBlock(const std::string &blockId) const =0
std::map< int, Teuchos::RCP< const Map > > gh_reducedFieldMaps_
ghosted field vector
Teuchos::RCP< const IntVector > gh_fieldVector_
ghosted reduced field vector
Teuchos::RCP< const Tpetra::Map< int, panzer::GlobalOrdinal, panzer::TpetraNodeType > > getFieldMap(int fieldNum, const Tpetra::Vector< int, int, panzer::GlobalOrdinal, panzer::TpetraNodeType > &fieldTVector)
virtual bool fieldInBlock(const std::string &field, const std::string &block) const =0
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void updateGhostedDataReducedVector(const std::string &fieldName, const std::string blockId, const GlobalIndexer &ugi, const ArrayT &data, Tpetra::MultiVector< ScalarT, int, panzer::GlobalOrdinal, panzer::TpetraNodeType > &dataVector)
Teuchos::RCP< const GlobalIndexer > ugi_
DOF mapping.
Teuchos::RCP< Tpetra::MultiVector< ScalarT, int, panzer::GlobalOrdinal, panzer::TpetraNodeType > > getGhostedDataVector(const std::string &fieldName, const std::map< std::string, ArrayT > &data) const
virtual int getFieldNum(const std::string &str) const =0
Get the number used for access to this field.
Teuchos::RCP< Tpetra::MultiVector< ScalarT, int, panzer::GlobalOrdinal, panzer::TpetraNodeType > > getDataVector(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.
virtual void getElementGIDs(panzer::LocalOrdinal localElmtId, std::vector< panzer::GlobalOrdinal > &gids, const std::string &blockIdHint="") const =0
Get the global IDs for a particular element. This function overwrites the gids variable.
void buildFieldVector(const Tpetra::Vector< int, int, panzer::GlobalOrdinal, panzer::TpetraNodeType > &source) const
build unghosted field vector from ghosted field vector
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< const IntVector > fieldVector_
Maps for each field (as needed)