A hydrodynamic approach is used to find an analytical solution to hydrodynamic equations in a soliton approximation for one- and two-dimensional layer collisions. The stages of compression, decompression, and expansion are investigated using a single formula for layers with energies of around 10 MeV per nucleon. Two-dimensional generalization produces a region of a rarefied bubble at the stage of expansion. The approach is of intrinsic interest and can be used in other fields of physics to calculate the nonlinear dynamics of oscillations of complex systems.