main.jl 2.65 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
33
34
35
36
37
38
39
40
41
### MAIN LOOP
results = JSON.parse(open(add * "results.json"))
n_local_searches = 5
n_models = 10
max_iterations = 20
k = 50
for i in 1:n_models
    s = time()
    obj = "M" * string(i)
    if obj in keys(results) || obj == "M4" || obj == "M9"
        continue # skip is already done
42
    end
43
    println("Starting " * obj)
44

45
46
47
48
49
50
51
52
    # Load data
    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
    vd = voxdata(obj_add * "_voxels.csv", cdata)
    construct_cost(cdata, vd, ABS, td, :cost_f)
    construct_best_neighbor(cdata, cost_f, k)
53

54
55
56
57
    # default rollout cost
    rl = Vector(1:length(cdata.contours))
    c = cost_f(rl)
    update_result(results, obj, rl, c, :default)
58

59
60
61
62
63
64
65
66
67
68
69
    # local search
    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
    println("Completed in " * string(time()-s) * " seconds")
Jayant Khatkar's avatar
Jayant Khatkar committed
70
end
71
save_result(results, add * "results.json")
72

73
74
### Visualisations
# distribution of stresses
75
76
77
78
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
79
80
histogram!(sort(data, rev=true)[1:4000]) # vast majority of voxels near 0 stress - can ignore

81
# voxmap sanity check
82
plot(vd, 46, cdata)
83
84

# rollout order 3d
85
plot(Vector(1:length(rl)), cdata)
86
87
plot(rl, cdata)

88
# rollout order animated
89
90
91
rl = random_rollout(cdata)
rl = Vector(1:length(rl))
@time plot_animate(rl, cdata)