Finally found the right way to calculate the bottle pressure in bar after refermentation.

Wed, 16 Nov 2022 17:26:27 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 16 Nov 2022 17:26:27 +0100
changeset 439
31419b7cee69
parent 438
e06b04ef1579
child 440
349c0c5bd512

Finally found the right way to calculate the bottle pressure in bar after refermentation.

src/EditProduct.h file | annotate | diff | comparison | revisions
src/EditProductTab11.cpp file | annotate | diff | comparison | revisions
translations/bmsapp_en.ts file | annotate | diff | comparison | revisions
translations/bmsapp_nl.ts file | annotate | diff | comparison | revisions
--- a/src/EditProduct.h	Tue Nov 15 09:42:25 2022 +0100
+++ b/src/EditProduct.h	Wed Nov 16 17:26:27 2022 +0100
@@ -334,7 +334,8 @@
     double get_fg(double gravity);
     double ResCO2(double T);
     double CarbCO2toS(double CO2, double T, double SFactor);
-    double GetPressure(double CO2, double T1, double T2);
+    double GetPressure(double CO2, double T);
+    double GetPressureBar(double gl, double T);
     double CarbCO2ToPressure(double CO2, double T);
     void calcPack();
     void exportBeerXML();
--- a/src/EditProductTab11.cpp	Tue Nov 15 09:42:25 2022 +0100
+++ b/src/EditProductTab11.cpp	Wed Nov 16 17:26:27 2022 +0100
@@ -34,19 +34,37 @@
 }
 
 
-double EditProduct::GetPressure(double CO2, double T1, double T2)
+double EditProduct::GetPressure(double CO2, double T)
 {
-    double V = CO2 - ResCO2(T1);
-    V = CO2; // TODO: temp only total pressure, testing
-    if (V < 0)
+    if (CO2 < 0)
 	return 0;
 
-    double P = -1.09145427669121 + 0.00800006989646477 * T2 + 0.000260276315484684 * T2 * T2 + 0.0215142075945119 * T2 * V +
-		0.674996600795854 * V + -0.00471757220150754 * V * V;
+    double P = -1.09145427669121 + 0.00800006989646477 * T + 0.000260276315484684 * T * T + 0.0215142075945119 * T * CO2 +
+		0.674996600795854 * CO2 + -0.00471757220150754 * CO2 * CO2;
+
+    P = round((P * 1.01325) * 100.0) / 100.0;  // atm to bar
+    qDebug() << "  GetPressure(" << CO2 << "," << T << ") CO2:" << CO2 << "Bar:" << P;
+    return P;
+}
+
+
+/*
+ * Calculate pressure in the bottles after refermentation.
+ * @param gl	Sugar in gram/liter
+ * @param T	Temperature in celsius
+ * @return	Pressure in Bar.
+ */
+double EditProduct::GetPressureBar(double gl, double T)
+{
+    if (gl <= 0)
+	return 0;
+
+    double P = ((gl / 10.0) / exp(-10.73797 + (2617.25 / (T + 273.15)))) - 1.013;
     if (P < 0)
 	P = 0;
-    P = round((P * 1.01325) * 100.0) / 100.0;	// atm to bar
-    qDebug() << "  GetPressure(" << CO2 << "," << T1 << "," << T2 << ") V:" << V << "Bar:" << P << "ignored ResCO2:" << ResCO2(T1);
+
+    P = round(P * 100.0) / 100.0;
+    qDebug() << "  GetPressureBar(" << gl << "," << T << ") P:" << P;
     return P;
 }
 
@@ -143,10 +161,11 @@
 		refreshFermentables();
 	    } else {
 		product->bottle_priming_amount = CarbCO2toS(product->bottle_carbonation, TSec, SFactor);
+//		qDebug() << "  priming CarbCO2toS(" << product->bottle_carbonation << TSec << SFactor << ") =" << product->bottle_priming_amount;
 		ui->bottle_sug_amountShow->setValue(product->bottle_priming_amount);
 		double total = round(product->bottle_priming_amount * product->bottle_amount * 100.0) / 100000.0;
-		qDebug() << "  total" << total << product->fermentables.at(i).amount;
 		if (total != product->fermentables.at(i).amount) {
+		    qDebug() << "  total" << total << product->fermentables.at(i).amount;
 		    qDebug() << "  update priming sugar" << total;
 		    product->fermentables[i].amount = total;
 		    refreshFermentables();
@@ -159,7 +178,7 @@
 		talc = product->bottle_amount - pvol;
   		tvol = pvol + product->bottle_priming_water;
 		product->bottle_abv = talc / (tvol + talc) * 100;
-		product->bottle_bar = GetPressure(product->bottle_carbonation, TSec, product->bottle_carbonation_temp);
+		product->bottle_bar = GetPressureBar(product->bottle_priming_amount, product->bottle_carbonation_temp);
 		ui->bottle_abvShow->setValue(product->bottle_abv);
 		ui->bottle_barShow->setValue(product->bottle_bar);
 	    }
@@ -241,7 +260,7 @@
                     talc = product->keg_amount - pvol;
                     tvol = pvol + product->keg_priming_water;
 		    product->keg_abv = talc / (tvol + talc) * 100;
-		    product->keg_bar = GetPressure(product->keg_carbonation, TSec, product->keg_carbonation_temp);
+		    product->keg_bar = GetPressure(product->keg_carbonation, product->keg_carbonation_temp);
                     ui->keg_abvShow->setValue(product->keg_abv);
                     ui->keg_barShow->setValue(product->keg_bar);
             	}
--- a/translations/bmsapp_en.ts	Tue Nov 15 09:42:25 2022 +0100
+++ b/translations/bmsapp_en.ts	Wed Nov 16 17:26:27 2022 +0100
@@ -4774,12 +4774,12 @@
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/EditProductTab11.cpp" line="298"/>
+        <location filename="../src/EditProductTab11.cpp" line="317"/>
         <source>Confirm package</source>
         <translation type="unfinished"></translation>
     </message>
     <message>
-        <location filename="../src/EditProductTab11.cpp" line="298"/>
+        <location filename="../src/EditProductTab11.cpp" line="317"/>
         <source>Confirm that the beer is packaged and all data is correct</source>
         <translation type="unfinished"></translation>
     </message>
--- a/translations/bmsapp_nl.ts	Tue Nov 15 09:42:25 2022 +0100
+++ b/translations/bmsapp_nl.ts	Wed Nov 16 17:26:27 2022 +0100
@@ -5440,12 +5440,12 @@
         <translation type="vanished">Batterij volt</translation>
     </message>
     <message>
-        <location filename="../src/EditProductTab11.cpp" line="298"/>
+        <location filename="../src/EditProductTab11.cpp" line="317"/>
         <source>Confirm package</source>
         <translation>Bevestig verpakken</translation>
     </message>
     <message>
-        <location filename="../src/EditProductTab11.cpp" line="298"/>
+        <location filename="../src/EditProductTab11.cpp" line="317"/>
         <source>Confirm that the beer is packaged and all data is correct</source>
         <translation>Bevestig dat het bier verpakt is en de gegevens kloppen</translation>
     </message>

mercurial