16 #include <stk_util/parallel/Parallel.hpp> 18 #include <stk_mesh/base/Entity.hpp> 19 #include <stk_mesh/base/BulkData.hpp> 20 #include <stk_mesh/base/MetaData.hpp> 22 #include <stk_search/IdentProc.hpp> 23 #include <stk_search/BoundingBox.hpp> 46 typedef stk::search::IdentProc<EntityKey, unsigned>
EntityProc;
49 typedef stk::search::Point<double>
Point;
50 typedef stk::search::Sphere<double>
Sphere;
55 typedef std::vector<std::pair<std::string, std::string> >
PairNames;
56 std::vector< const stk::mesh::FieldBase *>
57 get_fields(
const stk::mesh::MetaData &toMetaData,
const PairNames &VarPairName) {
59 bool allFieldsAreFine =
true;
60 std::vector< const stk::mesh::FieldBase *> toFieldVec;
62 for( PairNames::const_iterator i=VarPairName.begin(); i!=VarPairName.end(); ++i) {
63 const std::string &fieldName = i->second;
64 const stk::mesh::FieldBase *tofield = stk::mesh::get_field_by_name(fieldName,toMetaData);
65 if ( NULL == tofield ) {
66 allFieldsAreFine =
false;
67 NaluEnv::self().naluOutputP0()
68 <<
"Xfer::ToMesh:Error field: " << fieldName
69 <<
" has not been registered anywhere within the ToRealm: " << toRealm_.name() << std::endl;
73 toFieldVec.push_back(tofield);
76 stk::mesh::Selector fieldSelector = stk::mesh::selectField(*tofield);
77 for (
size_t k = 0; k < toPartVec_.size(); ++k ) {
80 = toBulkData_.get_buckets(stk::topology::NODE_RANK, stk::mesh::Selector(*toPartVec_[k]));
82 bool fieldIsFine =
true;
83 for ( stk::mesh::BucketVector::const_iterator ib = partBuckets.begin();
84 ib != partBuckets.end() ; ++ib ) {
85 stk::mesh::Bucket & b = **ib ;
86 fieldIsFine &= fieldSelector(b);
91 NaluEnv::self().naluOutputP0()
92 <<
"Xfer::ToMesh:Error field: " << tofield->name()
93 <<
" is not registered on part: " << toPartVec_[k]->name() << std::endl;
94 allFieldsAreFine =
false;
101 if ( allFieldsAreFine ) {
105 throw std::runtime_error(
"Xfer::ToMesh:Error field registration on desired parts of the mesh is not complete");
110 stk::mesh::MetaData &toMetaData,
111 stk::mesh::BulkData &toBulkData,
113 const std::string &coordinates_name,
114 const PairNames &VarPairName,
116 const stk::ParallelMachine comm,
118 : toMetaData_(toMetaData),
119 toBulkData_(toBulkData),
121 tocoordinates_(toMetaData.get_field<
VectorFieldType>(
stk::topology::NODE_RANK,coordinates_name)),
122 toPartVec_(toPartVec),
123 toFieldVec_ (get_fields(toMetaData, VarPairName)),
133 bool operator()(
const BoundingBox &a,
const BoundingBox & b)
const 135 return a.second.id() < b.second.id();
141 stk::ParallelMachine
comm()
const {
return comm_;}
146 const unsigned spatial_dimension = toMetaData_.spatial_dimension();
150 stk::mesh::Selector s_locally_owned_union = toMetaData_.locally_owned_part()
151 &stk::mesh::selectUnion(toPartVec_);
154 = toBulkData_.get_buckets( stk::topology::NODE_RANK, s_locally_owned_union );
155 for ( stk::mesh::BucketVector::const_iterator ib = node_buckets.begin();
156 ib != node_buckets.end() ; ++ib ) {
157 stk::mesh::Bucket & b = **ib ;
159 const stk::mesh::Bucket::size_type length = b.size();
161 for ( stk::mesh::Bucket::size_type k = 0 ; k < length ; ++k ) {
164 stk::mesh::Entity node = b[k];
166 double * coord = stk::mesh::field_data(*tocoordinates_, node);
167 for (
unsigned i=0; i<spatial_dimension; ++i) {
168 center[i] = coord[i];
172 ToMesh::EntityProc theIdent(toBulkData_.entity_key(node), toBulkData_.parallel_rank());
183 std::vector<const stk::mesh::FieldBase *> fields(toFieldVec_.begin(), toFieldVec_.end());
184 stk::mesh::copy_owned_to_shared ( toBulkData_, fields);
196 typedef std::map<stk::mesh::EntityKey, std::vector<double> >
TransferInfo;
std::vector< Part * > PartVector
Definition: Algorithm.h:16
Definition: ABLForcingAlgorithm.C:26
stk::search::Sphere< double > Sphere
Definition: Actuator.h:40
TransferInfo TransferInfo_
Definition: ToMesh.h:197
const double radius_
Definition: ToMesh.h:194
void update_values()
Definition: ToMesh.h:181
const stk::mesh::PartVector toPartVec_
Definition: ToMesh.h:191
std::vector< const stk::mesh::FieldBase * > get_fields(const stk::mesh::MetaData &toMetaData, const PairNames &VarPairName)
Definition: ToMesh.h:57
bool operator()(const BoundingBox &a, const BoundingBox &b) const
Definition: ToMesh.h:133
std::vector< std::pair< std::string, std::string > > PairNames
Definition: ToMesh.h:55
std::vector< Entity > EntityVec
Definition: ToMesh.h:43
Definition: Algorithm.h:14
stk::search::Sphere< double > Sphere
Definition: ToMesh.h:50
stk::mesh::Field< double, stk::mesh::Cartesian > VectorFieldType
Definition: FieldTypeDef.h:24
const std::vector< const stk::mesh::FieldBase * > toFieldVec_
Definition: ToMesh.h:192
stk::mesh::BulkData & toBulkData_
Definition: ToMesh.h:188
void bounding_boxes(std::vector< BoundingBox > &v) const
Definition: ToMesh.h:143
stk::mesh::Entity Entity
Definition: ToMesh.h:42
stk::mesh::MetaData & toMetaData_
Definition: ToMesh.h:187
const stk::ParallelMachine comm_
Definition: ToMesh.h:193
stk::search::IdentProc< EntityKey, unsigned > EntityProc
Definition: ToMesh.h:46
stk::search::Point< double > Point
Definition: ToMesh.h:49
std::vector< EntityProc > EntityProcVec
Definition: ToMesh.h:47
std::vector< Bucket * > BucketVector
Definition: PromotedPartHelper.h:21
std::pair< Sphere, EntityProc > BoundingBox
Definition: ToMesh.h:51
std::set< EntityKey > EntityKeySet
Definition: ToMesh.h:45
const VectorFieldType * tocoordinates_
Definition: ToMesh.h:190
stk::mesh::EntityKey EntityKey
Definition: ToMesh.h:44
~ToMesh()
Definition: ToMesh.h:130
std::map< stk::mesh::EntityKey, std::vector< double > > TransferInfo
Definition: ToMesh.h:196
Realm & toRealm_
Definition: ToMesh.h:189
ToMesh(stk::mesh::MetaData &toMetaData, stk::mesh::BulkData &toBulkData, Realm &toRealm, const std::string &coordinates_name, const PairNames &VarPairName, const stk::mesh::PartVector &toPartVec, const stk::ParallelMachine comm, const double radius)
Definition: ToMesh.h:109
stk::ParallelMachine comm() const
Definition: ToMesh.h:141