Megacasting, an advanced technology stemming from high-pressure die-casting (HPDC), offers the notable benefit of reducing costs while enhancing efficiency. Nevertheless, the rapid filling and cooling process inevitably leads to the problem of heterogeneous mechanical properties. Moreover, existing mechanical analysis methods struggle to accurately predict performances in defective castings, posing substantial challenges to the structural design megacastings. To meet this challenge, a high-precision hardening model that accounts for casting defects and saturation stress is proposed. And the shear-modified Gurson-Tvergaard-Needleman (GTN) damage model is adopted. The damage model parameters are identified by a novel framework that integrates machine learning method and optimization algorithm, which tackles the issues of high cost and low efficiency of traditional parameter identification methods. For the parameter calibration of hardening and damage models, different specimens are cut and machined from the megacasting. The results show that the proposed hardening model provides a higher fitting accuracy (R2 > 0.98) compared with the classical model. Additionally, the force-displacement curves of different specimens are compared, and the simulation is in good agreement with the experiment results. This verifies the reasonableness of the proposed framework for identifying the parameters of the damage model. Furthermore, based on the constructed machine learning model and the Sobol sensitivity analysis method, crucial parameters in the GTN damage model are identified. Local strain analysis is also performed on specimens with varied void levels. In conclusion, this study can serve as a valuable reference for the design of megacastings and contribute to the advancement of megacasting technology.