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/ionicSolver.hpp" |
21 |
|
|
|
22 |
|
|
namespace felisce { |
23 |
|
✗ |
IonicSolver::IonicSolver(FelisceTransient::Pointer fstransient): |
24 |
|
✗ |
m_size(0), |
25 |
|
✗ |
m_fstransient(fstransient), |
26 |
|
✗ |
m_nComp(1), |
27 |
|
✗ |
m_stabInit(false) { |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
|
31 |
|
✗ |
IonicSolver::~IonicSolver() { |
32 |
|
✗ |
m_uExtrap.destroy(); |
33 |
|
✗ |
m_ion.destroy(); |
34 |
|
✗ |
if (FelisceParam::instance().stateFilter &&m_stabInit ) { |
35 |
|
✗ |
m_stabTerm.destroy(); |
36 |
|
✗ |
m_stabInit=false; |
37 |
|
|
} |
38 |
|
✗ |
if (m_nComp>1) { |
39 |
|
✗ |
for (std::size_t i=0; i<m_nComp; i++) { |
40 |
|
✗ |
m_vecRHS[i].destroy(); |
41 |
|
✗ |
m_vecSolEDO[i].destroy(); |
42 |
|
|
} |
43 |
|
|
} else { //nComp==1 |
44 |
|
✗ |
m_RHS.destroy(); |
45 |
|
✗ |
m_solEDO.destroy(); |
46 |
|
|
} |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
|
50 |
|
✗ |
void IonicSolver::defineOrderBdf(int order, int nComp) { |
51 |
|
✗ |
m_bdf.defineOrder(order, nComp); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
//Size of equation not necessarily V_0 size. |
55 |
|
✗ |
void IonicSolver::defineSizeAndMappingOfIonicProblem(felInt size, ISLocalToGlobalMapping& mapping, AO ao) { |
56 |
|
✗ |
m_size = size; |
57 |
|
✗ |
m_localDofToGlobalDof = mapping; |
58 |
|
✗ |
m_ao = ao; |
59 |
|
|
//Print the mapping. |
60 |
|
|
//ISLocalToGlobalMappingView(m_localDofToGlobalDof, PETSC_VIEWER_STDOUT_WORLD); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
✗ |
void IonicSolver::initializeExtrap(PetscVector& V_0) { |
66 |
|
|
//Initialize u_extrapolate. |
67 |
|
✗ |
m_uExtrap.duplicateFrom(V_0); |
68 |
|
✗ |
m_uExtrap.copyFrom(V_0); |
69 |
|
|
|
70 |
|
✗ |
if (m_nComp ==1) { |
71 |
|
|
//Initialize m_RHS of Schaf EDO. |
72 |
|
✗ |
m_RHS.duplicateFrom(V_0); |
73 |
|
✗ |
m_RHS.set(0.); |
74 |
|
|
|
75 |
|
|
//Initialize solution of Schaf EDO. |
76 |
|
✗ |
m_solEDO.duplicateFrom(V_0); |
77 |
|
✗ |
m_solEDO.set(0.); |
78 |
|
|
|
79 |
|
|
} else { |
80 |
|
✗ |
m_vecRHS.resize(m_nComp);//for Vec: MV, Paci |
81 |
|
✗ |
m_vecSolEDO.resize(m_nComp); |
82 |
|
|
|
83 |
|
|
//Initialize m_RHS of Schaf EDO. |
84 |
|
✗ |
for (std::size_t i=0; i<m_nComp; i++) { |
85 |
|
✗ |
m_vecRHS[i].duplicateFrom(V_0); |
86 |
|
✗ |
m_vecRHS[i].set(0.); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
//Initialize solution of Schaf EDO. |
90 |
|
✗ |
for (std::size_t i=0; i<m_nComp; i++) { |
91 |
|
✗ |
m_vecSolEDO[i].duplicateFrom(V_0); |
92 |
|
✗ |
m_vecSolEDO[i].set(0.); |
93 |
|
|
} |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
//Initialize value of ionic current m_ion |
97 |
|
✗ |
m_ion.duplicateFrom(V_0); |
98 |
|
✗ |
m_ion.set(0.); |
99 |
|
|
|
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
//Initialize solution of Schaf EDO in case of bdf order == 1. |
103 |
|
✗ |
void IonicSolver::initialize(PetscVector& sol_0) { |
104 |
|
✗ |
m_bdf.initialize(sol_0); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
✗ |
void IonicSolver::initialize(std::vector<PetscVector>& sol_0) { |
108 |
|
✗ |
if (m_nComp ==1) { |
109 |
|
✗ |
m_bdf.initialize(sol_0[0]); |
110 |
|
|
} else { |
111 |
|
✗ |
m_bdf.initialize(sol_0); |
112 |
|
|
|
113 |
|
|
} |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
//Initialize solution of Schaf EDO in case of bdf order == 2. |
117 |
|
✗ |
void IonicSolver::initialize(PetscVector& sol_0, PetscVector& sol_1) { |
118 |
|
✗ |
m_bdf.initialize(sol_0,sol_1); |
119 |
|
|
} |
120 |
|
|
|
121 |
|
✗ |
void IonicSolver::initialize(std::vector<PetscVector>& sol_0, std::vector<PetscVector>& sol_1) { |
122 |
|
✗ |
if (m_nComp == 1) { |
123 |
|
✗ |
m_bdf.initialize(sol_0[0],sol_1[0]); |
124 |
|
|
} else { |
125 |
|
✗ |
m_bdf.initialize(sol_0,sol_1); |
126 |
|
|
} |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
//Initialize solution of Schaf EDO in case of bdf order == 3. |
130 |
|
✗ |
void IonicSolver::initialize(PetscVector& sol_0, PetscVector& sol_1, PetscVector& sol_2) { |
131 |
|
✗ |
m_bdf.initialize(sol_0,sol_1,sol_2); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
✗ |
void IonicSolver::initialize(std::vector<PetscVector>& sol_0, std::vector<PetscVector>& sol_1, std::vector<PetscVector>& sol_2) { |
135 |
|
✗ |
if (m_nComp == 1) { |
136 |
|
✗ |
m_bdf.initialize(sol_0[0],sol_1[0],sol_2[0]); |
137 |
|
|
} else { |
138 |
|
✗ |
m_bdf.initialize(sol_0,sol_1,sol_2); |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
|
142 |
|
✗ |
void IonicSolver::updateBdf() { |
143 |
|
✗ |
if (m_nComp ==1) { |
144 |
|
✗ |
m_bdf.update(m_solEDO); |
145 |
|
|
} else { |
146 |
|
✗ |
m_bdf.update(m_vecSolEDO); |
147 |
|
|
} |
148 |
|
|
} |
149 |
|
|
|
150 |
|
✗ |
void IonicSolver::update(PetscVector& V_1) { |
151 |
|
✗ |
m_uExtrap.copyFrom(V_1); |
152 |
|
|
} |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|