From 1bd661e656523cb1a86178a43b1bb63243feebe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20S=2E=20Dokken?= Date: Tue, 15 Oct 2024 11:04:19 +0200 Subject: [PATCH 1/3] Bump versions Add destruction of PETSc objects to tests, demos and benchmarks --- CITATION.cff | 4 ++-- cpp/CMakeLists.txt | 4 ++-- python/benchmarks/bench_contact_3D.py | 3 ++- python/demos/demo_contact_2D.py | 3 ++- python/demos/demo_elasticity.py | 2 ++ python/dolfinx_mpc/utils/mpc_utils.py | 2 ++ python/pyproject.toml | 4 ++-- python/tests/test_cube_contact.py | 2 ++ python/tests/test_integration_domains.py | 1 - python/tests/test_lifting.py | 3 +++ python/tests/test_linear_problem.py | 2 ++ python/tests/test_surface_integral.py | 4 ++++ python/tests/test_vector_assembly.py | 2 ++ python/tests/test_vector_poisson.py | 1 + 14 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index fb0fbbb8..5318d068 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -5,5 +5,5 @@ authors: given-names: Jørgen Schartum orcid: https://orcid.org/0000-0001-6489-8858 title: "DOLFINx-MPC" -version: 0.8.0 -date-released: 2023-04-25 +version: 0.9.0 +date-released: 2023-10-15 diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 298af6e8..d3c0719a 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.21) #------------------------------------------------------------------------------ # Set project name and version number -project(DOLFINX_MPC VERSION "0.8.0.0") +project(DOLFINX_MPC VERSION "0.9.0.0") #------------------------------------------------------------------------------ # General configuration @@ -23,7 +23,7 @@ option(CMAKE_INSTALL_RPATH_USE_LINK_PATH "Add paths to linker search and install add_feature_info(CMAKE_INSTALL_RPATH_USE_LINK_PATH CMAKE_INSTALL_RPATH_USE_LINK_PATH "Add paths to linker search and installed rpath.") # Check for required package DOLFINX -find_package(DOLFINX 0.8.0.0 REQUIRED) +find_package(DOLFINX 0.9.0.0 REQUIRED) set_package_properties(DOLFINX PROPERTIES TYPE REQUIRED DESCRIPTION "New generation Dynamic Object-oriented Library for - FINite element computation" URL "https://github.com/FEniCS/dolfinx" diff --git a/python/benchmarks/bench_contact_3D.py b/python/benchmarks/bench_contact_3D.py index b2730d32..f09d158a 100644 --- a/python/benchmarks/bench_contact_3D.py +++ b/python/benchmarks/bench_contact_3D.py @@ -372,7 +372,8 @@ def sigma(v): if comm.rank == 0: print(op, num_calls, avg_time, min_time, max_time, file=results_file) list_timings(MPI.COMM_WORLD, [TimingType.wall]) - + b.destroy() + solver.destroy() if __name__ == "__main__": parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) diff --git a/python/demos/demo_contact_2D.py b/python/demos/demo_contact_2D.py index e1c8f182..a66f0f30 100644 --- a/python/demos/demo_contact_2D.py +++ b/python/demos/demo_contact_2D.py @@ -157,6 +157,7 @@ def left_corner(x): # Solve Linear problem problem = LinearProblem(a, rhs, mpc, bcs=bcs, petsc_options=petsc_options) + # Build near nullspace null_space = rigid_motions_nullspace(mpc.function_space) problem.A.setNearNullSpace(null_space) @@ -210,7 +211,7 @@ def left_corner(x): uh_numpy = K @ d assert np.allclose(uh_numpy, u_mpc, rtol=tol, atol=tol) L_org.destroy() - + A_org.destroy() if __name__ == "__main__": parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) diff --git a/python/demos/demo_elasticity.py b/python/demos/demo_elasticity.py index 4395a96e..dfa90399 100644 --- a/python/demos/demo_elasticity.py +++ b/python/demos/demo_elasticity.py @@ -173,6 +173,8 @@ def l2b(li): l2g = dofmap.index_map.local_to_global(np.arange(num_local, dtype=np.int32)) l_index = np.flatnonzero(l2g == in_data[0] // bs)[0] print("Master*Coeff (on other proc): {0:.5e}".format(u_h.x.array[l_index * bs + in_data[0] % bs] * in_data[1])) + L_org.destroy() + solver.destroy() if __name__ == "__main__": diff --git a/python/dolfinx_mpc/utils/mpc_utils.py b/python/dolfinx_mpc/utils/mpc_utils.py index 5a0b7e63..7787d97b 100644 --- a/python/dolfinx_mpc/utils/mpc_utils.py +++ b/python/dolfinx_mpc/utils/mpc_utils.py @@ -143,6 +143,8 @@ def tangential_proj(u, n): solver.solve(b, nh.x.petsc_vec) nh.x.petsc_vec.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD) # type: ignore timer.stop() + solver.destroy() + b.destroy() return nh diff --git a/python/pyproject.toml b/python/pyproject.toml index 1596107e..8bc80de6 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -13,7 +13,7 @@ build-backend = "scikit_build_core.build" [project] name = "dolfinx_mpc" -version = "0.8.0.dev0" +version = "0.9.0" description = "DOLFINx_MPC Python interface" readme = "README.md" requires-python = ">=3.8.0" @@ -24,7 +24,7 @@ dependencies = [ "cffi", "petsc4py", "mpi4py", - "fenics-dolfinx>0.8.0", + "fenics-dolfinx>=0.9.0", ] [project.optional-dependencies] diff --git a/python/tests/test_cube_contact.py b/python/tests/test_cube_contact.py index 0c26258f..7537ca1d 100644 --- a/python/tests/test_cube_contact.py +++ b/python/tests/test_cube_contact.py @@ -298,5 +298,7 @@ def sigma(v): atol = 1000 * np.finfo(default_scalar_type).resolution nt.assert_allclose(uh_numpy, u_mpc, atol=atol) L_org.destroy() + b.destroy() + solver.destroy() list_timings(comm, [TimingType.wall]) diff --git a/python/tests/test_integration_domains.py b/python/tests/test_integration_domains.py index b550e2bb..f7582299 100644 --- a/python/tests/test_integration_domains.py +++ b/python/tests/test_integration_domains.py @@ -127,7 +127,6 @@ def l2b(li): ) solver.destroy() b.destroy() - del uh A.destroy() pc.destroy() L_org.destroy() diff --git a/python/tests/test_lifting.py b/python/tests/test_lifting.py index 1f80f0c2..cd7e9f69 100644 --- a/python/tests/test_lifting.py +++ b/python/tests/test_lifting.py @@ -118,3 +118,6 @@ def l2b(li): nt.assert_allclose(uh_numpy, u_mpc, rtol=1e-5, atol=1e-8) list_timings(comm, [TimingType.wall]) + L_org.destroy() + b.destroy() + solver.destroy() diff --git a/python/tests/test_linear_problem.py b/python/tests/test_linear_problem.py index 5f7ae2c3..c989bf75 100644 --- a/python/tests/test_linear_problem.py +++ b/python/tests/test_linear_problem.py @@ -97,6 +97,8 @@ def PeriodicBoundary(x): rtol=500 * np.finfo(default_scalar_type).resolution, atol=500 * np.finfo(default_scalar_type).resolution, ) + L_org.destroy() + A_org.destroy() else: uh = fem.Function(V) diff --git a/python/tests/test_surface_integral.py b/python/tests/test_surface_integral.py index 80f0017b..23fafecc 100644 --- a/python/tests/test_surface_integral.py +++ b/python/tests/test_surface_integral.py @@ -140,6 +140,8 @@ def l2b(li): L_org.destroy() b.destroy() + A_org.destroy() + solver.destroy() list_timings(comm, [TimingType.wall]) @@ -213,4 +215,6 @@ def l2b(li): dolfinx_mpc.utils.compare_mpc_rhs(L_org, b, mpc, root=root) L_org.destroy() b.destroy() + A_org.destroy() + A.destroy() list_timings(comm, [TimingType.wall]) diff --git a/python/tests/test_vector_assembly.py b/python/tests/test_vector_assembly.py index 5e32ef2c..785a4595 100644 --- a/python/tests/test_vector_assembly.py +++ b/python/tests/test_vector_assembly.py @@ -60,3 +60,5 @@ def l2b(li): dolfinx_mpc.utils.compare_mpc_rhs(L_org, b, mpc, root=root) list_timings(comm, [TimingType.wall]) + b.destroy() + L_org.destroy() \ No newline at end of file diff --git a/python/tests/test_vector_poisson.py b/python/tests/test_vector_poisson.py index f2889878..6efdce3c 100644 --- a/python/tests/test_vector_poisson.py +++ b/python/tests/test_vector_poisson.py @@ -130,4 +130,5 @@ def l2b(li): b.destroy() L_org.destroy() + solver.destroy() list_timings(comm, [TimingType.wall]) From 706b7a7802f055cd8fc10f51075613133969c5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Schartum=20Dokken?= Date: Tue, 15 Oct 2024 11:05:25 +0200 Subject: [PATCH 2/3] Fix date --- CITATION.cff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CITATION.cff b/CITATION.cff index 5318d068..e1fca639 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -6,4 +6,4 @@ authors: orcid: https://orcid.org/0000-0001-6489-8858 title: "DOLFINx-MPC" version: 0.9.0 -date-released: 2023-10-15 +date-released: 2024-10-15 From fb8903fecd9226df4ba2d9be0e6a1da148df6dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20S=2E=20Dokken?= Date: Tue, 15 Oct 2024 11:16:20 +0200 Subject: [PATCH 3/3] Ruff formatting --- python/benchmarks/bench_contact_3D.py | 1 + python/demos/demo_contact_2D.py | 2 +- python/dolfinx_mpc/utils/mpc_utils.py | 2 +- python/tests/test_vector_assembly.py | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/python/benchmarks/bench_contact_3D.py b/python/benchmarks/bench_contact_3D.py index f09d158a..0dd86780 100644 --- a/python/benchmarks/bench_contact_3D.py +++ b/python/benchmarks/bench_contact_3D.py @@ -375,6 +375,7 @@ def sigma(v): b.destroy() solver.destroy() + if __name__ == "__main__": parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) parser.add_argument( diff --git a/python/demos/demo_contact_2D.py b/python/demos/demo_contact_2D.py index a66f0f30..38ef0a72 100644 --- a/python/demos/demo_contact_2D.py +++ b/python/demos/demo_contact_2D.py @@ -157,7 +157,6 @@ def left_corner(x): # Solve Linear problem problem = LinearProblem(a, rhs, mpc, bcs=bcs, petsc_options=petsc_options) - # Build near nullspace null_space = rigid_motions_nullspace(mpc.function_space) problem.A.setNearNullSpace(null_space) @@ -213,6 +212,7 @@ def left_corner(x): L_org.destroy() A_org.destroy() + if __name__ == "__main__": parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) parser.add_argument("--res", default=0.1, type=np.float64, dest="res", help="Resolution of Mesh") diff --git a/python/dolfinx_mpc/utils/mpc_utils.py b/python/dolfinx_mpc/utils/mpc_utils.py index 7787d97b..2fe39764 100644 --- a/python/dolfinx_mpc/utils/mpc_utils.py +++ b/python/dolfinx_mpc/utils/mpc_utils.py @@ -144,7 +144,7 @@ def tangential_proj(u, n): nh.x.petsc_vec.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD) # type: ignore timer.stop() solver.destroy() - b.destroy() + b.destroy() return nh diff --git a/python/tests/test_vector_assembly.py b/python/tests/test_vector_assembly.py index 785a4595..c2f75b3c 100644 --- a/python/tests/test_vector_assembly.py +++ b/python/tests/test_vector_assembly.py @@ -61,4 +61,4 @@ def l2b(li): list_timings(comm, [TimingType.wall]) b.destroy() - L_org.destroy() \ No newline at end of file + L_org.destroy()