public void neutralize(Beaker beaker)
        {
            float H  = beaker.getComponentVolume(ChemNotation.ion_H);
            float OH = beaker.getComponentVolume(ChemNotation.ion_OH);

            if (H > 0 && OH > 0)
            {
                int[] reactionRatio = densityToReactionRatio();

                // Because without reaction, amount of positive ion : negative ion = 1 : 1
                float OH_by_K  = beaker.getComponentVolume(ChemNotation.ion_K);
                float OH_by_Na = OH - OH_by_K;

                // Need to optimize those algorithms..
                if (H / reactionRatio[0] > OH_by_K / reactionRatio[1] + OH_by_Na / reactionRatio[2])
                {
                    beaker.removeBeakerComponent(ChemNotation.ion_H, H - (H / reactionRatio[0] - (OH_by_K / reactionRatio[1] + OH_by_Na / reactionRatio[2])));
                    beaker.removeBeakerComponent(ChemNotation.ion_OH, OH);
                    beaker.addBeakerComponent(ChemNotation.H2O, OH);
                }
                else
                {
                    beaker.removeBeakerComponent(ChemNotation.ion_H, H);
                    beaker.removeBeakerComponent(ChemNotation.ion_OH, OH - (OH_by_K / reactionRatio[1] + OH_by_Na / reactionRatio[2] - H / reactionRatio[0]));
                    beaker.addBeakerComponent(ChemNotation.H2O, H);
                }
            }
        }
Ejemplo n.º 2
0
 private void linkToGraph()
 {
     for (int i = 0; i < 5; i++)
     {
         GraphWindow.Instance.AddValue(i, defaultBeaker.getComponentVolume(i));
     }
 }