7 #ifndef WONTON_POLYTOPE_H_ 8 #define WONTON_POLYTOPE_H_ 29 int nfaces =
static_cast<int>(vertex_points.size());
32 vertex_points_ = vertex_points;
33 face_vertices_.resize(nfaces);
34 for (
int iface = 0; iface < nfaces; iface++)
35 face_vertices_[iface] = { iface, (iface + 1)%nfaces };
47 assert(vertex_points.size() > 3);
50 vertex_points_ = vertex_points;
61 const std::vector< Point<D> >&
points()
const {
return vertex_points_; }
71 assert((face_id >= 0) && (
unsigned(face_id) < face_vertices_.size()));
72 return face_vertices_[face_id];
82 std::vector< Point<D> >
face_points(
int const face_id)
const {
83 assert((face_id >= 0) && (
unsigned(face_id) < face_vertices_.size()));
85 int nvrts =
static_cast<int>(face_vertices_[face_id].size());
86 std::vector< Point<D> > fpoints;
87 fpoints.reserve(nvrts);
88 for (
int ivrt = 0; ivrt < nvrts; ivrt++)
89 fpoints.push_back(vertex_points_[face_vertices_[face_id][ivrt]]);
99 return face_vertices_;
108 assert((vertex_id >= 0) && (
unsigned(vertex_id) < vertex_points_.size()));
109 return vertex_points_[vertex_id];
116 int num_vertices()
const {
return static_cast<int>(vertex_points_.size()); }
121 int num_faces()
const {
return static_cast<int>(face_vertices_.size()); }
143 std::vector<double>
moments()
const;
146 std::vector< Point<D> > vertex_points_;
147 std::vector< std::vector<int> > face_vertices_;
160 assert((face_id >= 0) && (face_id < nfaces));
162 std::vector<double> fmoments(3);
163 fmoments[0] = (vertex_points_[(face_id + 1)%nfaces] - vertex_points_[face_id]).norm();
164 for (
int ixy = 0; ixy < 2; ixy++)
165 fmoments[ixy + 1] = 0.5*fmoments[0]*(
166 vertex_points_[face_id][ixy] + vertex_points_[(face_id + 1)%nfaces][ixy]);
182 assert((face_id >= 0) && (face_id <
num_faces()));
186 int nfvrts =
static_cast<int>(fvertices.size());
189 face_moments[0] = 0.5*
cross(vertex_points_[fvertices[1]] - vertex_points_[fvertices[0]],
190 vertex_points_[fvertices[2]] - vertex_points_[fvertices[0]]).norm();
192 for (
int ivrt = 0; ivrt < 3; ivrt++)
193 for (
int ixyz = 0; ixyz < 3; ixyz++)
194 face_moments[ixyz + 1] += face_moments[0]*vertex_points_[fvertices[ivrt]][ixyz]/3.0;
200 for (
int ivrt = 0; ivrt < nfvrts; ivrt++)
201 gcenter += vertex_points_[fvertices[ivrt]];
204 for (
int ivrt = 0; ivrt < nfvrts; ivrt++) {
205 int ifv = fvertices[ivrt];
206 int isv = fvertices[(ivrt + 1)%nfvrts];
208 double tri_size = 0.5*
cross(
209 vertex_points_[isv] - vertex_points_[ifv], gcenter - vertex_points_[ifv]).norm();
211 face_moments[0] += tri_size;
212 for (
int ixyz = 0; ixyz < 3; ixyz++)
213 face_moments[ixyz + 1] +=
214 tri_size*(vertex_points_[ifv][ixyz] + vertex_points_[isv][ixyz] + gcenter[ixyz])/3.0;
230 assert((face_id >= 0) && (face_id < nfaces));
232 int ifv = face_id, isv = (face_id + 1)%nfaces;
233 double flen = (vertex_points_[isv] - vertex_points_[ifv]).norm();
238 (vertex_points_[isv][1] - vertex_points_[ifv][1])/flen,
239 -(vertex_points_[isv][0] - vertex_points_[isv][0])/flen);
255 assert((face_id >= 0) && (face_id <
num_faces()));
259 int nfvrts =
static_cast<int>(fvertices.size());
261 fnormal =
cross(vertex_points_[fvertices[1]] - vertex_points_[fvertices[0]],
262 vertex_points_[fvertices[2]] - vertex_points_[fvertices[0]]);
269 if (fmoments[0] == 0.0)
273 for (
int ixyz = 0; ixyz < 3; ixyz++)
274 fcentroid[ixyz] = fmoments[ixyz + 1]/fmoments[0];
276 for (
int ivrt = 0; ivrt < nfvrts; ivrt++) {
277 int ifv = fvertices[ivrt], isv = fvertices[(ivrt + 1)%nfvrts];
279 vertex_points_[isv] - vertex_points_[ifv],
280 fcentroid - vertex_points_[ifv]);
281 fnormal += tri_normal;
283 fnormal /= fmoments[0];
296 std::vector<double> poly_moments(3, 0.0);
299 for (
int ivrt = 0; ivrt < nvrts; ivrt++) {
300 int ifv = ivrt, isv = (ivrt + 1)%nvrts;
301 double cur_term = vertex_points_[ifv][0]*vertex_points_[isv][1] -
302 vertex_points_[ifv][1]*vertex_points_[isv][0];
303 poly_moments[0] += cur_term;
304 for (
int ixy = 0; ixy < 2; ixy++)
305 poly_moments[ixy + 1] += cur_term*(
306 vertex_points_[ifv][ixy] + vertex_points_[isv][ixy]);
308 poly_moments[0] /= 2.0;
309 for (
int ixy = 0; ixy < 2; ixy++)
310 poly_moments[ixy + 1] /= 6.0;
324 std::vector<double> poly_moments(4, 0.0);
327 for (
int iface = 0; iface < nfaces; iface++) {
330 if (fmoments[0] == 0.0)
333 std::vector< Point<3> > face_pts =
face_points(iface);
334 std::vector< std::vector<int> > itri_pts;
336 int nfvrts = face_vertices_[iface].size();
338 itri_pts.push_back({0, 1, 2});
341 for (
int ixyz = 0; ixyz < 3; ixyz++)
342 fcentroid[ixyz] = fmoments[ixyz + 1]/fmoments[0];
343 face_pts.emplace_back(fcentroid);
345 itri_pts.reserve(nfvrts);
346 for (
int ivrt = 0; ivrt < nfvrts; ivrt++)
347 itri_pts.push_back({nfvrts, ivrt, (ivrt + 1)%nfvrts});
350 for (
auto&& point : itri_pts) {
352 face_pts[point[2]] - face_pts[point[0]]);
354 poly_moments[0] +=
dot(vcp, face_pts[point[0]].asV());
355 for (
int ixyz = 0; ixyz < 3; ixyz++) {
356 for (
int ivrt = 0; ivrt < 3; ivrt++) {
357 int ifv = point[ivrt], isv = point[(ivrt + 1)%3];
358 poly_moments[ixyz + 1] += vcp[ixyz]*pow(face_pts[ifv][ixyz] +
359 face_pts[isv][ixyz], 2);
365 poly_moments[0] /= 6.0;
366 for (
int ixyz = 0; ixyz < 3; ixyz++)
367 poly_moments[ixyz + 1] /= 48.0;
375 #endif // WONTON_POLYTOPE_H_ Polytope(const std::vector< Point< 3 > > &vertex_points, const std::vector< std::vector< int > > &face_vertices)
Constructor for a 3D polyhedron.
Definition: Polytope.h:45
int num_vertices() const
Number of material poly's vertices.
Definition: Polytope.h:116
const std::vector< Point< D > > & points() const
Points for all the vertices of the polytope.
Definition: Polytope.h:61
WONTON_INLINE double cross(const Vector< 2 > &a, const Vector< 2 > &b)
Cross product operator for two 2d vectors, .
Definition: Vector.h:304
std::vector< double > face_moments(int face_id) const
Moments for a face of the polytope.
Factorize a number N into D equal (or nearly equal) factors.
Definition: adaptive_refinement_mesh.h:31
std::vector< T > vector
Definition: wonton.h:285
Vector< D > face_normal(int face_id) const
Effective normal to a face of the polytope.
std::vector< double > moments() const
Moments for the polytope.
const std::vector< std::vector< int > > & face_vertices() const
Indices of vertices for all the faces of the polytope.
Definition: Polytope.h:98
Represents a point in an N-dimensional space.
Definition: Point.h:50
std::vector< Point< D > > face_points(int const face_id) const
Coordinates of vertices of the polytope's face in counter-clockwise order (i.e. so that the normal to...
Definition: Polytope.h:82
Polytope(const std::vector< Point< 2 > > &vertex_points)
Constructor for a 2D polygon.
Definition: Polytope.h:28
WONTON_INLINE void normalize()
Convert this Vector into a unit Vector.
Definition: Vector.h:180
Point< D > vertex_point(int const vertex_id) const
Coordinates of a polytope's vertex.
Definition: Polytope.h:107
const std::vector< int > & face_vertices(int const face_id) const
Indices of vertices of the polytope's face in counter-clockwise order (i.e. so that the normal to the...
Definition: Polytope.h:70
Definition: Polytope.h:21
int num_faces() const
Number of material poly's faces.
Definition: Polytope.h:121
Represents a vector in N-dimensional space.
Definition: Vector.h:40
WONTON_INLINE double dot(const Vector< D > &a, const Vector< D > &b)
Dot product of two vectors, .
Definition: Vector.h:248