18 #include <stk_mesh/base/Types.hpp> 19 #include <stk_mesh/base/Entity.hpp> 20 #include <stk_mesh/base/Field.hpp> 21 #include <stk_mesh/base/FieldData.hpp> 23 #include <stk_util/environment/ReportHandler.hpp> 25 #include <stk_util/parallel/Parallel.hpp> 29 static const size_t NODE_RANK = stk_classic::mesh::fem::FEMMetaData::NODE_RANK;
36 std::vector<std::vector<double> > & coordinates)
39 std::vector<const mesh::Entity *> mesh_nodes;
41 const mesh::EntityRank enttype = entity.entity_rank();
42 if ( enttype == NODE_RANK )
44 throw std::runtime_error(
"GeomDecomp::entity_coordinates Error: Can not be called for nodal entities.");
50 for ( ; nr.first != nr.second; ++nr.first )
58 throw std::runtime_error(
"GeomDecomp::entity_coordinates Error: The coordinate field does not exist.");
60 std::vector<double> temp(ndim);
61 for (
unsigned i = 0; i < ndim; ++i ) { temp[i] = coor[i]; }
62 coordinates.push_back(temp);
63 mesh_nodes.push_back(nent);
72 std::vector<double> & centroid)
74 std::vector<std::vector<double> > coordinates;
77 const int ndim = coordinates.front().size();
78 const int num_nodes = coordinates.size();
80 centroid.resize(ndim);
81 for (
int i=0; i<ndim; ++i) { centroid[i] = 0; }
82 for (
int j = 0; j < num_nodes; ++j ) {
83 for (
int i = 0; i < ndim; ++i ) { centroid[i] += coordinates[j][i]; }
86 for (
int i=0; i<ndim; ++i) { centroid[i] /= num_nodes; }
92 void apply_rotation (std::vector<double> &coor)
98 static const double tS = 0.0001 ;
99 static const double tC = sqrt( (
double)( 1.0 - tS * tS ) );
100 static const double tQ = tS / sqrt( (
double) 3.0 );
101 static const double t1 = tC * tC - tQ * tQ ;
102 static const double t2 = 2.0 * tQ * ( tC + tQ );
103 static const double t3 = -2.0 * tQ * ( tC - tQ );
106 std::vector<double> temp(coor);
107 const size_t nd = temp.size();
113 coor[0] = t1 * temp[0] + t3 * temp[1] + t2 * temp[2] ;
114 coor[1] = t2 * temp[0] + t1 * temp[1] + t3 * temp[2] ;
115 coor[2] = t3 * temp[0] + t2 * temp[1] + t1 * temp[2] ;
117 else if ( nd == 2 ) {
118 coor[0] = tC * temp[0] - tS * temp[1] ;
119 coor[1] = tS * temp[0] + tC * temp[1] ;
121 else if ( nd == 1 ) {
125 ThrowRequireMsg(
false,
"Spatial Dimention not 1, 2, or 3, can not apply rotation.");
135 std::vector<double> & coor)
138 apply_rotation (coor);
Entity * entity() const
The referenced entity.
unsigned field_data_size(const FieldBase &f, const Bucket &k)
Size, in bytes, of the field data for each entity.
bool rebalance(mesh::BulkData &bulk_data, const mesh::Selector &selector, const VectorField *coord_ref, const ScalarField *elem_weight_ref, Partition &partition, const stk_classic::mesh::EntityRank rank=stk_classic::mesh::InvalidEntityRank)
Rebalance with a Partition object.
FieldTraits< field_type >::data_type * field_data(const field_type &f, const Bucket::iterator i)
Pointer to the field data array.
static std::vector< const mesh::Entity * > entity_coordinates(const mesh::Entity &entity, const VectorField &ref, std::vector< std::vector< double > > &coordinates)
Used to return the nodal entities that compute_entity_centroid averages.
Field with defined data type and multi-dimensions (if any)
A relation between two mesh entities with a relation identifier and kind .
Geometric support for partitioning of mesh entities.
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
unsigned entity_rank() const
The rank of the referenced entity.
static void entity_to_point(const mesh::Entity &entity, const VectorField &ref, std::vector< double > &coor)
Convert a single mesh entity to a single point.
static std::vector< std::vector< double > > compute_entity_centroid(const mesh::Entity &entity, const VectorField &ref, std::vector< double > &coor)
Returns a vector of vectors containing the coordinates of the nodes that were used to compute the cen...