public void TestCombinatorics() { Model model = new Model("Test Model", Guid.NewGuid()); BasicReactionSupporter brs = new BasicReactionSupporter(); InitializeForTesting(brs); Mixture mixture = new Mixture(model, "Contents of vat 1", Guid.NewGuid()); MaterialCatalog cat = brs.MyMaterialCatalog; AddSubstance(ref mixture, cat["Nitrous Acid"], 100, 20); AddSubstance(ref mixture, cat["Potassium Hydroxide"], 150, 41); AddSubstance(ref mixture, cat["Water"], 100, 100); Assert.IsTrue(mixture.Mass.Equals(350D), "Mass is not 350 kg"); Assert.IsTrue(Math.Abs(mixture.Temperature - (18150D / 350D)) < 0.00001, "Temperature is not 51.86724 C."); IMaterial matl = mixture.RemoveMaterial(cat["Nitrous Acid"]); Debug.WriteLine("Removing all avaliable " + matl.MaterialType.Name); DiagnosticAids.DumpMaterial(mixture); Assert.IsTrue(mixture.Mass.Equals(250D), "Mass is not 250 kg"); Debug.WriteLine("Adding " + matl.MaterialType.Name + " back in."); mixture.AddMaterial(matl); DiagnosticAids.DumpMaterial(mixture); Assert.IsTrue(mixture.Mass.Equals(350D), "Mass is not 350 kg"); Debug.WriteLine("Removing 50 kg of the " + matl.MaterialType.Name); matl = mixture.RemoveMaterial(matl.MaterialType, 50.0); DiagnosticAids.DumpMaterial(mixture); Assert.IsTrue(mixture.Mass.Equals(300D), "Mass is not 300 kg"); }
public void TestRemoval() { Model model = new Model("Test Model", Guid.NewGuid()); BasicReactionSupporter brs = new BasicReactionSupporter(); InitializeForTesting(brs); Mixture mixture = new Mixture(model, "Contents of vat 1", Guid.NewGuid()); MaterialCatalog cat = brs.MyMaterialCatalog; mixture.AddMaterial(cat["Acetone"].CreateMass(100, 20)); mixture.AddMaterial(cat["Potassium Sulfate"].CreateMass(100, 20)); mixture.AddMaterial(cat["Ammonia"].CreateMass(100, 20)); Debug.WriteLine("Mixture has the following stuff..."); DiagnosticAids.DumpMaterial(mixture); Assert.IsTrue(mixture.Mass.Equals(300D), "Mixture is not 300 kg"); Debug.WriteLine("Removing 100 kg of Acetone."); IMaterial matl = mixture.RemoveMaterial(cat["Acetone"], 100); DiagnosticAids.DumpMaterial(matl); Assert.IsTrue(mixture.Mass.Equals(200D), "Mixture is not 200 kg"); Debug.WriteLine("Remaining is the following mixture:"); DiagnosticAids.DumpMaterial(mixture); }
public void TestVolumetricsOfDissolvedGases() { Model model = new Model("Test Model", Guid.NewGuid()); BasicReactionSupporter brs = new BasicReactionSupporter(); InitializeForTesting(brs); brs.MyMaterialCatalog.Add(new MaterialType(model, "Nitrous Oxide", Guid.NewGuid(), .001, 5, MaterialState.Gas)); brs.MyMaterialCatalog.Add(new MaterialType(model, "Pixie Breath", Guid.NewGuid(), .001, 5, MaterialState.Gas)); Mixture mixture = new Mixture(model, "Contents of vat 1", Guid.NewGuid()); MaterialCatalog cat = brs.MyMaterialCatalog; AddSubstance(ref mixture, cat["Nitrous Oxide"], 100, 20); Assert.IsTrue(mixture.Volume.Equals(100000D), "Mass is not 10000 liters"); AddSubstance(ref mixture, cat["Water"], 100, 50); Assert.IsTrue(mixture.Volume.Equals(100D), "Mass is not 100 liters"); RemoveSubstance(ref mixture, cat["Water"], 100); Assert.IsTrue(mixture.Volume.Equals(100000D), "Mass is not 10000 liters"); AddSubstance(ref mixture, cat["Pixie Breath"], 100, 20); Assert.IsTrue(mixture.Volume.Equals(200000D), "Mass is not 100 liters"); }
public void RegisterMaterialCatalog(MaterialCatalog materialCatalog) { if (m_materialCatalog == null) { m_materialCatalog = materialCatalog; } else { throw new ApplicationException("Attempt to register a new material catalog into a BasicReactionSupporter that already has one. This is prohibited."); } }
private void Initialize(BasicReactionSupporter brs) { MaterialCatalog mcat = brs.MyMaterialCatalog; ReactionProcessor rp = brs.MyReactionProcessor; // Model Name Guid SpecGrav SpecHeat mcat.Add(new MaterialType(null, "Water", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Hydrochloric Acid", Guid.NewGuid(), 1.1890, 2.5500, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Caustic Soda", Guid.NewGuid(), 2.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Chloride", Guid.NewGuid(), 2.1650, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sulfuric Acid 98%", Guid.NewGuid(), 1.8420, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Potassium Hydroxide", Guid.NewGuid(), 1.3000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Potassium Sulfate", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Nitrous Acid", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Nitrite", Guid.NewGuid(), 2.3800, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Potassium Nitrite", Guid.NewGuid(), 1.9150, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Aluminum Hydroxide", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Ammonia", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Ammonium Hydroxide", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Bromine", Guid.NewGuid(), 3.1200, 4.1800, MaterialState.Liquid)); Reaction r1 = new Reaction(null, "Reaction 1", Guid.NewGuid()); r1.AddReactant(mcat["Caustic Soda"], 0.5231); r1.AddReactant(mcat["Hydrochloric Acid"], 0.4769); r1.AddProduct(mcat["Water"], 0.2356); r1.AddProduct(mcat["Sodium Chloride"], 0.7644); rp.AddReaction(r1); Reaction r2 = new Reaction(null, "Reaction 2", Guid.NewGuid()); r2.AddReactant(mcat["Sulfuric Acid 98%"], 0.533622); r2.AddReactant(mcat["Potassium Hydroxide"], 0.466378); r2.AddProduct(mcat["Water"], 0.171333); r2.AddProduct(mcat["Potassium Sulfate"], 0.828667); rp.AddReaction(r2); Reaction r3 = new Reaction(null, "Reaction 3", Guid.NewGuid()); r3.AddReactant(mcat["Caustic Soda"], 0.459681368); r3.AddReactant(mcat["Nitrous Acid"], 0.540318632); r3.AddProduct(mcat["Water"], 0.207047552); r3.AddProduct(mcat["Sodium Nitrite"], 0.792952448); rp.AddReaction(r3); Reaction r4 = new Reaction(null, "Reaction 4", Guid.NewGuid()); r4.AddReactant(mcat["Potassium Hydroxide"], 0.544102); r4.AddReactant(mcat["Nitrous Acid"], 0.455898); r4.AddProduct(mcat["Water"], 0.174698); r4.AddProduct(mcat["Potassium Nitrite"], 0.825302); rp.AddReaction(r4); }
/// <summary> /// Loads the material catalog in the model with sample materials. /// </summary> /// <param name="mcat">the Material Catalog to be initialized.</param> private static void LoadSampleCatalog(MaterialCatalog mcat) { //Console.WriteLine("Warning: Specification is creating a MaterialType without propagating its molecular weight, emissions classifications or VaporPressure constants."); mcat.Add(new MaterialType(null, "Ethyl Acetate", Guid.NewGuid(), 0.9020, 1.9230, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Hydrochloric Acid", Guid.NewGuid(), 1.1890, 2.5500, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Ethanol", Guid.NewGuid(), 0.8110, 3.0000, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Hexane", Guid.NewGuid(), 0.6700, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Triethylamine", Guid.NewGuid(), 0.7290, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "MTBE", Guid.NewGuid(), 0.7400, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Isopropyl Alcohol", Guid.NewGuid(), 0.7860, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Acetone", Guid.NewGuid(), 0.7899, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Propyl Alcohol", Guid.NewGuid(), 0.8035, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Butanol", Guid.NewGuid(), 0.8100, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Aluminum Hydroxide", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Ammonia", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Ammonium Hydroxide", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Carbon Dioxide", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Manganese Sulfate", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Nitrous Acid", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Potassium Phosphate", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Potassium Sulfate", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Sulfate", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Manganese Dioxide", Guid.NewGuid(), 1.3000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Potassium Hydroxide", Guid.NewGuid(), 1.3000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Bromide", Guid.NewGuid(), 1.3000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Bisulfite", Guid.NewGuid(), 1.4800, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Titanium Dioxide", Guid.NewGuid(), 1.5000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Titanium Tetrachloride", Guid.NewGuid(), 1.5000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Nitrate", Guid.NewGuid(), 1.6000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Phosphoric Acid", Guid.NewGuid(), 1.6850, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Sulfide", Guid.NewGuid(), 1.8580, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Caustic Soda", Guid.NewGuid(), 2.0000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Chloride", Guid.NewGuid(), 2.1650, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Bicarbonate", Guid.NewGuid(), 2.2000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Nitrite", Guid.NewGuid(), 2.3800, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Potassium Nitrite", Guid.NewGuid(), 1.9150, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sodium Carbonate", Guid.NewGuid(), 2.5330, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Pot. Permanganate", Guid.NewGuid(), 2.7000, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Bromine", Guid.NewGuid(), 3.1200, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Sulfuric Acid", Guid.NewGuid(), 1.8420, 4.1800, MaterialState.Liquid)); mcat.Add(new MaterialType(null, "Methanol", Guid.NewGuid(), 0.7920, 4.1800, MaterialState.Liquid, 32)); mcat.Add(new MaterialType(null, "Methylene Chloride", Guid.NewGuid(), 2.15, 4.1800, MaterialState.Liquid, 85)); mcat.Add(new MaterialType(null, "Water", Guid.NewGuid(), 1.0000, 4.1800, MaterialState.Liquid)); mcat["Methanol"].SetAntoinesCoefficients3(7.879, 1473.1, 230, PressureUnits.mmHg, TemperatureUnits.Celsius); mcat["Methylene Chloride"].SetAntoinesCoefficients3(7.263, 1222.7, 238.4, PressureUnits.mmHg, TemperatureUnits.Celsius); mcat["Water"].SetAntoinesCoefficients3(8.040, 1715.1, 232.4, PressureUnits.mmHg, TemperatureUnits.Celsius); Debug.WriteLine(" ... sample substances loaded."); }
public void TestCompositeConstruction() { BasicReactionSupporter brs = new BasicReactionSupporter(); InitializeForTesting(brs); MaterialCatalog cat = brs.MyMaterialCatalog; Mixture mixture = Mixture.Create(cat["Acetone"].CreateMass(100, 20), cat["Potassium Sulfate"].CreateMass(100, 20), cat["Ammonia"].CreateMass(100, 20)); Debug.WriteLine("Mixture has the following stuff..."); DiagnosticAids.DumpMaterial(mixture); Assert.IsTrue(mixture.Mass.Equals(300D), "Mixture is not 300 kg"); Debug.WriteLine("Removing 100 kg of Acetone."); IMaterial matl = mixture.RemoveMaterial(cat["Acetone"], 100); DiagnosticAids.DumpMaterial(matl); Assert.IsTrue(mixture.Mass.Equals(200D), "Mixture is not 200 kg"); Debug.WriteLine("Remaining is the following mixture:"); DiagnosticAids.DumpMaterial(mixture); }
/// <summary> /// Deserializes this object from the specified XmlSerializatonContext. /// </summary> /// <param name="xmlsc">The XmlSerializatonContext from which this object is to be reconstituted.</param> public void DeserializeFrom(XmlSerializationContext xmlsc) { m_materialCatalog = (MaterialCatalog)xmlsc.LoadObject("MaterialCatalog"); m_reactionProcessor = (ReactionProcessor)xmlsc.LoadObject("ReactionProcessor"); }