Skip to content

Commit

Permalink
Improve how the code blocks are displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Nov 6, 2024
1 parent 1e39add commit 899885c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LDLFactorizations = "40e66cde-538c-5869-a4ad-c39174c6795b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearOperators = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125"
MatrixMarket = "4d4711f2-db25-561a-b6b3-d35e7d4047d3"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SuiteSparseMatrixCollection = "ac199af8-68bc-55b8-82c4-7abd6f96ed98"
Expand Down
14 changes: 9 additions & 5 deletions docs/src/custom_workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ It is parameterized by:
- **`FC`**: The element type of the vector.
- **`D`**: The data array type, which uses `OffsetArray` to enable custom indexing.

```julia
```@example halo-regions; continued = true
using OffsetArrays
struct HaloVector{FC, D} <: AbstractVector{FC}
Expand Down Expand Up @@ -110,7 +110,9 @@ The `size` and `getindex` functions support REPL display, aiding interaction, th
Using `HaloVector` with `OffsetArray`, we can apply the discrete Laplacian operator in a matrix-free approach with a 5-point stencil, managing halo regions effectively.
This layout allows **clean and efficient Laplacian computation** without boundary checks within the core loop.

```julia
```@example halo-regions; continued = true
using LinearAlgebra
# Define a matrix-free Laplacian operator
struct LaplacianOperator
Nx::Int # Number of grid points in the x-direction
Expand Down Expand Up @@ -145,7 +147,7 @@ end
To integrate `HaloVector` with Krylov.jl, we define essential vector operations, including dot products, norms, scalar multiplication, and element-wise updates.
These implementations allow Krylov.jl to leverage custom vector types, enhancing both solver flexibility and performance.

```julia
```@example halo-regions; continued = true
using Krylov
import Krylov.FloatOrComplex
Expand Down Expand Up @@ -252,8 +254,8 @@ Note that `Krylov.kref!` is only required for `minres_qlp`.

### 2D Poisson equation solver with Krylov methods

```julia
using Krylov, LinearAlgebra, OffsetArrays
```@example halo-regions
using Krylov, OffsetArrays
# Parameters
L = 1.0 # Length of the square domain
Expand Down Expand Up @@ -282,7 +284,9 @@ b = HaloVector(data)
# Solve the system with CG
u_sol, stats = Krylov.cg(A, b, atol=1e-12, rtol=0.0, verbose=1)
```

```@example halo-regions
# The exact solution is u(x,y) = sin(πx) * sin(πy)
u_star = [sin(π * i * Δx) * sin(π * j * Δy) for i=1:Nx, j=1:Ny]
norm(u_sol.data[1:Nx, 1:Ny] - u_star, Inf)
Expand Down
4 changes: 4 additions & 0 deletions docs/src/matrix_free.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ A = FFTPoissonOperator(n, L, complex)
# Solve the linear system using CG
u_sol, stats = cg(A, f, atol=1e-10, rtol=0.0, verbose=1)
```

```@example fft_poisson
# The exact solution is u(x) = -sin(x)
u_star = -sin.(x)
u_star ≈ u_sol
Expand Down Expand Up @@ -418,7 +420,9 @@ f = vec(F)
# Solve the linear system using MinAres
u_sol, stats = minares(A, f, atol=1e-10, rtol=0.0, verbose=1)
```

```@example helmholtz
# Solution as 3D array
U_sol = reshape(u_sol, Nx, Ny, Nz)
Expand Down

0 comments on commit 899885c

Please sign in to comment.