Fixes mistake in scrubbing calculation

This commit is contained in:
mwerezak
2014-08-01 19:33:57 -04:00
parent 0345024f04
commit 400c1b5cf6
3 changed files with 28 additions and 19 deletions

View File

@@ -1,7 +1,14 @@
/*
Atmos processes
These procs generalize various processes used by atmos machinery, such as pumping, filtering, or scrubbing gas, allowing them to be reused elsewhere.
*/
//Generalized gas pumping proc.
//Moves gas from one gas_mixture to another and returns the amount of power needed (assuming 1 second), or -1 if no gas was pumped.
//transfer_moles - Limits the amount of moles to transfer. The actual amount of gas moved may also be limited by available_power, if given.
//available_power - the maximum amount of power that may be used when moving gas. If null then the transfer is not limited by power, however power will still be used!
//available_power - the maximum amount of power that may be used when moving gas. If null then the transfer is not limited by power.
/obj/machinery/atmospherics/var/last_flow_rate = 0 //Can't return multiple values, unfortunately...
@@ -17,7 +24,7 @@
if (available_power && specific_power > 0)
transfer_moles = min(transfer_moles, available_power / specific_power)
if (transfer_moles < MINUMUM_MOLES_TO_PUMP)
if (transfer_moles < MINUMUM_MOLES_TO_PUMP) //we check this repeatedly so that we do as little processing as possible
return -1
last_flow_rate = (transfer_moles/source.total_moles)*source.volume //group_multiplier gets divided out here
@@ -34,33 +41,36 @@
return power_draw
//Generalized gas filtering proc.
//Filters the gasses specified by filtering from one gas_mixture to another and returns the amount of power needed (assuming 1 second), or -1 if no gas was filtered.
//filtering - A list of gasids to be filtered from source
//total_transfer_moles - Limits the amount of moles to filter. The actual amount of gas filtered may also be limited by available_power, if given.
//available_power - the maximum amount of power that may be used when filtering gas. If null then the filtering is not limited by power, however power will still be used!
/obj/machinery/atmospherics/proc/filter_gas(var/list/filtering, var/datum/gas_mixture/source, var/datum/gas_mixture/sink, var/total_transfer_moles = null, var/available_power = null)
//Generalized gas scrubbing proc.
//Selectively moves specified gasses one gas_mixture to another and returns the amount of power needed (assuming 1 second), or -1 if no gas was filtered.
//filtering - A list of gasids to be scrubbed from source
//total_transfer_moles - Limits the amount of moles to scrub. The actual amount of gas scrubbed may also be limited by available_power, if given.
//available_power - the maximum amount of power that may be used when scrubbing gas. If null then the scrubbing is not limited by power.
/obj/machinery/atmospherics/proc/scrub_gas(var/list/filtering, var/datum/gas_mixture/source, var/datum/gas_mixture/sink, var/total_transfer_moles = null, var/available_power = null)
if (source.total_moles < MINUMUM_MOLES_TO_FILTER)
return -1
filtering &= source.gas //only filter gasses that are actually there.
//Filter it
var/total_specific_power = 0 //the power required to remove one mole of filterable gas
//Determine the specific power of each filterable gas type, and the total amount of filterable gas
var/total_filterable_moles = 0
var/list/specific_power_gas = list()
var/list/specific_power_gas = list() //the power required to remove one mole of pure gas, for each gas type
for (var/g in filtering)
if (source.gas[g] < MINUMUM_MOLES_TO_FILTER)
continue
var/specific_power = calculate_specific_power_gas(g, source, sink)/ATMOS_FILTER_EFFICIENCY
specific_power_gas[g] = specific_power
total_specific_power += specific_power
total_filterable_moles += source.gas[g]
if (total_filterable_moles < MINUMUM_MOLES_TO_FILTER)
return -1
var/total_specific_power = 0 //the power required to remove one mole of filterable gas
for (var/g in filtering)
var/ratio = source.gas[g]/total_filterable_moles //converts the specific power per mole of pure gas to specific power per mole of filterable gas mix
total_specific_power = specific_power_gas[g]*ratio
//Figure out how much of each gas to filter
if (!total_transfer_moles)
total_transfer_moles = total_filterable_moles
@@ -71,7 +81,7 @@
if (available_power && total_specific_power > 0)
total_transfer_moles = min(total_transfer_moles, available_power/total_specific_power)
if (total_transfer_moles < MINUMUM_MOLES_TO_FILTER)
if (total_transfer_moles < MINUMUM_MOLES_TO_FILTER) //we check this repeatedly so that we do as little processing as possible
return -1
var/power_draw = 0

View File

@@ -128,7 +128,7 @@
//limit flow rate from turfs
var/transfer_moles = min(environment.total_moles, environment.total_moles*MAX_FILTER_FLOWRATE/environment.volume) //group_multiplier gets divided out here
power_draw = filter_gas(scrubbing_gas, environment, air_contents, transfer_moles, active_power_usage)
power_draw = scrub_gas(scrubbing_gas, environment, air_contents, transfer_moles, active_power_usage)
else //Just siphon all air
//limit flow rate from turfs
var/transfer_moles = min(environment.total_moles, environment.total_moles*MAX_SIPHON_FLOWRATE/environment.volume) //group_multiplier gets divided out here

View File

@@ -119,8 +119,7 @@
. += ratio * specific_entropy_gas(g)
. /= total_moles
//Returns the ideal gas specific entropy of a specific gas in the mix. This is the entropy per mole of /pure/ gas.
//It's important not to get that mixed up with the mixed entropy, which takes into account mole ratios (I did, it was bad).
//Returns the ideal gas specific entropy of a specific gas in the mix. This is the entropy due to that gas per mole of /that/ gas in the mixture, not the entropy due to that gas per mole of gas mixture.
/datum/gas_mixture/proc/specific_entropy_gas(var/gasid)
if (!(gasid in gas) || gas[gasid] == 0)
return SPECIFIC_ENTROPY_VACUUM //that gas isn't here