diff --git a/A/4/kinematics_check.py b/A/4/kinematics_check.py index de87c55..4a59d6b 100644 --- a/A/4/kinematics_check.py +++ b/A/4/kinematics_check.py @@ -188,7 +188,7 @@ if __name__ == "__main__": orbit = BetterOrbit() loong = Loong(orbit, 224, mp.mpf("1.0"), mp.mpf("1e-8")) res_list = [] - for ti in np.arange(5, 10, 0.025): + for ti in np.arange(10, 20, 0.025): print(f"calculating time_point={ti}", file=sys.stderr) res_list.append(loong.CalcStatusListByTime(mp.mpf(ti), res_list[-1] if res_list else None)) # 转换成内置浮点数并保留6位 diff --git a/A/4/seek_max.py b/A/4/seek_max.py index 4adcf54..0d3e738 100644 --- a/A/4/seek_max.py +++ b/A/4/seek_max.py @@ -6,9 +6,13 @@ kSampleNum = 1000 kStep = (kTiEnd - kTiBeg) / kSampleNum kParallelNum=24 tasks_list = [i for i in np.arange(kTiBeg, kTiEnd, kStep)] -for i in np.arange(0, 10, 0.1): +for i in np.arange(10, 20, 1/1000): tasks_list.append(i) -for i in np.arange(5, 10, 5.0/1000): +for i in np.arange(12, 14.2, 1/10000): + tasks_list.append(i) +for i in np.arange(13,13.2,1/100000): + tasks_list.append(i) +for i in np.arange(13.085,13.095,1/1000000): tasks_list.append(i) task_list_per_process=[tasks_list[i::kParallelNum] for i in range(kParallelNum)] @@ -18,18 +22,33 @@ def ProcessEntryPoint(arg): orbit = GoodOrbit() loong = Loong(orbit, 224, mp.mpf("1.0"), mp.mpf("1e-8")) max_speed_found=mp.mpf("0.0") + max_speed_time=0 + last_status = None + last_ti = ti_list[0] for ti in ti_list: print(f"calculating time_point={ti}",file=sys.stderr) - res = loong.CalcStatusListByTime(mp.mpf(ti)) - for node in res: - max_speed_found=max(max_speed_found,node["v"]) - return max_speed_found + try: + res = loong.CalcStatusListByTime(mp.mpf(ti), last_status if (last_status and abs(ti-last_ti)<=0.1) else None) + for node in res: + if node["v"] > max_speed_found: + max_speed_found = node["v"] + max_speed_time = ti + last_status = res + last_ti = ti + except ValueError as e: + print(f"Error: {e}",file=sys.stdout) + return max_speed_found, max_speed_time if __name__ == "__main__": manager = multiprocessing.Manager() task_args_list = [(task_list_per_process[i], i) for i in range(kParallelNum)] with multiprocessing.Pool(processes=kParallelNum) as pool: res_list=pool.map(ProcessEntryPoint, task_args_list) - max_speed_found=max(res_list) + max_speed_found=mp.mpf("0.0") + max_speed_time=0 + for res in res_list: + if res[0]>max_speed_found: + max_speed_found=res[0] + max_speed_time=res[1] valid_head_speed = mp.mpf("1.0") * (mp.mpf("2.0")/max_speed_found) - print(f"max_speed_found={max_speed_found}, valid_head_speed={valid_head_speed}") \ No newline at end of file + print(f"max_speed_found={max_speed_found} at {max_speed_time}, valid_head_speed={valid_head_speed}") \ No newline at end of file