不同位置管道排液量

2024-05-13 17:16:56 发布

您现在位置:Python中文网/ 问答频道 /正文

这可能更像是一个算法问题,但我是用Python编写的。你知道吗

我有一组关于一条管道的数据,随着管道的进展,它会上升或下降。我的数据是两列,沿管道的测量值和该测量值处的高程。我的数据集中有上万行。(这些将是列而不是行)

测量:1、2、3、4、5、6、7、8、9、10

立面图:5、7、9、15、12、13、18、14、23、9

在这个脚本中,假设管道两端都有封顶。我们的目标是计算出管道中任何一点泄漏时排出的液体的总体积。压力/流量无关紧要。我试图解释的主要部分是所有的陷阱/山谷(比如浴室水槽),液体会留在里面,即使剩下的管道排水,像这样:

https://www.youtube.com/watch?v=o82yNzLIKYo

管道半径和泄漏位置将由用户设置参数。你知道吗

我真的在寻找一个正确的方向,我想自己尽可能地解决这个问题。但在实际的编程上,我会很有帮助的,谢谢你的建议。 enter image description here

就这么说吧 graph泄漏出现在x轴的第9点,并且管道的半径已知r。我正在想办法让我的脚本输出总的液体量,以r计,无论时间长短,都会被清空。如果管道发生泄漏,空气会进来,水也会出来,但并不是所有的水都会出来,这是因为管道的水位和水位不同。你知道吗


Tags: 数据脚本算法目标管道半径体积流量
2条回答

如果我正确理解了这个问题,我认为这可以通过 从泄漏点左右移动管道。在每个点 将当前水位与管道高程进行比较 在水位保持不变的淹没点,或海滩和 一个新的干峰。插值是计算物体位置所必需的 海滩。你知道吗

实现如下所示。算法的大部分在 traverse函数。希望评论能提供足够的描述。你知道吗

#!/usr/bin/python3

import numpy as np
import matplotlib.pyplot as pp

# Positions and elevations
n = 25
h = np.random.random((n, ))
x = np.linspace(0, 1, h.size)

# Index of leak
leak = np.random.randint(0, h.size)

# Traverse a pipe with positions (x) and elevations (h) from a leak index
# (leak) in a direction (step, +1 or -1). Return the positions of the changes
# in water level (y) the elevations at these changes (g) and the water level
# values (w).
def traverse(x, h, leak, step):
    # End of the index range for the traversal
    end = h.size if step == 1 else -1
    # Initialise 1-element output arrays with values at the leak
    y, g, w = [x[leak]], [h[leak]], [h[leak]]
    # Loop from the index adjacent to the leak
    for i in range(leak + step, end, step):
        if w[-1] > h[i]:
            # The new height is less than the old water level. Location i is
            # submerged. No new points are created and the water level stays
            # the same.
            y.append(x[i])
            g.append(h[i])
            w.append(w[-1])
        else:
            # The new height is greater than the old water level. We have a
            # "beach" and a "dry peak".
            # ...
            # Calculate the location of the beach as the position where the old
            # water level intersects the pipe section from [i-step] to [i].
            # This is added as a new point. The elevation and water level are
            # the same as the old water level.
            # ...
            # The if statement is not strictly necessary. It just prevents
            # duplicate points being generated.
            if w[-1] != h[i-step]:
                t = (w[-1] - h[i-step])/(h[i] - h[i-step])
                b = x[i-step] + (x[i] - x[i-step])*t
                y.append(b)
                g.append(w[-1])
                w.append(w[-1])
            # ...
            # Add the dry peak.
            y.append(x[i])
            g.append(h[i])
            w.append(h[i])
    # Convert from list to numpy array and return
    return np.array(y), np.array(g), np.array(w)

# Traverse left and right
yl, gl, wl = traverse(x, h, leak, -1)
yr, gr, wr = traverse(x, h, leak, 1)

# Combine, reversing the left arrays and deleting the repeated start point
y = np.append(yl[:0:-1], yr)
g = np.append(gl[:0:-1], gr)
w = np.append(wl[:0:-1], wr)

# Output the total volume of water by integrating water level minus elevation
print('Total volume =', np.trapz(w - g, y), 'm^3 per unit cross sectional area')

# Display
pp.plot(x, h, '.-', label='elevation')
pp.plot(y, w, '.-', label='water level')
pp.plot([x[leak]], [h[leak]], 'o', label='leak')
pp.legend()
pp.show()

Sample output

对于半径远小于高程变化的等半径管道,即管道截面始终充满水。我认为,在这种情况下,如果管道末端加盖,就不起作用,必须有一些空气进入,让水流出。管道中仍充满水的部分位于左侧自由面(绿色圆圈)和右侧自由面(红色正方形)之间。为简单起见,假定管道的两端都是最大高程点,否则管道将自身清空。平衡可能不稳定。你知道吗

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

def find_first_intersection(x, y, y_leak):
    for i in range(len(x)-1):
        dy_left = y[i] - y_leak
        dy_right = y[i+1] -  y_leak

        if  dy_left*dy_right < 0:
            x_free = x[i] + (y_leak - y[i])*(x[i+1] - x[i])/(y[i+1] - y[i])
            break

    return x_free

# Generate random data
x = np.linspace(0, 1, 10)
y = np.random.rand(*np.shape(x))
y[0], y[-1] = 1.1, 1.1
x_leak = np.random.rand(1)

# Look for the free surfaces
y_leak = np.interp(x_leak, x, y)

x_free_left = find_first_intersection(x, y, y_leak)
x_free_right =  find_first_intersection(x[::-1], y[::-1], y_leak)

# Plot
plt.plot(x, y, '-', label='pipe');
plt.plot(x_leak, y_leak, 'sk', label='leak')
plt.axhline(y=y_leak, linestyle=':', label='surface level');

plt.plot(x_free_left, y_leak, 'o', label="left free surface");
plt.plot(x_free_right, y_leak, 's', label="right free surface");

plt.legend(bbox_to_anchor=(1.5, 1.)); plt.xlabel('x'); plt.ylabel('y');

example

我在图表上添加了一些注释。我认为水会留在“令人困惑的部分”是令人困惑的,因为我认为这只适用于非常小直径的管道。对于一个更大的管道,这里的水将流经泄漏,然后估计管道的剩余填充部分更为复杂。。。你知道吗

相关问题 更多 >