Skip to content

Add the 1D wave.jl documentation into example.md #2301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ docs/src/tutorials/
*.gz
*.mp4
*.png
.DS_Store
88 changes: 88 additions & 0 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,94 @@

## 1D Column examples

### 1D Wave Equation

The 1D linear wave example in [`examples/column/wave.jl`](https://github.com/CliMA/ClimaCore.jl/blob/main/examples/column/wave.jl) demonstrates solving the following system of PDEs:

#### Equations and Discretizations

The first-order system for the 1D linear wave equation is:

```math
\begin{aligned}
\frac{\partial u}{\partial t} &= -\frac{\partial p}{\partial z} \\
\frac{\partial p}{\partial t} &= -\frac{\partial u}{\partial z}
\end{aligned}
```

This is discretized using finite difference operators with a staggered grid:

- `u` is defined at cell centers (`CenterFiniteDifferenceSpace`)
- `p` is defined at cell faces (`FaceFiniteDifferenceSpace`)

The discrete form is:

```math
\begin{aligned}
\frac{d u}{dt} &\approx - \nabla \cdot p \\
\frac{d p}{dt} &\approx - \nabla u
\end{aligned}
```

These are implemented in code using:

```julia
∂f = GradientC2F(left = SetValue(0.0), right = SetValue(0.0))
∂c = DivergenceF2C()

@. dp = -WVector(∂f(u))
@. du = -∂c(p)
```

with Dirichlet boundary conditions (`SetValue(0.0)`) applied at both ends.

#### Prognostic Variables

| Variable | Description | Space |
|----------|-----------------------------|------------------------------|
| `u` | Scalar velocity | CenterFiniteDifferenceSpace |
| `p` | Face-centered pressure flux | FaceFiniteDifferenceSpace |

#### Time Integration

The system is solved using the `SSPRK33` time integrator from the `OrdinaryDiffEqSSPRK` package:

```julia
prob = ODEProblem(tendency!, Y, (0.0, 4π))
sol = solve(prob, SSPRK33(), dt = 0.01, saveat = 0.1)
```

#### ClimaCore Operators Used

| Operator | Purpose | Code Example |
|----------------------|-------------------------------------------------------------------------|-----------------------------------|
| `GradientC2F(...)` | Computes the gradient from center (C) to face (F) locations | `∂f = GradientC2F(...)` |
| `DivergenceF2C()` | Computes the divergence from face (F) to center (C) locations | `∂c = DivergenceF2C()` |
| `WVector(...)` | Constructs a vertical vector field at faces | `@. dp = -WVector(∂f(u))` |
| `SetValue(val)` | Enforces a boundary condition by setting values at the boundary | `GradientC2F(left = SetValue(0.0))` |

- **`GradientC2F`**: Computes ∂u/∂z, placing the result on face points.
- **`DivergenceF2C`**: Computes ∂p/∂z, placing the result on center points.
- **`WVector`**: Wraps scalars into 1D vertical vectors for compatibility with `DivergenceF2C`.
- **`SetValue(0.0)`**: Applies fixed-value Dirichlet boundary conditions.

#### Problem Flow and Setup

1. **Mesh and Domain**: Create a 1D interval domain `[0, 4π]` with 30 elements.
2. **Function Spaces**: Construct staggered finite-difference spaces for `u` (cell centers) and `p` (cell faces).
3. **Initial Conditions**: Set `u(z) = sin(z)` and `p(z) = 0`.
4. **Differential Operators**: Apply `GradientC2F` and `DivergenceF2C` with Dirichlet boundaries.
5. **Tendency Function**: Compute time derivatives of `u` and `p`.
6. **ODE Integration**: Solve the PDE system using `SSPRK33` with `OrdinaryDiffEqSSPRK`.
7. **Output**: Save the final state and animated wave evolution using `Plots.jl`.

#### Visualization

An animation of `u(z, t)` is generated with `Plots.jl`, and the final state is saved as an image:

- ![wave_end.png](../assets/wave_end.png) Final state of `u`
- ![wave.gif](../assets/wave.gif) Time evolution of `u`
Comment on lines +90 to +91
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cquiroz1031 , thank you so much for your contribution!

The linking to these visual aids breaks here.

┌ Error: invalid local link/image: path pointing to a file outside of build directory in docs/src/examples.md
│   link =
│    @ast MarkdownAST.Image("../assets/wave_end.png", "") do
│      MarkdownAST.Text("wave_end.png")
│    end
│    
└ @ Documenter ~/.julia/packages/Documenter/ZlqFj/src/utilities/utilities.jl:47
┌ Error: invalid local link/image: path pointing to a file outside of build directory in docs/src/examples.md
│   link =
│    @ast MarkdownAST.Image("../assets/wave.gif", "") do
│      MarkdownAST.Text("wave.gif")
│    end
│    
└ @ Documenter ~/.julia/packages/Documenter/ZlqFj/src/utilities/utilities.jl:47

I understand you thought it would be helpful to show them in the docs, but we usually don't show output of examples. (We do for tutorials, but they are parsed and executed via Literate.jl, which is not needed here).

You need to remove these two lines to fix the documentation build error, otherwise there cannot be a preview generated in CI. Thank you


## 2D Cartesian examples

### Flux Limiters advection
Expand Down
Loading