From 66bce8c42d4d851af6bbc70a3f9fbbb7f0cb4d0b Mon Sep 17 00:00:00 2001 From: CGH0S7 <776459475@qq.com> Date: Tue, 12 May 2026 14:56:38 +0800 Subject: [PATCH] Add plot-only restart script to skip recomputation when plotting is interrupted Co-Authored-By: Claude Opus 4.7 --- AMSS_NCKU_Program_Plot.py | 100 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 AMSS_NCKU_Program_Plot.py diff --git a/AMSS_NCKU_Program_Plot.py b/AMSS_NCKU_Program_Plot.py new file mode 100644 index 0000000..f64bb43 --- /dev/null +++ b/AMSS_NCKU_Program_Plot.py @@ -0,0 +1,100 @@ +################################################################## +## +## AMSS-NCKU Plot-Only Restart Script +## Author: Xiaoqu / Claude +## 2026/05/12 +## +## This script checks for existing output data from AMSS_NCKU_Program.py. +## If data exists, it skips all computation and goes directly to plotting, +## saving time when plotting was interrupted. +## If no data is found, it exits with a message. +## +################################################################## + +## Guard against re-execution by multiprocessing child processes. +if __name__ != '__main__': + import sys as _sys + _sys.exit(0) + + +import os +import sys + +import AMSS_NCKU_Input as input_data + +################################################################## + +## Construct paths from input configuration +File_directory = os.path.join(input_data.File_directory) +output_directory = os.path.join(File_directory, "AMSS_NCKU_output") +binary_results_directory = os.path.join(output_directory, input_data.Output_directory) +figure_directory = os.path.join(File_directory, "figure") + +################################################################## + +## Check whether the required output data files exist + +required_files = [ + os.path.join(binary_results_directory, "bssn_BH.dat"), + os.path.join(binary_results_directory, "bssn_ADMQs.dat"), + os.path.join(binary_results_directory, "bssn_psi4.dat"), + os.path.join(binary_results_directory, "bssn_constraint.dat"), +] + +missing_files = [f for f in required_files if not os.path.exists(f)] + +if missing_files: + print(" No existing AMSS_NCKU_Program.py output data found. ") + print(" The following required files are missing: ") + for f in missing_files: + print(f" {f}") + print() + print(" Please run AMSS_NCKU_Program.py first to generate the simulation data. ") + print(" Exiting. ") + sys.exit(1) + +print(" Found existing AMSS_NCKU_Program.py output data. " ) +print(" Skipping all computation and going directly to plotting. " ) +print() + +## Ensure the figure directory exists (it should, but be safe) +os.makedirs(figure_directory, exist_ok=True) + +################################################################## + +## Plot the AMSS-NCKU program results + +import plot_xiaoqu +import plot_GW_strain_amplitude_xiaoqu +from parallel_plot_helper import run_plot_tasks_parallel + +plot_tasks = [] + +## Plot black hole trajectory +plot_tasks.append((plot_xiaoqu.generate_puncture_orbit_plot, (binary_results_directory, figure_directory))) +plot_tasks.append((plot_xiaoqu.generate_puncture_orbit_plot3D, (binary_results_directory, figure_directory))) + +## Plot black hole separation vs. time +plot_tasks.append((plot_xiaoqu.generate_puncture_distence_plot, (binary_results_directory, figure_directory))) + +## Plot gravitational waveforms (psi4 and strain amplitude) +for i in range(input_data.Detector_Number): + plot_tasks.append((plot_xiaoqu.generate_gravitational_wave_psi4_plot, (binary_results_directory, figure_directory, i))) + plot_tasks.append((plot_GW_strain_amplitude_xiaoqu.generate_gravitational_wave_amplitude_plot, (binary_results_directory, figure_directory, i))) + +## Plot ADM mass evolution +for i in range(input_data.Detector_Number): + plot_tasks.append((plot_xiaoqu.generate_ADMmass_plot, (binary_results_directory, figure_directory, i))) + +## Plot Hamiltonian constraint violation over time +for i in range(input_data.grid_level): + plot_tasks.append((plot_xiaoqu.generate_constraint_check_plot, (binary_results_directory, figure_directory, i))) + +run_plot_tasks_parallel(plot_tasks) + +## Plot stored binary data (runs serially, not in the parallel pool) +plot_xiaoqu.generate_binary_data_plot(binary_results_directory, figure_directory) + +print() +print(" Plotting completed successfully. ") +print()