G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsINSAssembler.h
Go to the documentation of this file.
1
12#pragma once
13
14#include <gsCore/gsField.h>
18
19namespace gismo
20{
21
25template<class T, int MatOrder>
26class gsINSAssembler: public gsFlowAssemblerBase<T, MatOrder>
27{
28
29public:
31
32
33protected: // *** Class members ***
34
35 T m_viscosity;
36 gsSparseMatrix<T, MatOrder> m_baseMatrix, m_matrix;
37 gsMatrix<T> m_baseRhs, m_rhs;
38
39 index_t m_udofs;
40 index_t m_pdofs;
41 index_t m_pshift;
42 index_t m_nnzPerRowU, m_nnzPerRowP;
43 gsINSVisitorUUlin<T, MatOrder> m_visitorUUlin;
44 gsINSVisitorUUnonlin<T, MatOrder> m_visitorUUnonlin;
45 gsINSVisitorPU_withUPrhs<T, MatOrder> m_visitorUP;
46 gsINSVisitorRhsU<T, MatOrder> m_visitorF;
47 gsINSVisitorRhsP<T, MatOrder> m_visitorG;
48 gsSparseMatrix<T, MatOrder> m_blockUUlin_comp, m_blockUUnonlin_comp, m_blockUP;
49 gsSparseMatrix<T, MatOrder> m_blockUUlin_whole, m_blockUUnonlin_whole;
50 gsMatrix<T> m_rhsUlin, m_rhsUnonlin, m_rhsBtB, m_rhsFG;
51 gsField<T> m_currentVelField, m_currentPresField;
52
53 bool m_isMassMatReady;
54 std::vector< gsSparseMatrix<T, MatOrder> > m_massMatBlocks;
55
56 // PCD members
57 // std::vector<index_t> m_presInIDs, m_presOutIDs, m_presWallIDs
58 // std::vector< gsSparseMatrix<T, MatOrder> > m_pcdBlocks(3); // [laplaceP, robinBCblock, convectionP]
59
60
61protected: // *** Base class members ***
62
63 using Base::m_params;
64 using Base::m_dofs;
65 using Base::m_tarDim;
66 using Base::m_dofMappers;
67 using Base::m_ddof;
68 using Base::m_solution;
69 using Base::m_isBaseReady;
70 using Base::m_isSystemReady;
71
72public: // *** Base class member functions ***
73
74 using Base::getBases;
75 using Base::getPatches;
77 using Base::getBCs;
78
79public: // *** Constructor/destructor ***
80
82 Base(params)
83 { }
84
85 virtual ~gsINSAssembler()
86 { }
87
88protected: // *** Member functions ***
89
91 void initMembers();
92
94 virtual void updateSizes();
95
97 virtual void updateDofMappers();
98
102 virtual void updateCurrentSolField(const gsMatrix<T> & solVector, bool updateSol);
103
105 virtual void assembleLinearPart();
106
108 virtual void assembleNonlinearPart();
109
114
119
124
129
131 virtual void fillBaseSystem();
132
134 virtual void fillSystem();
135
136
137 // --- PCD member functions ---
138
139 // void findPressureBoundaryIDs();
140
141 // void findPressureBoundaryPartIDs(std::vector<std::pair<int, boxSide> > bndPart, std::vector<index_t>& idVector);
142
143
144public: // *** Member functions ***
145
147 virtual void initialize();
148
152 virtual void update(const gsMatrix<T> & solVector, bool updateSol = true);
153
157 virtual void markDofsAsEliminatedZeros(const std::vector< gsMatrix< index_t > > & boundaryDofs, const index_t unk);
158
160 virtual void fillStokesSystem(gsSparseMatrix<T, MatOrder>& stokesMat, gsMatrix<T>& stokesRhs);
161
166 virtual gsField<T> constructSolution(const gsMatrix<T>& solVector, index_t unk) const;
167
172 T computeFlowRate(index_t patch, boxSide side, gsMatrix<T> solution) const;
173
174
175public: // *** Getters/setters ***
176
178 T getViscosity() const { return m_viscosity; }
179
181 virtual const gsSparseMatrix<T, MatOrder>& matrix() const
182 {
183 GISMO_ASSERT(m_isSystemReady, "Matrix not ready, is fillGlobalSyst in the solver params true? If so, update() must be called first.");
184 return m_matrix;
185 }
186
188 virtual const gsMatrix<T>& rhs() const
189 {
190 GISMO_ASSERT(m_isSystemReady, "Rhs not ready, is fillGlobalSyst in the solver params true? If so, update() must be called first.");
191 return m_rhs;
192 }
193
195 const gsMatrix<T>& getSolution() const { return m_solution; }
196
199 index_t numDofsUnk(index_t i);
200
202 index_t getUdofs() const { return m_udofs; }
203
205 index_t getPdofs() const { return m_pdofs; }
206
208 index_t getPshift() const { return m_pshift; }
209
212 virtual gsSparseMatrix<T, MatOrder> getBlockUU(bool linPartOnly = false);
213
216 {
217 GISMO_ASSERT(i >= 0 && i < m_tarDim, "Component index out of range.");
218 return getBlockUU().block(i * m_udofs, i * m_udofs, m_udofs, m_udofs);
219 }
220
221
224 { return m_blockUP; }
225
228 { return (-1.0)*gsSparseMatrix<T, MatOrder>(m_blockUP.transpose()); }
229
232 {
233 GISMO_ASSERT(i >= 0 && i < m_tarDim, "Component index out of range.");
234 return getBlockUP().middleRows(i * m_udofs, m_udofs);
235 }
236
239 {
240 GISMO_ASSERT(i >= 0 && i < m_tarDim, "Component index out of range.");
241 return (-1.0)*gsSparseMatrix<T, MatOrder>(getBlockUPcomp(i).transpose());
242 }
243
247 {
248 GISMO_ASSERT(unkID == 0 || unkID == 1, "unkID must be 0 (velocity) or 1 (pressure).");
249 GISMO_ASSERT(m_isMassMatReady, "Mass matrices not assembled in gsINSAssembler.");
250 return m_massMatBlocks[unkID];
251 }
252
253 virtual const gsSparseMatrix<T, MatOrder>& getMassMatrix(index_t unkID) const
254 {
255 GISMO_ASSERT(unkID == 0 || unkID == 1, "unkID must be 0 (velocity) or 1 (pressure).");
256 GISMO_ASSERT(m_isMassMatReady, "Mass matrices not assembled in gsINSAssembler.");
257 return m_massMatBlocks[unkID];
258 }
259
261 virtual gsMatrix<T> getRhsU() const;
262
264 virtual gsMatrix<T> getRhsUcomp(index_t i) const
265 {
266 GISMO_ASSERT(i >= 0 && i < m_tarDim, "Component index out of range.");
267 return getRhsU().middleRows(i * m_udofs, m_udofs);
268 }
269
271 gsMatrix<T> getRhsP() const;
272
273}; // gsINSAssembler
274
275
276// ===================================================================================================================
277
278
281template<class T, int MatOrder>
282class gsINSAssemblerSteady: public gsINSAssembler<T, MatOrder>
283{
284
285public:
287
288
289public: // *** Constructor/destructor ***
290
292 Base(params)
293 {
295 }
296
297 virtual ~gsINSAssemblerSteady()
298 { }
299
300}; // gsINSAssemblerSteady
301
302
303// ===================================================================================================================
304
305
308template<class T, int MatOrder>
309class gsINSAssemblerUnsteady: public gsINSAssembler<T, MatOrder>
310{
311
312public:
314
315
316protected: // *** Class members ***
317
318 gsINSVisitorUUtimeDiscr<T, MatOrder> m_visitorTimeDiscr;
319 gsSparseMatrix<T, MatOrder> m_blockTimeDiscr;
320 gsMatrix<T> m_rhsTimeDiscr;
321 gsField<T> m_oldTimeVelField;
322
323
324protected: // *** Base class members ***
325
326 using Base::m_params;
327 using Base::m_pshift;
328 using Base::m_nnzPerRowU;
329 using Base::m_dofMappers;
330 using Base::m_solution;
331 using Base::m_baseMatrix;
332 using Base::m_matrix;
333 using Base::m_rhs;
334 using Base::m_currentVelField;
335
336
337public: // *** Constructor/destructor ***
338
340 Base(params)
341 {
342 initMembers();
343 }
344
346 { }
347
348
349protected: // *** Member functions ***
350
352 void initMembers();
353
355 virtual void updateSizes();
356
358 virtual void updateDofMappers();
359
363 virtual void updateCurrentSolField(const gsMatrix<T> & solVector, bool updateSol);
364
366 virtual void assembleLinearPart();
367
369 virtual void fillSystem();
370
371
372public: // *** Member functions ***
373
377 virtual void update(const gsMatrix<T> & solVector, bool updateSol = true);
378
379
380public: // *** Getters/setters ***
381
384 { return Base::getBlockUU() + m_blockTimeDiscr; }
385
386
388 virtual gsMatrix<T> getRhsU() const
389 { return Base::getRhsU() + m_rhsTimeDiscr; }
390
391
392}; //gsINSAssemblerUnsteady
393
394} // namespace gismo
395
396#ifndef GISMO_BUILD_LIB
397#include GISMO_HPP_HEADER(gsINSAssembler.hpp)
398#endif
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
A scalar of vector field defined on a m_parametric geometry.
Definition gsField.h:55
A base class for all assemblers in gsIncompressibleFlow.
Definition gsFlowAssemblerBase.h:25
const gsBoundaryConditions< T > & getBCs() const
Returns a const reference to the boundary conditions.
Definition gsFlowAssemblerBase.h:185
std::vector< gsMultiBasis< T > > & getBases()
Returns a reference to the discretization bases.
Definition gsFlowAssemblerBase.h:181
gsAssemblerOptions getAssemblerOptions() const
Returns the assembler options.
Definition gsFlowAssemblerBase.h:191
const gsMultiPatch< T > & getPatches() const
Returns a const reference to the multipatch representing the computational domain.
Definition gsFlowAssemblerBase.h:172
A class that holds all parameters needed by the incompressible flow solver.
Definition gsFlowSolverParams.h:34
The steady incompressible Navier–Stokes assembler.
Definition gsINSAssembler.h:283
The unsteady incompressible Navier–Stokes assembler.
Definition gsINSAssembler.h:310
virtual void updateCurrentSolField(const gsMatrix< T > &solVector, bool updateSol)
Update the current solution field stored in the assembler (used as convection coefficient).
Definition gsINSAssembler.hpp:624
virtual gsMatrix< T > getRhsU() const
///
Definition gsINSAssembler.h:388
virtual void assembleLinearPart()
Assemble the linear part of the matrix.
Definition gsINSAssembler.hpp:634
virtual void updateDofMappers()
Update the DOF mappers in all visitors (e.g. after markDofsAsEliminatedZeros() ).
Definition gsINSAssembler.hpp:615
virtual gsSparseMatrix< T, MatOrder > getBlockUU()
Returns the velocity-velocity block of the linear system.
Definition gsINSAssembler.h:383
void initMembers()
Initialize all members.
Definition gsINSAssembler.hpp:592
virtual void update(const gsMatrix< T > &solVector, bool updateSol=true)
Definition gsINSAssembler.hpp:662
virtual void fillSystem()
Add the nonlinear part to the given matrix and right-hand side.
Definition gsINSAssembler.hpp:652
virtual void updateSizes()
Update sizes of members (when DOF numbers change, e.g. after markDofsAsEliminatedZeros()).
Definition gsINSAssembler.hpp:603
A base class for incompressible Navier-Stokes assemblers.
Definition gsINSAssembler.h:27
gsSparseMatrix< T, MatOrder > getBlockPU() const
Returns the pressure-velocity block of the linear system.
Definition gsINSAssembler.h:227
index_t numDofsUnk(index_t i)
Returns the number of DOFs for the i-th unknown.
Definition gsINSAssembler.hpp:486
virtual void fillBaseSystem()
Fill the linear part of the global matrix and right-hand side.
Definition gsINSAssembler.hpp:276
void fillGlobalMat_UU(gsSparseMatrix< T, MatOrder > &globalMat, const gsSparseMatrix< T, MatOrder > &sourceMat)
Fill the velocity-velocity block into the global saddle-point matrix.
Definition gsINSAssembler.hpp:229
virtual void initialize()
Initialize the assembler.
Definition gsINSAssembler.hpp:334
virtual const gsMatrix< T > & rhs() const
Returns the assembled right-hand side.
Definition gsINSAssembler.h:188
virtual void updateCurrentSolField(const gsMatrix< T > &solVector, bool updateSol)
Update the current solution field stored in the assembler (used as convection coefficient).
Definition gsINSAssembler.hpp:112
virtual void assembleLinearPart()
Assemble the linear part of the problem.
Definition gsINSAssembler.hpp:123
index_t getPdofs() const
Returns the number of pressure DOFs.
Definition gsINSAssembler.h:205
virtual const gsSparseMatrix< T, MatOrder > & matrix() const
Returns the assembled matrix.
Definition gsINSAssembler.h:181
const gsSparseMatrix< T, MatOrder > & getBlockUP() const
Returns the velocity-pressure block of the linear system.
Definition gsINSAssembler.h:223
virtual void fillStokesSystem(gsSparseMatrix< T, MatOrder > &stokesMat, gsMatrix< T > &stokesRhs)
Fill the matrix and right-hand side for the Stokes problem.
Definition gsINSAssembler.hpp:375
index_t getPshift() const
Returns the DOF shift of pressure (i.e. the total number of velocity DOFs).
Definition gsINSAssembler.h:208
virtual void markDofsAsEliminatedZeros(const std::vector< gsMatrix< index_t > > &boundaryDofs, const index_t unk)
Eliminate given DOFs as homogeneous Dirichlet boundary.
Definition gsINSAssembler.hpp:354
virtual gsSparseMatrix< T, MatOrder > getBlockUU(bool linPartOnly=false)
Returns the velocity-velocity block of the linear system.
Definition gsINSAssembler.hpp:498
virtual gsMatrix< T > getRhsU() const
///
Definition gsINSAssembler.hpp:539
index_t getUdofs() const
Returns the number of velocity DOFs (one velocity component).
Definition gsINSAssembler.h:202
void fillGlobalMat_PU(gsSparseMatrix< T, MatOrder > &globalMat, const gsSparseMatrix< T, MatOrder > &sourceMat)
Fill the pressure-velocity block into the global saddle-point matrix.
Definition gsINSAssembler.hpp:258
T computeFlowRate(index_t patch, boxSide side, gsMatrix< T > solution) const
Compute flow rate through a side of a given patch.
Definition gsINSAssembler.hpp:433
virtual gsSparseMatrix< T, MatOrder > getBlockPUcomp(index_t i) const
Returns part of pressure-velocity block for i-th velocity component.
Definition gsINSAssembler.h:238
virtual void updateDofMappers()
Update the DOF mappers in all visitors (when DOF numbers change, e.g. after markDofsAsEliminatedZeros...
Definition gsINSAssembler.hpp:101
virtual gsSparseMatrix< T, MatOrder > getBlockUUcompDiag(index_t i=0)
Returns the diagonal block of velocity-velocity block for i-th component.
Definition gsINSAssembler.h:215
virtual gsField< T > constructSolution(const gsMatrix< T > &solVector, index_t unk) const
Construct solution from computed solution vector for unknown unk.
Definition gsINSAssembler.hpp:389
T getViscosity() const
Returns the viscosity value.
Definition gsINSAssembler.h:178
virtual gsSparseMatrix< T, MatOrder > getBlockUPcomp(index_t i) const
Returns the part of velocity-pressure block for i-th velocity component.
Definition gsINSAssembler.h:231
void fillGlobalMat_UP(gsSparseMatrix< T, MatOrder > &globalMat, const gsSparseMatrix< T, MatOrder > &sourceMat)
Fill the velocity-pressure block into the global saddle-point matrix.
Definition gsINSAssembler.hpp:248
void initMembers()
Initialize the class members.
Definition gsINSAssembler.hpp:19
virtual void update(const gsMatrix< T > &solVector, bool updateSol=true)
Definition gsINSAssembler.hpp:344
virtual void assembleNonlinearPart()
Assemble the linear part of the problem.
Definition gsINSAssembler.hpp:194
virtual gsMatrix< T > getRhsUcomp(index_t i) const
///
Definition gsINSAssembler.h:264
virtual void fillSystem()
Add the nonlinear part to the given matrix and right-hand side.
Definition gsINSAssembler.hpp:316
gsMatrix< T > getRhsP() const
Returns the pressure part of the right-hand side.
Definition gsINSAssembler.hpp:552
virtual gsSparseMatrix< T, MatOrder > & getMassMatrix(index_t unkID)
Returns the mass matrix for unknown with index unk. There is also a const version.
Definition gsINSAssembler.h:246
virtual void updateSizes()
Update sizes of members (when DOF numbers change, e.g. after markDofsAsEliminatedZeros()).
Definition gsINSAssembler.hpp:62
void fillGlobalMat_PP(gsSparseMatrix< T, MatOrder > &globalMat, const gsSparseMatrix< T, MatOrder > &sourceMat)
Fill the pressure-pressure block into the global saddle-point matrix.
Definition gsINSAssembler.hpp:267
const gsMatrix< T > & getSolution() const
Returns a const reference to the current computed solution.
Definition gsINSAssembler.h:195
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
Provides declaration of the Field class.
The G+Smo namespace, containing all definitions for the library.