In the engineering related to seismic activities, such as shale gas extraction and EGS system, numerical simulation is a common research method. In current numerical simulations, the critical value of a variable (e.g., sliding velocity) is often set artificially to determine whether the element is destabilized, on which the seismic magnitude is calculated. This practice is highly subjective and arbitrary, which leads to inaccurate calculation results. In this paper, we propose a new method for calculating seismic magnitude based on the rate-state dependent friction law. Firstly, the sliding history of each element on the sliding surface is divided into stages, and then all elements in the coseismic stage are clustered in time and space. Finally, the seismic moment of an event is obtained by calculating the sum of the corresponding areas of the "cumulative slip-fault location" plot according to the clustering labels, which in turn gives the seismic magnitude.