From 601a1e2c5f7451f7982e889d3876542f2ee29fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Miclu=C8=9Ba-C=C3=A2mpeanu?= Date: Thu, 8 Jan 2026 20:31:12 +0200 Subject: [PATCH] Fix overdetermined initialization in Element1D and ConvectiveElement1D In MTK v11, the syntax `dT(t) = dT` with a constant value creates an initial_condition, which adds an initialization equation. For algebraic variables like `dT` and `Q_flow` that are constrained by equations (e.g., `dT ~ port_a.T - port_b.T`), this creates an overdetermined initialization system. The fix changes from initial conditions to guesses: - Old: `dT(t) = dT, [guess = 0.0]` (dT arg as initial condition) - New: `dT(t), [guess = dT_guess]` (dT_guess arg as guess only) This follows the MTK v11 semantics where algebraic/observed variables should only have guesses, not initial conditions. Co-Authored-By: Claude Opus 4.5 --- src/Thermal/utils.jl | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Thermal/utils.jl b/src/Thermal/utils.jl index 6489775a..3aac54ef 100644 --- a/src/Thermal/utils.jl +++ b/src/Thermal/utils.jl @@ -24,7 +24,7 @@ Port for a thermal system. """ HeatPort """ - Element1D(; name, dT = 0.0, Q_flow = 0.0) + Element1D(; name, dT_guess = 0.0, Q_flow_guess = 0.0) This partial model contains the basic connectors and variables to allow heat transfer models to be created that do not store energy. This model defines and includes equations for the temperature drop across the element, `dT`, and the heat @@ -32,15 +32,15 @@ flow rate through the element from `port_a` to `port_b`, `Q_flow`. # States: - - `dT`: [`K`] Temperature difference across the component a.T - b.T. It accepts an initial value, which defaults to 0.0. - - `Q_flow`: [`W`] Heat flow rate from port a -> port b. It accepts an initial value, which defaults to 0.0. + - `dT`: [`K`] Temperature difference across the component a.T - b.T (algebraically constrained). + - `Q_flow`: [`W`] Heat flow rate from port a -> port b (algebraically constrained). # Connectors: `port_a` `port_b` """ -@component function Element1D(; dT = 0.0, Q_flow = 0.0, name) +@component function Element1D(; name, dT_guess = 0.0, Q_flow_guess = 0.0) pars = @parameters begin end @@ -50,8 +50,8 @@ flow rate through the element from `port_a` to `port_b`, `Q_flow`. end vars = @variables begin - dT(t) = dT, [guess = 0.0] - Q_flow(t) = Q_flow, [guess = 0.0] + dT(t), [guess = dT_guess] + Q_flow(t), [guess = Q_flow_guess] end equations = Equation[ @@ -64,7 +64,7 @@ flow rate through the element from `port_a` to `port_b`, `Q_flow`. end """ - ConvectiveElement1D(; name, dT = 0.0, Q_flow = 0.0) + ConvectiveElement1D(; name, dT_guess = 0.0, Q_flow_guess = 0.0) This partial model contains the basic connectors and variables to allow heat transfer models to be created that do not store energy. This model defines and @@ -73,15 +73,15 @@ flow rate through the element from `solid` to `fluid`, `Q_flow`. # States: - - `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T`. It accepts an initial value, which defaults to 0.0. - - `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid`. It accepts an initial value, which defaults to 0.0. + - `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T` (algebraically constrained). + - `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid` (algebraically constrained). # Connectors: `solid` `fluid` """ -@component function ConvectiveElement1D(; dT = 0.0, Q_flow = 0.0, name) +@component function ConvectiveElement1D(; name, dT_guess = 0.0, Q_flow_guess = 0.0) pars = @parameters begin end @@ -91,8 +91,8 @@ flow rate through the element from `solid` to `fluid`, `Q_flow`. end vars = @variables begin - dT(t) = dT, [guess = 0.0] - Q_flow(t) = Q_flow, [guess = 0.0] + dT(t), [guess = dT_guess] + Q_flow(t), [guess = Q_flow_guess] end equations = Equation[