Showing posts with label Meshing. Show all posts
Showing posts with label Meshing. Show all posts

Thursday, April 17, 2014

CFD: Generating Non-Uniform 2D Rectangular Grid Meshes in Fortran

In Computational Fluid Dynamics (CFD), resolving boundary layers and high-gradient shear regions requires non-uniform grid clustering near solid walls while keeping cell counts manageable in free-stream regions. Here is a Fortran routine to generate a geometrically stretched, symmetric 2D rectangular grid.

Domain: Rectangular 2D domain \([a, b] imes [c, d]\) • Method: Geometric progression expansion clustering toward boundaries

Mathematical Formulation

Given domain limits \(x \in [a, b]\) with \(n_x\) divisions and expansion ratio \(r_x\), the initial wall-adjacent step size \(\eta_x\) is computed from the geometric sum across the symmetric half-domain:

eta_x = (b - a) * (1 - exp_x) / (2 * (1 - exp_x**(n_x / 2)))
eta_y = (d - c) * (1 - exp_y) / (2 * (1 - exp_y**(n_y / 2)))

Fortran Source Code

! ====================================================================
! 2D Non-Uniform Symmetric Rectangular Grid Generator
! ====================================================================
      exp_x = 1.05   ! x-axis expansion factor
      exp_y = 1.10   ! y-axis expansion factor

      a = 0.0
      b = 1.0
      c = 0.0
      d = 1.0

! Uniform step sizes for reference
      del_x = (b - a) / n_x
      del_y = (d - c) / n_y

! Compute first wall-adjacent step sizes (eta_x, eta_y)
      eta_x = (b - a) * (1.0 - exp_x) / (2.0 * (1.0 - exp_x**(n_x / 2)))
      eta_y = (d - c) * (1.0 - exp_y) / (2.0 * (1.0 - exp_y**(n_y / 2)))

      x(1) = a
      y(1) = c

! --- X-Direction Mesh Generation ---
! Half 1: Wall to Center (Expanding)
      DO i = 2, n_x / 2 + 1
          x(i) = x(i - 1) + eta_x * exp_x**(i - 2)
      END DO

! Half 2: Center to Opposite Wall (Contracting)
      DO i = n_x / 2 + 2, n_x + 1
          x(i) = x(i - 1) + eta_x * exp_x**(n_x + 1 - i)
      END DO

! --- Y-Direction Mesh Generation ---
! Half 1: Wall to Center (Expanding)
      DO j = 2, n_y / 2 + 1
          y(j) = y(j - 1) + eta_y * exp_y**(j - 2)
      END DO

! Half 2: Center to Opposite Wall (Contracting)
      DO j = n_y / 2 + 2, n_y + 1
          y(j) = y(j - 1) + eta_y * exp_y**(n_y + 1 - j)
      END DO
! ====================================================================

How Google Antigravity Solved the Mysterious NVIDIA Sleep Reboot on My Dell Inspiron 7567 (Ubuntu Linux)

If you run modern Ubuntu or Linux on a Dell Inspiron 15 Gaming (7567) or a similar 7th-gen Intel laptop paired with an NVIDIA GeForce GTX ...