Numerical simulations of the solar granulation. I - Basic equations and methods