-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.h
More file actions
346 lines (332 loc) · 10.8 KB
/
node.h
File metadata and controls
346 lines (332 loc) · 10.8 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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#define TRUE 1
#define FALSE 0
struct Connection
{
public:
int tonode;
double factors[3]; //proportional, derivative and second derivative
};
class Node {
private:
bool *Fixed; //only boundary condition used in part 4
double *initialstate;
double *curstate, *paststate; //displacement or delta-charge, current and previous
double *selffactors;
int DegreesFreedom;
int conncount;
Connection *conn; //will hold which nodes are connected to each other
public:
void init(int,int); //this function will have the nodes either hard-coded or read from a CSV
void initProb4(int);
void UpdateDelta(double*);
double GetCurState(int);
double GetInitState(int);
double GetPosition(int);
bool isFixed();
bool isFixed(int);
int getconn();
int connto(int);
double get_2D_Distance(Node,int,int);
double getFrac(Node,int,int);
double getselffactor(int);
double getconnfactor(int,int);
void initProb3(int);
void gettransformation(Node,double**);
};
/***********************CLASS FUNCTIONS***********************************/
void Node::init(int index, int DoF)
{
DegreesFreedom = DoF;
curstate = new double[DoF];
paststate = new double[DoF];
initialstate = new double[DoF];
Fixed = new bool[DoF];
selffactors = new double[3]; //proportional, derivative and second derivative term
std::cout<< "Enter initial conditions for Node " << index << std::endl;
for(int i = 0;i<DegreesFreedom;i++)
{
std::cout << "Initial Value (ex. charge in circuit, position in mds system) for Degree " << (i+1) << ": ";
std::cin >> initialstate[i] ;
paststate[i] = 0;
curstate[i] = 0;
std::cout<<std::endl<<"Is this degree fixed (1 if true, 0 if false)?";
std::cin >> Fixed[i];
}
std::cout<<"Factor for self-referential proportional ";
std::cin>>selffactors[0];
std::cout<<"Factor for self-referential derivative ";
std::cin>>selffactors[1];
std::cout<<"Factor for self-referential 2nd derivative ";
std::cin>>selffactors[2];
std::cout<<"How many higher indexed nodes is this node connected to?"<<std::endl;
std::cin>>conncount;
conn = new Connection[conncount];
for(int i = 0;i<conncount;i++)
{
std::cout<<"Input node index for connection"<<(i+1)<<std::endl;
std::cin>>conn[i].tonode;
std::cout<<"Factor for coupled proportional ";
std::cin>>conn[i].factors[0];
std::cout<<"Factor for coupled derivative ";
std::cin>>conn[i].factors[1];
std::cout<<"Factor for coupled 2nd derivative ";
std::cin>>conn[i].factors[2];
}
std::cout<<std::endl;
}
void Node::initProb3(int index)
{
DegreesFreedom = 1;
curstate = new double[DegreesFreedom];
paststate = new double[DegreesFreedom];
initialstate = new double[DegreesFreedom];
Fixed = new bool[DegreesFreedom];
selffactors = new double[3];
selffactors[0] = 0;
selffactors[1] = 0;
curstate[0] = 0;
paststate[0] = 0;
switch (index)
{
case 0:
initialstate[0] = 80;
conn = new Connection[1];
conn[0].tonode = 1;
conn[0].factors[0] = 1000; //stiffness k = 100N/m
conn[0].factors[1] = 1200; //damping c = 1 Ns/m
conn[0].factors[2] = 0; //no coupled mass (whatever that is)
selffactors[2] = 0;
conncount = 1;
Fixed[0] = TRUE;
break;
case 1:
initialstate[0] = 60;
conn = new Connection[2];
conn[0].tonode = 2;
conn[1].tonode = 3;
conn[0].factors[0] = 1500; //stiffness k = 100N/m
conn[0].factors[1] = 1600; //damping c = 1 Ns/m
conn[0].factors[2] = 0;
conn[1].factors[0] = 2000; //stiffness k = 100N/m
conn[1].factors[1] = 1600; //damping c = 1 Ns/m
conn[1].factors[2] = 0;
selffactors[2] = 15;
conncount = 2;
Fixed[0] = FALSE;
break;
case 2:
initialstate[0] = 40;
conn = new Connection[1];
conn[0].tonode = 4;
conn[0].factors[0] = 1000; //stiffness k = 100N/m
conn[0].factors[1] = 0; //damping c = 1 Ns/m
conn[0].factors[2] = 0;
selffactors[2] = 10;
conncount = 1;
Fixed[0] = FALSE;
break;
case 3:
initialstate[0] = 40;
conn = new Connection[1];
conn[0].tonode = 4;
conn[0].factors[0] = 2000; //stiffness k = 100N/m
conn[0].factors[1] = 1600; //damping c = 1 Ns/m
conn[0].factors[2] = 0;
selffactors[2] = 0;
conncount = 1;
Fixed[0] = TRUE;
break;
case 4:
initialstate[0] = 20;
conn = new Connection[1];
conn[0].tonode = 2;
conn[0].factors[0] = 1200; //stiffness k = 100N/m
conn[0].factors[1] = 2500; //damping c = 1 Ns/m
conn[0].factors[2] = 0;
selffactors[2] = 10;
conncount = 1;
Fixed[0] = FALSE;
break;
case 5:
initialstate[0] = 0;
conn = new Connection[0];
selffactors[2] = 0;
conncount = 0;
Fixed[0] = TRUE;
break;
default:
break;
}
}
void Node::initProb4(int index)
{
DegreesFreedom = 2;
curstate = new double[DegreesFreedom];
paststate = new double[DegreesFreedom];
initialstate = new double[DegreesFreedom];
Fixed = new bool[DegreesFreedom];
selffactors = new double[3];
selffactors[0] = 0;
selffactors[1] = 0;
selffactors[2] = 1; //They are have a mass of 1kg
curstate[0] = 0;
curstate[1] = 0;
paststate[0] = 0;
paststate[0] = 0;
switch (index)
{
case 0:
initialstate[0] = -200;
initialstate[1] = 200;
conn = new Connection[1];
conn[0].tonode = 1;
conn[0].factors[0] = 100; //stiffness k = 100N/m
conn[0].factors[1] = 1; //damping c = 1 Ns/m
conn[0].factors[2] = 0; //no coupled mass (whatever that is)
conncount = 1;
Fixed[0] = TRUE;
Fixed[1] = TRUE;
break;
case 1:
initialstate[0] = -100;
initialstate[1] = 100;
conn = new Connection[1];
conn[0].tonode = 2;
conn[0].factors[0] = 100; //stiffness k = 100N/m
conn[0].factors[1] = 1; //damping c = 1 Ns/m
conn[0].factors[2] = 0;
conncount = 1;
Fixed[0] = FALSE;
Fixed[1] = FALSE;
break;
case 2:
initialstate[0] = 0;
initialstate[1] = 0;
conn = new Connection[2];
conn[0].tonode = 3;
conn[1].tonode = 5;
conn[0].factors[0] = 100; //stiffness k = 100N/m
conn[0].factors[1] = 1; //damping c = 1 Ns/m
conn[0].factors[2] = 0;
conn[1].factors[0] = 100; //stiffness k = 100N/m
conn[1].factors[1] = 1; //damping c = 1 Ns/m
conn[1].factors[2] = 0;
conncount = 2;
Fixed[0] = FALSE;
Fixed[1] = FALSE;
break;
case 3:
initialstate[0] = -100;
initialstate[1] = -100;
conn = new Connection[1];
conn[0].tonode = 4;
conn[0].factors[0] = 100; //stiffness k = 100N/m
conn[0].factors[1] = 1; //damping c = 1 Ns/m
conn[0].factors[2] = 0;
conncount = 1;
Fixed[0] = FALSE;
Fixed[1] = FALSE;
break;
case 4:
initialstate[0] = -200;
initialstate[1] = -200;
conn = NULL;
conncount = 0;
Fixed[0] = TRUE;
Fixed[1] = TRUE;
break;
case 5:
initialstate[0] = 100;
initialstate[1] = 0;
conn = new Connection[1];
conn[0].tonode = 6;
conn[0].factors[0] = 100; //stiffness k = 100N/m
conn[0].factors[1] = 1; //damping c = 1 Ns/m
conn[0].factors[2] = 0; //no coupled mass (whatever that is)
conncount = 1;
Fixed[0] = FALSE;
Fixed[1] = FALSE;
break;
case 6:
initialstate[0] = 0;
initialstate[1] = 200;
conn = NULL;
conncount = 0;
Fixed[0] = FALSE;
Fixed[1] = FALSE;
break;
default:
break;
}
}
void Node:: UpdateDelta(double *newPos)
{
for(int i = 0;i<DegreesFreedom;i++)
{
paststate[i] = curstate[i]; //pos[][0] is the old displacement
curstate[i] = newPos[i];
}
return;
}
double Node::GetInitState(int index)
{
return initialstate[index];
}
double Node::GetCurState(int index)
{
return curstate[index];
}
double Node::GetPosition(int index)
{
return curstate[index]+initialstate[index];
}
bool Node::isFixed(int index)
{
return Fixed[index];
}
bool Node::isFixed()
{
bool temp = TRUE;
for(int i = 0;i<DegreesFreedom;i++)
{
temp = temp&Fixed[i];
}
return temp;
}
//to get distance if degrees describe physical orientation.
double Node::get_2D_Distance(Node other, int index1, int index2)
{
double sum;
sum = (((*this).GetPosition(index1))-(other.GetPosition(index1)))*(((*this).GetPosition(index1))-(other.GetPosition(index1)));
sum += (((*this).GetPosition(index2))-(other.GetPosition(index2)))*(((*this).GetPosition(index2))-(other.GetPosition(index2)));
return sqrt(sum);
}
//this gets the fraction that one degree affects another
//If the system being solved was 2-D. X and Y would be index
//0 and 1 respectively. Cos is delta-X over length.
//This would be specified by calling Node1.getFrac(Node2,0,1)
//In a similar manner, sin would be Node1.getFrac(Node2,1,0)
//main code needs to check degree of freedom to decide whether or not this
//function is necessary
double Node::getFrac(Node other, int index1, int index2)
{
double delta = other.GetPosition(index1)-(*this).GetPosition(index1);
double dis = (*this).get_2D_Distance(other,index1,index2);
return delta/dis;
}
int Node::getconn()
{
return conncount;
}
int Node::connto(int index)
{
return conn[index].tonode;
}
double Node:: getconnfactor(int index,int select)
{
return conn[index].factors[select];
}
double Node:: getselffactor(int index)
{
return selffactors[index];
}