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: J Fouchet & C Bui |
13 |
|
|
// |
14 |
|
|
|
15 |
|
|
#ifndef _COEFPROBLEM_HPP |
16 |
|
|
#define _COEFPROBLEM_HPP |
17 |
|
|
|
18 |
|
|
// System includes |
19 |
|
|
#include <set> |
20 |
|
|
#include <unordered_map> |
21 |
|
|
#include <ostream> |
22 |
|
|
#include <vector> |
23 |
|
|
|
24 |
|
|
// External includes |
25 |
|
|
#include "Core/NoThirdPartyWarning/Petsc/mat.hpp" |
26 |
|
|
#include "Core/NoThirdPartyWarning/Petsc/vec.hpp" |
27 |
|
|
#include "Core/NoThirdPartyWarning/Petsc/pc.hpp" |
28 |
|
|
#include "Core/NoThirdPartyWarning/Petsc/ao.hpp" |
29 |
|
|
#include "Core/NoThirdPartyWarning/Petsc/ksp.hpp" |
30 |
|
|
#include "Core/NoThirdPartyWarning/Petsc/error.hpp" |
31 |
|
|
#include "Core/NoThirdPartyWarning/Mpi/mpi.hpp" |
32 |
|
|
|
33 |
|
|
// Project includes |
34 |
|
|
#include "PETScInterface/petscVector_fwd.hpp" |
35 |
|
|
#include "PETScInterface/petscMatrix.hpp" |
36 |
|
|
#include "Core/felisceParam.hpp" |
37 |
|
|
#include "InputOutput/io.hpp" |
38 |
|
|
#include "Core/chrono.hpp" |
39 |
|
|
#include "PETScInterface/KSPInterface.hpp" |
40 |
|
|
|
41 |
|
|
namespace felisce |
42 |
|
|
{ |
43 |
|
|
/*! |
44 |
|
|
\class CoefProblem |
45 |
|
|
\authors J Fouchet & C Bui |
46 |
|
|
\date 04/01/2013 |
47 |
|
|
\brief find the alpha_i coeficient. |
48 |
|
|
*/ |
49 |
|
|
|
50 |
|
|
class CoefProblem { |
51 |
|
|
public: |
52 |
|
|
|
53 |
|
|
// Constructor |
54 |
|
|
//============ |
55 |
|
|
CoefProblem(); |
56 |
|
|
virtual ~CoefProblem(); |
57 |
|
|
|
58 |
|
|
void initializeCoefProblem(MPI_Comm& comm); |
59 |
|
|
|
60 |
|
|
// Allocate Matrix and RHS |
61 |
|
|
//======================== |
62 |
|
|
void allocateMatrixRHS(int size, int rank); |
63 |
|
|
|
64 |
|
|
// Assemble Matrix and RHS |
65 |
|
|
//======================== |
66 |
|
|
void assembleMatrix(const int idInflowOutflowBC, const std::vector<double> m_fluxLinCombBC, int rank); |
67 |
|
|
void assembleRHS(const std::vector<double> pressure, const std::vector<double> m_fluxLinCombBC, const std::vector<double> m_fluxLinCombBCtotal, int rank); |
68 |
|
|
|
69 |
|
|
// Write |
70 |
|
|
//======== |
71 |
|
|
|
72 |
|
|
//Write in file matrix.m, matrix in matlab format. |
73 |
|
|
void writeMatrixForMatlab(int verbose = 0, std::ostream& outstr = std::cout) const; |
74 |
|
|
|
75 |
|
|
//Write in file RHS.m, RHS in matlab format. |
76 |
|
|
void writeRHSForMatlab(int verbose = 0, std::ostream& outstr = std::cout) const; |
77 |
|
|
|
78 |
|
|
void writeSolForMatlab(int verbose = 0, std::ostream& outstr = std::cout) const; |
79 |
|
|
|
80 |
|
|
//Write in file filename, matrix in matlab format. |
81 |
|
|
void writeMatrixForMatlab(std::string const& fileName, PetscMatrix& matrix) const; |
82 |
|
|
|
83 |
|
|
//Write in file filenam, std::vector in matlab format. |
84 |
|
|
void writeVectorForMatlab(std::string const& fileName, PetscVector& vector) const; |
85 |
|
|
|
86 |
|
|
// Print solution of the system solve. |
87 |
|
|
void printSolution(int verbose = 0, std::ostream& outstr = std::cout) const; |
88 |
|
|
|
89 |
|
|
//Solve linear system |
90 |
|
|
//=================== |
91 |
|
|
void buildSolver(); |
92 |
|
|
void solve(int rank, int size); |
93 |
|
|
|
94 |
|
|
// Access Functions |
95 |
|
|
//================= |
96 |
|
|
|
97 |
|
|
inline const PetscVector& solution() const { |
98 |
|
|
return m_sol; |
99 |
|
|
} |
100 |
|
✗ |
inline PetscVector& solution() { |
101 |
|
✗ |
return m_sol; |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
inline const PetscVector& RHS() const { |
105 |
|
|
return _RHS; |
106 |
|
|
} |
107 |
|
|
inline PetscVector& RHS() { |
108 |
|
|
return _RHS; |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
inline const PetscMatrix& Matrix() const { |
112 |
|
|
return m_Matrix; |
113 |
|
|
} |
114 |
|
|
inline PetscMatrix& Matrix() { |
115 |
|
|
return m_Matrix; |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
protected: |
119 |
|
|
|
120 |
|
|
int m_verbose; |
121 |
|
|
MPI_Comm m_petscComm; |
122 |
|
|
|
123 |
|
|
//! RHS of the system. |
124 |
|
|
PetscVector _RHS; |
125 |
|
|
|
126 |
|
|
//! solution of the problem. |
127 |
|
|
PetscVector m_sol; |
128 |
|
|
|
129 |
|
|
//! Matrix of the system. |
130 |
|
|
PetscMatrix m_Matrix; |
131 |
|
|
|
132 |
|
|
std::vector<double> timeStepOverC; |
133 |
|
|
std::vector<double> RplusTimeStepOverC; |
134 |
|
|
|
135 |
|
|
bool m_buildSolver; |
136 |
|
|
KSPInterface::Pointer m_ksp = felisce::make_shared<KSPInterface>(); |
137 |
|
|
}; |
138 |
|
|
|
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
#endif |
142 |
|
|
|