Transducers for transforming thermal into mechanical energy or vice versa