Skip to content

Compiling & Generating Solvers

To ensure maximum performance with zero runtime overhead, Shardian compiles symbolic expressions directly into the solver source code. This page explains the code generation scripts and the compilation process for both solvers.


1. The Code Generation Workflow

When the symbolic regression search in eml-sr-core discovers a new, higher-performing physical correction model, it saves the mathematical tree as a structured JSON model. Code generator scripts read this model and overwrite the static equations in the C++ (OpenFOAM) and Fortran (WRF) source files.

graph TD
    JSON["model_weights.json"] -->|export_aero_weights.py| CPP["AdvancedZonalModel.C"]
    JSON -->|export_fortran_models.py| F90["module_bl_eml_sr.F"]
    CPP -->|wmake libso| SO["libShardianAero.so"]
    F90 -->|./compile em_real| SIF["shardian_atmos.sif"]

2. Exporting Model Weights

Developers use two utility scripts in the scripts/ directory to update solver models:

A. Shardian Aero Code Generator

Run export_aero_weights.py to compile the symbolic model into the OpenFOAM C++ solver:

python scripts/export_aero_weights.py --model datasets/models/aero_v2.json

This script parses the JSON representation of the expression tree and replaces the target placeholder block in applications/openfoam_cfd/AdvancedZonalModel/AdvancedZonalModel.C:

// GENERATED BY export_aero_weights.py - DO NOT EDIT MANUALLY
scalar f_IA = min(3.0, max(0.1, (0.09 * Re_y) / (1.0 + 0.05 * sqr(S_star) * sqrt(Omega_star))));

B. Shardian Atmos Code Generator

Run export_fortran_models.py to compile the symbolic model into the WRF Fortran boundary layer scheme:

python scripts/export_fortran_models.py --model datasets/models/atmos_v2.json

This generates the corresponding mathematical expressions inside applications/wrf/phys/module_bl_eml_sr.F using nested Fortran arithmetic syntax:

! GENERATED BY export_fortran_models.py - DO NOT EDIT MANUALLY
kB_inv = (Re_star**0.45 * VEGFRA) / (1.0 + 0.23 * Re_star**0.15)

3. Compiling the Solvers

Once the source files are updated, compile the binaries:

A. Compiling Shardian Aero (OpenFOAM)

Navigate to the OpenFOAM CFD directory and execute wmake:

cd applications/openfoam_cfd
wmake libso

This compiles the C++ classes and packages them into the shared library libShardianAero.so, saving it to $FOAM_USER_LIBBIN.

B. Compiling Shardian Atmos (WRF)

To compile WRF with the integrated module_bl_eml_sr.F module:

cd applications/wrf
./clean -a
./configure
# Select option for Intel/GNU compilers with DM+SM (MPI+OpenMP) parallelization
./compile em_real

Once compiled, build the Singularity container to package the executable:

singularity build shardian_atmos.sif Singularity.def