thermferm/simulator.c

changeset 265
63a003914b72
parent 264
91c358556ecf
child 362
c92651a54969
--- 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);
 	}

mercurial