-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataModel.js
More file actions
119 lines (83 loc) · 1.92 KB
/
DataModel.js
File metadata and controls
119 lines (83 loc) · 1.92 KB
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
let FEM = require('./BeamElementFEA');
let Points = [ [ 200, 300 ], [ 600, 300 ], [ 400, 200 ] ];
let Connections = [[0,1, 20, 1],[0,2, 20, 1],[1,2, 20, 1]];
let Forces = [[0,1,0,"Fixed Y"],[0,1,0,"Fixed X"],[1,1,0,"Fixed Y"], [2,0,-2000,"Force"]];
let Results = {}
let removePoint = function(index){
Points.splice(index, 1)
update()
};
let subs = [];
let update = function(){
for(let C of Connections){
let p1 = Points[C[0]]
let p2 = Points[C[1]]
C[2] = (Math.atan2(p1[1]-p2[1],p1[0]-p2[0])+Math.PI) * 180 / Math.PI;
C[3] = Math.sqrt((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)
}
for(let sub of subs) sub(Points, Connections, Forces, Results);
}
let addSubscriber = function(call){
subs.push(call)
}
let getPoints = function(){
return Points;
}
let addPoint = function(point){
Points = [...Points, point]
Results = {}
update()
}
let movePoint = function(index, point){
for(let i in Points){
if(i == index) Points[i] = point;
}
Results = {}
update()
}
let addForce = function(node,x,y,type){
Forces.push([node, x,y,type]);
Results = {}
update();
}
let addConnection = function(node1, node2){
Connections.push([node1, node2, 'angle', 'length']);
Results = {}
update();
}
let clearForces = function(){
Forces = [];
Results = {}
update();
}
let clearConnections = function(){
Connections = [];
Results = {}
update();
}
let getConnections = function(){
return Connections;
}
let getForces = function(){
return Forces;
}
update()
let runFEM = function(E, I, A){
Results = FEM([...Points], [...Connections], [...Forces], E, I, A);
update()
return Results
}
module.exports = {
removePoint,
addSubscriber,
getPoints,
addPoint,
movePoint,
addConnection,
clearConnections,
getConnections,
addForce,
getForces,
runFEM,
clearForces
}