Skip to content

Adaptive curvature-weighted grid generation #46

@jc-macdonald

Description

@jc-macdonald

Adaptive grid generation utility

Add a utility for generating curvature-weighted non-uniform grids, used as the spatial discretization for trait-structured PDE models.

Algorithm

Given a reference solution or profile function f(x) on domain [a, b]:

  1. Compute curvature κ(x) = |f''| / (1 + f'²)^(3/2) on a fine uniform grid
  2. Define density function ρ(x) = (κ(x) + ε) / ∫(κ + ε) (ε prevents degenerate spacing)
  3. Compute CDF F(x) = ∫_a^x ρ(s) ds
  4. Invert: place N grid points at x_i = F⁻¹(i/N) for i = 0, ..., N

This concentrates grid points where the solution has high curvature.

Implementation

  • generate_adaptive_grid(f, domain, n_points, epsilon=1e-3) — from callable
  • generate_adaptive_grid_from_data(x, y, n_points, epsilon=1e-3) — from discrete data
  • Option: minimum spacing constraint to prevent degenerate cells
  • Option: smoothing of curvature field before inversion

Source code reference

  • Thoery_1_Code.ipynb: generate_adaptive_theta_from_curvature(N=5000) — curvature-weighted grid for trait space

Tests

  • Uniform function → approximately uniform grid
  • Gaussian peak → grid concentrated at peak
  • Monotone refinement: doubling N halves max spacing
  • All grid points within domain bounds

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions