Skip to content

Feature: mesh deformation with RBFs (TPS and CPC2) - #2470

Open
Lena-Richter wants to merge 17 commits into
mainfrom
feature-RBF_CPC2
Open

Lena-Richter wants to merge 17 commits into
mainfrom
feature-RBF_CPC2

Conversation

@Lena-Richter

@Lena-Richter Lena-Richter commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2471

Describe your changes here:
This PR introduces an RBF-based mesh deformation, using OpenCASCADE and Eigen. It implements support for the compactly supported (CPC2) and globally supported (TPS) basis functions to compute the deformation for the inner nodes from the displacement of the boundary nodes. Additionally, for CPC2, a dynamic radius is implemented as well as a grading factor. The deformed geometry needs to have the same parametrization as the input geometry, otherwise the deformation will not work.

All these boxes must be checked by the AUTHOR before requesting review:

  • The PR is small enough to be reviewed easily. If not, consider splitting up the changes in multiple PRs.
  • The title starts with one of the following prefixes: Documentation:, Bugfix:, Feature:, Improvement: or Other:.
  • If the PR is related to an issue, make sure to link it.
  • The author made sure that, as a reviewer, he/she would check all boxes below.

All these boxes must be checked by the REVIEWERS before merging the pull request:

As a reviewer please read through all the code lines and make sure that the code is fully understood, bug free, well-documented and well-structured.

General

  • The reviewer executed the new code features at least once and checked the results manually.
  • The code follows the t8code coding guidelines.
  • New source/header files are properly added to the CMake files.
  • The code is well documented. In particular, all function declarations, structs/classes and their members have a proper doxygen documentation. Make sure to add a file documentation for each file!
  • README.md files are updated if necessary.
  • All new algorithms and data structures are sufficiently optimal in terms of memory and runtime (If this should be merged, but there is still potential for optimization, create a new issue).

Tests

  • The code is covered in an existing or new test case using Google Test.
  • The code coverage of the project (reported in the CI) should not decrease. If coverage is decreased, make sure that this is reasonable and acceptable.
  • Valgrind doesn't find any bugs in the new code. This script can be used to check for errors; see also this wiki article.

If the Pull request introduces code that is not covered by the github action (for example coupling with a new library):

  • Should this use case be added to the github action?
  • If not, does the specific use case compile and all tests pass (check manually).

Scripts and Wiki

  • If a new directory with source files is added, it must be covered by the scripts/internal/find_all_source_files.sh to check the indentation of these files.
  • If this PR introduces a new feature, it must be covered in an example or tutorial and a Wiki article.

License

  • The author added a BSD statement to doc/ (or already has one).

@Lena-Richter Lena-Richter changed the title Feature rbf cpc2 Feature mesh deformation with RBFs (TPS and CPC2) Oct 5, 2026
@Lena-Richter Lena-Richter changed the title Feature mesh deformation with RBFs (TPS and CPC2) Feature: mesh deformation with RBFs (TPS and CPC2) Oct 5, 2026
@Lena-Richter
Lena-Richter marked this pull request as ready for review October 6, 2026 11:05
@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.11%. Comparing base (9d755d4) to head (6458bf3).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2470      +/-   ##
==========================================
+ Coverage   82.76%   83.11%   +0.34%     
==========================================
  Files         139      138       -1     
  Lines       21593    21504      -89     
==========================================
  Hits        17872    17872              
+ Misses       3721     3632      -89     

☔ View full report in Codecov by Harness.
📢 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.

@ole-alb
ole-alb self-requested a review October 6, 2026 13:10

@ole-alb ole-alb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this very cool contribution and implementation. I have a couple general remarks.
Can you check if ervything that can be const is const?

Please add tests for your functionality as it is not tested yet. Please also test the new dependecy on the newly added thirdparty library Eigen.
After the PR is merged, please keep in mind to update the wiki accordingly (Eigen, CMake,..).

Also I thought if there could be the option to use a system Eigen like it is for SC and p4est?

And last but not least, I coudn't find you in the CITATION.cff and in doc/auther_. Please add yourself here.

/** Calculate the distance between the current pair of boundary nodes. */
const double distance = t8_dist (boundary_nodes[row].position, boundary_nodes[col].position);
/** Evaluate the radial basis function for the current distance and write the value to the matrix A. */
A (row, col) = rbf_function->evaluate (distance, 0.0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible to solve that with a default value? As tps doesn't have a radius, adding 0 could be misunterstood.

Comment on lines +119 to +124
double r = distance / radius;
if (r < 1.0) {
double d = 1.0 - r;
return (d * d * d * d) * (4.0 * r + 1.0);
}
return 0.0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In genearal, the use of variables consisting of only one letter is stronlgy discouraged in t8code. For me this could be an exemption, as it's only four lines and just math, but maybe you can come up with a better way.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay renamed r to normalized_distance and removed d by using std::pow

std::unordered_map<t8_gloidx_t, t8_3D_vec>
t8_cmesh_mesh_deformation::calculate_displacement_surface_vertices (const t8_cad_handle *cad)
static double
calculate_local_support_radius (t8_cmesh_t cmesh, const std::vector<std::pair<t8_locidx_t, int>> &tree_list,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function is specific to RBF, why is it here and not in t8_rbf.cxx? Also please add documentation and a "t8_" prefix to the function name.

t8_cmesh_mesh_deformation::calculate_displacement_surface_vertices (const t8_cad_handle *cad)
static double
calculate_local_support_radius (t8_cmesh_t cmesh, const std::vector<std::pair<t8_locidx_t, int>> &tree_list,
int current_global_vertex_id, const t8_3D_vec &displacements)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is an int here, but in the usage a t8_gloidx_t is used a input. So I'd suggest to make this also a t8_gloidx_t

}
}
/* If the boundary node can not be found in the list of boundary nodes.*/
t8_errorf ("ERROR: The boundary node %ld is missing in the boundary node list.\n", global_id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
t8_errorf ("ERROR: The boundary node %ld is missing in the boundary node list.\n", global_id);
t8_errorf ("ERROR: The boundary node % " T8_GLOIDX_FORMAT " is missing in the boundary node list.\n", global_id);


double displacement_magnitude = std::sqrt (displacements[0] * displacements[0] + displacements[1] * displacements[1]
+ displacements[2] * displacements[2]);
/** Get the first tree where this vertex exists. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Which vertex?

}
}
/** Fill the sparse matrix A with the triplets. */
Eigen::SparseMatrix<double> A (num_boundary_nodes, num_boundary_nodes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A might not be the best name.

A.setFromTriplets (coefficients.begin (), coefficients.end ());
/** Solve the linear system using the conjugate gradient method. */
Eigen::BiCGSTAB<Eigen::SparseMatrix<double>> solver;
solver.setTolerance (1e-10);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is that an experimental value?

Comment on lines +116 to +117
/** Because of the symmetric property of the distance between nodes, we only need to compute the upper triangular part of the matrix
* and can mirror the values to the lower triangular part. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you really do that?

Comment thread CMakeLists.txt
option( T8CODE_ENABLE_MPI "Enable t8code's features which rely on MPI" ON )
option( T8CODE_ENABLE_VTK "Enable t8code's features which rely on VTK" OFF )
option( T8CODE_ENABLE_OCC "Enable t8code's features which rely on OpenCASCADE" OFF )
option( T8CODE_ENABLE_EIGEN "Enable t8code's features which rely on eigen" OFF )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
option( T8CODE_ENABLE_EIGEN "Enable t8code's features which rely on eigen" OFF )
option( T8CODE_ENABLE_EIGEN "Enable t8code's features which rely on Eigen" OFF )

@ole-alb ole-alb assigned Lena-Richter and unassigned ole-alb Oct 7, 2026
…on.cxx

Co-authored-by: Ole Albers <122293607+ole-alb@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

Feature rbf cpc2

2 participants