Line |
Branch |
Exec |
Source |
1 |
|
|
// ______ ______ _ _ _____ ______ |
2 |
|
|
// | ____| ____| | (_)/ ____| | ____| |
3 |
|
|
// | |__ | |__ | | _| (___ ___| |__ |
4 |
|
|
// | __| | __| | | | |\___ \ / __| __| |
5 |
|
|
// | | | |____| |____| |____) | (__| |____ |
6 |
|
|
// |_| |______|______|_|_____/ \___|______| |
7 |
|
|
// Finite Elements for Life Sciences and Engineering |
8 |
|
|
// |
9 |
|
|
// License: LGL2.1 License |
10 |
|
|
// FELiScE default license: LICENSE in root folder |
11 |
|
|
// |
12 |
|
|
// Main authors: E. Schenone C. Corrado |
13 |
|
|
// |
14 |
|
|
|
15 |
|
|
// System includes |
16 |
|
|
|
17 |
|
|
// External includes |
18 |
|
|
|
19 |
|
|
// Project includes |
20 |
|
|
#include "Solver/linearProblemBidomainExtraCell.hpp" |
21 |
|
|
#include "Core/felisceTransient.hpp" |
22 |
|
|
#include "FiniteElement/elementMatrix.hpp" |
23 |
|
|
#include "InputOutput/io.hpp" |
24 |
|
|
|
25 |
|
|
namespace felisce { |
26 |
|
✗ |
LinearProblemBidomainExtraCell::LinearProblemBidomainExtraCell(): |
27 |
|
|
LinearProblem("Problem cardiac Bidomain second equation",2), |
28 |
|
✗ |
m_fePotExtraCell(nullptr), |
29 |
|
✗ |
m_fePotExtraCellCurv(nullptr), |
30 |
|
✗ |
m_sortedSol(nullptr), |
31 |
|
✗ |
m_fiber(nullptr), |
32 |
|
✗ |
m_angleFiber(nullptr), |
33 |
|
✗ |
m_endocardiumDistance(nullptr) |
34 |
|
|
{} |
35 |
|
|
|
36 |
|
✗ |
LinearProblemBidomainExtraCell::~LinearProblemBidomainExtraCell() { |
37 |
|
✗ |
m_fstransient = nullptr; |
38 |
|
✗ |
m_fePotExtraCell = nullptr; |
39 |
|
✗ |
m_fePotExtraCellCurv = nullptr; |
40 |
|
✗ |
if (m_fiber) |
41 |
|
✗ |
delete [] m_fiber; |
42 |
|
✗ |
if (m_angleFiber) |
43 |
|
✗ |
delete [] m_angleFiber; |
44 |
|
✗ |
if (m_endocardiumDistance) |
45 |
|
✗ |
delete [] m_endocardiumDistance; |
46 |
|
✗ |
delete [] m_sortedSol; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
✗ |
void LinearProblemBidomainExtraCell::initialize(std::vector<GeometricMeshRegion::Pointer>& mesh, FelisceTransient::Pointer fstransient, MPI_Comm& comm, bool doUseSNES) { |
50 |
|
✗ |
LinearProblem::initialize(mesh,comm, doUseSNES); |
51 |
|
✗ |
m_fstransient = fstransient; |
52 |
|
✗ |
std::vector<PhysicalVariable> listVariable(1); |
53 |
|
✗ |
std::vector<std::size_t> listNumComp(1); |
54 |
|
✗ |
listVariable[0] = potExtraCell; |
55 |
|
✗ |
listNumComp[0] = 1; |
56 |
|
|
//define unknown of the linear system. |
57 |
|
✗ |
m_listUnknown.push_back(potExtraCell); |
58 |
|
✗ |
definePhysicalVariable(listVariable,listNumComp); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
✗ |
void LinearProblemBidomainExtraCell::readData(IO& io) { |
62 |
|
|
// Read fibers file (*.00000.vct) |
63 |
|
✗ |
m_fiber = new double[m_mesh[m_currentMesh]->numPoints()*3]; |
64 |
|
✗ |
io.readVariable(0, 0.,m_fiber, m_mesh[m_currentMesh]->numPoints()*3); |
65 |
|
✗ |
if (FelisceParam::instance().hasCoupledAtriaVent) { |
66 |
|
✗ |
m_angleFiber = new double[m_numDof]; |
67 |
|
✗ |
io.readVariable(2, 0.,m_angleFiber, m_numDof); |
68 |
|
|
} |
69 |
|
|
} |
70 |
|
|
|
71 |
|
✗ |
void LinearProblemBidomainExtraCell::getFiberDirection(felInt iel, int iUnknown, std::vector<double>& elemFiber) { |
72 |
|
✗ |
int numSupport = static_cast<int>(supportDofUnknown(iUnknown).iEle()[iel+1] - supportDofUnknown(iUnknown).iEle()[iel]); |
73 |
|
✗ |
elemFiber.resize( numSupport*3,0.); |
74 |
|
✗ |
for (int i = 0; i < numSupport; i++) { |
75 |
|
✗ |
elemFiber[i*3] = m_fiber[3*(supportDofUnknown(iUnknown).iSupportDof()[supportDofUnknown(iUnknown).iEle()[iel]+i])]; |
76 |
|
✗ |
elemFiber[i*3+1] = m_fiber[3*(supportDofUnknown(iUnknown).iSupportDof()[supportDofUnknown(iUnknown).iEle()[iel]+i])+1]; |
77 |
|
✗ |
elemFiber[i*3+2] = m_fiber[3*(supportDofUnknown(iUnknown).iSupportDof()[supportDofUnknown(iUnknown).iEle()[iel]+i])+2]; |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
|
81 |
|
✗ |
void LinearProblemBidomainExtraCell::getAngleFiber(felInt iel, int iUnknown, std::vector<double>& elemAngle) { |
82 |
|
✗ |
int numSupport = static_cast<int>(supportDofUnknown(iUnknown).iEle()[iel+1] - supportDofUnknown(iUnknown).iEle()[iel]); |
83 |
|
✗ |
elemAngle.resize(numSupport,0.); |
84 |
|
✗ |
for (int i = 0; i < numSupport; i++) { |
85 |
|
✗ |
elemAngle[i] = m_angleFiber[(supportDofUnknown(iUnknown).iSupportDof()[supportDofUnknown(iUnknown).iEle()[iel]+i])]; |
86 |
|
|
} |
87 |
|
|
} |
88 |
|
|
|
89 |
|
✗ |
void LinearProblemBidomainExtraCell::initPerElementType(ElementType eltType, FlagMatrixRHS flagMatrixRHS) { |
90 |
|
|
IGNORE_UNUSED_FLAG_MATRIX_RHS; |
91 |
|
|
IGNORE_UNUSED_ELT_TYPE; |
92 |
|
|
//Init pointer on Finite Element, Variable or idVariable |
93 |
|
|
// m_ipotTransMemb = m_listVariable.getVariableIdList(potTransMemb); |
94 |
|
✗ |
m_ipotExtraCell = m_listVariable.getVariableIdList(potExtraCell); |
95 |
|
|
// m_fePotTransMemb = m_listCurrentFiniteElement[m_ipotTransMemb]; |
96 |
|
✗ |
m_fePotExtraCell = m_listCurrentFiniteElement[m_ipotExtraCell]; |
97 |
|
|
|
98 |
|
|
} |
99 |
|
|
|
100 |
|
✗ |
void LinearProblemBidomainExtraCell::computeElementArray(const std::vector<Point*>& elemPoint, const std::vector<felInt>& elemIdPoint, felInt& iel, FlagMatrixRHS flagMatrixRHS) { |
101 |
|
|
IGNORE_UNUSED_ELEM_ID_POINT; |
102 |
|
|
IGNORE_UNUSED_FLAG_MATRIX_RHS; |
103 |
|
|
|
104 |
|
✗ |
m_fePotExtraCell->updateFirstDeriv(0, elemPoint); |
105 |
|
✗ |
std::vector<double> elemFiber; |
106 |
|
✗ |
getFiberDirection(iel,m_ipotExtraCell, elemFiber); |
107 |
|
|
|
108 |
|
|
|
109 |
|
✗ |
double eps = 1.0e-6; |
110 |
|
✗ |
m_elementMat[0]->phi_i_phi_j(eps,*m_fePotExtraCell,0,0,1); |
111 |
|
|
|
112 |
|
|
//2nd equation : (\sigma_i^t+\sigma_e^t)) \grad u_e |
113 |
|
✗ |
m_elementMat[0]->grad_phi_i_grad_phi_j(FelisceParam::instance().intraTransvTensor+FelisceParam::instance().extraTransvTensor,*m_fePotExtraCell,0,0,1); |
114 |
|
|
|
115 |
|
|
//2nd equation : ((\sigma_i^l-\sigma_i^t)+(\sigma_e^l-\sigma_e^t)) a vec a \grad u_e |
116 |
|
✗ |
m_elementMat[0]->tau_grad_phi_i_tau_grad_phi_j((FelisceParam::instance().intraFiberTensor-FelisceParam::instance().intraTransvTensor)+(FelisceParam::instance().extraFiberTensor-FelisceParam::instance().extraTransvTensor),elemFiber,*m_fePotExtraCell,0,0,1); |
117 |
|
|
|
118 |
|
|
//2nd equation RHS : -(\sigma_i^t) \grad V_m |
119 |
|
✗ |
m_elementMat[1]->grad_phi_i_grad_phi_j(-1.*(FelisceParam::instance().intraTransvTensor),*m_fePotExtraCell,0,0,1); |
120 |
|
|
|
121 |
|
|
//2nd equation RHS : -(\sigma_i^l-\sigma_i^t) a vec a \grad V_m |
122 |
|
✗ |
m_elementMat[1]->tau_grad_phi_i_tau_grad_phi_j(-1.*(FelisceParam::instance().intraFiberTensor-FelisceParam::instance().intraTransvTensor),elemFiber,*m_fePotExtraCell,0,0,1); |
123 |
|
|
|
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
|
127 |
|
✗ |
void LinearProblemBidomainExtraCell::computeElementArrayBoundaryCondition(const std::vector<Point*>& elemPoint, const std::vector<felInt>& elemIdPoint, felInt& iel, FlagMatrixRHS flagMatrixRHS) { |
128 |
|
|
(void) elemIdPoint; |
129 |
|
|
(void) flagMatrixRHS; |
130 |
|
✗ |
m_ipotExtraCell = m_listVariable.getVariableIdList(potExtraCell); |
131 |
|
✗ |
m_fePotExtraCellCurv = m_listCurvilinearFiniteElement[m_ipotExtraCell]; |
132 |
|
|
|
133 |
|
✗ |
m_fePotExtraCellCurv->updateMeasNormalContra(0, elemPoint); |
134 |
|
|
|
135 |
|
|
|
136 |
|
✗ |
if ((m_currentLabel >= 30) && (m_currentLabel <= 40)) { |
137 |
|
✗ |
std::vector<double> elemAngle; |
138 |
|
✗ |
getAngleFiber(iel,m_ipotExtraCell,elemAngle); |
139 |
|
|
|
140 |
|
✗ |
std::vector<double> elemFiber; |
141 |
|
✗ |
getFiberDirection(iel,m_ipotExtraCell,elemFiber); |
142 |
|
|
|
143 |
|
|
// Constant angle |
144 |
|
|
//double angle = acos(0.0)/2.0; |
145 |
|
|
|
146 |
|
|
|
147 |
|
|
//2nd equation : (\sigma_i^t+\sigma_e^t) \grad u_e |
148 |
|
✗ |
double eps = 1.0e-6; |
149 |
|
✗ |
m_elementMatBD[0]->phi_i_phi_j(eps,*m_fePotExtraCellCurv,0,0,1); |
150 |
|
|
|
151 |
|
✗ |
if (m_currentLabel < 40) { // regular atrial myocardium |
152 |
|
✗ |
m_elementMatBD[0]->grad_phi_i_grad_phi_j((FelisceParam::instance().intraTransvTensorAtria+FelisceParam::instance().extraTransvTensorAtria),*m_fePotExtraCellCurv,0,0,1); |
153 |
|
✗ |
m_elementMatBD[0]->tau_orthotau_grad_phi_i_grad_phi_j((FelisceParam::instance().intraFiberTensorAtria - FelisceParam::instance().intraTransvTensorAtria + FelisceParam::instance().extraFiberTensorAtria - FelisceParam::instance().extraTransvTensorAtria),elemFiber,elemAngle,*m_fePotExtraCellCurv,0,0,1); |
154 |
|
✗ |
} else if (m_currentLabel == 40) { // connexion aera |
155 |
|
✗ |
m_elementMatBD[0]->grad_phi_i_grad_phi_j((FelisceParam::instance().intraTransvTensorAtria+FelisceParam::instance().extraTransvTensorAtria)*0.005,*m_fePotExtraCellCurv,0,0,1); |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
|
159 |
|
|
//2nd equation RHS : -(\sigma_i^t) \grad V_m |
160 |
|
✗ |
if (m_currentLabel < 40) { // regular atrial myocardium |
161 |
|
✗ |
m_elementMatBD[1]->grad_phi_i_grad_phi_j(-1.0*(FelisceParam::instance().intraTransvTensorAtria),*m_fePotExtraCellCurv,0,0,1); |
162 |
|
✗ |
m_elementMatBD[1]->tau_orthotau_grad_phi_i_grad_phi_j(-1.0*(FelisceParam::instance().intraFiberTensorAtria - FelisceParam::instance().intraTransvTensorAtria),elemFiber,elemAngle,*m_fePotExtraCellCurv,0,0,1); |
163 |
|
✗ |
} else if (m_currentLabel == 40) { // connexion aera |
164 |
|
✗ |
m_elementMatBD[1]->grad_phi_i_grad_phi_j(-0.005*(FelisceParam::instance().intraTransvTensorAtria),*m_fePotExtraCellCurv,0,0,1); |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
} |
168 |
|
|
} |
169 |
|
|
|
170 |
|
✗ |
void LinearProblemBidomainExtraCell::addMatrixRHS() { |
171 |
|
|
// _RHS = _Ksigmai * _RHS |
172 |
|
✗ |
PetscVector tmpB; |
173 |
|
✗ |
tmpB.duplicateFrom(vector()); |
174 |
|
✗ |
tmpB.copyFrom(vector()); |
175 |
|
✗ |
mult(matrix(1),tmpB,vector()); |
176 |
|
✗ |
tmpB.destroy(); |
177 |
|
|
|
178 |
|
|
} |
179 |
|
|
|
180 |
|
|
} |
181 |
|
|
|