www/includes/formulas.php

changeset 90
d4246abee34e
parent 89
082c23b26055
child 91
44981507b781
--- a/www/includes/formulas.php	Mon Nov 12 16:34:43 2018 +0100
+++ b/www/includes/formulas.php	Mon Nov 12 22:47:49 2018 +0100
@@ -196,6 +196,69 @@
 
 
 
+function calc_IBU($useat, $form, $sg, $volume, $mass, $boiltime, $alpha, $method) {
+
+	$fmoment  = 1.0;
+	if (($useat == "Dry Hop") || ($useat == "Dry hop") || ($useat == "Whirlpool") || ($useat == "Aroma")) {
+		$fmoment = 0.0;
+	} else if ($useat == "Mash") {
+		$fmoment += /* Settings.MashHopFactor.Value = -30% */ -30 / 100;         // Brouwhulp
+	} else if (($useat == "First Wort") || ($useat == "First wort")) {
+		$fmoment += /* Settings.FWHFactor.Value = 10% */ 10 / 100;         // Brouwhulp, Louis, Ozzie
+	}
+
+	$pfactor  = 1.0;
+	if ($form == "Pellet") {
+		$pfactor += /* Settings.PelletFactor.Value = 10% */ 10 / 100;
+	}
+	if ($form == "Plug") {
+		$pfactor += /* Settings.PlugFactor.Value = 2% */ 2 / 100;
+	}
+
+	$ibu = 0;
+	if (($method == "Tinseth") || ($method == "Garetz")) {	// For Garetz, we need the $ibu
+		$AddedAlphaAcids = (($alpha / 100) * $mass * 1000) / $volume;
+		$Bigness_factor = 1.65 * pow( 0.000125, $sg - 1);
+		$BoilTime_factor = ((1 - exp(-0.04 * $boiltime)) / 4.15);
+		$utiisation = $Bigness_factor * $BoilTime_factor;
+		$ibu = (round($utiisation * $AddedAlphaAcids * $fmoment * $pfactor * 10) / 10.0);
+	}
+	if ($method == "Daniels") {
+
+		if ($form == "Leaf")
+			$boilfactor = -(0.0041*$boiltime*$boiltime)+(0.6162*$boiltime)+1.5779;
+		else
+			$boilfactor = -(0.0051*$boiltime*$boiltime)+(0.7835*$boiltime)+1.9348;
+		if ($sg < 1.050)
+			$sgfactor = 0;
+		else
+			$sgfactor = (($sg * 1000) - 1050) / 200;
+		$ibu = $fmoment * (($mass * $alpha * $boilfactor * 0.1) / ($volume * (1 + $sgfactor)));
+	}
+	if ($method == "Rager") {
+		$boilfactor = $fmoment * 18.11 + 13.86 * tanh(($boiltime * 31.32) / 18.27);
+		if ($sg < 1.050)
+			$sgfactor = 0;
+		else
+			$sgfactor = (($sg * 1000) - 1050) / 200;
+		$ibu = ($mass * $alpha * $boilfactor * 0.1) / ($volume * (1 + $sgfactor));
+	}
+	if ($method == "Garetz") {
+		/* Something is wrong, late hops and dryhops give negative results. */
+		$boilfactor = $fmoment * 6.03253 + 16.5289 * tanh(($boiltime - 19.17323) / 26.8013);
+		$cfactor = $volume / (1.1 * $volume);	// ConcentratieFactor = (Volume na koelen) / (Volume bij Koken)
+		$kookdichtheid = ($cfactor * (($sg * 1000) - 1000) / 1000) + 1;
+		$sgfactor = ($kookdichtheid - 1.05) / 0.2 + 1;
+		$hopratefactor = (($cfactor * $ibu) / 260) + 1;	// $ibu is Tinseth bitterness. Weird.
+		$tempfactor = (32.8/550)*0.02+1;
+		$ibu = ($boilfactor * $alpha * $mass * 0.1) / ($volume * $sgfactor * $hopratefactor * $tempfactor);
+	}
+	/* TODO: Noonan and Mosher */
+
+	return $ibu;
+}
+
+
 /*
 
 Brouwhulp data.pas

mercurial