Skip to content

Support interpolation from general-dimension tables#418

Merged
hyschive merged 24 commits intogamer-project:mainfrom
hsinhaoHHuang:InterpolateFromTable
Feb 16, 2026
Merged

Support interpolation from general-dimension tables#418
hyschive merged 24 commits intogamer-project:mainfrom
hsinhaoHHuang:InterpolateFromTable

Conversation

@hsinhaoHHuang
Copy link
Contributor

Goal

Changes

  • Add new functions for the calculation of interpolation

    • Mis_LinearInterpolate() for interpolation of 1D values
    • Mis_BilinearInterpolate() for interpolation of 2D values
    • Mis_TrilinearInterpolate() for interpolation of 3D values
    • Mis_MultilinearInterpolate() for interpolation of general nD values
  • Add new functions for the interpolations from tables

    • Mis_InterpolateFrom2DTable() for interpolation from a 2D table
    • Mis_InterpolateFrom3DTable() for interpolation from a 3D table
    • Mis_InterpolateFrom_nDim_Table() for interpolation from a general nD table
    • Mis_InterpolateFrom_nDim_Table_withIdxL() for interpolation from a general nD table with the IdxL already known
  • Replace the HaloMerger_Trilinear_Interpolation() and HaloMerger_Get_Value_From_HALO_IC_Data in src/TestProblem/ELBDM/HaloMerger/Init_TestProb_ELBDM_HaloMerger.cpp

    • Now, we convert the data into a double-precision array and prepare the coordinates arrays and call the Mis_InterpolateFrom_nDim_Table_withIdxL().
    • The method to deal with the boundary values (1/2 cell size) of the table changes from interpolation with zero to extending values from the surface.
  • Some minor format adjustments in src/TestProblem/ELBDM/HaloMerger/Init_TestProb_ELBDM_HaloMerger.cpp

Verifications

  • The Mis_InterpolateFromTable() for the soliton profile can return the same value as before in TestProblem/ELBDM/HaloMerger

  • The projections of the initial conditions of TestProblem/ELBDM/HaloMerger are the same as before.

  • All unit tests attached in Mis_InterpolateFromTable.cpp and Mis_LinearInterpolate.cpp pass.

    • The answers are calculated by the scipy.interpolate.RegularGridInterpolator
      For example,
      import numpy as np
      from scipy.interpolate import RegularGridInterpolator
      
      def f(x, y, z):
         return x*y*y*z
      
      Table_x = np.array( [ 1.0, 2.0, 3.0, 4.0 ] )
      Table_y = np.array( [ 2.0, 3.0 ] )
      Table_z = np.array( [ 4.0, 5.0, 8.0 ] )
      
      Mesh_x, Mesh_y, Mesh_z = np.meshgrid( Table_x, Table_y, Table_z, indexing='ij' )
      
      Table_f = f(Mesh_x, Mesh_y, Mesh_z)
      
      interp = RegularGridInterpolator( (Table_x, Table_y, Table_z), Table_f, method='linear', bounds_error=False, fill_value=None )
      print( interp( np.array( [xp, yp, zp] ) ) )

@hsinhaoHHuang hsinhaoHHuang changed the title Support more general interpolation from tables Support more general interpolation from general-dimension tables Jan 26, 2025
@hsinhaoHHuang hsinhaoHHuang changed the title Support more general interpolation from general-dimension tables Support interpolation from general-dimension tables Jan 26, 2025
@hyschive hyschive requested a review from ChunYen-Chen February 2, 2025 15:12
@hyschive hyschive added general General issues and improvement new feature labels Feb 2, 2025
@hyschive hyschive requested review from barrytchiang and removed request for ChunYen-Chen February 2, 2025 15:16
@hyschive hyschive assigned barrytchiang and unassigned ChunYen-Chen Feb 2, 2025
Copy link
Contributor

@barrytchiang barrytchiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you again for expanding the array of interpolation functions in GAMER! All the edits, additions, and tests to the code itself look great to me. I've also tested it myself, and everything seems good.

All the comments I left are small things in the text descriptions in this PR. Once these are addressed, it is ready to be merged.

@hsinhaoHHuang
Copy link
Contributor Author

@barrytchiang Thank you for reviewing and testing this PR.
I have fixed the grammatical errors you listed. Thank you for your careful checks!

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hsinhaoHHuang This PR is neat! And good job in adding unit tests for all the newly introduced functionalities! I only have some minor comments before merging.

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hsinhaoHHuang This PR is neat! And good job in adding unit tests for all the newly introduced functionalities! I only have some minor comments before merging.

Copy link
Contributor Author

@hsinhaoHHuang hsinhaoHHuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for all the suggestions! I have updated this PR accordingly.

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hsinhaoHHuang Thanks for the careful revision. Good job!

@hyschive hyschive merged commit ea8c197 into gamer-project:main Feb 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

general General issues and improvement new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Mis_InterpolateFrom2D/3DTable()

4 participants