Face.cpp
1 #include "Face.hpp"
2 
3 using namespace std;
4 
5 Face::Face(vector<Vector3D> const& vert,size_t neighbor1,size_t neighbor2):
6  vertices(vert),neighbors(neighbor1,neighbor2) {}
7 
8 Face::Face(void): vertices(), neighbors() {}
9 
10 Face& Face::operator=(const Face& other)
11 {
12  vertices = other.vertices;
13  neighbors = other.neighbors;
14  return *this;
15 }
16 
17  Face::~Face(void)
18  {}
19 
20 Face::Face(Face const& other):
21  vertices(other.vertices),
22  neighbors(other.neighbors) {}
23 
24  double Face::GetArea(void) const
25  {
26  double res=0;
27  for(size_t i=0;i<vertices.size()-2;++i)
28  res+=0.5*abs(CrossProduct(vertices[i+1]-vertices[0],vertices[i+2]-vertices[0]));
29  return res;
30  }
31 
33 {
34  Vector3D res;
35  for(size_t i=0;i<face.vertices.size()-2;++i)
36  {
37  double area=0.5*abs(CrossProduct(face.vertices[i+1]-face.vertices[0],
38  face.vertices[i+2]-face.vertices[0]));
39  res.x+=area*(face.vertices[0].x+face.vertices[i+2].x+face.vertices[i+1].x)/3.;
40  res.y+=area*(face.vertices[0].y+face.vertices[i+2].y+face.vertices[i+1].y)/3.;
41  res.z+=area*(face.vertices[0].z+face.vertices[i+2].z+face.vertices[i+1].z)/3.;
42  }
43  return res;
44 }
double z
Component in the z direction.
Definition: Vector3D.hpp:50
Vector3D CrossProduct(Vector3D const &v1, Vector3D const &v2)
Returns the cross product of two vectors.
Definition: Vector3D.cpp:213
std::pair< size_t, size_t > neighbors
Neighboring cells.
Definition: Face.hpp:23
Face between cells.
std::vector< Vector3D > vertices
Points at the ends of the edge.
Definition: Face.hpp:20
3D Mathematical vector
Definition: Vector3D.hpp:15
double y
Component in the y direction.
Definition: Vector3D.hpp:47
Vector3D calc_centroid(const Face &face)
Calculates the centroid of aa face.
Definition: Face.cpp:32
double GetArea(void) const
Returns the area of the face.
Definition: Face.cpp:24
Face & operator=(const Face &other)
Copy operator.
Definition: Face.cpp:10
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
double x
Component in the x direction.
Definition: Vector3D.hpp:44
Interface between two cells.
Definition: Face.hpp:15
Face(vector< Vector3D > const &vert, size_t neighbor1, size_t neighbor2)
Class constructor.
Definition: Face.cpp:5