A new method of calculating the flow and magnetic fields of the sun