-
Notifications
You must be signed in to change notification settings - Fork 4
Introduce orientation (replacing tangent) #12
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c789ab2
Tangent as UFL expression
schnellerhase d8a8488
Introduce orientation
schnellerhase 0029c10
Merge branch 'main' into tangent-as-ufl-expr
schnellerhase e047ad3
Update src/networks_fenicsx/mesh.py
schnellerhase ae1353a
Reorder and meshtag indices
schnellerhase a7a65b6
Fix silent assumption on topology to geometry mapping
schnellerhase b22b7e8
Extend to non unit lcar
schnellerhase e44040d
Compute from cells
schnellerhase a9998d1
ruff
schnellerhase 9c88ae9
Merge branch 'main' into tangent-as-ufl-expr
schnellerhase 70f8102
Addapt up to edge coloring
schnellerhase 41529a3
Merge branch 'main' into tangent-as-ufl-expr
schnellerhase 53aaf75
Fix rebase
schnellerhase 9a4f4f1
Merge branch 'main' into tangent-as-ufl-expr
schnellerhase 0bc96d4
Fixup merge
schnellerhase 53c22cc
Merge branch 'main' into tangent-as-ufl-expr
jorgensd 5362e8a
Fixes for dtype
jorgensd ced5bb0
Remove duplicate value
jorgensd 2aae09c
Update tests/test_orientation.py
schnellerhase 4f743d9
Pull out order functionality
schnellerhase 944e3e3
Missed one
schnellerhase 106168c
Simplify (remove in_order checks)
schnellerhase 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,58 @@ | ||
| import networkx as nx | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| import dolfinx | ||
| import ufl | ||
| from networks_fenicsx.mesh import NetworkMesh | ||
|
|
||
|
|
||
| def linear_graph(n: int, dim: int = 2, ordered=lambda _: True) -> nx.DiGraph: | ||
| G = nx.DiGraph() | ||
| G.add_nodes_from(range(n)) | ||
|
|
||
| for i in range(n - 1): | ||
| if ordered(i): | ||
| G.add_edge(i, i + 1) | ||
| else: | ||
| G.add_edge(i + 1, i) | ||
|
|
||
| for i in range(n): | ||
| pos = np.zeros(dim) | ||
| pos[0] = i / (n - 1) | ||
| G.nodes[i]["pos"] = pos | ||
|
|
||
| return G | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("n", [30]) | ||
| @pytest.mark.parametrize("order", ["in", "reverse", "alternating"]) | ||
| @pytest.mark.parametrize("N", [1, 4, 8]) | ||
| def test_orientation(n: int, order: str, N: int) -> None: | ||
| if order == "in": | ||
| ordered = lambda _: True | ||
| elif order == "reverse": | ||
| ordered = lambda _: False | ||
| elif order == "alternating": | ||
| ordered = lambda k: k % 2 | ||
| else: | ||
| raise RuntimeError() | ||
|
|
||
| G = linear_graph(n, ordered=ordered) | ||
|
|
||
| network_mesh = NetworkMesh(G, N=N) | ||
|
|
||
| J = ufl.Jacobian(network_mesh.mesh) | ||
| t = J[:, 0] | ||
| t /= ufl.sqrt(ufl.inner(t, t)) | ||
| f = dolfinx.fem.form(ufl.inner(ufl.as_vector((1, 0)), t) * network_mesh.orientation * ufl.dx) | ||
|
|
||
| val = network_mesh.comm.allreduce(dolfinx.fem.assemble_scalar(f)) | ||
|
|
||
| if order == "in": | ||
| assert np.isclose(val, 1.0) | ||
| elif order == "reverse": | ||
| assert np.isclose(val, -1.0) | ||
| else: | ||
| edge_count = n - 1 | ||
| assert np.isclose(val, edge_count % 2 * -1 / edge_count) |
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 guess as we are in 1D, we don't really worry about if UFL over-estimates quadrature for this.
And in the case of "curved" meshes, we could actually gain accuracy by this approach rather than encoding the tangent.