ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

根据cad文件求给水管网求节点流量

2020-01-13 09:51:36  阅读:325  来源: 互联网

标签:node int dic pipe 网求 print ax 给水管 cad


在课程设计过程中,数据处理往往让学生头痛。本该但是由电脑完成的工作强加于人,也难怪学生叫苦连天。尤其是在求节点流量时,虽然鸿业和天正等软件具备此功能,但有兴趣的同学可以从底层开发出属于自己的程序。这里给出我的一些方法,即根据cad作图输出.dxf文件,利用python的matplotlib作出节点流量图。当然,这里要用到一个另一个第三方库dxfgrabber。具体方法如下:

1、根据所给的城市道路图按照相关规范(干管或连接管之间的间距有规范)设计节点和管段。这里应该注意,节点一定要用cad的点命令画出,再用管线连接。

2、根据最高日最高时用水量的结果,执行程序,即可获得结果图

.dxf文件的图形如下:

 

代码如下:

 1 '''根据管段流量算节点流量'''
 2 import dxfgrabber
 3 import matplotlib.pyplot as plt
 4 import numpy as np
 5 
 6 dxf = dxfgrabber.readfile("C:\\1.dxf")
 7 j = -1
 8 pipe = []
 9 coodinate = []
10 q_total = 1012-92#最高时用水量,(L/s),92为总集中流量
11 for e in dxf.entities:
12     if e.dxftype == 'LINE':
13         j += 1
14         start_node = [int(i) for i in list(e.start)]
15         end_node = [int(i) for i in list(e.end)]
16         length = int(((start_node[0] - end_node[0])**2 +
17                   (start_node[1] - end_node[1])**2)**(0.5))
18         pipe.append([start_node, end_node, length])
19         #print([start_node, end_node, length])
20     elif e.dxftype == 'POINT':
21         coodinate.append([int(i) for i in e.point])
22     else:
23         None
24 #print(coodinate)
25 
26 l_total = sum([i[2] for i in pipe])
27 q_specific = [q_total*i[2]/l_total for i in pipe]#管段流量列表
28 print(q_specific)
29         
30 x=[]
31 y=[]
32 z=[]
33 node = []#节点坐标以两元素列表存在node中
34 j=-1
35 for i in coodinate:
36     j+=1
37     x.append(i[0])
38     y.append(i[1])
39     z.append(i[2])
40     node.append([int(x[j]), int(y[j]), int(z[j])])
41     #print(node[j])
42     
43 dic = {}    
44 for i in range(len(node)):
45     dic[i]=node[i]
46 print(dic)
47 for i in node:
48     for element in pipe:
49         None
50         
51 dic_q = {k:0 for k in range(len(node))}
52 for k in dic.keys():
53     for p in range(len(pipe)):
54         if dic[k]==pipe[p][0]:
55             dic_q[k] += q_specific[p]/2
56         elif dic[k]==pipe[p][1]:
57             dic_q[k] += q_specific[p]/2
58         else:
59             None             
60 print(dic_q)           
61             
62 
63 
64 
65 fig = plt.figure(1)
66 ax = fig.gca()
67 
68 x = np.array(x)
69 y = np.array(y)
70 qtext = [i for i in dic_q.values()]
71 ax.scatter(x,y,c='r',marker='o')#print(x,y)
72 for i in range(len(pipe)):
73     ax.plot([pipe[i][0][0], pipe[i][1][0]], [pipe[i][0][1], pipe[i][1][1]], c='b')
74 
75 for i in range(len(x)):
76     ax.annotate(int(qtext[i]), xy=(x[i],y[i]))
77 
78 fig = plt.figure()
79 ax = fig.add_subplot(111)
80 for i in range(len(pipe)):
81     ax.plot([pipe[i][0][0], pipe[i][1][0]], [pipe[i][0][1], pipe[i][1][1]], c='b')
82     ax.annotate(pipe[i][2], xy=((pipe[i][0][0]+pipe[i][1][0])/2, (pipe[i][0][1]+pipe[i][1][1])/2))
83 plt.show
求节点流量程序

标签:node,int,dic,pipe,网求,print,ax,给水管,cad
来源: https://www.cnblogs.com/w-netboy/p/12185833.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有