Last active
July 7, 2016 15:22
-
-
Save YotaXP/d671fbd03698a2b1a40e86abe8777e20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
public static class GasConstants | |
{ | |
const float OneAtmosphere = 101.325; // kPa | |
const float IdealGasEquation = 8.31; // kPa*L/(K*mol) | |
const float TemperatureCosmicMicrowaveBackround = 2.7; // K | |
} | |
public sealed class GasType | |
{ | |
public string Name { get; private set; } | |
public string ShortName { get; private set; } | |
public float SpecificHeat { get; private set; } | |
private GasType(string name, string shortName, float specificHeat) | |
{ | |
Name = name; | |
ShortName = shortName; | |
SpecificHeat = specificHeat; | |
} | |
public static GasType Oxygen = new GasType("oxygen", "O2", 20); | |
public static GasType Nitrogen = new GasType("nitrogen", "N", 20); | |
public static GasType Plasma = new GasType("plasma", "Pl", 300); | |
public static GasType NitrousOxide = new GasType("nitrous oxide", "N2O", 40); | |
public static GasType CarbonDioxide = new GasType("carbon dioxide", "CO2", 30); | |
} | |
public class GasMixture | |
{ | |
private Dictionary<GasType, float> moles = new Dictionary<GasType, float>(); | |
private float temperature = GasConstants.TemperatureCosmicMicrowaveBackround; | |
// Moles | |
public float this[GasType type] { | |
get { | |
if (moles.ContainsKey(type)) | |
return moles[type]; | |
else | |
return 0; | |
} | |
set | |
{ | |
if (value <= float.Epsilon) | |
moles.Remove(type); | |
else | |
moles[type] = value; | |
} | |
} | |
// Returns in K | |
public float Temperature { | |
get { return temperature; } | |
set { temperature = Math.Max(value, GasConstants.TemperatureCosmicMicrowaveBackround); } | |
} | |
// Returns in kPa, volume in L | |
public float Pressure(float volume) | |
{ | |
return moles.Values.Sum() * GasConstants.IdealGasEquation * temperature / volume; | |
} | |
public float HeatCapacity() | |
{ | |
return moles.Sum(g => g.Value * g.Key.SpecificHeat); | |
} | |
//public void AddGas(GasMixture otherMixture) { ... } | |
public void MoveGas(GasMixture otherMixture, float percentage) { ... } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment