13 #include <stk_mesh/base/GetEntities.hpp>
14 #include <stk_mesh/base/GetBuckets.hpp>
15 #include <stk_mesh/base/FieldBase.hpp>
18 #include "Tpetra_Map.hpp"
19 #include "Tpetra_Import.hpp"
20 #include "Tpetra_Vector.hpp"
22 #include "Teuchos_FancyOStream.hpp"
24 namespace panzer_stk {
26 namespace periodic_helpers {
30 const std::vector<std::pair<std::size_t,std::size_t> > & locallyMatchedIds,
33 using LO = panzer::LocalOrdinal;
34 using GO = panzer::GlobalOrdinal;
36 using Map = Tpetra::Map<LO,GO,NODE>;
37 using Importer = Tpetra::Import<LO,GO,NODE>;
43 int myVal = failure ? 1 : 0;
48 std::vector<GO> requiredInts(locallyRequiredIds.size());
49 for(std::size_t i=0;i<requiredInts.size();i++)
50 requiredInts[i] = locallyRequiredIds[i];
52 std::vector<GO> providedInts(locallyMatchedIds.size());
53 for(std::size_t i=0;i<locallyMatchedIds.size();i++)
54 providedInts[i] = locallyMatchedIds[i].first;
60 Importer importer(providedMap,requiredMap);
63 Tpetra::Vector<GO,LO,GO,NODE> providedVector(providedMap);
65 auto pvHost = providedVector.getLocalViewHost(Tpetra::Access::OverwriteAll);
66 for(std::size_t i=0;i<locallyMatchedIds.size();i++)
67 pvHost(i,0) = locallyMatchedIds[i].second;
70 Tpetra::Vector<GO,LO,GO,NODE> requiredVector(requiredMap);
71 requiredVector.doImport(providedVector,importer,Tpetra::INSERT);
75 =
Teuchos::rcp(
new std::vector<std::pair<std::size_t,std::size_t> >(requiredInts.size()));
77 auto rvHost = requiredVector.getLocalViewHost(Tpetra::Access::ReadOnly);
78 for(std::size_t i=0;i<result->size();i++) {
79 (*result)[i].first = requiredInts[i];
80 (*result)[i].second = rvHost(i,0);
92 const std::string & sideName,
const std::string type_)
100 ss <<
"Can't find part=\"" << sideName <<
"\"" << std::endl;
101 stk::mesh::Part * side = metaData->get_part(sideName,ss.str().c_str());
102 stk::mesh::Selector mySides = *side & (metaData->locally_owned_part() | metaData->globally_shared_part());
104 stk::mesh::EntityRank rank;
105 panzer::GlobalOrdinal offset = 0;
106 if(type_ ==
"coord"){
108 }
else if(type_ ==
"edge"){
111 }
else if(type_ ==
"face"){
115 ss <<
"Can't do BCs of type " << type_ << std::endl;
119 std::vector<stk::mesh::Bucket*>
const& nodeBuckets =
120 bulkData->get_buckets(rank, mySides);
124 std::size_t nodeCount = 0;
125 for(std::size_t b=0;b<nodeBuckets.size();b++)
126 nodeCount += nodeBuckets[b]->size();
129 =
Teuchos::rcp(
new std::vector<std::size_t>(nodeCount));
132 for(std::size_t b=0,index=0;b<nodeBuckets.size();b++) {
133 stk::mesh::Bucket & bucket = *nodeBuckets[b];
135 for(std::size_t n=0;n<bucket.size();n++,index++)
136 (*sideIds)[index] = bulkData->identifier(bucket[n]) + offset;
142 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
145 const std::string & sideName,
const std::string type_)
154 std::stringstream ss;
155 ss <<
"Can't find part=\"" << sideName <<
"\"" << std::endl;
156 stk::mesh::Part * side = metaData->get_part(sideName,ss.str().c_str());
157 stk::mesh::Selector mySides = (*side) & metaData->locally_owned_part();
159 stk::mesh::EntityRank rank;
161 stk::mesh::EntityId offset = 0;
162 if(type_ ==
"coord"){
165 }
else if(type_ ==
"edge"){
169 }
else if(type_ ==
"face"){
174 ss <<
"Can't do BCs of type " << type_ << std::endl;
178 std::vector<stk::mesh::Bucket*>
const& nodeBuckets =
179 bulkData->get_buckets(rank, mySides);
183 std::size_t nodeCount = 0;
184 for(std::size_t b=0;b<nodeBuckets.size();b++)
185 nodeCount += nodeBuckets[b]->size();
188 =
Teuchos::rcp(
new std::vector<std::size_t>(nodeCount));
193 for(std::size_t b=0,index=0;b<nodeBuckets.size();b++) {
194 stk::mesh::Bucket & bucket = *nodeBuckets[b];
195 double const* array = stk::mesh::field_data(*field, bucket);
197 for(std::size_t n=0;n<bucket.size();n++,index++) {
198 (*sideIds)[index] = bulkData->identifier(bucket[n]) + offset;
202 for(std::size_t d=0;d<physicalDim;d++)
203 coord[d] = array[physicalDim*n + d];
207 for(std::size_t d=physicalDim;d<3;d++)
212 return std::make_pair(sideIds,sideCoords);
215 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
218 const std::string & sideName,
const std::string type_)
222 using LO = panzer::LocalOrdinal;
223 using GO = panzer::GlobalOrdinal;
225 using Map = Tpetra::Map<LO,GO,NODE>;
226 using Importer = Tpetra::Import<LO,GO,NODE>;
237 std::pair<Teuchos::RCP<std::vector<std::size_t> >,
241 std::vector<std::size_t> & local_side_ids = *sidePair.first;
242 std::vector<Teuchos::Tuple<double,3> > & local_side_coords = *sidePair.second;
243 std::size_t nodeCount = local_side_ids.size();
247 RCP<Map> idMap_ =
rcp(
new Map(computeInternally,nodeCount,0,comm));
253 auto lidHost = localIdVec_->getLocalViewHost(Tpetra::Access::OverwriteAll);
254 auto lcoordHost = localCoordVec_->getLocalViewHost(Tpetra::Access::OverwriteAll);
255 for(std::size_t n=0;n<local_side_ids.size();n++) {
256 std::size_t nodeId = local_side_ids[n];
259 lidHost(n,0) =
static_cast<GO
>(nodeId);
260 for(
unsigned d=0;d<physicalDim;d++)
261 lcoordHost(n,d) = coords[d];
269 std::size_t dist_nodeCount = idMap_->getGlobalNumElements();
272 RCP<Map> distMap_ =
rcp(
new Map(dist_nodeCount,0,comm,Tpetra::LocallyReplicated));
277 Importer importer_(idMap_,distMap_);
278 distIdVec_->doImport(*localIdVec_,importer_,Tpetra::INSERT);
279 distCoordVec_->doImport(*localCoordVec_,importer_,Tpetra::INSERT);
285 =
Teuchos::rcp(
new std::vector<std::size_t>(dist_nodeCount));
290 const auto didHost = distIdVec_->getLocalViewHost(Tpetra::Access::ReadOnly);
291 const auto dcoordHost = distCoordVec_->getLocalViewHost(Tpetra::Access::ReadOnly);
292 for(std::size_t n=0;n<dist_side_ids->size();++n) {
293 (*dist_side_ids)[n] = didHost(n,0);
296 for(
unsigned d=0;d<physicalDim;++d) {
297 coords[d] = dcoordHost(n,d);
300 for(
unsigned d=physicalDim;d<3;++d)
304 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