From ccd10133a45264ecd9afcdb9dbc6dc75e193feeb Mon Sep 17 00:00:00 2001 From: Francesco Ballarin Date: Mon, 11 Sep 2023 20:05:38 +0200 Subject: [PATCH] dolfinx.fem.VectorFunctionSpace has been deprecated in favor of passing a shape argument to dolfin.fem.FunctionSpace. Furthermore, the base function space class has been renamed to dolfinx.fem.FunctionSpaceBase, with dolfinx.fem.FunctionSpace being a deprecated free function which calls dolfinx.fem.functionspace. --- rbnicsx/backends/functions_list.py | 6 +++--- rbnicsx/backends/import_.py | 6 ++++-- tests/unit/backends/test_backends_export_import.py | 12 ++++++------ tests/unit/backends/test_backends_functions_list.py | 4 ++-- tests/unit/backends/test_backends_gram_schmidt.py | 6 +++--- tests/unit/backends/test_backends_mesh_motion.py | 4 ++-- tests/unit/backends/test_backends_projection.py | 2 +- .../test_backends_proper_orthogonal_decomposition.py | 10 +++++----- tests/unit/backends/test_backends_tensors_array.py | 8 ++++---- tests/unit/backends/test_backends_tensors_list.py | 4 ++-- tutorials/01_thermal_block.ipynb | 6 +++--- tutorials/02_elastic_block.ipynb | 4 ++-- tutorials/03_hole.ipynb | 10 ++++++---- tutorials/04_graetz.ipynb | 7 ++++--- tutorials/05_gaussian.ipynb | 4 ++-- tutorials/07_nonlinear_elliptic.ipynb | 4 ++-- tutorials/12_stokes.ipynb | 11 +++++++---- tutorials/17_navier_stokes.ipynb | 8 +++++--- 18 files changed, 63 insertions(+), 53 deletions(-) diff --git a/rbnicsx/backends/functions_list.py b/rbnicsx/backends/functions_list.py index 7242e64..0b89a6e 100644 --- a/rbnicsx/backends/functions_list.py +++ b/rbnicsx/backends/functions_list.py @@ -31,12 +31,12 @@ class FunctionsList(FunctionsListBase[dolfinx.fem.Function]): Finite element space provided as input. """ - def __init__(self, function_space: dolfinx.fem.FunctionSpace) -> None: - self._function_space: dolfinx.fem.FunctionSpace = function_space + def __init__(self, function_space: dolfinx.fem.FunctionSpaceBase) -> None: + self._function_space: dolfinx.fem.FunctionSpaceBase = function_space super().__init__(function_space.mesh.comm) @property - def function_space(self) -> dolfinx.fem.FunctionSpace: + def function_space(self) -> dolfinx.fem.FunctionSpaceBase: """Return the common finite element space of any Function that will be added to this list.""" return self._function_space diff --git a/rbnicsx/backends/import_.py b/rbnicsx/backends/import_.py index 6e03b12..f848d67 100644 --- a/rbnicsx/backends/import_.py +++ b/rbnicsx/backends/import_.py @@ -19,7 +19,9 @@ from rbnicsx.io import on_rank_zero -def import_function(function_space: dolfinx.fem.FunctionSpace, directory: str, filename: str) -> dolfinx.fem.Function: +def import_function( + function_space: dolfinx.fem.FunctionSpaceBase, directory: str, filename: str +) -> dolfinx.fem.Function: """ Import a dolfinx.fem.Function from file. @@ -46,7 +48,7 @@ def import_function(function_space: dolfinx.fem.FunctionSpace, directory: str, f def import_functions( - function_space: dolfinx.fem.FunctionSpace, directory: str, filename: str + function_space: dolfinx.fem.FunctionSpaceBase, directory: str, filename: str ) -> typing.List[dolfinx.fem.Function]: """ Import a list of dolfinx.fem.Function from file. diff --git a/tests/unit/backends/test_backends_export_import.py b/tests/unit/backends/test_backends_export_import.py index d0a83c0..b6e3251 100644 --- a/tests/unit/backends/test_backends_export_import.py +++ b/tests/unit/backends/test_backends_export_import.py @@ -29,7 +29,7 @@ def mesh() -> dolfinx.mesh.Mesh: def test_backends_export_import_function(mesh: dolfinx.mesh.Mesh) -> None: """Check I/O for a dolfinx.fem.Function.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) function = dolfinx.fem.Function(V) function.vector.set(1.0) @@ -42,7 +42,7 @@ def test_backends_export_import_function(mesh: dolfinx.mesh.Mesh) -> None: def test_backends_export_import_functions(mesh: dolfinx.mesh.Mesh) -> None: """Check I/O for a list of dolfinx.fem.Function.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) functions = list() indices = list() for i in range(2): @@ -62,7 +62,7 @@ def test_backends_export_import_functions(mesh: dolfinx.mesh.Mesh) -> None: def test_backends_export_import_vector(mesh: dolfinx.mesh.Mesh) -> None: """Check I/O for a petsc4py.PETSc.Vec.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) v = ufl.TestFunction(V) linear_form = ufl.inner(1, v) * ufl.dx linear_form_cpp = dolfinx.fem.form(linear_form) @@ -78,7 +78,7 @@ def test_backends_export_import_vector(mesh: dolfinx.mesh.Mesh) -> None: def test_backends_export_import_vectors(mesh: dolfinx.mesh.Mesh) -> None: """Check I/O for a list of petsc4py.PETSc.Vec.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) v = ufl.TestFunction(V) linear_forms = [ufl.inner(i + 1, v) * ufl.dx for i in range(2)] linear_forms_cpp = dolfinx.fem.form(linear_forms) @@ -100,7 +100,7 @@ def test_backends_export_import_matrix( # type: ignore[no-any-unimported] to_dense_matrix: typing.Callable[[petsc4py.PETSc.Mat], np.typing.NDArray[petsc4py.PETSc.ScalarType]] ) -> None: """Check I/O for a petsc4py.PETSc.Mat.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) u = ufl.TrialFunction(V) v = ufl.TestFunction(V) bilinear_form = ufl.inner(u, v) * ufl.dx @@ -120,7 +120,7 @@ def test_backends_export_import_matrices( # type: ignore[no-any-unimported] to_dense_matrix: typing.Callable[[petsc4py.PETSc.Mat], np.typing.NDArray[petsc4py.PETSc.ScalarType]] ) -> None: """Check I/O for a list of petsc4py.PETSc.Mat.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) u = ufl.TrialFunction(V) v = ufl.TestFunction(V) bilinear_forms = [(i + 1) * ufl.inner(u, v) * ufl.dx for i in range(2)] diff --git a/tests/unit/backends/test_backends_functions_list.py b/tests/unit/backends/test_backends_functions_list.py index 441e296..fbf878f 100644 --- a/tests/unit/backends/test_backends_functions_list.py +++ b/tests/unit/backends/test_backends_functions_list.py @@ -26,7 +26,7 @@ def mesh() -> dolfinx.mesh.Mesh: @pytest.fixture def functions_list(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.FunctionsList: """Generate a rbnicsx.backends.FunctionsList with two entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) functions_list = rbnicsx.backends.FunctionsList(V) for i in range(2): function = dolfinx.fem.Function(V) @@ -134,7 +134,7 @@ def test_backends_functions_list_mul(functions_list: rbnicsx.backends.FunctionsL def test_backends_functions_list_mul_empty(mesh: dolfinx.mesh.Mesh) -> None: """Check rbnicsx.backends.FunctionsList.__mul__ with empty list.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) empty_functions_list = rbnicsx.backends.FunctionsList(V) online_vec = rbnicsx.online.create_vector(0) diff --git a/tests/unit/backends/test_backends_gram_schmidt.py b/tests/unit/backends/test_backends_gram_schmidt.py index db4a319..24fa275 100644 --- a/tests/unit/backends/test_backends_gram_schmidt.py +++ b/tests/unit/backends/test_backends_gram_schmidt.py @@ -27,7 +27,7 @@ def mesh() -> dolfinx.mesh.Mesh: @pytest.fixture def functions(mesh: dolfinx.mesh.Mesh) -> typing.List[dolfinx.fem.Function]: """Generate a list of pairwise linearly independent functions.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) function0 = dolfinx.fem.Function(V) with function0.vector.localForm() as function0_local: function0_local.set(1) @@ -44,7 +44,7 @@ def functions(mesh: dolfinx.mesh.Mesh) -> typing.List[dolfinx.fem.Function]: @pytest.fixture def inner_product(mesh: dolfinx.mesh.Mesh) -> ufl.Form: # type: ignore[no-any-unimported] """Generate a UFL form storing the L^2 inner product.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) u = ufl.TrialFunction(V) v = ufl.TestFunction(V) return ufl.inner(u, v) * ufl.dx @@ -81,7 +81,7 @@ def test_backends_gram_schmidt_zero( # type: ignore[no-any-unimported] mesh: dolfinx.mesh.Mesh, inner_product: ufl.Form ) -> None: """Check rbnicsx.backends.gram_schmidt when adding a linearly dependent function (e.g., zero).""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) functions_list = rbnicsx.backends.FunctionsList(V) assert len(functions_list) == 0 diff --git a/tests/unit/backends/test_backends_mesh_motion.py b/tests/unit/backends/test_backends_mesh_motion.py index 4690ce7..5f425d8 100644 --- a/tests/unit/backends/test_backends_mesh_motion.py +++ b/tests/unit/backends/test_backends_mesh_motion.py @@ -62,7 +62,7 @@ def _(x: np.typing.NDArray[np.float64]) -> np.typing.NDArray[np.float64]: def shape_parametrization(mesh: dolfinx.mesh.Mesh) -> dolfinx.fem.Function: """Generate a shape parametrization of the unit square for use in tests in this file.""" assert len(mesh.geometry.cmaps) == 1 - M = dolfinx.fem.VectorFunctionSpace(mesh, ("Lagrange", mesh.geometry.cmaps[0].degree)) + M = dolfinx.fem.functionspace(mesh, ("Lagrange", mesh.geometry.cmaps[0].degree, (mesh.geometry.dim, ))) shape_parametrization = dolfinx.fem.Function(M) shape_parametrization.interpolate(shape_parametrization_expression(mesh.topology.dim)) return shape_parametrization @@ -72,7 +72,7 @@ def shape_parametrization(mesh: dolfinx.mesh.Mesh) -> dolfinx.fem.Function: def identity(mesh: dolfinx.mesh.Mesh) -> dolfinx.fem.Function: """Generate the identity shape parametrization of the unit square for use in tests in this file.""" assert len(mesh.geometry.cmaps) == 1 - M = dolfinx.fem.VectorFunctionSpace(mesh, ("Lagrange", mesh.geometry.cmaps[0].degree)) + M = dolfinx.fem.functionspace(mesh, ("Lagrange", mesh.geometry.cmaps[0].degree, (mesh.geometry.dim, ))) identity = dolfinx.fem.Function(M) identity.interpolate(lambda x: x[:mesh.topology.dim]) return identity diff --git a/tests/unit/backends/test_backends_projection.py b/tests/unit/backends/test_backends_projection.py index d70959b..9396f52 100644 --- a/tests/unit/backends/test_backends_projection.py +++ b/tests/unit/backends/test_backends_projection.py @@ -30,7 +30,7 @@ def mesh() -> dolfinx.mesh.Mesh: @pytest.fixture def functions_list(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.FunctionsList: """Generate a rbnicsx.backends.FunctionsList with several entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) functions_list = rbnicsx.backends.FunctionsList(V) for i in range(14): function = dolfinx.fem.Function(V) diff --git a/tests/unit/backends/test_backends_proper_orthogonal_decomposition.py b/tests/unit/backends/test_backends_proper_orthogonal_decomposition.py index 840d83d..5ee021d 100644 --- a/tests/unit/backends/test_backends_proper_orthogonal_decomposition.py +++ b/tests/unit/backends/test_backends_proper_orthogonal_decomposition.py @@ -30,7 +30,7 @@ def mesh() -> dolfinx.mesh.Mesh: @pytest.fixture def functions_list(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.FunctionsList: """Generate a rbnicsx.backends.FunctionsList with four linearly dependent entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) functions_list = rbnicsx.backends.FunctionsList(V) for i in range(4): function = dolfinx.fem.Function(V) @@ -43,7 +43,7 @@ def functions_list(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.FunctionsList: @pytest.fixture def inner_product(mesh: dolfinx.mesh.Mesh) -> ufl.Form: # type: ignore[no-any-unimported] """Generate a UFL form storing the L^2 inner product.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) u = ufl.TrialFunction(V) v = ufl.TestFunction(V) return ufl.inner(u, v) * ufl.dx @@ -52,7 +52,7 @@ def inner_product(mesh: dolfinx.mesh.Mesh) -> ufl.Form: # type: ignore[no-any-u @pytest.fixture def tensors_list_vec(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsList: """Generate a rbnicsx.backends.TensorsList with two linearly dependent petsc4py.PETSc.Vec entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) v = ufl.TestFunction(V) linear_forms = [ufl.inner(i + 1, v) * ufl.dx for i in range(2)] linear_forms_cpp = dolfinx.fem.form(linear_forms) @@ -68,7 +68,7 @@ def tensors_list_vec(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsList: @pytest.fixture def tensors_list_mat(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsList: """Generate a rbnicsx.backends.TensorsList with two linearly dependent petsc4py.PETSc.Mat entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) u = ufl.TrialFunction(V) v = ufl.TestFunction(V) bilinear_forms = [(i + 1) * ufl.inner(u, v) * ufl.dx for i in range(2)] @@ -221,7 +221,7 @@ def test_backends_proper_orthogonal_decomposition_zero( # type: ignore[no-any-u mesh: dolfinx.mesh.Mesh, inner_product: ufl.Form, normalize: bool ) -> None: """Check rbnicsx.backends.proper_orthogonal_decomposition for the case of all zero snapshots.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) functions_list = rbnicsx.backends.FunctionsList(V) functions_list.extend([dolfinx.fem.Function(V) for _ in range(2)]) compute_inner_product = rbnicsx.backends.bilinear_form_action(inner_product) diff --git a/tests/unit/backends/test_backends_tensors_array.py b/tests/unit/backends/test_backends_tensors_array.py index 653f4cd..9478fb7 100644 --- a/tests/unit/backends/test_backends_tensors_array.py +++ b/tests/unit/backends/test_backends_tensors_array.py @@ -32,7 +32,7 @@ def mesh() -> dolfinx.mesh.Mesh: @pytest.fixture def tensors_1d_array_vec(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsArray: """Generate a rbnicsx.backends.TensorsArray with six petsc4py.PETSc.Vec entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) v = ufl.TestFunction(V) linear_forms = [ufl.inner(i + 1, v) * ufl.dx for i in range(6)] linear_forms_cpp = dolfinx.fem.form(linear_forms) @@ -49,7 +49,7 @@ def tensors_1d_array_vec(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsArr @pytest.fixture def tensors_2d_array_vec(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsArray: """Generate a rbnicsx.backends.TensorsArray with two-by-three petsc4py.PETSc.Vec entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) v = ufl.TestFunction(V) linear_forms = [ufl.inner(i + 1, v) * ufl.dx for i in range(6)] linear_forms_cpp = dolfinx.fem.form(linear_forms) @@ -67,7 +67,7 @@ def tensors_2d_array_vec(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsArr @pytest.fixture def tensors_1d_array_mat(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsArray: """Generate a rbnicsx.backends.TensorsArray with six petsc4py.PETSc.Mat entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) u = ufl.TrialFunction(V) v = ufl.TestFunction(V) bilinear_forms = [(i + 1) * ufl.inner(u, v) * ufl.dx for i in range(6)] @@ -85,7 +85,7 @@ def tensors_1d_array_mat(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsArr @pytest.fixture def tensors_2d_array_mat(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsArray: """Generate a rbnicsx.backends.TensorsArray with two-by-three petsc4py.PETSc.Mat entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) u = ufl.TrialFunction(V) v = ufl.TestFunction(V) bilinear_forms = [(i + 1) * ufl.inner(u, v) * ufl.dx for i in range(6)] diff --git a/tests/unit/backends/test_backends_tensors_list.py b/tests/unit/backends/test_backends_tensors_list.py index abc6c90..8ed1807 100644 --- a/tests/unit/backends/test_backends_tensors_list.py +++ b/tests/unit/backends/test_backends_tensors_list.py @@ -32,7 +32,7 @@ def mesh() -> dolfinx.mesh.Mesh: @pytest.fixture def tensors_list_vec(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsList: """Generate a rbnicsx.backends.TensorsList with two petsc4py.PETSc.Vec entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) v = ufl.TestFunction(V) linear_forms = [ufl.inner(i + 1, v) * ufl.dx for i in range(2)] linear_forms_cpp = dolfinx.fem.form(linear_forms) @@ -49,7 +49,7 @@ def tensors_list_vec(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsList: @pytest.fixture def tensors_list_mat(mesh: dolfinx.mesh.Mesh) -> rbnicsx.backends.TensorsList: """Generate a rbnicsx.backends.TensorsList with two petsc4py.PETSc.Mat entries.""" - V = dolfinx.fem.FunctionSpace(mesh, ("Lagrange", 1)) + V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1)) u = ufl.TrialFunction(V) v = ufl.TestFunction(V) bilinear_forms = [(i + 1) * ufl.inner(u, v) * ufl.dx for i in range(2)] diff --git a/tutorials/01_thermal_block.ipynb b/tutorials/01_thermal_block.ipynb index 3ef1e58..6d7282c 100644 --- a/tutorials/01_thermal_block.ipynb +++ b/tutorials/01_thermal_block.ipynb @@ -238,7 +238,7 @@ "\n", " def __init__(self) -> None:\n", " # Define function space\n", - " V = dolfinx.fem.FunctionSpace(mesh, (\"Lagrange\", 1))\n", + " V = dolfinx.fem.functionspace(mesh, (\"Lagrange\", 1))\n", " self._V = V\n", " # Define trial and test functions\n", " u = ufl.TrialFunction(V)\n", @@ -272,7 +272,7 @@ " self._bcs = bcs\n", "\n", " @property\n", - " def function_space(self) -> dolfinx.fem.FunctionSpace:\n", + " def function_space(self) -> dolfinx.fem.FunctionSpaceBase:\n", " \"\"\"Return the function space of the problem.\"\"\"\n", " return self._V\n", "\n", @@ -412,7 +412,7 @@ " self._restriction = restriction\n", "\n", " @property\n", - " def function_space(self) -> dolfinx.fem.FunctionSpace:\n", + " def function_space(self) -> dolfinx.fem.FunctionSpaceBase:\n", " \"\"\"Return the function space of the eigenvalue problem.\"\"\"\n", " return self._V\n", "\n", diff --git a/tutorials/02_elastic_block.ipynb b/tutorials/02_elastic_block.ipynb index 6aa247c..e831a2e 100644 --- a/tutorials/02_elastic_block.ipynb +++ b/tutorials/02_elastic_block.ipynb @@ -206,7 +206,7 @@ "\n", " def __init__(self) -> None:\n", " # Define function space\n", - " V = dolfinx.fem.VectorFunctionSpace(mesh, (\"Lagrange\", 1))\n", + " V = dolfinx.fem.functionspace(mesh, (\"Lagrange\", 1, (mesh.geometry.dim, )))\n", " self._V = V\n", " # Define trial and test functions\n", " u = ufl.TrialFunction(V)\n", @@ -249,7 +249,7 @@ " + lambda_1 * ufl.inner(ufl.tr(ufl.sym(ufl.grad(u))), ufl.tr(ufl.sym(ufl.grad(v)))))\n", "\n", " @property\n", - " def function_space(self) -> dolfinx.fem.FunctionSpace:\n", + " def function_space(self) -> dolfinx.fem.FunctionSpaceBase:\n", " \"\"\"Return the function space of the problem.\"\"\"\n", " return self._V\n", "\n", diff --git a/tutorials/03_hole.ipynb b/tutorials/03_hole.ipynb index 20b2017..f74366a 100644 --- a/tutorials/03_hole.ipynb +++ b/tutorials/03_hole.ipynb @@ -313,7 +313,8 @@ " def __init__(self, mu: np.typing.NDArray[np.float64]) -> None:\n", " # Define function space\n", " assert len(mesh.geometry.cmaps) == 1\n", - " M = dolfinx.fem.VectorFunctionSpace(mesh, (\"Lagrange\", mesh.geometry.cmaps[0].degree))\n", + " M = dolfinx.fem.functionspace(\n", + " mesh, (\"Lagrange\", mesh.geometry.cmaps[0].degree, (mesh.geometry.dim, )))\n", " # Interpolate affine shape parametrization expression on a dolfinx Function\n", " shape_parametrization = dolfinx.fem.Function(M)\n", " for (label, expression) in enumerate(self.get_shape_parametrization_expression(mu)):\n", @@ -379,7 +380,8 @@ " def __init__(self, mu: np.typing.NDArray[np.float64]) -> None:\n", " # Define function space\n", " assert len(mesh.geometry.cmaps) == 1\n", - " M = dolfinx.fem.VectorFunctionSpace(mesh, (\"Lagrange\", mesh.geometry.cmaps[0].degree))\n", + " M = dolfinx.fem.functionspace(\n", + " mesh, (\"Lagrange\", mesh.geometry.cmaps[0].degree, (mesh.geometry.dim, )))\n", " # Define trial and test functions\n", " m = ufl.TrialFunction(M)\n", " n = ufl.TestFunction(M)\n", @@ -491,7 +493,7 @@ "\n", " def __init__(self) -> None:\n", " # Define function space\n", - " V = dolfinx.fem.FunctionSpace(mesh, (\"Lagrange\", 1))\n", + " V = dolfinx.fem.functionspace(mesh, (\"Lagrange\", 1))\n", " self._V = V\n", " # Define trial and test functions\n", " u = ufl.TrialFunction(V)\n", @@ -513,7 +515,7 @@ " self._mu = np.zeros(mu_symb.value.shape)\n", "\n", " @property\n", - " def function_space(self) -> dolfinx.fem.FunctionSpace:\n", + " def function_space(self) -> dolfinx.fem.FunctionSpaceBase:\n", " \"\"\"Return the function space of the problem.\"\"\"\n", " return self._V\n", "\n", diff --git a/tutorials/04_graetz.ipynb b/tutorials/04_graetz.ipynb index 7c7a510..843f18c 100644 --- a/tutorials/04_graetz.ipynb +++ b/tutorials/04_graetz.ipynb @@ -193,7 +193,8 @@ " def __init__(self, mu: np.typing.NDArray[np.float64]) -> None:\n", " # Define function space\n", " assert len(mesh.geometry.cmaps) == 1\n", - " M = dolfinx.fem.VectorFunctionSpace(mesh, (\"Lagrange\", mesh.geometry.cmaps[0].degree))\n", + " M = dolfinx.fem.functionspace(\n", + " mesh, (\"Lagrange\", mesh.geometry.cmaps[0].degree, (mesh.geometry.dim, )))\n", " # Interpolate affine shape parametrization expression on a dolfinx Function\n", " shape_parametrization = dolfinx.fem.Function(M)\n", " shape_parametrization.interpolate(\n", @@ -228,7 +229,7 @@ "\n", " def __init__(self) -> None:\n", " # Define function space\n", - " V = dolfinx.fem.FunctionSpace(mesh, (\"Lagrange\", 1))\n", + " V = dolfinx.fem.functionspace(mesh, (\"Lagrange\", 1))\n", " self._V = V\n", " # Define trial and test functions\n", " u = ufl.TrialFunction(V)\n", @@ -265,7 +266,7 @@ " self._mesh_motion: typing.Optional[rbnicsx.backends.MeshMotion] = None\n", "\n", " @property\n", - " def function_space(self) -> dolfinx.fem.FunctionSpace:\n", + " def function_space(self) -> dolfinx.fem.FunctionSpaceBase:\n", " \"\"\"Return the function space of the problem.\"\"\"\n", " return self._V\n", "\n", diff --git a/tutorials/05_gaussian.ipynb b/tutorials/05_gaussian.ipynb index 32feb26..5169eec 100644 --- a/tutorials/05_gaussian.ipynb +++ b/tutorials/05_gaussian.ipynb @@ -172,7 +172,7 @@ "\n", " def __init__(self) -> None:\n", " # Define function space\n", - " V = dolfinx.fem.FunctionSpace(mesh, (\"Lagrange\", 1))\n", + " V = dolfinx.fem.functionspace(mesh, (\"Lagrange\", 1))\n", " self._V = V\n", " # Define trial and test functions\n", " u = ufl.TrialFunction(V)\n", @@ -200,7 +200,7 @@ " self._bcs = bcs\n", "\n", " @property\n", - " def function_space(self) -> dolfinx.fem.FunctionSpace:\n", + " def function_space(self) -> dolfinx.fem.FunctionSpaceBase:\n", " \"\"\"Return the function space of the problem.\"\"\"\n", " return self._V\n", "\n", diff --git a/tutorials/07_nonlinear_elliptic.ipynb b/tutorials/07_nonlinear_elliptic.ipynb index 045a5a7..bb11a83 100644 --- a/tutorials/07_nonlinear_elliptic.ipynb +++ b/tutorials/07_nonlinear_elliptic.ipynb @@ -170,7 +170,7 @@ "\n", " def __init__(self) -> None:\n", " # Define function space\n", - " V = dolfinx.fem.FunctionSpace(mesh, (\"Lagrange\", 1))\n", + " V = dolfinx.fem.functionspace(mesh, (\"Lagrange\", 1))\n", " self._V = V\n", " # Define test function\n", " v = ufl.TestFunction(V)\n", @@ -201,7 +201,7 @@ " self._bcs = bcs\n", "\n", " @property\n", - " def function_space(self) -> dolfinx.fem.FunctionSpace:\n", + " def function_space(self) -> dolfinx.fem.FunctionSpaceBase:\n", " \"\"\"Return the function space of the problem.\"\"\"\n", " return self._V\n", "\n", diff --git a/tutorials/12_stokes.ipynb b/tutorials/12_stokes.ipynb index f464f8a..9538554 100644 --- a/tutorials/12_stokes.ipynb +++ b/tutorials/12_stokes.ipynb @@ -248,7 +248,8 @@ " def __init__(self, mu: np.typing.NDArray[np.float64]) -> None:\n", " # Define function space\n", " assert len(mesh.geometry.cmaps) == 1\n", - " M = dolfinx.fem.VectorFunctionSpace(mesh, (\"Lagrange\", mesh.geometry.cmaps[0].degree))\n", + " M = dolfinx.fem.functionspace(\n", + " mesh, (\"Lagrange\", mesh.geometry.cmaps[0].degree, (mesh.geometry.dim, )))\n", " # Interpolate affine shape parametrization expression on a dolfinx Function\n", " shape_parametrization = dolfinx.fem.Function(M)\n", " shape_parametrization.interpolate(\n", @@ -294,8 +295,8 @@ " # Define function space\n", " V_element = ufl.VectorElement(\"Lagrange\", mesh.ufl_cell(), 2)\n", " Q_element = ufl.FiniteElement(\"Lagrange\", mesh.ufl_cell(), 1)\n", - " V = dolfinx.fem.FunctionSpace(mesh, V_element)\n", - " Q = dolfinx.fem.FunctionSpace(mesh, Q_element)\n", + " V = dolfinx.fem.functionspace(mesh, V_element)\n", + " Q = dolfinx.fem.functionspace(mesh, Q_element)\n", " self._VQ = (V, Q)\n", " # Define trial and test functions\n", " (v, q) = (ufl.TestFunction(V), ufl.TestFunction(Q))\n", @@ -326,7 +327,9 @@ " self._mesh_motion: typing.Optional[rbnicsx.backends.MeshMotion] = None\n", "\n", " @property\n", - " def function_spaces(self) -> typing.Tuple[dolfinx.fem.FunctionSpace, dolfinx.fem.FunctionSpace]:\n", + " def function_spaces(self) -> typing.Tuple[\n", + " dolfinx.fem.FunctionSpaceBase, dolfinx.fem.FunctionSpaceBase\n", + " ]:\n", " \"\"\"Return the function spaces of the problem.\"\"\"\n", " return self._VQ\n", "\n", diff --git a/tutorials/17_navier_stokes.ipynb b/tutorials/17_navier_stokes.ipynb index 0838d23..b1c34e9 100644 --- a/tutorials/17_navier_stokes.ipynb +++ b/tutorials/17_navier_stokes.ipynb @@ -182,8 +182,8 @@ " # Define function space\n", " V_element = ufl.VectorElement(\"Lagrange\", mesh.ufl_cell(), 2)\n", " Q_element = ufl.FiniteElement(\"Lagrange\", mesh.ufl_cell(), 1)\n", - " V = dolfinx.fem.FunctionSpace(mesh, V_element)\n", - " Q = dolfinx.fem.FunctionSpace(mesh, Q_element)\n", + " V = dolfinx.fem.functionspace(mesh, V_element)\n", + " Q = dolfinx.fem.functionspace(mesh, Q_element)\n", " self._VQ = (V, Q)\n", " # Define trial and test functions\n", " (v, q) = (ufl.TestFunction(V), ufl.TestFunction(Q))\n", @@ -222,7 +222,9 @@ " self._bcs = bcs\n", "\n", " @property\n", - " def function_spaces(self) -> typing.Tuple[dolfinx.fem.FunctionSpace, dolfinx.fem.FunctionSpace]:\n", + " def function_spaces(self) -> typing.Tuple[\n", + " dolfinx.fem.FunctionSpaceBase, dolfinx.fem.FunctionSpaceBase\n", + " ]:\n", " \"\"\"Return the function spaces of the problem.\"\"\"\n", " return self._VQ\n", "\n",