# HG changeset patch # User Michiel Broek # Date 1408914092 -7200 # Node ID 63a003914b72cbe1f62254d861cfbeaa1b074c85 # Parent 91c358556ecf87a978ee37dde8e035f5cb2dd0dc More math for the simulator. Web interface changes for heater in graph. diff -r 91c358556ecf -r 63a003914b72 thermferm/simulator.c --- a/thermferm/simulator.c Sun Aug 24 14:41:31 2014 +0200 +++ b/thermferm/simulator.c Sun Aug 24 23:01:32 2014 +0200 @@ -40,8 +40,8 @@ simulator_list *simulator; time_t now, last = (time_t)0; int seconds = 0; - double k_room_air, sqm_room_air, thick_room_air, heat_transfer; - double t_change, vhc_air = 1.21, vhc_water = 4179.6; + double k_room_air, k_beer_air, sqm_room_air, sqm_beer_air, thick_room_air, thick_beer_air, air_heat_transfer, beer_heat_transfer; + double air_change, beer_change, vhc_air = 0.00121, vhc_water = 4.1796; syslog(LOG_NOTICE, "Thread my_simulator_loop started"); if (debug) @@ -69,16 +69,9 @@ sqm_room_air = (cbrtl(simulator->volume_air) * cbrtl(simulator->volume_air) * 6) / 100; /* square meters all fridge sides */ thick_room_air = 0.04; /* 4 cm walls */ k_room_air = 0.03; /* Polystrene */ - heat_transfer=(k_room_air * sqm_room_air * (simulator->room_temperature - simulator->air_temperature)) / thick_room_air; - if (heat_transfer != 0) -// t_change = heat_transfer * vhc_air * (simulator->volume_air / 1000); - t_change = vhc_air / (heat_transfer * (simulator->volume_air * 1000)); - else - t_change = 0.0; - simulator->air_temperature = simulator->air_temperature + t_change; - if (debug) - fprintf(stdout, "room_air=%f room=%f air=%.15f heat_transfer=%f t_change=%.15f\n", - sqm_room_air, simulator->room_temperature, simulator->air_temperature, heat_transfer, t_change); + air_heat_transfer=(k_room_air * sqm_room_air * (simulator->room_temperature - simulator->air_temperature)) / thick_room_air; + air_change = air_heat_transfer / (vhc_air * ((simulator->volume_air - simulator->volume_beer) * 1000)); + simulator->air_temperature += air_change; /* * If heating, calculate temperature of the heating plate. If heating is off but @@ -97,11 +90,19 @@ * fermentation process. Peak about one day after start and slowly decrease after * that. */ + sqm_beer_air = (cbrtl(simulator->volume_beer) * cbrtl(simulator->volume_beer) * 6) / 100; /* Simple, the beer is in a cubic box */ + thick_beer_air = 0.001; + k_beer_air = 0.5; /* HDPE */ + beer_heat_transfer=(k_beer_air * sqm_beer_air * (simulator->air_temperature - simulator->beer_temperature)) / thick_beer_air; + beer_change = 0; /* * Calculate final temperature of the beer and the air. */ - + if (debug) + fprintf(stdout, "sqm_room_air=%f air=%f air_heat_transfer=%f air_change=%f sqm_beer_air=%f beer=%f beer_heat_transfer=%f\n", + sqm_room_air, simulator->air_temperature, air_heat_transfer, air_change, + sqm_beer_air, simulator->beer_temperature, beer_heat_transfer); } usleep(100000); } diff -r 91c358556ecf -r 63a003914b72 www-thermferm/liveview.php --- a/www-thermferm/liveview.php Sun Aug 24 14:41:31 2014 +0200 +++ b/www-thermferm/liveview.php Sun Aug 24 23:01:32 2014 +0200 @@ -112,7 +112,7 @@ $outstr .= ' { name: \'Air\', type: \'float\' },'.PHP_EOL; $outstr .= ' { name: \'Beer\', type: \'float\' },'.PHP_EOL; $outstr .= ' { name: \'Target\', type: \'float\' },'.PHP_EOL; - $outstr .= ' { name: \'Heater\' },'.PHP_EOL; + $outstr .= ' { name: \'Heater\', type: \'bool\' },'.PHP_EOL; $outstr .= ' { name: \'Cooler\', type: \'int\' },'.PHP_EOL; $outstr .= ' { name: \'Fan\' },'.PHP_EOL; $outstr .= ' { name: \'Door\', type: \'bool\' }'.PHP_EOL; @@ -154,6 +154,7 @@ $outstr .= ' series: ['.PHP_EOL; $outstr .= ' { dataField: \'Air\', displayText: \'Air\' },'.PHP_EOL; $outstr .= ' { dataField: \'Beer\', displayText: \'Beer\' },'.PHP_EOL; + $outstr .= ' { dataField: \'Heater\', displayText: \'Heater\' },'.PHP_EOL; $outstr .= ' { dataField: \'Target\', displayText: \'Target\' }'.PHP_EOL; $outstr .= ' ]'.PHP_EOL; $outstr .= ' }]'.PHP_EOL;