Numerical study of an explosion in a non-homogeneous medium with and without magnetic fields