-
Notifications
You must be signed in to change notification settings - Fork 0
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
Drop Python 3.9 support and add DOLFINx v0.8 support #22
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a8221a
Drop Python 3.9 support and test against DOLFINx v0.8
matt-graham 33544b3
Remove references to Python 3.9 in README
matt-graham c12e6a6
Use latest Python version to build docs
matt-graham 7a581af
Additional fixes for changes to API in DOLFINx v0.8
matt-graham c57e835
Maintain DOLFINx <v0.8 compatibility
matt-graham 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 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 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 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 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 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 |
---|---|---|
|
@@ -6,8 +6,7 @@ | |
from typing import TYPE_CHECKING, Literal | ||
|
||
if TYPE_CHECKING: | ||
from collections.abc import Sequence | ||
from typing import Callable, Optional, Union | ||
from collections.abc import Callable, Sequence | ||
|
||
import dolfinx | ||
import matplotlib.pyplot as plt | ||
|
@@ -22,6 +21,13 @@ | |
# Compatibility w [email protected]: try importing old DirichletBCMetaClass name. | ||
from dolfinx.fem import DirichletBCMetaClass as DirichletBC | ||
|
||
try: | ||
from dolfinx.fem import functionspace | ||
except ImportError: | ||
# Compatibility w [email protected]: if the new functionspace function is not in DOLFINx | ||
# then use the class constructor directly. | ||
from dolfinx.fem import FunctionSpace as functionspace # noqa: N813 | ||
|
||
try: | ||
from dolfinx.geometry import bb_tree, compute_collisions_points | ||
except ImportError: | ||
|
@@ -75,10 +81,9 @@ | |
|
||
|
||
def project_expression_on_function_space( | ||
expression: Union[ | ||
ufl.core.expr.Expr, | ||
Callable[[ufl.SpatialCoordinate], ufl.core.expr.Expr], | ||
], | ||
expression: ( | ||
ufl.core.expr.Expr | Callable[[ufl.SpatialCoordinate], ufl.core.expr.Expr] | ||
), | ||
function_space: ufl.FunctionSpace, | ||
) -> Function: | ||
""" | ||
|
@@ -154,7 +159,7 @@ | |
|
||
|
||
def _preprocess_functions( | ||
functions: Union[Function, Sequence[Function], dict[str, Function]], | ||
functions: Function | Sequence[Function] | dict[str, Function], | ||
) -> list[tuple[str, Function]]: | ||
if isinstance(functions, Function): | ||
return [(functions.name, functions)] | ||
|
@@ -165,9 +170,9 @@ | |
|
||
|
||
def plot_1d_functions( | ||
functions: Union[Function, Sequence[Function], dict[str, Function]], | ||
functions: Function | Sequence[Function] | dict[str, Function], | ||
*, | ||
points: Optional[NDArray[np.float64]] = None, | ||
points: NDArray[np.float64] | None = None, | ||
axis_size: tuple[float, float] = (5.0, 5.0), | ||
arrangement: Literal["horizontal", "vertical", "stacked"] = "horizontal", | ||
) -> plt.Figure: | ||
|
@@ -226,13 +231,13 @@ | |
|
||
|
||
def plot_2d_functions( | ||
functions: Union[Function, list[Function], dict[str, Function]], | ||
functions: Function | list[Function] | dict[str, Function], | ||
*, | ||
plot_type: Literal["pcolor", "surface"] = "pcolor", | ||
axis_size: tuple[float, float] = (5.0, 5.0), | ||
colormap: Union[str, Colormap, None] = None, | ||
colormap: str | Colormap | None = None, | ||
show_colorbar: bool = True, | ||
triangulation_color: Union[str, tuple[float, float, float], None] = None, | ||
triangulation_color: str | tuple[float, float, float] | None = None, | ||
arrangement: Literal["horizontal", "vertical"] = "horizontal", | ||
) -> plt.Figure: | ||
""" | ||
|
@@ -281,7 +286,11 @@ | |
raise ValueError(msg) | ||
subplot_kw = {"projection": "3d"} if plot_type == "surface" else {} | ||
fig, axes = plt.subplots(n_rows, n_cols, figsize=figsize, subplot_kw=subplot_kw) | ||
for ax, (label, function) in zip(np.atleast_1d(axes), label_and_functions): | ||
for ax, (label, function) in zip( | ||
np.atleast_1d(axes), | ||
label_and_functions, | ||
strict=True, | ||
): | ||
mesh = function.function_space.mesh | ||
if mesh.topology.dim != 2: | ||
msg = "Only two-dimensional spatial domains are supported" | ||
|
@@ -321,12 +330,10 @@ | |
|
||
|
||
def define_dirichlet_boundary_condition( | ||
boundary_value: Union[Function, Constant, float], | ||
function_space: Optional[FunctionSpace] = None, | ||
boundary_value: Function | Constant | float, | ||
function_space: FunctionSpace | None = None, | ||
*, | ||
boundary_indicator_function: Optional[ | ||
Callable[[ufl.SpatialCoordinate], bool] | ||
] = None, | ||
boundary_indicator_function: Callable[[ufl.SpatialCoordinate], bool] | None = None, | ||
) -> DirichletBC: | ||
""" | ||
Define DOLFINx object representing Dirichlet boundary condition. | ||
|
@@ -359,20 +366,21 @@ | |
msg = "function_space must not be None if boundary_value is not a Function" | ||
raise ValueError(msg) | ||
mesh = function_space.mesh | ||
facet_dim = mesh.topology.dim - 1 | ||
if boundary_indicator_function is not None: | ||
boundary_dofs = dolfinx.fem.locate_dofs_geometrical( | ||
function_space, | ||
boundary_facets = dolfinx.mesh.locate_entities_boundary( | ||
mesh, | ||
facet_dim, | ||
boundary_indicator_function, | ||
) | ||
else: | ||
facet_dim = mesh.topology.dim - 1 | ||
mesh.topology.create_connectivity(facet_dim, mesh.topology.dim) | ||
boundary_facets = dolfinx.mesh.exterior_facet_indices(mesh.topology) | ||
boundary_dofs = dolfinx.fem.locate_dofs_topological( | ||
function_space, | ||
facet_dim, | ||
boundary_facets, | ||
) | ||
boundary_dofs = dolfinx.fem.locate_dofs_topological( | ||
function_space, | ||
facet_dim, | ||
boundary_facets, | ||
) | ||
return dolfinx.fem.dirichletbc( | ||
boundary_value, | ||
boundary_dofs, | ||
|
@@ -382,11 +390,11 @@ | |
|
||
def error_norm( | ||
function_1: dolfinx.fem.Function, | ||
function_or_expression_2: Union[ | ||
dolfinx.fem.Function, | ||
ufl.core.expr.Expr, | ||
Callable[[ufl.SpatialCoordinate], ufl.core.expr.Expr], | ||
], | ||
function_or_expression_2: ( | ||
dolfinx.fem.Function | ||
| ufl.core.expr.Expr | ||
| Callable[[ufl.SpatialCoordinate], ufl.core.expr.Expr] | ||
), | ||
degree_raise: int = 3, | ||
norm_order: Literal[1, 2, "inf-dof"] = 2, | ||
) -> float: | ||
|
@@ -440,10 +448,13 @@ | |
Computed Lᵖ error norm value. | ||
""" | ||
# Create raised degree function space with same element as for original function_1 | ||
original_degree = function_1.function_space.ufl_element().degree() | ||
family = function_1.function_space.ufl_element().family() | ||
original_degree = function_1.function_space.ufl_element().degree | ||
if callable(original_degree): | ||
# Depending on Basix version degree may be an accesor method or attribute | ||
original_degree = original_degree() | ||
family = function_1.function_space.ufl_element().family_name | ||
mesh = function_1.function_space.mesh | ||
raised_degree_function_space = FunctionSpace( | ||
raised_degree_function_space = functionspace( | ||
mesh, | ||
(family, original_degree + degree_raise), | ||
) | ||
|
Oops, something went wrong.
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.
TIL you can do this!