-
Notifications
You must be signed in to change notification settings - Fork 0
/
StructModule.jl
87 lines (75 loc) · 2.01 KB
/
StructModule.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# using Distributed
@everywhere module StructModule
using Distributions: Normal
using LinearAlgebra: norm, cross
export Node, MassSystem, SimData
const M_TOT = 1e11 # Sun masses
const R_INITIAL = 50e3 # Parsec
mutable struct Node
borders::Array{Float64,2}
diagonal::Float64
mass_count::Int64
leafs::Array{Node,1}
parent::Node
center_of_mass::Array{Float64,1}
masses_indices::Array{Int64,1}
function Node(borders_::Array{Float64,2}, mass_count::Int64)
x = new();
x.borders = borders_;
x.diagonal = norm(borders_[1,:]-borders_[2,:], 2);
x.mass_count = mass_count;
x.center_of_mass = zeros(3)
x.masses_indices = []
x
end
end
function Node(borders::Array{Float64,2})
return Node(borders,0)
end
mutable struct MassSystem
N::Int32
each_mass::Float64
positions::Array{Float64,2}
velocities::Array{Float64,2}
forces::Array{Float64,2}
root::Node
end
function MassSystem(N::Int64,velocity::Float64)
# initialize MassSystem
each_mass = M_TOT/N
# calculate positions
u = rand(N)
cos_theta = rand(N)
phi = rand(N)
phi = 2*pi*phi
cos_theta = 2 .* cos_theta .- 1
sin_theta = sqrt.(1 .- cos_theta .^ 2)
r = R_INITIAL .* u .^ (1/3)
positions = r .* [sin_theta .* cos.(phi) sin_theta .* sin.(phi) cos_theta]
d = Normal(0, velocity/sqrt(3) )
# calculate velocities
if N == 2
positions = rand()*[0 0 -R_INITIAL;0 0 R_INITIAL]
velocities = [0 velocity 0;0 -velocity 0]
println("change v, p")
else
velocities = rand(d,N,3)
end
# initialize forces
forces = zeros(N,3)
# build tree
root = Node(zeros(2,3))
system = MassSystem(N,each_mass,positions,velocities,forces,root)
# system.root = build_tree!(system)
system
end
mutable struct SimData
t_span::Tuple{Float64,Float64}
n::Int64
abstol::Float64
folder::String
end # mutable struct
function SimData(t_span, n, abstol)
SimData(t_span, n, abstol,"")
end
end