add new result presentation & new simulation
This commit is contained in:
parent
c90af4e313
commit
1fc0a79137
@ -59,6 +59,15 @@ app.py ----服务器的主程序
|
||||
|
||||
## 更新日志
|
||||
|
||||
* 2021年3月23号,前端更新
|
||||
|
||||
* 新增:多种仿真模式下的数据显示
|
||||
* 2021年3月22号,后端更新
|
||||
|
||||
* bug1:当放置同一种组件时,名称存在重复;手动更改名称后,需要将组件进行移动后,名称才会修改。
|
||||
* bug2:当进行组件的复制后,将组件的部分元件进行调整,将无法提取spice。
|
||||
* bug3:Tab的作用域问题,希望Tab的openmode函数中加入作用域。
|
||||
* 新增:DC仿真处理
|
||||
* 2021年3月20号,前端更新
|
||||
|
||||
* 新增:仿真结果数据显示,成功将仿真得到的节点电压绘制出来。
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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]
|
||||
|
@ -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
|
||||
|
||||
@ -116,6 +132,6 @@ class Simulator_CZ :
|
||||
else:
|
||||
the_num = float(0)
|
||||
return the_num
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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"
|
||||
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 plotPoint_tran() {
|
||||
|
||||
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 !!!');
|
||||
}
|
||||
});
|
||||
var count = 0 ;
|
||||
return sim_result ;
|
||||
};
|
||||
|
||||
function Callback_Refresh(){
|
||||
source.data.x = [];
|
||||
source.data.y = [];
|
||||
// var the_x = SimResult["time"];
|
||||
var the_x = [2,4] ;
|
||||
|
||||
// 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();
|
||||
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<sim_mode.length; i++){
|
||||
the_source[sim_mode[i]] = new Bokeh.ColumnDataSource({
|
||||
data: { x: [], y: [], color: [] }
|
||||
});
|
||||
}
|
||||
|
||||
plot.multi_line({field:"x"},{field:"y"},{source:source});
|
||||
// plot.multi_line([[1,2,3],[1,2,3]],[[2,4,6],[7,8,9]]);
|
||||
// 创建tab
|
||||
for(var i=0; i<sim_mode.length; i++){
|
||||
var div_mode = document.createElement('button');
|
||||
div_mode.setAttribute('class',"tablinks");
|
||||
div_mode.setAttribute('onclick',"openMode_Bokeh(event, 'ShowResult"+ sim_mode[i] +"')");
|
||||
|
||||
Bokeh.Plotting.show(plot,'#bokeh_01');
|
||||
div_mode.innerHTML = sim_mode[i] ;
|
||||
|
||||
div_tab.appendChild(div_mode);
|
||||
};
|
||||
|
||||
for(var i=0; i<sim_mode.length; i++){
|
||||
var div_mode = document.createElement('div');
|
||||
div_mode.setAttribute('class',"tabcontent");
|
||||
div_mode.setAttribute('id',"ShowResult"+sim_mode[i]);
|
||||
|
||||
var div_plot = document.createElement('div');
|
||||
div_plot.setAttribute('id', 'ResultPlot'+sim_mode[i] );
|
||||
div_mode.appendChild(div_plot);
|
||||
|
||||
|
||||
var div_button = document.createElement('div');
|
||||
div_button.setAttribute('id', 'button'+sim_mode[i] );
|
||||
div_mode.appendChild(div_button);
|
||||
|
||||
div_node.appendChild(div_mode);
|
||||
|
||||
var RefreshButton = document.createElement("Button");
|
||||
RefreshButton.appendChild(document.createTextNode("Refresh"));
|
||||
document.currentScript.parentElement.appendChild(RefreshButton);
|
||||
RefreshButton.addEventListener("click", Callback_Refresh);
|
||||
// RefreshButton.addEventListener("click", Callback_Refresh);
|
||||
RefreshButton.onclick = function(){
|
||||
Callback_Refresh(sim_mode[i]);
|
||||
};
|
||||
div_button.appendChild(RefreshButton);
|
||||
|
||||
var addDataButton = document.createElement("Button");
|
||||
addDataButton.appendChild(document.createTextNode("Plot"));
|
||||
document.currentScript.parentElement.appendChild(addDataButton);
|
||||
// addDataButton.addEventListener("click", plotPoint_tran);
|
||||
addDataButton.onclick = function(){
|
||||
PlotSimulationResult(sim_mode[i]);
|
||||
};
|
||||
div_button.appendChild(addDataButton);
|
||||
|
||||
// div_tab.appendChild(div_mode);
|
||||
};
|
||||
|
||||
for(var i=0; i<sim_mode.length; i++){
|
||||
bokeh_plot[i] = Bokeh.Plotting.figure({
|
||||
title: sim_mode[i],
|
||||
tools: "pan,wheel_zoom,box_zoom,reset,save",
|
||||
height: 300,
|
||||
width: 400,
|
||||
background_fill_color: "#F2F2F7"
|
||||
});
|
||||
|
||||
// add a line with data from the source
|
||||
bokeh_plot[i].multi_line({field:"x"},{field:"y"},{
|
||||
source: the_source[sim_mode[i]],
|
||||
color: {field:"color"},
|
||||
line_width: 2
|
||||
});
|
||||
// Bokeh.Plotting.show(bokeh_plot[i],'#ResultPlot'+sim_mode[i]);
|
||||
};
|
||||
|
||||
for(var i=0; i<sim_mode.length; i++){
|
||||
Bokeh.Plotting.show(bokeh_plot[i],'#ResultPlot'+sim_mode[i]);
|
||||
};
|
||||
|
@ -1202,7 +1202,7 @@ function showOutline(graph)
|
||||
// let spice = get_spice(graph);
|
||||
|
||||
var frame = document.createElement('div');
|
||||
frame.setAttribute('id','bokeh_02');
|
||||
frame.setAttribute('id','simulator');
|
||||
|
||||
// var x = document.createElement('script');
|
||||
// x.setAttribute('src','static/spice/bokeh_02.js');
|
||||
@ -1308,10 +1308,10 @@ function showOutline(graph)
|
||||
{
|
||||
|
||||
var frame = document.createElement('div');
|
||||
frame.setAttribute('id','bokeh_01');
|
||||
frame.setAttribute('id','show_result');
|
||||
|
||||
var x = document.createElement('script');
|
||||
x.setAttribute('src','static/spice/show_result.js');
|
||||
x.setAttribute('src','static/spice/show_result2.js');
|
||||
|
||||
frame.appendChild(x);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user