From a976782df3dbcbeb8016e5bf8c21687b0e180fd3 Mon Sep 17 00:00:00 2001 From: nate-sime Date: Tue, 24 May 2022 12:24:50 -0400 Subject: [PATCH] some demo typos and documentation updates --- python/demo/demo_cahn-hilliard.py | 2 +- python/demo/demo_elasticity.py | 17 +++++----- python/demo/demo_gmsh.py | 1 - python/demo/demo_helmholtz.py | 8 ++--- python/demo/demo_interpolation-io.py | 4 +-- python/demo/demo_lagrange_variants.py | 6 ++-- python/demo/demo_poisson.py | 2 +- python/demo/demo_pyvista.py | 16 +++++----- python/demo/demo_static-condensation.py | 4 +-- python/demo/demo_stokes.py | 41 +++++++++++++------------ python/demo/demo_types.py | 4 +-- 11 files changed, 54 insertions(+), 51 deletions(-) diff --git a/python/demo/demo_cahn-hilliard.py b/python/demo/demo_cahn-hilliard.py index 338f557b59f..9616a4a4ca6 100644 --- a/python/demo/demo_cahn-hilliard.py +++ b/python/demo/demo_cahn-hilliard.py @@ -155,7 +155,7 @@ lmbda = 1.0e-02 # surface parameter dt = 5.0e-06 # time step -theta = 0.5 # time stepping family, e.g. theta=1 -> backward Euler, theta=0.5 -> Crank-Nicolson +theta = 0.5 # time stepping family, e.g. theta=1 -> backward Euler, theta=0.5 -> Crank-Nicholson # A unit square mesh with 96 cells edges in each direction is created, # and on this mesh a diff --git a/python/demo/demo_elasticity.py b/python/demo/demo_elasticity.py index 67319a85d26..4870240241f 100644 --- a/python/demo/demo_elasticity.py +++ b/python/demo/demo_elasticity.py @@ -39,9 +39,9 @@ dtype = PETSc.ScalarType # - -# ## Operators nullspace +# ## Operator's nullspace # -# Smoother aggregation algebraic multigrid solver require the so-called +# Smooth aggregation algebraic multigrid solvers require the so-called # 'near-nullspace', which is the nullspace of the operator in the # absence of boundary conditions. The below function builds a PETSc # NullSpace object. For this 3D elasticity problem the nullspace is @@ -123,7 +123,7 @@ def σ(v): L = form(inner(f, v) * dx) # A homogeneous (zero) boundary condition is created on $x_0 = 0$ and -# $x_1 = 1$ by finding all boundary facets on $x_0 = 0$ and # $x_1 = 1$, +# $x_1 = 1$ by finding all boundary facets on $x_0 = 0$ and $x_1 = 1$, # and then creating a Dirichlet boundary condition object. facets = locate_entities_boundary(msh, dim=2, @@ -157,12 +157,12 @@ def σ(v): set_bc(b, [bc]) # - -# Create the a near nullspace and attach it to the PETSc matrix: +# Create the near-nullspace and attach it to the PETSc matrix: null_space = build_nullspace(V) A.setNearNullSpace(null_space) -# Set PETsc solver options, create a PETSc Krylov solver, and attach the +# Set PETSc solver options, create a PETSc Krylov solver, and attach the # matrix `A` to the solver: # + @@ -188,18 +188,19 @@ def σ(v): solver.setOperators(A) # - -# Create a solution Function `uh` and solve: +# Create a solution {py:class}`Function`, `uh`, and +# solve: # + uh = Function(V) -# Set a monitor, solve linear system, and dispay the solver +# Set a monitor, solve linear system, and display the solver # configuration solver.setMonitor(lambda _, its, rnorm: print(f"Iteration: {its}, rel. residual: {rnorm}")) solver.solve(b, uh.vector) solver.view() -# Scatter forward the solution vector to udpate ghost values +# Scatter forward the solution vector to update ghost values uh.x.scatter_forward() # - diff --git a/python/demo/demo_gmsh.py b/python/demo/demo_gmsh.py index 920f0ab5a26..111bcbf6a58 100644 --- a/python/demo/demo_gmsh.py +++ b/python/demo/demo_gmsh.py @@ -61,7 +61,6 @@ msh = create_mesh(MPI.COMM_SELF, cells, x, ufl_mesh_from_gmsh(element_types[0], x.shape[1])) -# with XDMFFile(MPI.COMM_SELF, f"out_gmsh/mesh_rank_{MPI.COMM_WORLD.rank}.xdmf", "w") as file: with XDMFFile(MPI.COMM_SELF, f"out_gmsh/mesh_rank_{MPI.COMM_WORLD.rank}.xdmf", "w") as file: file.write_mesh(msh) # - diff --git a/python/demo/demo_helmholtz.py b/python/demo/demo_helmholtz.py index 19f1a8dbb25..8dcf52a8eb3 100644 --- a/python/demo/demo_helmholtz.py +++ b/python/demo/demo_helmholtz.py @@ -67,15 +67,15 @@ problem = LinearProblem(a, L, u=uh, petsc_options={"ksp_type": "preonly", "pc_type": "lu"}) problem.solve() -# Save solution in XDMF format (to be viewed in Paraview, for example) +# Save solution in XDMF format (to be viewed in ParaView, for example) with XDMFFile(MPI.COMM_WORLD, "out_helmholtz/plane_wave.xdmf", "w", encoding=XDMFFile.Encoding.HDF5) as file: file.write_mesh(msh) file.write_function(uh) # - -# Calculate L2 and H1 errors of FEM solution and best approximation. -# This demonstrates the error bounds given in Ihlenburg. Pollution errors -# are evident for high wavenumbers. +# Calculate $L_2$ and $H^1$ errors of FEM solution and best approximation. +# This demonstrates the error bounds given in Ihlenburg. Pollution errors are +# evident for high wavenumbers. # + # Function space for exact solution - need it to be higher than deg diff --git a/python/demo/demo_interpolation-io.py b/python/demo/demo_interpolation-io.py index 6ff41805ffe..7e7f05b10b3 100644 --- a/python/demo/demo_interpolation-io.py +++ b/python/demo/demo_interpolation-io.py @@ -16,8 +16,8 @@ # # # Interpolation and IO # -# This demo show the interpolation of functions into vector-element -# (H(curl)) finite element spaces, and the interpolation of these +# This demo shows the interpolation of functions into vector-element +# $H(\mathrm{curl})$ finite element spaces, and the interpolation of these # special finite elements in discontinuous Lagrange spaces for # artifact-free visualisation. diff --git a/python/demo/demo_lagrange_variants.py b/python/demo/demo_lagrange_variants.py index b5decee1f6c..e400da52baf 100644 --- a/python/demo/demo_lagrange_variants.py +++ b/python/demo/demo_lagrange_variants.py @@ -196,14 +196,14 @@ def saw_tooth(x): # interpolation being less accurate when using the equispaced variant of # Lagrange compared to the GLL variant. # -# To quantify the error, we compute the interpolation error in the L2 +# To quantify the error, we compute the interpolation error in the $L_2$ # norm, # # $$\left\|u - u_h\right\|_2 = \left(\int_0^1 (u - u_h)^2\right)^{\frac{1}{2}},$$ # # where $u$ is the function and $u_h$ is its interpolation in the finite -# element space. The following code uses UFL to compute the L2 error for -# the equispaced and GLL variants. The L2 error for the GLL variant is +# element space. The following code uses UFL to compute the $L_2$ error for +# the equispaced and GLL variants. The $L_2$ error for the GLL variant is # considerably smaller than the error for the equispaced variant. # + diff --git a/python/demo/demo_poisson.py b/python/demo/demo_poisson.py index 8a6e8c095a5..6f384cc2572 100644 --- a/python/demo/demo_poisson.py +++ b/python/demo/demo_poisson.py @@ -142,7 +142,7 @@ # - # The solution can be written to a {py:class}`XDMFFile -# ` file visualization with ParaView ot VisIt +# ` file visualization with ParaView or VisIt # + with io.XDMFFile(msh.comm, "out_poisson/poisson.xdmf", "w") as file: diff --git a/python/demo/demo_pyvista.py b/python/demo/demo_pyvista.py index 6e7febaaf5e..3026f1a1f04 100644 --- a/python/demo/demo_pyvista.py +++ b/python/demo/demo_pyvista.py @@ -56,7 +56,7 @@ def plot_scalar(): u.interpolate(lambda x: np.sin(np.pi * x[0]) * np.sin(2 * x[1] * np.pi)) # As we want to visualize the function u, we have to create a grid to - # attached the dof values to We do this by creating a topology and + # attached the DoF values to We do this by creating a topology and # geometry based on the function space V cells, types, x = plot.create_vtk_mesh(V) grid = pyvista.UnstructuredGrid(cells, types, x) @@ -90,7 +90,7 @@ def plot_scalar(): subplotter.show() -# ## MeshTags and using subplots +# ## Mesh tags and using subplots def plot_meshtags(): @@ -103,7 +103,7 @@ def in_circle(x): """True for points inside circle with radius 2""" return np.array((x.T[0] - 0.5)**2 + (x.T[1] - 0.5)**2 < 0.2**2, dtype=np.int32) - # Create a dolfinx.MeshTag for all cells. If midpoint is inside the + # Create mesh tags for all cells. If midpoint is inside the # circle, it gets value 1, otherwise 0. num_cells = msh.topology.index_map(msh.topology.dim).size_local midpoints = compute_midpoints(msh, msh.topology.dim, list(np.arange(num_cells, dtype=np.int32))) @@ -112,13 +112,13 @@ def in_circle(x): cells, types, x = plot.create_vtk_mesh(msh, msh.topology.dim) grid = pyvista.UnstructuredGrid(cells, types, x) - # As the dolfinx.MeshTag contains a value for every cell in the + # As the mesh tags contain a value for every cell in the # geometry, we can attach it directly to the grid grid.cell_data["Marker"] = cell_tags.values grid.set_active_scalars("Marker") # We create a plotter consisting of two windows, and add a plot of the - # Meshtags to the first window. + # mesh tags to the first window. subplotter = pyvista.Plotter(shape=(1, 2)) subplotter.subplot(0, 0) subplotter.add_text("Mesh with markers", font_size=14, color="black", position="upper_edge") @@ -127,7 +127,7 @@ def in_circle(x): # We can also visualize subsets of data, by creating a smaller topology, # only consisting of those entities that has value one in the - # dolfinx.MeshTag + # mesh tags cells, types, x = plot.create_vtk_mesh( msh, msh.topology.dim, cell_tags.indices[cell_tags.values == 1]) @@ -160,14 +160,14 @@ def in_circle(x): """Mark sphere with radius < sqrt(2)""" return np.array((x.T[0] - 0.5)**2 + (x.T[1] - 0.5)**2 < 0.2**2, dtype=np.int32) - # Create a dolfinx.MeshTag for all cells. If midpoint is inside the + # Create mesh tags for all cells. If midpoint is inside the # circle, it gets value 1, otherwise 0. num_cells = msh.topology.index_map(msh.topology.dim).size_local midpoints = compute_midpoints(msh, msh.topology.dim, list(np.arange(num_cells, dtype=np.int32))) cell_tags = meshtags(msh, msh.topology.dim, np.arange(num_cells), in_circle(midpoints)) # We start by interpolating a discontinuous function into a second order - # discontinuous Lagrange space Note that we use the `cell_tags` from + # discontinuous Lagrange space. Note that we use the `cell_tags` from # the previous section to get the cells for each of the regions cells0 = cell_tags.indices[cell_tags.values == 0] cells1 = cell_tags.indices[cell_tags.values == 1] diff --git a/python/demo/demo_static-condensation.py b/python/demo/demo_static-condensation.py index 73ac74763b7..f1442da78b2 100644 --- a/python/demo/demo_static-condensation.py +++ b/python/demo/demo_static-condensation.py @@ -81,7 +81,7 @@ def sigma_u(u): - """Consitutive relation for stress-strain. Assuming plane-stress in XY""" + """Constitutive relation for stress-strain. Assuming plane-stress in XY""" eps = 0.5 * (ufl.grad(u) + ufl.grad(u).T) sigma = E / (1. - nu ** 2) * ((1. - nu) * eps + nu * ufl.Identity(2) * ufl.tr(eps)) return sigma @@ -117,7 +117,7 @@ def sigma_u(u): @numba.cfunc(c_signature, nopython=True) def tabulate_condensed_tensor_A(A_, w_, c_, coords_, entity_local_index, permutation=ffi.NULL): - # Prepare target condensed local elem tensor + # Prepare target condensed local element tensor A = numba.carray(A_, (Usize, Usize), dtype=PETSc.ScalarType) # Tabulate all sub blocks locally diff --git a/python/demo/demo_stokes.py b/python/demo/demo_stokes.py index e6bcb8d5839..ed056fd92db 100644 --- a/python/demo/demo_stokes.py +++ b/python/demo/demo_stokes.py @@ -10,7 +10,7 @@ # # Stokes equations with Taylor-Hood elements # -# This demo show how to solve the Stokes problem using Taylor-Hood +# This demo shows how to solve the Stokes problem using Taylor-Hood # elements with a range of different linear solvers. # # ## Equation and problem definition @@ -23,11 +23,11 @@ # \nabla \cdot u &= 0 \quad {\rm in} \ \Omega. # $$ # -# :::{note} +# ```{note} # The sign of the pressure has been flipped from the classical # definition. This is done in order to have a symmetric system # of equations rather than a non-symmetric system of equations. -# ::: +# ``` # # A typical set of boundary conditions on the boundary $\partial # \Omega = \Gamma_{D} \cup \Gamma_{N}$ can be: @@ -40,7 +40,7 @@ # # ### Weak formulation # -# We formulate the Stokes equations mixed variational form; that is, a +# We formulate the Stokes equations' mixed variational form; that is, a # form where the two variables, the velocity and the pressure, are # approximated. We have the problem: find $(u, p) \in W$ such that # @@ -58,12 +58,12 @@ # \Omega_N} g \cdot v \, {\rm d} s. # $$ # -# The space $W$ is mixed (product) function space $W = V +# The space $W$ is a mixed (product) function space $W = V # \times Q$, such that $u \in V$ and $q \in Q$. # # ### Domain and boundary conditions # -# We shall the lid-driven cavity problem with the following definitions +# We define the lid-driven cavity problem with the following # domain and boundary conditions: # # - $\Omega = [0,1]\times[0,1]$ (a unit square) @@ -74,7 +74,7 @@ # # ## Implementation # -# We first import the modules and function that the program uses: +# We first import the modules and functions that the program uses: # + import numpy as np @@ -94,7 +94,10 @@ from petsc4py import PETSc # - -# We create a Mesh and attach a coordinate map to the mesh: +# We create a {py:class}`Mesh `, define functions to +# geometrically locate subsets of its boundary and define a function +# describing the velocity to be imposed as a boundary condition in a lid +# driven cavity problem: # + # Create mesh @@ -122,16 +125,16 @@ def lid_velocity_expression(x): # - # We define two {py:class}`FunctionSpace ` -# instances with different finite elements. `P2` corresponds to -# piecewise quadratics for the velocity field and `P1` to continuous -# piecewise linears for the pressure field: +# instances with different finite elements. `P2` corresponds to a continuous +# piecewise quadratic basis for the velocity field and `P1` to a continuous +# piecewise linear basis for the pressure field: P2 = ufl.VectorElement("Lagrange", msh.ufl_cell(), 2) P1 = ufl.FiniteElement("Lagrange", msh.ufl_cell(), 1) V, Q = FunctionSpace(msh, P2), FunctionSpace(msh, P1) -# We can define boundary conditions: +# We define boundary conditions: # + # No-slip boundary condition for velocity field (`V`) on boundaries @@ -207,7 +210,7 @@ def lid_velocity_expression(x): fem.petsc.set_bc_nest(b, bcs0) # - -# Ths pressure field for this problem is determined only up to a +# The pressure field for this problem is determined only up to a # constant. We can supply the vector that spans the nullspace and any # component of the solution in this direction will be eliminated during # the iterative linear solution process. @@ -259,7 +262,7 @@ def lid_velocity_expression(x): # - # To compute the solution, we create finite element {py:class}`Function -# ` for the velocity (on the space `V`) and +# ` for the velocity (on the space `V`) and # for the pressure (on the space `Q`). The vectors for `u` and `p` are # combined to form a nested vector and the system is solved: @@ -276,7 +279,7 @@ def lid_velocity_expression(x): print("(A) Norm of pressure coefficient vector (nested, iterative): {}".format(norm_p_0)) # The solution fields can be saved to file in XDMF format for -# visualization, e.g. with ParView. Before writing to file, ghost values +# visualization, e.g. with ParaView. Before writing to file, ghost values # are updated. # + @@ -303,7 +306,7 @@ def lid_velocity_expression(x): P.assemble() b = fem.petsc.assemble_vector_block(L, a, bcs=bcs) -# Set near null space for pressure +# Set near nullspace for pressure null_vec = A.createVecLeft() offset = V.dofmap.index_map.size_local * V.dofmap.index_map_bs null_vec.array[offset:] = 1.0 @@ -345,7 +348,7 @@ def lid_velocity_expression(x): ksp.setFromOptions() # - -# We also need to create a block vector,\`\`x\`\`, to store the (full) +# We also need to create a block vector, `x`, to store the (full) # solution, which we initialize using the block RHS form `L`. # + @@ -366,7 +369,7 @@ def lid_velocity_expression(x): norm_p_1 = p.x.norm() if MPI.COMM_WORLD.rank == 0: print("(B) Norm of velocity coefficient vector (blocked, iterative): {}".format(norm_u_1)) - print("(B) Norm of pressure coefficient vector (blocked, interative): {}".format(norm_p_1)) + print("(B) Norm of pressure coefficient vector (blocked, iterative): {}".format(norm_p_1)) assert np.isclose(norm_u_1, norm_u_0) assert np.isclose(norm_p_1, norm_p_0) @@ -381,7 +384,7 @@ def lid_velocity_expression(x): ksp.getPC().setType("lu") ksp.getPC().setFactorSolverType("superlu_dist") -# We also need to create a block vector,\`\`x\`\`, to store the (full) +# We also need to create a block vector, `x`, to store the (full) # solution, which we initialize using the block RHS form `L`. # + diff --git a/python/demo/demo_types.py b/python/demo/demo_types.py index 5ec3b4ef850..a518a63664c 100644 --- a/python/demo/demo_types.py +++ b/python/demo/demo_types.py @@ -28,7 +28,7 @@ # - -# SciPy solvers do no support MPI, so all computations are performed on +# SciPy solvers do not support MPI, so all computations are performed on # a single MPI rank # + @@ -41,7 +41,7 @@ cell_type=mesh.CellType.triangle) V = fem.FunctionSpace(msh, ("Lagrange", 1)) -# Define a variartional problem +# Define a variational problem u, v = ufl.TrialFunction(V), ufl.TestFunction(V) x = ufl.SpatialCoordinate(msh) fr = 10 * ufl.exp(-((x[0] - 0.5) ** 2 + (x[1] - 0.5) ** 2) / 0.02)