38 #endif |
38 #endif |
39 { |
39 { |
40 simulator_list *simulator; |
40 simulator_list *simulator; |
41 time_t now, last = (time_t)0; |
41 time_t now, last = (time_t)0; |
42 int seconds = 0; |
42 int seconds = 0; |
43 double k_room_air, sqm_room_air, thick_room_air, heat_transfer; |
43 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; |
44 double t_change, vhc_air = 1.21, vhc_water = 4179.6; |
44 double air_change, beer_change, vhc_air = 0.00121, vhc_water = 4.1796; |
45 |
45 |
46 syslog(LOG_NOTICE, "Thread my_simulator_loop started"); |
46 syslog(LOG_NOTICE, "Thread my_simulator_loop started"); |
47 if (debug) |
47 if (debug) |
48 fprintf(stdout, "Thread my_simulator_loop started\n"); |
48 fprintf(stdout, "Thread my_simulator_loop started\n"); |
49 |
49 |
67 * the room temperature. |
67 * the room temperature. |
68 */ |
68 */ |
69 sqm_room_air = (cbrtl(simulator->volume_air) * cbrtl(simulator->volume_air) * 6) / 100; /* square meters all fridge sides */ |
69 sqm_room_air = (cbrtl(simulator->volume_air) * cbrtl(simulator->volume_air) * 6) / 100; /* square meters all fridge sides */ |
70 thick_room_air = 0.04; /* 4 cm walls */ |
70 thick_room_air = 0.04; /* 4 cm walls */ |
71 k_room_air = 0.03; /* Polystrene */ |
71 k_room_air = 0.03; /* Polystrene */ |
72 heat_transfer=(k_room_air * sqm_room_air * (simulator->room_temperature - simulator->air_temperature)) / thick_room_air; |
72 air_heat_transfer=(k_room_air * sqm_room_air * (simulator->room_temperature - simulator->air_temperature)) / thick_room_air; |
73 if (heat_transfer != 0) |
73 air_change = air_heat_transfer / (vhc_air * ((simulator->volume_air - simulator->volume_beer) * 1000)); |
74 // t_change = heat_transfer * vhc_air * (simulator->volume_air / 1000); |
74 simulator->air_temperature += air_change; |
75 t_change = vhc_air / (heat_transfer * (simulator->volume_air * 1000)); |
|
76 else |
|
77 t_change = 0.0; |
|
78 simulator->air_temperature = simulator->air_temperature + t_change; |
|
79 if (debug) |
|
80 fprintf(stdout, "room_air=%f room=%f air=%.15f heat_transfer=%f t_change=%.15f\n", |
|
81 sqm_room_air, simulator->room_temperature, simulator->air_temperature, heat_transfer, t_change); |
|
82 |
75 |
83 /* |
76 /* |
84 * If heating, calculate temperature of the heating plate. If heating is off but |
77 * If heating, calculate temperature of the heating plate. If heating is off but |
85 * the plate is warmer then the air, calculate the cooling down temperature. |
78 * the plate is warmer then the air, calculate the cooling down temperature. |
86 * Finally, calculate the new air and plate temperature. |
79 * Finally, calculate the new air and plate temperature. |
95 /* |
88 /* |
96 * Calculate the extra beer temperatur rise to simulate the heat produced by the |
89 * Calculate the extra beer temperatur rise to simulate the heat produced by the |
97 * fermentation process. Peak about one day after start and slowly decrease after |
90 * fermentation process. Peak about one day after start and slowly decrease after |
98 * that. |
91 * that. |
99 */ |
92 */ |
|
93 sqm_beer_air = (cbrtl(simulator->volume_beer) * cbrtl(simulator->volume_beer) * 6) / 100; /* Simple, the beer is in a cubic box */ |
|
94 thick_beer_air = 0.001; |
|
95 k_beer_air = 0.5; /* HDPE */ |
|
96 beer_heat_transfer=(k_beer_air * sqm_beer_air * (simulator->air_temperature - simulator->beer_temperature)) / thick_beer_air; |
|
97 beer_change = 0; |
100 |
98 |
101 /* |
99 /* |
102 * Calculate final temperature of the beer and the air. |
100 * Calculate final temperature of the beer and the air. |
103 */ |
101 */ |
104 |
102 if (debug) |
|
103 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", |
|
104 sqm_room_air, simulator->air_temperature, air_heat_transfer, air_change, |
|
105 sqm_beer_air, simulator->beer_temperature, beer_heat_transfer); |
105 } |
106 } |
106 usleep(100000); |
107 usleep(100000); |
107 } |
108 } |
108 usleep(50000); |
109 usleep(50000); |
109 } |
110 } |