From 4ce3a664d9f77e0eace16314a2c45a950901d96f Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Thu, 13 Aug 2026 12:06:46 +0300 Subject: [PATCH] Add sanity checks to stream construction Introduce a `new` constructor function for the Stream struct to validate initial state and prevent invalid configurations. Closes #25 --- Streams/streams.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Streams/streams.jl diff --git a/Streams/streams.jl b/Streams/streams.jl new file mode 100644 index 0000000..46981c8 --- /dev/null +++ b/Streams/streams.jl @@ -0,0 +1,17 @@ +struct Stream + name::String + Tin::Float64 + Tout::Float64 + Cp::Float64 + type::Symbol + function Stream(name::String, Tin::Float64, Tout::Float64, Cp::Float64, type::Symbol) + @assert Cp > 0 "Heat capacity Cp must be positive." + @assert type in (:hot, :cold) "Stream type must be :hot or :cold." + if type == :hot + @assert Tin > Tout "Hot streams must have Tin > Tout." + else + @assert Tin < Tout "Cold streams must have Tin < Tout." + end + return new(name, Tin, Tout, Cp, type) + end +end