docs: annotate compact difference and compiler stage cores using standard conventions
All checks were successful
Deploy Documentation / build-and-deploy (push) Successful in 1m10s

This commit is contained in:
ignis 2026-06-01 06:37:38 +00:00
parent 94e2988ed1
commit b37f869cc5
4 changed files with 118 additions and 16 deletions

View file

@ -1,18 +1,18 @@
!> @author Ignis
!> @brief High-order compact finite difference scheme solver.
!> @brief order of accuracy를 compact finite difference scheme (generalized Padé scheme) .
!!
!! This module handles the generation of tridiagonal/pentadiagonal matrices,
!! LU decomposition calculations, and tridiagonal solver operations for periodic
!! and non-periodic boundary conditions.
!! high-order compact .
!! Compact implicit , implicit
!! tridiagonal matrix solver(stdlu, ptdlu ) .
MODULE Compact
use, intrinsic :: iso_fortran_env, only: real64
IMPLICIT NONE
REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: lxf,lxs,wxf,wxs, &
lyf,lys,wyf,wys, &
lzf,lzs,wzf,wzs
REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: lxf,lxs,wxf,wxs, & !< x- LU Decomposition
lyf,lys,wyf,wys, & !< y- LU Decomposition
lzf,lzs,wzf,wzs !< z- LU Decomposition
INTEGER :: nxc,nyc,nzc
INTEGER :: nxc,nyc,nzc !< (x, y, z)
REAL(KIND=8), PARAMETER :: ezero = 1.0e-14
@ -43,6 +43,17 @@
END SUBROUTINE ludcmp
!> LU workspace .
!!
!! (xp, yp, zp = 0 , 1 )
!! , (STOP).
!!
!! @param nx Grid size in x-direction.
!! @param ny Grid size in y-direction.
!! @param nz Grid size in z-direction.
!! @param xp Periodic flag for x-direction (0 = periodic, other = non-periodic).
!! @param yp Periodic flag for y-direction (0 = periodic, other = non-periodic).
!! @param zp Periodic flag for z-direction (0 = periodic, other = non-periodic).
SUBROUTINE ludcmp_allocate(nx,ny,nz,xp,yp,zp)
INTEGER, INTENT(IN) :: nx,ny,nz
INTEGER, INTENT(IN) :: xp,yp,zp

View file

@ -6,7 +6,17 @@ from sympy.printing.fortran import FCodePrinter
@v_args(inline=True)
class LarkToSympy(Transformer):
"""Transformer that parses Lark AST mathematical nodes into SymPy expression objects.
This recursively traverses the AST for algebraic equations, mapping operations,
constants, brackets, and custom derivative definitions directly to standard SymPy nodes.
"""
def __init__(self, fdict):
"""Initializes the Lark-to-SymPy transformer.
Args:
fdict (dict): Dictionary mapping variables to their Field definitions.
"""
self.fdict = fdict
def number(self, numeral):
@ -1083,9 +1093,18 @@ call MPI_ALLREDUCE(MPI_IN_PLACE, {{ name }}, nxp, MPI_REAL8, MPI_SUM, MPI_COMM_T
class Stage1():
''' conversion from tree to python data '''
"""First compilation stage. Performs conversion of Lark AST tree into Python field datasets.
This uses a visitor class to collect all algebraic equations, primary variables,
derived fields, and average specs from the parsed DSL input.
"""
def __init__ (self, raw_tree):
"""Initializes Stage 1 by parsing the raw AST tree.
Args:
raw_tree (lark.Tree): The parsed AST representation of the DSL input.
"""
self.primary = set([])
self.derived = {}
self.averaged = {}
@ -1098,9 +1117,18 @@ class Stage1():
class Stage2():
''' expand derivatives and averages'''
"""Second compilation stage. Expands derivative and fluctuation terms.
This stage traverses the collected definitions, resolving and creating matching
derived fields for derivatives, fluctuations, and weighted averages.
"""
def __init__ (self, src):
"""Initializes Stage 2 by expanding variables from the previous stage.
Args:
src (Stage1): Completed Stage 1 compilation dataset.
"""
self.src = src
self.primary = src.primary
self.derived = src.derived
@ -1144,9 +1172,19 @@ class Stage2():
class Stage3():
''' calculate execution order '''
"""Third compilation stage. Calculates the topological execution order.
Resolves dependencies between algebraic equations and calculates the correct order
of calculations. It splits calculation passes into two distinct execution blocks
(Pre-averaging Pass 1, and Post-averaging Pass 2) using a topological sorter.
"""
def __init__ (self, src):
"""Initializes Stage 3 by resolving execution flows.
Args:
src (Stage2): Completed Stage 2 dataset.
"""
self.src = src
self.primary = src.primary
self.derived = src.derived
@ -1291,8 +1329,18 @@ close (200)
class Stage4():
''' analyze liveness and allocate array '''
"""Fourth compilation stage. Performs variable liveness analysis and memory pooling.
Analyzes variable lifetimes inside loops to perform cache-friendly array pooling.
It leverages SymPy to simplify expressions, count flops, extract Common Subexpressions (CSE),
and compile highly optimized Fortran calculations with minimal memory footprint.
"""
def __init__ (self, src):
"""Initializes Stage 4.
Args:
src (Stage3): Completed Stage 3 execution order.
"""
self.src = src
self.primary = src.primary
self.derived = src.derived

View file

@ -1,9 +1,9 @@
!> @author Google DeepMind Team & Ignis
!> @brief DNS post-processing mathematical operations and derivatives.
!> @brief (Flow domain) x, y, z compact (Cache) .
!!
!! This module calculates spatial derivatives (first and second derivatives in X, Y, Z directions)
!! using high-order compact finite difference schemes. It also calculates chemical reaction rates,
!! positive/negative component extraction, and threshold operations.
!! 3 .
!! 1 2 (ddx, ddy, ddz ) ,
!! (Cache blocking) (Transpose) (`tp2`) .
module m_calculate
use, intrinsic :: iso_fortran_env, only: real64

View file

@ -2,8 +2,27 @@ import numpy as np
from compact import compact
class CompactScheme:
"""Python wrapper for the high-order compact finite difference scheme core.
This wraps the compiled Fortran `compact` solver module, handling grid configurations,
boundary periodicities, array allocations, and LU decompositions. It exposes
differentiation methods ddx, ddy, and ddz to Python.
"""
def __init__ (self, nx, ny, nz, px, py, pz, lx, ly, lz):
"""Initializes the CompactScheme solver.
Args:
nx (int): Grid points in X direction.
ny (int): Grid points in Y direction.
nz (int): Grid points in Z direction.
px (bool): Periodic boundary condition flag for X direction.
py (bool): Periodic boundary condition flag for Y direction.
pz (bool): Periodic boundary condition flag for Z direction.
lx (float): Domain size in X direction.
ly (float): Domain size in Y direction.
lz (float): Domain size in Z direction.
"""
pi8 = np.arccos(-1., dtype=np.float64)
@ -196,6 +215,14 @@ class CompactScheme:
def ddx (self, src):
"""Computes the first-order spatial derivative in the X direction.
Args:
src (numpy.ndarray): 3D input field array matching (nz, ny, nx) shape.
Returns:
numpy.ndarray: 3D first derivative array in the X direction.
"""
if src.shape != self.shape:
print ("error")
@ -219,6 +246,14 @@ class CompactScheme:
return dst
def ddy (self, src):
"""Computes the first-order spatial derivative in the Y direction.
Args:
src (numpy.ndarray): 3D input field array matching (nz, ny, nx) shape.
Returns:
numpy.ndarray: 3D first derivative array in the Y direction.
"""
if src.shape != self.shape:
print ("error")
@ -242,6 +277,14 @@ class CompactScheme:
return dst
def ddz (self, src):
"""Computes the first-order spatial derivative in the Z direction.
Args:
src (numpy.ndarray): 3D input field array matching (nz, ny, nx) shape.
Returns:
numpy.ndarray: 3D first derivative array in the Z direction.
"""
if src.shape != self.shape:
print ("error")