In order to study the magnetic compensation of Marine diesel engines, finite element simulation is used to guide the degaussing design work. In the geomagnetic environment, a finite element simulation model of a diesel engine is established by using Ansys Maxwell software, to calculate the spatial distribution of the induced magnetic field of the diesel engine. compared with the measured magnetic field of the diesel engine, the error is not more than 10%,within the error range allowed. and the compensation coil is used to compensate the magnetic field of the diesel engine. By optimizing the setting of the compensation current, the maximum magnetic field of the diesel engine is reduced from 336nT to 50nT, reducing about 85%.