Saras
Finite   Difference   Solver   for   Fluid   Dynamics   Simulations
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
hydro Class Reference

The base class hydro to solve the incompressible Navier-Stokes equations. More...

#include "lib/hydro.h"

Inheritance diagram for hydro:
hydro_d2 hydro_d3 scalar scalar_d2 scalar_d3

Public Member Functions

 hydro (const grid &mesh, const parser &solParam, parallel &mpiParam)
 Constructor of the base hydro class. More...
 
virtual void solvePDE ()
 The core publicly accessible function of the hydro class to solve the Navier-Stokes equations. More...
 
virtual real testPeriodic ()
 Function to test whether periodic BC is being implemented properly. More...
 

Public Attributes

vfield V
 The vector field that stores the velocity field.
 
sfield P
 The scalar field that stores the pressure field.
 
forcevForcing
 Instance of force class to handle velocity field forcing.
 

Protected Member Functions

void checkPeriodic ()
 Function to enable/disable periodic data transfer as per the problem. More...
 
void setCoefficients ()
 Function to set the coefficients used for solving the implicit equations of U, V and W. More...
 
void initVBC ()
 Function to initialize the boundary conditions for velocity. More...
 
void imposeUBCs ()
 Function to impose the boundary conditions for the X-component of velocity. More...
 
void imposeVBCs ()
 Function to impose the boundary conditions for the Y-component of velocity. More...
 
void imposeWBCs ()
 Function to impose the boundary conditions for the Z-component of velocity. More...
 
void initVForcing ()
 Function to initialize the forcing terms for velocity. More...
 
virtual void solveVx ()
 Function to solve the implicit equation for x-velocity. More...
 
virtual void solveVy ()
 Function to solve the implicit equation for y-velocity. More...
 
virtual void solveVz ()
 Function to solve the implicit equation for z-velocity. More...
 
virtual void timeAdvance ()
 The subroutine to solve the NS equations using the implicit Crank-Nicholson method. More...
 

Protected Attributes

int timeStepCount
 Integer value for the number of time-steps elapsed - it is incremented by 1 in each time-step.
 
int maxIterations
 Maximum number of iterations for the iterative solvers hydro::solveVx, hydro::solveVy and hydro::solveVz.
 
real time
 
real dt
 
real hx
 
real hy
 
real hz
 
real hx2
 
real hz2
 
real hz2hx2
 
real hx2hy2
 
real hy2hz2
 
real hx2hy2hz2
 
const gridmesh
 
const parserinputParams
 
const real inverseRe
 
probesdataProbe
 Instance of the probe class to collect data from probes in the domain.
 
boundaryuLft
 Instances of the boundary class to impose boundary conditions on all the 6 walls for the 3 components of the velocity field.
 
boundaryuRgt
 
boundaryuFrn
 
boundaryuBak
 
boundaryuTop
 
boundaryuBot
 
boundaryvLft
 
boundaryvRgt
 
boundaryvFrn
 
boundaryvBak
 
boundaryvTop
 
boundaryvBot
 
boundarywLft
 
boundarywRgt
 
boundarywFrn
 
boundarywBak
 
boundarywTop
 
boundarywBot
 
parallelmpiData
 Instance of the parallel class that holds the MPI-related data like rank, xRank, etc.
 
plainsf Pp
 Plain scalar field into which the pressure correction is calculated and written by the Poisson solver.
 
plainsf mgRHS
 Plain scalar field into which the RHS for pressure Poisson equation is written and passed to the Poisson solver.
 
plainvf nseRHS
 Plain vector field into which the RHS of the Navier-Stokes equation is written and stored.
 
plainvf velocityLaplacian
 Plain vector field into which the RHS of the implicit equation for velocities are calculated during iterative solving.
 
plainvf pressureGradient
 Plain vector field which stores the pressure gradient term.
 
plainvf guessedVelocity
 Plain vector field which serves as a temporary array during iterative solution procedure for velocity terms.
 

Detailed Description

The base class hydro to solve the incompressible Navier-Stokes equations.

The class initializes and stores the velocity vector field and the pressure scalar field along with a few auxilliary fields to solve the PDE. It solves the NSE using the solvePDE function from within which the implicit Crank-Nicholson method is used to solve the PDE.

Constructor & Destructor Documentation

◆ hydro()

hydro::hydro ( const grid mesh,
const parser solParam,
parallel mpiParam 
)

Constructor of the base hydro class.

     The short base constructor of the hydro class merely assigns the const references to the grid and parser
     class instances being used in the solver.
     Also, the maximum allowable number of iterations for the Jacobi iterative solver being used to solve for the
     velocities implicitly is set as \f$ N_{max} = N_x \times N_y \times N_z \f$, where \f$N_x\f$, \f$N_y\f$ and \f$N_z\f$
     are the number of grid points in the collocated grid at the local sub-domains along x, y and z directions
     respectively.
Parameters
meshis a const reference to the global data contained in the grid class
solParamis a const reference to the user-set parameters contained in the parser class

Member Function Documentation

◆ checkPeriodic()

void hydro::checkPeriodic ( )
protected

Function to enable/disable periodic data transfer as per the problem.

     The function checks the xPer, yPer and zPer flags in the parser class
     and enables/disables MPI data transfer at boundaries accordingly
     By default, the MPI neighbours at boundaries are set for periodic data-transfer.
     This has to be disabled if the problem has non-periodic boundaries.

◆ imposeUBCs()

void hydro::imposeUBCs ( )
protected

Function to impose the boundary conditions for the X-component of velocity.

     The function first calls the \ref sfield#syncData "syncData" function of the Vx field to update the sub-domain pads.
     Then the boundary conditions are applied at the full domain boundaries by calling the imposeBC()
     of each boundary class object assigned to each wall.
     The order of imposing boundary conditions is - left, right, front, back, bottom and top boundaries.
     The corner values are not being imposed specifically and is thus dependent on the above order.

◆ imposeVBCs()

void hydro::imposeVBCs ( )
protected

Function to impose the boundary conditions for the Y-component of velocity.

     The function first calls the \ref sfield#syncData "syncData" function of the Vy field to update the sub-domain pads.
     Then the boundary conditions are applied at the full domain boundaries by calling the imposeBC()
     of each boundary class object assigned to each wall.
     The order of imposing boundary conditions is - left, right, front, back, bottom and top boundaries.
     The corner values are not being imposed specifically and is thus dependent on the above order.

◆ imposeWBCs()

void hydro::imposeWBCs ( )
protected

Function to impose the boundary conditions for the Z-component of velocity.

     The function first calls the \ref sfield#syncData "syncData" function of the Vz field to update the sub-domain pads.
     Then the boundary conditions are applied at the full domain boundaries by calling the imposeBC()
     of each boundary class object assigned to each wall.
     The order of imposing boundary conditions is - left, right, front, back, bottom and top boundaries.
     The corner values are not being imposed specifically and is thus dependent on the above order.

◆ initVBC()

void hydro::initVBC ( )
protected

Function to initialize the boundary conditions for velocity.

     The boundary conditions for all the 6 walls (4 in case of 2D simulations) are initialized here.
     Out of the different boundary conditions available in the boundary class,
     the appropriate BCs are chosen according to the type of problem being solved.

◆ initVForcing()

void hydro::initVForcing ( )
protected

Function to initialize the forcing terms for velocity.

     The forcing terms for the velocity field are initialized here.
     Out of the different forcings available in the force class,
     the appropriate forcing is chosen according to the parameters set by the user.

◆ setCoefficients()

void hydro::setCoefficients ( )
protected

Function to set the coefficients used for solving the implicit equations of U, V and W.

     The function assigns values to the variables \ref hx, \ref hy, etc.
     These coefficients are repeatedly used at many places in the Poisson solver for implicit calculation of velocities.

◆ solvePDE()

void hydro::solvePDE ( )
virtual

The core publicly accessible function of the hydro class to solve the Navier-Stokes equations.

     The NSE are integrated in time from within this function by calling \ref hydro#timeAdvance in a loop.
     The function keeps track of the non-dimensional time with \ref time and number of iterations with \ref iterCount.
     Both these values are continuously incremented from within the loop, and finally, when \ref time has reached the
     user-ser value in \ref parser#tMax "tMax", the time-integration loop is broken and the program exits.

Reimplemented in hydro_d2, hydro_d3, scalar_d2, and scalar_d3.

◆ solveVx()

void hydro::solveVx ( )
protectedvirtual

Function to solve the implicit equation for x-velocity.

     The implicit equation for \f$ u_x' \f$ of the implicit Crank-Nicholson method is solved using the Jacobi
     iterative method here.

     The loop exits when the global maximum of the error in computed solution obtained using the \ref plainvf#vxMax "vxMax" function
     of scalar fields in sfield.h falls below the specified tolerance.
     If the solution doesn't converge even after an internally assigned maximum number for iterations, the solver
     aborts with an error message.

     Note that this function uses the blitz index place holders firstIndex, secondIndex and thirdIndex.
     They are declared as i, j, and k respectively.
     Hence the variables i, j and k are not scalars in this function.

◆ solveVy()

void hydro::solveVy ( )
protectedvirtual

Function to solve the implicit equation for y-velocity.

     The implicit equation for \f$ u_y' \f$ of the implicit Crank-Nicholson method is solved using the Jacobi
     iterative method here.

     The loop exits when the global maximum of the error in computed solution obtained using the \ref plainvf#vyMax "vyMax" function
     of scalar fields in sfield.h falls below the specified tolerance.
     If the solution doesn't converge even after an internally assigned maximum number for iterations, the solver
     aborts with an error message.

     Note that this function uses the blitz index place holders firstIndex, secondIndex and thirdIndex.
     They are declared as i, j, and k respectively.
     Hence the variables i, j and k are not scalars in this function.

◆ solveVz()

void hydro::solveVz ( )
protectedvirtual

Function to solve the implicit equation for z-velocity.

     The implicit equation for \f$ u_z' \f$ of the implicit Crank-Nicholson method is solved using the Jacobi
     iterative method here.

     The loop exits when the global maximum of the error in computed solution obtained using the \ref plainvf#vzMax "vzMax" function
     of scalar fields in sfield.h falls below the specified tolerance.
     If the solution doesn't converge even after an internally assigned maximum number for iterations, the solver
     aborts with an error message.

     Note that this function uses the blitz index place holders firstIndex, secondIndex and thirdIndex.
     They are declared as i, j, and k respectively.
     Hence the variables i, j and k are not scalars in this function.

◆ testPeriodic()

real hydro::testPeriodic ( )
virtual

Function to test whether periodic BC is being implemented properly.

     The function populates the arrays with predetermined values at all locations.
     It then calls imposeUBCs, imposeVBCs and imposeWBCs functions and checks if the correct values of the functions are imposed at boundaries

Reimplemented in hydro_d2, hydro_d3, scalar_d2, and scalar_d3.

◆ timeAdvance()

void hydro::timeAdvance ( )
protectedvirtual

The subroutine to solve the NS equations using the implicit Crank-Nicholson method.

     This function uses the values of velocity vector field and pressure scalar field, along with a specifed time-step
     to update the values of both fields by one time-step.
     Hence this function has to be repeatedly called in a loop from within the \ref solvePDE function to solve the equations.

The documentation for this class was generated from the following files: