NeuralFlowTheory & User Reference Manual
PyNeuralFlow Guide
LIKUA HomeManual Home
NeuralFlow User's Guide v2.0 — Chapter 17

17 PyNeuralFlow Guide

Advanced Python scripting reference containing syntax templates and parallel session wrapper links.

17.1 Introduction & Architecture Overview

PyNeuralFlow is a dedicated Python interface that wraps the core NeuralFlow solver engine and bypasses the GUIX-H graphical user interface. By enabling direct command-line and script-driven access to the solver pipeline, PyNeuralFlow allows users to execute simulations in a completely headless environment, automate complex CFD workflows, and integrate NeuralFlow into larger computational frameworks.

This architecture is particularly tailored for high-volume engineering tasks and unattended computational runs where interacting with a GUI is either inefficient or infeasible. Key use cases and operational advantages include:

  • Automated Sequential Runs (e.g., Aerodynamic Database Generation): Constructing comprehensive aerodynamic tables requires executing hundreds of boundary condition combinations (e.g., sweeping across varying angles of attack, sideslip angles, and Mach numbers). PyNeuralFlow can programmatically iterate through these parameters, updating boundary conditions, running the solver, and exporting results automatically.

  • Unattended & Long-Term Execution: For extended transient or high-resolution steady simulations that run overnight or across multiple days, PyNeuralFlow eliminates the overhead of a graphical desktop environment. Scripts can be executed directly on remote High-Performance Computing (HPC) nodes, servers, or background clusters.

  • Batch Processing & Parametric Studies: Multiple mesh configurations, turbulence models, or physical parameters can be queued in a single Python script with custom exception handling and automated restart capabilities.

17.2 PyNeuralFlow Execution & Parallel Session Management

This section will cover launching the solver via Python scripts, loading grid/case files programmatically, and configuring multi-core parallel (MPI) execution parameters.

17.3 Syntax Reference & Command Templates

This section presents a function-by-function reference of the PyNeuralFlow2D Python interface, detailing function signatures, argument placeholders, available enumeration choices, and operational behaviors.

17.3.1 Detailed API Command Reference

This subsection provides a comprehensive function-by-function reference of the PyNeuralFlow2D and PyNeuralFlow3D Python interfaces. Function signatures, input argument placeholders, explicit enumeration choices, and solver actions are detailed below.

17.3.1.1 Importing Solver and Operating System

At the top of every PyNeuralFlow script, the user must import the solver interface module corresponding to the problem dimensionality: PyNeuralFlow2D for two-dimensional/axisymmetric problems or PyNeuralFlow3D for full three-dimensional configurations. Additionally, Python’s native os module is imported to facilitate system-level file path resolution and working directory settings.

import PyNeuralFlow2D  # Use import PyNeuralFlow3D for 3D computational domains
import os

17.3.1.2 Process Lifecycle and MPI Management

  • PyNeuralFlow2D.start_neuralflow(): Initializes the core solver runtime engine, sets up MPI communicators, and prepares memory allocations. Must be called prior to invoking any solver operations.

  • PyNeuralFlow2D.is_main_process() bool: Returns True on the root process (Rank 0) controlling execution flow; returns False on worker ranks.

  • PyNeuralFlow2D.worker_loop(): Enters an execution loop on non-root MPI processes, awaiting calculation commands dispatched by the root process.

  • PyNeuralFlow2D.stop_neuralflow(): Terminates the solver session, releases memory allocations, and shuts down MPI communication channels.

17.3.1.3 Environment, Mesh Setup & Wall Distance

  • PyNeuralFlow2D.set_working_directory(path): Sets the active working directory for input/output operational files.

  • PyNeuralFlow2D.read_mesh("MeshFileName.msh"): Imports and builds the internal unstructured computational grid from the specified file.

  • PyNeuralFlow2D.set_axisymmetric(enable): Toggles planar 2D formulation (False) versus axisymmetric 2D formulation (True).

  • PyNeuralFlow2D.set_wall_distance_method(
    PyNeuralFlow2D.EWallDistanceMethod.Method): Specifies the numerical algorithm used to calculate closest wall distances for turbulence models. Available options for Method:

    • DIRECT_SEARCH: Geometric direct search algorithm.

    • POISSON: Differential Poisson equation approach for wall distance calculation.

    • FAST_MARCHING: Fast marching method on grid nodes.

  • PyNeuralFlow2D.set_cell_zone_phase(Zone_Name="zone",
    Phase=PyNeuralFlow2D.EPyCellZonePhase.Phase): Assigns the phase domain type to a specific cell zone. Available options for Phase:

    • FLUID: Designates the cell zone as fluid continuum.

    • SOLID: Designates the cell zone as solid conducting domain.

17.3.1.4 Physical Models, Governing Equations & Turbulence

  • PyNeuralFlow2D.set_flow_model(
    PyNeuralFlow2D.EFlowModel.Model): Defines governing fluid dynamics equations. Available options for Model:

    • INVISCID: Inviscid compressible flow formulation (Euler equations).

    • LAMINAR: Laminar compressible Navier-Stokes equations without turbulence closure.

    • GE_RANS: Generalized Reynolds-Averaged Navier-Stokes formulation for turbulent flows.

    • SAS: Scale-Adaptive Simulation model for scale-resolving unsteady turbulent flows.

    • LES: Large Eddy Simulation model (Note: Experimental / not in active production use).

  • PyNeuralFlow2D.set_SST_m_model(
    PyNeuralFlow2D.ESSTmModel.State): Toggles the modified SST turbulence formulation. Available options for State:

    • ON: Enable modified SST formulation.

    • OFF: Disable modified SST formulation.

  • PyNeuralFlow2D.set_realizable_scale(
    PyNeuralFlow2D.ERealizableScaleOption.State): Controls realizable time-scale limiting in turbulence modeling. Available options for State: ON, OFF.

  • PyNeuralFlow2D.set_eCurvatureCorrection(
    PyNeuralFlow2D.ECurvatureCorrection.Method): Applies rotation/curvature correction terms to turbulence model equations. Available options for Method:

    • OFF: No curvature correction active.

    • SMIRNOV_MENTER: Smirnov-Menter rotation and curvature correction model.

    • HELLSTEN: Hellsten rotation and curvature correction model.

  • PyNeuralFlow2D.set_viscous_dissipation(
    PyNeuralFlow2D.EViscousDissipation.State): Toggles viscous dissipation heating in the energy equation. Available options for State: ON, OFF.

  • PyNeuralFlow2D.set_BL_viscous_heating(
    PyNeuralFlow2D.EBLViscousHeating.State): Controls viscous heating specifically within boundary layer regions. Available options for State: ON, OFF.

17.3.1.5 Multi-Phase & Dispersed-Phase Modeling

  • PyNeuralFlow2D.set_dispersed_phase_solution(
    PyNeuralFlow2D.EDispersedPhaseSolution.State): Enables or disables the Eulerian dispersed-phase particulate solver module. Available options for State: ON, OFF.

  • PyNeuralFlow2D.set_interfacial_area_transport(
    PyNeuralFlow2D.EInterfacialAreaTransport.State): Toggles the Interfacial Area Transport Equation (IATE) model for dispersed-phase dynamics. Available options for State: ON, OFF.

  • PyNeuralFlow2D.set_particle_flux_type(
    PyNeuralFlow2D.EParticleFluxType.Type): Defines the numerical flux function for particulate phase transport. Available options for Type:

    • STANDARD: Standard advective particle flux formulation.

    • RUSANOV: Rusanov local Lax-Friedrichs flux scheme.

    • AUSM: Advection Upstream Splitting Method for particle phase.

    • HLLC: Harten-Lax-van Leer-Contact flux scheme for particle phase.

17.3.1.6 Temporal Discretization & Problem Configuration

  • PyNeuralFlow2D.set_ProblemType(
    PyNeuralFlow2D.EProblemType.Type): Defines temporal solver mode. Available options for Type:

    • STEADY: Steady-state pseudo-time integration.

    • TRANSIENT: Unsteady time-accurate integration.

  • PyNeuralFlow2D.set_implicit_temporal_discretisation(
    PyNeuralFlow2D.EImplicitTemporalDiscretisation.Order): Sets temporal order of accuracy for implicit transient stepping. Available options for Order:

    • FirstOrder: First-order implicit Euler scheme.

    • SecondOrder: Second-order accurate implicit temporal discretization.

17.3.1.7 Spatial Discretization, Gradients & Numerics

  • PyNeuralFlow2D.set_reconstruction_method(
    PyNeuralFlow2D.EReconstructionMethod.Method): Defines spatial flux reconstruction order across cell faces. Available options for Method:

    • FIRST_ORDER: First-order upwind reconstruction scheme.

    • SECOND_ORDER: High-resolution second-order reconstruction scheme.

    • BCDS: Bounded Central Difference Scheme.

  • PyNeuralFlow2D.set_gradient_method(
    PyNeuralFlow2D.EGradientMethod.Method): Specifies cell-centered gradient calculation strategy. Available options for Method:

    • GREEN_GAUSS: Cell-based Green-Gauss theorem formulation.

    • LEAST_SQUARE: Cell-based Weighted Least-Squares gradient reconstruction.

    • NODE_BASED_LEAST_SQUARE: Node-based Least-Squares gradient reconstruction for irregular meshes.

  • PyNeuralFlow2D.set_slope_limiter(
    PyNeuralFlow2D.ESlopeLimiter.Limiter): Selects monotonicity slope limiter for second-order spatial reconstruction. Available options for Limiter:

    • BartJespersen: MinMod / Bart-Jespersen non-differentiable limiter.

    • Differentiable: Smooth differentiable limiter function.

    • ModifiedVenkatakrishnan: Venkatakrishnan limiter modified for unstructured grids.

  • PyNeuralFlow2D.set_flux_type(
    PyNeuralFlow2D.EFluxType.Type): Defines inviscid numerical flux calculation scheme. Available options for Type:

    • AUSM: Advection Upstream Splitting Method family.

    • HLLC: Harten-Lax-van Leer-Contact Riemann solver scheme.

  • PyNeuralFlow2D.set_wave_speeds_method(
    PyNeuralFlow2D.EWaveSpeedsMethod.Method): Defines acoustic wave speed estimation method in Riemann solvers. Available options for Method:

    • ALL_SPEEDS: Preconditioned wave speed formulation for low-to-high Mach regimes.

    • DAVIS: Davis direct wave speed bounds estimation.

    • EINFIELDT: Einfeldt signal speed estimate.

  • PyNeuralFlow2D.set_limiting_direction(
    PyNeuralFlow2D.ELimitingDirection.Direction): Controls slope limiter evaluation stencil. Available options for Direction:

    • CELL_TO_CELL: Limiting computed based on neighbor cell centroids.

    • CELL_TO_FACE: Limiting evaluated directly at face quadrature points.

  • PyNeuralFlow2D.set_Preconditioning(
    PyNeuralFlow2D.EPreconditioning.State): Toggles low-Mach preconditioning matrix. Available options for State: ON, OFF.

17.3.1.8 Material Database and Assignment

  • PyNeuralFlow2D.import_User_Defined_Mat_List("database.mdb"): Reads thermodynamic and transport material properties from a specified database file.

  • PyNeuralFlow2D.add_material_from_UserDefinedLib(
    Mat_Type=PyNeuralFlow2D.EPyMaterialType.Type,
    Material_Name="Name"): Loads a material entry into the solver memory. Available options for Type:

    • FLUID: Fluid thermodynamic phase property definition.

    • SOLID: Solid thermal conduction property definition.

    • PARTICLE: Dispersed particulate phase property definition.

  • PyNeuralFlow2D.set_material_to_fluid_domain(
    Material_Name="Name"): Assigns an active material entry to fluid computational zones.

17.3.1.9 Boundary Condition Definitions

  • PyNeuralFlow2D.set_mass_flow_inlet_BC(
    BC_Name="name",
    Mass_Input_Type=PyNeuralFlow2D.EPyMassFlowInletType.Type,
    Mass_Input=val, P_supersonic=p_sup,
    refPressure=p_ref, T_total=t_tot,
    Turbulence_K=k, Turbulence_omega=omega):
    Prescribes mass inlet conditions. Available options for Type:

    • MASS_FLOW_RATE: Total inlet mass flow rate .

    • MASS_FLUX: Mass flux per unit area .

  • PyNeuralFlow2D.set_pressure_outlet_BC(
    BC_Name="name", P=pressure,
    Outlet_Type=PyNeuralFlow2D.EPressureOutletType.Type):
    Sets pressure boundary conditions at domain outlets. Available options for Type:

    • FORCED: Explicitly forced backpressure .

    • INTERPOLATED: Pressure extrapolated from interior domain cells.

  • PyNeuralFlow2D.set_wall_BC(
    BC_Name="name",
    WallThermalBoundaryCondition=
    PyNeuralFlow2D.EBoundaryWallThermalCondition.Condition, [...]):
    Applies thermal wall conditions. Available options for Condition:

    • NONE: No thermal condition applied.

    • ADIABATIC: Zero thermal flux ().

    • CONSTANT_HEAT_FLUX: Fixed wall heat flux .

    • CONST_TEMPERATURE: Fixed wall temperature .

    • CONVECTIVE_HEAT_TRANSFER: External Robin convective heat transfer condition.

    • EXTERNAL_RADIATION: External radiative boundary flux.

    • EXTERNAL_MIXED: Combined external radiation and convective boundary.

  • PyNeuralFlow2D.set_FSI_wall_thermal_BC(
    BC_Name="name",
    ThermalCondition=PyNeuralFlow2D.EFSIWallThermalCondition.Condition):
    Sets thermal conditions for Fluid-Structure Interaction (FSI) surfaces. Available options for Condition: NONE, ADIABATIC, NON_ADIABATIC.

  • PyNeuralFlow2D.set_surface_property(
    BC_Name="name",
    Property=PyNeuralFlow2D.SP_Surface.EPropSurf.Property):
    Assigns time- or pressure-dependent transient boundary profiles. Available options for Property:

    • PressureDependentMassFlux: Mass flux computed dynamically from boundary pressure.

    • TimeDependentMassFlowRate: Time-table transient mass flow rate.

    • TimeDependentTotalPressure: Time-table transient total pressure.

17.3.1.10 Post-Processing, Probes & Surface Integrals

  • PyNeuralFlow2D.get_probe_data(
    Probe_Name="name",
    DataType=PyNeuralFlow2D.EProbeDataType.Type):
    Extracts point or zone monitoring values. Available options for Type:

    • Physical/Thermodynamic:
      Density, Pressure, Temperature, TotalPressure,
      TotalTemperature, InternalEnergy, TotalEnergy,
      TotalEnthalpy, MachNumber, EffViscosity.

    • Kinematic/Velocity:
      XVelocity, YVelocity, ZVelocity,
      VelMag, VorticityMag.

    • Turbulence Data:
      TurbKinEnergy, TurbDissRate,
      TurbViscosity, TurbIntensity.

    • Integral/Force Metrics:
      CenterOfPressure, Force, HeatFlux,
      MassFlowRate, MassFlux.

  • PyNeuralFlow2D.calculate_surface_integral(
    BC_Name="name",
    IntegralType=PyNeuralFlow2D.ESurfaceIntegralType.Type):
    Integrates flow quantities over surface boundaries. Available options for Type:

    • MASS_FLOW_RATE: Net integrated mass flow rate .

    • TOTAL_PRESSURE_FORCE: Pressure force vector component .

    • TOTAL_SHEAR_FORCE: Shear/viscous force vector component .

    • TOTAL_FORCE: Total combined aerodynamic force .

    • MOMENT: Aerodynamic moment vector .

    • MOMENTUM: Net surface momentum flux.

    • AVERAGE_TOTAL_PRESSURE: Area-weighted average total pressure .

    • AVERAGE_TOTAL_TEMPERATURE: Area-weighted average total temperature .

    • PARTICLE_MASS_FLOW_RATE: Dispersed phase particulate mass flow rate .

  • PyNeuralFlow2D.export_vtk_binary(): Exports volumetric domain solution field into binary VTK files.

  • PyNeuralFlow2D.export_zone_vtk_binary("zone_name"): Exports boundary surface solution data into VTK format.

17.3.2 Complete Production Script Archetype

The script below demonstrates how these API components assemble into a complete, automated RANS flow solution with progressive CFL ramping and boundary VTK exports:

import PyNeuralFlow2D
import os

def solve_AkisKKYRM():
    PyNeuralFlow2D.set_working_directory(os.getcwd())
    PyNeuralFlow2D.read_mesh("App_Akis_fluent.msh")

    PyNeuralFlow2D.set_reconstruction_method(
        PyNeuralFlow2D.EReconstructionMethod.SECOND_ORDER
    )
    PyNeuralFlow2D.set_ProblemType(PyNeuralFlow2D.EProblemType.STEADY)

    PyNeuralFlow2D.set_axisymmetric(True)
    PyNeuralFlow2D.set_flow_model(PyNeuralFlow2D.EFlowModel.GE_RANS)

    PyNeuralFlow2D.import_User_Defined_Mat_List("mizrak_db.mdb")
    PyNeuralFlow2D.add_material_from_UserDefinedLib(
        Mat_Type=PyNeuralFlow2D.EPyMaterialType.FLUID, 
        Material_Name="fluidmaterial"
    )
    PyNeuralFlow2D.set_material_to_fluid_domain(
        Material_Name="fluidmaterial"
    )

    PyNeuralFlow2D.set_mass_flow_inlet_BC(
        BC_Name="pressure-inlet", 
        Mass_Input_Type=
            PyNeuralFlow2D.EPyMassFlowInletType.MASS_FLOW_RATE, 
        Mass_Input=100, 
        P_supersonic=5000000.0, 
        refPressure=5500000.0, 
        T_total=3500.0, 
        Turbulence_K=55.15, 
        Turbulence_omega=1.567e7
    )

    PyNeuralFlow2D.set_pressure_outlet_BC(
        BC_Name="pressure-outlet", P=101325
    )
    PyNeuralFlow2D.set_axis_BC(BC_Name="axis")
    PyNeuralFlow2D.set_wall_BC(
        BC_Name="wall_adb", 
        WallThermalBoundaryCondition=
            PyNeuralFlow2D.EBoundaryWallThermalCondition.ADIABATIC
    )
    PyNeuralFlow2D.set_wall_BC(
        BC_Name="wall_cekirdek_temp", 
        WallThermalBoundaryCondition=
            PyNeuralFlow2D.EBoundaryWallThermalCondition.CONST_TEMPERATURE, 
        T_w=2800
    )
    PyNeuralFlow2D.set_wall_BC(
        BC_Name="wall_yalitim_temp", 
        WallThermalBoundaryCondition=
            PyNeuralFlow2D.EBoundaryWallThermalCondition.CONST_TEMPERATURE, 
        T_w=2800
    )
    PyNeuralFlow2D.set_wall_BC(
        BC_Name="wall_yltm_step_temp", 
        WallThermalBoundaryCondition=
            PyNeuralFlow2D.EBoundaryWallThermalCondition.CONST_TEMPERATURE, 
        T_w=2800
    )

    PyNeuralFlow2D.init(
        Cell_Zone_Name="geom-3-bora1305psi", 
        P=7101325, 
        T=2800, 
        U=[30.0, 0.0], 
        Turbulence_K=53.82, 
        Turbulence_omega=1.485e7
    )

    PyNeuralFlow2D.set_Preconditioning(PyNeuralFlow2D.EPreconditioning.ON)
    PyNeuralFlow2D.set_isentMachAccelerator(True)
    PyNeuralFlow2D.set_eCurvatureCorrection(
        PyNeuralFlow2D.ECurvatureCorrection.SMIRNOV_MENTER
    )
    PyNeuralFlow2D.set_AR_Acceleration(True)
    PyNeuralFlow2D.set_minimum_residual(1e-12)

    # Progressive CFL Ramping Strategy
    cfl_steps = [
        (5, 300), (10, 500), (20, 1000), (30, 500), 
        (50, 500), (100, 500), (200, 1500)
    ]
    for cfl, iterations in cfl_steps:
        PyNeuralFlow2D.set_CFL(cfl)
        PyNeuralFlow2D.set_total_iterations(iterations)
        PyNeuralFlow2D.Run()

    # Binary VTK Data Export
    PyNeuralFlow2D.export_vtk_binary()
    PyNeuralFlow2D.export_zone_vtk_binary("axis")
    PyNeuralFlow2D.export_zone_vtk_binary("pressure-outlet")
    PyNeuralFlow2D.export_zone_vtk_binary("wall_cekirdek_temp")
    PyNeuralFlow2D.export_zone_vtk_binary("wall_yltm_step_temp")
    PyNeuralFlow2D.export_zone_vtk_binary("wall_yalitim_temp")

def main():
    PyNeuralFlow2D.start_neuralflow()

    if PyNeuralFlow2D.is_main_process():
        solve_AkisKKYRM()
    else:
        PyNeuralFlow2D.worker_loop()

    PyNeuralFlow2D.stop_neuralflow()

if __name__ == "__main__":
    main()