Make grain_mass/water_mass per-step and re-derive plant params on change

grain_mass and water_mass now live on each step (defaulted from
default.step) instead of being fixed for the whole brew, since both
change over a mash (malt going in, water boiling off).
Sud.derive_plant_params() takes them as arguments so it can be
recomputed per step; the demo re-applies the resulting M/C to both the
real plant and the controller's Smith-predictor model on every step
change via the new Pot.set_thermal_params()/
TempController.set_model_params().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CgR9tPaSzFkAwRAUyeaaCD
This commit is contained in:
2026-06-20 07:45:42 +02:00
co-authored by Claude Sonnet 4.6
parent ca0a014ffb
commit 241a796ffa
6 changed files with 41 additions and 16 deletions
+4
View File
@@ -24,6 +24,10 @@ class TempController(TempControllerBase):
self.model.set_power(power)
self.model_delay.set_power(power)
def set_model_params(self, M, C):
self.model.set_thermal_params(M, C)
self.model_delay.set_thermal_params(M, C)
def on_state_entered(self, state):
if state == States.HEAT:
self.model.initial(self.theta_ist)
+4
View File
@@ -56,6 +56,10 @@ class Pot(APlant):
def set_ambient_temperature(self, theta_amb):
self.theta_amb = theta_amb
def set_thermal_params(self, M, C):
self.M = M
self.C = C
def set_power(self, power):
self.p_in = power
+10 -9
View File
@@ -37,7 +37,7 @@ def _build_step(number, defaults, raw_step):
ramp or a hold depending on which of those keys it specifies; the other
is left out rather than synthesized from defaults."""
step = {'number': number}
for key in ('descr', 'user_message', 'user_wait_for_continue'):
for key in ('descr', 'user_message', 'user_wait_for_continue', 'grain_mass', 'water_mass'):
step[key] = raw_step.get(key, defaults.get(key))
for key in ('ramp', 'hold'):
if key in raw_step:
@@ -59,8 +59,6 @@ class Sud(AttributeChange):
self.pot_mass = data.get('pot_mass', 0)
self.pot_material = data.get('pot_material')
self.grain_mass = data.get('grain_mass', 0)
self.water_mass = data.get('water_mass', 0)
self.index = -1
self.hold_remaining = 0.0
@@ -68,13 +66,16 @@ class Sud(AttributeChange):
self.step = None
self.user_message = None
def derive_plant_params(self):
"""Lumped (mass, specific heat) lifted from pot_mass/pot_material/
grain_mass/water_mass, for use as Pot's "M"/"C" params."""
def derive_plant_params(self, grain_mass, water_mass):
"""Lumped (mass, specific heat) lifted from pot_mass/pot_material and
the current step's grain_mass/water_mass, for use as Pot's "M"/"C"
params. grain_mass/water_mass vary per step (e.g. malt going in,
water boiling off), so this is recomputed on every step change
rather than once at startup."""
c_pot = SPECIFIC_HEAT_BY_MATERIAL.get(self.pot_material, SPECIFIC_HEAT_WATER)
mass = self.water_mass + self.grain_mass + self.pot_mass
capacitance = (self.water_mass * SPECIFIC_HEAT_WATER
+ self.grain_mass * SPECIFIC_HEAT_GRAIN
mass = water_mass + grain_mass + self.pot_mass
capacitance = (water_mass * SPECIFIC_HEAT_WATER
+ grain_mass * SPECIFIC_HEAT_GRAIN
+ self.pot_mass * c_pot)
return {