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]:
- Compute curvature
κ(x) = |f''| / (1 + f'²)^(3/2) on a fine uniform grid
- Define density function
ρ(x) = (κ(x) + ε) / ∫(κ + ε) (ε prevents degenerate spacing)
- Compute CDF
F(x) = ∫_a^x ρ(s) ds
- 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
Source code reference
Thoery_1_Code.ipynb: generate_adaptive_theta_from_curvature(N=5000) — curvature-weighted grid for trait space
Tests
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]:κ(x) = |f''| / (1 + f'²)^(3/2)on a fine uniform gridρ(x) = (κ(x) + ε) / ∫(κ + ε)(ε prevents degenerate spacing)F(x) = ∫_a^x ρ(s) dsx_i = F⁻¹(i/N)for i = 0, ..., NThis concentrates grid points where the solution has high curvature.
Implementation
generate_adaptive_grid(f, domain, n_points, epsilon=1e-3)— from callablegenerate_adaptive_grid_from_data(x, y, n_points, epsilon=1e-3)— from discrete dataSource code reference
Thoery_1_Code.ipynb:generate_adaptive_theta_from_curvature(N=5000)— curvature-weighted grid for trait spaceTests