Saras
Finite   Difference   Solver   for   Fluid   Dynamics   Simulations
hydro.h
Go to the documentation of this file.
1/********************************************************************************************************************************************
2 * Saras
3 *
4 * Copyright (C) 2019, Mahendra K. Verma
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 ********************************************************************************************************************************************
31 */
43#ifndef HYDRO_H
44#define HYDRO_H
45
46#include <blitz/array.h>
47
48#include "boundary.h"
49#include "parallel.h"
50#include "poisson.h"
51#include "plainvf.h"
52#include "tseries.h"
53#include "writer.h"
54#include "reader.h"
55#include "probes.h"
56#include "sfield.h"
57#include "vfield.h"
58#include "parser.h"
59#include "force.h"
60#include "grid.h"
61
62class hydro {
63 public:
66
69
72
73 hydro(const grid &mesh, const parser &solParam, parallel &mpiParam);
74
75 virtual void solvePDE();
76 virtual real testPeriodic();
77
78 virtual ~hydro() { };
79
80 protected:
83
86
87 real time, dt;
88
89 real hx, hy, hz;
90 real hx2, hz2, hz2hx2;
91 real hx2hy2, hy2hz2, hx2hy2hz2;
92
93 const grid &mesh;
94 const parser &inputParams;
95
96 const real inverseRe;
97
100
103 boundary *uLft, *uRgt, *uFrn, *uBak, *uTop, *uBot;
104 boundary *vLft, *vRgt, *vFrn, *vBak, *vTop, *vBot;
105 boundary *wLft, *wRgt, *wFrn, *wBak, *wTop, *wBot;
107
110
115
124
125 void checkPeriodic();
126 void setCoefficients();
127
128 void initVBC();
129 void imposeUBCs();
130 void imposeVBCs();
131 void imposeWBCs();
132
133 void initVForcing();
134
135 virtual void solveVx();
136 virtual void solveVy();
137 virtual void solveVz();
138
139 virtual void timeAdvance();
140};
141
154class hydro_d2: public hydro {
155 public:
156 hydro_d2(const grid &mesh, const parser &solParam, parallel &mpiParam);
157
158 void solvePDE();
159 real testPeriodic();
160
161 ~hydro_d2();
162
163 private:
164 multigrid_d2 mgSolver;
165
166 void solveVx();
167 void solveVz();
168
169 void timeAdvance();
170};
171
183class hydro_d3: public hydro {
184 public:
185 hydro_d3(const grid &mesh, const parser &solParam, parallel &mpiParam);
186
187 void solvePDE();
188 real testPeriodic();
189
190 ~hydro_d3();
191
192 private:
193 multigrid_d3 mgSolver;
194
195#ifdef TIME_RUN
196 real visc_time, nlin_time, intr_time, impl_time, prhs_time, pois_time;
197#endif
198
199 void solveVx();
200 void solveVy();
201 void solveVz();
202
203 void timeAdvance();
204};
205
216#endif
Class declaration of boundary.
Contains all the global variables related to the imposing of boundary conditions, and functions to im...
Definition: boundary.h:51
Contains all the global variables related to the imposing of forcing, and associated functions.
Definition: force.h:52
Contains all the global variables related to the grid, its slices, limits, and grid derivatives used ...
Definition: grid.h:53
The derived class from the hydro base class to solve the incompressible NSE in 2D.
Definition: hydro.h:154
hydro_d2(const grid &mesh, const parser &solParam, parallel &mpiParam)
Constructor of the hydro_d2 class derived from the base hydro class.
Definition: hydro_d2.cc:60
void solvePDE()
The core publicly accessible function of the hydro class to solve the Navier-Stokes equations.
Definition: hydro_d2.cc:117
real testPeriodic()
Function to test whether periodic BC is being implemented properly.
Definition: hydro_d2.cc:386
The derived class from the hydro base class to solve the incompressible NSE in 3D.
Definition: hydro.h:183
hydro_d3(const grid &mesh, const parser &solParam, parallel &mpiParam)
Constructor of the hydro_d3 class derived from the base hydro class.
Definition: hydro_d3.cc:63
void solvePDE()
The core publicly accessible function of the hydro class to solve the Navier-Stokes equations.
Definition: hydro_d3.cc:122
real testPeriodic()
Function to test whether periodic BC is being implemented properly.
Definition: hydro_d3.cc:536
The base class hydro to solve the incompressible Navier-Stokes equations.
Definition: hydro.h:62
probes * dataProbe
Instance of the probe class to collect data from probes in the domain.
Definition: hydro.h:99
plainvf nseRHS
Plain vector field into which the RHS of the Navier-Stokes equation is written and stored.
Definition: hydro.h:117
void imposeWBCs()
Function to impose the boundary conditions for the Z-component of velocity.
Definition: hydro.cc:446
force * vForcing
Instance of force class to handle velocity field forcing.
Definition: hydro.h:71
plainsf Pp
Plain scalar field into which the pressure correction is calculated and written by the Poisson solver...
Definition: hydro.h:112
boundary * uLft
Instances of the boundary class to impose boundary conditions on all the 6 walls for the 3 components...
Definition: hydro.h:103
virtual void timeAdvance()
The subroutine to solve the NS equations using the implicit Crank-Nicholson method.
Definition: hydro.cc:100
parallel & mpiData
Instance of the parallel class that holds the MPI-related data like rank, xRank, etc.
Definition: hydro.h:109
hydro(const grid &mesh, const parser &solParam, parallel &mpiParam)
Constructor of the base hydro class.
Definition: hydro.cc:60
void initVBC()
Function to initialize the boundary conditions for velocity.
Definition: hydro.cc:287
plainsf mgRHS
Plain scalar field into which the RHS for pressure Poisson equation is written and passed to the Pois...
Definition: hydro.h:114
virtual void solvePDE()
The core publicly accessible function of the hydro class to solve the Navier-Stokes equations.
Definition: hydro.cc:88
sfield P
The scalar field that stores the pressure field.
Definition: hydro.h:68
void imposeVBCs()
Function to impose the boundary conditions for the Y-component of velocity.
Definition: hydro.cc:416
virtual void solveVx()
Function to solve the implicit equation for x-velocity.
Definition: hydro.cc:120
virtual void solveVz()
Function to solve the implicit equation for z-velocity.
Definition: hydro.cc:160
int maxIterations
Maximum number of iterations for the iterative solvers hydro::solveVx, hydro::solveVy and hydro::solv...
Definition: hydro.h:85
vfield V
The vector field that stores the velocity field.
Definition: hydro.h:65
void checkPeriodic()
Function to enable/disable periodic data transfer as per the problem.
Definition: hydro.cc:174
plainvf guessedVelocity
Plain vector field which serves as a temporary array during iterative solution procedure for velocity...
Definition: hydro.h:123
virtual real testPeriodic()
Function to test whether periodic BC is being implemented properly.
Definition: hydro.cc:472
virtual void solveVy()
Function to solve the implicit equation for y-velocity.
Definition: hydro.cc:140
plainvf pressureGradient
Plain vector field which stores the pressure gradient term.
Definition: hydro.h:121
int timeStepCount
Integer value for the number of time-steps elapsed - it is incremented by 1 in each time-step.
Definition: hydro.h:78
void initVForcing()
Function to initialize the forcing terms for velocity.
Definition: hydro.cc:253
void setCoefficients()
Function to set the coefficients used for solving the implicit equations of U, V and W.
Definition: hydro.cc:223
plainvf velocityLaplacian
Plain vector field into which the RHS of the implicit equation for velocities are calculated during i...
Definition: hydro.h:119
void imposeUBCs()
Function to impose the boundary conditions for the X-component of velocity.
Definition: hydro.cc:386
The derived class from poisson to perform multi-grid operations on a 2D grid.
Definition: poisson.h:156
The derived class from poisson to perform multi-grid operations on a 3D grid.
Definition: poisson.h:193
Class for all the global variables and functions related to parallelization.
Definition: parallel.h:51
Contains all the global variables set by the user through the yaml file.
Definition: parser.h:63
Plain scalar field class to store simple scalar fields with no differentiation or interpolation.
Definition: plainsf.h:51
Plain vector field class to store simple vector fields with no additional operators like differentiat...
Definition: plainvf.h:49
Handles the writing of data from probes placed in the domain.
Definition: probes.h:77
Scalar field class to store and operate on scalar fields.
Definition: sfield.h:54
Vector field class to store and operate on vector fields.
Definition: vfield.h:54
Class declaration of force.
Class declaration of grid.
Class declaration of parallel.
Class declaration of parser.
Class declaration of plainvf - plain vector field.
Class declaration of poisson.
Class declaration of probes.
Class declaration of reader.
Class declaration of sfield - scalar field.
Class declaration of tseries.
Class declaration of vfield - vector field.
Class declaration of writer.