13 #include <stk_mesh/base/GetEntities.hpp>
14 #include <stk_mesh/base/FieldBase.hpp>
17 #include "Tpetra_Map.hpp"
18 #include "Tpetra_Import.hpp"
19 #include "Tpetra_Vector.hpp"
21 #include "Teuchos_FancyOStream.hpp"
23 namespace panzer_stk {
25 namespace periodic_helpers {
29 const std::vector<std::pair<std::size_t,std::size_t> > & locallyMatchedIds,
32 using LO = panzer::LocalOrdinal;
33 using GO = panzer::GlobalOrdinal;
35 using Map = Tpetra::Map<LO,GO,NODE>;
36 using Importer = Tpetra::Import<LO,GO,NODE>;
42 int myVal = failure ? 1 : 0;
47 std::vector<GO> requiredInts(locallyRequiredIds.size());
48 for(std::size_t i=0;i<requiredInts.size();i++)
49 requiredInts[i] = locallyRequiredIds[i];
51 std::vector<GO> providedInts(locallyMatchedIds.size());
52 for(std::size_t i=0;i<locallyMatchedIds.size();i++)
53 providedInts[i] = locallyMatchedIds[i].first;
59 Importer importer(providedMap,requiredMap);
62 Tpetra::Vector<GO,LO,GO,NODE> providedVector(providedMap);
64 auto pvHost = providedVector.getLocalViewHost(Tpetra::Access::OverwriteAll);
65 for(std::size_t i=0;i<locallyMatchedIds.size();i++)
66 pvHost(i,0) = locallyMatchedIds[i].second;
69 Tpetra::Vector<GO,LO,GO,NODE> requiredVector(requiredMap);
70 requiredVector.doImport(providedVector,importer,Tpetra::INSERT);
74 =
Teuchos::rcp(
new std::vector<std::pair<std::size_t,std::size_t> >(requiredInts.size()));
76 auto rvHost = requiredVector.getLocalViewHost(Tpetra::Access::ReadOnly);
77 for(std::size_t i=0;i<result->size();i++) {
78 (*result)[i].first = requiredInts[i];
79 (*result)[i].second = rvHost(i,0);
91 const std::string & sideName,
const std::string type_)
99 ss <<
"Can't find part=\"" << sideName <<
"\"" << std::endl;
100 stk::mesh::Part * side = metaData->get_part(sideName,ss.str().c_str());
101 stk::mesh::Selector mySides = *side & (metaData->locally_owned_part() | metaData->globally_shared_part());
103 stk::mesh::EntityRank rank;
104 panzer::GlobalOrdinal offset = 0;
105 if(type_ ==
"coord"){
107 }
else if(type_ ==
"edge"){
110 }
else if(type_ ==
"face"){
114 ss <<
"Can't do BCs of type " << type_ << std::endl;
118 std::vector<stk::mesh::Bucket*>
const& nodeBuckets =
119 bulkData->get_buckets(rank, mySides);
123 std::size_t nodeCount = 0;
124 for(std::size_t b=0;b<nodeBuckets.size();b++)
125 nodeCount += nodeBuckets[b]->size();
128 =
Teuchos::rcp(
new std::vector<std::size_t>(nodeCount));
131 for(std::size_t b=0,index=0;b<nodeBuckets.size();b++) {
132 stk::mesh::Bucket & bucket = *nodeBuckets[b];
134 for(std::size_t n=0;n<bucket.size();n++,index++)
135 (*sideIds)[index] = bulkData->identifier(bucket[n]) + offset;
141 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
144 const std::string & sideName,
const std::string type_)
153 std::stringstream ss;
154 ss <<
"Can't find part=\"" << sideName <<
"\"" << std::endl;
155 stk::mesh::Part * side = metaData->get_part(sideName,ss.str().c_str());
156 stk::mesh::Selector mySides = (*side) & metaData->locally_owned_part();
158 stk::mesh::EntityRank rank;
160 stk::mesh::EntityId offset = 0;
161 if(type_ ==
"coord"){
164 }
else if(type_ ==
"edge"){
168 }
else if(type_ ==
"face"){
173 ss <<
"Can't do BCs of type " << type_ << std::endl;
177 std::vector<stk::mesh::Bucket*>
const& nodeBuckets =
178 bulkData->get_buckets(rank, mySides);
182 std::size_t nodeCount = 0;
183 for(std::size_t b=0;b<nodeBuckets.size();b++)
184 nodeCount += nodeBuckets[b]->size();
187 =
Teuchos::rcp(
new std::vector<std::size_t>(nodeCount));
192 for(std::size_t b=0,index=0;b<nodeBuckets.size();b++) {
193 stk::mesh::Bucket & bucket = *nodeBuckets[b];
194 double const* array = stk::mesh::field_data(*field, bucket);
196 for(std::size_t n=0;n<bucket.size();n++,index++) {
197 (*sideIds)[index] = bulkData->identifier(bucket[n]) + offset;
201 for(std::size_t d=0;d<physicalDim;d++)
202 coord[d] = array[physicalDim*n + d];
206 for(std::size_t d=physicalDim;d<3;d++)
211 return std::make_pair(sideIds,sideCoords);
214 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
217 const std::string & sideName,
const std::string type_)
221 using LO = panzer::LocalOrdinal;
222 using GO = panzer::GlobalOrdinal;
224 using Map = Tpetra::Map<LO,GO,NODE>;
225 using Importer = Tpetra::Import<LO,GO,NODE>;
236 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
240 std::vector<std::size_t> & local_side_ids = *sidePair.first;
241 std::vector<Teuchos::Tuple<double,3> > & local_side_coords = *sidePair.second;
242 std::size_t nodeCount = local_side_ids.size();
246 RCP<Map> idMap_ =
rcp(
new Map(computeInternally,nodeCount,0,comm));
252 auto lidHost = localIdVec_->getLocalViewHost(Tpetra::Access::OverwriteAll);
253 auto lcoordHost = localCoordVec_->getLocalViewHost(Tpetra::Access::OverwriteAll);
254 for(std::size_t n=0;n<local_side_ids.size();n++) {
255 std::size_t nodeId = local_side_ids[n];
258 lidHost(n,0) =
static_cast<GO
>(nodeId);
259 for(
unsigned d=0;d<physicalDim;d++)
260 lcoordHost(n,d) = coords[d];
268 std::size_t dist_nodeCount = idMap_->getGlobalNumElements();
271 RCP<Map> distMap_ =
rcp(
new Map(dist_nodeCount,0,comm,Tpetra::LocallyReplicated));
276 Importer importer_(idMap_,distMap_);
277 distIdVec_->doImport(*localIdVec_,importer_,Tpetra::INSERT);
278 distCoordVec_->doImport(*localCoordVec_,importer_,Tpetra::INSERT);
284 =
Teuchos::rcp(
new std::vector<std::size_t>(dist_nodeCount));
289 const auto didHost = distIdVec_->getLocalViewHost(Tpetra::Access::ReadOnly);
290 const auto dcoordHost = distCoordVec_->getLocalViewHost(Tpetra::Access::ReadOnly);
291 for(std::size_t n=0;n<dist_side_ids->size();++n) {
292 (*dist_side_ids)[n] = didHost(n,0);
295 for(
unsigned d=0;d<physicalDim;++d) {
296 coords[d] = dcoordHost(n,d);
299 for(
unsigned d=physicalDim;d<3;++d)
303 return std::make_pair(dist_side_ids,dist_side_coords);
stk::mesh::Field< double > VectorFieldType
Teuchos::RCP< std::vector< std::size_t > > getLocalSideIds(const STK_Interface &mesh, const std::string &sideName, const std::string type_)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
stk::mesh::EntityId getMaxEntityId(unsigned entityRank) const
get max entity ID of type entityRank
std::pair< Teuchos::RCP< std::vector< std::size_t > >, Teuchos::RCP< std::vector< Teuchos::Tuple< double, 3 > > > > getLocalSideIdsAndCoords(const STK_Interface &mesh, const std::string &sideName, const std::string type_)
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing.
unsigned getDimension() const
get the dimension
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
stk::mesh::EntityRank getFaceRank() const
Teuchos::RCP< stk::mesh::MetaData > getMetaData() const
const VectorFieldType & getEdgesField() const
PHX::MDField< ScalarT, panzer::Cell, panzer::BASIS > field
A field to which we'll contribute, or in which we'll store, the result of computing this integral...
stk::mesh::EntityRank getEdgeRank() const
Teuchos::RCP< std::vector< std::pair< std::size_t, std::size_t > > > getGlobalPairing(const std::vector< std::size_t > &locallyRequiredIds, const std::vector< std::pair< std::size_t, std::size_t > > &locallyMatchedIds, const STK_Interface &mesh, bool failure)
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
get the comm associated with this mesh
const VectorFieldType & getFacesField() const
#define TEUCHOS_ASSERT(assertion_test)
stk::mesh::EntityRank getNodeRank() const
Tpetra::KokkosCompat::KokkosDeviceWrapperNode< PHX::Device > TpetraNodeType
std::pair< Teuchos::RCP< std::vector< std::size_t > >, Teuchos::RCP< std::vector< Teuchos::Tuple< double, 3 > > > > getSideIdsAndCoords(const STK_Interface &mesh, const std::string &sideName, const std::string type_)
const VectorFieldType & getCoordinatesField() const