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

@@ -25,8 +25,8 @@
/obj/machinery/atmospherics/binary/circulator/proc/return_transfer_air()
var/datum/gas_mixture/removed
if(anchored && !(stat&BROKEN) )
var/input_starting_pressure = air1.return_pressure()
var/output_starting_pressure = air2.return_pressure()
var/input_starting_pressure = air1.pressure
var/output_starting_pressure = air2.pressure
last_pressure_delta = max(input_starting_pressure - output_starting_pressure + 10, 0)
//only circulate air if there is a pressure difference (plus 10 kPa to represent friction in the machine)
@@ -38,7 +38,7 @@
//Actually transfer the gas
removed = air1.remove(recent_moles_transferred)
if(removed)
last_heat_capacity = removed.heat_capacity()
last_heat_capacity = removed.heat_capacity
last_temperature = removed.temperature
//Update the gas networks.

View File

@@ -73,7 +73,7 @@
return
var/datum/gas_mixture/environment = loc.return_air()
var/environment_pressure = environment.return_pressure()
var/environment_pressure = environment.pressure
if(pump_direction) //input -> external
var/pressure_delta = 10000
@@ -81,7 +81,7 @@
if(pressure_checks&1)
pressure_delta = min(pressure_delta, (external_pressure_bound - environment_pressure))
if(pressure_checks&2)
pressure_delta = min(pressure_delta, (air1.return_pressure() - input_pressure_min))
pressure_delta = min(pressure_delta, (air1.pressure - input_pressure_min))
if(pressure_delta > 0)
if(air1.temperature > 0)
@@ -100,7 +100,7 @@
if(pressure_checks&1)
pressure_delta = min(pressure_delta, (environment_pressure - external_pressure_bound))
if(pressure_checks&4)
pressure_delta = min(pressure_delta, (output_pressure_max - air2.return_pressure()))
pressure_delta = min(pressure_delta, (output_pressure_max - air2.pressure))
if(pressure_delta > 0)
if(environment.temperature > 0)

View File

@@ -33,8 +33,8 @@
if(!on)
return
var/output_starting_pressure = air2.return_pressure()
var/input_starting_pressure = air1.return_pressure()
var/output_starting_pressure = air2.pressure
var/input_starting_pressure = air1.pressure
if(output_starting_pressure >= min(target_pressure,input_starting_pressure-10))
//No need to pump gas if target is already reached or input pressure is too low
@@ -42,7 +42,7 @@
return
//Calculate necessary moles to transfer using PV = nRT
if((air1.total_moles() > 0) && (air1.temperature>0))
if((air1.total_moles > 0) && (air1.temperature>0))
var/pressure_delta = min(target_pressure - output_starting_pressure, (input_starting_pressure - output_starting_pressure)/2)
//Can not have a pressure delta that would cause output_pressure > input_pressure

View File

@@ -55,14 +55,14 @@ Thus, the two variables affect pump operation are set in New():
if((stat & (NOPOWER|BROKEN)) || !on)
return
var/output_starting_pressure = air2.return_pressure()
var/output_starting_pressure = air2.pressure
if( (target_pressure - output_starting_pressure) < 0.01)
//No need to pump gas if target is already reached!
return
//Calculate necessary moles to transfer using PV=nRT
if((air1.total_moles() > 0) && (air1.temperature>0))
if((air1.total_moles > 0) && (air1.temperature>0))
var/pressure_delta = target_pressure - output_starting_pressure
var/transfer_moles = pressure_delta*air2.volume/(air1.temperature * R_IDEAL_GAS_EQUATION)

View File

@@ -51,8 +51,8 @@ Thus, the two variables affect pump operation are set in New():
// Pump mechanism just won't do anything if the pressure is too high/too low
var/input_starting_pressure = air1.return_pressure()
var/output_starting_pressure = air2.return_pressure()
var/input_starting_pressure = air1.pressure
var/output_starting_pressure = air2.pressure
if((input_starting_pressure < 0.01) || (output_starting_pressure > 9000))
return

View File

@@ -58,9 +58,9 @@ obj/machinery/atmospherics/trinary/filter/process()
if(!on)
return
var/output_starting_pressure = air3.return_pressure()
var/output_starting_pressure = air3.pressure
if(output_starting_pressure >= target_pressure || air2.return_pressure() >= target_pressure )
if(output_starting_pressure >= target_pressure || air2.pressure >= target_pressure )
//No need to mix if target is already full!
return
@@ -104,7 +104,7 @@ obj/machinery/atmospherics/trinary/filter/process()
filtered_out = null
for(var/gasid in gases_to_remove)
filtered_out.adjust_gas(gasid, removed.get_moles_by_id(gasid), 0)
filtered_out.adjust_gas(gasid, removed.gases[gasid], 0)
removed.set_gas(gasid, 0, 0)
air2.merge(filtered_out)

View File

@@ -40,7 +40,7 @@ obj/machinery/atmospherics/trinary/mixer/process()
if(!on)
return
var/output_starting_pressure = air3.return_pressure()
var/output_starting_pressure = air3.pressure
if(output_starting_pressure >= target_pressure)
//No need to mix if target is already full!
@@ -58,8 +58,8 @@ obj/machinery/atmospherics/trinary/mixer/process()
if(air2.temperature > 0)
transfer_moles2 = (node2_concentration*pressure_delta)*air3.volume/(air2.temperature * R_IDEAL_GAS_EQUATION)
var/air1_moles = air1.total_moles()
var/air2_moles = air2.total_moles()
var/air1_moles = air1.total_moles
var/air2_moles = air2.total_moles
if((air1_moles < transfer_moles1) || (air2_moles < transfer_moles2))
if(!transfer_moles1 || !transfer_moles2) return

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)