PetIBM 0.5.4
Toolbox and applications of the immersed-boundary method for distributed-memory architectures
navierstokes.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <yaml-cpp/yaml.h>
13
14#include <petibm/boundary.h>
15#include <petibm/linsolver.h>
16#include <petibm/mesh.h>
17#include <petibm/operators.h>
18#include <petibm/probes.h>
19#include <petibm/solution.h>
21
30{
31public:
33 NavierStokesSolver() = default;
34
40 NavierStokesSolver(const MPI_Comm &world,
41 const YAML::Node &node);
42
45
47 PetscErrorCode destroy();
48
61 PetscErrorCode init(const MPI_Comm &world, const YAML::Node &node);
62
64 PetscErrorCode ioInitialData();
65
67 PetscErrorCode advance();
68
70 PetscErrorCode write();
71
73 bool finished();
74
75protected:
77 MPI_Comm comm;
78
80 PetscMPIInt commSize;
81
83 PetscMPIInt commRank;
84
86 YAML::Node config;
87
90
93
96
99
102
105
108
110 std::vector<petibm::type::Probe> probes;
111
113 PetscReal dt;
114
116 PetscInt ite;
117
119 PetscReal t;
120
122 PetscInt nstart;
123
125 PetscInt nt;
126
128 PetscInt nsave;
129
131 PetscInt nrestart;
132
134 PetscReal nu;
135
137 Mat L;
138
141
143 Mat G;
144
146 Mat D;
147
150
152 Mat N;
153
155 Mat A;
156
158 Mat BNG;
159
161 Mat DBNG;
162
164 Vec dP;
165
167 Vec bc1;
168
170 Vec rhs1;
171
173 Vec rhs2;
174
176 std::vector<Vec> conv;
177
179 std::vector<Vec> diff;
180
182 PetscBool isRefP;
183
185 PetscLogStage stageInitialize;
186
188 PetscLogStage stageRHSVelocity;
189
191 PetscLogStage stageSolveVelocity;
192
194 PetscLogStage stageRHSPoisson;
195
197 PetscLogStage stageSolvePoisson;
198
200 PetscLogStage stageUpdate;
201
203 PetscLogStage stageWrite;
204
206 PetscLogStage stageMonitor;
207
209 PetscViewer solversViewer;
210
212 virtual PetscErrorCode assembleRHSVelocity();
213
215 virtual PetscErrorCode solveVelocity();
216
218 virtual PetscErrorCode assembleRHSPoisson();
219
221 virtual PetscErrorCode solvePoisson();
222
223 virtual PetscErrorCode applyDivergenceFreeVelocity();
224
225 virtual PetscErrorCode updatePressure();
226
228 virtual PetscErrorCode createOperators();
229
231 virtual PetscErrorCode createVectors();
232
234 virtual PetscErrorCode setNullSpace();
235
243 virtual PetscErrorCode createPetscViewerASCII(const std::string &filePath,
244 const PetscFileMode &mode,
245 PetscViewer &viewer);
246
252 virtual PetscErrorCode writeSolutionHDF5(const std::string &filePath);
253
259 virtual PetscErrorCode writeRestartDataHDF5(const std::string &filePath);
260
266 virtual PetscErrorCode readRestartDataHDF5(const std::string &filePath);
267
269 virtual PetscErrorCode writeLinSolversInfo();
270
277 virtual PetscErrorCode writeTimeHDF5(const PetscReal &t,
278 const std::string &filePath);
279
286 virtual PetscErrorCode readTimeHDF5(const std::string &filePath,
287 PetscReal &t);
288
290 virtual PetscErrorCode monitorProbes();
291
292}; // NavierStokesSolver
boundary::BoundaryBase, type::Boundary, and factory function.
Solve the incompressible Navier-Stokes equations with a projection method (Perot 1993).
Definition: navierstokes.h:30
Vec rhs2
Right-hand side vector of the Poisson system.
Definition: navierstokes.h:173
petibm::type::Solution solution
Data object holding the velocity and pressure fields.
Definition: navierstokes.h:95
petibm::type::LinSolver pSolver
Poisson linear solver.
Definition: navierstokes.h:107
PetscReal nu
Viscous diffusion coefficient.
Definition: navierstokes.h:134
PetscInt nstart
Starting time-step index.
Definition: navierstokes.h:122
PetscLogStage stageMonitor
Log stage for monitoring user-defined regions of the domain.
Definition: navierstokes.h:206
Mat L
Laplacian operator.
Definition: navierstokes.h:137
Vec bc1
Inhomogeneous boundary terms for the velocity system.
Definition: navierstokes.h:167
PetscLogStage stageSolvePoisson
Log stage for solving the Poisson system.
Definition: navierstokes.h:197
PetscErrorCode ioInitialData()
Read or write initial data.
PetscReal t
Time value.
Definition: navierstokes.h:119
YAML::Node config
YAML configuration settings.
Definition: navierstokes.h:86
std::vector< petibm::type::Probe > probes
Probes to monitor the solution.
Definition: navierstokes.h:110
petibm::type::Boundary bc
Information about the domain boundaries.
Definition: navierstokes.h:92
NavierStokesSolver()=default
Default constructor.
PetscInt nsave
Frequency at which the solution fields are written to files.
Definition: navierstokes.h:128
virtual PetscErrorCode updatePressure()
virtual PetscErrorCode assembleRHSVelocity()
Assemble the RHS vector of the velocity system.
PetscErrorCode advance()
Advance the solution by one time step.
virtual PetscErrorCode readRestartDataHDF5(const std::string &filePath)
Read data required to restart a simulation from a HDF5 file.
petibm::type::TimeIntegration convCoeffs
Time scheme for the convective terms.
Definition: navierstokes.h:98
virtual PetscErrorCode writeLinSolversInfo()
Write numbers of iterations and residuals of solvers to file.
PetscLogStage stageInitialize
Log stage for the initialization phase.
Definition: navierstokes.h:185
virtual PetscErrorCode readTimeHDF5(const std::string &filePath, PetscReal &t)
Read the time value from a HDF5 file.
bool finished()
Evaluate if the simulation is finished.
Vec rhs1
Right-hand side vector of the velocity system.
Definition: navierstokes.h:170
Vec dP
Pressure-correction vector.
Definition: navierstokes.h:164
virtual PetscErrorCode writeSolutionHDF5(const std::string &filePath)
Write the solution fields into a HDF5 file.
Mat A
Implicit operator for the velocity solver.
Definition: navierstokes.h:155
Mat G
Gradient operator.
Definition: navierstokes.h:143
virtual PetscErrorCode createOperators()
Create operators.
petibm::type::LinSolver vSolver
Velocity linear solver.
Definition: navierstokes.h:104
PetscMPIInt commRank
Rank of the process in the MPI communicator.
Definition: navierstokes.h:83
PetscReal dt
Time-step size.
Definition: navierstokes.h:113
Mat N
Convective operator (matrix-free).
Definition: navierstokes.h:152
Mat LCorrection
Laplacian correction operator for boundary conditions.
Definition: navierstokes.h:140
std::vector< Vec > conv
Explicit convective terms.
Definition: navierstokes.h:176
virtual PetscErrorCode assembleRHSPoisson()
Assemble the RHS vector of the Poisson system.
MPI_Comm comm
MPI communicator.
Definition: navierstokes.h:77
virtual PetscErrorCode solvePoisson()
Solve the Poisson system.
virtual PetscErrorCode writeRestartDataHDF5(const std::string &filePath)
Write data required to restart a simulation into a HDF5 file.
PetscBool isRefP
True if we pin the pressure at a reference point.
Definition: navierstokes.h:182
~NavierStokesSolver()
Default destructor.
petibm::type::TimeIntegration diffCoeffs
Time scheme for the diffusion terms.
Definition: navierstokes.h:101
virtual PetscErrorCode applyDivergenceFreeVelocity()
PetscInt nrestart
Frequency at which data to restart are written to files.
Definition: navierstokes.h:131
Mat DCorrection
Divergence correction for boundary conditions.
Definition: navierstokes.h:149
PetscMPIInt commSize
Size of the MPI communicator.
Definition: navierstokes.h:80
PetscLogStage stageRHSVelocity
Log stage for assembling the RHS of the velocity system.
Definition: navierstokes.h:188
PetscErrorCode write()
Write solution and solver info to files.
PetscErrorCode init(const MPI_Comm &world, const YAML::Node &node)
Initialize the Navier-Stokes solver.
virtual PetscErrorCode setNullSpace()
Set Poisson nullspace or pin pressure at a reference point.
PetscLogStage stageWrite
Log stage when write the solution fields.
Definition: navierstokes.h:203
std::vector< Vec > diff
Explicit diffusion terms.
Definition: navierstokes.h:179
PetscLogStage stageUpdate
Log stage for updating field variables.
Definition: navierstokes.h:200
PetscInt ite
Time-step index.
Definition: navierstokes.h:116
petibm::type::Mesh mesh
Structured Cartesian mesh object.
Definition: navierstokes.h:89
PetscLogStage stageSolveVelocity
Log stage for solving the velocity system.
Definition: navierstokes.h:191
PetscLogStage stageRHSPoisson
Log stage for assembling the RHS of the Poisson system.
Definition: navierstokes.h:194
virtual PetscErrorCode solveVelocity()
Solve the velocity system.
virtual PetscErrorCode monitorProbes()
Monitor the solution at probes.
Mat BNG
Projection operator.
Definition: navierstokes.h:158
PetscInt nt
Number of time steps to compute.
Definition: navierstokes.h:125
virtual PetscErrorCode writeTimeHDF5(const PetscReal &t, const std::string &filePath)
Write the time value into a HDF5 file.
virtual PetscErrorCode createVectors()
Create vectors.
PetscErrorCode destroy()
Manually destroy data.
Mat D
Divergence operator.
Definition: navierstokes.h:146
virtual PetscErrorCode createPetscViewerASCII(const std::string &filePath, const PetscFileMode &mode, PetscViewer &viewer)
Create an ASCII PetscViewer.
Mat DBNG
Poisson operator.
Definition: navierstokes.h:161
PetscViewer solversViewer
ASCII PetscViewer object to output solvers info.
Definition: navierstokes.h:209
std::shared_ptr< boundary::BoundaryBase > Boundary
Type definition of petibm::type::Boundary.
Definition: boundary.h:175
std::shared_ptr< linsolver::LinSolverBase > LinSolver
Type definition of LinSolver.
Definition: linsolver.h:174
std::shared_ptr< mesh::MeshBase > Mesh
Type definition of Mesh.
Definition: mesh.h:348
std::shared_ptr< solution::SolutionBase > Solution
Type definition of solution object.
Definition: solution.h:210
std::shared_ptr< timeintegration::TimeIntegrationBase > TimeIntegration
Definition of type::TimeIntegration.
Def. of LinSolverBase, LinSolver, and factory function.
Prototype of mesh::MeshBase, type::Mesh, and factory function.
Prototypes of factory functions for operators.
Prototype of probe classes, type::Probe, and factory function.
Definition of the class petibm::solution::SolutionBase, the type definition petibm::type::Solution,...
Definition of TimeIntegration related classes.