Skip to content

Commit

Permalink
Tutorials: use tags: [hide-output]
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Dec 7, 2022
1 parent 49052d8 commit dd52305
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
19 changes: 9 additions & 10 deletions docs/tuto_cbox.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ kernelspec:
name: python3
---

<!-- #region tags=[] -->

# Demo sidewall convection (snek5000-cbox solver)

<!-- #endregion -->

## Initialize and setup simulation parameters

This example is based on
Expand Down Expand Up @@ -63,6 +59,9 @@ print(f"Script executed in {perf_counter() - t_start:.2f} s")
The script has now been executed. Let's look at its output.

```{code-cell} ipython3
---
tags: [hide-output]
---
print(process.stdout)
```

Expand All @@ -83,6 +82,9 @@ path_run
We can now read the Nek5000 log file.

```{code-cell} ipython3
---
tags: [hide-output]
---
from pathlib import Path
path_log = Path(path_run) / "cbox.log"
Expand All @@ -97,6 +99,9 @@ print("\n".join(lines[:index_step2+20]))
```

```{code-cell} ipython3
---
tags: [hide-output]
---
index_final_step = 0
for line in lines[::-1]:
if line.startswith("Step") and ", t= " in line:
Expand Down Expand Up @@ -200,9 +205,3 @@ field = field.interp(x=x_new, y=y_new)
field.temperature.mean('x').plot();
```

## Versions used in this tutorial

```{code-cell} ipython3
!snek-info
```
18 changes: 11 additions & 7 deletions docs/tuto_phill_script.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ kernelspec:
name: python3
---

<!-- #region tags=[] -->

# Demo periodic hill (`snek5000-phill` solver): running a simulation from a script

<!-- #endregion -->

## Execution of the script

Now let's execute the simulation. We will use the script
Expand Down Expand Up @@ -48,18 +44,26 @@ print(f"Script executed in {perf_counter() - t_start:.2f} s")

### Snek5000 and Nek5000 log

The simulation is done! Let's look at its output:
The simulation is done! We are going to look at its output (which is now in the
variable `process.stdout`). However, be prepared to get something long because
Nek5000 is very verbose. For readability of this tutorial, the output is hidden
by default (click to see it):

```{code-cell} ipython3
---
tags: [hide-output]
---
lines = [
line for line in process.stdout.split("\n")
if not line.endswith(", errno = 1")
]
print("\n".join(lines))
```

To "load the simulation", i.e. to recreate a simulation object, we now need to extract
from the output the path of the directory of the simulation:
To "load the simulation", i.e. to recreate a simulation object, we now need to
extract from the output the path of the directory of the simulation. This is
also very specific to this tutorial, so you don't need to understand this code.
In real life, we can just read the log to know where the data has been saved.

```{code-cell} ipython3
path_run = None
Expand Down
15 changes: 9 additions & 6 deletions docs/tuto_tgv.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ print(f"Script executed in {perf_counter() - t_start:.2f} s")
The script has now been executed. Let's look at its output:

```{code-cell} ipython3
---
tags: [hide-output]
---
lines = [
line for line in process.stdout.split("\n")
if not line.endswith(", errno = 1")
Expand All @@ -66,6 +69,9 @@ print("\n".join(lines[:index_step2+20]))
```

```{code-cell} ipython3
---
tags: [hide-output]
---
index_final_step = 0
for line in lines[::-1]:
if line.startswith(" Final time step ="):
Expand Down Expand Up @@ -182,6 +188,9 @@ lines = !snek-restart {sim.path_run} --use-start-from -1 --add-to-end-time 4
Let's look at the end of the output of this command:

```{code-cell} ipython3
---
tags: [hide-output]
---
# filter to remove useless warnings
lines = [line for line in lines if not line.endswith(", errno = 1")]
print("\n".join(lines[-120:]))
Expand Down Expand Up @@ -230,9 +239,3 @@ ax.figure

Note that we use for this tutorial very small and coarse simulations, which explain the
differences between our results and the reference!

## Versions used in this tutorial

```{code-cell} ipython3
!snek-info
```

0 comments on commit dd52305

Please sign in to comment.