|
| 1 | +import yt |
| 2 | +import os |
| 3 | +import re |
| 4 | +import numpy as np |
| 5 | +from yt.utilities.parallel_tools.parallel_analysis_interface import communication_system |
| 6 | +import matplotlib.pyplot as plt |
| 7 | + |
| 8 | +yt.enable_parallelism() |
| 9 | + |
| 10 | +plt.rcParams['font.size'] = 21 |
| 11 | +plt.rcParams['font.family'] = 'serif' |
| 12 | +plt.rcParams["axes.labelsize"] = 21 |
| 13 | +plt.rcParams['mathtext.fontset'] = 'stix' |
| 14 | +plt.rcParams['savefig.bbox']='tight' |
| 15 | + |
| 16 | +curr_dir = os.getcwd() |
| 17 | +plt_dir_a04 = [f.name for f in os.scandir(curr_dir) if (f.is_dir() and re.search("^plt[0-9]{5,8}$",f.name))] |
| 18 | +plt_dir_a04.sort(key=lambda x: int(x[3:])) |
| 19 | + |
| 20 | +dir_paths_a04 = [] |
| 21 | +for dir in plt_dir_a04: |
| 22 | + dir_paths_a04.append(os.path.join(curr_dir, dir)) |
| 23 | + |
| 24 | +index_a04 = dict(zip(plt_dir_a04, [i for i in range(len(plt_dir_a04))])) |
| 25 | + |
| 26 | +curr_dir = "../nova_t7_0.8km_ext_pert" |
| 27 | +plt_dir_a08 = [f.name for f in os.scandir(curr_dir) if (f.is_dir() and re.search("^plt[0-9]{5,8}$",f.name))] |
| 28 | +plt_dir_a08.sort(key=lambda x: int(x[3:])) |
| 29 | + |
| 30 | +dir_paths_a08 = [] |
| 31 | +for dir in plt_dir_a08: |
| 32 | + dir_paths_a08.append(os.path.join(curr_dir, dir)) |
| 33 | + |
| 34 | +index_a08 = dict(zip(plt_dir_a08, [i for i in range(len(plt_dir_a08))])) |
| 35 | + |
| 36 | +curr_dir = "../nova_t7_0.2km" |
| 37 | +plt_dir_b02 = [f.name for f in os.scandir(curr_dir) if (f.is_dir() and re.search("^plt[0-9]{5,8}$",f.name))] |
| 38 | +plt_dir_b02.sort(key=lambda x: int(x[3:])) |
| 39 | + |
| 40 | +dir_paths_b02 = [] |
| 41 | +for dir in plt_dir_b02: |
| 42 | + dir_paths_b02.append(os.path.join(curr_dir, dir)) |
| 43 | + |
| 44 | +index_b02 = dict(zip(plt_dir_b02, [i for i in range(len(plt_dir_b02))])) |
| 45 | + |
| 46 | +curr_dir = "../nova_t7_0.4km" |
| 47 | +plt_dir_b04 = [f.name for f in os.scandir(curr_dir) if (f.is_dir() and re.search("^plt[0-9]{5,8}$",f.name))] |
| 48 | +plt_dir_b04.sort(key=lambda x: int(x[3:])) |
| 49 | + |
| 50 | +dir_paths_b04 = [] |
| 51 | +for dir in plt_dir_b04: |
| 52 | + dir_paths_b04.append(os.path.join(curr_dir, dir)) |
| 53 | + |
| 54 | +index_b04 = dict(zip(plt_dir_b04, [i for i in range(len(plt_dir_b04))])) |
| 55 | + |
| 56 | +ts_a08 = yt.DatasetSeries(dir_paths_a08) |
| 57 | +ts_a04 = yt.DatasetSeries(dir_paths_a04) |
| 58 | + |
| 59 | +ts_b04 = yt.DatasetSeries(dir_paths_b04[0:138]) |
| 60 | +ts_b02 = yt.DatasetSeries(dir_paths_b02[0:267]) |
| 61 | + |
| 62 | +N_a08 = len(plt_dir_a08) |
| 63 | +time_a08 = np.zeros(N_a08) |
| 64 | +qvalue_a08 = np.zeros(N_a08) |
| 65 | + |
| 66 | +N_a04 = len(plt_dir_a04) |
| 67 | +time_a04 = np.zeros(N_a04) |
| 68 | +qvalue_a04 = np.zeros(N_a04) |
| 69 | + |
| 70 | +N_b04 = len(plt_dir_b04[0:138]) |
| 71 | +time_b04 = np.zeros(N_b04) |
| 72 | +qvalue_b04 = np.zeros(N_b04) |
| 73 | + |
| 74 | +N_b02 = len(plt_dir_b02[0:267]) |
| 75 | +time_b02 = np.zeros(N_b02) |
| 76 | +qvalue_b02 = np.zeros(N_b02) |
| 77 | + |
| 78 | +comm = communication_system.communicators[-1] |
| 79 | + |
| 80 | +for ds in ts_a04.piter(): |
| 81 | + |
| 82 | + id_i = index_a04[ds.basename] |
| 83 | + |
| 84 | + sp = ds.all_data() |
| 85 | + |
| 86 | + max_enuc = sp.max("enuc") |
| 87 | + time_a04[id_i] = ds.current_time.value |
| 88 | + qvalue_a04[id_i] = max_enuc |
| 89 | + |
| 90 | + ds.index.clear_all_data() |
| 91 | + |
| 92 | +comm.barrier() |
| 93 | + |
| 94 | +for ds in ts_a08.piter(): |
| 95 | + |
| 96 | + id_i = index_a08[ds.basename] |
| 97 | + |
| 98 | + sp = ds.all_data() |
| 99 | + |
| 100 | + max_enuc = sp.max("enuc") |
| 101 | + time_a08[id_i] = ds.current_time.value |
| 102 | + qvalue_a08[id_i] = max_enuc |
| 103 | + |
| 104 | + ds.index.clear_all_data() |
| 105 | + |
| 106 | +for ds in ts_b02.piter(): |
| 107 | + |
| 108 | + id_i = index_b02[ds.basename] |
| 109 | + |
| 110 | + sp = ds.all_data() |
| 111 | + |
| 112 | + max_enuc = sp.max("enuc") |
| 113 | + time_b02[id_i] = ds.current_time.value |
| 114 | + qvalue_b02[id_i] = max_enuc |
| 115 | + |
| 116 | + ds.index.clear_all_data() |
| 117 | + |
| 118 | +for ds in ts_b04.piter(): |
| 119 | + |
| 120 | + id_i = index_b04[ds.basename] |
| 121 | + |
| 122 | + sp = ds.all_data() |
| 123 | + |
| 124 | + max_enuc = sp.max("enuc") |
| 125 | + time_b04[id_i] = ds.current_time.value |
| 126 | + qvalue_b04[id_i] = max_enuc |
| 127 | + |
| 128 | + ds.index.clear_all_data() |
| 129 | + |
| 130 | +time_a04[:] = comm.mpi_allreduce(time_a04[:], op="sum") |
| 131 | +qvalue_a04[:] = comm.mpi_allreduce(qvalue_a04[:], op="sum") |
| 132 | + |
| 133 | +time_a08[:] = comm.mpi_allreduce(time_a08[:], op="sum") |
| 134 | +qvalue_a08[:] = comm.mpi_allreduce(qvalue_a08[:], op="sum") |
| 135 | + |
| 136 | +time_b02[:] = comm.mpi_allreduce(time_b02[:], op="sum") |
| 137 | +qvalue_b02[:] = comm.mpi_allreduce(qvalue_b02[:], op="sum") |
| 138 | + |
| 139 | +time_b04[:] = comm.mpi_allreduce(time_b04[:], op="sum") |
| 140 | +qvalue_b04[:] = comm.mpi_allreduce(qvalue_b04[:], op="sum") |
| 141 | + |
| 142 | +if yt.is_root(): |
| 143 | + |
| 144 | + per = 10 |
| 145 | + t_a04 = time_a04[::per] |
| 146 | + t_a08 = time_a08[::per] |
| 147 | + t_b02 = time_b02[::per] |
| 148 | + t_b04 = time_b04[::per] |
| 149 | + |
| 150 | + q_a04 = qvalue_a04[::per] |
| 151 | + q_a08 = qvalue_a08[::per] |
| 152 | + q_b02 = qvalue_b02[::per] |
| 153 | + q_b04 = qvalue_b04[::per] |
| 154 | + |
| 155 | + fig = plt.figure() |
| 156 | + ax = fig.add_subplot(111) |
| 157 | + ax.plot(t_a04, q_a04, label="Model A4", linestyle='--') |
| 158 | + ax.plot(t_a08, q_a08, label="Model A8", linestyle='--') |
| 159 | + ax.plot(t_b02, q_b02, label="Model B2", linestyle='-', linewidth=3.0) |
| 160 | + ax.plot(t_b04, q_b04, label="Model B4", linestyle='-', linewidth=3.0) |
| 161 | + |
| 162 | + ax.set_xlabel(r'$t\,[s]$') |
| 163 | + ax.set_ylabel(r'$\dot{e}_{\mathrm{nuc},\mathrm{max}}\,[\mathrm{erg}\cdot \mathrm{g}^{-1}\,\mathrm{s}^{-1}]$') |
| 164 | + ax.set_yscale('log') |
| 165 | + ax.set_ylim(1.0e13, 1.0e19) |
| 166 | + ax.legend(loc='upper left') |
| 167 | + |
| 168 | + fig.set_size_inches(8, 6) |
| 169 | + ax.tick_params(labelsize=21) |
| 170 | + plt.tight_layout() |
| 171 | + |
| 172 | + fig.savefig('q_series_04_ext.pdf', bbox_inches="tight") |
0 commit comments