Exemple #1
0
void Simulation::integrateExplicitEuler()
{
	VectorX force;
	computeForces(m_mesh->m_current_positions, force);

	VectorX pos_next;
	pos_next.resize(m_mesh->m_system_dimension);

	//two explicit euler different modes:
	if (m_integration_method == INTEGRATION_EXPLICIT_EULER_DISCRETE)
	{

		//update rule here is xn+1 = xn + m_h*(vn-1 + f(xn-1,vn-1))
		pos_next = m_mesh->m_current_positions +m_h*(m_mesh->m_previous_velocities + force*m_h);
	}
	else if (m_integration_method == INTEGRATION_EXPLICIT_EULER_SYMPLETIC)
	{
		//Sympletic Euler uses the new velocity when computing for the new position
		ScalarType mh_squared = m_h*m_h;

		//vn+1 = vn + h*f(xn,vn)
		//xn+1 = xn + vn+1*h;
		//update rule here is xn+1 = xn + m_h*(vn  + f(xn,vn))
		pos_next = m_mesh->m_current_positions + m_mesh->m_current_velocities*m_h + force*mh_squared;
	}

	updatePosAndVel(pos_next);
}
void Simulation::integrateExplicitEuler()
{
    // q_{n+1} - 2q_n + q_{n-1} = h^2 * M^{-1} * force(q_{n-1})

    // inertia term 2q_n - q_{n-1} is calculated in calculateInertiaY function

    // calculate force(q_{n-1})
   // VectorX position_previous = m_mesh->m_current_positions - m_mesh->m_current_velocities*m_h;
    VectorX position_previous = m_mesh->m_current_positions - m_mesh->m_current_velocities*m_h;
    VectorX force_previous;
    computeForces(position_previous, force_previous);

	//cout<<force_previous<<endl;
    // update q_{n+1}
    ScalarType h_square = m_h*m_h;
    VectorX pos_next = m_inertia_y + h_square*m_mesh->m_inv_mass_matrix*force_previous;
	//cout<<"pos_next"<<pos_next.block_vector(0)<<endl;
	//cout<<"m_current"<<m_mesh->m_current_positions.block_vector(0)<<endl;
    updatePosAndVel(pos_next);
}