Skip to content

Commit 601a1e2

Browse files
SebastianM-Cclaude
andcommitted
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 <noreply@anthropic.com>
1 parent bd1e2b8 commit 601a1e2

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/Thermal/utils.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ Port for a thermal system.
2424
""" HeatPort
2525

2626
"""
27-
Element1D(; name, dT = 0.0, Q_flow = 0.0)
27+
Element1D(; name, dT_guess = 0.0, Q_flow_guess = 0.0)
2828
2929
This partial model contains the basic connectors and variables to allow heat transfer models to be created that do not
3030
store energy. This model defines and includes equations for the temperature drop across the element, `dT`, and the heat
3131
flow rate through the element from `port_a` to `port_b`, `Q_flow`.
3232
3333
# States:
3434
35-
- `dT`: [`K`] Temperature difference across the component a.T - b.T. It accepts an initial value, which defaults to 0.0.
36-
- `Q_flow`: [`W`] Heat flow rate from port a -> port b. It accepts an initial value, which defaults to 0.0.
35+
- `dT`: [`K`] Temperature difference across the component a.T - b.T (algebraically constrained).
36+
- `Q_flow`: [`W`] Heat flow rate from port a -> port b (algebraically constrained).
3737
3838
# Connectors:
3939
4040
`port_a`
4141
`port_b`
4242
"""
43-
@component function Element1D(; dT = 0.0, Q_flow = 0.0, name)
43+
@component function Element1D(; name, dT_guess = 0.0, Q_flow_guess = 0.0)
4444
pars = @parameters begin
4545
end
4646

@@ -50,8 +50,8 @@ flow rate through the element from `port_a` to `port_b`, `Q_flow`.
5050
end
5151

5252
vars = @variables begin
53-
dT(t) = dT, [guess = 0.0]
54-
Q_flow(t) = Q_flow, [guess = 0.0]
53+
dT(t), [guess = dT_guess]
54+
Q_flow(t), [guess = Q_flow_guess]
5555
end
5656

5757
equations = Equation[
@@ -64,7 +64,7 @@ flow rate through the element from `port_a` to `port_b`, `Q_flow`.
6464
end
6565

6666
"""
67-
ConvectiveElement1D(; name, dT = 0.0, Q_flow = 0.0)
67+
ConvectiveElement1D(; name, dT_guess = 0.0, Q_flow_guess = 0.0)
6868
6969
This partial model contains the basic connectors and variables to allow heat
7070
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`.
7373
7474
# States:
7575
76-
- `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T`. It accepts an initial value, which defaults to 0.0.
77-
- `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid`. It accepts an initial value, which defaults to 0.0.
76+
- `dT`: [`K`] Temperature difference across the component `solid.T` - `fluid.T` (algebraically constrained).
77+
- `Q_flow`: [`W`] Heat flow rate from `solid` -> `fluid` (algebraically constrained).
7878
7979
# Connectors:
8080
8181
`solid`
8282
`fluid`
8383
"""
84-
@component function ConvectiveElement1D(; dT = 0.0, Q_flow = 0.0, name)
84+
@component function ConvectiveElement1D(; name, dT_guess = 0.0, Q_flow_guess = 0.0)
8585
pars = @parameters begin
8686
end
8787

@@ -91,8 +91,8 @@ flow rate through the element from `solid` to `fluid`, `Q_flow`.
9191
end
9292

9393
vars = @variables begin
94-
dT(t) = dT, [guess = 0.0]
95-
Q_flow(t) = Q_flow, [guess = 0.0]
94+
dT(t), [guess = dT_guess]
95+
Q_flow(t), [guess = Q_flow_guess]
9696
end
9797

9898
equations = Equation[

0 commit comments

Comments
 (0)