-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffusiveCurrent.cpp
More file actions
154 lines (139 loc) · 5.39 KB
/
Copy pathDiffusiveCurrent.cpp
File metadata and controls
154 lines (139 loc) · 5.39 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
#include<iostream>
#include<cstdlib>
#include "DiffusiveCurrent.hpp"
#include "GeometricEntities.hpp"
#include "LocalMatrices.hpp"
#include "CSROperators.hpp"
#include "Chrono.hpp"
#include "ProxyFunctions.hpp"
DiffusiveCurrent::DiffusiveCurrent()
:_ptrmesh(NULL),
_data(NULL),
_ptrIdiff(NULL),
_ptrVmn(NULL)
{
_condmatrix.clear(1);
}
DiffusiveCurrent::~DiffusiveCurrent()
{
clear();
}
void DiffusiveCurrent::clear()
{
_condmatrix.clear(1);
_ptrmesh = NULL;
_data = NULL;
_ptrIdiff=NULL;
_ptrVmn=NULL;
}
void DiffusiveCurrent::initialize()
{
if( (_ptrmesh != NULL) && (_data != NULL) )
{
Chrono chrono;
chrono.start();
// Mesh connectivity does not furnishes connections of the point with itself, hence flag to true
_condmatrix.initialize_matrix(_ptrmesh->pointConnectivity(), true);
CSRMatrix massmatrix;
massmatrix.duplicate(_condmatrix);
//now I assemble
LocalMatrices locmat(_ptrmesh,_data);
switch(_ptrmesh->spacedim_GeoEle())
{
case 1:
{
for(size_t iEdg=0; iEdg<_ptrmesh->num_Edges(); iEdg++)
{
const Element & Ele=_ptrmesh->Edg(iEdg);
std::vector<double> locstiff=locmat.aniso_local_stiffness(Ele, Ele, Ele.QuadRule(0));
std::vector<double> locmass=locmat.local_mass(Ele, Ele, Ele.QuadRule(1));
assemble(Ele, locstiff, _condmatrix);
assemble(Ele, locmass, massmatrix);
}
break;
}
case 2:
{
for(size_t iTria=0; iTria<_ptrmesh->num_Trias(); iTria++)
{
const Element & Ele=_ptrmesh->Tri(iTria);
std::vector<double> locstiff=locmat.aniso_local_stiffness(Ele, Ele, Ele.QuadRule(0));
std::vector<double> locmass=locmat.local_mass(Ele, Ele, Ele.QuadRule(1));
assemble(Ele, locstiff, _condmatrix);
assemble(Ele, locmass, massmatrix);
}
for(size_t iQuad=0; iQuad<_ptrmesh->num_Quads(); iQuad++)
{
const Element & Ele=_ptrmesh->Quad(iQuad);
std::vector<double> locstiff=locmat.aniso_local_stiffness(Ele, Ele, Ele.QuadRule(1));
std::vector<double> locmass=locmat.local_mass(Ele, Ele, Ele.QuadRule(1));
assemble(Ele, locstiff, _condmatrix);
assemble(Ele, locmass, massmatrix);
}
break;
}
case 3:
{
for(size_t iTetra=0; iTetra<_ptrmesh->num_Tetras(); iTetra++)
{
const Element & Ele=_ptrmesh->Tet(iTetra);
std::vector<double> locstiff=locmat.aniso_local_stiffness(Ele, Ele, Ele.QuadRule(0));
std::vector<double> locmass=locmat.local_mass(Ele, Ele, Ele.QuadRule(1));
assemble(Ele, locstiff, _condmatrix);
assemble(Ele, locmass, massmatrix);
}
for(size_t iHexa=0; iHexa<_ptrmesh->num_Hexas(); iHexa++)
{
const Element & Ele=_ptrmesh->Hex(iHexa);
std::vector<double> locstiff=locmat.aniso_local_stiffness(Ele, Ele, Ele.QuadRule(1));
std::vector<double> locmass=locmat.local_mass(Ele, Ele, Ele.QuadRule(1));
assemble(Ele, locstiff, _condmatrix);
assemble(Ele, locmass, massmatrix);
}
break;
}
default:
{
std::cerr<<"ERROR: UNKNOWN GEOMETRIC ELEMENT DIMENSION"<<std::endl;
exit(1);
break;
}
}
std::vector<double> mlumped=lumping(massmatrix);
// Now divide by Mlumped
alphInvMlumpAij(_condmatrix, mlumped, -1.0 );
chrono.stop();
std::cout<<"diffusive current operator evaluated in "<<chrono<<std::endl;
}
else
{
std::cerr<<"ERROR: DATA AND/OR MESH ARE NOT INITIALIZED"<<std::endl;
exit(1);
}
}
void DiffusiveCurrent::compute()
{
matrixVectorProd(_condmatrix, (*_ptrVmn), (*_ptrIdiff) );
}
// Private functions
void DiffusiveCurrent::assemble(const Element & VarEle, const std::vector<double> & lstif, CSRMatrix & globalmat)
{
for(short int irow=0; irow<VarEle.nbV();irow++)
{
globalmat.addEntry(VarEle.vertices(irow), VarEle.vertices(irow), lstif[RMIndex(irow,irow,VarEle.nbV())] );
for(short int jcol=irow+1; jcol<VarEle.nbV();jcol++)
{
globalmat.addEntry(VarEle.vertices(irow), VarEle.vertices(jcol), lstif[RMIndex(irow,jcol,VarEle.nbV())] );
globalmat.addEntry(VarEle.vertices(jcol), VarEle.vertices(irow), lstif[RMIndex(jcol,irow,VarEle.nbV())] );
}
}
}
std::vector<double> DiffusiveCurrent::lumping(const CSRMatrix & matrix_to_lump)
{
//it works only for square matrices.
// It multiplies the matrix by a vector made of 1 only. This corresponds to sum up a row
std::vector<double> mlumped(matrix_to_lump.nrows(),0.0);
std::vector<double> tmpRHS(matrix_to_lump.nrows(),1.0);
matrixVectorProd(matrix_to_lump, tmpRHS, mlumped );
return(mlumped);
}