From 5046ffb4cc3ae7e3195139583a61590b09cabfb9 Mon Sep 17 00:00:00 2001 From: ColsonZhang <784278850@qq.com> Date: Wed, 17 Mar 2021 15:07:37 +0800 Subject: [PATCH] add new functions of executing the simulation according to the data from the front --- README.md | 4 + handler/__pycache__/simulation.cpython-36.pyc | Bin 1781 -> 2831 bytes handler/__pycache__/spice.cpython-36.pyc | Bin 3373 -> 3368 bytes handler/simulation.py | 88 ++++++++++++++++-- handler/spice.py | 13 +-- 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index da64bee..2f80480 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,10 @@ app.py ----服务器的主程序 ## 更新日志 +* 2021年3月17号,后端更新 + + * 新增:根据前端传入的电路数据和仿真参数,进行参数转换,调用pyspice执行电路仿真 + * 待解决:仿真结果传递回前端,进行可视化展示 * 2021年3月16号,前端+后端更新 * 新增:成功将spice网表和simulation设置参数传入后端 diff --git a/handler/__pycache__/simulation.cpython-36.pyc b/handler/__pycache__/simulation.cpython-36.pyc index 6888ad5b9aa86bc6600bedd1260fb13e11807507..7c46d4f0c8d2112f4b697e8c0ca3d3fefc2c92a7 100644 GIT binary patch literal 2831 zcmaJ@&668P74M!e&5WeQ+4v(HaBxB(QA~v6P(YY zI@Ot~Ao1q;%%JZb&9jMmU`I~DclI+qS!6WC-&wwO_k;1Fo=w%nB)4zfzBN8NyuW`i zK0K{x)p)z%gbv#Lw%7g%B#H?xnQ&xZI?{c{g)2SjKV!m^f$X67TeU?XW7!4Ykv*us z1I4mpk*8*+lYP;|Rm)|wa^kEHqMq75TD1dWSj|_wW(iKj9(*)#v=4dHnXE76G+w3h zCyj41ldFF)-NW!#cfWSa=SQ~-$NM7rWUfkUtno=&%3SI3bDf6s(m1&ripPVLnEr_AnOLuD#N#xAn?+ zQp~FHdq2BX774*&F_Sl97$w3@!#xBd)J<8n2xot1Ou8ZLS5u8zAQ~rfAYv zh+HLd4Wx18q;b;8AZRWjJE5RKQYVM0u2kd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=#}U*?wLxN1Z(8jrAJNPXqDO` zYI`$^h%FF19+B~EQp^32i3`>7ee$laMX#Uu+VLPQy6v7VQuj%1p>$u> z#Vt8Jym)bPkvw^l?cRN#x{oX diff --git a/handler/__pycache__/spice.cpython-36.pyc b/handler/__pycache__/spice.cpython-36.pyc index 2062b39ccc2963fc5393b6b31e12ec7e20a3737d..c5628ffefed33f1ea4d6fd0f5af00c9d4f7234ec 100644 GIT binary patch delta 620 zcmY+AK}#D!6vtna7;>oc0Xl6A5wlXR&(V5OPCe zgQ1_mh%S!?){-R>B!Xm%1j!n0>PNq(%z%|irt9ymrYAX;=@|2>{3krFxqj9 zNJHV89EO}Ig2!iR4z8U+LzNbx#V6xX9+Q(XDE|bF*i|QoS*gBLvR8Z#{@L&F0-n#r z@B-q$WA81(ornYA3+61m0u;WAX*hP`EiQv_<4ETimM^^_QtdMzV9%|1s(Yz=kfTb* a;NBfdsgHE2M>$T{@Dg4ZcRkDF80I5#t8_vD delta 549 zcmYk2&o4tk5XX1ldwp;FezdQoRSiw05}JtU4{ahMXhcG^(q8C+(pN&_N4DkE8{sVD z;4cst2XS=~7k>i|5;t-22MDu8)1A!hPUbV;o!zU@btsy&EIo9&SdJTnypgu0;CT|g zc6S!7sE*}$j>*~ibYPY^T~6?rIKe7Cl1m+qQY5kNn-@v;Xo$<`dC^vY4|&#ZkZsw~ zjwmG#L5{(ulJvQ2`&*T2BoZ0pUPNOGJScr?KpZvrR)!&E*u7y)gF?v0KqQ@_N$hu5 zZ+BeXln%kEIvAi>&I(XW+`NV6cn_?|UA<49gWawAYMrm`);9L|PDWr71|snh_+;bo zte(&bSl6;Ni5)>-9BbqM6q9%ysVsD`Ihufby&qngLTBKFP5tt&6tYJo6TJ!=uy8me3D3<2Yn=_#LXjA=AZ&xqEyDs>g*<%%2EamAYdttP*%V3&++5z#l yr8ZvVu})~1CBJwS7n5=^08fjM5g!C!rZ*hI)TB0LXr{}yY(F!Y%hqg$uKobWJ!&=p diff --git a/handler/simulation.py b/handler/simulation.py index 02e34da..2b2d386 100644 --- a/handler/simulation.py +++ b/handler/simulation.py @@ -1,4 +1,6 @@ +import re + #----调用PySpice包---- from PySpice.Doc.ExampleTools import find_libraries from PySpice.Probe.Plot import plot @@ -19,35 +21,101 @@ class Simulator_CZ : self.circuit = Circuit(title) - def Get_Spice( spice ): - self.circuit.raw_spice += ".include D:\\Project_2020\\SPICE\\PySpice\\libraries\cmos\\180nm_cmos.mod" - self.circuit.raw_spice += spice + def Get_Spice(self, spice ): + the_circuit = ".include D:\\Project_2020\\SPICE\\PySpice\\libraries\cmos\\180nm_cmos.mod \n" + the_circuit += spice + self.circuit.raw_spice = the_circuit - def Sim(sim_type,properties): + def Sim(self, sim_type,properties): + parameter = self.Properties_Parse(sim_type,properties) + print("parameter:\n",parameter) self.simulator = self.circuit.simulator(temperature=25, nominal_temperature=25) + # print('simulator:\n',self.simulator) if(sim_type == 'transient'): self.analysis = self.simulator.transient(step_time = parameter['step_time'], end_time = parameter['end_time'], start_time = parameter['start_time'], max_time = parameter['max_time'], use_initial_condition = parameter['use_initial_condition']) - pass + print(self.analysis) + return self.analysis elif(sim_type == 'dc' ): pass elif(sim_type == 'ac' ): pass else: pass + - def Properties_Parse(sim_type,properties): + # 属性解析 + def Properties_Parse(self, sim_type,properties): parameter = {} if(sim_type == 'transient'): - parameter["step_time"] = 0 - pass - - def unit_transform(value_raw): + parameter["step_time"] = self.unit_tran(properties["step_time"]) + parameter["end_time"] = self.unit_tran(properties["end_time"]) + parameter["start_time"] = self.unit_tran(properties["start_time"]) + parameter["max_time"] = self.unit_tran(properties["max_time"]) + parameter["use_initial_condition"] = self.unit_tran(properties["use_initial_condition"]) + + elif(sim_type == 'dc' ): + pass + elif(sim_type == 'ac' ): + pass + + return parameter + + # 单位转换函数 + def unit_tran(self , value_raw): + # 匹配数字的正则表达式 + regInt = '\d+' + regFloat = '^\d+\.\d+' + regNumber = regFloat + '|' + regInt + pattern_number = re.compile(regNumber) + + # 匹配字符的正则表达式 + regChars = '([a-z]+)' + pattern_char = re.compile(regChars, re.I) + + # 进行数字和单位的提取 + unit_chars = pattern_char.findall(value_raw) + unit_num = pattern_number.findall(value_raw) + + # 进行格式转换 + # 有单位时的情况 + if(unit_chars != []): + the_unit = unit_chars[0] + + if the_unit in ['true','TRUE','True']: + return True + + elif the_unit in ['false','FALSE','False']: + return False + + elif the_unit in ['none','NONE','None']: + return None + + elif the_unit in ['us','US','uS','Us']: + if(unit_num != []): + the_num = float(unit_num[0]) + else: + the_num = float(0) + return u_us(the_num) + + elif the_unit in ['ms','MS','mS','Ms']: + if(unit_num != []): + the_num = float(unit_num[0]) + else: + the_num = float(0) + return u_us(the_num) + # 无单位时的情况 + else: + if(unit_num != []): + the_num = float(unit_num[0]) + else: + the_num = float(0) + return the_num pass diff --git a/handler/spice.py b/handler/spice.py index ad54cc6..3977768 100644 --- a/handler/spice.py +++ b/handler/spice.py @@ -29,18 +29,19 @@ class SimulationHandler(AuthBaseHandler): properties = properties_transform(properties_str) - print("sim type:",sim_type) - print("property:",properties_str) - print("spice :",spice) + # print("sim type:",sim_type) + # print("property:",properties_str) + # print("spice :\n",spice) - # simulator = Simulator_CZ() - # simulator.Get_Spice(spice) + simulator = Simulator_CZ() + simulator.Get_Spice(spice) + analysis = simulator.Sim(sim_type,properties) + print('simulation finished !') self.write("success") - def properties_transform(properties_str): properties = {} attributes = properties_str.split(";")