src/Utils.cpp

changeset 453
fc0c10d79539
parent 452
c4c5d02131be
child 454
2dfead81c72f
equal deleted inserted replaced
452:c4c5d02131be 453:fc0c10d79539
280 280
281 return round(sg * 10000) / 10000; 281 return round(sg * 10000) / 10000;
282 } 282 }
283 283
284 284
285 /*
286 * Returns the log base b of y.
287 */
288 double Utils::logbase(double y, int b)
289 {
290 double lg;
291
292 lg = log10(y) / log10(b);
293 return lg;
294 }
295
296
285 double Utils::estimate_fg(double psugar, double pcara, double wgratio, double mashtime, double mashtemp, double svg, double og, bool sta1) 297 double Utils::estimate_fg(double psugar, double pcara, double wgratio, double mashtime, double mashtemp, double svg, double og, bool sta1)
286 { 298 {
287 double BD; 299 double BD;
300 double att_mashtime;
288 double att_mashtemp; 301 double att_mashtemp;
289 302
290 if (psugar > 40) 303 if (psugar > 40)
291 psugar = 0; 304 psugar = 0;
292 if (pcara > 50) 305 if (pcara > 50)
303 mashtemp = 67; 316 mashtemp = 67;
304 mashtime = 75; 317 mashtime = 75;
305 } 318 }
306 if (svg < 30) 319 if (svg < 30)
307 svg = 77; 320 svg = 77;
308 if (mashtime > 240)
309 mashtime = 240;
310 321
311 /* 322 /*
312 * Original from brouwhulp: 323 * Original from brouwhulp:
313 * 0.00825 Attenuation factor yeast (Real to apparant ??) 324 * 0.00825 Attenuation factor yeast (Real to apparant ??)
314 * 0.00817 Attenuation factor water/grain ratio 325 * 0.00817 Attenuation factor water/grain ratio
320 * 0.597 Attenuation factor constant when STA1 gen is true. 331 * 0.597 Attenuation factor constant when STA1 gen is true.
321 */ 332 */
322 double top_mashtemp = 66.11; /* Highest fermentable at 151 degrees fahrenheit */ 333 double top_mashtemp = 66.11; /* Highest fermentable at 151 degrees fahrenheit */
323 /* 334 /*
324 * Derived from Karl Troester's data and Matt Kahn. 335 * Derived from Karl Troester's data and Matt Kahn.
336 * Original was just: -0.00684 * mashtemp
325 */ 337 */
326 if (mashtemp > top_mashtemp) { 338 if (mashtemp > top_mashtemp) {
327 /* Above optimum mash temperature decrease attenuation */ 339 /* Above optimum mash temperature decrease attenuation */
328 att_mashtemp = -0.00684 * mashtemp; 340 att_mashtemp = -0.00684 * mashtemp;
329 } else { 341 } else {
330 /* Below optimum mash temperature decrease slowly attenuation */ 342 /* Below optimum mash temperature decrease slowly attenuation */
331 att_mashtemp = -0.00684 * (top_mashtemp + (top_mashtemp - mashtemp) / 4); 343 att_mashtemp = -0.00684 * (top_mashtemp + (top_mashtemp - mashtemp) / 4);
332 } 344 }
333 345
334 double AttBeer = 0.00825 * svg + 0.00817 * BD + att_mashtemp + 0.00026 * mashtime - 0.00356 * pcara + 0.00553 * psugar; 346 /*
347 * Reference is set at 60 minutes equals old formula
348 * Use log base 5 to create a good realistic response.
349 * With mashtime < 12 minutes, the result will be negative, good.
350 */
351 att_mashtime = logbase(mashtime / 12, 5) * 0.0156;
352 //qDebug() << "estimate_fg temp" << att_mashtemp << "time" << att_mashtime;
353
354 double AttBeer = 0.00825 * svg + 0.00817 * BD + att_mashtemp + att_mashtime - 0.00356 * pcara + 0.00553 * psugar;
335 AttBeer += (sta1) ? 0.597:0.547; 355 AttBeer += (sta1) ? 0.597:0.547;
336 qDebug() << "estimate_fg(" << psugar << pcara << BD << mashtime << mashtemp << svg << og << sta1 << ") AttBeer:" << AttBeer; 356 qDebug() << "estimate_fg(" << psugar << pcara << BD << mashtime << mashtemp << svg << og << sta1 << ") AttBeer:" << AttBeer;
337 return round((1 + (1 - AttBeer) * (og -1)) * 10000) / 10000; 357 return round((1 + (1 - AttBeer) * (og -1)) * 10000) / 10000;
338 } 358 }
339 359

mercurial