Newer
Older
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// Amira Abdel-Rahman
// (c) Massachusetts Institute of Technology 2020
///////////call from node app.js code///////////////
// wait for the rhino3dm web assembly to load asynchronously
// rhino3dm().then(function(m) {// todo change call to app.js
// _rhino3dm = m; // global
// initRhino3dm(1,10,createVoxel,true,true);
// saveJSON();
// });
/////////////////////////////////////
var three; //todo change location
var three1; //todo change location
var setup=JSON.parse(JSON.stringify(setupEmpty));
var setup1=JSON.parse(JSON.stringify(setupEmpty));
var globalSetup={
exaggeration:0.5,
speed:3.0,
updateStress:false
};
// var ex=gui.add(globalSetup, 'exaggeration', 0, 10e4).listen();
// var sp=gui.add(globalSetup, 'speed', 0, 5).listen();
// var sp=gui.add(globalSetup, 'updateStress').listen();
var static=true;
var latticeSize=15;
var voxelSize=5.0;
// ex.onChange(updateExSpeed);
// sp.onChange();
rhino3dm().then(async m => {
console.log('Loaded rhino3dm.');
// document.getElementById("footer2").innerHTML = "Loaded rhino3dm.";
_rhino3dm = m; // global
var material={
area:2.38*2.38,
density:0.028,
stiffness:4000
};
var material2={
area:1.0,
density:0.028,
stiffness:2000
};
setup.hierarchical=false;
setup.voxelSize=voxelSize;
const position=new THREE.Vector3(0,0,0);
const position2=new THREE.Vector3(voxelSize*2,0,0);
///
//try bounding box conditions
var support=new _rhino3dm.BoundingBox([-voxelSize/2+position.x,-voxelSize/2+position.y,-voxelSize/2+position.z], [voxelSize/2+position.x,voxelSize/2+position.y,voxelSize/2+position.z]);
var temp=voxelSize*5-voxelSize;
// var load=new _rhino3dm.BoundingBox([-voxelSize/2+position.x,-voxelSize/2+position.y,temp-voxelSize/2+position.z], [voxelSize/2+position.x,voxelSize/2+position.y,temp+voxelSize/2+position.z]);
var load=new _rhino3dm.BoundingBox([-voxelSize/2+position.x,
-voxelSize/2+position.y+voxelSize/4,
temp+position.z+voxelSize/4],
[voxelSize/2+position.x-voxelSize/4,
voxelSize/2+position.y-voxelSize/4,
temp+voxelSize/2+position.z]);
var load1=new _rhino3dm.BoundingBox([voxelSize/2+position.x,
-voxelSize/2+position.y+voxelSize/4,
temp+position.z+voxelSize/4],
[voxelSize/2+position.x+voxelSize/4,
voxelSize/2+position.y-voxelSize/4,
temp+voxelSize/2+position.z]);
// var temp1=voxelSize*10-voxelSize;
// var load1=new _rhino3dm.BoundingBox([voxelSize/2+position.x,
// -voxelSize/2+position.y+voxelSize/4,
// temp1+position.z+voxelSize/4],
// [voxelSize/2+position.x+voxelSize/4,
// voxelSize/2+position.y-voxelSize/4,
// temp1+voxelSize/2+position.z]);
// var load1_1=new _rhino3dm.BoundingBox([-voxelSize/2+position.x,
// -voxelSize/2+position.y+voxelSize/4,
// temp1+position.z+voxelSize/4],
// [voxelSize/2+position.x-voxelSize/4,
// voxelSize/2+position.y-voxelSize/4,
// temp1+voxelSize/2+position.z]);
// var temp2=voxelSize*latticeSize-voxelSize;
// var load2=new _rhino3dm.BoundingBox([-voxelSize/2+position.x,
// -voxelSize/2+position.y+voxelSize/4,
// temp2+position.z+voxelSize/4],
// [voxelSize/2+position.x-voxelSize/4,
// voxelSize/2+position.y-voxelSize/4,
// temp2+voxelSize/2+position.z]);
// var load2_1=new _rhino3dm.BoundingBox([voxelSize/2+position.x,
// -voxelSize/2+position.y+voxelSize/4,
// temp2+position.z+voxelSize/4],
// [voxelSize/2+position.x+voxelSize/4,
// voxelSize/2+position.y-voxelSize/4,
// temp2+voxelSize/2+position.z]);
var dof=[true,true,true,true,true,true];
var supports=[[support,dof]];
var loads=[[load,{x:0.0,y:0,z:-0.1}],[load1,{x:0.0,y:0,z:-0.1}]];
// var loads=[[load,{x:0.0,y:0,z:-1.0}],[load1,{x:0.0,y:0,z:-1.0}],[load2,{x:0.0,y:0,z:-1.0}],[load_1,{x:0.0,y:0,z:-2.0}],[load1_1,{x:0.0,y:0,z:-2.0}],[load2_1,{x:0.0,y:0,z:-2.0}]];
// var loads=[[load,{x:0.0,y:0,z:-1.0}],[load_1,{x:0.0,y:0,z:-2.0}]];
// var diffMaterialBox=[[matB,material2]];
///
lateralLoadSetup(setup,position,latticeSize,voxelSize,createVoxel,supports,loads,material);
// changeMaterialFromBox(setup,diffMaterialBox);
// setup.viz.colorMaps=[YlGnBu,coolwarm, winter ,jet];
setup.viz.minStress=10e6;
setup.viz.maxStress=-10e6;
setup.viz.exaggeration=0.5;
// setup.viz.exaggeration=globalSetup.exaggeration;
// setup.solve=solveParallel;
// setup.numTimeSteps=100;
// setup.supports=supports;
// setup.loads=loads;
// three= new threejs(setup,"webgl1","graph",static);
// three.init();
// three.drawConstraintBoundingBoxes([support],[load]);
////////////////////////////////////
setup1.hierarchical=true;
setup1.voxelSize=voxelSize;
lateralLoadSetup(setup1,position,latticeSize,voxelSize,createHieraricalVoxel,supports,loads,material);
// changeMaterialFromBox(setup1,diffMaterialBox);
setup1.viz.colorMaps=[YlGnBu,coolwarm, winter ,jet];
setup1.viz.minStress=10e6;
setup1.viz.maxStress=-10e6;
// setup1.viz.exaggeration=globalSetup.exaggeration;
setup1.solve=solveParallel;
setup1.supports=supports;
setup1.loads=loads;
setup.supports=[
[{
min:[
support.min[0],
support.min[1],
support.min[2]
],
max:[
support.max[0],
support.max[1],
support.max[2]
]
}]
];
setup.loads=[
[{
min:[
load.min[0],
load.min[1],
load.min[2]
],
max:[
load.max[0],
load.max[1],
load.max[2]
]
}],
[{
min:[
load1.min[0],
load1.min[1],
load1.min[2]
],
max:[
load1.max[0],
load1.max[1],
load1.max[2]
]
}]
];
saveJSON()
// three1= new threejs(setup1,"webgl","threejs",static);
// three1.init();
// gui.add(three.setup,"numTimeSteps", 0, 500).listen();
// gui.add(three.setup,"solve");
// document.getElementById("footer2").innerHTML = "Press solve for structure simulation.";
// more stuff
});
function solveParallel(){
document.getElementById("footer2").innerHTML = "Running...";
var numTimeSteps=250;
/////////////////////////////////////////////////////
var dt=0.0251646; //?? todo change to recommended step
var dt=0.01; //?? todo change to recommended step
setTimeout(function() {
simulateParallel( setup,three.setup.numTimeSteps,dt,static,2);
simulateParallel(setup1,three.setup.numTimeSteps,dt,static,2);
}, 1);
// var dt=0.0251646; //?? todo change to recommended step
// simulateParallel(setup1,numTimeSteps,dt);
///////////////////////////////////////
// updateColors();
// three.animate();
// three1.animate();
/////////////////////
}
function updateExSpeed(){
three.setup.animation.exaggeration=globalSetup.exaggeration;
three1.setup.animation.exaggeration=globalSetup.exaggeration;
three.setup.animation.speed=globalSetup.speed;
three1.setup.animation.speed=globalSetup.speed;
}
function getForce(x,t){
var a0=10000.0;
var l=1.0 ;
var f=2.0;
var amp=0.1;
var x=parseInt(x/voxelSize)/10.0;
var t=t/100.0;
var ax=1-0.825*(x-1)+1.0625*(x*x-1);
return a0* ax *Math.sin(2*Math.PI*(x/l-f*t+amp));
}