  Virial theorem is important for understanding stellar structures. It produces
an interesting connection between the magnetic energy and the gravitational
one. Using the general form of the virial theorem including the magnetic field
(toroidal magnetic field), we may explain the solar dynamo model in related to
variations of the magnetic and gravitational energies. We emphasize the role of
the gravitational energy in sub-surface layers which has been certainly minored
up to now. We also consider two types of solar outer shape (spherical and
spheroidal) to study the behavior of magnetic and gravitational energies. The
magnetic energy affects the solar shape, while the gravitational energy is not
changed by the considered shapes of the Sun.
