Ground-state solution of Bose--Einstein condensate by directly minimizing the energy functional