-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.cpp
executable file
·200 lines (171 loc) · 4.25 KB
/
global.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
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
/*
ver.03.03
file global.cpp
*/
#include "global.h"
using std::vector;
using std::cout;
using std::endl;
using std::setw;
using std::left;
using std::scientific;
//public
Global::Global(
const unsigned loadSteps,
const double tolerance_equivalence,
const unsigned max_iteration,
const unsigned interval,
bool symmetric
):
loadSteps(loadSteps),
tolerance_equivalence(tolerance_equivalence),
max_iteration(max_iteration),
interval(interval),
symmetric(symmetric),
prepost(NULL),
K(NULL)
{
K=new Default_sparse(symmetric);
}
Global::~Global(){
if(prepost)
delete prepost;
prepost=NULL;
if(K)
delete K;
}
bool Global::solve(void){
using namespace ABFEM::MATH;
//issue12
extern int g_loadstep_cnt;
for(unsigned load_step=0;load_step<loadSteps;load_step++){
//issue12
g_loadstep_cnt=load_step+1;
#ifdef SHORT
cout << "\r\x1b[K";
#endif
cout << "load step:" << load_step << "/" << loadSteps << endl;
int iteration_cnt=0;
double tol;
update_loadstep();
update_iteration();
int debug_cnt=0;
do{
#ifdef SHORT
cout << "\x1b[K";
#endif
cout << "iteration:" << iteration_cnt << endl;
iteration();
tol=Rminus.Norm2()/(T.Norm2()+F.Norm2());
#ifdef SHORT
cout << "\x1b[K";
#endif
cout << "tolerance:" << left << scientific << setw(16) << sqrt(tol) << endl;
if(
isnan(tol) || isinf(tol) || tol<0.0 ||
iteration_cnt++==max_iteration
){
cout << endl << "####didn't converge" << endl;
if(((load_step)%(loadSteps/interval)))
prepost->post_process(load_step-1);
return false;
}
#ifdef SHORT
cout << "\x1b[2A\r";
#endif
cout.flush();
//prepost->post_process(debug_cnt++);
}while(tol>SQR(tolerance_equivalence));
after_iteration(load_step);
#ifdef SHORT
cout << "\x1b[2A\r";
#endif
cout << "####" << iteration_cnt << " iterations" << endl;
}
#ifdef SHORT
cout << "\x1b[4B";
#endif
return true;
}
//protected
void Global::after_preprocess(void){
find_matrix_size();
for(unsigned int i=0;i<velements.size();i++)
velements[i]->initialize();
//global vectors, matrices
for(int i=0;i<num_dof_dirichlet+num_dof_nond;i++)
vdof[i]->u=0.0;
T.Renew(num_row+num_dof_dirichlet,1);
F.Renew(num_row+num_dof_dirichlet,1);
Rminus.Renew(num_row,1);
K->initialize(num_row);
ABFEM::Progress progress(velements.size());
cout << "initializing sparse matrix..." << endl;
for(unsigned int i=0;i<velements.size();i++){
progress.display(i);
velements[i]->initialize_sparse(*K);
}
cout << "...done" << endl << endl;
}
void Global::update_loadstep(void){
for(vector<Dof*>::iterator it=vdof.begin();it!=vdof.end();it++){
(*it)->X=(*it)->x;
(*it)->u=0;
}
for(int i=0;i<num_dof_dirichlet;i++){
vdof[i]->x+=vdof[i]->dirichlet/(double)loadSteps;
vdof[i]->u=vdof[i]->dirichlet/(double)loadSteps;
}
for(unsigned i=0;i<velements.size();i++)
velements[i]->update_loadstep();
}
void Global::update_iteration(void){
#ifdef __INTEL_COMPILER
#pragma omp parallel for
#endif
for(unsigned int i=0;i<velements.size();i++)
velements[i]->update_iteration();
findT();
}
void Global::after_iteration(unsigned load_step){
prepost->save_result(load_step);
if(!((load_step+1)%(loadSteps/interval)) || !load_step)
prepost->post_process(load_step);
}
void Global::allocate_K(void){
K->allocate();
for(unsigned int i=0;i<velements.size();i++)
velements[i]->sync_Kmatrix(*K);
}
void Global::findK(void){
K->zeroOut();
for(unsigned int i=0;i<velements.size();i++){
velements[i]->calcK(*K);
}
}
//private
void Global::iteration(void){
findK();
calculate();
update_iteration();
}
void Global::findT(void){
T.ZeroOut();
for(unsigned int i=0;i<velements.size();i++){
velements[i]->calcT(T);
}
}
void Global::calculate(void){
for(unsigned i=0;i<num_row;i++)
Rminus(i,0)=F(i+num_dof_dirichlet,0)-T(i+num_dof_dirichlet,0);
double* delta_u=new double[num_row];
//issue6
#ifdef __MKL_PARDISO_H
K->solve(Rminus.GetData(),delta_u);
#endif
affect_solution(delta_u);
delete[] delta_u;
}
//for(int i=0;i<num_comp_all;i++){
//cout << left << setw(8) << vcinfo[i]->X << "\t" << vcinfo[i]->x << endl;
//}