47 |
47 |
48 syslog(LOG_NOTICE, "Thread my_simulator_loop started"); |
48 syslog(LOG_NOTICE, "Thread my_simulator_loop started"); |
49 if (debug) |
49 if (debug) |
50 fprintf(stdout, "Thread my_simulator_loop started\n"); |
50 fprintf(stdout, "Thread my_simulator_loop started\n"); |
51 |
51 |
|
52 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
|
53 /* |
|
54 * Heater and cooler have the air temperature |
|
55 */ |
|
56 simulator->s_heat_temp = simulator->s_cool_temp = simulator->room_temperature; |
|
57 } |
|
58 |
52 for (;;) { |
59 for (;;) { |
53 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
60 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
54 if (my_shutdown) |
61 if (my_shutdown) |
55 break; |
62 break; |
56 |
63 |
79 * If heating, calculate temperature of the heating plate. If heating is off but |
86 * If heating, calculate temperature of the heating plate. If heating is off but |
80 * the plate is warmer then the air, calculate the cooling down temperature. |
87 * the plate is warmer then the air, calculate the cooling down temperature. |
81 * Finally, calculate the new air and plate temperature. |
88 * Finally, calculate the new air and plate temperature. |
82 */ |
89 */ |
83 if (SIMheating) { |
90 if (SIMheating) { |
84 simulator->air_temperature += 0.01; |
91 if (simulator->s_heat_temp < simulator->heater_temp) |
|
92 simulator->s_heat_temp += 0.05; |
|
93 } else { |
|
94 if (simulator->s_heat_temp > simulator->room_temperature) |
|
95 simulator->s_heat_temp -= 0.05; |
85 } |
96 } |
86 |
97 |
87 /* |
98 /* |
88 * If cooling, calculate temperature of the cooling plate. If cooling is off but |
99 * If cooling, calculate temperature of the cooling plate. If cooling is off but |
89 * the plate is colder then the air, calculate the warming up temperature. |
100 * the plate is colder then the air, calculate the warming up temperature. |
90 * Finsally, calculate the new air and plate temperature. |
101 * Finsally, calculate the new air and plate temperature. |
91 */ |
102 */ |
92 if (SIMcooling) { |
103 if (SIMcooling) { |
93 simulator->air_temperature -= 0.01; |
104 if (simulator->s_cool_temp > simulator->cooler_temp) |
|
105 simulator->s_cool_temp -= 0.05; |
|
106 } else { |
|
107 if (simulator->s_cool_temp < simulator->room_temperature) |
|
108 simulator->s_cool_temp += 0.05; |
94 } |
109 } |
|
110 |
|
111 simulator->air_temperature += ((simulator->s_heat_temp - simulator->air_temperature) / 50.0); |
|
112 simulator->air_temperature -= ((simulator->air_temperature - simulator->s_cool_temp) / 50.0); |
95 |
113 |
96 /* |
114 /* |
97 * Calculate the extra beer temperatur rise to simulate the heat produced by the |
115 * Calculate the extra beer temperatur rise to simulate the heat produced by the |
98 * fermentation process. Peak about one day after start and slowly decrease after |
116 * fermentation process. Peak about one day after start and slowly decrease after |
99 * that. |
117 * that. |
105 beer_change = 0; |
123 beer_change = 0; |
106 |
124 |
107 /* |
125 /* |
108 * Calculate final temperature of the beer and the air. |
126 * Calculate final temperature of the beer and the air. |
109 */ |
127 */ |
|
128 // Cheap trick, just follow slowly the air temp. |
|
129 simulator->beer_temperature += ((simulator->air_temperature - simulator->beer_temperature) / 200.0); |
|
130 |
|
131 syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature, |
|
132 simulator->s_heat_temp, simulator->s_cool_temp); |
|
133 |
110 if (debug) |
134 if (debug) |
111 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", |
135 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", |
112 sqm_room_air, simulator->air_temperature, air_heat_transfer, air_change, |
136 sqm_room_air, simulator->air_temperature, air_heat_transfer, air_change, |
113 sqm_beer_air, simulator->beer_temperature, beer_heat_transfer); |
137 sqm_beer_air, simulator->beer_temperature, beer_heat_transfer); |
114 } |
138 } |