From 295cdbfae983b4a62e44d6e4745945dc9475d15e Mon Sep 17 00:00:00 2001 From: niravshah241 Date: Thu, 1 Aug 2024 19:40:42 +0100 Subject: [PATCH] Demos added in CI --- .../0_fundamentals.py | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/demo/0_fundamental_deformation/0_fundamentals.py b/demo/0_fundamental_deformation/0_fundamentals.py index b604f2e..1043eb7 100644 --- a/demo/0_fundamental_deformation/0_fundamentals.py +++ b/demo/0_fundamental_deformation/0_fundamentals.py @@ -1,23 +1,3 @@ -''' -The purpose of this excercise is to demonstrate Harmonic mesh extension: -Shamanskiy, A., Simeon, B. Mesh moving techniques in fluid-structure interaction: robustness, accumulated distortion and computational efficiency. Comput Mech 67, 583–600 (2021). https://doi.org/10.1007/s00466-020-01950-x -We solve Laplace's equation on the reference domain to calculate pointwise mesh deformation based on the specified mesh deformation on the boundary. - -In this example, we consider unit square as the reference domain \Omega. We apply specified mesh displacement on the top (\Gamma_{top} \subset \partial \Omega) and bottom (\Gamma_{bottom}\subset \partial \Omega) boundaries and use Harmonic mesh extension to propoagate the displacement inside the domain. - -Reference domain: \Omega = [0, 1]^2 (Unit square) -Solve Laplace's equation: -- \Delta u = 0 \ , \ \text{in} \Omega \ , -B.C.s ((x, y) \in \Omega): -On bottom boundary (\Gamma_1 \cup \Gamma_5): u = (0., 0.2 * sin(2 \pi x)) \ , (Specified mesh displacement) \\ -On top boundary (\Gamma_9 \cup \Gamma_{12}): u = (0., 0.1 * sin(2 \pi x)) \ , (Specified mesh displacement) \\ -On left and right boundaries (\Gamma_4 \cup \Gamma_6 \cup \Gamma_{10} \cup \Gamma_{11}): -u = (0., 0.) - -The deformed domain \tilde{\Omega} is given by: -\tilde{x} = x + u \ , \ \tilde{x} \in \tilde{\Omega} \ , \ x \in \Omega \ . -''' - from mpi4py import MPI from petsc4py import PETSc @@ -87,19 +67,22 @@ def bc_side(x): ''' # We now solve Laplace's equation on the REFERENCE mesh -a_form = dolfinx.fem.form(ufl.inner(ufl.grad(u), ufl.grad(v))*ufl.dx) +a_form = dolfinx.fem.form(ufl.inner(ufl.grad(u), + ufl.grad(v)) * ufl.dx) l_form = \ dolfinx.fem.form(ufl.inner(dolfinx.fem.Constant - (mesh, PETSc.ScalarType((0.,) * mesh.geometry.dim)), - v) * ufl.dx) + (mesh, + PETSc.ScalarType((0.,) * + mesh.geometry.dim) + ), v) * ufl.dx) uh = dolfinx.fem.Function(V) A = assemble_matrix(a_form, bcs=bc_list) A.assemble() F = assemble_vector(l_form) -dolfinx.fem.petsc.apply_lifting(F, [a_form], [bc_list]) +apply_lifting(F, [a_form], [bc_list]) F.ghostUpdate(addv=PETSc.InsertMode.ADD, mode=PETSc.ScatterMode.REVERSE) -dolfinx.fem.petsc.set_bc(F, bc_list) +set_bc(F, bc_list) ksp = PETSc.KSP() ksp.create(mesh.comm) ksp.setOperators(A) @@ -117,7 +100,7 @@ def bc_side(x): with dolfinx.io.XDMFFile(mesh.comm, - f"deformed_mesh_data/deformed_mesh.xdmf", + "deformed_mesh_data/deformed_mesh.xdmf", "w") as mesh_file_xdmf: mesh_file_xdmf.write_mesh(mesh) mesh_file_xdmf.write_meshtags(subdomains, mesh.geometry)