main.jl 3.59 KB
Newer Older
1
include("utils.jl")
2

3
### ABS material properties
4
α_ABS = 63e-6
5
6
E_ABS = 2.5e9    # 1.19e9 - 2.9e9
σ̄ = 6e7          # mega
7
Tcutoff = 100 # temperature above which strain isn't happening
8
σ̄_ABS = [
9
10
11
    [σ̄       σ̄*0.5   σ̄*0.375]
    [σ̄*0.5   σ̄       σ̄*0.375]
    [σ̄*0.375 σ̄*0.375 σ̄*0.75 ]
12
    ]
13
14
15
16
17
ABS = material(α_ABS, E_ABS, σ̄_ABS, Tcutoff)
td = tempdecay(215, 25, 0.04) # extrusion temp, room temp, decay rate
tdslow = tempdecay(215, 25, 0.01)
tdfast = tempdecay(215, 25, 0.08)
# visualise_tempdecay(tdfast)
18

19

20
add = "/Users/jayant/phd/tempaware/models/"
21
#stress_multiplier!(vd.voxels, 10)
22
#rl = random_rollout(cdata)
23

24

25
26
27
28
# single local search
#rl = random_rollout(cdata)
#cost_f(rl)
#@time local_search!(rl, max_iterations)
29
30


31
32
### MAIN LOOP
results = JSON.parse(open(add * "results.json"))
33
n_local_searches = 10
34
n_models = 10
35
36
max_iterations = 50
k = 150
37
38
39
for i in 1:n_models
    s = time()
    obj = "M" * string(i)
40
41
    # if obj in keys(results) || obj == "M4" || obj == "M9"
    if obj == "M4" || obj == "M9"
42
        continue # skip is already done
43
    end
44
    println("Starting " * obj)
45

46
    # Load data
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    f_name = Symbol("cost_" * obj)
    try
        cost_func = getfield(Main, f_name)
    catch
        println("Loading data...")
        obj_add =  add * obj
        contours = clean_contour.(contour.(JSON.parse(open(obj_add * "contours.json"))))
        cdata = contourdata(contours, 40, 5) # contour data
        println(string(length(cdata.contours)) * " contours")
        vd = voxdata(obj_add * "_voxels.csv", cdata)
        println("Constructing Cost function...")
        construct_cost(cdata, vd, ABS, td, f_name)
        cost_func = getfield(Main, f_name)
        println(cost_func)
        construct_best_neighbor(cdata, cost_func, k)
    end
    cost_func = getfield(Main, f_name)
64

65
    # default rollout cost
66
67
68
69
70
71
72
73
    rl_d = Vector(1:length(cdata.contours))
    c = cost_func(rl_d)
    update_result(results, obj, rl_d, c, :default)

    # greedy rollout cost
    rl_g = greedy_rollout(cdata)
    c = cost_func(rl_g)
    update_result(results, obj, rl_g, c, :greedy)
74

75
    # local search
76
77
78
79
80
81
82
83
84
    # println("Doing local search " * string(n_local_searches) * " times")
    # opt_costs = zeros(n_local_searches)
    # Threads.@threads for i in 1:n_local_searches
    #     rl = random_rollout(cdata)
    #     random_cost = cost_f(rl)
    #     update_result(results, obj, rl, random_cost, :random)
    #     local_cost = local_search!(rl, max_iterations)
    #     update_result(results, obj, rl, local_cost, :local)
    # end
85
    println("Completed in " * string(time()-s) * " seconds")
Jayant Khatkar's avatar
Jayant Khatkar committed
86
end
87
save_result(results, add * "results.json")
88

89
90
91
92
93
94
95
96
### Load individual models for the plots
obj = "M1"
obj_add = add * obj
contours = clean_contour.(contour.(JSON.parse(open(obj_add * "contours.json"))))
cdata = contourdata(contours, 40, 5) # contour data
vd = voxdata(obj_add * "_voxels.csv", cdata)


97
98
### Visualisations
# distribution of stresses
99
100
101
102
data_stress = .( vd.voxels.Sx.^2 + vd.voxels.Sy.^2 + vd.voxels.Sz.^2)
data_strain = .(vd.voxels.Txy.^2 + vd.voxels.Tyz.^2 + vd.voxels.Txz.^2)
data = data_stress
histogram(data) # vast majority of voxels near 0 stress - can ignore
103
104
histogram!(sort(data, rev=true)[1:4000]) # vast majority of voxels near 0 stress - can ignore

105
# voxmap sanity check
106
plot(vd, 1500, cdata)
107
108

# rollout order 3d
109
110
111
112
113
114
115
116
117
rl_d = Vector(1:length(cdata.contours))
rl_r = random_rollout(cdata)
rl_g = greedy_rollout(cdata)
rl_l = Vector{Int}(results[obj]["best_rollout"])

plot(rl_d, cdata)
plot(rl_r, cdata)
plot(rl_g, cdata)
plot(rl_l, cdata)
118

119
# rollout order animated
120
@time plot_animate(rl_g, cdata, rate=5)
Jayant Khatkar's avatar
Jayant Khatkar committed
121
122
123

# plot results
plot(results)