Simple MAC  1.0
A Marker and Cell Method Solver for the Navier Stokes Equations
 All Classes Files Functions Variables Pages
Public Member Functions | Public Attributes
solver Module Reference

The MAC Method solver and it's persistent data. More...

List of all members.

Public Member Functions

subroutine initzero ()
 Initialize all variables with zero values.
subroutine returnu (array)
 Accessor for U-Velocity.
subroutine returnv (array)
 Accessor for V-Velocity.
subroutine returnp (array)
 Accessor for Pressure.
subroutine ghostcondition ()
 Applies ghost cell boundary conditions at the walls.
subroutine lidcondition ()
 Applies a moving lid to the top of the cavity, and a no slip condition at every other wall.
subroutine calctstep ()
 Calculates are maximum allowable timestep, \( \Delta t \), based on our stability conditions.
subroutine calcfngn ()
 Calculates intermediate step of \( F_n \) and \( G_n \). Reference Harlow & Welch (1965) for explanation.
subroutine calcqn ()
 \( Q_n \) is calculated as a source for the RHS of the pressure Poisson equation.
subroutine calcvel ()
 This subroutine calculates velocity of the field and stores the data in the module.
subroutine vort (w)
 Calculates vorticity based on velocity field.
subroutine poisson ()
 Poisson solver for the pressure field.
subroutine parpoisson ()
 Parallelized Poisson solver.

Public Attributes

double precision, dimension(nx, ny) u
 Instantaneous velocity in x-direction, \( u_{i,j}^{n+1} \).
double precision, dimension(nx, ny) v
 Instantaneous velocity in y-direction, \( v_{i,j}^{n+1} \).
double precision, dimension(nx, ny) p
 Scalar pressure at cell center \( P_{i,j} \).
double precision, dimension(nx, ny) fn
 See Harlow & Welch 1965.
double precision, dimension(nx, ny) gn
 See Harlow & Welch 1965.
double precision, dimension(nx, ny) q
 Pressure source term for Poisson.

Detailed Description

The MAC Method solver and it's persistent data.

Definition at line 33 of file mac.f90.


Member Function/Subroutine Documentation

subroutine solver::calcfngn ( )

Calculates intermediate step of \( F_n \) and \( G_n \). Reference Harlow & Welch (1965) for explanation.

These variables are calculated based on the previous time-step's velocity. \( F_n \) is:

\[ F_{i+\frac{1}{2},j}^n = u_{i+\frac{1}{2},j} + \Delta t \left [ \frac{u^n_{i+\frac{3}{2},j} - 2u^n_{i+\frac{1}{2},j} + u^n_{i-\frac{1}{2},j}}{Re(\Delta x)^2} + \frac{u^n_{i+\frac{1}{2},j-1} - 2u^n_{i+\frac{1}{2},j} + u^n_{i+\frac{1}{2},j-1}}{Re(\Delta y)^2} - \frac{(uv)^n_{i+\frac{1}{2},j+\frac{1}{2}} - (uv)^n_{i-\frac{1}{2},j-\frac{1}{2}}}{\Delta y} \right ] \]

\( G_n \) is defined as:

\[ G_{i,j+\frac{1}{2}}^n = v_{i,j+\frac{1}{2}} + \Delta t \left [ \frac{v^n_{i+1,j+\frac{1}{2}} - 2v^n_{i,j+\frac{1}{2}} + v^n_{i-1,j+\frac{1}{2}}}{Re(\Delta x)^2} + \frac{v^n_{i,j+\frac{3}{2}} - 2v^n_{i,j+\frac{1}{2}} + u^n_{i,j-\frac{1}{2}}}{Re(\Delta y)^2} - \frac{(uv)^n_{i+\frac{1}{2},j+\frac{1}{2}} - (uv)^n_{i-\frac{1}{2},j-\frac{1}{2}}}{\Delta y} - \frac{(v^n_{i,j+1})^2 - (v^n_{i,j})^2}{\Delta y} \right ] \]

Definition at line 197 of file mac.f90.

subroutine solver::calcqn ( )

\( Q_n \) is calculated as a source for the RHS of the pressure Poisson equation.

It is calculated based on the values of \( F_n \) and \( Q_n \) calculated in the routine calcfngn().

\[ Q^n_{i,j} = \left [ \frac{P_{i-1,j} -2P_{i+1,j}}{(\Delta x)^2} + \frac{P_{i,j-1} - 2P_{i,j} + P_{i,j+1}}{(\Delta y)^2}\right ]^{n+1} \]

which may be discretized to show:

\[ Q^n_{i,j} = \frac{1}{\Delta t} \left [ \frac{F^n_{i+\frac{1}{2},j} - F^n_{i-\frac{1}{2},j}}{\Delta x} + \frac{G^n_{i,j+\frac{1}{2}} - G^n_{i,j-\frac{1}{2}}}{\Delta y} \right ]. \]

Definition at line 235 of file mac.f90.

subroutine solver::calctstep ( )

Calculates are maximum allowable timestep, \( \Delta t \), based on our stability conditions.

The first stability condition to be evaluated is:

\[ \Delta t = Re \Delta x \Delta y * r \]

Where \( r \) must be less than 0.25. The second stability condition, called the CFL condition, is shown to be:

\[ \Delta t = \frac{4}{Re (|u|+|v|)^2} \]

We take the minimum of these two conditions to ensure stability.

Definition at line 143 of file mac.f90.

subroutine solver::calcvel ( )

This subroutine calculates velocity of the field and stores the data in the module.

Values of the velocity may be accessed in Python from the routines returnu() and returnv(). The velocity is calculated by the equations:

\[ u_{i+\frac{1}{2},j}^{n+1} = F_{i+\frac{1}{2},j}^n - \frac{\Delta t}{\Delta x}(P_{i+1,j}^{n+1} - P_{i,j}^{n+1}) \]

\[ v_{i+,j+\frac{1}{2} }^{n+1} = G_{i,j+\frac{1}{2} }^n - \frac{\Delta t}{\Delta x}(P_{i,j+1}^{n+1} - P_{i,j}^{n+1}) \]

Definition at line 261 of file mac.f90.

subroutine solver::ghostcondition ( )

Applies ghost cell boundary conditions at the walls.

For a rectanglular shape, we see that:

\[ u|_{L_x=0} = 0\]

\[u|_{L_x=1} = 0\]

\[v|_{L_y=0} = 0\]

\[v|_{L_y=1} = 0 \]

This mathematically states that a fluid element cannot pass through a wall.

Definition at line 83 of file mac.f90.

subroutine solver::initzero ( )

Initialize all variables with zero values.

Definition at line 46 of file mac.f90.

subroutine solver::lidcondition ( )

Applies a moving lid to the top of the cavity, and a no slip condition at every other wall.

The no slip condition discretized for MAC Method is posed as such:

\[ u|_{L_y=0} = 0\]

\[u|_{L_y=1} = 1\]

\[v|_{L_x=0} = 0\]

\[v|_{L_x=1} = 0 \]

Definition at line 114 of file mac.f90.

subroutine solver::parpoisson ( )

Parallelized Poisson solver.

Todo:
Parallel Poisson solver does not currently work due to F2Py bug with OpenMP barriers. Use the function poisson()

Definition at line 373 of file mac.f90.

subroutine solver::poisson ( )

Poisson solver for the pressure field.

The equation for the pressure field is defined to be:

\[ \nabla^2 P = Q_n \]

For two dimensions the equation becomes

\[ \frac{\partial P}{\partial x} + \frac{\partial P}{\partial y} - Q_n = 0 \]

In discretized form, using an explicit Gauss-Seidel method, we see

\[ P^{n+1}_{i,j} = \frac{1}{4} \left [ P^{n+1}_{i-1,j} + P^{n+1}_{i,j-1} + P^n_{i+1,j} + P^n_{i,j+1} - (\Delta x)^2 Q^n_{i,j}\right ] \]

Definition at line 319 of file mac.f90.

subroutine solver::returnp ( double precision, dimension(nx,ny), intent(out)  array)

Accessor for Pressure.

Parameters:
[out]arrayFunction returns a Numpy array of P

Definition at line 68 of file mac.f90.

subroutine solver::returnu ( double precision, dimension(nx,ny), intent(out)  array)

Accessor for U-Velocity.

Parameters:
[out]arrayFunction returns a Numpy array of U

Definition at line 56 of file mac.f90.

subroutine solver::returnv ( double precision, dimension(nx,ny), intent(out)  array)

Accessor for V-Velocity.

Parameters:
[out]arrayFunction returns a Numpy array of V

Definition at line 62 of file mac.f90.

subroutine solver::vort ( double precision, dimension(nx,ny), intent(out)  w)

Calculates vorticity based on velocity field.

Vorticity is mathematically defined as half the curl of the velocity field.

\[ \omega = \frac{1}{2} \nabla \times \bar U \]

Definition at line 290 of file mac.f90.


Member Data Documentation

double precision, dimension(nx,ny) solver::fn

See Harlow & Welch 1965.

Definition at line 39 of file mac.f90.

double precision, dimension(nx,ny) solver::gn

See Harlow & Welch 1965.

Definition at line 40 of file mac.f90.

double precision, dimension(nx,ny) solver::p

Scalar pressure at cell center \( P_{i,j} \).

Definition at line 38 of file mac.f90.

double precision, dimension(nx,ny) solver::q

Pressure source term for Poisson.

Definition at line 41 of file mac.f90.

double precision, dimension(nx,ny) solver::u

Instantaneous velocity in x-direction, \( u_{i,j}^{n+1} \).

Definition at line 36 of file mac.f90.

double precision, dimension(nx,ny) solver::v

Instantaneous velocity in y-direction, \( v_{i,j}^{n+1} \).

Definition at line 37 of file mac.f90.


The documentation for this module was generated from the following file: