Contact metamorphism occurs when