-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced Unitful with DynamicQuantities
- Loading branch information
1 parent
e212a8d
commit 59d5810
Showing
12 changed files
with
252 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
Oops, something went wrong.
59d5810
There was a problem hiding this comment.
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
Unitful
withDynamicQuantities
Wire
structCrossSection
s toProfile
s59d5810
There was a problem hiding this comment.
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: