618 |
613 |
619 var AT = $("#wa_acid_name").val(); |
614 var AT = $("#wa_acid_name").val(); |
620 var BT = $("#wa_base_name").val(); |
615 var BT = $("#wa_base_name").val(); |
621 |
616 |
622 var result = GetAcidSpecs(AT); |
617 var result = GetAcidSpecs(AT); |
623 pK1 = result.pK1; |
618 var pK1 = result.pK1; |
624 pK2 = result.pK2; |
619 var pK2 = result.pK2; |
625 pK3 = result.pK3; |
620 var pK3 = result.pK3; |
626 MolWt = result.MolWt; |
621 var MolWt = result.MolWt; |
627 AcidSG = result.AcidSG; |
622 var AcidSG = result.AcidSG; |
628 AcidPrc = result.AcidPrc; |
623 var AcidPrc = result.AcidPrc; |
629 |
624 |
630 if (dataRecord.calc_acid) { |
625 if (dataRecord.calc_acid) { |
631 TpH = parseFloat(dataRecord.mash_ph); |
626 TpH = parseFloat(dataRecord.mash_ph); |
632 protonDeficit = ProtonDeficit(TpH); |
627 protonDeficit = ProtonDeficit(TpH); |
633 console.log("calc_acid tgt: "+TpH+" protonDeficit: "+protonDeficit); |
628 console.log("calc_acid tgt: "+TpH+" protonDeficit: "+protonDeficit); |
650 bicarbonate = bicarbonate - protonDeficit * frac / liters; |
645 bicarbonate = bicarbonate - protonDeficit * frac / liters; |
651 total_alkalinity = bicarbonate * 50 / 61; |
646 total_alkalinity = bicarbonate * 50 / 61; |
652 } else if (protonDeficit < 0) { //Add base |
647 } else if (protonDeficit < 0) { //Add base |
653 $("#wa_acid").val(0); |
648 $("#wa_acid").val(0); |
654 setWaterAgent(last_acid, 0); |
649 setWaterAgent(last_acid, 0); |
655 r1d = Math.pow(10, (TpH - 6.38)); |
650 var r1d = Math.pow(10, (TpH - 6.38)); |
656 r2d = Math.pow(10, (TpH - 10.38)); |
651 var r2d = Math.pow(10, (TpH - 10.38)); |
657 f1d = 1 / (1 + r1d + r1d * r2d); |
652 var f1d = 1 / (1 + r1d + r1d * r2d); |
658 f2d = f1d * r1d; |
653 var f2d = f1d * r1d; |
659 f3d = f2d * r2d; |
654 var f3d = f2d * r2d; |
660 switch (BT) { |
655 switch (BT) { |
661 case 'NaHCO3': base = -protonDeficit / (f1d - f3d); //mmol totaal |
656 case 'NaHCO3': RA = -protonDeficit / (f1d - f3d); //mmol totaal |
662 base = base * MMNaHCO3/1000; //gram |
657 RA = RA * MMNaHCO3/1000; //gram |
663 $("#wa_base").val(Math.round(base * 100) / 100); |
658 $("#wa_base").val(Math.round(RA * 100) / 100); |
664 setWaterAgent(BT, Math.round(base * 100) / 100); |
659 setWaterAgent(BT, Math.round(RA * 100) / 100); |
665 if (liters > 0) { |
660 if (liters > 0) { |
666 // Na |
661 // Na |
667 RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl + |
662 RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl + |
668 parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMNa / MMNaHCO3; |
663 parseFloat($("#wa_base").jqxNumberInput('decimal')) * MMNa / MMNaHCO3; |
669 RA = 1000 * RA / liters; |
664 RA = 1000 * RA / liters; |
674 bicarbonate = wg_bicarbonate + RA; |
669 bicarbonate = wg_bicarbonate + RA; |
675 total_alkalinity = bicarbonate * 50 / 61; |
670 total_alkalinity = bicarbonate * 50 / 61; |
676 RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium); |
671 RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium); |
677 } |
672 } |
678 break; |
673 break; |
679 case 'Na2CO3': base = -protonDeficit / (2 * f1d + f2d); //mmol totaal |
674 case 'Na2CO3': RA = -protonDeficit / (2 * f1d + f2d); //mmol totaal |
680 base = base * MMNa2CO3/1000; //gram |
675 RA = RA * MMNa2CO3/1000; //gram |
681 $("#wa_base").val(Math.round(base * 100) / 100); |
676 $("#wa_base").val(Math.round(RA * 100) / 100); |
682 setWaterAgent(BT, Math.round(base * 100) / 100); |
677 setWaterAgent(BT, Math.round(RA * 100) / 100); |
683 if (liters > 0) { |
678 if (liters > 0) { |
684 RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl + |
679 RA = parseFloat($("#wa_nacl").jqxNumberInput('decimal')) * MMNa / MMNaCl + |
685 parseFloat($("#wa_base").jqxNumberInput('decimal')) * 2 * MMNa / MMNa2CO3; |
680 parseFloat($("#wa_base").jqxNumberInput('decimal')) * 2 * MMNa / MMNa2CO3; |
686 RA = 1000 * RA / liters; |
681 RA = 1000 * RA / liters; |
687 sodium = wg_sodium + RA; |
682 sodium = wg_sodium + RA; |
691 bicarbonate = wg_bicarbonate + RA; |
686 bicarbonate = wg_bicarbonate + RA; |
692 total_alkalinity = bicarbonate * 50 / 61; |
687 total_alkalinity = bicarbonate * 50 / 61; |
693 RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium); |
688 RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium); |
694 } |
689 } |
695 break; |
690 break; |
696 case 'CaCO3': base = -protonDeficit * (f1d - f3d); //mmol totaal |
691 case 'CaCO3': RA = -protonDeficit * (f1d - f3d); //mmol totaal |
697 base = base * MMCaCO3/1000; //gram |
692 RA = RA * MMCaCO3/1000; //gram |
698 //but only 1/3 is effective, so add 3 times as much |
693 //but only 1/3 is effective, so add 3 times as much |
699 base = 3 * base; |
694 RA = 3 * RA; |
700 $("#wa_base").val(Math.round(base * 100) / 100); |
695 $("#wa_base").val(Math.round(RA * 100) / 100); |
701 setWaterAgent(BT, Math.round(base * 100) / 100); |
696 setWaterAgent(BT, Math.round(RA * 100) / 100); |
702 if (liters > 0) { |
697 if (liters > 0) { |
703 //Bicarbonate |
698 //Bicarbonate |
704 RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) / 3 * MMHCO3 / MMCaCO3; |
699 RA = parseFloat($("#wa_base").jqxNumberInput('decimal')) / 3 * MMHCO3 / MMCaCO3; |
705 RA = 1000 * RA / liters; |
700 RA = 1000 * RA / liters; |
706 bicarbonate = wg_bicarbonate + RA; |
701 bicarbonate = wg_bicarbonate + RA; |
712 RA = 1000 * RA / liters; |
707 RA = 1000 * RA / liters; |
713 calcium = wg_calcium + RA; |
708 calcium = wg_calcium + RA; |
714 RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium); |
709 RA = ResidualAlkalinity(wb_total_alkalinity, wb_calcium, wb_magnesium); |
715 } |
710 } |
716 break; |
711 break; |
717 case 'Ca(OH)2': base = -protonDeficit / 19.3; // g |
712 case 'Ca(OH)2': RA = -protonDeficit / 19.3; // g |
718 $("#wa_base").val(Math.round(base * 100) / 100); |
713 $("#wa_base").val(Math.round(RA * 100) / 100); |
719 setWaterAgent(BT, Math.round(base * 100) / 100); |
714 setWaterAgent(BT, Math.round(RA * 100) / 100); |
720 if (liters > 0) { |
715 if (liters > 0) { |
721 // Bicarbonate |
716 // Bicarbonate |
722 RA = -protonDeficit / liters; |
717 RA = -protonDeficit / liters; |
723 total_alkalinity = wg_total_alkalinity + RA; |
718 total_alkalinity = wg_total_alkalinity + RA; |
724 bicarbonate = total_alkalinity * 61 / 50; |
719 bicarbonate = total_alkalinity * 61 / 50; |
920 } |
915 } |
921 |
916 |
922 console.log("calcSparge() target pH: "+TargetpH+" Source: "+Source_pH+" alkalinity: "+Source_alkalinity); |
917 console.log("calcSparge() target pH: "+TargetpH+" Source: "+Source_pH+" alkalinity: "+Source_alkalinity); |
923 |
918 |
924 // Step 1: Compute the mole fractions of carbonic (f1o), bicarbonate (f2o) and carbonate(f3o) at the water pH |
919 // Step 1: Compute the mole fractions of carbonic (f1o), bicarbonate (f2o) and carbonate(f3o) at the water pH |
925 r1 = Math.pow(10, Source_pH - 6.38); |
920 var r1 = Math.pow(10, Source_pH - 6.38); |
926 r2 = Math.pow(10, Source_pH - 10.33); |
921 var r2 = Math.pow(10, Source_pH - 10.33); |
927 d = 1 + r1 + r1*r2; |
922 var d = 1 + r1 + r1*r2; |
928 f1 = 1/d; |
923 var f1 = 1/d; |
929 f2 = r1/d; |
924 var f2 = r1/d; |
930 f3 = r1 * r2 / d; |
925 var f3 = r1 * r2 / d; |
931 |
926 |
932 //Step 2. Compute the mole fractions at pH = 4.3 (the pH which defines alkalinity) |
927 //Step 2. Compute the mole fractions at pH = 4.3 (the pH which defines alkalinity) |
933 r143 = Math.pow(10, 4.3 - 6.38); |
928 var r143 = Math.pow(10, 4.3 - 6.38); |
934 r243 = Math.pow(10, 4.3 - 10.33); |
929 var r243 = Math.pow(10, 4.3 - 10.33); |
935 d43 = 1 + r143 + r143*r243; |
930 var d43 = 1 + r143 + r143*r243; |
936 f143 = 1/d43; |
931 var f143 = 1/d43; |
937 f243 = r143 / d43; |
932 var f243 = r143 / d43; |
938 f343 = r143 * r243 / d43; |
933 var f343 = r143 * r243 / d43; |
939 |
934 |
940 //Step 3. Convert the sample alkalinity to milliequivalents/L |
935 //Step 3. Convert the sample alkalinity to milliequivalents/L |
941 alkalinity = Source_alkalinity / 50; |
936 var alkalinity = Source_alkalinity / 50; |
942 //Step 4. Solve |
937 //Step 4. Solve |
943 alkalinity = alkalinity / ((f143-f1)+(f3-f343)); |
938 alkalinity = alkalinity / ((f143-f1)+(f3-f343)); |
944 |
939 |
945 //Step 5. Compute mole fractions at desired pH |
940 //Step 5. Compute mole fractions at desired pH |
946 r1g = Math.pow(10, TargetpH - 6.38); |
941 var r1g = Math.pow(10, TargetpH - 6.38); |
947 r2g = Math.pow(10, TargetpH - 10.33); |
942 var r2g = Math.pow(10, TargetpH - 10.33); |
948 dg = 1 + r1g + r1g*r2g; |
943 var dg = 1 + r1g + r1g*r2g; |
949 f1g = 1/dg; |
944 var f1g = 1/dg; |
950 f2g = r1g / dg; |
945 var f2g = r1g / dg; |
951 f3g = r1g * r2g / dg; |
946 var f3g = r1g * r2g / dg; |
952 |
947 |
953 //Step 6. Use these to compute the milliequivalents acid required per liter (mEq/L) |
948 //Step 6. Use these to compute the milliequivalents acid required per liter (mEq/L) |
954 Acid = alkalinity * ((f1g-f1)+(f3-f3g)) + Math.pow(10, -TargetpH) - Math.pow(10, -Source_pH); //mEq/l |
949 var Acid = alkalinity * ((f1g-f1)+(f3-f3g)) + Math.pow(10, -TargetpH) - Math.pow(10, -Source_pH); //mEq/l |
955 |
950 |
956 if ($("#sparge_acid_type").val() == "") { |
951 if ($("#sparge_acid_type").val() == "") { |
957 $("#sparge_acid_type").val('Melkzuur'); |
952 $("#sparge_acid_type").val('Melkzuur'); |
958 dataRecord.sparge_acid_type = 'Melkzuur'; |
953 dataRecord.sparge_acid_type = 'Melkzuur'; |
959 } |
954 } |
960 AT = dataRecord.sparge_acid_type; |
955 var AT = dataRecord.sparge_acid_type; |
961 var result = GetAcidSpecs(AT); |
956 var result = GetAcidSpecs(AT); |
962 pK1 = result.pK1; |
957 var pK1 = result.pK1; |
963 pK2 = result.pK2; |
958 var pK2 = result.pK2; |
964 pK3 = result.pK3; |
959 var pK3 = result.pK3; |
965 MolWt = result.MolWt; |
960 var MolWt = result.MolWt; |
966 AcidSG = result.AcidSG; |
961 var AcidSG = result.AcidSG; |
967 AcidPrc = result.AcidPrc; |
962 var AcidPrc = result.AcidPrc; |
968 fract = CalcFrac(TargetpH, pK1, pK2, pK3); |
963 var fract = CalcFrac(TargetpH, pK1, pK2, pK3); |
969 |
964 |
970 //Step 9. Now divide the mEq required by the "fraction". This is the required number of moles of acid. |
965 //Step 9. Now divide the mEq required by the "fraction". This is the required number of moles of acid. |
971 Acid /= fract; |
966 Acid /= fract; |
972 |
967 |
973 //Step 10. Multiply by molecular weight of the acid |
968 //Step 10. Multiply by molecular weight of the acid |
974 Acid *= MolWt; //mg |
969 Acid *= MolWt; //mg |
975 |
970 |
976 Acid = Acid / AcidSG; //ml ; 88% lactic solution |
971 Acid = Acid / AcidSG; //ml ; 88% lactic solution |
977 f1 = dataRecord.sparge_acid_perc; |
972 var f1 = dataRecord.sparge_acid_perc; |
978 if (f1 <= 0.1) |
973 if (f1 <= 0.1) |
979 f1 = AcidPrc; |
974 f1 = AcidPrc; |
980 Acid = Acid * AcidPrc / (f1 / 100); |
975 Acid = Acid * AcidPrc / (f1 / 100); |
981 |
976 |
982 Acid *= dataRecord.sparge_volume; //ml lactic acid total |
977 Acid *= dataRecord.sparge_volume; //ml lactic acid total |