Commit bae6283c authored by Jayant Khatkar's avatar Jayant Khatkar
Browse files

add material prperties and cost function (slow)

parent 5d54b998
......@@ -8,6 +8,13 @@ using BenchmarkTools
using Plots
struct material
α::Number
E::Number
σ̄::AbstractArray{Number, 2} # Yield stress \sigma\bar
end
mutable struct contour
pos
time
......@@ -465,34 +472,46 @@ end
T0 = 215 # extrusion temp
Tc = 25 # room temp
Tcutoff = 100 # temperature above which strain isn't happening
k = 0.02 #value unknown
k = 0.08 #value unknown
Temp(t::Number) = Tc + (T0-Tc)*^(-k*t)
# see shape of temp function
#x = 1:100
#y = Temp.(x)
#plot(x,y)
function calc_cost(rollout::Vector{Int}, cdata::contourdata, vd::voxdata)
function calc_cost(rollout::Vector{Int}, cdata::contourdata, vd::voxdata, mat::material)
# go from rollout to timestart for each contour
timestart = rollout2time(rollout, cdata)
# calculate time at each voxel
voxtimes = [sum(v.seglen.*(v.segoffset + timestart[v.segcontours]))/sum(v.seglen) for v in vd.maps]
println("Empty voxels: ", sum(isnan.(voxtimes)))
#replace!(voxtimes, NaN=>0)
# calculate temp difference from voxel below it
considered_voxels = (1:length(vd.below))[(below.!=0) .& (.!isnan.(voxtimes))] # cannot calculate cost is no voxel underneath
considered_voxels = considered_voxels[.!isnan.(voxtimes[below[considered_voxels]])]
Δt = voxtimes[considered_voxels] - voxtimes[below[considered_voxels]]
considered_voxels = (1:length(vd.below))[(vd.below.!=0) .& (.!isnan.(voxtimes))] # cannot calculate cost is no voxel underneath
considered_voxels = considered_voxels[.!isnan.(voxtimes[vd.below[considered_voxels]])]
Δt = voxtimes[considered_voxels] - voxtimes[vd.below[considered_voxels]]
ΔT = Tcutoff .- Temp.(Δt)
# calculate stresses at each voxel
F = (2/mat.σ̄[1,1]^2 - 1/mat.σ̄[3,3]^2)/2
G = 1/(2*mat.σ̄[3,3]^2)
L = 1/(2*mat.σ̄[1,2]^2)
M = 1/(2*mat.σ̄[1,3]^2)
rel_voxels = vd.voxels[considered_voxels,:]
# calculate cost func at each voxel
# sum over the voxels
σ11 = rel_voxels.Sx + mat.E*mat.α*ΔT
σ22 = rel_voxels.Sy + mat.E*mat.α*ΔT
σ33 = rel_voxels.Sz
σ12 = rel_voxels.Txy
σ23 = rel_voxels.Tyz + (cdata.layer_height/vd.width)*mat.E*mat.α*ΔT
σ31 = rel_voxels.Txy + (cdata.layer_height/vd.width)*mat.E*mat.α*ΔT
cost = F * (σ11 - σ22).^2 +
G * ((σ33 - σ11).^2 + (σ33 - σ22).^2) +
2 * L * (σ12).^2 +
2 * M * (σ23 + σ31).^2 .- 1.0
return sum(cost)
end
......@@ -520,11 +539,23 @@ function clean_contour(c::contour)
return c
end
# ABS material properties
α_ABS = 100 # 78 - 108
E_ABS = 2.5e9 # 1.19e9 - 2.9e9
σ̄ = 3e7
σ̄_ABS = [
[σ̄ σ̄*0.5 σ̄*0.5]
[σ̄*0.5 σ̄ σ̄*0.5]
[σ̄*0.5 σ̄*0.5 σ̄*0.75]
]
ABS = material(α_ABS, E_ABS, σ̄_ABS)
obj = "/Users/jayant/phd/tempaware/" * "M1"
contours = clean_contour.(contour.(JSON.parse(open(obj * "contours.json"))))
cdata = contourdata(contours, 5, 5) # contour data
vd = voxdata(obj * "_voxels.csv", cdata) # TODO Need to debug
rl = random_rollout(cdata)
@benchmark rl = random_rollout(cdata) # 20/second
@benchmark valid_swap(rl, rand(1:length(contours)), rand(1:length(contours)), cdata) # 1mil/second
rl = random_rollout(cdata)
\ No newline at end of file
calc_cost(rl, cdata, vd, ABS) # 500/second
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment