Newer
Older
# Amira Abdel-Rahman
# (c) Massachusetts Institute of Technology 2020
function updateDataAndSave!(metavoxel,setup,fileName,sys="GPU")
nodes = setup["nodes"]
edges = setup["edges"]
setup["animation"]["showDisplacement"]=false
voxCount=size(nodes)[1]
linkCount=size(edges)[1]
if (sys=="GPU")
N_displacement=Array(metavoxel["N_displacementGPU"])
N_position=Array(metavoxel["N_positionGPU"])
N_angle=Array(metavoxel["N_angleGPU"])
E_stress=Array(metavoxel["E_stressGPU"])
else
# CPU
N_displacement=Array(metavoxel["N_displacement"])
N_position=Array(metavoxel["N_position"])
N_angle=Array(metavoxel["N_angle"])
E_stress=Array(metavoxel["E_stress"])
end
setup["viz"]["maxStress"]=maximum(E_stress)
setup["viz"]["minStress"]=minimum(E_stress)
setup["animation"]["exaggeration"]=1.0
i=1
for edge in edges
edge["stress"]=E_stress[i]
i=i+1
end
scale1=1.0
if haskey(setup,"scale")
scale1=setup["scale"]
end
scale2=1.0
scale=scale1/scale2
# if haskey(setup,"voxelSize")
# setup["voxelSize"]=setup["voxelSize"]*scale1
# end
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
88
89
90
91
92
93
94
95
96
97
if haskey(setup,"supports")
supports = setup["supports"]
for support in supports
support[1]["min"]["x"]=support[1]["min"]["x"]*scale1
support[1]["min"]["y"]=support[1]["min"]["y"]*scale1
support[1]["min"]["z"]=support[1]["min"]["z"]*scale1
support[1]["max"]["x"]=support[1]["max"]["x"]*scale1
support[1]["max"]["y"]=support[1]["max"]["y"]*scale1
support[1]["max"]["z"]=support[1]["max"]["z"]*scale1
end
end
if haskey(setup,"loads")
loads = setup["loads"]
for load in loads
load[1]["min"]["x"]=load[1]["min"]["x"]*scale1
load[1]["min"]["y"]=load[1]["min"]["y"]*scale1
load[1]["min"]["z"]=load[1]["min"]["z"]*scale1
load[1]["max"]["x"]=load[1]["max"]["x"]*scale1
load[1]["max"]["y"]=load[1]["max"]["y"]*scale1
load[1]["max"]["z"]=load[1]["max"]["z"]*scale1
end
end
if haskey(setup,"materials")
materials = setup["materials"]
for material in materials
material[1]["min"]["x"]=material[1]["min"]["x"]*scale1
material[1]["min"]["y"]=material[1]["min"]["y"]*scale1
material[1]["min"]["z"]=material[1]["min"]["z"]*scale1
material[1]["max"]["x"]=material[1]["max"]["x"]*scale1
material[1]["max"]["y"]=material[1]["max"]["y"]*scale1
material[1]["max"]["z"]=material[1]["max"]["z"]*scale1
end
end
if haskey(setup,"fixedDisplacements")
disps = setup["fixedDisplacements"]
for disp in disps
disp[1]["min"]["x"]=disp[1]["min"]["x"]*scale1
disp[1]["min"]["y"]=disp[1]["min"]["y"]*scale1
disp[1]["min"]["z"]=disp[1]["min"]["z"]*scale1
disp[1]["max"]["x"]=disp[1]["max"]["x"]*scale1
disp[1]["max"]["y"]=disp[1]["max"]["y"]*scale1
disp[1]["max"]["z"]=disp[1]["max"]["z"]*scale1
end
end
i=1
for node in nodes
node["posTimeSteps"]=[]
node["angTimeSteps"]=[]
# node["degrees_of_freedom"]=""
if !haskey(setup,"multiscale") || node["parent"]==""
node["position"]["x"]= (N_position[i].x)*scale
node["position"]["y"]= (N_position[i].y)*scale
node["position"]["z"]= (N_position[i].z)*scale
node["displacement"]["x"]= N_displacement[i].x*scale
node["displacement"]["y"]= N_displacement[i].y*scale
node["displacement"]["z"]= N_displacement[i].z*scale
node["angle"]["x"]= N_angle[i].x
node["angle"]["y"]= N_angle[i].y
node["angle"]["z"]= N_angle[i].z
else
# node["position"]["x"]= node["position"]["x"]*scale
# node["position"]["y"]= node["position"]["y"]*scale
# node["position"]["z"]= node["position"]["z"]*scale
Amira Abdel-Rahman
committed
# println(node["parent"])
# println("parent: $(node["parent"]), id: $(node["id"]), scale: $(node["scale"])" )
parent=parse(Int,node["parent"][2:end])+1
Amira Abdel-Rahman
committed
index=parse(Int,node["id"][2:end])
# relPos=Vector3(node["position"]["x"]/scale/2,node["position"]["y"]/scale/2,node["position"]["z"]/scale/2)
Amira Abdel-Rahman
committed
relPos=getRelativePosition(index,setup["voxelSize"]/scale/2.0)
displacementss=Vector3(convert(Float64,N_displacement[parent].x),convert(Float64,N_displacement[parent].y),convert(Float64,N_displacement[parent].z))
angless=Vector3(convert(Float64,N_angle[parent].x),convert(Float64,N_angle[parent].y),convert(Float64,N_angle[parent].z))
displacementss=displacementss+applyQuaternion1(relPos,setQuaternionFromEuler1(angless))
node["displacement"]["x"]= displacementss.x*scale
node["displacement"]["y"]= displacementss.y*scale
node["displacement"]["z"]= displacementss.z*scale
node["angle"]["x"]= angless.x
node["angle"]["y"]= angless.y
node["angle"]["z"]= angless.z
i=i+1
end
# pass data as a json string (how it shall be displayed in a file)
stringdata = JSON.json(setup)
# write the file with the stringdata variable information
open(fileName, "w") do f
write(f, stringdata)
end
end
####################utils#############################
function getSetup(fileName)
setup = Dict()
name=string("./json/$(fileName)",".json")
open(name, "r") do f
#global setup
dicttxt = String(read(f)) # file information to string
setup=JSON.parse(dicttxt) # parse and transform data
end
setup=setup["setup"]
setup["viz"]["colorMaps"]=""
return setup
end
function getSetupFullPath(path)
setup = Dict()
open(path, "r") do f
#global setup
dicttxt = String(read(f)) # file information to string
setup=JSON.parse(dicttxt) # parse and transform data
end
setup=setup["setup"]
setup["viz"]["colorMaps"]=""
return setup
end
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
function getSetup1(fileName)
setup = Dict()
# name=string("../json/setupTestUni$latticeSize",".json")
name=string("./json/$(fileName)",".json")
open(name, "r") do f
#global setup
dicttxt = String(read(f)) # file information to string
setup=JSON.parse(dicttxt) # parse and transform data
end
return setup
end
function getSetup1FullPath(path)
setup = Dict()
open(path, "r") do f
#global setup
dicttxt = String(read(f)) # file information to string
setup=JSON.parse(dicttxt) # parse and transform data
end
return setup
end
function exportJuliaSettingsUsingNode(setup,name)
#export prev. settings to json
fileName="./json/$(name)Init.json"
setup1=Dict()
setup1["setup"]=setup
stringdata = JSON.json(setup1)
open(fileName, "w") do f
write(f, stringdata)
end
#run node.js to draw the gerometry using rhino3dm
mycommand = `node app1.js $(name)`
run(mycommand)
end
function getFinalDisplacement(path,id,axis)
setupViz=getSetup1FullPath("$(path)0.json")
maxNumFiles=setupViz["maxNumFiles"]
setupVizLast=getSetup1FullPath("$(path)$(Int(maxNumFiles-1)).json");
nodes=setupVizLast["nodes"]
node=setupVizLast["nodes"][id]
dis=node["displacement"][axis]
for node in nodes
if (node["displacement"][axis]>dis)
dis=node["displacement"][axis]
end
end
return dis
end
#########################################