mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-12 03:02:54 +00:00
Air alarm cooling now resembles thermodynamics
Gas cooling power consumption now resembles the work required to operate a Carnot heat pump. Cooling hot air takes less energy than cooling cold air.
This commit is contained in:
@@ -141,6 +141,30 @@ What are the archived variables for?
|
|||||||
|
|
||||||
return max(MINIMUM_HEAT_CAPACITY,heat_capacity_archived)
|
return max(MINIMUM_HEAT_CAPACITY,heat_capacity_archived)
|
||||||
|
|
||||||
|
//this seems like such a common thing to do I can't believe this hasn't been made into it's own proc yet.
|
||||||
|
/datum/gas_mixture/proc/add_thermal_energy(var/thermal_energy)
|
||||||
|
//Purpose: Adjusting temperature based on thermal energy transfer
|
||||||
|
//Called by: Anyone who wants to add or remove energy from the gas mix
|
||||||
|
//Inputs: An amount of energy in J to be added. Negative values remove energy.
|
||||||
|
//Outputs: The actual thermal energy change.
|
||||||
|
|
||||||
|
var/old_temperature = temperature
|
||||||
|
var/heat_capacity = heat_capacity()
|
||||||
|
|
||||||
|
temperature += thermal_energy/heat_capacity
|
||||||
|
if (temperature < 0)
|
||||||
|
temperature = 0
|
||||||
|
|
||||||
|
return (temperature - old_temperature)*heat_capacity
|
||||||
|
|
||||||
|
/datum/gas_mixture/proc/get_thermal_energy_change(var/new_temperature)
|
||||||
|
//Purpose: Determining how much thermal energy is required
|
||||||
|
//Called by: Anyone. Machines that want to adjust the temperature of a gas mix.
|
||||||
|
//Inputs: None
|
||||||
|
//Outputs: The amount of energy required to get to the new temperature in J. A negative value means that energy needs to be removed.
|
||||||
|
|
||||||
|
return heat_capacity()*(new_temperature - temperature)
|
||||||
|
|
||||||
/datum/gas_mixture/proc/total_moles()
|
/datum/gas_mixture/proc/total_moles()
|
||||||
return total_moles
|
return total_moles
|
||||||
/*var/moles = oxygen + carbon_dioxide + nitrogen + phoron
|
/*var/moles = oxygen + carbon_dioxide + nitrogen + phoron
|
||||||
|
|||||||
@@ -198,17 +198,24 @@
|
|||||||
var/datum/gas_mixture/gas
|
var/datum/gas_mixture/gas
|
||||||
gas = location.remove_air(0.25*environment.total_moles)
|
gas = location.remove_air(0.25*environment.total_moles)
|
||||||
if(gas)
|
if(gas)
|
||||||
var/heat_capacity = gas.heat_capacity()
|
|
||||||
var/energy_used = min( abs( heat_capacity*(gas.temperature - target_temperature) ), MAX_ENERGY_CHANGE)
|
|
||||||
|
|
||||||
//Use power. Assuming that each power unit represents 1 watts....
|
if (gas.temperature <= target_temperature) //gas heating
|
||||||
|
var/energy_used = min( gas.get_thermal_energy_change(target_temperature) , MAX_ENERGY_CHANGE)
|
||||||
|
|
||||||
|
gas.add_thermal_energy(energy_used)
|
||||||
use_power(energy_used, ENVIRON)
|
use_power(energy_used, ENVIRON)
|
||||||
|
else //gas cooling
|
||||||
|
var/heat_transfer = min(abs(gas.get_thermal_energy_change(target_temperature)), MAX_ENERGY_CHANGE)
|
||||||
|
|
||||||
//We need to cool ourselves.
|
//Assume the heat is being pumped into the hull which is fixed at 20 C
|
||||||
if(environment.temperature > target_temperature)
|
//none of this is really proper thermodynamics but whatever
|
||||||
gas.temperature -= energy_used/heat_capacity
|
|
||||||
else
|
//heat transfer is limited by the max amount of power the heat pump can put out, which lets say is also MAX_ENERGY_CHANGE
|
||||||
gas.temperature += energy_used/heat_capacity
|
heat_transfer = min(heat_transfer, gas.temperature/T20C*MAX_ENERGY_CHANGE)
|
||||||
|
var/energy_used = heat_transfer * T20C/gas.temperature
|
||||||
|
|
||||||
|
gas.add_thermal_energy(-heat_transfer)
|
||||||
|
use_power(energy_used * 1.1, ENVIRON) //heat pump inefficiencies
|
||||||
|
|
||||||
environment.merge(gas)
|
environment.merge(gas)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user