예제 #1
0
        private void CommandAdd(string suffix)
        {
            try
            {
                Ion      ion   = null;
                string[] parts = suffix.Split(' ');
                if (parts.Length == 3)
                {
                    ion = new Ion(parts[0], double.Parse(parts[1]), double.Parse(parts[2]));
                    ion = ionTable.Lookup(ion);
                }
                else if (parts.Length == 4)
                {
                    ion = new Ion(parts[0], int.Parse(parts[1]), double.Parse(parts[2]), double.Parse(parts[3]), double.Parse(parts[4]));
                }

                if (ion is null)
                {
                    throw new ArgumentException();
                }

                Console.WriteLine($"Adding {ion}");
                ionSet.Add(ion);
            }
            catch
            {
                CommandArgumentError();
            }
        }
예제 #2
0
        public static void Figure_EffectOfTemperature_Simple()
        {
            var ionTable = new IonTable();

            double[] temps = ScottPlot.DataGen.Consecutive(50);
            double[] ljps  = new double[temps.Length];

            for (int i = 0; i < temps.Length; i++)
            {
                Console.WriteLine($"Calculating for {temps[i]}C...");
                var ionSet = new List <Ion> {
                    new Ion("Zn", 9, 0.0284), new Ion("K", 0, 3), new Ion("Cl", 18, 3.0568)
                };
                ljps[i] = Calculate.Ljp(ionTable.Lookup(ionSet), temps[i]).mV;
            }

            var plt = new ScottPlot.Plot(800, 600);

            plt.PlotScatter(temps, ljps);
            plt.Title("JLJP Screenshot Ion Set");
            plt.YLabel("LJP (mV)");
            plt.XLabel("Temperature (C)");

            string filePath = System.IO.Path.GetFullPath("Figure_EffectOfTemperatureSimple.png");

            plt.SaveFig(filePath);
            Console.WriteLine($"Saved: {filePath}");
        }
예제 #3
0
        public Ion GetIon(string name, double c0 = 0, double cL = 0)
        {
            var ion = Table.Lookup(name);

            ion.c0 = c0;
            ion.cL = cL;
            return(ion);
        }
예제 #4
0
        private void IonTableListboxSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (IonTableListbox is null || ionTable is null || IonTableListbox.SelectedIndex < 0)
            {
                return;
            }

            string selectedIonName = IonTableListbox.SelectedItem.ToString();
            Ion    ion             = ionTable.Lookup(selectedIonName);

            IonNameTextbox.Text         = ion.name;
            IonChargeTextbox.Text       = ion.charge.ToString();
            IonConductivityTextbox.Text = (ion.conductivity * 1e4).ToString("0.000");
            IonC0Textbox.Text           = "0";
            IonCLTextbox.Text           = "0";
            Message($"Loaded Ion: {ion.nameWithCharge}", ion.ToString());

            ValidateIon();
        }
예제 #5
0
        public void Test_LjpCalculationMatches_ExampleFromSourceCode()
        {
            /* From JLJP: https://github.com/swharden/JLJP/blob/2.0.0/src/Example.java */

            Ion Zn = new Ion("Zn", MolsPerCubicMeter(9), MolsPerCubicMeter(0.0284));
            Ion K  = new Ion("K", MolsPerCubicMeter(0), MolsPerCubicMeter(3));
            Ion Cl = new Ion("Cl", MolsPerCubicMeter(18), MolsPerCubicMeter(3.0568));

            var ionSet = new List <Ion> {
                Zn, K, Cl
            };
            var ionTable = new IonTable();

            ionSet = ionTable.Lookup(ionSet);
            var ljp = Calculate.Ljp(ionSet);

            Assert.AreEqual(-20.79558643, ljp.mV, 1e-6);
        }
예제 #6
0
        public void Test_LjpCalculationMatches_Harper004()
        {
            // ion set from Harper (1985) Table I
            // https://pubs.acs.org/doi/pdf/10.1021/j100255a022

            var ionSet = new List <Ion>
            {
                new Ion("Zn", .4, .0186),
                new Ion("SO4", .4, .0186),
            };

            var ionTable = new IonTable();

            ionSet = ionTable.Lookup(ionSet);

            var ljp = Calculate.Ljp(ionSet);

            Assert.AreEqual(-8.1, ljp.mV, 0.5);
        }
예제 #7
0
        public void Test_LjpCalculationMatches_Harper003()
        {
            // ion set from Harper (1985) Table I
            // https://pubs.acs.org/doi/pdf/10.1021/j100255a022

            var ionSet = new List <Ion>
            {
                new Ion("Ca", .29, .00545),
                new Ion("Cl", .29 * 2, .00545 * 2)
            };

            var ionTable = new IonTable();

            ionSet = ionTable.Lookup(ionSet);

            var ljp = Calculate.Ljp(ionSet);

            Assert.AreEqual(-35, ljp.mV, 0.5);
        }
예제 #8
0
        public void Test_LjpCalculationMatches_ExampleFromScreenshot()
        {
            /* Test came from screenshot on original JLJP website */

            var ionSet = new List <Ion>
            {
                new Ion("Zn", 9, 0.0284),
                new Ion("K", 0, 3),
                new Ion("Cl", 18, 3.0568)
            };

            var ionTable = new IonTable();

            ionSet = ionTable.Lookup(ionSet);

            var ljp = Calculate.Ljp(ionSet);

            Assert.AreEqual(-20.79558643, ljp.mV, 1e-6);
        }
예제 #9
0
        public void Test_LjpCalculationMatches_NgAndBarry001()
        {
            /* LJP for this test came from Ng and Barry (1994) Table 2 */

            // 50 mM NaCl : 50 mM KCl
            var ionSet = new List <Ion>
            {
                new Ion("Na", 50, 0),
                new Ion("K", 0, 50),
                new Ion("Cl", 50, 50)
            };

            var ionTable = new IonTable();

            ionSet = ionTable.Lookup(ionSet);

            var ljp = Calculate.Ljp(ionSet);

            Assert.AreEqual(-4.3, ljp.mV, 0.5);
        }
예제 #10
0
        public void Test_LjpCalculationMatches_JPWin002()
        {
            // ion set shown in JPCalcWin manual (page 10)
            // https://tinyurl.com/wk7otn7

            var ionSet = new List <Ion>
            {
                new Ion("Cs", 145, 0),
                new Ion("Na", 0, 145),
                new Ion("F", 125, 0),
                new Ion("Cl", 20, 145)
            };

            var ionTable = new IonTable();

            ionSet = ionTable.Lookup(ionSet);

            var ljp = Calculate.Ljp(ionSet);

            Assert.AreEqual(+8.71, ljp.mV, 0.5);
        }
예제 #11
0
        public void Test_LjpCalculationMatches_NgAndBarry005()
        {
            /* LJP for this test came from Ng and Barry (1994) Table 2 */

            // 100 CaCl2 : 100 MgCl2
            // Ca (100), Cl (200) : Mg (100) Cl (200)
            var ionSet = new List <Ion>
            {
                new Ion("Ca", 100, 0),
                new Ion("Mg", 0, 100),
                new Ion("Cl", 200, 200)
            };

            var ionTable = new IonTable();

            ionSet = ionTable.Lookup(ionSet);

            var ljp = Calculate.Ljp(ionSet);

            Assert.AreEqual(+0.6, ljp.mV, 0.5);
        }
예제 #12
0
        public void Test_LjpCalculationMatches_NgAndBarry007()
        {
            /* LJP for this test came from Ng and Barry (1994) Table 2 */

            // 50 CaCl2 + 50 MgCl2 : 100 LiCl
            // Ca (50), Cl (200), Mg (50) : Li (100), Cl (100)
            var ionSet = new List <Ion>
            {
                new Ion("Ca", 50, 0),
                new Ion("Cl", 200, 100),
                new Ion("Mg", 50, 0),
                new Ion("Li", 0, 100)
            };

            var ionTable = new IonTable();

            ionSet = ionTable.Lookup(ionSet);

            var ljp = Calculate.Ljp(ionSet);

            Assert.AreEqual(-8.2, ljp.mV, 0.5);
        }
예제 #13
0
        public void Test_LjpCalculationMatches_NgAndBarry006()
        {
            /* LJP for this test came from Ng and Barry (1994) Table 2 */

            // 100 KCl + 2 CaCl2 : 100 LiCl + 2 CaCl2
            // K (100), Cl (104), Ca (2) : Li (100), Cl (104), Ca (2)
            var ionSet = new List <Ion>
            {
                new Ion("Ca", 2, 2),
                new Ion("K", 100, 0),
                new Ion("Li", 0, 100),
                new Ion("Cl", 104, 104)
            };

            var ionTable = new IonTable();

            ionSet = ionTable.Lookup(ionSet);

            var ljp = Calculate.Ljp(ionSet);

            Assert.AreEqual(+6.4, ljp.mV, 0.5);
        }
예제 #14
0
        public static void Figure_EffectOfTemperature_SeveralSets()
        {
            /* this study calculates one of several known ionSets at every temperature between 0C and 50C */

            var ionTable = new IonTable();

            double[] temps             = ScottPlot.DataGen.Consecutive(50);
            double[] jljpResults       = new double[temps.Length];
            double[] ngAndBarryResults = new double[temps.Length];
            double[] HarperResults     = new double[temps.Length];
            double[] jpWinResults      = new double[temps.Length];

            List <Ion> ionSet;

            for (int i = 0; i < temps.Length; i++)
            {
                Console.WriteLine($"Calculating for {temps[i]}C...");

                // see LjpCalculationTests.cs for ion set citations

                // create a new ion set for each iteration to prevent modifications due to solving from carrying to the next solve

                ionSet = new List <Ion> {
                    new Ion("Zn", 9, 0.0284), new Ion("K", 0, 3), new Ion("Cl", 18, 3.0568)
                };
                jljpResults[i] = Calculate.Ljp(ionTable.Lookup(ionSet), temps[i]).mV;

                ionSet = new List <Ion> {
                    new Ion("Ca", 2, 2), new Ion("K", 100, 0), new Ion("Li", 0, 100), new Ion("Cl", 104, 104)
                };
                ngAndBarryResults[i] = Calculate.Ljp(ionTable.Lookup(ionSet), temps[i]).mV;

                ionSet = new List <Ion> {
                    new Ion("Ca", .29, .00545), new Ion("Cl", .29 * 2, .00545 * 2)
                };
                HarperResults[i] = Calculate.Ljp(ionTable.Lookup(ionSet), temps[i]).mV;

                ionSet = new List <Ion> {
                    new Ion("Na", 10, 145), new Ion("Cl", 10, 145), new Ion("Cs", 135, 0), new Ion("F", 135, 0)
                };
                jpWinResults[i] = Calculate.Ljp(ionTable.Lookup(ionSet), temps[i]).mV;
            }

            var mplt = new ScottPlot.MultiPlot(800, 600, 2, 2);

            mplt.subplots[0].PlotScatter(temps, jljpResults);
            mplt.subplots[0].Title("JLJP screenshot");

            mplt.subplots[1].PlotScatter(temps, ngAndBarryResults);
            mplt.subplots[1].Title("Ng and Barry (1994)");

            mplt.subplots[2].PlotScatter(temps, HarperResults);
            mplt.subplots[2].Title("Harper (1985)");

            mplt.subplots[3].PlotScatter(temps, jpWinResults);
            mplt.subplots[3].Title("JPWin screenshot");

            for (int i = 0; i < 4; i++)
            {
                mplt.subplots[i].YLabel("LJP (mV)");
                mplt.subplots[i].XLabel("Temperature (C)");
            }

            string filePath = System.IO.Path.GetFullPath("Figure_EffectOfTemperature.png");

            mplt.SaveFig(filePath);
            Console.WriteLine($"Saved: {filePath}");
        }