Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dhruvDev23
Copy link

Issue #242 Fix

Problem:
The grid library only supported interpolation on orthogonal grids (axes aligned with Cartesian coordinates). It couldn't handle parallelepiped grids (non-orthogonal, skewed axes).

Solution:
Added support for non-orthogonal grids using coordinate transformation with the inverse Jacobian matrix.

Key Changes Made:

  1. Core Implementation (src/grid/cubic.py)
  • Added is_orthogonal(): checks if grid axes are orthogonal or skewed.
  • Added _interpolate_parallelepiped(): Handles interpolation on non-orthogonal grids using scipy.interpn.
  • Added _closest_point_general(): Finds closest points on non-orthogonal grids.
  • Modified interpolate(): Automatically routes to correct method based on grid type.
  • Modified closest_point(): Works with both orthogonal and non-orthogonal grids.
  1. Mathematical Approach
  • Uses inverse Jacobian matrix for coordinate transformation.
  • Converts from Cartesian system to grid's internal coordinate system,
  1. Tests (src/grid/tests/test_cubic.py)
  • Added 2 new tests for non-orthogonal functionality.
  • Updated 1 existing test to support non-orthogonal grids.
  • All 33 cubic grid tests pass.
  1. Example (examples/parallelepiped_interpolation.py)
  • Created working example demonstrating the new functionality

- Add is_orthogonal() method to detect non-orthogonal grids
- Add _interpolate_parallelepiped() method using scipy.interpn with coordinate transformation
- Add _closest_point_general() method for non-orthogonal grids
- Modify interpolate() to automatically select interpolation method
- Update closest_point() to work with non-orthogonal axes
- Add comprehensive tests for non-orthogonal interpolation
- Add example demonstrating parallelepiped interpolation functionality
- Maintain full backward compatibility with existing orthogonal grids

Uses inverse Jacobian matrix (axes^(-1)) for coordinate transformation:
grid_coords = (cartesian_coords - origin) × axes^(-1)

All 33 cubic grid tests pass, including 2 new tests for non-orthogonal functionality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant