diff --git a/src/Thermal/HeatTransfer/sources.jl b/src/Thermal/HeatTransfer/sources.jl index 1ee8d36f7..1057f34d8 100644 --- a/src/Thermal/HeatTransfer/sources.jl +++ b/src/Thermal/HeatTransfer/sources.jl @@ -28,7 +28,9 @@ the component FixedHeatFlow is connected, if parameter `Q_flow` is positive. end @equations begin - port.Q_flow ~ -Q_flow * (1 + alpha * (port.T - T_ref)) + port.Q_flow ~ ifelse(alpha == 0.0, + -Q_flow, # Simplified equation when alpha is 0 + -Q_flow * (1 + alpha * (port.T - T_ref))) end end diff --git a/test/Thermal/thermal.jl b/test/Thermal/thermal.jl index 49c5d634c..9513aa260 100644 --- a/test/Thermal/thermal.jl +++ b/test/Thermal/thermal.jl @@ -155,3 +155,30 @@ end zeros(length(sol[collector.port_b.Q_flow])) @test sol[collector.port_b.T] == sol[collector.port_a1.T] == sol[collector.port_a2.T] end + +@testset "FixedHeatFlow with alpha=0.0 test" begin + @mtkmodel TestModel begin + + @components begin + temp = FixedTemperature(T=300) + heatflow = FixedHeatFlow(Q_flow=-1.0) + wall = ThermalResistor(R=1) + end + + @equations begin + connect(temp.port, wall.port_a) + connect(wall.port_b, heatflow.port) + end + + end + + @info "Building a FixedHeatFlow with alpha=0.0" + @mtkbuild test_model = TestModel() + prob = ODEProblem(test_model, Pair[], (0, 10.0)) + sol = solve(prob) + + heat_flow = sol[test_model.heatflow.port.Q_flow] + + @test SciMLBase.successful_retcode(sol) # Ensure the simulation is successful + @test all(isapprox.(heat_flow, 1.0, rtol=1e-6)) # Heat flow value should be equal to the fixed value defined +end \ No newline at end of file