这可能是一个数学问题,也是一个编程问题,但是当在下面的代码中将扭曲设置为高值(1000+)时,我的类方法“update()”中似乎遇到了严重的温度波动. 为简单起见,所有温度均以开尔文为单位。
(我不是专业的程序员。这种格式可能令人不快。)
import math
#Critical to the Stefan-Boltzmann equation. Otherwise known as Sigma
BOLTZMANN_CONSTANT = 5.67e-8
class GeneratorObject(object):
"""Create a new object to run thermal simulation on."""
def __init__(self, mass, emissivity, surfaceArea, material, temp=0, power=5000, warp=1):
self.tK = temp #Temperature of the object.
self.mass = mass #Mass of the object.
self.emissivity = emissivity #Emissivity of the object. Always between 0 and 1.
self.surfaceArea = surfaceArea #Emissive surface area of the object.
self.material = material #Store the material name for some reason.
self.specificHeat = (0.45*1000)*self.mass #Get the specific heat of the object in J/kg (Iron: 0.45*1000=450J/kg)
self.power = power #Joules/Second (Watts) input. This is for heating the object.
self.warp = warp #Warp Multiplier. This pertains to how KSP's warp multiplier works.
def update(self):
"""Update the object's temperature according to it's properties."""
#This method updates the object's temperature according to heat losses and other factors.
self.tK -= (((self.emissivity * BOLTZMANN_CONSTANT * self.surfaceArea * (math.pow(self.tK,4) - math.pow(30+273.15,4))) / self.specificHeat) - (self.power / self.specificHeat)) * self.warp
使用的定律是用于计算黑体热损失的 Stefan-Boltzmann 定律:
Temp -= (发射率*Sigma*SurfaceArea*(Temp^4-Amb^4))/SpecificHeat)
这是从 KSP 插件移植的,以便更快地调试。Object.update() 每秒被调用 50 次。
是否有一种解决方案来防止这些极端振荡,而不涉及每一步多次执行代码?