Controlling the photoanode mesostructure for dye-sensitized and perovskite-sensitized solar cells