风扇模拟程序 HVAC
fan simulation program HVAC
我正在尝试创建一个简单的程序来模拟加热通风应用程序中的可变风扇。下面的脚本只是模拟基于风扇启动和加速的管道压力读数(以英寸水柱为单位)。基本上风扇会启动,管道压力将为零。当电机加速时,管道压力将每 10 秒缓慢上升一个值 0.1"WC 每 10 秒。当风扇处于 1.5 的管道压力设定点时,程序将生成一个大约 1.3 - 1.7 至模仿风扇在设定点附近徘徊。希望这是有道理的!
我觉得这可以写得更好,但以最简单的形式:
import time
from numpy.random import seed
from numpy.random import randint
# seed random number generator
seed(1)
#generate random number to mimic fan hovering at setpoint
def ductRandStatic():
value = randint(13, 17, 20)
return value * .1
ductStaticStart = 0
ductStaticEnd = 1.5
#mimic fan ramping up to setpoint slowly
def startFan():
static = ductStaticStart + .1
time.sleep(10)
if static < ductStaticEnd:
static = ductRandStatic()
else:
static = static
print(static)
while True:
startFan()
出于某种原因,该程序只打印我认为随机数生成器...我希望它每 10 秒打印一个值模拟管道压力...
[1.5 1.6 1.6 1.5 1.4 1.4 1.4 1.6 1.3 1.3 1.4 1.6 1.3 1.5 1.3 1.3 1.4 1.6
1.4 1.5]
我想你想去掉 startFan()
函数并将它的大部分代码移到主循环中,这样 static
就可以记住它的值:
# initialize to 0.1
static = 0.1
# mimic fan ramping up to setpoint slowly
while True:
if static < 1.5:
static = ductRandStatic()
print(static)
time.sleep(10)
此外,您对 randint()
的调用是错误的——它应该采用两个整数,但您传递了三个。
您的模拟有两个阶段:启动(一系列固定值)和维持(您的随机变化)。代码如下:
from time import sleep
from numpy.random import randint
def ductRandStatic():
return randint(13, 17) * 0.1
delay = 10
for i in range(16):
pressure = i * 0.1
print(pressure)
sleep(delay)
while True:
print(ductRandStatic() )
sleep(delay)
输出:
0.0
0.1
0.2
0.30000000000000004
0.4
0.5
0.6000000000000001
0.7000000000000001
0.8
0.9
1.0
1.1
1.2000000000000002
1.3
1.4000000000000001
1.5
1.5
1.6
1.4000000000000001
1.4000000000000001
1.4000000000000001
1.6
1.4000000000000001
1.4000000000000001
1.6
1.4000000000000001
1.3
1.4000000000000001
1.3
1.3
1.5
1.3
^CTraceback (most recent call last):
File "so.py", line 18, in <module>
sleep(delay)
KeyboardInterrupt
我正在尝试创建一个简单的程序来模拟加热通风应用程序中的可变风扇。下面的脚本只是模拟基于风扇启动和加速的管道压力读数(以英寸水柱为单位)。基本上风扇会启动,管道压力将为零。当电机加速时,管道压力将每 10 秒缓慢上升一个值 0.1"WC 每 10 秒。当风扇处于 1.5 的管道压力设定点时,程序将生成一个大约 1.3 - 1.7 至模仿风扇在设定点附近徘徊。希望这是有道理的!
我觉得这可以写得更好,但以最简单的形式:
import time
from numpy.random import seed
from numpy.random import randint
# seed random number generator
seed(1)
#generate random number to mimic fan hovering at setpoint
def ductRandStatic():
value = randint(13, 17, 20)
return value * .1
ductStaticStart = 0
ductStaticEnd = 1.5
#mimic fan ramping up to setpoint slowly
def startFan():
static = ductStaticStart + .1
time.sleep(10)
if static < ductStaticEnd:
static = ductRandStatic()
else:
static = static
print(static)
while True:
startFan()
出于某种原因,该程序只打印我认为随机数生成器...我希望它每 10 秒打印一个值模拟管道压力...
[1.5 1.6 1.6 1.5 1.4 1.4 1.4 1.6 1.3 1.3 1.4 1.6 1.3 1.5 1.3 1.3 1.4 1.6
1.4 1.5]
我想你想去掉 startFan()
函数并将它的大部分代码移到主循环中,这样 static
就可以记住它的值:
# initialize to 0.1
static = 0.1
# mimic fan ramping up to setpoint slowly
while True:
if static < 1.5:
static = ductRandStatic()
print(static)
time.sleep(10)
此外,您对 randint()
的调用是错误的——它应该采用两个整数,但您传递了三个。
您的模拟有两个阶段:启动(一系列固定值)和维持(您的随机变化)。代码如下:
from time import sleep
from numpy.random import randint
def ductRandStatic():
return randint(13, 17) * 0.1
delay = 10
for i in range(16):
pressure = i * 0.1
print(pressure)
sleep(delay)
while True:
print(ductRandStatic() )
sleep(delay)
输出:
0.0
0.1
0.2
0.30000000000000004
0.4
0.5
0.6000000000000001
0.7000000000000001
0.8
0.9
1.0
1.1
1.2000000000000002
1.3
1.4000000000000001
1.5
1.5
1.6
1.4000000000000001
1.4000000000000001
1.4000000000000001
1.6
1.4000000000000001
1.4000000000000001
1.6
1.4000000000000001
1.3
1.4000000000000001
1.3
1.3
1.5
1.3
^CTraceback (most recent call last):
File "so.py", line 18, in <module>
sleep(delay)
KeyboardInterrupt