-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analysis.cpp
155 lines (130 loc) · 4.17 KB
/
Analysis.cpp
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
#include "Analysis.h"
#include "Matrix.h"
#include "OutfileWriter.h"
#include "Solvers.h"
Analysis::Analysis() :TS(TableStorage::getInstance()), EM(ErrorManager::getInstance())
{
stiffness = NULL;
force = NULL;
displacement = NULL;
// Set max problem DOF here -- we start with only one
npdofs = 1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Analysis::~Analysis()
{
if (stiffness != NULL)
delete stiffness;
if (force != NULL)
delete force;
if (displacement != NULL)
delete displacement;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//*************************************************************************************************
int Analysis::SolveStatic(OutfileWriter* wr)
{
int error = 0;
int ntotaldofs = npdofs * TS.NumGrid();
error = BuildGlobalStiffness(wr);
if (error > 0)
return error;
error = ModifyStiffnessForConstraints();
std::string h2(" Stiffnes Matrix");
wr->WriteMatrix(h2.c_str(), stiffness->getDataPtr(), stiffness->getNrows(), stiffness->getNcols());
error = CreateForceVector();
displacement = new Matrix(ntotaldofs, 1);
Solvers* solver = new Solvers();
solver->GauseSolve(stiffness->data, force->data, displacement->data, ntotaldofs);
std::cout << " displacements" << std::endl;
for (int i = 0; i < ntotaldofs; i++) {
std::cout << " " << displacement->data[i] << std::endl;
}
wr->WriteDisplacementReport(displacement->data, displacement->getNrows());
return error;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Analysis::BuildGlobalStiffness(OutfileWriter* wr)
{
//OutfileWriter* wr = new OutfileWriter();
int error = 0;
double AEL; // AE/L
Element e1;
PBAR p1;
MAT1 m1;
int nld = 2; // dimension of local stiffness matrix
int size = nld * nld;
double ElK[4];
int ng = TS.NumGrid();
std::string h1(" Element Matrix");
//std::string h2(" Stiffnes Matrix");
stiffness = new Matrix(ng, ng);
int nel = TS.NumElement();
for (int i = 0; i < nel; i++) {
e1 = TS.getElement(i);
BuildElementStiffness(&e1, ElK);
//wr->WriteMatrix(h1.c_str(),ElK, 2, 2);
error += stiffness->AddVal(e1.intgrida, e1.intgrida, ElK[0]);
error += stiffness->AddVal(e1.intgrida, e1.intgridb, ElK[1]);
error += stiffness->AddVal(e1.intgridb, e1.intgrida, ElK[2]);
error += stiffness->AddVal(e1.intgridb, e1.intgridb, ElK[3]);
}
//wr->WriteMatrix(h2.c_str(), stiffness->getDataPtr(), stiffness->getNrows(),stiffness->getNcols());
return error;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Analysis::BuildElementStiffness(Element* pe1, double* els)
{
PBAR p1;
MAT1 m1;
int nld = 2; // dimension of local stiffness matrix
double AEL;
int error = 0;
int indx = pe1->intpid;
p1 = TS.getProperty(indx);
indx = p1.intmid;
m1 = TS.getMaterial(indx);
AEL = p1.area * m1.e / pe1->length; // Use AE/L
els[0] = AEL;
els[1] = -AEL;
els[2] = -AEL;
els[3] = AEL;
return error;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Analysis::ModifyStiffnessForConstraints()
{
int error = 0;
int ng = TS.NumGrid();
int ndof;
for (int i = 0; i < ng; i++) {
Grid g = TS.getGrid(i);
if (g.constraints[0]) {
ndof = (i * npdofs);
stiffness->ClearRow(ndof);
stiffness->ClearCol(ndof);
stiffness->AddVal(ndof, ndof, 1.0);
}
}
return error;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int Analysis::CreateForceVector()
{
int error = 0;
force = new Matrix(npdofs * TS.NumGrid(), 1); // column vector
int nf = TS.NumForces();
int idof;
Force f;
for (int i = 0; i < nf; i++) {
f = TS.getForce(i);
idof = f.intgid * npdofs;
force->AddVal(idof, 0, f.fm[0]);
if (npdofs > 1)
force->AddVal(idof+1, 1, f.fm[1]); // Y directon
if (npdofs > 2)
force->AddVal(idof + 2, 1, f.fm[3]); // Z -- direction
//Note: no moments yet
}
return error;
}