thermferm/simulator.c

changeset 365
df0261bb3feb
parent 363
468ec0d96cce
child 366
7b698d012a0c
--- a/thermferm/simulator.c	Sun May 17 23:23:25 2015 +0200
+++ b/thermferm/simulator.c	Mon May 18 21:19:06 2015 +0200
@@ -43,7 +43,7 @@
     time_t		now, last = (time_t)0;
     int			seconds = 0;
     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;
+    double		air_change, /* beer_change, */ vhc_air = 0.00121 /*, vhc_water = 4.1796 */;
 
     syslog(LOG_NOTICE, "Thread my_simulator_loop started");
     if (debug)
@@ -79,7 +79,7 @@
 		thick_room_air = 0.04;	/* 4 cm walls	*/
 		k_room_air = 0.03;	/* Polystrene	*/
 		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));
+		air_change = (air_heat_transfer / (vhc_air * ((simulator->volume_air - simulator->volume_beer) * 1000))) / 60.0;
 		simulator->air_temperature += air_change;
 
 	    	/*
@@ -88,11 +88,16 @@
 	    	 * Finally, calculate the new air and plate temperature.
 	    	 */
 		if (SIMheating) {
-		    if (simulator->s_heat_temp < simulator->heater_temp)
+		    if (simulator->s_heat_temp < simulator->heater_temp) {
 			simulator->s_heat_temp += 0.05;
+			if (simulator->s_heat_temp > simulator->air_temperature)
+			    simulator->air_temperature += ((simulator->s_heat_temp - simulator->air_temperature) / 100.0);
+		    }
 		} else {
-		    if (simulator->s_heat_temp > simulator->room_temperature)
-			simulator->s_heat_temp -= 0.05;
+		    /*
+		     * Follow the air temperature
+		     */
+		    simulator->s_heat_temp -= (simulator->s_heat_temp - simulator->air_temperature) / 25.0;
 		}
 
 	    	/* 
@@ -101,16 +106,15 @@
 	    	 * Finsally, calculate the new air and plate temperature.
 	    	 */
 		if (SIMcooling) {
-		    if (simulator->s_cool_temp > simulator->cooler_temp)
+		    if (simulator->s_cool_temp > simulator->cooler_temp) {
 			simulator->s_cool_temp -= 0.05;
+			if (simulator->s_cool_temp < simulator->air_temperature)
+			    simulator->air_temperature -= ((simulator->air_temperature - simulator->s_cool_temp) / 100.0);
+		    }
 		} else {
-		    if (simulator->s_cool_temp < simulator->room_temperature)
-			simulator->s_cool_temp += 0.05;
+		    simulator->s_cool_temp -= (simulator->s_cool_temp - simulator->air_temperature) / 25.0;
 		}
 
-		simulator->air_temperature += ((simulator->s_heat_temp - simulator->air_temperature) / 50.0);
-		simulator->air_temperature -= ((simulator->air_temperature - simulator->s_cool_temp) / 50.0);
-
 	    	/*
 	    	 * Calculate the extra beer temperatur rise to simulate the heat produced by the
 	    	 * fermentation process. Peak about one day after start and slowly decrease after
@@ -120,13 +124,14 @@
 		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;
+		/* beer_change = 0; */
 
 	    	/*
 	    	 * Calculate final temperature of the beer and the air.
 	    	 */
 		// Cheap trick, just follow slowly the air temp.
 		simulator->beer_temperature += ((simulator->air_temperature - simulator->beer_temperature) / 200.0);
+		simulator->air_temperature += ((simulator->beer_temperature - simulator->air_temperature) / 1000.0);
 
 		syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature,
 				simulator->s_heat_temp, simulator->s_cool_temp);

mercurial