45 #include <stk_mesh/base/GetEntities.hpp>
46 #include <stk_mesh/base/GetBuckets.hpp>
47 #include <stk_mesh/base/FieldBase.hpp>
50 #include "Tpetra_Map.hpp"
51 #include "Tpetra_Import.hpp"
52 #include "Tpetra_Vector.hpp"
54 #include "Teuchos_FancyOStream.hpp"
56 namespace panzer_stk {
58 namespace periodic_helpers {
62 const std::vector<std::pair<std::size_t,std::size_t> > & locallyMatchedIds,
65 using LO = panzer::LocalOrdinal;
66 using GO = panzer::GlobalOrdinal;
68 using Map = Tpetra::Map<LO,GO,NODE>;
69 using Importer = Tpetra::Import<LO,GO,NODE>;
75 int myVal = failure ? 1 : 0;
80 std::vector<GO> requiredInts(locallyRequiredIds.size());
81 for(std::size_t i=0;i<requiredInts.size();i++)
82 requiredInts[i] = locallyRequiredIds[i];
84 std::vector<GO> providedInts(locallyMatchedIds.size());
85 for(std::size_t i=0;i<locallyMatchedIds.size();i++)
86 providedInts[i] = locallyMatchedIds[i].first;
92 Importer importer(providedMap,requiredMap);
95 Tpetra::Vector<GO,LO,GO,NODE> providedVector(providedMap);
96 providedVector.sync_host();
97 auto pvHost = providedVector.getLocalViewHost();
98 for(std::size_t i=0;i<locallyMatchedIds.size();i++)
99 pvHost(i,0) = locallyMatchedIds[i].second;
100 providedVector.modify_host();
102 Tpetra::Vector<GO,LO,GO,NODE> requiredVector(requiredMap);
103 requiredVector.doImport(providedVector,importer,Tpetra::INSERT);
107 =
Teuchos::rcp(
new std::vector<std::pair<std::size_t,std::size_t> >(requiredInts.size()));
109 requiredVector.sync_host();
110 auto rvHost = requiredVector.getLocalViewHost();
111 for(std::size_t i=0;i<result->size();i++) {
112 (*result)[i].first = requiredInts[i];
113 (*result)[i].second = rvHost(i,0);
125 const std::string & sideName,
const std::string type_)
132 std::stringstream ss;
133 ss <<
"Can't find part=\"" << sideName <<
"\"" << std::endl;
134 stk::mesh::Part * side = metaData->get_part(sideName,ss.str().c_str());
135 stk::mesh::Selector mySides = *side & (metaData->locally_owned_part() | metaData->globally_shared_part());
137 stk::mesh::EntityRank rank;
138 unsigned int offset = 0;
139 if(type_ ==
"coord"){
141 }
else if(type_ ==
"edge"){
144 }
else if(type_ ==
"face"){
148 ss <<
"Can't do BCs of type " << type_ << std::endl;
152 std::vector<stk::mesh::Bucket*>
const& nodeBuckets =
153 bulkData->get_buckets(rank, mySides);
157 std::size_t nodeCount = 0;
158 for(std::size_t b=0;b<nodeBuckets.size();b++)
159 nodeCount += nodeBuckets[b]->size();
162 =
Teuchos::rcp(
new std::vector<std::size_t>(nodeCount));
165 for(std::size_t b=0,index=0;b<nodeBuckets.size();b++) {
166 stk::mesh::Bucket & bucket = *nodeBuckets[b];
168 for(std::size_t n=0;n<bucket.size();n++,index++)
169 (*sideIds)[index] = bulkData->identifier(bucket[n]) + offset;
175 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
178 const std::string & sideName,
const std::string type_)
187 std::stringstream ss;
188 ss <<
"Can't find part=\"" << sideName <<
"\"" << std::endl;
189 stk::mesh::Part * side = metaData->get_part(sideName,ss.str().c_str());
190 stk::mesh::Selector mySides = (*side) & metaData->locally_owned_part();
192 stk::mesh::EntityRank rank;
194 unsigned int offset = 0;
195 if(type_ ==
"coord"){
198 }
else if(type_ ==
"edge"){
202 }
else if(type_ ==
"face"){
207 ss <<
"Can't do BCs of type " << type_ << std::endl;
211 std::vector<stk::mesh::Bucket*>
const& nodeBuckets =
212 bulkData->get_buckets(rank, mySides);
216 std::size_t nodeCount = 0;
217 for(std::size_t b=0;b<nodeBuckets.size();b++)
218 nodeCount += nodeBuckets[b]->size();
221 =
Teuchos::rcp(
new std::vector<std::size_t>(nodeCount));
226 for(std::size_t b=0,index=0;b<nodeBuckets.size();b++) {
227 stk::mesh::Bucket & bucket = *nodeBuckets[b];
228 double const* array = stk::mesh::field_data(*field, bucket);
230 for(std::size_t n=0;n<bucket.size();n++,index++) {
231 (*sideIds)[index] = bulkData->identifier(bucket[n]) + offset;
235 for(std::size_t d=0;d<physicalDim;d++)
236 coord[d] = array[physicalDim*n + d];
240 for(std::size_t d=physicalDim;d<3;d++)
245 return std::make_pair(sideIds,sideCoords);
248 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
251 const std::string & sideName,
const std::string type_)
255 using LO = panzer::LocalOrdinal;
256 using GO = panzer::GlobalOrdinal;
258 using Map = Tpetra::Map<LO,GO,NODE>;
259 using Importer = Tpetra::Import<LO,GO,NODE>;
270 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
274 std::vector<std::size_t> & local_side_ids = *sidePair.first;
275 std::vector<Teuchos::Tuple<double,3> > & local_side_coords = *sidePair.second;
276 int nodeCount = local_side_ids.size();
280 RCP<Map> idMap_ =
rcp(
new Map(computeInternally,nodeCount,0,comm));
285 localIdVec_->sync_host();
286 localCoordVec_->sync_host();
287 auto lidHost = localIdVec_->getLocalViewHost();
288 auto lcoordHost = localCoordVec_->getLocalViewHost();
289 for(std::size_t n=0;n<local_side_ids.size();n++) {
290 std::size_t nodeId = local_side_ids[n];
293 lidHost(n,0) =
static_cast<GO
>(nodeId);
294 for(
unsigned d=0;d<physicalDim;d++)
295 lcoordHost(n,d) = coords[d];
297 localIdVec_->modify_host();
298 localCoordVec_->modify_host();
304 int dist_nodeCount = idMap_->getGlobalNumElements();
307 RCP<Map> distMap_ =
rcp(
new Map(dist_nodeCount,0,comm,Tpetra::LocallyReplicated));
312 Importer importer_(idMap_,distMap_);
313 distIdVec_->doImport(*localIdVec_,importer_,Tpetra::INSERT);
314 distCoordVec_->doImport(*localCoordVec_,importer_,Tpetra::INSERT);
320 =
Teuchos::rcp(
new std::vector<std::size_t>(dist_nodeCount));
325 distIdVec_->sync_host();
326 distCoordVec_->sync_host();
327 const auto didHost = distIdVec_->getLocalViewHost();
328 const auto dcoordHost = distCoordVec_->getLocalViewHost();
329 for(std::size_t n=0;n<dist_side_ids->size();++n) {
330 (*dist_side_ids)[n] = didHost(n,0);
333 for(
unsigned d=0;d<physicalDim;++d) {
334 coords[d] = dcoordHost(n,d);
337 for(
unsigned d=physicalDim;d<3;++d)
341 return std::make_pair(dist_side_ids,dist_side_coords);
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)
stk::mesh::Field< double, stk::mesh::Cartesian > VectorFieldType
Teuchos::RCP< stk::mesh::BulkData > getBulkData() const
Kokkos::Compat::KokkosDeviceWrapperNode< PHX::Device > TpetraNodeType
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
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