add new functions of executing the simulation according to the data from the front
parent
46d65a33b9
commit
5046ffb4cc
|
@ -59,6 +59,10 @@ app.py ----服务器的主程序
|
|||
|
||||
## 更新日志
|
||||
|
||||
* 2021年3月17号,后端更新
|
||||
|
||||
* 新增:根据前端传入的电路数据和仿真参数,进行参数转换,调用pyspice执行电路仿真
|
||||
* 待解决:仿真结果传递回前端,进行可视化展示
|
||||
* 2021年3月16号,前端+后端更新
|
||||
|
||||
* 新增:成功将spice网表和simulation设置参数传入后端
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,4 +1,6 @@
|
|||
|
||||
import re
|
||||
|
||||
#----调用PySpice包----
|
||||
from PySpice.Doc.ExampleTools import find_libraries
|
||||
from PySpice.Probe.Plot import plot
|
||||
|
@ -19,21 +21,26 @@ 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' ):
|
||||
|
@ -41,13 +48,74 @@ class Simulator_CZ :
|
|||
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
|
||||
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"])
|
||||
|
||||
def unit_transform(value_raw):
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -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(";")
|
||||
|
|
Loading…
Reference in New Issue