G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsINSVisitors.hpp
Go to the documentation of this file.
1
12#pragma once
14
15namespace gismo
16{
17
18
19template <class T, int MatOrder>
20void gsINSVisitorUU<T, MatOrder>::localToGlobal(const std::vector<gsMatrix<T> >& eliminatedDofs, gsSparseMatrix<T, MatOrder>& globalMat, gsMatrix<T>& globalRhs)
21{
22 index_t dim = m_params.getPde().dim();
23 const index_t uCompSize = m_dofMappers[m_testUnkID].freeSize(); // number of dofs for one velocity component
24 index_t nComponents = globalMat.rows() / uCompSize;
25
26 GISMO_ASSERT(nComponents == 1 || nComponents == dim, "Wrong matrix size in gsINSVisitorUU::localToGlobal.");
27
28 m_dofMappers[m_testUnkID].localToGlobal(m_testFunActives, m_patchID, m_testFunActives);
29 m_dofMappers[m_shapeUnkID].localToGlobal(m_shapeFunActives, m_patchID, m_shapeFunActives);
30
31
32 index_t numActTest = m_testFunActives.rows();
33 index_t numActShape = m_shapeFunActives.rows();
34
35 for (index_t i = 0; i < numActTest; ++i)
36 {
37 const index_t ii = m_testFunActives(i);
38
39 if (m_dofMappers[m_testUnkID].is_free_index(ii))
40 {
41 for (index_t j = 0; j < numActShape; ++j)
42 {
43 const index_t jj = m_shapeFunActives(j);
44
45 if (m_dofMappers[m_shapeUnkID].is_free_index(jj))
46 {
47 for (index_t d = 0; d < nComponents; d++)
48 globalMat.coeffRef(ii + d*uCompSize, jj + d*uCompSize) += m_localMat(i, j);
49 }
50 else // is_boundary_index(jj)
51 {
52 const int bb = m_dofMappers[m_shapeUnkID].global_to_bindex(jj);
53
54 for (index_t d = 0; d < dim; d++)
55 globalRhs(ii + d*uCompSize, 0) -= m_localMat(i, j) * eliminatedDofs[m_shapeUnkID](bb, d);
56 }
57 }
58 }
59 }
60}
61
62// ===================================================================================================================
63
64template <class T, int MatOrder>
65void gsINSVisitorPU<T, MatOrder>::localToGlobal(const std::vector<gsMatrix<T> >& eliminatedDofs, gsSparseMatrix<T, MatOrder>& globalMat, gsMatrix<T>& globalRhs)
66{
67 index_t dim = m_params.getPde().dim();
68 const index_t uCompSize = m_dofMappers[m_testUnkID].freeSize(); // number of dofs for one velocity component
69
70 GISMO_ASSERT(globalMat.rows() == dim*uCompSize, "Wrong matrix size in gsINSVisitorPU::localToGlobal.");
71
72 m_dofMappers[m_testUnkID].localToGlobal(m_testFunActives, m_patchID, m_testFunActives);
73 m_dofMappers[m_shapeUnkID].localToGlobal(m_shapeFunActives, m_patchID, m_shapeFunActives);
74
75 index_t numActTest = m_testFunActives.rows();
76 index_t numActShape = m_shapeFunActives.rows();
77
78
79 for (index_t i = 0; i < numActTest; ++i)
80 {
81 const index_t ii = m_testFunActives(i);
82
83 if (m_dofMappers[m_testUnkID].is_free_index(ii))
84 {
85 for (index_t j = 0; j < numActShape; ++j)
86 {
87 const index_t jj = m_shapeFunActives(j);
88
89 if (m_dofMappers[m_shapeUnkID].is_free_index(jj))
90 {
91 for (index_t d = 0; d < dim; d++)
92 globalMat.coeffRef(ii + d*uCompSize, jj) += m_locMatVec[d](i, j);
93 }
94 else // is_boundary_index(jj)
95 {
96 const int bb = m_dofMappers[m_shapeUnkID].global_to_bindex(jj);
97
98 for (index_t d = 0; d < dim; d++)
99 globalRhs(ii + d*uCompSize, 0) -= m_locMatVec[d](i, j) * eliminatedDofs[m_shapeUnkID](bb, 0);
100 }
101 }
102 }
103 }
104}
105
106// ===================================================================================================================
107
108template <class T, int MatOrder>
109void gsINSVisitorPU_withUPrhs<T, MatOrder>::localToGlobal(const std::vector<gsMatrix<T> >& eliminatedDofs, gsSparseMatrix<T, MatOrder>& globalMat, gsMatrix<T>& globalRhs)
110{
111 index_t dim = m_params.getPde().dim();
112 const index_t uCompSize = m_dofMappers[m_testUnkID].freeSize(); // number of dofs for one velocity component
113
114 GISMO_ASSERT(globalMat.rows() == dim*uCompSize, "Wrong matrix size in gsINSVisitorPU::localToGlobal.");
115
116 m_dofMappers[m_testUnkID].localToGlobal(m_testFunActives, m_patchID, m_testFunActives);
117 m_dofMappers[m_shapeUnkID].localToGlobal(m_shapeFunActives, m_patchID, m_shapeFunActives);
118
119 index_t numActTest = m_testFunActives.rows();
120 index_t numActShape = m_shapeFunActives.rows();
121
122 for (index_t i = 0; i < numActTest; ++i)
123 {
124 const index_t ii = m_testFunActives(i);
125
126 if (m_dofMappers[m_testUnkID].is_free_index(ii))
127 {
128 for (index_t j = 0; j < numActShape; ++j)
129 {
130 const index_t jj = m_shapeFunActives(j);
131
132 if (m_dofMappers[m_shapeUnkID].is_free_index(jj))
133 {
134 for (index_t d = 0; d < dim; d++)
135 globalMat.coeffRef(ii + d*uCompSize, jj) += m_locMatVec[d](i, j);
136 }
137 else // is_boundary_index(jj)
138 {
139 const int bb = m_dofMappers[m_shapeUnkID].global_to_bindex(jj);
140
141 for (index_t d = 0; d < dim; d++)
142 globalRhs(ii + d*uCompSize, 0) -= m_locMatVec[d](i, j) * eliminatedDofs[m_shapeUnkID](bb, 0);
143 }
144 }
145 }
146 else // part arising from block B (assuming that the offdiag. blocks are symmetric)
147 {
148 const int bb = m_dofMappers[m_testUnkID].global_to_bindex(ii);
149 for (index_t k = 0; k < numActShape; k++)
150 {
151 const int kk = m_shapeFunActives(k);
152
153 if (m_dofMappers[m_shapeUnkID].is_free_index(kk))
154 {
155 T tmp = 0;
156
157 for (index_t d = 0; d < dim; d++)
158 tmp += m_locMatVec[d](i, k) * eliminatedDofs[m_testUnkID](bb, d);
159
160 globalRhs(dim*uCompSize + kk, 0) += tmp;
161 }
162 }
163 }
164 }
165}
166
167// ===================================================================================================================
168
169template <class T, int MatOrder>
170void gsINSVisitorUP<T, MatOrder>::localToGlobal(const std::vector<gsMatrix<T> >& eliminatedDofs, gsSparseMatrix<T, MatOrder>& globalMat, gsMatrix<T>& globalRhs)
171{
172 index_t dim = m_params.getPde().dim();
173 const index_t uCompSize = m_dofMappers[m_shapeUnkID].freeSize(); // number of dofs for one velocity component
174
175 GISMO_ASSERT(globalMat.cols() == dim*uCompSize, "Wrong matrix size in gsINSVisitorUP::localToGlobal.");
176
177 m_dofMappers[m_testUnkID].localToGlobal(m_testFunActives, m_patchID, m_testFunActives);
178 m_dofMappers[m_shapeUnkID].localToGlobal(m_shapeFunActives, m_patchID, m_shapeFunActives);
179
180 index_t numActTest = m_testFunActives.rows();
181 index_t numActShape = m_shapeFunActives.rows();
182
183 for (index_t i = 0; i < numActTest; ++i)
184 {
185 const index_t ii = m_testFunActives(i);
186
187 if (m_dofMappers[m_testUnkID].is_free_index(ii))
188 {
189 for (index_t j = 0; j < numActShape; ++j)
190 {
191 const index_t jj = m_shapeFunActives(j);
192
193 if (m_dofMappers[m_shapeUnkID].is_free_index(jj))
194 {
195 for (index_t d = 0; d < dim; d++)
196 globalMat.coeffRef(ii, jj + d*uCompSize) += m_locMatVec[d](i, j);
197 }
198 else // is_boundary_index(jj)
199 {
200 const int bb = m_dofMappers[m_shapeUnkID].global_to_bindex(jj);
201
202 T tmp = 0;
203
204 for (index_t d = 0; d < dim; d++)
205 tmp -= m_locMatVec[d](i, j) * eliminatedDofs[m_shapeUnkID](bb, d);
206
207 globalRhs(ii, 0) += tmp;
208 }
209 }
210 }
211 }
212}
213
214// ===================================================================================================================
215
216template <class T, int MatOrder>
217void gsINSVisitorPP<T, MatOrder>::localToGlobal(const std::vector<gsMatrix<T> >& eliminatedDofs, gsSparseMatrix<T, MatOrder>& globalMat, gsMatrix<T>& globalRhs)
218{
219 m_dofMappers[m_testUnkID].localToGlobal(m_testFunActives, m_patchID, m_testFunActives);
220 m_dofMappers[m_shapeUnkID].localToGlobal(m_shapeFunActives, m_patchID, m_shapeFunActives);
221
222 index_t numActTest = m_testFunActives.rows();
223 index_t numActShape = m_shapeFunActives.rows();
224
225 for (index_t i = 0; i < numActTest; ++i)
226 {
227 const int ii = m_testFunActives(i);
228
229 if (m_dofMappers[m_testUnkID].is_free_index(ii))
230 {
231 for (index_t j = 0; j < numActShape; ++j)
232 {
233 const int jj = m_shapeFunActives(j);
234
235 if (m_dofMappers[m_shapeUnkID].is_free_index(jj))
236 {
237 globalMat.coeffRef(ii, jj) += m_localMat(i, j);
238 }
239 else // is_boundary_index(jj)
240 {
241 const int bb = m_dofMappers[m_shapeUnkID].global_to_bindex(jj);
242
243 globalRhs(ii, 0) -= m_localMat(i, j) * eliminatedDofs[m_shapeUnkID](bb, 0);
244 }
245 }
246 }
247 }
248}
249
250// ===================================================================================================================
251
252template <class T, int MatOrder>
253void gsINSVisitorRhsU<T, MatOrder>::assemble()
254{
255 m_localMat.setZero(m_testFunActives.rows(), m_params.getPde().dim());
256
257 for (size_t i = 0; i < m_terms.size(); i++)
258 m_terms[i]->assemble(m_mapData, m_quWeights, m_testFunData, m_shapeFunData, m_localMat);
259}
260
261
262template <class T, int MatOrder>
263void gsINSVisitorRhsU<T, MatOrder>::localToGlobal(gsMatrix<T>& globalRhs)
264{
265 index_t dim = m_params.getPde().dim();
266 const index_t uCompSize = m_dofMappers[0].freeSize(); // number of dofs for one velocity component
267
268 m_dofMappers[m_testUnkID].localToGlobal(m_testFunActives, m_patchID, m_testFunActives);
269
270 index_t numActTest = m_testFunActives.rows();
271
272 for (index_t i = 0; i < numActTest; ++i)
273 {
274 const index_t ii = m_testFunActives(i);
275
276 if (m_dofMappers[m_testUnkID].is_free_index(ii))
277 {
278 for (index_t d = 0; d != dim; d++)
279 globalRhs(ii + d*uCompSize, 0) += m_localMat(i, d);
280 }
281 }
282}
283
284// ===================================================================================================================
285
286template <class T, int MatOrder>
287void gsINSVisitorRhsP<T, MatOrder>::assemble()
288{
289 m_localMat.setZero(m_testFunActives.rows(), 1);
290
291 for (size_t i = 0; i < m_terms.size(); i++)
292 m_terms[i]->assemble(m_mapData, m_quWeights, m_testFunData, m_shapeFunData, m_localMat);
293}
294
295
296template <class T, int MatOrder>
297void gsINSVisitorRhsP<T, MatOrder>::localToGlobal(gsMatrix<T>& globalRhs)
298{
299 index_t dim = m_params.getPde().dim();
300 const index_t uCompSize = m_dofMappers[0].freeSize(); // number of dofs for one velocity component
301
302 m_dofMappers[m_testUnkID].localToGlobal(m_testFunActives, m_patchID, m_testFunActives);
303
304 index_t numActTest = m_testFunActives.rows();
305
306 for (index_t i = 0; i < numActTest; ++i)
307 {
308 const index_t ii = m_testFunActives(i);
309
310 if (m_dofMappers[m_testUnkID].is_free_index(ii))
311 globalRhs(dim*uCompSize + ii, 0) += m_localMat(i);
312 }
313}
314
315} // namespace gismo
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
#define index_t
Definition gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
The G+Smo namespace, containing all definitions for the library.