Skip to content

Lookup tables in more than 3 dimensions#1443

Merged
bcoconni merged 46 commits into
JSBSim-Team:masterfrom
agodemar:n-dimensional-interpolation
May 10, 2026
Merged

Lookup tables in more than 3 dimensions#1443
bcoconni merged 46 commits into
JSBSim-Team:masterfrom
agodemar:n-dimensional-interpolation

Conversation

@agodemar
Copy link
Copy Markdown
Contributor

Pull request as per discussion #1425 (reply in thread)

@bcoconni
Copy link
Copy Markdown
Member

Thanks for the PR @agodemar. I think you need to clean it up a bit:

  • Please remove the files matlab-sfunction-ubuntu.yml and matlab-sfunction.yml from the folder .github/workflows
  • Please remove the changes to cpp-python-build.yml in the folder .github/workflows.
  • Please do not add to .gitignore any *.yml file from the folder .github/workflows. Otherwise any future change to cpp-python-build.yml will be ignored by git.
    • Said otherwise, the following lines should be removed from .gitignore:
.github/workflows/matlab-sfunction-ubuntu.yml
.github/workflows/matlab-sfunction.yml
.github/workflows/cpp-python-build.yml
  • Please remove the file BRANCH_NOTES.md from the branch.
  • Please remove the changes to README.md: you have added a link to your "GitHub Codespace", I do not see much point in including it in the official repo.

I have not yet reviewed the rest of your changes, the suggestions above are only meant to focus the PR to the changes that are directly related to the N dimensional interpolation.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 83.82979% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.18%. Comparing base (3896d4a) to head (01d43d6).

Files with missing lines Patch % Lines
src/math/FGTable.cpp 83.33% 38 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1443      +/-   ##
==========================================
+ Coverage   25.11%   25.18%   +0.06%     
==========================================
  Files         169      169              
  Lines       18721    18783      +62     
==========================================
+ Hits         4702     4730      +28     
- Misses      14019    14053      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@agodemar
Copy link
Copy Markdown
Contributor Author

@bcoconni thank you for your suggestions. I cleand up the PR as you requested

Copy link
Copy Markdown
Member

@bcoconni bcoconni left a comment

Choose a reason for hiding this comment

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

@agodemar I have only reviewed the changes you made since the comments I made in #1425 (comment).

So I made a few comments that, hopefully should make the code slightly easier to read (at least for me).

Comment thread JSBSimCommon.xsd Outdated
Comment thread src/math/FGTable.cpp Outdated
Comment thread src/math/FGTable.cpp Outdated
Comment thread .gitignore Outdated
@bcoconni bcoconni changed the title N dimensional interpolation (2) Lookup tables in more than 3 dimensions Apr 26, 2026
@bcoconni
Copy link
Copy Markdown
Member

I have pushed a couple of commits to this PR to restore the CI workflow (i.e. the file .github/workflows/cpp-python-build.xml and fix a crash in CheckAircrafts.py.

Also I have renamed the PR to the title of the discussion #1425 that you have initiated: Lookup tables in more than 3 dimensions. I think this is clearer than N dimensional interpolation (2) 😃

Finally, for the record, this PR will fix issue #1117.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends FGTable to support lookup tables with more than 3 dimensions by introducing an N-dimensional parsing/evaluation path based on nested <tableData breakPoint="..."> elements, and updates related schema, examples, and unit tests.

Changes:

  • Generalize FGTable parsing and interpolation from fixed 1D/2D/3D to N-D via nested <tableData> breakpoints.
  • Add public APIs for 4D–6D lookups plus a vector-based lookup overload.
  • Update XML schema and add new unit tests and an example aircraft configuration demonstrating ND table syntax.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/math/FGTable.cpp Implements ND XML parsing, breakpoint nesting, and recursive interpolation for N-D tables.
src/math/FGTable.h Updates table API/documentation to expose ND lookup overloads and store lookup axes dynamically.
tests/unit_tests/FGTableTest.h Adds basic load tests for 4D/5D/6D XML table structures.
JSBSimCommon.xsd Extends schema to allow recursively nested <tableData> for ND tables and adds missing type attribute.
aircraft/ballx/ballx.xml Provides a concrete 4D table example within an aircraft config.
aircraft/ballx/reset00.xml Adds an initialization preset for the new example aircraft.
.gitignore Adds ignores for devcontainer and environment/venv files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/unit_tests/FGTableTest.h
Comment thread tests/unit_tests/FGTableTest.h Outdated
Comment thread tests/unit_tests/FGTableTest.h
Comment thread tests/unit_tests/FGTableTest.h
Comment thread tests/unit_tests/FGTableTest.h
Comment thread src/math/FGTable.cpp Outdated
Comment thread src/math/FGTable.cpp Outdated
Comment thread tests/unit_tests/FGTableTest.h
Comment thread aircraft/ballx/ballx.xml Outdated
Comment thread JSBSimCommon.xsd
Comment on lines +129 to +134
<xs:complexType name="table-data" mixed="true">
<xs:sequence>
<xs:element name="tableData" type="table-data" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="breakPoint" type="xs:double" use="optional"/>
</xs:complexType>
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

The new recursive table-data type is mixed="true" and no longer constrains leaf <tableData> content to numbers-list, so schema validation will now accept empty/non-numeric <tableData> that JSBSim rejects at runtime. If possible, consider a stricter schema (e.g., XSD 1.1 xs:assert, or separate leaf/container types) or at least document this loss of validation explicitly.

Copilot uses AI. Check for mistakes.
@agodemar
Copy link
Copy Markdown
Contributor Author

@bcoconni thank you for reviewing this PR.
I'm not sure you also see the additional reviews that GitHub Copilot provides after yours, or I'm the only one that sees them because of my licenses.
I kindly ask you now what I am supposed to do at this point?

@bcoconni
Copy link
Copy Markdown
Member

@bcoconni thank you for reviewing this PR. I'm not sure you also see the additional reviews that GitHub Copilot provides after yours, or I'm the only one that sees them because of my licenses.

Yes, I can see them as well, and I guess everyone can.

Just for the record, I have pushed the button because I have some premium requests left on my Pro plan and I know I will not be able to use all of them before the reset on May 1st 😄

I kindly ask you now what I am supposed to do at this point?

  • Beneath your diffs, the GitHub interface gives me a button "Commit suggestion". If I commit, does it overwrite your pushes?

If you push the button "Commit suggestion", it is supposed to apply on the latest commit in your branch which includes the ones I have pushed earlier.

Yes, sorry I took the liberty to push directly on the PR branch because they were trivial changes that restored the CI workflow. I needed that to check that everything was working in your branch. Apologies for that.

I cannot modify (nor anyone else) anything in your repo beyond the branch that you pushed for this PR. If you do not want other maintainers from JSBSim to push on branches you submit for PRs, you need to untick the option "Allow edits and access to secrets by maintainers" next to the "Create Pull Request" button:

image

You should be able to restore everything on your side with git pull origin n-dimensional-interpolation while your local branch n-dimensional-interpolation is checked out (i.e. active). If neede, replace origin with the name of the remote you are using

Once again, apologies for the confusion that it brought.

@agodemar
Copy link
Copy Markdown
Contributor Author

@bcoconni no problem, nothing to apologize for. I'm just trying to understand who's doing what.
I did check on purpose the option "Allow edits and access to secrets by maintainers" because I really do rely on your expertise. After all, our interest here is to converge faster towards this new feature.

Regarding the suggestions by Copilot, I'll accepr them. In our unit tests we are only proving that parsing the tables succeeds. We should also assert at least that one expected lookup result (exact-grid and interpolated) to exercise the added ND lookup path.

@bcoconni
Copy link
Copy Markdown
Member

Regarding the suggestions by Copilot, I'll accepr them. In our unit tests we are only proving that parsing the tables succeeds. We should also assert at least that one expected lookup result (exact-grid and interpolated) to exercise the added ND lookup path.

Looks good to me.

When you will do that, please use the button "Add suggestion to batch" to include all the suggestions in one single commit and avoid launching as many CI jobs as there are suggestions.

@bcoconni
Copy link
Copy Markdown
Member

bcoconni commented May 1, 2026

I have pushed some commits to this PR:

  • Fixed 2 suggestions made by Copilot (exceptions from std::stoul and repeated allocations on the heap).
  • Fixed some errors introduced by Copilot suggestions: it suggested to remove variables (a1, a2, ...) creation but also made some suggestions to use them to test FGTable::GetValue().
    • Lesson learnt: Copilot do not check the consistency of its suggestions.
  • FGTable::GetValue(const std::vector<double>& keys) now throws if the size of its input argument keys is smaller than the dimension of the table as per the discussion Lookup tables in more than 3 dimensions #1425 (reply in thread)

Copy link
Copy Markdown
Member

@bcoconni bcoconni left a comment

Choose a reason for hiding this comment

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

Looks good to me.

agodemar and others added 9 commits May 1, 2026 20:03
Co-authored-by: Bertrand Coconnier <bcoconni@users.noreply.github.com>
Co-authored-by: Bertrand Coconnier <bcoconni@users.noreply.github.com>
Co-authored-by: Bertrand Coconnier <bcoconni@users.noreply.github.com>
Basically, besides parsing, add tests on the results of n-dimensional interpolations

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bcoconni bcoconni force-pushed the n-dimensional-interpolation branch from c7a1ec4 to 3fe29ee Compare May 1, 2026 18:03
@agodemar
Copy link
Copy Markdown
Contributor Author

agodemar commented May 3, 2026

I added the Jupyter notebook examples/python/test_ballx.ipynb to experiment with the 4D interpolation.

At the moment the result doesn't look correct. In the bottom-right plot, the red dot should be on the gray surface, but it's not:
image

There's probably something wrong with the function jsbsim_lookup4D defined in the notebook.

@seanmcleod70 @bcoconni ideas?

@agodemar
Copy link
Copy Markdown
Contributor Author

agodemar commented May 8, 2026

@seanmcleod70 @bcoconni did you have the chance to look at my notebook examples/python/test_ballx.ipynb yet?

@seanmcleod70
Copy link
Copy Markdown
Contributor

I did briefly look at it at the time you posted, but didn't spot anything obviously wrong, and had a couple of questions, but then got distracted by the JOSS paper etc. 😉

    # Interpolated lookup at row=1, col=1 for the current (axis3, axis4) slice.
    x0, y0 = 1.0, 1.0
    ax3 = 20.0
    ax4 = 1.0
    z_ = float(np.asarray(jsbsim_lookup4D(row=x0, col=y0, axis3=ax3, axis4=ax4)))
    #z_=5.0 # just to test
    ax.scatter([x0], [y0], [z_], color="red", s=120, edgecolor="k", linewidth=0.7)

    ax.text(x0, y0, z_, f"  ({x0:.1f}, {y0:.1f}, {ax3:.1f}, {ax4:.1f}; {z_:.3f})", color="red", fontsize=9, weight="bold")

So you mention ..for current (axis3, axis4) slice, but it looks like all four of the axes are hard-coded (1.0, 1.0, 20.0, 1.0) for which you get a lookup value of 0.28? And the lookup value should be on the order of 10.x if I eyeball the dummy4 table?

@seanmcleod70
Copy link
Copy Markdown
Contributor

Ah, shouldn't this:

def jsbsim_lookup4D(row, col, axis3=0.0, axis4=0.0):
    fdm['aero/dummy4D/aero/alpha-deg'] = row
    fdm['aero/dummy4D/aero/beta-deg'] = col
    fdm['aero/dummy4D/fcs/flap-pos-deg'] = axis3
    fdm['aero/dummy4D/fcs/parachute_reef_pos_norm'] = axis4

Rather be:

def jsbsim_lookup4D(row, col, axis3=0.0, axis4=0.0):
    fdm['aero/alpha-deg'] = row
    fdm['aero/beta-deg'] = col
    fdm['fcs/flap-pos-deg'] = axis3
    fdm['fcs/parachute_reef_pos_norm'] = axis4

In other words I don't think you were actually setting the relevant properties, and your lookup was for (0, 0, 0, 0), which is exactly 0.28.

@agodemar
Copy link
Copy Markdown
Contributor Author

agodemar commented May 8, 2026

@seanmcleod70 oh, thanks!

@agodemar
Copy link
Copy Markdown
Contributor Author

@bcoconni @seanmcleod70
I think we got to the point we could merge this PR.

I fixed the example examples/python/test_ballx.ipynb that gives this output when I test the 4D-interpolation on data provided in ballx.xml example:

image

The two bigger dots, colored in red and magenta, look correctly placed onto the light blue surfaces, in the right-top and right-bottom subplots.

What do you think?

PS: Some days ago, I configured the hook betweeen JSBSim releases and the Zenodo artifact uploads. I kindly ask @bcoconni to double check if the settings is OK. If we decide to merge this PR, it would be a good chance to make a minor release and see if the artifacts are correctly uploaded to Zenodo.
Bear in mind that DOI of our Zenodo artifacts are going to be cited in our CITATION.cff file.

@bcoconni
Copy link
Copy Markdown
Member

I kindly ask @bcoconni to double check if the settings is OK.

@agodemar Oops ! Sorry, I have missed that. Could you remind me what was that I had to check ?

I think we got to the point we could merge this PR.

Yep, still looking good to me.

@agodemar
Copy link
Copy Markdown
Contributor Author

I kindly ask @bcoconni to double check if the settings is OK.

@agodemar Oops ! Sorry, I have missed that. Could you remind me what was that I had to check ?

I think we got to the point we could merge this PR.

Yep, still looking good to me.

Oh, never mind. It's a setting that I can configure from Zenodo when I log with my GitHub credentials.

Here is what I have now:
image

When a new release comes out, I expect tha Zenodo will emit a badge and the DOI that we can use later on.

@agodemar
Copy link
Copy Markdown
Contributor Author

@seanmcleod70 are you OK with merging this PR?

@seanmcleod70
Copy link
Copy Markdown
Contributor

are you OK with merging this PR?

Yes.

@bcoconni bcoconni merged commit 1ecd08f into JSBSim-Team:master May 10, 2026
30 checks passed
@bcoconni
Copy link
Copy Markdown
Member

Great! The PR is now merged.

@seanmcleod70
Copy link
Copy Markdown
Contributor

@agodemar I meant to ask, what are the particular dimensions you're looking at for the high dimensional data you need to use?

@agodemar
Copy link
Copy Markdown
Contributor Author

@agodemar I meant to ask, what are the particular dimensions you're looking at for the high dimensional data you need to use?

I'm supervising a project work where some provided lookup tables are 5D and 6D. Not more than that.

@seanmcleod70
Copy link
Copy Markdown
Contributor

I should've been clearer, I was looking for a list of parameters for the dimensions, e.g. (alpha, beta, flaps, speedbrake, aileron) for force/moment X.

@agodemar agodemar deleted the n-dimensional-interpolation branch May 11, 2026 08:09
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.

5 participants