Phase transitions and shape memory in NiTi