src/Utils.cpp

changeset 339
2f3cfb983fcc
parent 337
8133cdb19aa1
child 340
b9af88bfe972
--- a/src/Utils.cpp	Thu Jul 07 09:54:42 2022 +0200
+++ b/src/Utils.cpp	Thu Jul 07 14:17:53 2022 +0200
@@ -379,48 +379,33 @@
  * Formula is from the 'Mash Made Easy' spreadsheet.
  * https://mashmadeeasy.yolasite.com/
  * https://www.homebrewtalk.com/threads/a-rather-simplified-whirlpool-hop-ibu-computation-method.701093/
+ *
+ * Source of the formula Mark G. Malowicki.
  */
 double Utils::IBU_reduction(double Tc)
 {
-    return (2.39 * pow(10, 11) * pow(2.71828182846, - (9773 / (Tc + Kelvin))) ) * 1/1.009231744;
+    /*
+     * Original formula plus a small correction factor.
+     */
+    return (2.39 * pow(10, 11) * exp(-(9773 / (Tc + Kelvin))) ) * 1/1.009231743647;
 }
 
 
-double Utils::boilIBU(int Form, double SG, double Volume, double Amount, double Time, double Alpha, int Method)
+double Utils::TinsethIBU(double SG, double Volume, double Amount, double Time, double Alpha)
 {
-    double	ibu = 0.0, sgfactor, boilfactor;
-
     double alpha = Alpha / 100.0;
     double mass = Amount * 1000.0;
 
-    if (Method == 0) { // Tinseth
-        /* http://realbeer.com/hops/research.html */
-        double AddedAlphaAcids = (alpha * mass * 1000) / Volume;
-        double Bigness_factor = 1.65 * pow(0.000125, SG - 1);
-        double BoilTime_factor = ((1 - exp(-0.04 * Time)) / 4.15);
-        ibu = Bigness_factor * BoilTime_factor * AddedAlphaAcids;
-    }
-    if (Method == 2) { // Daniels
-        if (Form == 2) // Leaf
-            boilfactor = -(0.0041 * Time * Time) + (0.6162 * Time) + 1.5779;
-        else
-            boilfactor = -(0.0051 * Time * Time) + (0.7835 * Time) + 1.9348;
-        if (SG < 1.050)
-            sgfactor = 0;
-        else
-            sgfactor = ((SG * 1000) - 1050) / 200;
-        ibu = (mass * (alpha * 100) * boilfactor * 0.1) / (Volume * (1 + sgfactor));
-    }
-    if (Method == 1) { // Rager
-        boilfactor = 18.11 + 13.86 * tanh((Time * 31.32) / 18.27);
-        if (SG < 1.050)
-            sgfactor = 0;
-        else
-            sgfactor = ((SG * 1000) - 1050) / 200;
-        ibu = (mass * (alpha * 100) * boilfactor * 0.1) / (Volume * (1 + sgfactor));
-    }
+    /*
+     * Basic Tinseth formula.
+     * http://realbeer.com/hops/research.html
+     */
+    double AddedAlphaAcids = (alpha * mass * 1000) / Volume;
+    double Bigness_factor = 1.65 * pow(0.000125, SG - 1);
+    double BoilTime_factor = ((1 - exp(-0.04 * Time)) / 4.15);
+    double ibu = Bigness_factor * BoilTime_factor * AddedAlphaAcids;
 
-    //qDebug() << "boilIBU" << Form << SG << Volume << Amount << Time << Alpha << Method << "IBU:" << ibu;
+    qDebug() << "boilIBU" << SG << Volume << Amount << Time << Alpha << "IBU:" << ibu;
     return ibu;
 }
 
@@ -428,6 +413,8 @@
 double Utils::toIBU(int Use, int Form, double SG, double Volume, double Amount, double Boiltime, double Alpha,
 		    int Method, double Whirlpool9, double Whirlpool7, double Whirlpool6, double Fulltime)
 {
+    double loss_boiltemp = 1.0;		/* Loss due to the lower boil temperature at higher altitude.	*/
+
     double ibu = 0.0, whirlibus = 0.0;
     double alpha = Alpha / 100.0;
     double mass = Amount * 1000.0;
@@ -477,7 +464,7 @@
      * IBU's from hops during Mash, FWH and boil.
      */
     if ((Use == HOP_USEAT_MASH) || (Use == HOP_USEAT_FWH) || (Use == HOP_USEAT_BOIL)) {
-	ibu = boilIBU(Form, SG, Volume, Amount, Fulltime, Alpha, Method);
+	ibu = TinsethIBU(SG, Volume, Amount, Fulltime, Alpha);
 	/*
 	 * Corrections for Mash and FWH
 	 */
@@ -502,8 +489,12 @@
 	} else if (Form == HOP_FORMS_EXTRACT) {
 	    // Nothing for now.
 	}
-//	ibu *= IBU_reduction(boilPoint());
-//	qDebug() << "ibu" << ibu << IBU_reduction(boilPoint());
+
+	if (Method > 0) {
+	    loss_boiltemp = IBU_reduction(boilPoint());
+	    ibu *= loss_boiltemp;
+	    qDebug() << "ibu" << ibu << "loss_boiltemp" << loss_boiltemp;
+	}
 
 //    } else if (Use == HOP_USEAT_AROMA) {
 	/*
@@ -515,7 +506,6 @@
 //	qDebug() << "whirlibus" <<  whirlibus << Use;
     }
 
-
     return round((ibu + whirlibus) * 100.0) / 100.0;
 }
 

mercurial