Skip to content

Commit

Permalink
replaced Unitful with DynamicQuantities
Browse files Browse the repository at this point in the history
  • Loading branch information
bodokaiser committed Sep 11, 2024
1 parent 406207f commit 0b6594f
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 177 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ jobs:
fail-fast: false
matrix:
version:
- "1.0"
- "1.8"
- "nightly"
- "1.10"
os:
- ubuntu-latest
arch:
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name = "HeatTransferFluids"
uuid = "44505bb3-94ea-493c-a20c-f0ca548ab76b"
authors = ["Bodo Kaiser"]
version = "0.0.1"
version = "0.1.0"

[deps]
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"

[compat]
julia = "1"
Unitful = "1.12"
DynamicQuantities = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
6 changes: 1 addition & 5 deletions src/HeatTransferFluids.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
module HeatTransferFluids

using Unitful

@derived_dimension SpecificHeatCapacity dimension(u"J/(kg*K)")
@derived_dimension ThermalConductivity dimension(u"W/(m*K)")
@derived_dimension VolumeFlow dimension(u"m^3/s")
using DynamicQuantities

include("fluid.jl")
include("structure.jl")
Expand Down
6 changes: 3 additions & 3 deletions src/flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function reynolds_number(f::Fluid, t::Tube)
μ = f.viscosity
D = t.diameter

return upreferred* v * D / μ)
return ustrip* v * D / μ)
end

"""
Expand All @@ -37,7 +37,7 @@ function prandtl_number(f::Fluid)
μ = f.viscosity
k = f.thermal_conductivity

return c * μ / k
return ustrip(c * μ / k)
end

"""
Expand Down Expand Up @@ -85,4 +85,4 @@ function nusselt_number_turbulent(f::Fluid, t::Tube)
ξ = (1.8log10(Re) - 1.5)^(-2)

return ((ξ / 8)Re * Pr) * (1 + λ^(2 / 3)) / (1 + 12.7/ 8)^(1 / 2) * (Pr^(2 / 3) - 1))
end
end
105 changes: 42 additions & 63 deletions src/fluid.jl
Original file line number Diff line number Diff line change
@@ -1,90 +1,69 @@
export Fluid, Water

"""
Fluid{
T1<:Unitful.Density,
T2<:Unitful.Velocity,
T3<:Unitful.DynamicViscosity,
T4<:SpecificHeatCapacity,
T5<:ThermalConductivity,
T6<:Unitful.Temperature,
}
Fluid{T<:AbstractQuantity}
A fluid with the important physical properties to be used in heat transfer calculations.
# Fields
- `density::T1`: the density of the fluid
- `velocity::T2`: the velocity of the fluid
- `viscosity::T3`: the viscosity of the fluid
- `heat_capacity::T4`: the specific heat capacity of the fluid
- `thermal_conductivity::T5`: the thermal conductivity of the fluid
- `temperature::T6`: the temperature of the fluid
- `density::T`: the density of the fluid
- `velocity::T`: the velocity of the fluid
- `viscosity::T`: the viscosity of the fluid
- `heat_capacity::T`: the specific heat capacity of the fluid
- `thermal_conductivity::T`: the thermal conductivity of the fluid
- `temperature::T`: the temperature of the fluid
"""
struct Fluid{
T1<:Unitful.Density,
T2<:Unitful.Velocity,
T3<:Unitful.DynamicViscosity,
T4<:SpecificHeatCapacity,
T5<:ThermalConductivity,
T6<:Unitful.Temperature,
}
density::T1
velocity::T2
viscosity::T3
heat_capacity::T4
thermal_conductivity::T5
temperature::T6
end

"""
Fluid(
density::Unitful.Density,
velocity::Unitful.Velocity,
viscosity::Unitful.DynamicViscosity,
heat_capacity::SpecificHeatCapacity,
thermal_conductivity::ThermalConductivity,
temperature::Unitful.Temperature,
)
struct Fluid{T<:AbstractQuantity}
density::T
velocity::T
viscosity::T
heat_capacity::T
thermal_conductivity::T
temperature::T

Returns a Fluid with the given properties.
function Fluid(;
density::T,
velocity::T,
viscosity::T,
heat_capacity::T,
thermal_conductivity::T,
temperature::T,
) where {T}
@assert dimension(density) == dimension(u"kg/m^3") "density must have units of mass per volume"
@assert dimension(velocity) == dimension(u"m/s") "velocity must have units of length per time"
@assert dimension(viscosity) == dimension(u"Pa*s") "viscosity must have units of pressure times time"
@assert dimension(heat_capacity) == dimension(u"J/(kg*K)") "heat_capacity must have units of energy per mass per temperature"
@assert dimension(thermal_conductivity) == dimension(u"W/(m*K)") "thermal_conductivity must have units of power per length per temperature"
@assert dimension(temperature) == dimension(u"K") "temperature must have units of temperature"
@assert ustrip(density) > 0 "density must be positive"
@assert ustrip(velocity) > 0 "velocity must be positive"
@assert ustrip(viscosity) > 0 "viscosity must be positive"
@assert ustrip(heat_capacity) > 0 "heat_capacity must be positive"
@assert ustrip(thermal_conductivity) > 0 "thermal_conductivity must be positive"
@assert ustrip(temperature) > 0 "temperature must be positive"

# Keywords
- `density::Unitful.Density`: the density of the fluid
- `velocity::Unitful.Velocity`: the velocity of the fluid
- `viscosity::Unitful.DynamicViscosity`: the viscosity of the fluid
- `heat_capacity::SpecificHeatCapacity`: the specific heat capacity of the fluid
- `thermal_conductivity::ThermalConductivity`: the thermal conductivity of the fluid
- `temperature::Unitful.Temperature`: the temperature of the fluid
new{T}(density, velocity, viscosity, heat_capacity, thermal_conductivity, temperature)
end

# Returns
- `Fluid`: the fluid with the given properties
"""
Fluid(;
density::Unitful.Density,
velocity::Unitful.Velocity,
viscosity::Unitful.DynamicViscosity,
heat_capacity::SpecificHeatCapacity,
thermal_conductivity::ThermalConductivity,
temperature::Unitful.Temperature,
) = Fluid(density, velocity, viscosity, heat_capacity, thermal_conductivity, temperature)
end

"""
Water
Returns a Fluid with the properties of water close to room temperature.
# Keywords
- `velocity::Unitful.Velocity`: the velocity of the water
- `temperature::Unitful.Temperature`: the temperature of the water
- `velocity::AbstractQuantity`: the velocity of the water
- `temperature::AbstractQuantity`: the temperature of the water
# Returns
- `Fluid`: the fluid with the properties of water close to room temperature at the given velocity and temperature
"""
Water(; velocity::Unitful.Velocity, temperature::Unitful.Temperature) = Fluid(
Water(; velocity::AbstractQuantity, temperature::AbstractQuantity) = Fluid(
density = 997u"kg/m^3",
velocity = velocity,
viscosity = 1u"mPa*s",
viscosity = 1e-3u"Pa*s",
heat_capacity = 4186u"J/(kg*K)",
thermal_conductivity = 0.591u"W/(m*K)",
temperature = temperature,
)
)
4 changes: 2 additions & 2 deletions src/heat_transfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Computes the heat transfer coefficient of a `fluid`` flowing through a `tube`.
- `t::Tube`: the tube through which the fluid flows
# Returns
- `Unitful.Quantity`: the heat transfer coefficient of the fluid flowing through the tube
- `DynamicQuantity.AbstractQuantity`: the heat transfer coefficient of the fluid flowing through the tube
"""
function heat_transfer(f::Fluid, t::Tube)
k = f.thermal_conductivity
D = t.diameter
Nu = nusselt_number(f, t)

return Nu * (k / D)
end
end
26 changes: 13 additions & 13 deletions src/pressure_drop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See VDI Heat Atlas, p. 1057 for details.
- `friction::Float`: the friction factor of the fluid flowing through the tube
# Returns
- `Unitful.Quantity`: the pressure drop of the fluid flowing through the tube
- `DynamicQuantities.AbstractQuantity`: the pressure drop of the fluid flowing through the tube
"""
function pressure_drop(f::Fluid, t::Tube; friction = nothing)
Re = reynolds_number(f, t)
Expand All @@ -30,7 +30,7 @@ function pressure_drop(f::Fluid, t::Tube; friction = nothing)
ξ = friction
end

return uconvert(u"bar", ξ * (L / d) ** u^2 / 2))
return uconvert(us"bar", ξ * (L / d) ** u^2 / 2))
end

"""
Expand All @@ -45,22 +45,22 @@ See VDI Heat Atlas, p. 1062 to 1063 for details.
- `c::Coil`: the coiled tube through which the fluid flows
# Returns
- `Unitful.Quantity`: the pressure drop of the fluid flowing through the tube
- `DynamicQuantity.AbstractQuantity`: the pressure drop of the fluid flowing through the tube
"""
function pressure_drop(f::Fluid, c::Coil)
Dw = c.diameter
H = c.pitch
function pressure_drop(f::Fluid, h::Helix)
Dw = h.diameter
H = h.pitch
D = Dw * (1 + (H /* Dw))^2)
d = c.tube.diameter
Re = reynolds_number(f, c.tube)
d = h.tube.diameter
Re = reynolds_number(f, h.tube)

if (d / D)^(-2) < Re && Re < 2300
ξ = (64 / Re) * (1 + 0.033(log10(Re * sqrt(d / D))))
else
ξ = (0.3164 / Re^(1 / 4)) * (1 + 0.095sqrt(d / D) * Re^(1 / 4))
end

return pressure_drop(f, c.tube, friction = ξ)
return pressure_drop(f, h.tube, friction = ξ)
end

"""
Expand All @@ -73,16 +73,16 @@ Computes the pressure drop of a `fluid` flowing through a `valve`.
- `v::Valve`: the valve through which the fluid flows
# Returns
- `Unitful.Quantity`: the pressure drop of the fluid flowing through the tube
- `DynamicQuantity.AbstractQuantity`: the pressure drop of the fluid flowing through the tube
"""
# https://en.wikipedia.org/wiki/Flow_coefficient
function pressure_drop(f::Fluid, v::Valve)
Q = uconvert(u"m^3/hr", v.flow_rate)
Kv = uconvert(u"m^3/hr", v.flow_factor)
Q = uconvert(us"m^3/hr", v.flow_rate)
Kv = uconvert(us"m^3/hr", v.flow_factor)

ρ = f.density
ρ₀ = 1000u"kg/m^3"
p₀ = 1u"bar"

return p₀ * (Q / Kv)^2 * ρ / ρ₀
end
end
Loading

2 comments on commit 0b6594f

@bodokaiser
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Breaking changes

  • replaced Unitful with DynamicQuantities
  • renamed Coil to Helix

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/115004

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" 0b6594f0b1a449e97d795cf1057638b991ee2382
git push origin v0.1.0

Please sign in to comment.