Skip to content

Commit

Permalink
atmos touchups: thermodynamics enforcement week (#6790)
Browse files Browse the repository at this point in the history
  • Loading branch information
silicons authored Oct 21, 2024
1 parent 7a0bf3c commit 656a8cb
Show file tree
Hide file tree
Showing 89 changed files with 1,666 additions and 1,308 deletions.
59 changes: 35 additions & 24 deletions citadel.dme
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@
#include "code\__DEFINES\assets\medical.dm"
#include "code\__DEFINES\atmospherics\atmos.dm"
#include "code\__DEFINES\atmospherics\atmospheres.dm"
#include "code\__DEFINES\atmospherics\constants-heat_capacity.dm"
#include "code\__DEFINES\atmospherics\constants-thermodynamics.dm"
#include "code\__DEFINES\atmospherics\constants.dm"
#include "code\__DEFINES\atmospherics\environmental.dm"
#include "code\__DEFINES\atmospherics\gas_strings.dm"
#include "code\__DEFINES\atmospherics\gasmixtures.dm"
#include "code\__DEFINES\atmospherics\helpers.dm"
#include "code\__DEFINES\atmospherics\machinery.dm"
#include "code\__DEFINES\atmospherics\math.dm"
#include "code\__DEFINES\atmospherics\pipes.dm"
#include "code\__DEFINES\atmospherics\gases\flags.dm"
#include "code\__DEFINES\atmospherics\gases\generation.dm"
Expand Down Expand Up @@ -2317,6 +2320,7 @@
#include "code\modules\atmospherics\atmosphere\planet.dm"
#include "code\modules\atmospherics\environmental\atom.dm"
#include "code\modules\atmospherics\environmental\public.dm"
#include "code\modules\atmospherics\environmental\turf-share.dm"
#include "code\modules\atmospherics\environmental\turf.dm"
#include "code\modules\atmospherics\environmental\zas\_docs.dm"
#include "code\modules\atmospherics\environmental\zas\airflow.dm"
Expand All @@ -2325,31 +2329,38 @@
#include "code\modules\atmospherics\environmental\zas\connection_manager.dm"
#include "code\modules\atmospherics\environmental\zas\controller.dm"
#include "code\modules\atmospherics\environmental\zas\debug.dm"
#include "code\modules\atmospherics\environmental\zas\edge.dm"
#include "code\modules\atmospherics\environmental\zas\fire.dm"
#include "code\modules\atmospherics\environmental\zas\phoron.dm"
#include "code\modules\atmospherics\environmental\zas\turf.dm"
#include "code\modules\atmospherics\environmental\zas\variable_settings.dm"
#include "code\modules\atmospherics\environmental\zas\zone.dm"
#include "code\modules\atmospherics\gasmixtures\flow.dm"
#include "code\modules\atmospherics\environmental\zas\edges\edge-simulated.dm"
#include "code\modules\atmospherics\environmental\zas\edges\edge-unsimulated.dm"
#include "code\modules\atmospherics\environmental\zas\edges\edge.dm"
#include "code\modules\atmospherics\gasmixtures\_helpers-compute.dm"
#include "code\modules\atmospherics\gasmixtures\_helpers-transfer.dm"
#include "code\modules\atmospherics\gasmixtures\gas.dm"
#include "code\modules\atmospherics\gasmixtures\gas_data.dm"
#include "code\modules\atmospherics\gasmixtures\gas_generation.dm"
#include "code\modules\atmospherics\gasmixtures\gas_mixture-compare.dm"
#include "code\modules\atmospherics\gasmixtures\gas_mixture-environmental.dm"
#include "code\modules\atmospherics\gasmixtures\gas_mixture-reactions.dm"
#include "code\modules\atmospherics\gasmixtures\gas_mixture-remove.dm"
#include "code\modules\atmospherics\gasmixtures\gas_mixture-share.dm"
#include "code\modules\atmospherics\gasmixtures\gas_mixture-thermodynamics.dm"
#include "code\modules\atmospherics\gasmixtures\gas_mixture.dm"
#include "code\modules\atmospherics\gasmixtures\gas_types.dm"
#include "code\modules\atmospherics\gasmixtures\gas_types_hardcoded.dm"
#include "code\modules\atmospherics\gasmixtures\immutable_mixtures.dm"
#include "code\modules\atmospherics\gasmixtures\reactions.dm"
#include "code\modules\atmospherics\gasmixtures\transfer_helpers.dm"
#include "code\modules\atmospherics\gasmixtures\procedural_gas.dm"
#include "code\modules\atmospherics\gasmixtures\gas_mixture\immutable.dm"
#include "code\modules\atmospherics\gasmixtures\gas_types\core.dm"
#include "code\modules\atmospherics\gasmixtures\gas_types\gas_types_legacy_hardcoded.dm"
#include "code\modules\atmospherics\machinery\_atmos_setup.dm"
#include "code\modules\atmospherics\machinery\_atmospherics_helpers.dm"
#include "code\modules\atmospherics\machinery\air_alarm.dm"
#include "code\modules\atmospherics\machinery\analyzer_hooks.dm"
#include "code\modules\atmospherics\machinery\datum_pipe_network.dm"
#include "code\modules\atmospherics\machinery\datum_pipeline.dm"
#include "code\modules\atmospherics\machinery\machinery.dm"
#include "code\modules\atmospherics\machinery\mainspipe.dm"
#include "code\modules\atmospherics\machinery\meter.dm"
#include "code\modules\atmospherics\machinery\pipeline.dm"
#include "code\modules\atmospherics\machinery\pipenet.dm"
#include "code\modules\atmospherics\machinery\components\component.dm"
#include "code\modules\atmospherics\machinery\components\binary_devices\algae_generator_vr.dm"
#include "code\modules\atmospherics\machinery\components\binary_devices\binary_atmos_base.dm"
Expand Down Expand Up @@ -4303,24 +4314,24 @@
#include "code\modules\power\antimatter\shielding.dm"
#include "code\modules\power\cells\device_cells.dm"
#include "code\modules\power\cells\power_cells.dm"
#include "code\modules\power\engines\rust\_setup.dm"
#include "code\modules\power\engines\rust\fusion_circuits.dm"
#include "code\modules\power\engines\rust\fusion_reactions.dm"
#include "code\modules\power\engines\rust\fusion_reagents.dm"
#include "code\modules\power\engines\rust\magpower.dm"
#include "code\modules\power\engines\rust\core\_core.dm"
#include "code\modules\power\engines\rust\core\core_control.dm"
#include "code\modules\power\engines\rust\core\core_field.dm"
#include "code\modules\power\engines\rust\fuel_assembly\fuel_assembly.dm"
#include "code\modules\power\engines\rust\fuel_assembly\fuel_compressor.dm"
#include "code\modules\power\engines\rust\fuel_assembly\fuel_control.dm"
#include "code\modules\power\engines\rust\fuel_assembly\fuel_injector.dm"
#include "code\modules\power\engines\rust\gyrotron\gyrotron.dm"
#include "code\modules\power\engines\rust\gyrotron\gyrotron_control.dm"
#include "code\modules\power\fission\carry.dm"
#include "code\modules\power\fission\computer.dm"
#include "code\modules\power\fission\engine.dm"
#include "code\modules\power\fission\rods.dm"
#include "code\modules\power\fusion\_setup.dm"
#include "code\modules\power\fusion\fusion_circuits.dm"
#include "code\modules\power\fusion\fusion_reactions.dm"
#include "code\modules\power\fusion\fusion_reagents.dm"
#include "code\modules\power\fusion\magpower.dm"
#include "code\modules\power\fusion\core\_core.dm"
#include "code\modules\power\fusion\core\core_control.dm"
#include "code\modules\power\fusion\core\core_field.dm"
#include "code\modules\power\fusion\fuel_assembly\fuel_assembly.dm"
#include "code\modules\power\fusion\fuel_assembly\fuel_compressor.dm"
#include "code\modules\power\fusion\fuel_assembly\fuel_control.dm"
#include "code\modules\power\fusion\fuel_assembly\fuel_injector.dm"
#include "code\modules\power\fusion\gyrotron\gyrotron.dm"
#include "code\modules\power\fusion\gyrotron\gyrotron_control.dm"
#include "code\modules\power\lighting\lighting.dm"
#include "code\modules\power\lighting\lights.dm"
#include "code\modules\power\lighting\lightswitch.dm"
Expand Down
48 changes: 0 additions & 48 deletions code/__DEFINES/atmospherics/atmos.dm
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
// Math constants.
/// kPa.
#define ONE_ATMOSPHERE 101.325
/// (mol^3 * s^3) / (kg^3 * L).
#define IDEAL_GAS_ENTROPY_CONSTANT 1164

#define TN60C 213.15 //! -60.0 degrees celcius
#define T0C 273.15 //! 0.0 degrees celcius
#define T20C 293.15 //! 20.0 degrees celcius
#define T100C 373.15 //! 100.0 degrees celsius
#define TCMB 2.7 //! -270.3 degrees celcius

// Radiation constants.
/// W/m^2. Kind of arbitrary. Really this should depend on the sun position much like solars.
#define AVERAGE_SOLAR_RADIATION 200
/// kPa at 20 C. This should be higher as gases aren't great conductors until they are dense. Used the critical pressure for air.
#define RADIATOR_OPTIMUM_PRESSURE 3771
/// K. The critical point temperature for air.
#define GAS_CRITICAL_TEMPERATURE 132.65
/// (3 cm + 100 cm * sin(3deg))/(2*(3+100 cm)). Unitless ratio.
#define RADIATOR_EXPOSED_SURFACE_AREA_RATIO 0.04
///m^2, surface area of 1.7m (H) x 0.46m (D) cylinder
#define HUMAN_EXPOSED_SURFACE_AREA 5.2
/// Percentage.
#define O2STANDARD 0.21
#define N2STANDARD 0.79
Expand Down Expand Up @@ -94,15 +75,6 @@
* stupid shit end
*/

// Must be between 0 and 1. Values closer to 1 equalize temperature faster. Should not exceed 0.4, else strange heat flow occurs.
#define FLOOR_HEAT_TRANSFER_COEFFICIENT 0.4
#define WALL_HEAT_TRANSFER_COEFFICIENT 0.0
#define DOOR_HEAT_TRANSFER_COEFFICIENT 0.0
/// A hack to partly simulate radiative heat.
#define SPACE_HEAT_TRANSFER_COEFFICIENT 0.2
#define OPEN_HEAT_TRANSFER_COEFFICIENT 0.4
/// A hack for now.
#define WINDOW_HEAT_TRANSFER_COEFFICIENT 0.1
// Fire damage.
#define CARBON_LIFEFORM_FIRE_RESISTANCE (T0C + 200)
#define CARBON_LIFEFORM_FIRE_DAMAGE 4
Expand All @@ -129,23 +101,3 @@
//How many moles of fuel are contained within one solid/liquid fuel volume unit
///mol/volume unit
#define LIQUIDFUEL_AMOUNT_TO_MOL 0.45
/// Pipe-insulation rate divisor.
#define NORMPIPERATE 30
/// Heat-exchange pipe insulation.
#define HEATPIPERATE 8
/// Fraction of gas transfered per process.
#define FLOWFRAC 0.99
//Flags for zone sleeping
#define ZONE_ACTIVE 1
#define ZONE_SLEEPING 0

// Defines how much of certain gas do the Atmospherics tanks start with. Values are in kpa per tile (assuming 20C)
/// A lot of N2 is needed to produce air mix, that's why we keep 90MPa of it
#define ATMOSTANK_NITROGEN 90000
/// O2 is also important for airmix, but not as much as N2 as it's only 21% of it.
#define ATMOSTANK_OXYGEN 40000
/// CO2 and PH are not critically important for station, only for toxins and alternative coolants, no need to store a lot of those.
#define ATMOSTANK_CO2 25000
#define ATMOSTANK_PHORON 25000
/// N2O doesn't have a real useful use, i guess it's on station just to allow refilling of sec's riot control canisters?
#define ATMOSTANK_NITROUSOXIDE 10000
14 changes: 12 additions & 2 deletions code/__DEFINES/atmospherics/atmospheres.dm
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
// Atmosphere IDs
//* Atmosphere IDs *//

//? abstract ids
//? Abstract IDs ?//
//? These will be converted by SSair during loading. ?//

/// Use zlevel's outdoors air
#define ATMOSPHERE_USE_OUTDOORS "!OUTDOORS"
/// Use zlevel's indoors air
#define ATMOSPHERE_USE_INDOORS "!INDOORS"
/// Use area default
#define ATMOSPHERE_USE_AREA "!AREA"

//* *//
//* Prefer not using stuff below on turfs. *//
//* You should almost always be using outdoors/indoors/area/static. *//
//* *//

// Tethermap
/// Virgo 2 planetary atmosphere ID
#define ATMOSPHERE_ID_VIRGO2 /datum/atmosphere/planet/virgo2
Expand Down
4 changes: 4 additions & 0 deletions code/__DEFINES/atmospherics/constants-heat_capacity.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//* Heat Capacity Entity Definitions *//
//* These are all in J / K. *//


55 changes: 55 additions & 0 deletions code/__DEFINES/atmospherics/constants-thermodynamics.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//* Thermodynamics - Constants *//

/**
* Constant used as absolute zero.
*
* * Why the hell is this conflicting with COSMIC_RADIATION_TEMPERATURE?
* * This is basically the absolute zero of simulation. Gas cannot / should not get colder than this, ever.
* * This is -270.3C.
* * Please get this a better name.
*/
#define TCMB 2.7
/**
* * Constant used for calculating blackbody radiation emittance.
* * Unit is W / (m^2 * K^4)
*/
#define STEFAN_BOLTZMANN_CONSTANT 5.6704e-8
/**
* Temperature of cosmic microwave background radiation used for radiative space cooling.
*
* * This is above TCMB. Why?
*/
#define COSMIC_RADIATION_TEMPERATURE 3.15

//* Thermodynamics - Radiation *//

// todo: all of these below are semi-confusing. is there a better way?

/**
* * kPa at 20C
* * This should realistically be higher as gases aren't great conductors until they are dense.
* * Uses the critical pressure for air.
*/
#define THERMODYNAMICS_OPTIMAL_RADIATOR_PRESSURE 3771
/**
* The critical point temperature for air.
*
* * This is where standard airmix's liquid / gas / supercritical phases meet.
*/
#define THERMODYANMICS_CRITICAL_TEMPERATURE_OF_AIR 132.65

/**
* Ratio of surface area exposed to theroetical star for radiative heating while in space.
*
* todo: wouldn't it be funny if this was based on overmap entity :drooling:
*/
#define THERMODYNAMICS_THEORETICAL_STAR_EXPOSURE_RATIO (1 / 4)
/**
* W / m^2 energy hitting external surfaces from a theoretical star.
*
* todo: wouldn't it be funny if this was based on overmap entity :drooling:
*/
#define THERMODYNAMICS_THEORETICAL_STAR_EXPOSED_POWER_DENSITY 200

/// m^2, surface area of 1.7m (H) x 0.46m (D) cylinder
#define THERMODYNAMICS_HUMAN_EXPOSED_SURFACE_AREA 5.2
37 changes: 28 additions & 9 deletions code/__DEFINES/atmospherics/constants.dm
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
//* Physics Constants *//

/// in Kelvin, temperature of cosmic microwave background radiation (used for radiative space cooling)
#define COSMIC_RADIATION_TEMPERATURE 3.15
/// kPa*L/(K*mol).
#define R_IDEAL_GAS_EQUATION 8.31
/// W/(m^2*K^4).
#define STEFAN_BOLTZMANN_CONSTANT 5.6704e-8

//* Simulation Constants *//

/// Volume, in liters, of a single tile. Y'KNOW WHY THIS IS A CONSTANT? WELL FOR ONE, initial_gas_mix IS MOLES, NOT PERCENTAGES OR PRESSURES. IF YOU TOUCH THIS, YOU BREAK *EVERYTHING*. DON'T TOUCH THIS.
/// Exceptions can be made if you're a big boy who knows how this clusterfuck of a ZAS/LINDA hybrid works and have good reason to touch this.
#define CELL_VOLUME 2500
/// Moles in a 2.5 m^3 cell at 101.325 kPa and 20 C.
#define CELL_MOLES (ONE_ATMOSPHERE*CELL_VOLUME/(T20C*R_IDEAL_GAS_EQUATION))

//* Gas Constants *//

/// kPa*L/(K*mol).
#define R_IDEAL_GAS_EQUATION 8.31

//* Math Helpers - Pressures *//

/// 1atm of earth-standard pressure, in kPa
#define ONE_ATMOSPHERE 101.325

//* Math Helpers - Temperatures *//

// todo: T_0C?

/**
* -60C in Kelvin
*
* * Please get this a better name. T_NEG_60C?
*/
#define TN60C 213.15
/// 0 deg C, in Kelvin
#define T0C 273.15
/// 20 deg C, in Kelvin
#define T20C 293.15
/// 100 deg C, in Kelvin
#define T100C 373.15
35 changes: 26 additions & 9 deletions code/__DEFINES/atmospherics/gasmixtures.dm
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
//! helpers for if we end up doing auxmos

#define GAS_MIXTURE_VOLUME(GM) (GM.volume * GM.group_multiplier)
#define GAS_MIXTURE_VOLUME_SINGULAR(GM) (GM.volume)
#define GAS_MIXTURE_PRESSURE(GM) (GM.return_pressure())
#define GAS_MIXTURE_TEMPERATURE(GM) (GM.temperature)
#define GAS_MIXTURE_TOTAL_MOLES(GM) (GM.total_moles * GM.group_multiplier)
#define GAS_MIXTURE_TOTAL_MOLES_SINGULAR(GM) (GM.total_moles)
#define GAS_MIXTURE_HEAT_CAPACITY(GM) (GM.heat_capacity())
//* Helpers, so we're not up a creek if we ever decide to use something like auxmos. *//
//* -- These are only necessary for things that aren't already proc-calls! -- *//

//* group multiplier dependent *//

/// Takes group_multiplier into account.
#define XGM_VOLUME(GM) (GM.volume * GM.group_multiplier)
/// Does not take group_multiplier into account.
#define XGM_VOLUME_SINGULAR(GM) (GM.volume)
/// Takes group_multiplier into account.
#define XGM_TOTAL_MOLES(GM) (GM.total_moles * GM.group_multiplier)
/// Does not take group_multiplier into account.
#define XGM_TOTAL_MOLES_SINGULAR(GM) (GM.total_moles)
/// Takes group_multiplier into account.
///
/// * In Joules
#define XGM_THERMAL_ENERGY(GM) (GM.heat_capacity() * GM.temperature)
/// Does not take group_multiplier into account.
///
/// * In Joules
#define XGM_THERMAL_ENERGY_SINGULAR(GM) (GM.heat_capacity_singular() * GM.temperature)

//* group multiplier independent *//

#define XGM_TEMPERATURE(GM) (GM.temperature)
#define XGM_PRESSURE(GM) ((GM.total_moles * R_IDEAL_GAS_EQUATION * GM.temperature) / GM.volume)
6 changes: 1 addition & 5 deletions code/__DEFINES/atmospherics/helpers.dm
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
//! gasmixtures
#define THERMAL_ENERGY(gas) (gas.temperature * gas.heat_capacity())
/// Atmospherics quantization define.
#define QUANTIZE(variable) (round(variable,0.00001))/*I feel the need to document what happens here. Basically this is used to catch most rounding errors, however it's previous value made it so that
once gases got hot enough, most procedures wouldnt occur due to the fact that the mole counts would get rounded away. Thus, we lowered it a few orders of magnititude */

/// Writes the total moles of cached gases gaslist to out_var. Use this to spare a proccall in performance critical areas.
#define TOTAL_MOLES(cached_gases, out_var)\
Expand All @@ -15,7 +11,7 @@
#define GAS_GARBAGE_COLLECT(GASGASGAS)\
var/list/CACHE_GAS = GASGASGAS;\
for(var/id in CACHE_GAS){\
if(QUANTIZE(CACHE_GAS[id]) <= 0)\
if(XGM_QUANTIZE(CACHE_GAS[id]) <= 0)\
CACHE_GAS -= id;\
}

Expand Down
11 changes: 11 additions & 0 deletions code/__DEFINES/atmospherics/math.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//* General Functions *//

/// Atmospherics quantization define.
#define XGM_QUANTIZE(variable) (round(variable,0.00001))/*I feel the need to document what happens here. Basically this is used to catch most rounding errors, however it's previous value made it so that
once gases got hot enough, most procedures wouldnt occur due to the fact that the mole counts would get rounded away. Thus, we lowered it a few orders of magnititude */
/// floating points are satanic.
///
/// checks if something is close enough to be equivalent.
/// as of right now, this is within 0.01% of the bigger number.
/// mostly only used in unit tests.
#define XGM_MOSTLY_CLOSE_ENOUGH(A, B) (abs(A - B) <= (max(abs(A), abs(B)) * 0.0001))
2 changes: 1 addition & 1 deletion code/__HELPERS/_logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ GLOBAL_LIST_INIT(testing_global_profiler, list("_PROFILE_NAME" = "Global"))
#define testing_profile_local_output(NAME) testing_profile_output(NAME, _timer_system)
#define testing_profile_local_output_all testing_profile_output_all(_timer_system)

#if defined(UNIT_TESTS) || defined(SPACEMAN_DMM)
#if defined(UNIT_TESTS) || defined(SPACEMAN_DMM) || defined(INCLUDE_UNIT_TESTS)
/proc/log_test(text)
WRITE_LOG(GLOB.test_log, text)
SEND_TEXT(world.log, text)
Expand Down
Loading

0 comments on commit 656a8cb

Please sign in to comment.