diff --git a/README.md b/README.md index 7c2ef49..5d441c0 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,15 @@ app.py ----服务器的主程序 ## 更新日志 +* 2021年3月23号,前端更新 + + * 新增:多种仿真模式下的数据显示 +* 2021年3月22号,后端更新 + + * bug1:当放置同一种组件时,名称存在重复;手动更改名称后,需要将组件进行移动后,名称才会修改。 + * bug2:当进行组件的复制后,将组件的部分元件进行调整,将无法提取spice。 + * bug3:Tab的作用域问题,希望Tab的openmode函数中加入作用域。 + * 新增:DC仿真处理 * 2021年3月20号,前端更新 * 新增:仿真结果数据显示,成功将仿真得到的节点电压绘制出来。 diff --git a/handler/__pycache__/MysqlDB.cpython-36.pyc b/handler/__pycache__/MysqlDB.cpython-36.pyc index 25bcf29..e395b49 100644 Binary files a/handler/__pycache__/MysqlDB.cpython-36.pyc and b/handler/__pycache__/MysqlDB.cpython-36.pyc differ diff --git a/handler/__pycache__/sim_data_container.cpython-36.pyc b/handler/__pycache__/sim_data_container.cpython-36.pyc index 89c0ee1..7629dba 100644 Binary files a/handler/__pycache__/sim_data_container.cpython-36.pyc and b/handler/__pycache__/sim_data_container.cpython-36.pyc differ diff --git a/handler/__pycache__/simulation.cpython-36.pyc b/handler/__pycache__/simulation.cpython-36.pyc index e692fc9..fbf2ad3 100644 Binary files a/handler/__pycache__/simulation.cpython-36.pyc and b/handler/__pycache__/simulation.cpython-36.pyc differ diff --git a/handler/__pycache__/spice.cpython-36.pyc b/handler/__pycache__/spice.cpython-36.pyc index a9aa356..aa64e2c 100644 Binary files a/handler/__pycache__/spice.cpython-36.pyc and b/handler/__pycache__/spice.cpython-36.pyc differ diff --git a/handler/sim_data_container.py b/handler/sim_data_container.py index 26cc968..57f2507 100644 --- a/handler/sim_data_container.py +++ b/handler/sim_data_container.py @@ -3,17 +3,20 @@ class Sim_Data_Container : def __init__(self): self.sim_type = {'transient':False,'ac':False,'dc':False} - # self.analysis = None + self.result = {} print('container initial sucessfully !!!') def load_analysis(self, simtype, analysis): - print() self.sim_type[simtype] = True - # self.analysis = analysis - # print("loading analysising") + if(simtype == 'transient'): self.parse_transient(analysis) + elif(simtype == 'dc'): + self.parse_dc(analysis) + elif(simtype == 'ac'): + pass + def del_analysis(self): @@ -21,7 +24,7 @@ class Sim_Data_Container : self.result = {} def parse_transient(self, analysis): - # print('parsing the transient analysising !!!') + result_tran = {} result_tran['time'] = [float(i) for i in analysis.time] result_tran['nodes_name'] = list(analysis.nodes.keys()) @@ -38,5 +41,24 @@ class Sim_Data_Container : self.result['transient'] = result_tran + + def parse_dc(self, analysis): + result_dc = {} + result_dc['sweep'] = [float(i) for i in analysis.sweep] + result_dc['nodes_name'] = list(analysis.nodes.keys()) + nodes = {} + nodes = {} + for i in result_dc['nodes_name'] : + nodes[i] = [float(j) for j in analysis.nodes[i]] + result_dc['nodes'] = nodes + + result_dc['branches_name'] = list(analysis.branches.keys()) + branches = {} + for i in result_dc['branches_name']: + branches[i] = [float(j) for j in analysis.branches[i]] + result_dc['branches'] = branches + + self.result['dc'] = result_dc + def simulation_info_request(self, simtype): return self.result[simtype] diff --git a/handler/simulation.py b/handler/simulation.py index 34ff8ea..410d4c6 100644 --- a/handler/simulation.py +++ b/handler/simulation.py @@ -30,7 +30,7 @@ class Simulator_CZ : def Sim(self, sim_type,properties): parameter = self.Properties_Parse(sim_type,properties) - # print("parameter:\n",parameter) + print("parameter:\n",parameter) self.simulator = self.circuit.simulator(temperature=25, nominal_temperature=25) # print('simulator:\n',self.simulator) if(sim_type == 'transient'): @@ -39,10 +39,22 @@ class Simulator_CZ : start_time = parameter['start_time'], max_time = parameter['max_time'], use_initial_condition = parameter['use_initial_condition']) - # print(self.analysis) return self.analysis elif(sim_type == 'dc' ): - pass + print("doing the dc simulation !!!") + src_name = parameter['src_name'] + vstart = parameter['start'] + vstop = parameter['stop'] + vstep = parameter['step'] + the_args = "{} = slice({},{},{})".format(src_name, vstart, vstop, vstep) + + exec("self.analysis = self.simulator.dc( {} )".format(the_args)) + + print("dc simulation finished !!!") + # print(self.analysis) + + return self.analysis + elif(sim_type == 'ac' ): pass else: @@ -60,7 +72,11 @@ class Simulator_CZ : parameter["use_initial_condition"] = self.unit_tran(properties["use_initial_condition"]) elif(sim_type == 'dc' ): - pass + parameter["src_name"] = properties["src"] + parameter["start"] = properties["start"] + parameter["stop"] = properties["stop"] + parameter["step"] = properties["step"] + elif(sim_type == 'ac' ): pass @@ -109,13 +125,13 @@ class Simulator_CZ : 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 98eef15..6876c79 100644 --- a/handler/spice.py +++ b/handler/spice.py @@ -70,11 +70,18 @@ class SimulationInfoRequest_Handler(AuthBaseHandler): def post(self,*args,**kwargs): sim_type = self.get_argument('sim_type') + print(sim_type) + sim_info = Container_SimResult.simulation_info_request(sim_type) # sim_info = {'ab':1,'cd':2,'ef':'d2','hello':[1,2,3,4,5]} + print(sim_info) + sim_info_json = json.dumps( sim_info ) - # print('json transform ok !!') + print('json transform ok !!') + self.write( sim_info_json ) + print("send the simulation info request successfully!!!") + # self.write(json_decode(sim_info)) # self.write("successful") diff --git a/static/spice/show_result2.js b/static/spice/show_result2.js index 49e147b..17caed3 100644 --- a/static/spice/show_result2.js +++ b/static/spice/show_result2.js @@ -1,37 +1,239 @@ -// create some data and a ColumnDataSource +/* 基于bokeh.js库文件 + 使用该文件前请现在html加载相关js文件*/ -var source = new Bokeh.ColumnDataSource({ data: { x: [], y: [] } }); +// 仿真结果数据 +var SimResult = {} ; +var Flag_Refresh = {"transient":false,"dc":false,"ac":false} ; + +var color_store = ["blue","brown","cyan","green","orange","pink","purple","red","whitesmoke","yellow"]; +// create a data source to hold data +// var the_source = new Bokeh.ColumnDataSource({ +// data: { x: [], y: [], color: [] } +// }); -// make the plot -var plot = Bokeh.Plotting.figure({ - title: "BokehJS Plot", - plot_width: 400, - plot_height: 400, - background_fill_color: "#F2F2F7" -}); -var count = 0 ; +function openMode_Bokeh(evt, tabMode) { + var i, tabcontent, tablinks; + tabcontent = document.getElementsByClassName("tabcontent"); + for (i = 0; i < tabcontent.length; i++) { + tabcontent[i].style.display = "none"; + } + tablinks = document.getElementsByClassName("tablinks"); + for (i = 0; i < tablinks.length; i++) { + tablinks[i].className = tablinks[i].className.replace(" active", ""); + } + document.getElementById(tabMode).style.display = "block"; + evt.currentTarget.className += " active"; +}; -function Callback_Refresh(){ - source.data.x = []; - source.data.y = []; - // var the_x = SimResult["time"]; - var the_x = [2,4] ; +function plotPoint_tran() { - // var the_y = SimResult["nodes"][the_nodes_name[i]] ; - var the_y = [1+count,3+count]; - source.data.x.push(the_x); - source.data.y.push(the_y); - count = count+1; - source.change.emit(); + if(Flag_Refresh['transient'] == true){ + + the_source.data.x = []; + the_source.data.y = []; + the_source.data.color = []; + + + console.log("Flag_Refresh = true !"); + var the_nodes_name = SimResult['transient']["nodes_name"]; + + var the_x = SimResult['transient']["time"]; + for(var i=0; i < the_nodes_name.length; i++){ + var the_y = SimResult['transient']["nodes"][the_nodes_name[i]] ; + the_source.data.x.push(the_x); + the_source.data.y.push(the_y); + the_source.data.color.push(color_store[i%color_store.length]); + } + the_source.change.emit(); + } + else{ + alert("The information has not been updated !!!"); + } +}; +function plotPoint_dc() { + + if(Flag_Refresh['dc'] == true){ + + the_source.data.x = []; + the_source.data.y = []; + the_source.data.color = []; + + console.log("Flag_Refresh = true !"); + var the_nodes_name = SimResult['dc']["nodes_name"]; + + var the_x = SimResult['dc']["sweep"]; + for(var i=0; i < the_nodes_name.length; i++){ + var the_y = SimResult['dc']["nodes"][the_nodes_name[i]] ; + the_source.data.x.push(the_x); + the_source.data.y.push(the_y); + the_source.data.color.push(color_store[i%color_store.length]); + } + the_source.change.emit(); + } + else{ + alert("The information has not been updated !!!"); + } +}; +function plotPoint_ac() { + + if(Flag_Refresh['ac'] == true){ + + the_source.data.x = []; + the_source.data.y = []; + the_source.data.color = []; + + console.log("Flag_Refresh = true !"); + var the_nodes_name = SimResult['ac']["nodes_name"]; + + var the_x = SimResult['ac']["fre"]; + for(var i=0; i < the_nodes_name.length; i++){ + var the_y = SimResult['ac']["nodes"][the_nodes_name[i]] ; + the_source.data.x.push(the_x); + the_source.data.y.push(the_y); + the_source.data.color.push(color_store[i%color_store.length]); + } + the_source.change.emit(); + } + else{ + alert("The information has not been updated !!!"); + } +}; +function PlotSimulationResult(sim_type){ + if(sim_type == "transient"){ + plotPoint_tran(); + } + else if(sim_type == "dc"){ + plotPoint_dc(); + } + else if(sim_type == 'ac'){ + plotPoint_ac(); + } +}; + + +function requestSimInfo(sim_type){ + var data = new Object(); + var sim_result ; + + data["sim_type"] = sim_type; + console.log(sim_type); + console.log(data); + + $.ajax({ + type: 'POST', + url: "/getsiminfo", + data: data, + async:false, // 必须关闭异步!!! + dataType: "json", + success: function (siminfo) { + console.log("load sim result successfully !!"); + sim_result = siminfo; + }, + error: function(){ + alert('ajax post failed !!!'); + } + }); + return sim_result ; +}; + + +function Callback_Refresh(sim_type){ + SimResult[sim_type] = requestSimInfo(sim_type); + Flag_Refresh[sim_type] = true; +}; + + + +// bokeh组件相关变量 +var bokeh_plot = [] ; +var the_source = {} ; + + +// 添加 Tab 组件 +var sim_mode = ['transient', 'dc', 'ac']; + +var div_node = document.createElement('div'); +var div_tab = document.createElement('div'); +div_tab.setAttribute('class','tab'); +div_node.appendChild(div_tab); + +var frame = $("#show_result"); +frame.append(div_node); + + +for(var i=0; i