Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partition of unity RBF data mapping #1483

Merged
merged 70 commits into from Mar 23, 2023
Merged

Conversation

davidscn
Copy link
Member

@davidscn davidscn commented Nov 18, 2022

Main changes of this PR

Adds the partition of unity RBF mapping as a new mapping variant.

Motivation and additional information

There are a few details yet to be clarified and a few TODOs in the code, but I'm sure these changes are ready for a first review. We need to fix a user interface in the configuration file.

Post TODO: Adjust the auto-selection of our mapping-config.

Closes #1273.

Author's checklist

  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I added a changelog file with make changelog if there are user-observable changes since the last release.
  • I added a test to cover the proposed changes in our test suite.
  • I sticked to C++17 features.
  • I sticked to CMake version 3.16.3.
  • I squashed / am about to squash all commits that should be seen as one.
  • Fixing a proper user-interface (related to Rename use-qr-decomposition to something more appropriate #1417)

Reviewers' checklist

  • Does the changelog entry make sense? Is it formatted correctly?
  • Do you understand the code changes?

@davidscn davidscn added the enhancement A new feature, a new functionality of preCICE (from user perspective) label Nov 18, 2022
@davidscn davidscn added this to the Version 3.0.0 milestone Nov 18, 2022
@davidscn davidscn self-assigned this Nov 18, 2022
Add basic working version

Register only non-empty partitions

Add index tree for center mesh

Apply indexing for partition queries

Use stored output vertex -> partition associations computed during computeMapping

Make variables no member

Add exports for center partitioning

Replace size_t by vertexID in type

Fix vector fill

Clean-up includes and warn about non-matching output vertices

Implement and document a tagging strategy

Fiy typo

Simplify partition BB logging

Clean-up computeMapping function and factor out partitioning

Remove empty partition map

Set dead axis according to space dim

Clarify data dimension vs space dimension

Move partitioning strategy to separate file

Work on partitioning

Add tentative heuristic radius determination

Some more logging and filtering of partitions

Facot out filter logic

Bugfix for vertex transform

Make projection configurable

Add global logger in namespace

Remove unnecessary sqrt

Parametrize overlap for the partitioning

Add input projection as config parameter

Fix test

Add 2D version for duplication tagging

Support vectorial data

Improve debugging

Bugfix for 2D cases

A few tweaks and make it work for corner cases

Fix a few warnings and remove static assert

Fix typo

Add more tests

Add 3D test

Add simple parallel test and exports in parallel

More tests for the partitioning

Remove obsolete code

More modularity and synchronization of local vs global BBs

Add a very simple parallel tagging algorithm

First draft implementation for conservative pou mappings

Use input mesh to construct partition distribution

Resolve ambiguity of local variable and class member

Add TODO regarding the tagging

Add scalar conservative PoU tests

Use free functions for begin and end

Fixup

Fixup fixup

Use eigen methods

Updates regarding new comm updates in preCICE

preCICE compatibility updates pt2

Add conservative 2D vector test

Add 3D conservative test

Add a simple 3D vector consistent test

Fix last test

Further test fixes

Add 3D conservative vector test

Move weight computation into 'computeMapping'

Make polynomial configurable
Copy link
Member

@uekerman uekerman left a comment

Choose a reason for hiding this comment

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

Looks promising already 👍
So far, I only had a big picture view and I did not yet try it out.

I struggle a bit with the name of the file CreatePartitioning and the namespace partitioner. Partition vs Partitioner vs Partitioning, how are they connected?
It gets even more complicated: we already have a package partition with a class Partition. Maybe we could find a different name here, also to clearly distinguish between parallel partition (mesh on one rank) and partitions meant here.
Maybe the connection between PoUMapping and CreatePartition could be a "has-a" connection?

CreatePartitioning and Partition could probably go into impl?

Let's add default values to all configuration attributes where we already know that there is a good safe choice.

Should we merge this before or after #1418?

src/mapping/config/MappingConfiguration.cpp Outdated Show resolved Hide resolved
src/mapping/config/MappingConfiguration.cpp Outdated Show resolved Hide resolved
src/mapping/config/MappingConfiguration.cpp Outdated Show resolved Hide resolved
src/mesh/BoundingBox.hpp Outdated Show resolved Hide resolved
src/mesh/BoundingBox.hpp Outdated Show resolved Hide resolved
src/mapping/PartitionOfUnityMapping.hpp Outdated Show resolved Hide resolved
src/mapping/PartitionOfUnityMapping.hpp Outdated Show resolved Hide resolved
src/mapping/PartitionOfUnityMapping.hpp Outdated Show resolved Hide resolved
src/mapping/PartitionOfUnityMapping.hpp Outdated Show resolved Hide resolved
src/mapping/PartitionOfUnityMapping.hpp Outdated Show resolved Hide resolved
@davidscn
Copy link
Member Author

Should we merge this before or after #1418?

Would be better to merge the bounding box refactoring first, the changes here are non-intrusive and can easily be adapted to the new class layout.

@davidscn
Copy link
Member Author

While investigating the performance of the OpenFOAM-adapter using the 3D bending-flap tutorial, we observed a rather huge amount of time spent in the mapping part from the more refined solid side to the fluid side. Looking at the total amount of time in the fluid summary log, we had the following timings for the PETSc RBF mappings:

advance/map.pet.computeMapping.FromSolid-writeToFluid-Mesh-Nodes |          1 |        408 |        408 |        408 |        408 |    0.00163 |
advance/map.pet.mapData.FromSolid-writeToFluid-Mesh-Nodes        |        141 |      43943 |        526 |         17 |        311 |      0.176 |

i.e., we have almost 44 seconds spent in the mapData (advance) call of preCICE.

Using the POU method implemented here, we get the following timings:

 advance/map.pou.computeMapping.FromSolid-writeToFluid-Mesh-Nodes |          1 |         37 |         37 |         37 |         37 |   0.000215 |
        advance/map.pou.mapData.FromSolid-writeToFluid-Mesh-Nodes |        141 |        495 |          3 |          2 |          3 |    0.00287 |

i.e., the time spent in mapData is around 100 times smaller. The computeMapping call is around 10 times faster (note that a rescaling is computed in the PETSc version).

As a disclaimer: I still have to add an early exit from the 'computeMapping' function here in order to bail out at the right time when a rank is empty (has no interface vertices). For the measurement, I added an easy bail-out strategy, but I want think about it again and add a clean (maybe in the end even the same) version .

unsigned int getNumberOfInputVertices() const;

/// The center coordinate of this partition
std::array<double, 3> getCenterCoords() const;
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason not to use Eigen::Vertex3D or Eigen::VertexXD instead?.

I only used this in the Vertex to prevent dynamic allocations and simplify the interface to boost.geometry.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see your point, but would rather delay adjustments in this direction. Here, I need to preserve compatibility towards vertex.rawCoords. Maybe something to adjust later on.

src/mapping/Partition.hpp Outdated Show resolved Hide resolved
src/mapping/Partition.hpp Outdated Show resolved Hide resolved
src/mapping/Partition.hpp Outdated Show resolved Hide resolved
src/mapping/Partition.hpp Outdated Show resolved Hide resolved
src/mapping/CreatePartitioning.hpp Outdated Show resolved Hide resolved
src/mapping/Partition.hpp Outdated Show resolved Hide resolved
src/mapping/config/MappingConfiguration.cpp Outdated Show resolved Hide resolved
src/mesh/BoundingBox.cpp Show resolved Hide resolved
src/mesh/BoundingBox.cpp Outdated Show resolved Hide resolved
src/mesh/BoundingBox.hpp Outdated Show resolved Hide resolved
src/query/Index.hpp Outdated Show resolved Hide resolved
void setNormalizedWeight(double normalizedWeight, VertexID vertexID);

/// Compute the weight for a given vertex
double computeWeight(const mesh::Vertex &v) const;
Copy link
Member

Choose a reason for hiding this comment

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

This only requires coordinates

Suggested change
double computeWeight(const mesh::Vertex &v) const;
double computeWeight(const Eigen::VertorXD &v) const;

Copy link
Member Author

Choose a reason for hiding this comment

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

I see your point, but would rather delay adjustments in this direction. Here, I need to preserve compatibility towards vertex.rawCoords. Maybe something to adjust later on.

src/mapping/Partition.hpp Outdated Show resolved Hide resolved
src/mapping/Partition.hpp Outdated Show resolved Hide resolved
Copy link
Member

@uekerman uekerman left a comment

Choose a reason for hiding this comment

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

I had a look over everything again with a focus on SphericalVertexCluster.hpp. I did not step through all details of CreateClustering.hpp.

I think we are in a good state now. Still a few things to tweak, but all minor.

Nice documentation in SphericalVertexCluster 👍

Does it make sense to also implement unit tests for estimateClusterRadius (and the other helper functions) ?

After merging, please add a new section in the mapping docs explaining the attributes with a picture.

src/mapping/config/MappingConfiguration.cpp Outdated Show resolved Hide resolved
src/mapping/config/MappingConfiguration.cpp Outdated Show resolved Hide resolved
src/mapping/config/MappingConfiguration.cpp Outdated Show resolved Hide resolved
src/mapping/impl/SphericalVertexCluster.hpp Outdated Show resolved Hide resolved
src/mapping/impl/SphericalVertexCluster.hpp Show resolved Hide resolved
src/mapping/impl/CreateClustering.hpp Outdated Show resolved Hide resolved
src/mesh/BoundingBox.cpp Show resolved Hide resolved
src/query/Index.cpp Show resolved Hide resolved
Comment on lines +254 to +256
#ifndef NDEBUG
exportClusterCentersAsVTU(centerMesh);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Something to mention in the user docs

src/mapping/PartitionOfUnityMapping.hpp Outdated Show resolved Hide resolved
@davidscn
Copy link
Member Author

@uekerman regarding all the defaults: I added now defaults for the pum specific parameters. I'm just afraid that these settings will be considered as a silver bullet and people don't think and or modify these parameters: Example: going higher with the number of vertices-per-cluster might give more accurate results, but it's also more expensive. The values set here are just reasonable default values.

@davidscn davidscn merged commit 3ef11b4 into precice:develop Mar 23, 2023
17 checks passed
@davidscn davidscn mentioned this pull request Mar 23, 2023
2 tasks
@precice-bot
Copy link

This pull request has been mentioned on preCICE Forum on Discourse. There might be relevant details there:

https://precice.discourse.group/t/can-precice-be-used-for-volume-coupling/27/7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature, a new functionality of preCICE (from user perspective)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Partition of unity based data mappings
4 participants