Skip to content

Julia Wrapper for BATL Mesh Generation #168

@henry2004y

Description

@henry2004y

Objective

Create a native Julia interface for the Fortran-based BATL (Block-Adaptive Tree Library) mesh generation routines. The architecture will utilize an iso_c_binding Fortran layer to expose a stable C Application Binary Interface (ABI), which will be cross-compiled via BinaryBuilder.jl and accessed in Julia using ccall.

The plan is to create a new wrapper package BATL.jl.

Phase 1: Fortran C-Binding Layer

Develop the translation layer to expose BATL routines without Fortran name-mangling issues.

  • Create batl_c_api.f90 utilizing the iso_c_binding module.
  • Write C-compatible wrapper subroutines for core mesh initialization (e.g., batl_initialize_mesh_c).
  • Write getter functions to expose block coordinates, refinement levels, and ghost cell data.
  • Ensure all input/output arguments use strictly C-compatible types (e.g., c_int, c_double).
  • Draft a local Makefile or CMakeLists.txt to compile the source and wrapper into a local shared object (.so) for initial testing.

Phase 2: Cross-Compilation System (BinaryBuilder.jl)

Set up the automated build pipeline to distribute precompiled binaries, eliminating the need for end users to maintain local Fortran compilers.

  • Write a build_tarballs.jl script for the BATL source.
  • Configure the build script to compile with -fPIC and link the shared library properly.
  • Run BinaryBuilder.jl to generate binaries across standard target platforms (Linux, macOS, Windows).
  • Publish the resulting artifact as a JLL package (e.g., BATL_jll.jl).

Phase 3: Julia Wrapper Package

Build the user-facing Julia package to interact with the precompiled BATL library.

  • Initialize the new Julia package structure (e.g., BATLMesh.jl).
  • Add the newly generated BATL_jll.jl as a dependency in Project.toml.
  • Implement the low-level ccall bindings in a dedicated submodule or file (e.g., src/CAPI.jl).
  • Design high-level Julia structs and methods to safely wrap the C pointers and manage the memory lifecycle of the mesh data.

Phase 4: VTK Integration and Validation

Ensure the mapped data behaves correctly and integrates with standard visualization workflows.

  • Write unit tests to verify mesh initialization matches expected block counts and refinement hierarchies.
  • Implement a conversion utility to map the extracted BATL block coordinates directly into vtkUniformGrid structures.
  • Assemble the uniform grids into a vtkNonOverlappingAMR dataset for validation in ParaView.
  • Verify memory stability and check for memory leaks when passing array pointers back and forth between Fortran and Julia.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions