這可能是一個數學問題,儘管它是一個編程問題,但我似乎遇到嚴重的溫度振盪在我的類方法「更新()」當warp設置爲一個高值(1000 +)在下面的代碼。爲簡單起見,所有溫度都以開爾文爲單位不可控的模擬振盪
(我不是一個程序員的職業此格式可能是不愉快的。)
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
使用的法律是計算黑體熱損失史蒂芬 - 玻耳茲曼定律:
溫度 - =(發射率*西格瑪*表面積*(溫度^ 4-Amb^4))/ SpecificHeat)
這是從KSP插件中移植出來的,用於快速調試。 Object.update()每秒被調用50次。
會不會有一個解決方案來防止這些不涉及每步執行代碼多次的極端振盪?
時間間隔不應該是該方程中的一個因子嗎? – Beta
我試圖模擬你所要求的,但找不到matlib包。 也可以啓動參數有幫助。 – MiooiM
代替調用matlib,只需將self.specificHeat設置爲450.我忽略從代碼中去除額外的模塊。 Obj = GeneratorObject(100,0.93,10,「iron」,0,0,1)self.Warp大於500通常會導致超出範圍的錯誤。 – Calrizan