Ejemplo n.º 1
0
// This is the function that we will tell OpenGL to call
// whenever the cursor is moved with a button pressed.
void mouse_motion( int x, int y )
{
	Vec2 P( model_coords( x, y ) );
	Vec2 delta( P - curr_pos );
	last_pos = curr_pos;
	curr_pos = P;
	theta += 0.5 * delta.y;
	phi   -= 0.5 * delta.x;
	glutPostRedisplay();
}
    KOKKOS_INLINE_FUNCTION
    void operator()(int inode) const {

      // Getting count as per 'CSR-like' data structure
      const int element_offset = node_elem_offset(inode);
      const int element_count  = node_elem_offset(inode + 1) - element_offset ;

      double local_force[] = {0.0, 0.0, 0.0};

      //  for each element that a node belongs to
      for(int i = 0; i < element_count ; i++){

        //  node_elem_offset is a cumulative structure, so
        //  node_elem_offset(inode) should be the index where
        //  a particular row's elem_IDs begin
        const int nelem = node_elem_ids( element_offset + i, 0);

        //  find the row in an element's stiffness matrix
        //  that corresponds to inode
        const int elem_node_index = node_elem_ids( element_offset + i, 1);

        local_force[0] += element_force(nelem, 0, elem_node_index);
        local_force[1] += element_force(nelem, 1, elem_node_index);
        local_force[2] += element_force(nelem, 2, elem_node_index);
      }

      internal_force(inode, 0) = local_force[0];
      internal_force(inode, 1) = local_force[1];
      internal_force(inode, 2) = local_force[2];


      Scalar v_new[3];
      Scalar a_current[3];

      const Scalar tol = 1.0e-7;

      if ( fabs(model_coords(inode,0)-x_bc) > tol ) { //not on x boundary
        acceleration(inode,0) = a_current[0] = -local_force[0] / nodal_mass(inode);
        acceleration(inode,1) = a_current[1] = -local_force[1] / nodal_mass(inode);
        acceleration(inode,2) = a_current[2] = -local_force[2] / nodal_mass(inode);
      } else { //enforce fixed BC
        acceleration(inode,0) = a_current[0] = 0;
        acceleration(inode,1) = a_current[1] = 0;
        acceleration(inode,2) = a_current[2] = 0;
      }

      velocity(inode,0,next_state) = v_new[0] = velocity(inode,0,current_state) + (*prev_dt+*dt)/2.0*a_current[0];
      velocity(inode,1,next_state) = v_new[1] = velocity(inode,1,current_state) + (*prev_dt+*dt)/2.0*a_current[1];
      velocity(inode,2,next_state) = v_new[2] = velocity(inode,2,current_state) + (*prev_dt+*dt)/2.0*a_current[2];

      displacement(inode,0,next_state) = displacement(inode,0,current_state) + *dt*v_new[0];
      displacement(inode,1,next_state) = displacement(inode,1,current_state) + *dt*v_new[1];
      displacement(inode,2,next_state) = displacement(inode,2,current_state) + *dt*v_new[2];

    }
Ejemplo n.º 3
0
// This is the function that we will tell OpenGL to call
// whenever a mouse button is pressed or released.
void mouse_button( int button, int state, int x, int y ){
	Vec2 P( model_coords( x, y ) );
	curr_pos=P;


	if( button == GLUT_LEFT_BUTTON && state == GLUT_DOWN )
	{
		last_pos = P;
		curr_pos = P;
		glutPostRedisplay();
	}
	else if( button == GLUT_LEFT_BUTTON && state == GLUT_UP )
	{
		glutPostRedisplay();
	}

}