Time Advancement

Source Code: NSE_TimeAdvancement

NSE_TimeAdvancement.py
 1# Copyright (C) 2025 Sukanta Basu
 2#
 3# This program is free software: you can redistribute it and/or modify
 4# it under the terms of the GNU General Public License as published by
 5# the Free Software Foundation, either version 3 of the License, or
 6# (at your option) any later version.
 7#
 8# This program is distributed in the hope that it will be useful,
 9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16"""
17File: NSE_TimeAdvancement.py
18===============================
19
20:Author: Sukanta Basu
21:AI Assistance: Claude Code (Anthropic) and Codex (OpenAI) are used for documentation,
22                code restructuring, and performance optimization
23:Date: 2025-4-29
24:Description: implements Adams-Bashforth (AB2) for time integration
25"""
26
27# ============================================================
28#  Imports
29# ============================================================
30
31import jax
32
33# Import configuration from namelist
34from ..config.ConfigLoader import *
35
36# Import derived variables
37from ..config.DerivedVars import *
38
39
40# ============================================================
41#  Time advancement using Adams-Bashforth scheme
42# ============================================================
43
44@jax.jit
45def AB2_uvw(u, v, w,
46            RHS_u, RHS_u_previous,
47            RHS_v, RHS_v_previous,
48            RHS_w, RHS_w_previous):
49    """
50    Parameters:
51    -----------
52    u, v, w : ndarray of shape (nx, ny, nz)
53        Current velocity components
54    RHS_u, RHS_v, RHS_w : ndarray of shape (nx, ny, nz)
55        Current right-hand side terms for velocity components
56    RHS_u_previous, RHS_v_previous, RHS_w_previous :
57        ndarray of shape (nx, ny, nz)
58        Previous right-hand side terms for velocity components
59
60    Returns:
61    --------
62    u_new, v_new, w_new : ndarray of shape (nx, ny, nz)
63        Updated velocity components after time advancement
64    """
65
66    u_new = u + dt_nondim * (1.5 * RHS_u - 0.5 * RHS_u_previous)
67    v_new = v + dt_nondim * (1.5 * RHS_v - 0.5 * RHS_v_previous)
68    w_new = w + dt_nondim * (1.5 * RHS_w - 0.5 * RHS_w_previous)
69
70    # Apply boundary conditions
71    u_new = u_new.at[:, :, nz - 1].set(u_new[:, :, nz - 2])
72    v_new = v_new.at[:, :, nz - 1].set(v_new[:, :, nz - 2])
73    w_new = w_new.at[:, :, nz - 1].set(0.0)
74    w_new = w_new.at[:, :, 0].set(0.0)
75
76    return u_new, v_new, w_new