G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsINSPrecondBlocks.hpp
Go to the documentation of this file.
1
12#pragma once
13
15
16namespace gismo
17{
18
19template <class T>
21{
22 if (m_opt.getSwitch("iter"))
23 {
24 return new typename gsSparseSolver<T>::BiCGSTABILUT;
25 }
26 else
27 {
28 #ifdef GISMO_WITH_PARDISO
29 return new typename gsSparseSolver<T>::PardisoLU;
30 #else
31 return new typename gsSparseSolver<T>::LU;
32 #endif
33 }
34}
35
36
37template <class T>
39{
40 if (m_opt.getSwitch("iter"))
41 {
42 typename gsSparseSolver<T>::BiCGSTABILUT* pSolver = dynamic_cast<typename gsSparseSolver<T>::BiCGSTABILUT*>(&solver);
43
44 pSolver->preconditioner().setDroptol(m_opt.getReal("dropTol"));
45 pSolver->preconditioner().setFillfactor(m_opt.getInt("fill"));
46 pSolver->setMaxIterations(m_opt.getInt("maxIt"));
47 pSolver->setTolerance(m_opt.getReal("tol"));
48 }
49 else
50 {
51 #ifdef GISMO_WITH_PARDISO
52 typename gsSparseSolver<T>::PardisoLU* pSolver = dynamic_cast<typename gsSparseSolver<T>::PardisoLU*>(&solver);
53 pardisoSetup<T>(*pSolver);
54 #endif
55 }
56}
57
58
59template <class T, int MatOrder>
61{
62 GISMO_ASSERT(input.rows() == m_size, "Wrong input size.");
63 x.resize(m_size, 1);
64
65 int udofs = m_opt.getInt("udofs");
66 for (int i = 0; i < m_opt.getInt("dim"); i++)
67 x.middleRows(i*udofs, udofs) = m_pSolver->solve(input.middleRows(i*udofs, udofs));
68}
69
70
71template <class T, int MatOrder>
73{
74 GISMO_ASSERT(input.rows() == m_size, "Wrong input size.");
75 x.resize(m_size, 1);
76
77 x = m_pSolver->solve(input);
78}
79
80
81template <class T, int MatOrder>
83{
84 GISMO_ASSERT(input.rows() == m_size, "Wrong input size.");
85 x.resize(m_size, 1);
86
87 int udofs = m_opt.getInt("udofs");
88
89 // solving system with lower block-triangular part of Agamma
90 for (int i = 0; i < m_opt.getInt("dim"); i++)
91 x.middleRows(i*udofs, udofs) = m_solvers[i]->solve(input.middleRows(i*udofs, udofs));
92
93}
94
95
96template <class T, int MatOrder>
98{
99 GISMO_ASSERT(input.rows() == m_size, "Wrong input size.");
100 x.resize(m_size, 1);
101
102 int udofs = m_opt.getInt("udofs");
103
104 // solving system with lower block-triangular part of Agamma
105 for (int i = 0; i < m_opt.getInt("dim"); i++)
106 {
107 gsMatrix<T> rhsi = input.middleRows(i*udofs, udofs);
108
109 for (int j = 0; j < i; j++)
110 rhsi -= m_matRef.block(i*udofs, j*udofs, udofs, udofs) * x.middleRows(j*udofs, udofs);
111
112 x.middleRows(i*udofs, udofs) = m_solvers[i]->solve(rhsi);
113 }
114}
115
116
117template <class T, int MatOrder>
118void gsINSPrecondBlockBt<T, MatOrder>::apply(const gsMatrix<T> & input, gsMatrix<T> & x) const
119{
120 GISMO_ASSERT(input.rows() == this->cols(), "Wrong input size.");
121 x.resize(this->rows(), 1);
122
123 x.noalias() = m_mat * input;
124}
125
126
127template <class T, int MatOrder>
128void gsINSPrecondSchurLSC<T, MatOrder>::apply(const gsMatrix<T>& input, gsMatrix<T>& x) const
129{
130 GISMO_ASSERT(input.rows() == this->rows(), "Wrong input size.");
131 x.resize(this->rows(), 1);
132
133 // solve -(mat1 * mat2^-1 * mat1) * x = input
134 gsMatrix<T> tmp;
135 tmp = m_pSolver->solve(-1 * input); // mat1 * tmp = -input, where tmp = mat2^-1 * mat1 * x
136 x = m_pSolver->solve(m_mat2 * tmp); // mat1 * x = mat2 * tmp
137}
138
139
140template <class T, int MatOrder>
141void gsINSPrecondSchurPCD<T, MatOrder>::apply(const gsMatrix<T>& input, gsMatrix<T>& x) const
142{
143 GISMO_ASSERT(input.rows() == this->rows(), "Wrong input size.");
144 x.resize(this->rows(), 1);
145
146 // solve - Ap * Fp^-1 * Mp * x = input
147 gsMatrix<T> tmp1, tmp2;
148 tmp1 = m_pSolver->solve(-1 * input); // Ap * y = - input
149 tmp2 = m_matFp * tmp1; // z = Fp * y
150 x = m_pMassSolver->solve(tmp2); // Mp * x = z
151}
152
153
154template <class T, int MatOrder>
155void gsINSPrecondSchurPCDmod<T, MatOrder>::apply(const gsMatrix<T>& input, gsMatrix<T>& x) const
156{
157 GISMO_ASSERT(input.rows() == this->rows(), "Wrong input size.");
158 x.resize(this->rows(), 1);
159
160 // solve - Mp * Fp^-1 * Ap * x = input
161 gsMatrix<T> tmp1, tmp2;
162 tmp1 = m_pMassSolver->solve(-1 * input); // Mp * y = - input
163 tmp2 = m_matFp * tmp1; // z = Fp * y
164 x = m_pSolver->solve(tmp2); // Ap * x = z
165}
166
167} // namespace gismo
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
Apply the block. Computes the vector \fx = F^{-1} y\f.
Definition gsINSPrecondBlocks.hpp:60
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
Apply the block. Computes the vector \fx = F^{-1} y\f.
Definition gsINSPrecondBlocks.hpp:82
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
Apply the block. Computes the vector \fx = F^{-1} y\f.
Definition gsINSPrecondBlocks.hpp:97
void apply(const gsMatrix< T > &input, gsMatrix< T > &x) const
Apply the block. Computes the vector \fx = F^{-1} y\f.
Definition gsINSPrecondBlocks.hpp:72
void setupLinSolver(gsSparseSolver< T > &solver)
Set up the linear solver for the block.
Definition gsINSPrecondBlocks.hpp:38
gsSparseSolver< T > * createLinSolver()
Returns a pointer to new linear solver (direct or iterative).
Definition gsINSPrecondBlocks.hpp:20
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Abstract class for solvers. The solver interface is base on 3 methods: -compute set the system matrix...
Definition gsSparseSolver.h:67
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
The G+Smo namespace, containing all definitions for the library.