-
-
Notifications
You must be signed in to change notification settings - Fork 250
p-refinement of mesh geometry #4205
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
Draft
jhale
wants to merge
21
commits into
main
Choose a base branch
from
jhale/interpolate-mesh-geometry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
02ad338
Add gdim.
jhale e713efd
Expose gdim through to Python.
jhale 47082dd
Add two tests
jhale d55e7dc
Added check on UFL coordinate element - check on array nonsense.
jhale 1c5af59
ruff
jhale 16f9e3f
Change exception message
jhale 4a2b51a
Move gdim before reorder_fn, fix a few other rough edges.
jhale 2d8210e
Restore original path for performance.
jhale 8bb6faa
Small tweaks.
jhale c376468
Add some asserts
jhale 28ef901
Change Mesh.RecombineAll option from 2 to 1
jhale f4874fc
Merge remote-tracking branch 'origin/jhale/gmsh-higher-order-fix' int…
jhale aa13059
clang-format
jhale 0ca6080
Direct translation, not tested, no Python interface.
jhale fceaa15
Claude generated tests, need careful checking.
jhale 4a4982b
Add tests
jhale a79c684
Tidy comment
jhale f65e6bd
Tidy up docstrings
jhale 79c91e0
Simplify
jhale 8ace6a6
Simplify
jhale e559c66
Merge remote-tracking branch 'origin/main' into jhale/interpolate-mes…
jhale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Copyright (C) 2026 Jack S. Hale | ||
| # | ||
| # This file is part of DOLFINx (https://www.fenicsproject.org) | ||
| # | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
|
||
| from mpi4py import MPI | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from dolfinx.fem import coordinate_element | ||
| from dolfinx.mesh import CellType, create_unit_square, interpolate_geometry | ||
|
|
||
|
|
||
| def _assert_close_up_to_row_permutation(a, b, atol): | ||
| """Assert rows of a and b are equal, up to a row permutation""" | ||
| a = np.asarray(a) | ||
| b = np.asarray(b) | ||
| assert a.shape == b.shape | ||
| used = [False] * len(b) | ||
| for ra in a: | ||
| for j, rb in enumerate(b): | ||
| if not used[j] and np.allclose(ra, rb, atol=atol, rtol=0.0): | ||
| used[j] = True | ||
| break | ||
| else: | ||
| raise AssertionError(f"No match for {ra} in {b}") | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("dtype", [np.float32, np.float64]) | ||
| def test_interpolate_geometry_p1_to_p2(dtype): | ||
| msh = create_unit_square(MPI.COMM_WORLD, 4, 4, dtype=dtype) | ||
| cmap = coordinate_element(CellType.triangle, 2, dtype=dtype) | ||
|
|
||
| new_msh = interpolate_geometry(msh, cmap) | ||
| assert new_msh.geometry.cmap().degree == 2 | ||
|
|
||
| # Topology should be the same cpp object. | ||
| assert new_msh.topology._cpp_object is msh.topology._cpp_object | ||
|
|
||
| x_old, x_new = msh.geometry.x, new_msh.geometry.x | ||
| dm_old, dm_new = msh.geometry.dofmap, new_msh.geometry.dofmap | ||
| assert dm_old.shape[0] == dm_new.shape[0] | ||
| assert dm_new.shape[1] == 6 | ||
|
|
||
| atol = 10 * np.finfo(dtype).eps | ||
| for c in range(dm_new.shape[0]): | ||
| v = x_old[dm_old[c]] | ||
| # P2 geometry has original vertices + midpoints. | ||
| expected = np.vstack([v, 0.5 * (v[0] + v[1]), 0.5 * (v[0] + v[2]), 0.5 * (v[1] + v[2])]) | ||
| _assert_close_up_to_row_permutation(x_new[dm_new[c]], expected, atol=atol) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("dtype", [np.float32, np.float64]) | ||
| def test_interpolate_geometry_p1_roundtrip(dtype): | ||
| msh = create_unit_square(MPI.COMM_WORLD, 4, 4, dtype=dtype) | ||
| cmap = coordinate_element(CellType.triangle, 1, dtype=dtype) | ||
|
|
||
| new_msh = interpolate_geometry(msh, cmap) | ||
|
|
||
| assert new_msh.geometry.cmap().degree == 1 | ||
| assert new_msh.topology._cpp_object is msh.topology._cpp_object | ||
|
|
||
| x_old, x_new = msh.geometry.x, new_msh.geometry.x | ||
| dm_old, dm_new = msh.geometry.dofmap, new_msh.geometry.dofmap | ||
| assert dm_old.shape == dm_new.shape | ||
|
|
||
| atol = 10 * np.finfo(dtype).eps | ||
| for c in range(dm_old.shape[0]): | ||
| np.testing.assert_allclose(x_new[dm_new[c]], x_old[dm_old[c]], atol=atol, rtol=0.0) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this on the way home, and could we potentially here make a DG geometry if we would like to, i.e. have an input option for setting discontinuous to True here?