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

Fixed the momentum exchange method in the JAX backend. #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hsalehipour
Copy link
Collaborator

@hsalehipour hsalehipour commented Jan 9, 2025

Contributing Guidelines

Description

  1. Fixed the momentum exchange method in the JAX backend (see MomentumTransfer is not correctly implemented in JAX #94)
  2. Fixed the ordering of D3Q19 velocity set to ensure (0,0,0) is the first index like other velocity sets
  3. Removed an unnecessary operation of aux recovery for ExtrapolationOutflow BC

I noticed that mlups_3d which relies on D3Q19 now gives tiny bit faster results (~ 0.1%) which could be due to item 2 above.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • All pytest tests pass

Linting and Code Formatting

Make sure the code follows the project's linting and formatting standards. This project uses Ruff for linting.

To run Ruff, execute the following command from the root of the repository:

ruff check .
  • Ruff passes

@hsalehipour hsalehipour requested a review from mehdiataei January 9, 2025 00:02
@@ -53,9 +53,6 @@ def __init__(
mesh_vertices,
)

# Set the flag for auxilary data recovery
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

was not needed for ExtrapolationOutflow BC. that BC directly uses _f_post_collision to put all the necessary ingredients.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure. We created reconstruction originally for this BC!:

        # Update the auxilary data for this BC using the neighbour's populations stored in f_aux and
        # f_pre (post-streaming values of the current voxel). We use directions that leave the domain
        # for storing this prepared data.

If you don[t recover, you'll 100% overwrite this data...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have changed those comments since then. I can remove this part and add it to another PR if that helps you understand why but this BC assembles all the information and stores it directly in _f_post_collision which is then recovered when we write in f_1 (not f_0 as in bc_recovery). Just like how halfway bc uses post-collision values in the opposite direction taken from f_0, this BC also takes "post-collision" values taken from f_0 which are hand crafted earlier inside a function that is called "update_bc_auxilary_data".

Copy link
Contributor

Choose a reason for hiding this comment

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

I have to think about this more to make sure it is correct. We're rushing PR merges for no reason and we're reverting them back or fix them almost immedately a few days later. I'll check this next week.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are not reverting anything! There are minor things that have been missed in the reivews or unknown new bugs that are discovered.

@@ -16,7 +16,7 @@ class D3Q19(VelocitySet):

def __init__(self, precision_policy, backend):
# Construct the velocity vectors and weights
c = np.array([ci for ci in itertools.product([-1, 0, 1], repeat=3) if np.sum(np.abs(ci)) <= 2]).T
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to make this consistant, pls make sure that D2Q9 is similar. But overall, again this could change in the future, as you have store them symmetrically and avoid storing values for opp index.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is consistent for all 3 lattices.

@@ -53,9 +53,6 @@ def __init__(
mesh_vertices,
)

# Set the flag for auxilary data recovery
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure. We created reconstruction originally for this BC!:

        # Update the auxilary data for this BC using the neighbour's populations stored in f_aux and
        # f_pre (post-streaming values of the current voxel). We use directions that leave the domain
        # for storing this prepared data.

If you don[t recover, you'll 100% overwrite this data...

@hsalehipour
Copy link
Collaborator Author

This PR fixes this issue:
#94

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.

2 participants