/// <summary> /// Transfers heat between two physics objects /// </summary> /// <param name="other">Other physics object</param> /// <param name="thermalConductivity">kW/K</param> /// <param name="dt">delta time</param> public void TransferHeat(ThermalPhysicsSlim other, float thermalConductivity, float dt = MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS) { // T1' = k1*(T2 - T1) // T2' = k2*(T1 - T2) // T1 = e ^ ((k1 + k2) * t) // T2 = (-k2 / k1) * e ^ ((k1 + k2) * t) var k1 = -thermalConductivity / _heatCapacity; var k2 = -thermalConductivity / other._heatCapacity; var exp = (float)Math.Exp((k1 + k2) * dt); var ct = Temperature; var ot = other.Temperature; // BC: // T1(0) = _currentTemperature // T2(0) = other._currentTemperature // c1 = T1(infty) = T2(infty) = total energy / total heat capacity var c1 = ((ct * _heatCapacity) + (ot * other._heatCapacity)) / (_heatCapacity + other._heatCapacity); Temperature = c1 + (Temperature - c1) * exp; other.Temperature = c1 + (ot - c1) * exp; }
public ThermalPhysicsComponent() { Physics = new ThermalPhysicsSlim(MaterialPropertyDatabase.IronMaterial, 1, PhysicalConstants.TemperatureSpace); Physics.NeedsUpdateChanged += (old, @new) => NeedsUpdate = @new; }