G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsFlowLinSystSolver.hpp
Go to the documentation of this file.
1
12#pragma once
14
15namespace gismo
16{
17
18template<class T, int MatOrder>
20{
21
22#ifdef GISMO_WITH_PETSC
23 if (m_paramsRef.options().getSwitch("parallel"))
24 {
25 MPI_Barrier(PETSC_COMM_WORLD);
26 return MPI_Wtime();
27 }
28 else
29#endif
30 m_clock.restart();
31
32 return 0.0;
33}
34
35
36template<class T, int MatOrder>
38{
39
40#ifdef GISMO_WITH_PETSC
41 if (m_paramsRef.options().getSwitch("parallel"))
42 {
43 MPI_Barrier(PETSC_COMM_WORLD);
44 return MPI_Wtime();
45 }
46 else
47#endif
48 return m_clock.stop();
49
50}
51
52
53template<class T, int MatOrder>
54void gsFlowLinSystSolver<T, MatOrder>::applySolver(const gsSparseMatrix<T, MatOrder>& mat, const gsMatrix<T>& rhs, gsMatrix<T>& solution, real_t alpha_u, real_t alpha_p, index_t usize, index_t pdofs)
55{
56 GISMO_ASSERT(solution.rows() > 0, "The solution in applySolver() is empty!");
57
58 gsMatrix<T> newSol;
59 this->applySolver(mat, rhs, newSol);
60
61 real_t time0 = stopwatchStart();
62 solution.topRows(usize) = alpha_u * newSol.topRows(usize) + (1 - alpha_u)*solution.topRows(usize);
63 solution.bottomRows(pdofs) = alpha_p * newSol.bottomRows(pdofs) + (1 - alpha_p)*solution.bottomRows(pdofs);
64 real_t time1 = stopwatchStop();
65
66 m_solveT += time1 - time0;
67}
68
69
70// ===================================================================================================================
71// ===================================================================================================================
72
73
74template<class T, int MatOrder>
76{
77 real_t time0 = stopwatchStart();
78 m_solver.analyzePattern(mat);
79 real_t time1 = stopwatchStop();
81 m_setupT += time1 - time0;
82}
83
84
85template<class T, int MatOrder>
87{
88 real_t time0 = stopwatchStart();
89 m_solver.factorize(mat);
90
91 real_t time1 = stopwatchStop();
92
93 solution = m_solver.solve(rhs);
94 real_t time2 = stopwatchStop();
95
96 m_setupT += time1 - time0;
97 m_solveT += time2 - time1;
98}
99
100// ===================================================================================================================
101
102template<class T, int MatOrder, class SolverType>
104{
105 real_t time0 = stopwatchStart();
107 real_t time1 = stopwatchStop();
108
109 m_setupT += time1 - time0;
110}
111
112template<class T, int MatOrder, class SolverType>
114{
115 real_t time0 = stopwatchStart();
116
117 this->setupPreconditioner(mat);
118
119 SolverType solver(mat, m_precPtr);
120 solver.setMaxIterations(m_paramsRef.options().getInt("lin.maxIt"));
121 solver.setTolerance(m_paramsRef.options().getReal("lin.tol"));
122
123 real_t time1 = stopwatchStop();
124
125 solver.solve(rhs, solution);
126
127 real_t time2 = stopwatchStop();
128
129 m_setupT += time1 - time0;
130 m_solveT += time2 - time1;
131
132 m_linIterVector.push_back(solver.iterations());
133}
134
135// ===================================================================================================================
136
137template<class T, int MatOrder, class SolverType>
139{
140 real_t time0 = stopwatchStart();
141
142 m_matrices.clear();
143 m_matrices.insert(std::make_pair("matNS", mat));
144 m_matrices.insert(std::make_pair("matMu", m_assemblerPtr->getMassMatrix(0)));
145 m_matrices.insert(std::make_pair("matMp", m_assemblerPtr->getMassMatrix(1)));
146
147 if (m_precType.substr(0, 3) == "PCD")
148 {
149 gsWarn << "PCD preconditioner not fully implemented yet, using LSC instead.";
150 m_precType.replace(0, 3, "LSC");
151
152 // gsSparseMatrix<T> Ap, Fp;
153 // m_assemblerPtr->fillPCDblocks(Ap, Fp, m_precOpt.getInt("pcd_bcType"), m_precOpt.getSwitch("pcd_assembAp"), m_precOpt.getSwitch("pcd_assembFp"), m_precOpt.getSwitch("lumpingM"));
154 // m_matrices.insert(std::make_pair("matFp", Fp));
155 // m_matrices.insert(std::make_pair("matAp", Ap));
156 }
157
158 m_precPtr = gsINSPreconditioner<T, MatOrder>::make(m_precType, m_matrices, m_precOpt);
159
160 real_t time1 = stopwatchStop();
161
162 m_setupT += time1 - time0;
163}
164
165
166}
virtual void applySolver(const gsSparseMatrix< T, MatOrder > &mat, const gsMatrix< T > &rhs, gsMatrix< T > &solution)
Solve the linear system.
Definition gsFlowLinSystSolver.hpp:86
virtual void setupSolver(const gsSparseMatrix< T, MatOrder > &mat)
Setup the linear solver for a given matrix.
Definition gsFlowLinSystSolver.hpp:75
virtual void setupPreconditioner(const gsSparseMatrix< T, MatOrder > &mat)
Setup the preconditioner for a given matrix.
Definition gsFlowLinSystSolver.hpp:138
virtual void setupPreconditioner(const gsSparseMatrix< T, MatOrder > &mat)
Setup the preconditioner for a given matrix.
Definition gsFlowLinSystSolver.hpp:103
virtual void applySolver(const gsSparseMatrix< T, MatOrder > &mat, const gsMatrix< T > &rhs, gsMatrix< T > &solution)
Solve the linear system.
Definition gsFlowLinSystSolver.hpp:113
virtual void applySolver(const gsSparseMatrix< T, MatOrder > &mat, const gsMatrix< T > &rhs, gsMatrix< T > &solution)
Solve the linear system.
Definition gsFlowLinSystSolver.h:69
T stopwatchStop()
Stop measuring time (decides whether to use gsStopwatch or MPI_Wtime)
Definition gsFlowLinSystSolver.hpp:37
T stopwatchStart()
Start measuring time (decides whether to use gsStopwatch or MPI_Wtime)
Definition gsFlowLinSystSolver.hpp:19
Gauss-Seidel preconditioner.
Definition gsSimplePreconditioners.h:279
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Sparse matrix class, based on gsEigen::SparseMatrix.
Definition gsSparseMatrix.h:139
@ symmetric
one total step is = one forward + one backward
Definition gsSimplePreconditioners.h:268
#define gsWarn
Definition gsDebug.h:50
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
The G+Smo namespace, containing all definitions for the library.