-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTPZElastoPlasticIntPointsStructMatrix.cpp
195 lines (154 loc) · 5.75 KB
/
TPZElastoPlasticIntPointsStructMatrix.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
#include "TPZElastoPlasticIntPointsStructMatrix.h"
#include "pzintel.h"
#include "pzskylstrmatrix.h"
#include "pzmetis.h"
#include "TPZConstitutiveLawProcessor.h"
#include "TPZElasticCriterion.h"
#include "pzbndcond.h"
#include "Timer.h"
#ifdef USING_MKL
#include <mkl.h>
#endif
TPZElastoPlasticIntPointsStructMatrix::TPZElastoPlasticIntPointsStructMatrix(TPZCompMesh *cmesh) : TPZSymetricSpStructMatrix(cmesh), fSparseMatrixLinear(), fRhsLinear(), fIntegrator(), fBCMaterialIds() {
if (!cmesh->Reference()->Dimension()) {
DebugStop();
}
fDimension = cmesh->Reference()->Dimension();
#ifdef USING_CUDA
dRhsLinear.resize(0);
#endif
}
TPZElastoPlasticIntPointsStructMatrix::~TPZElastoPlasticIntPointsStructMatrix() {
}
TPZStructMatrix * TPZElastoPlasticIntPointsStructMatrix::Clone(){
return new TPZElastoPlasticIntPointsStructMatrix(*this);
}
TPZMatrix<STATE> * TPZElastoPlasticIntPointsStructMatrix::Create(){
if(!fIntegrator.isBuilt()) {
this->SetUpDataStructure(); // When basis functions are computed and stored
}
TPZStack<int64_t> elgraph;
TPZVec<int64_t> elgraphindex;
fMesh->ComputeElGraph(elgraph,elgraphindex,fMaterialIds);
TPZMatrix<STATE> * mat = SetupMatrixData(elgraph, elgraphindex);
TPZSYsmpMatrix<STATE> *stiff = dynamic_cast<TPZSYsmpMatrix<STATE> *> (mat);
fIntegrator.FillLIndexes(stiff->IA(), stiff->JA());
#ifdef USING_CUDA
Timer timer;
timer.TimeUnit(Timer::ESeconds);
timer.TimerOption(Timer::ECudaEvent);
timer.Start();
std::cout << "Transfering data to GPU..." << std::endl;
this->TransferDataToGPU();
timer.Stop();
std::cout << "Done! It took " << timer.ElapsedTime() << timer.Unit() << std::endl;
#endif
return mat;
}
#ifdef USING_CUDA
void TPZElastoPlasticIntPointsStructMatrix::TransferDataToGPU() {
fIntegrator.TransferDataToGPU();
dRhsLinear.resize(fRhsLinear.Rows());
dRhsLinear.set(&fRhsLinear(0,0), fRhsLinear.Rows());
}
#endif
TPZMatrix<STATE> *TPZElastoPlasticIntPointsStructMatrix::CreateAssemble(TPZFMatrix<STATE> &rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) {
int64_t neq = fMesh->NEquations();
TPZMatrix<STATE> *stiff = Create();
rhs.Redim(neq,1);
Assemble(*stiff,rhs,guiInterface);
return stiff;
}
void TPZElastoPlasticIntPointsStructMatrix::SetUpDataStructure() {
if(fIntegrator.isBuilt()) {
std::cout << __PRETTY_FUNCTION__ << " Data structure has been setup." << std::endl;
return;
}
ClassifyMaterialsByDimension();
TPZVec<int> element_indexes;
ComputeDomainElementIndexes(element_indexes);
fIntegrator.SetElementIndexes(element_indexes);
fIntegrator.SetUpIrregularBlocksData(fMesh);
fIntegrator.SetUpIndexes(fMesh);
fIntegrator.SetUpColoredIndexes(fMesh);
AssembleBoundaryData();
}
void TPZElastoPlasticIntPointsStructMatrix::Assemble(TPZMatrix<STATE> & mat, TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface) {
int neq = fMesh->NEquations();
rhs.Resize(neq, 1);
rhs.Zero();
TPZSYsmpMatrix<STATE> &stiff = dynamic_cast<TPZSYsmpMatrix<STATE> &> (mat);
TPZVec<STATE> &Kg = stiff.A();
#ifdef USING_CUDA
TPZVecGPU<REAL> d_Kg(Kg.size());
d_Kg.Zero();
TPZVecGPU<REAL> d_rhs(rhs.Rows());
d_rhs.Zero();
fIntegrator.KAssembly(fMesh->Solution(), d_Kg, d_rhs);
fCudaCalls.DaxpyOperation(neq, 1., dRhsLinear.getData(), d_rhs.getData());
// back to CPU
d_rhs.get(&rhs(0,0), neq);
d_Kg.get(&Kg[0], d_Kg.getSize());
#else
fIntegrator.KAssembly(fMesh->Solution(), Kg, rhs);
rhs += fRhsLinear;
#endif
// Add Klinear contribution
auto it_end = fSparseMatrixLinear.MapEnd();
for (auto it = fSparseMatrixLinear.MapBegin(); it!=it_end; it++) {
int64_t row = it->first.first;
int64_t col = it->first.second;
STATE val = it->second + stiff.GetVal(row, col);
stiff.PutVal(row, col, val);
}
}
void TPZElastoPlasticIntPointsStructMatrix::Assemble(TPZFMatrix<STATE> & rhs, TPZAutoPointer<TPZGuiInterface> guiInterface){
int neq = fMesh->NEquations();
rhs.Resize(neq, 1);
rhs.Zero();
#ifdef USING_CUDA
TPZVecGPU<REAL> d_rhs(rhs.Rows());
d_rhs.Zero();
fIntegrator.ResidualIntegration(fMesh->Solution(),d_rhs);
fCudaCalls.DaxpyOperation(neq, 1., dRhsLinear.getData(), d_rhs.getData());
d_rhs.get(&rhs(0,0), neq); //back to CPU
#else
fIntegrator.ResidualIntegration(fMesh->Solution(),rhs);
rhs += fRhsLinear;
#endif
}
void TPZElastoPlasticIntPointsStructMatrix::AssembleBoundaryData() {
int64_t neq = fMesh->NEquations();
TPZStructMatrix str(fMesh);
str.SetMaterialIds(fBCMaterialIds);
str.SetNumThreads(fNumThreads);
TPZAutoPointer<TPZGuiInterface> guiInterface;
fRhsLinear.Resize(neq, 1);
fRhsLinear.Zero();
fSparseMatrixLinear.Resize(neq, neq);
str.Assemble(fSparseMatrixLinear, fRhsLinear, guiInterface);
}
void TPZElastoPlasticIntPointsStructMatrix::ComputeDomainElementIndexes(TPZVec<int> &element_indexes) {
TPZStack<int> el_indexes_loc;
for (int64_t i = 0; i < fMesh->NElements(); i++) {
TPZCompEl *cel = fMesh->Element(i);
if (!cel) continue;
TPZGeoEl *gel = cel->Reference();
if (!gel) continue;
if(gel->Dimension() == fDimension){
el_indexes_loc.Push(cel->Index());
}
}
element_indexes = el_indexes_loc;
}
void TPZElastoPlasticIntPointsStructMatrix::ClassifyMaterialsByDimension() {
for (auto material : fMesh->MaterialVec()) {
TPZBndCond * bc_mat = dynamic_cast<TPZBndCond *>(material.second);
bool domain_material_Q = !bc_mat;
if (domain_material_Q) {
fMaterialIds.insert(material.first);
}else{
fBCMaterialIds.insert(material.first);
}
}
}