Skip to content

Commit

Permalink
Update doc, ready to release dev-0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
islent committed Dec 3, 2019
1 parent 9f211a2 commit e867b68
Show file tree
Hide file tree
Showing 11 changed files with 331 additions and 48 deletions.
24 changes: 24 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ version = "0.8.2"
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[DocStringExtensions]]
deps = ["LibGit2", "Markdown", "Pkg", "Test"]
git-tree-sha1 = "88bb0edb352b16608036faadcc071adda068582a"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.8.1"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[LibGit2]]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

Expand Down Expand Up @@ -64,10 +73,18 @@ git-tree-sha1 = "f15e25a6fa064e0805ef7819d91d79e0ff0bedf4"
uuid = "5ad8b20f-a522-5ce9-bfc9-ddf1d5bda6ab"
version = "0.2.0"

[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand All @@ -89,6 +106,9 @@ git-tree-sha1 = "9cc4b586c71f9aea25312b94be8c195f119b0ec3"
uuid = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
version = "0.8.3"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

Expand All @@ -113,6 +133,10 @@ uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository = "https://github.com/JuliaAstroSim/PhysicalParticles.jl"
version = "0.1.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
PhysicalConstants = "5ad8b20f-a522-5ce9-bfc9-ddf1d5bda6ab"
Expand All @@ -15,5 +16,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f"

[compat]
[compat]
julia = "1.2.0, 1.3.0"
55 changes: 54 additions & 1 deletion docs/src/manual/Conversion.md
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
# Conversion
# Conversion

## Conversion from Arrays

`pconvert` is smart enough to handle 2D and 3D vectors at same time:
```julia
julia> pconvert([1.0, 2.0])
PVector2D{Float64}(1.0, 2.0)

julia> pconvert([1.0, 2.0, 3.0])
PVector{Float64}(1.0, 2.0, 3.0)

julia> pconvert([1.0, 2.0, 3.0, 4.0])
ERROR: Not supported dimension!


julia> a = pconvert([1.0 3.0;
2.0 4.0])
2-element Array{PVector2D,1}:
PVector2D{Float64}(1.0, 2.0)
PVector2D{Float64}(3.0, 4.0)

julia> pconvert([1.0 4.0;
2.0 5.0;
3.0 6.0])
2-element Array{PVector,1}:
PVector{Float64}(1.0, 2.0, 3.0)
PVector{Float64}(4.0, 5.0, 6.0)
```

## Assign from Arrays

`assign_points` takes in three paremeters: `particles`, `symbol` and `points`. Assignment of `:Pos`, `:Vel` and `:Acc` is enough for simulation tasks:
```julia
julia> pu = rand_pvector(3, u"m")
3-element Array{PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}},1}:
PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.6477898102542425 m, 0.4373299903072585 m, 0.7049677138795583 m)
PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.8651944634833202 m, 0.5480460857713867 m, 0.5620548650425954 m)
PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.28164175368241895 m, 0.1673360850328498 m, 0.31321825771349987 m)

julia> p_Ball = [Ball() for i=1:3]
3-element Array{Ball{Int64},1}:
Ball{Int64}(PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.0 m, 0.0 m, 0.0 m), PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}}}(0.0 m s^-1, 0.0 m s^-1, 0.0 m s^-1), 0.0 kg, 0)
Ball{Int64}(PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.0 m, 0.0 m, 0.0 m), PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}}}(0.0 m s^-1, 0.0 m s^-1, 0.0 m s^-1), 0.0 kg, 0)
Ball{Int64}(PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.0 m, 0.0 m, 0.0 m), PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}}}(0.0 m s^-1, 0.0 m s^-1, 0.0 m s^-1), 0.0 kg, 0)

julia> assign_points(p_Ball, :Pos, pu)

julia> p_Ball
3-element Array{Ball{Int64},1}:
Ball{Int64}(PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.6477898102542425 m, 0.4373299903072585 m, 0.7049677138795583 m), PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}}}(0.0 m s^-1, 0.0 m s^-1, 0.0 m s^-1), 0.0 kg, 0)
Ball{Int64}(PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.8651944634833202 m, 0.5480460857713867 m, 0.5620548650425954 m), PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}}}(0.0 m s^-1, 0.0 m s^-1, 0.0 m s^-1), 0.0 kg, 0)
Ball{Int64}(PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.28164175368241895 m, 0.1673360850328498 m, 0.31321825771349987 m), PVector{Quantity{Float64,𝐋*𝐓^-1,Unitful.FreeUnits{(m, s^-1),𝐋*𝐓^-1,nothing}}}(0.0 m s^-1, 0.0 m s^-1, 0.0 m s^-1), 0.0 kg, 0)
```
70 changes: 68 additions & 2 deletions docs/src/manual/Extent.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
# Extent

## Center
## Type Hierarchy

```julia
abstract type AbstractExtent{T} end
abstract type AbstractExtent2D{T} <: AbstractExtent{T} end
abstract type AbstractExtent3D{T} <: AbstractExtent{T} end

mutable struct Extent2D{T<:Union{Number, Quantity}} <: AbstractExtent2D{T}
xMin::T
xMax::T
yMin::T
yMax::T
SideLength::T
Center::PVector2D{T}
Corner::PVector2D{T}
end

## Finding Extent
mutable struct Extent{T<:Union{Number, Quantity}} <: AbstractExtent3D{T}
xMin::T
xMax::T
yMin::T
yMax::T
zMin::T
zMax::T
SideLength::T
Center::PVector{T}
Corner::PVector{T}
end
```

## Usage

You can get `Extent` of an array of mathical vectors or particles by calling `extent` functions:
```julia
julia> p = [Ball(PVector(-1.0u"m", 1.0u"m", 1.0u"m"), PVector(u"m"), 1.0u"kg", 1),
Ball(PVector(1.0u"m", -1.0u"m", -1.0u"m"), PVector(u"m"), 1000.0u"g", 2)]
julia> extent(p)
Extent{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(-1.0 m, 1.0 m, -1.0 m, 1.0 m, -1.0 m, 1.0 m, 2.0 m, PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.0 m, 0.0 m, 0.0 m), PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(-1.0 m, -1.0 m, -1.0 m))
```
or by comparing two `Extent`s and even array of `Extent`s:
```julia
# 5 methods for generic function "extent":
[1] extent(a::Array{T,N}) where {N, T<:Union{AbstractParticle2D, PVector2D}}
[2] extent(a::Array{T,N}) where {N, T<:Union{AbstractParticle3D, PVector}}
[3] extent(a::Extent2D, b::Extent2D)
[4] extent(a::Extent, b::Extent)
[5] extent(a::Array{T,N} where N) where T<:AbstractExtent

```

For particles with masses, compute the mass center with:
```julia
julia> mass_center(p)
PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.0 m, 0.0 m, 0.0 m)
```

## Minimum, maximum and center

The computation of `Extent`s are based on a series of small functions, we use `p` defined in previous section to demonstrate:
```julia
julia> min_x(p)
-1.0 m

julia> max_z(p)
1.0 m

julia> center(p)
PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.0 m, 0.0 m, 0.0 m)
```

We have implemented `max_x`, `max_y`, `max_z`, `min_x`, `min_y`, `min_z`, `center`, `center_x`, `center_y`, `center_z` for both points and particles. You could simply infer their functions by name.
45 changes: 26 additions & 19 deletions docs/src/manual/PVector.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@

All of the sub-types of `Number` and `Quantity` are supported. In general it works as we expected whereas there are too many possibilities to foresee. Mathematically vector operations, linear algebra, array conversions, neighbor searching, etc. are well documented in coreesponding sections.

The vector types are unmutable out of performance reason, and the coordinate members must be identical types:
```julia
julia> PVector2D(1.0, 1.0f0)
ERROR: MethodError: no method matching PVector2D(::Float64, ::Float32)
Closest candidates are:
PVector2D(::Number, ::Number, ::Unitful.Units) at C:\Users\islent\.julia\packages\PhysicalParticles\oFZmG\src\PVector.jl:45
PVector2D(::T, ::T) where T<:Number at C:\Users\islent\.julia\packages\PhysicalParticles\oFZmG\src\PVector.jl:2
Stacktrace:
[1] top-level scope at REPL[27]:1

julia> PVector2D(1.0u"m", 1.0u"km")
ERROR: MethodError: no method matching PVector2D(::Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}, ::Quantity{Float64,𝐋,Unitful.FreeUnits{(km,),𝐋,nothing}})
Closest candidates are:
PVector2D(::Number, ::Number, ::Unitful.Units) at C:\Users\islent\.julia\packages\PhysicalParticles\oFZmG\src\PVector.jl:45
PVector2D(::T, ::T) where T<:Number at C:\Users\islent\.julia\packages\PhysicalParticles\oFZmG\src\PVector.jl:2
Stacktrace:
[1] top-level scope at REPL[28]:1
```
The vector types are unmutable out of performance reason.

!!! note

Coordinate components must be identical types:
```julia
julia> PVector2D(1.0, 1.0f0)
ERROR: MethodError: no method matching PVector2D(::Float64, ::Float32)
Closest candidates are:
PVector2D(::Number, ::Number, ::Unitful.Units) at C:\Users\islent\.julia\packages\PhysicalParticles\oFZmG\src\PVector.jl:45
PVector2D(::T, ::T) where T<:Number at C:\Users\islent\.julia\packages\PhysicalParticles\oFZmG\src\PVector.jl:2
Stacktrace:
[1] top-level scope at REPL[27]:1

julia> PVector2D(1.0u"m", 1.0u"km")
ERROR: MethodError: no method matching PVector2D(::Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}, ::Quantity{Float64,𝐋,Unitful.FreeUnits{(km,),𝐋,nothing}})
Closest candidates are:
PVector2D(::Number, ::Number, ::Unitful.Units) at C:\Users\islent\.julia\packages\PhysicalParticles\oFZmG\src\PVector.jl:45
PVector2D(::T, ::T) where T<:Number at C:\Users\islent\.julia\packages\PhysicalParticles\oFZmG\src\PVector.jl:2
Stacktrace:
[1] top-level scope at REPL[28]:1
```

## Type Hierarchy

Expand Down Expand Up @@ -127,4 +131,7 @@ PVector2D{Float32}(2.0f0, 4.0f0)
julia> b * 2.0
PVector2D{Float64}(2.0, 4.0)
```
We did not cover all combinations in auto-test, but fortunately everything worked well in daily usage! When it comes to `Quantity`, the computed `Units` may causes some issues, so we handled them in particular as documented in LinearAlgebra section.

!!! note

We did not cover all combinations in auto-test, but fortunately everything worked well in daily usage! When it comes to `Quantity`, the computed `Units` may causes some issues, so we handled them in particular as documented in LinearAlgebra section.
30 changes: 29 additions & 1 deletion docs/src/manual/Random.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# Random
# Random

Usage of random point generators is straightforward:
```julia
julia> p = rand_pvector(3)
3-element Array{PVector{Float64},1}:
PVector{Float64}(0.899541890819791, 0.49609709458549345, 0.22817220536717397)
PVector{Float64}(0.21907343513386301, 0.39110699072427035, 0.3502946880565312)
PVector{Float64}(0.8107782153679699, 0.20218167820102884, 0.94236923352867)

julia> pu = rand_pvector(3, u"m")
3-element Array{PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}},1}:
PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.6477898102542425 m, 0.4373299903072585 m, 0.7049677138795583 m)
PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.8651944634833202 m, 0.5480460857713867 m, 0.5620548650425954 m)
PVector{Quantity{Float64,𝐋,Unitful.FreeUnits{(m,),𝐋,nothing}}}(0.28164175368241895 m, 0.1673360850328498 m, 0.31321825771349987 m)
```

Here is the list of supported generators:
```julia
rand_pvector(n::Integer)
rand_pvector(n::Integer, T::DataType)
rand_pvector(n::Integer, u::Unitful.Units)
rand_pvector(n::Integer, u::Unitful.Units, T::DataType)

rand_pvector2d(n::Integer)
rand_pvector2d(n::Integer, T::DataType)
rand_pvector2d(n::Integer, u::Unitful.Units)
rand_pvector2d(n::Integer, u::Unitful.Units, T::DataType)
```
Loading

0 comments on commit e867b68

Please sign in to comment.