public void AddFraction(ChemFraction fraction) { if (Infinite) { return; } ChemFraction newFrac = null; if (Fractions.ContainsKey(fraction.Element.Name)) { newFrac = Fractions[fraction.Element.Name]; newFrac.Mass += fraction.Mass; //newFrac.Heat+=fraction.Heat; } else { newFrac = fraction; Fractions[fraction.Element.Name] = newFrac; } massCache += fraction.Mass; //heatCache+=fraction.Heat; heatCapSumCache += fraction.Mass * fraction.Element.HeatCap; }
void TakeFraction(ChemFraction target, float mass, List <string> toRemove) { if (float.IsNaN(mass) || float.IsInfinity(mass)) { throw new UnityException("TakeFraction argument is Nan or Infinity!"); } if (Fractions.ContainsKey(target.Element.Name)) { ChemFraction source = Fractions[target.Element.Name]; float deltaM = 0; if (source.Mass <= mass) { deltaM = source.Mass; if (!Infinite) { source.Mass = 0; } } else { deltaM = mass; if (!Infinite) { source.Mass -= mass; } } plant.MaxDeltaM = Mathf.Max(plant.MaxDeltaM, deltaM); if (!Infinite) { if (source.Mass == 0) { toRemove.Add(target.Element.Name); } heatCapSumCache -= deltaM * target.Element.HeatCap; massCache -= deltaM; if (Fractions.Count == 0) { heatCapSumCache = 0; massCache = 0; Heat = 0; } if (heatCapSumCache < 0) { RebuildCache(); } } target.Mass += deltaM; //target.Heat+=deltaH; } }
// Use this for initialization void Start() { plant = GetComponentInParent <Plant>(); ChemFraction fraction = new ChemFraction(SteamElement); fraction.Mass = Constants.WorldPressure * Tank.Volume / (Constants.R * Constants.WorldTemp); Tank.Mix.AddFraction(fraction); Tank.Mix.Heat = Constants.WorldTemp * SteamElement.HeatCap * fraction.Mass; Tank.Mix.RebuildCache(); boilerHeat = new CTIntegrator(plant, 300f * CMboiler); boilerDelay = new CTDelay(plant, 0, 0.05f); }
// Use this for initialization void Start() { ChemVolume vol = GetComponent <ChemVolume>(); bool old = vol.Mix.Infinite; vol.Mix.Infinite = false; ChemFraction fraction = new ChemFraction(Element); fraction.Mass = Pressure * vol.Volume / (Constants.R * Temperature); vol.Mix.AddFraction(fraction); vol.Mix.Heat = Temperature * Element.HeatCap * fraction.Mass; vol.Mix.RebuildCache(); vol.Mix.Infinite = old; }
public ChemMix TakeMix(float mass) { ChemMix res = new ChemMix(plant); if (Mass == 0) { return(res); } float[] weights = new float[Fractions.Count]; int index = 0; foreach (ChemFraction f in Fractions.Values) { weights[index] = f.Mass / Mass; index++; } float deltaH = Heat * mass / massCache; plant.MaxDeltaH = Mathf.Max(plant.MaxDeltaH, deltaH); index = 0; List <string> toRemove = new List <string>(); foreach (ChemFraction f in Fractions.Values) { ChemFraction target = new ChemFraction(f.Element); TakeFraction(target, mass * weights[index], toRemove); index++; res.AddFraction(target); } foreach (string name in toRemove) { Fractions.Remove(name); } if (!Infinite) { Heat -= Mathf.Min(deltaH, Heat); } res.Heat += deltaH; return(res); }