private void LinearScalingAdapterTest(double scale, double massLinearity, double durationLinearity, double expectedWaterMass, TimeSpan expectedDuration) { Debug.WriteLine("We define a spec to test the removal of 50 kg of water from a mixture of 100 kg Water, 100 kg NaNO2."); TSTestJig tj = new TSTestJig(100, 100); MaterialTransferSpecByMass msbm = new MaterialTransferSpecByMass(tj.H2O_Type, 50, TimeSpan.FromMinutes(50)); if (!massLinearity.Equals(double.NaN)) { Debug.WriteLine("We provide the spec with a mass scaling adapter with linearity = " + massLinearity.ToString("F2")); msbm.SetMassScalingAdapter(new DoubleLinearScalingAdapter(msbm.Mass, massLinearity)); } else { Debug.WriteLine("The spec will have no mass scaling."); } if (!durationLinearity.Equals(double.NaN)) { Debug.WriteLine("We provide the spec with a duration scaling adapter with linearity = " + durationLinearity.ToString("F2")); msbm.SetDurationScalingAdapter(new TimeSpanLinearScalingAdapter(msbm.Duration, durationLinearity)); } else { Debug.WriteLine("The spec will have no duration scaling."); } Debug.WriteLine("We now scale the request by " + scale.ToString("F2")); msbm.Rescale(scale); IMaterial effluent = msbm.GetExtract(tj.Mixture); Debug.WriteLine("In the end, we obtained... " + effluent + " in " + msbm.Duration); Debug.WriteLine("... leaving " + tj.Mixture + ""); Debug.WriteLine("We expected " + expectedWaterMass + " kg of water in " + expectedDuration + "\r\n\r\n"); Assert.IsTrue(true == effluent.Mass.Equals(expectedWaterMass), "Water mass is not the expected one."); Assert.IsTrue(true == TimeSpan.FromTicks(Math.Abs(msbm.Duration.Ticks - expectedDuration.Ticks)) < TimeSpan.FromMilliseconds(50), "Duration is bigger then the expeced one."); }
public void TestRemovalByMassFromSubstance() { Model model = new Model("Hello, world.", Guid.NewGuid()); BasicReactionSupporter brs = new BasicReactionSupporter(); LoadSampleCatalog(brs.MyMaterialCatalog); // Now try to remove by mass from a substance. Debug.WriteLine("\r\nWe now work on a substance."); MaterialType mt = brs.MyMaterialCatalog["Hydrochloric Acid"]; Substance s = (Substance)mt.CreateMass(100, 20); Debug.WriteLine("We have " + s); MaterialTransferSpecByMass tsbm = new MaterialTransferSpecByMass(brs.MyMaterialCatalog["Hydrochloric Acid"], 10, TimeSpan.FromMinutes(5)); Debug.WriteLine("Want to remove " + tsbm); IMaterial removee = tsbm.GetExtract(s); Debug.WriteLine("Successful in removing " + removee + ".\r\nWhat remains is "); Debug.WriteLine(s); Assert.IsTrue(Math.Abs(s.Mass - 90.00) < 0.01, "The Water part is not 90 kg"); Assert.IsTrue(tsbm.Duration.Equals(new TimeSpan(0, 0, 5, 0, 0)), "Removing 10 kg Water part did not take 5 Min"); }
[TestMethod] public void TestNonScaledByMassTransfer() { TSTestJig tj = new TSTestJig(100, 100); Debug.WriteLine(tj.Mixture); MaterialTransferSpecByMass msbm = new MaterialTransferSpecByMass(tj.H2O_Type, 50, TimeSpan.FromMinutes(50)); IMaterial effluent = msbm.GetExtract(tj.Mixture); Debug.WriteLine(effluent); Debug.WriteLine(tj.Mixture); }
public void TestRemovalByMassFromMixture() { Model model = new Model("Hello, world.", Guid.NewGuid()); BasicReactionSupporter brs = new BasicReactionSupporter(); LoadSampleCatalog(brs.MyMaterialCatalog); // Define reactions Reaction r = new Reaction(null, "Reaction", Guid.NewGuid()); r.AddReactant(brs.MyMaterialCatalog["Caustic Soda"], 0.5231); r.AddReactant(brs.MyMaterialCatalog["Hydrochloric Acid"], 0.4769); r.AddProduct(brs.MyMaterialCatalog["Water"], 0.2356); r.AddProduct(brs.MyMaterialCatalog["Sodium Chloride"], 0.7644); brs.MyReactionProcessor.AddReaction(r); Mixture mixture = new Mixture(model, "Test mixture 1", Guid.NewGuid()); brs.MyReactionProcessor.Watch(mixture); // Add substances AddSubstance(ref mixture, brs.MyMaterialCatalog["Caustic Soda"], 40, 20.0); AddSubstance(ref mixture, brs.MyMaterialCatalog["Hydrochloric Acid"], 40, 20.0); mixture.Temperature = 100.0; // Definitions to retrive substances from mixture Substance water = null; Substance hydrochloricAcid = null; Substance sodiumCloride = null; foreach (Substance su in mixture.Constituents) { switch (su.Name) { case "Water": water = su; break; case "Hydrochloric Acid": hydrochloricAcid = su; break; case "Sodium Chloride": sodiumCloride = su; break; } } Assert.IsTrue(Math.Abs(hydrochloricAcid.Mass - 3.53) < 0.01, "The Hydrochloric Acid part is not 3.53 kg"); Assert.IsTrue(Math.Abs(water.Mass - 18.01) < 0.01, "The Water part is not 18.01 kg"); Assert.IsTrue(Math.Abs(sodiumCloride.Mass - 58.45) < 0.01, "The Sodium Cloride part is not 58.45 kg"); // Remove 10 kg of water MaterialTransferSpecByMass tsbm = new MaterialTransferSpecByMass(brs.MyMaterialCatalog["Water"], 10, TimeSpan.FromMinutes(5)); Debug.WriteLine("Want to remove " + tsbm); IMaterial removee = tsbm.GetExtract(mixture); Debug.WriteLine("Successful in removing " + removee + ".\r\nWhat remains is "); Debug.WriteLine(mixture); foreach (Substance su in mixture.Constituents) { switch (su.Name) { case "Water": water = su; break; case "Hydrochloric Acid": hydrochloricAcid = su; break; case "Sodium Chloride": sodiumCloride = su; break; } } Assert.IsTrue(Math.Abs(hydrochloricAcid.Mass - 3.53) < 0.01, "The Hydrochloric Acid part is not 3.53 kg"); Assert.IsTrue(Math.Abs(water.Mass - 8.01) < 0.01, "The Water part is not 8.01 kg"); Assert.IsTrue(Math.Abs(sodiumCloride.Mass - 58.45) < 0.01, "The Sodium Chloride part is not 58.45 kg"); Assert.IsTrue(tsbm.Duration.Equals(new TimeSpan(0, 0, 5, 0, 0)), "Removing 10 kg Water part did not take 5 Min"); }