write task5

This commit is contained in:
2024-09-07 15:52:12 +08:00
parent cd429d4abf
commit 4c409ace18
2 changed files with 54 additions and 0 deletions

19
A/4/A4_to_csv.py Normal file
View File

@@ -0,0 +1,19 @@
import json
with open("A4_res.json", "r") as file:
content=json.load(file)
fout1=open("tmp1.dat","w")
for node_point in range(224):
for time_point in range(201):
v=content[time_point][node_point]["v"]
print(v,'\t',file=fout1,sep="",end="")
print('\n',file=fout1,end="",sep="")
fout2=open("tmp2.dat","w")
for node_point in range(224):
for time_point in range(201):
x=content[time_point][node_point]["node"][0]
print(x,'\t',file=fout2,sep="",end="")
print('\n',file=fout2,end="",sep="")
for time_point in range(201):
y=content[time_point][node_point]["node"][1]
print(y,'\t',file=fout2,sep="",end="")
print('\n',file=fout2,end="",sep="")

35
A/4/seek_max.py Normal file
View File

@@ -0,0 +1,35 @@
from simulator import *
kTiBeg = -100
kTiEnd = 100
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):
tasks_list.append(i)
for i in np.arange(5, 10, 5.0/1000):
tasks_list.append(i)
task_list_per_process=[tasks_list[i::kParallelNum] for i in range(kParallelNum)]
print(f"len(task_list_per_thread)={len(task_list_per_process)}",file=sys.stderr)
def ProcessEntryPoint(arg):
ti_list, process_id = arg
orbit = GoodOrbit()
loong = Loong(orbit, 224, mp.mpf("1.0"), mp.mpf("1e-8"))
max_speed_found=mp.mpf("0.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
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)
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}")