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 e212a8d commit 59d5810
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 225 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,15 +1,15 @@
name = "ElectricWires"
uuid = "a6e744fb-b06e-4c79-977f-74d170207450"
authors = ["Bodo Kaiser"]
version = "0.0.1"
repo = "https://github.com/rydyb/ElectricWires.jl"
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: 3 additions & 3 deletions src/ElectricWires.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module ElectricWires

using Unitful
using DynamicQuantities

include("profiles.jl")
include("materials.jl")
include("cross_sections.jl")
include("properties.jl")
include("wire.jl")

end
91 changes: 0 additions & 91 deletions src/cross_sections.jl

This file was deleted.

45 changes: 28 additions & 17 deletions src/materials.jl
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
export Material, Copper

@derived_dimension SpecificHeatCapacity dimension(u"J/(kg*K)")

"""
Material{T1,T2,T3}
Material{T}
A material with a name, resistivity, density, and heat capacity.
# Fields
- `name::String`: The name of the material.
- `resistivity::T1`: The resistivity of the material.
- `density::T2`: The density of the material.
- `heat_capacity::T3`: The heat capacity of the material.
- `resistivity::AbstractQuantity`: The resistivity of the material.
- `density::AbstractQuantity`: The density of the material.
- `heat_capacity::AbstractQuantity`: The heat capacity of the material.
"""
struct Material{T1<:Unitful.ElectricalResistivity,T2<:Unitful.Density,T3<:SpecificHeatCapacity}
name::String
resistivity::T1
density::T2
heat_capacity::T3
struct Material{T<:AbstractQuantity}
resistivity::T
density::T
heat_capacity::T

function Material(; resistivity::T, density::T, heat_capacity::T) where {T}
@assert dimension(resistivity) == dimension(u"Ω*m") "resistivity must have units of resistance times length"
@assert dimension(density) == dimension(u"g/cm^3") "density must have units of mass per volume"
@assert dimension(heat_capacity) == dimension(u"J/(g*K)") "heat capacity must have units of energy per mass per temperature"
@assert ustrip(heat_capacity) > 0 "heat_capacity must be positive"
@assert ustrip(resistivity) > 0 "resistivity must be positive"
@assert ustrip(density) > 0 "density must be positive"
new{T}(resistivity, density, heat_capacity)
end
end

export Material
export Cu

"""
Copper
Cu
Copper as instance of `Material` with properties from [Wikipedia][1].
Cu as instance of `Material` with properties from [Wikipedia][1].
[1]: https://en.wikipedia.org/wiki/Electrical_resistivity_and_conductivity#Resistivity_and_conductivity_of_various_materials
"""
const Copper = Material("Copper", 1.68e-8u"Ω*m", 8.96u"g/cm^3", 0.385u"J/(g*K)")
const Cu = Material(;
resistivity = 1.68e-8u"Ω*m",
density = 8.96u"g/cm^3",
heat_capacity = 0.385u"J/(g*K)",
)
84 changes: 84 additions & 0 deletions src/profiles.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
export Profile, CircularProfile, RectangularProfile, DifferenceProfile, RectangularHollowProfile
export area

"""
Profile
Abstract type for wire cross-sections.
"""
abstract type Profile end

"""
CircularProfile{T}
A circular wire cross-section.
# Fields
- `diameter::T`: The diameter of the wire.
"""
struct CircularProfile{T<:AbstractQuantity} <: Profile
diameter::T

function CircularProfile(; diameter::T) where {T}
@assert dimension(diameter) == dimension(u"m") "diameter must have units of length"
@assert ustrip(diameter) > 0 "diameter must be positive"
new{T}(diameter)
end
end

"""
RectangularProfile{T}
A rectangular wire cross-section.
# Fields
- `width::T`: The width of the wire.
- `height::T`: The height of the wire.
"""
struct RectangularProfile{T<:AbstractQuantity} <: Profile
width::T
height::T

function RectangularProfile(; width::T, height::T) where {T}
@assert dimension(width) == dimension(u"m") "width must have units of length"
@assert dimension(height) == dimension(u"m") "height must have units of length"
@assert ustrip(width) > 0 "width must be positive"
@assert ustrip(height) > 0 "height must be positive"
new{T}(width, height)
end
end

"""
DifferenceProfile{S1,S2}
A difference of two wire cross-sections.
# Fields
- `a::S1`: The first wire cross-section which is subtracted from.
- `b::S2`: The second wire cross-section which is subtracted.
"""
struct DifferenceProfile{S1<:Profile,S2<:Profile} <: Profile
a::S1
b::S2
end

RectangularHollowProfile(;
width::AbstractQuantity,
height::AbstractQuantity,
hole_diameter::AbstractQuantity,
) = DifferenceProfile(RectangularProfile(width = width, height = height), CircularProfile(diameter = hole_diameter))

"""
area(s::CrossSection)
Returns the area of the given wire cross-section.
# Arguments
- `s::Profile`: The wire cross-section.
# Returns
- `Unitful.Area`: The area of the wire cross-section.
"""
area(s::CircularProfile) = π * (s.diameter / 2)^2
area(s::RectangularProfile) = s.width * s.height
area(s::DifferenceProfile) = area(s.a) - area(s.b)
79 changes: 0 additions & 79 deletions src/properties.jl

This file was deleted.

28 changes: 28 additions & 0 deletions src/wire.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export Wire
export weight, resistance, heat_capacity

"""
Wire{T}
A wire with a cross-section, material, and length.
# Fields
# - `profile::Profile`: The wire's cross-section.
# - `material::Material{T}`: The material of the wire.
# - `length::T`: The length of the wire.
"""
struct Wire{T<:AbstractQuantity}
profile::Profile
material::Material{T}
length::T

function Wire(; profile::Profile, material::Material{T}, length::T) where {T}
@assert dimension(length) == dimension(u"m") "length must have units of length"
@assert ustrip(length) > 0 "length must be positive"
new{T}(profile, material, length)
end
end

weight(w::Wire) = uconvert(us"g", w.length * area(w.profile) * w.material.density)
resistance(w::Wire) = uconvert(us"mΩ", w.length * w.material.resistivity / area(w.profile))
heat_capacity(w::Wire) = uconvert(us"J/K", w.material.heat_capacity * weight(w))
Loading

2 comments on commit 59d5810

@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
  • added Wire struct
  • renamed CrossSections to Profiles

@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/114997

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>" 59d581080659c9ac347fcf94a7c74cc1602e9a3f
git push origin v0.1.0

Please sign in to comment.