Overview
As outlined in #378 , there is a plan for defining a new grid API object. This development is part of a road map towards MOLE 2.0. Here we outline the road map for the MOLE.jl Julia implementation to match the desired behavior.
Please anyone review and comment to let us know that this is indeed the desired behavior.
cc: @jbrzensk , @Tony-Drummond , @cpaolini
Goal
Introduce a new Grids module that serves as the central data layer for MOLE 2.0 while preserving compatibility with the existing operator implementations.
The new API should allow users to create a grid once and pass that grid object to operators. Example:
grid = makeGrid(m=64, n=64, dx=1/64, dy=1/64)
G = grad(k, grid)
D = div(k, grid)
L = lap(k, grid)
instead of the current:
G = grad(k, m, dx, n, dy)
D = div(k, m, dx, n, dy)
L = lap(k, m, dx, n, dy)
Phase 1: Create the Grids Module
Directory Structure
MOLE.jl
├── src/
├── Grids/
│ ├── Grids.jl
│ ├── topologies.jl
│ ├── make_grid.jl
│ ├── validate_grid.jl
│ └── coordinates.jl
├── Operators/
│ ├── Operators.jl
│ ├── gradient.jl
│ ├── divergence.jl
│ ├── laplacian.jl
│ └── interpol.jl
└── BCs/
├── BCs.jl
├── scalarBC.jl
└── robinBC.jl
Update Package Entry Point
module MOLE
include("Grids/Grids.jl")
include("Operators/Operators.jl")
include("BCs/BCs.jl")
end
Phase 2: Define Grid Types
Grids Data Structure
Create a typed grid object that stores:
- dimensionality
- topology
- spacing information
- coordinate arrays
- boundary metadata
Example:
abstract type AbstractGrid end
struct BoundaryMetadata
isPeriodic::Vector{Bool}
dc::Vector{Float64}
nc::Vector{Float64}
end
struct Grid{T} <: AbstractGrid
dim::Int
topology::Symbol
m::Int
n::Union{Nothing,Int}
o::Union{Nothing,Int}
dx::Union{Nothing,T}
dy::Union{Nothing,T}
dz::Union{Nothing,T}
nodes::NamedTuple
faces::NamedTuple
centers::NamedTuple
bc::BoundaryMetadata
end
Phase 3: Implement makeGrid
User-Facing Constructor
Users should only create grids through:
Examples:
grid = makeGrid(m=100, dx=0.01)
grid = makeGrid(
m=64,
n=64,
dx=1/64,
dy=1/64
)
Responsibilities:
- Collect user inputs.
- Normalize keyword arguments.
- Call
validateGrid.
- Return a fully populated grid object.
Phase 4: Implement validateGrid
Validation Responsibilities
Infer and validate the following:
Dimensions
Determine:
from:
and/or
Topology
Determine:
:uniform
:periodic
:curvilinear
based on:
- coordinate arrays
- periodic boundary flags
Boundary Metadata
Verify:
bc.isPeriodic
bc.dc
bc.nc
Coordinate Arrays
Generate:
for supported grid types.
Phase 5: Coordinate Generation
Uniform Cartesian Grids
Generate:
Nodes
Cell Centers
Face Coordinates
Support:
before extending to 3D.
Phase 6: Add Grid-Based Operator Interfaces
New APIs
Add overloads:
grad(k, grid)
div(k, grid)
lap(k, grid)
interpol(k, grid)
Wrapper Strategy
The new methods should call the existing implementations internally.
Example:
function grad(k, grid::Grid)
if grid.dim == 1
return grad(
k,
grid.m,
grid.dx;
dc=grid.bc.dc,
nc=grid.bc.nc
)
elseif grid.dim == 2
return grad(
k,
grid.m,
grid.dx,
grid.n,
grid.dy;
dc=grid.bc.dc,
nc=grid.bc.nc
)
end
end
Preserve Backward Compatibility
Existing APIs remain unchanged for the migration phase:
grad(k, m, dx)
grad(k, m, dx, n, dy)
Phase 7: Integrate Boundary Conditions
Boundary Metadata Object
Store boundary information directly inside the grid.
More details needed.
Phase 8: Testing
Regression Tests
Verify numerical equivalence between:
Existing API
New API
grid = makeGrid(m=m, dx=dx)
G2 = grad(k, grid)
Tests:
Repeat for:
Phase 9: Documentation
Migration Guide
Create:
docs/src/migration/grid_api.md
Include:
Old Syntax
New Syntax
grid = makeGrid(m=m, dx=dx)
G = grad(k, grid)
Benefits
- simpler user code
- centralized metadata
- future support for curvilinear grids
- easier extension to 3D
Phase 10: Curvilinear Grid Support
After the uniform-grid API is stable:
Add Curvilinear Topology
Support:
using user-supplied coordinates:
grid = makeGrid(
X=X,
Y=Y
)
Curvilinear Coordinate Storage
Store:
grid.nodes.X
grid.nodes.Y
grid.centers.X
grid.centers.Y
grid.faces
using Julia's native array ordering.
Curvilinear Operators
Add specialized implementations for:
that consume the geometric information contained in the grid object.
Recommended Development Order
- Create
julia/MOLE.jl/Grids/
- Define
Grid and BoundaryMetadata
- Implement
makeGrid
- Implement
validateGrid
- Generate 1D uniform coordinates
- Generate 2D uniform coordinates
- Add
grad(k, grid)
- Add
div(k, grid)
- Add
lap(k, grid)
- Add
interpol(k, grid)
- Integrate boundary metadata
- Add documentation and migration guide
- Add curvilinear grid support
- Extend to 3D
Overview
As outlined in #378 , there is a plan for defining a new grid API object. This development is part of a road map towards MOLE 2.0. Here we outline the road map for the MOLE.jl Julia implementation to match the desired behavior.
Please anyone review and comment to let us know that this is indeed the desired behavior.
cc: @jbrzensk , @Tony-Drummond , @cpaolini
Goal
Introduce a new
Gridsmodule that serves as the central data layer for MOLE 2.0 while preserving compatibility with the existing operator implementations.The new API should allow users to create a grid once and pass that grid object to operators. Example:
instead of the current:
Phase 1: Create the
GridsModuleDirectory Structure
Update Package Entry Point
Phase 2: Define Grid Types
Grids Data Structure
Create a typed grid object that stores:
Example:
Phase 3: Implement
makeGridUser-Facing Constructor
Users should only create grids through:
Examples:
Responsibilities:
validateGrid.Phase 4: Implement
validateGridValidation Responsibilities
Infer and validate the following:
Dimensions
Determine:
from:
and/or
Topology
Determine:
based on:
Boundary Metadata
Verify:
Coordinate Arrays
Generate:
for supported grid types.
Phase 5: Coordinate Generation
Uniform Cartesian Grids
Generate:
Nodes
grid.nodesCell Centers
grid.centersFace Coordinates
grid.facesSupport:
before extending to 3D.
Phase 6: Add Grid-Based Operator Interfaces
New APIs
Add overloads:
Wrapper Strategy
The new methods should call the existing implementations internally.
Example:
Preserve Backward Compatibility
Existing APIs remain unchanged for the migration phase:
Phase 7: Integrate Boundary Conditions
Boundary Metadata Object
Store boundary information directly inside the grid.
More details needed.
Phase 8: Testing
Regression Tests
Verify numerical equivalence between:
Existing API
New API
Tests:
Repeat for:
graddivlapinterpolPhase 9: Documentation
Migration Guide
Create:
Include:
Old Syntax
New Syntax
Benefits
Phase 10: Curvilinear Grid Support
After the uniform-grid API is stable:
Add Curvilinear Topology
Support:
using user-supplied coordinates:
Curvilinear Coordinate Storage
Store:
using Julia's native array ordering.
Curvilinear Operators
Add specialized implementations for:
that consume the geometric information contained in the grid object.
Recommended Development Order
julia/MOLE.jl/Grids/GridandBoundaryMetadatamakeGridvalidateGridgrad(k, grid)div(k, grid)lap(k, grid)interpol(k, grid)