1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-12-30 16:13:32 +00:00

Center of mass graphics

This commit is contained in:
MoBit 2021-12-02 23:13:54 +01:00
parent cba608a425
commit d7ad9c3354
10 changed files with 178 additions and 27 deletions

View file

@ -1,7 +1,13 @@
name = "ReCo"
uuid = "b25f7548-fcc9-4c91-bc24-841b54f4dd54"
authors = ["MoBit <mo8it@protonmail.com>"]
version = "0.1.0"
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
@ -9,8 +15,13 @@ JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
ProfileView = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReinforcementLearning = "158674fc-8238-5cab-b5ba-03dfc80d1318"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
[compat]
julia = "1.6"

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# ReCo
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)

129
graphics/center_of_mass.jl Normal file
View file

@ -0,0 +1,129 @@
using Luxor
using StaticArrays
using ReCo: restrict_coordinate
##
function project(x, L)
φ = (x + L) * π / L
return Point(cos(φ), -sin(φ))
end
function project_back(θ, L)
return θ * L / π - L
end
##
box_length = 100
box_height = 100
L = 0.35 * box_length
R = 0.35 * box_length
A = -0.9 * L
B = 0.65 * L
pr = 0.03 * L
Ap = project(A, L)
Bp = project(B, L)
M = R * ((Ap + Bp) / 2)
θ = atan(-M[2], M[1])
COM = restrict_coordinate(project_back(θ, L); l=L)
COMp = R * Point(cos(θ), -sin(θ))
##
graphics_export_dir = "exports/graphics"
mkpath(graphics_export_dir)
Drawing(box_length, box_height, "$graphics_export_dir/line.pdf")
origin()
setcolor("black")
arrow(Point(-1.1 * L, 0), Point(1.2 * L, 0); arrowheadlength=0.1 * L, linewidth=0.8)
green_orange = blend(Point(-1.5 * L, 0), Point(1.5 * L, 0))
addstop(green_orange, 0.0, "orange")
addstop(green_orange, (L) / (3 * L), "green")
addstop(green_orange, (2 * L) / (3 * L), "orange")
addstop(green_orange, 1.0, "green")
setblend(green_orange)
setline(0.8)
line(Point(-L, 0), Point(L, 0), :stroke)
setcolor("red")
setline(0.5)
for x in SVector(-L, L)
line(Point(x, 0.05 * L), Point(x, -0.05 * L), :stroke)
end
setcolor("cyan3")
line(Point(0, 0.05 * L), Point(0, -0.05 * L), :stroke)
setcolor("blue")
for p in SVector(A, B)
circle(Point(p, 0), pr, :fill)
end
setcolor("brown")
circle(Point(COM, 0), pr, :fill)
setcolor("black")
fontsize(5)
text("x", Point(1.2 * L, 0.035 * L))
text("-L", Point(-L - 0.08 * L, 0.18 * L))
text("0", Point(0 - 0.035 * L, 0.18 * L))
text("+L", Point(L - 0.08 * L, 0.18 * L))
text("A", Point(A - 0.04 * L, -0.06 * L))
text("B", Point(B - 0.04 * L, -0.06 * L))
text("COM", Point(COM - 0.125 * L, -0.06 * L))
finish()
##
Drawing(box_length, box_height, "$graphics_export_dir/circle.pdf")
origin()
arrow(Point(-1.2 * R, 0), Point(1.2 * R, 0); arrowheadlength=0.1 * R, linewidth=0.8)
arrow(Point(0, 1.2 * R), Point(0, -1.2 * R); arrowheadlength=0.1 * R, linewidth=0.8)
setcolor("black")
fontsize(5)
text("α", Point(1.22 * R, 0.035 * R))
text("β", Point(-0.04 * R, -1.23 * R))
orange_green = blend(Point(0, -R), Point(0, R), "green", "orange")
setblend(orange_green)
setline(0.8)
circle(Point(0, 0), R, :stroke)
setcolor("red")
setline(0.5)
line(Point(1.05 * R, 0), Point(0.95 * R, 0), :stroke)
setcolor("cyan3")
line(Point(-1.05 * R, 0), Point(-0.95 * R, 0), :stroke)
setcolor("blue")
for pp in SVector(Ap, Bp)
circle(R * pp, pr, :fill)
end
setcolor("black")
setdash("dot")
line(R * Ap, R * Bp, :stroke)
line(Point(0, 0), COMp, :stroke)
setcolor("purple1")
circle(M, pr, :fill)
setcolor("brown")
circle(COMp, pr, :fill)
finish()

View file

@ -1,3 +1,6 @@
using StaticArrays: SVector
using LoopVectorization: @turbo
mutable struct Particle
id::Int64

View file

@ -1,28 +1,13 @@
using Pkg
Pkg.activate(".")
module ReCo
using Random, Distributions
using ProgressMeter
using GLMakie, ColorSchemes, LaTeXStrings
using StaticArrays
using LoopVectorization: @turbo, @tturbo
using JLD2: JLD2
using JSON3: JSON3
export init_sim, run_sim
import Dates: now, CompoundPeriod, canonicalize
import Base: push!, iterate, wait
# BEGIN dev deps
using Revise
using BenchmarkTools
# END
set_theme!(theme_black())
includet("PreVector.jl")
includet("Particle.jl")
includet("setup.jl")
includet("simulation.jl")
includet("data.jl")
include("PreVector.jl")
include("Particle.jl")
include("setup.jl")
include("simulation.jl")
include("data.jl")
# includet("animation.jl")
includet("run.jl")
include("run.jl")
end # module

View file

@ -1,4 +1,7 @@
function animate(directory::String, sol::Solution, variables; framerate=0)
using GLMakie, ColorSchemes
using LaTeXStrings: @L_str
function animate(dir::String; framerate=0)
println("Generating animation...")
fig = Figure(; resolution=(1080, 1080))

View file

@ -1,3 +1,7 @@
using StaticArrays: SVector
using LoopVectorization: @turbo
using JLD2: JLD2
struct Bundle
t::Vector{Float64}
c::Matrix{Vector{Float64}}

View file

@ -1,3 +1,6 @@
using Random: Random
using JSON3: JSON3
function run_sim(
dir::String;
duration::Float64,

View file

@ -1,3 +1,7 @@
using Distributions: Uniform
using Dates: now
using JSON3: JSON3
function initial_particle_grid_pos(i, j; grid_box_width, l)
term = -0.5 * grid_box_width - l
return [k * grid_box_width + term for k in (i, j)]

View file

@ -1,3 +1,9 @@
using ProgressMeter: @showprogress
using LoopVectorization: @turbo
using Distributions: Normal
using Dates: Dates, now
import Base: wait
rand_normal01() = rand(Normal(0, 1))
function update_verlet_list!(args)
@ -115,7 +121,7 @@ function simulate(
end
end_time = now()
elapsed_time = canonicalize(CompoundPeriod(end_time - start_time))
elapsed_time = Dates.canonicalize(Dates.CompoundPeriod(end_time - start_time))
println("Simulation done at $end_time and took $elapsed_time.")
return nothing