-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update doc, ready to release dev-0.1
- Loading branch information
Showing
11 changed files
with
331 additions
and
48 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 +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) | ||
``` |
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,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. |
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 +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) | ||
``` |
Oops, something went wrong.