Gas math stripping

Removed update_values(). RIP, shine on you CPU diamond.
Removed get_moles_by_id and get_archived_moles_by_id, all moles are now accessed directly to reduce call cost.
Added set_temperature and set_volume procs which recalc pressure when temperature or pressure change.
Heat_capacity is now a var updated when gases update.
Modified adjust_gas to use set_gas, modified set_gas to alter heat_capacity, total_moles, and pressure as needed.
This commit is contained in:
ComicIronic
2015-05-06 20:50:27 +01:00
parent 9d5911b404
commit c1a58dc3c3
95 changed files with 509 additions and 618 deletions

View File

@@ -26,7 +26,7 @@
. = ..()
if(!on || !network)
return
var/air_heat_capacity = air_contents.heat_capacity()
var/air_heat_capacity = air_contents.heat_capacity
var/combined_heat_capacity = current_heat_capacity + air_heat_capacity
var/old_temperature = air_contents.temperature

View File

@@ -38,8 +38,8 @@
update_cycle = air_master.current_cycle
partner.update_cycle = air_master.current_cycle
var/air_heat_capacity = air_contents.heat_capacity()
var/other_air_heat_capacity = partner.air_contents.heat_capacity()
var/air_heat_capacity = air_contents.heat_capacity
var/other_air_heat_capacity = partner.air_contents.heat_capacity
var/combined_heat_capacity = other_air_heat_capacity + air_heat_capacity
var/old_temperature = air_contents.temperature

View File

@@ -28,7 +28,7 @@
. = ..()
if(!on)
return
var/air_heat_capacity = air_contents.heat_capacity()
var/air_heat_capacity = air_contents.heat_capacity
var/combined_heat_capacity = current_heat_capacity + air_heat_capacity
var/old_temperature = air_contents.temperature

View File

@@ -45,7 +45,7 @@
return
if(air_contents.temperature > 0)
var/transfer_moles = (air_contents.return_pressure())*volume_rate/(air_contents.temperature * R_IDEAL_GAS_EQUATION)
var/transfer_moles = (air_contents.pressure)*volume_rate/(air_contents.temperature * R_IDEAL_GAS_EQUATION)
var/datum/gas_mixture/removed = air_contents.remove(transfer_moles)
@@ -63,7 +63,7 @@
injecting = 1
if(air_contents.temperature > 0)
var/transfer_moles = (air_contents.return_pressure())*volume_rate/(air_contents.temperature * R_IDEAL_GAS_EQUATION)
var/transfer_moles = (air_contents.pressure)*volume_rate/(air_contents.temperature * R_IDEAL_GAS_EQUATION)
var/datum/gas_mixture/removed = air_contents.remove(transfer_moles)

View File

@@ -33,10 +33,10 @@ obj/machinery/atmospherics/unary/oxygen_generator/process()
if(!on)
return
var/total_moles = air_contents.total_moles()
var/total_moles = air_contents.total_moles
if(total_moles < oxygen_content)
var/current_heat_capacity = air_contents.heat_capacity()
var/current_heat_capacity = air_contents.heat_capacity
var/added_oxygen = oxygen_content - total_moles

View File

@@ -26,26 +26,26 @@
//Get processable air sample and thermal info from environment
var/transfer_moles = 0.25 * environment.total_moles()
var/transfer_moles = 0.25 * environment.total_moles
var/datum/gas_mixture/external_removed = environment.remove(transfer_moles)
if (!external_removed)
return radiate()
if (external_removed.total_moles() < 10)
if (external_removed.total_moles < 10)
return radiate()
//Get same info from connected gas
var/internal_transfer_moles = 0.25 * air_contents.total_moles()
var/internal_transfer_moles = 0.25 * air_contents.total_moles
var/datum/gas_mixture/internal_removed = air_contents.remove(internal_transfer_moles)
if (!internal_removed)
environment.merge(external_removed)
return
var/combined_heat_capacity = internal_removed.heat_capacity() + external_removed.heat_capacity()
var/combined_energy = internal_removed.temperature * internal_removed.heat_capacity() + external_removed.heat_capacity() * external_removed.temperature
var/combined_heat_capacity = internal_removed.heat_capacity + external_removed.heat_capacity
var/combined_energy = internal_removed.temperature * internal_removed.heat_capacity + external_removed.heat_capacity * external_removed.temperature
if(!combined_heat_capacity) combined_heat_capacity = 1
var/final_temperature = combined_energy / combined_heat_capacity
@@ -73,14 +73,14 @@
air_contents.copy_from(network.radiate) //We can cut down on processing time by only calculating radiate() once and then applying the result
return
var/internal_transfer_moles = 0.25 * air_contents.total_moles()
var/internal_transfer_moles = 0.25 * air_contents.total_moles
var/datum/gas_mixture/internal_removed = air_contents.remove(internal_transfer_moles)
if (!internal_removed)
return
var/combined_heat_capacity = internal_removed.heat_capacity() + RADIATION_CAPACITY
var/combined_energy = internal_removed.temperature * internal_removed.heat_capacity() + (RADIATION_CAPACITY * 6.4)
var/combined_heat_capacity = internal_removed.heat_capacity + RADIATION_CAPACITY
var/combined_energy = internal_removed.temperature * internal_removed.heat_capacity + (RADIATION_CAPACITY * 6.4)
var/final_temperature = combined_energy / combined_heat_capacity

View File

@@ -93,7 +93,7 @@
if(!loc) return
var/datum/gas_mixture/environment = loc.return_air()
var/environment_pressure = environment.return_pressure()
var/environment_pressure = environment.pressure
if(pump_direction) //internal -> external
var/pressure_delta = 10000
@@ -101,7 +101,7 @@
if(pressure_checks&1)
pressure_delta = min(pressure_delta, (external_pressure_bound - environment_pressure))
if(pressure_checks&2)
pressure_delta = min(pressure_delta, (air_contents.return_pressure() - internal_pressure_bound))
pressure_delta = min(pressure_delta, (air_contents.pressure - internal_pressure_bound))
if(pressure_delta > 0.1)
if(air_contents.temperature > 0)
@@ -119,7 +119,7 @@
if(pressure_checks&1)
pressure_delta = min(pressure_delta, (environment_pressure - external_pressure_bound))
if(pressure_checks&2)
pressure_delta = min(pressure_delta, (internal_pressure_bound - air_contents.return_pressure()))
pressure_delta = min(pressure_delta, (internal_pressure_bound - air_contents.pressure))
if(pressure_delta > 0.1)
if(environment.temperature > 0)

View File

@@ -124,7 +124,7 @@
if(scrubbing)
if(scrubbing_gases.len)
var/transfer_moles = min(1, volume_rate/environment.volume)*environment.total_moles()
var/transfer_moles = min(1, volume_rate/environment.volume)*environment.total_moles
//Take a gas sample
var/datum/gas_mixture/removed = loc.remove_air(transfer_moles)
@@ -137,15 +137,13 @@
if(!(gasid in scrubbing_gases))
continue
filtered_out.adjust_gas(gasid, removed.get_moles_by_id(gasid), 0) //move to filtered
removed.set_gas(gasid, 0, 0) //set to 0
filtered_out.adjust_gas(gasid, removed.gases[gasid]) //move to filtered
removed.set_gas(gasid, 0) //set to 0
//Filter it
filtered_out.temperature = removed.temperature
filtered_out.set_temperature(removed.temperature)
filtered_out.update_values()
removed.update_values()
//Remix the resulting gases
air_contents.merge(filtered_out)
@@ -156,10 +154,10 @@
network.update = 1
else //Just siphoning all air
if (air_contents.return_pressure()>=50*ONE_ATMOSPHERE)
if (air_contents.pressure>=50*ONE_ATMOSPHERE)
return
var/transfer_moles = environment.total_moles()*(volume_rate/environment.volume)
var/transfer_moles = environment.total_moles*(volume_rate/environment.volume)
var/datum/gas_mixture/removed = loc.remove_air(transfer_moles)