Exemplo n.º 1
0
 void operator()(MESH& m, double t) {
   (void) t;
   double distance;  
   double r;
   Point directionVector;
   Point pos;
   Point c;
   Point R;
   Point velocity;
   Node node1;
   Node node2;
   
   for(auto it=m.node_begin(); it != m.node_end(); ++ it)
   {
       
       node1 = (*it);
       c = node1.position();
       r = 0.0;
       
       // iterate through connected edges and set r equal to  
       // the length of the shortest connected edge
       for(auto edge_it = node1.edge_begin(); edge_it != node1.edge_end(); ++edge_it)
       {
           if (r == 0.0 || (*edge_it).length() < r)
               r = (*edge_it).length();
       }
       
       // now iterate through all of the other nodes and see if any of
       // them are within distance r
       for(auto it2=m.node_begin(); it2 != m.node_end(); ++it2)
       {
           node2 = (*it2);
           pos = node2.position();
           distance = norm(pos-c);
           if (distance < r && node1 != node2)
           {
               // SET POSITION TO NEAREST POINT ON SURFACE OF SPHERE
               
               // get the direction vector from the center to our node 
               directionVector = pos-c;
               //normalize that vector
               directionVector = directionVector/norm(directionVector);
                   
               // set pos to the direction vector time the sphere's radius
               // which should get us to the point on the sphere closest
               // to the node's current position
               pos = c+directionVector*(r);
               node2.set_position(pos);
                   
               // SET THE COMPONENT OF VELOCITY THAT IS NORMAL TO THE 
               // SPHERE'S SURFACE TO ZERO
               R = (pos-c)/norm(pos-c);
               velocity = node2.value().velocity;
               node2.value().velocity = velocity - inner_prod(velocity,R)*R;
           }
       }
   }
 }
Exemplo n.º 2
0
Point post_process(MESH& m, FORCE force, CONSTRAINT& c, double t, double dt, uint water_nodes) {
  static double ball_bottom = std::numeric_limits<double>::max();
  double water_dis = std::numeric_limits<double>::max();
  double dh = 0;
  static double submerged_height = 0;
  Point bottom_loc;
  Point water_loc;

  for (auto n_it = m.node_begin(); n_it != m.node_end(); ++n_it) {
    // handles the shallow water
  	if ((*n_it).index() < water_nodes) {
	    double sum_area = 0;
	    QVar value = QVar(0,0,0);

	    for (auto tri_it = m.adj_triangle_begin((*n_it).uid()); tri_it != m.adj_triangle_end((*n_it).uid()); ++tri_it) {
	      value += (*tri_it).value().q_bar * (*tri_it).area();
	      sum_area += (*tri_it).area();
	    }

	    (*n_it).value().q = value * 1.0/(sum_area);
	  }
    // handles the ball
    else {
      (*n_it).set_position((*n_it).position() + (*n_it).value().velocity*dt);
      dh = (*n_it).value().q.h - (*n_it).position().z;
      (*n_it).value().q.h = (*n_it).position().z;
      (*n_it).value().velocity += force(m,(*n_it),t)*dt/(*n_it).value().mass;
      if ((*n_it).value().q.h < ball_bottom) {
        ball_bottom = (*n_it).position().z;
        bottom_loc = (*n_it).position();
      }
    }
  }
  // find the water node closest to the bottom of the ball
  for (auto n_it = m.node_begin(); (*n_it).index() != water_nodes; ++n_it) {
    if (norm(Point((*n_it).position().x,(*n_it).position().y,0)-Point(bottom_loc.x,bottom_loc.y,0)) < water_dis){
      water_dis = norm(Point((*n_it).position().x,(*n_it).position().y,0)-Point(bottom_loc.x,bottom_loc.y,0));
      water_loc = Point((*n_it).position().x,(*n_it).position().y,(*n_it).value().q.h);
    }
  }

  // apply contraints of neccessary
  c(m,ball_bottom);

  // determines if the ball fell below shallow water and updates height submerged
  if (bottom_loc.z < water_loc.z)
    submerged_height += dh;
  return Point(bottom_loc.x, bottom_loc.y, submerged_height);
}
Exemplo n.º 3
0
Point get_center(MESH& m)
{
  Point center = Point(0,0,0);
  for(auto it=m.node_begin(); it != m.node_end(); ++ it)
    center += (*it).position();
  center /= m.num_nodes();

  return center;
}
Exemplo n.º 4
0
 void operator()(MESH& m, double t) {
   (void) t;
   for(auto it=m.node_begin(); it != m.node_end(); ++ it)
   {
       if ((*it).position().z < plane_)
       {
           Point current_position = (*it).position();
           Point current_veloc = (*it).value().velocity;
           (*it).set_position(Point(current_position.x,current_position.y,plane_));
           (*it).value().velocity = Point(current_veloc.x,current_veloc.y,-current_veloc.z);
       }
   }
 }
Exemplo n.º 5
0
void post_process(MESH& m) {
  // HW4B: Post-processing step
  // Translate the triangle-averaged values to node-averaged values
  // Implement Equation 9 from your pseudocode here
  for (auto it = m.node_begin(); it != m.node_end(); ++it){
    double sumarea=0;
    QVar sumQ = QVar(0, 0, 0);
    for(auto j = m.triangle_begin(*it); j != m.triangle_end(*it); ++j){
      sumarea += (*j).area();
      sumQ += (*j).value().Q * (*j).area();
    }
    (*it).value().Q = sumQ/sumarea;
  }
}
Exemplo n.º 6
0
void post_process(MESH& m) {
  // HW4B: Post-processing step
  // Translate the triangle-averaged values to node-averaged values
  // Implement Equation 9 from your pseudocode here
  for (auto nit = m.node_begin(); nit != m.node_end(); ++nit) {
      double total_area = 0;
      QVar Q_tot(0, 0, 0);
      int count = 0;
  
      for (auto tri_it = m.adjacent_triangle_begin(*nit); tri_it != m.adjacent_triangle_end(*nit); ++tri_it) {
        Q_tot = Q_tot + (*tri_it).value() * (*tri_it).area();
        total_area += (*tri_it).area();
        ++count;
      }
      (*nit).value() = Q_tot / total_area;
  }
}
Exemplo n.º 7
0
/*	
 * post process of a mesh instance to update the values of all the nodes values
 * @pre: a valid mesh instance
 * @post: update the nodes values based on approximation of the average of neighbours values
		  refer to equation 9 on the notes
*/
void post_process(MESH& m) {
  // Translate the triangle-averaged values to node-averaged values
  // Implement Equation 8 from your pseudocode here
  	// iterate through all the nodes
  for ( auto it = m.node_begin(); it!= m.node_end(); ++it)
  {
	
	QVar sum = QVar(0,0,0);
	double sumTriArea = 0;
	// for each node, iterate through its adjacent triangles
	
	for (auto adji = m.vertex_begin((*it).index()); adji !=  m.vertex_end((*it).index()); ++ adji)
	{
		auto tri = (*adji);
		sum += tri.area() * tri.value();
		sumTriArea += tri.area();  
	}

	(*it).value() = sum/sumTriArea; // update nodes value
  }
}
Exemplo n.º 8
0
 void operator()(MESH& m, double z_bottom) {
   if (z_bottom < plane_)
     for(auto it=m.node_begin(); it != m.node_end(); ++it)
       (*it).value().velocity = Point(0,0,0);
 }