Chemical evolution using smooth particle hydrodynamical cosmological simulations – I. Implementation, tests and first results