Skip to content

Commit bf57774

Browse files
Merge pull request #9 from simvia-tech/florian/inc-checkpoint-restart
Add checkpoint/restart tutorial (splitting a transient calculation)
2 parents a40888b + b03514c commit bf57774

6 files changed

Lines changed: 376 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
time,velocity
2+
0,0.1
3+
5,0.1
4+
10,0.5
5+
15,0.5
6+
20,0.25
7+
30,0.25
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<?xml version="1.0" encoding="utf-8"?><Code_Saturne_GUI case="Inc_Checkpoint_Restart" solver_version="9.1;9.1.0" study="tutoriel" version="2.0">
2+
<additional_scalars/>
3+
<analysis_control>
4+
<output>
5+
<mesh id="-1" label="Fluid domain" type="cells">
6+
<all_variables status="on"/>
7+
<location>all[]</location>
8+
<writer id="-1"/>
9+
</mesh>
10+
<mesh id="-2" label="Boundary" type="boundary_faces">
11+
<all_variables status="on"/>
12+
<location>all[]</location>
13+
<writer id="-2"/>
14+
</mesh>
15+
<probe name="1" status="on">
16+
<probe_x>0.005</probe_x>
17+
<probe_y>0.01</probe_y>
18+
<probe_z>0.0025</probe_z>
19+
</probe>
20+
<probe name="2" status="on">
21+
<probe_x>0.995</probe_x>
22+
<probe_y>0.01</probe_y>
23+
<probe_z>0.0025</probe_z>
24+
</probe>
25+
<probe_format choice="CSV"/>
26+
<probe_recording_frequency>1</probe_recording_frequency>
27+
<writer id="-1" label="results">
28+
<directory name="postprocessing"/>
29+
<format name="ensight" options="separate_meshes"/>
30+
<frequency period="time_value">0.5</frequency>
31+
<output_at_end status="on"/>
32+
</writer>
33+
<writer id="-2" label="boundary">
34+
<directory name="postprocessing"/>
35+
<format name="ensight" options="separate_meshes"/>
36+
<frequency period="none"/>
37+
<output_at_end status="on"/>
38+
</writer>
39+
</output>
40+
<profiles/>
41+
<time_averages/>
42+
<time_parameters>
43+
<iterations>3000</iterations>
44+
<property name="courant_number" label="CourantNb"/>
45+
<property name="fourier_number" label="FourierNb"/>
46+
<time_passing>0</time_passing>
47+
<time_step_ref>0.01</time_step_ref>
48+
</time_parameters>
49+
</analysis_control>
50+
<boundary_conditions>
51+
<boundary label="inlet" name="1" nature="inlet">X0</boundary>
52+
<boundary label="outlet" name="2" nature="outlet">X1</boundary>
53+
<boundary label="bottom_wall" name="3" nature="wall">Y0</boundary>
54+
<boundary label="top_wall" name="4" nature="wall">Y1</boundary>
55+
<boundary label="front" name="5" nature="symmetry">Z0</boundary>
56+
<boundary label="back" name="6" nature="symmetry">Z1</boundary>
57+
<inlet label="inlet" field_id="none">
58+
<velocity_pressure choice="norm_formula" direction="normal">
59+
<norm_formula>u_norm = inlet_law[velocity];</norm_formula>
60+
</velocity_pressure>
61+
</inlet>
62+
<outlet label="outlet" field_id="none"/>
63+
<symmetry label="front" field_id="none"/>
64+
<symmetry label="back" field_id="none"/>
65+
<wall label="bottom_wall" field_id="none">
66+
<velocity_pressure choice="off">
67+
<dirichlet name="velocity" component="0">0</dirichlet>
68+
<dirichlet name="velocity" component="1">0</dirichlet>
69+
<dirichlet name="velocity" component="2">0</dirichlet>
70+
</velocity_pressure>
71+
</wall>
72+
<wall label="top_wall" field_id="none">
73+
<velocity_pressure choice="off">
74+
<dirichlet name="velocity" component="0">0</dirichlet>
75+
<dirichlet name="velocity" component="1">0</dirichlet>
76+
<dirichlet name="velocity" component="2">0</dirichlet>
77+
</velocity_pressure>
78+
</wall>
79+
</boundary_conditions>
80+
<calculation_management>
81+
<block_io/>
82+
<partitioning/>
83+
<start_restart>
84+
<frozen_field status="off"/>
85+
</start_restart>
86+
</calculation_management>
87+
<lagrangian model="off"/>
88+
<numerical_parameters>
89+
<velocity_pressure_algo choice="simplec"/>
90+
</numerical_parameters>
91+
<physical_properties>
92+
<fluid_properties>
93+
<material choice="user_material"/>
94+
<method choice="user_properties"/>
95+
<property name="density" choice="constant" label="Density">
96+
<initial_value>900</initial_value>
97+
<listing_printing status="off"/>
98+
<postprocessing_recording status="off"/>
99+
</property>
100+
<property name="molecular_viscosity" choice="constant" label="LamVisc">
101+
<initial_value>0.09</initial_value>
102+
<listing_printing status="off"/>
103+
<postprocessing_recording status="off"/>
104+
</property>
105+
<reference_pressure>101325</reference_pressure>
106+
<reference_temperature>293.15</reference_temperature>
107+
</fluid_properties>
108+
<gravity>
109+
<gravity_x>0</gravity_x>
110+
<gravity_y>0</gravity_y>
111+
<gravity_z>0</gravity_z>
112+
</gravity>
113+
<notebook/>
114+
<omega>
115+
<omega_x>0</omega_x>
116+
<omega_y>0</omega_y>
117+
<omega_z>0</omega_z>
118+
</omega>
119+
<time_tables>
120+
<table id="0" name="inlet_law" file_name="inlet_velocity.csv" delimiter=",">
121+
<skip_rows>1</skip_rows>
122+
<headers_list>time,velocity</headers_list>
123+
</table>
124+
</time_tables>
125+
</physical_properties>
126+
<solution_domain>
127+
<extrusion/>
128+
<faces_cutting status="off"/>
129+
<joining/>
130+
<mesh_cartesian>
131+
<x_direction ncells="100" min="0.0" max="1.0" prog="1.0" law="constant"/>
132+
<y_direction ncells="40" min="0.0" max="0.02" prog="1.05" law="parabolic"/>
133+
<z_direction ncells="1" min="0.0" max="0.005" prog="1.0" law="constant"/>
134+
</mesh_cartesian>
135+
<mesh_origin choice="mesh_cartesian"/>
136+
<mesh_smoothing status="off"/>
137+
<meshes_list/>
138+
<periodicity/>
139+
<thin_walls/>
140+
<volumic_conditions>
141+
<zone label="all_cells" id="1" initialization="on" physical_properties="on">all[]</zone>
142+
</volumic_conditions>
143+
</solution_domain>
144+
<thermophysical_models>
145+
<ale_method/>
146+
<atmospheric_flows model="off">
147+
<large_scale_meteo status="off"/>
148+
<read_meteo_data status="off"/>
149+
</atmospheric_flows>
150+
<compressible_model model="off"/>
151+
<conjugate_heat_transfer>
152+
<external_coupling>
153+
<syrthes_instances/>
154+
</external_coupling>
155+
</conjugate_heat_transfer>
156+
<gas_combustion model="off">
157+
<thermodynamical_pressure status="off"/>
158+
</gas_combustion>
159+
<immersed_boundaries/>
160+
<internal_coupling>
161+
<coupled_scalars/>
162+
<solid_zones/>
163+
</internal_coupling>
164+
<porosities/>
165+
<radiative_transfer model="off"/>
166+
<reference_values>
167+
<length/>
168+
</reference_values>
169+
<source_terms/>
170+
<thermal_scalar model="off"/>
171+
<turbomachinery model="off">
172+
<joining/>
173+
</turbomachinery>
174+
<turbulence model="off"/>
175+
<velocity_pressure>
176+
<initialization>
177+
<formula zone_id="1">velocity[0] = 0.1;
178+
velocity[1] = 0.;
179+
velocity[2] = 0.;</formula>
180+
</initialization>
181+
<property name="stress" label="Stress" support="boundary"/>
182+
<property name="total_pressure" label="total_pressure"/>
183+
<property name="yplus" label="Yplus" support="boundary"/>
184+
<variable name="pressure" label="Pressure">
185+
<rhs_reconstruction>2</rhs_reconstruction>
186+
</variable>
187+
<variable name="velocity" dimension="3" label="Velocity">
188+
<rhs_reconstruction>1</rhs_reconstruction>
189+
</variable>
190+
</velocity_pressure>
191+
</thermophysical_models>
192+
<user_functions>
193+
<calculator/>
194+
</user_functions>
195+
</Code_Saturne_GUI>
36.2 KB
Loading
58.4 KB
Loading
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Checkpoint and Restart (Splitting a Transient Calculation)
2+
3+
A step-by-step tutorial for **checkpointing and restarting** a code_saturne
4+
calculation: a transient run is stopped after 1200 time steps, then a second run
5+
restarts from its checkpoint and continues to step 3000. The restarted history
6+
superposes the one of an uninterrupted reference run down to the write precision
7+
of the probe files, demonstrating that a split calculation is equivalent to a
8+
continuous one.
9+
10+
The transient is a laminar channel whose inlet velocity ramps between plateaus
11+
(driven by a time table, see
12+
[Inc_Time_Table_Inlet](../Inc_Time_Table_Inlet)): the restart happens in the
13+
middle of the scenario, which also shows that time-dependent inputs resume
14+
correctly.
15+
16+
Maintained by [Simvia](https://Simvia.tech/fr), part of the
17+
[tutoriel-code_saturne](https://github.com/simvia-tech/tutorials-code_saturne) collection.
18+
19+
## Learning objectives
20+
21+
After completing this tutorial you will be able to:
22+
23+
1. Know what code_saturne writes in the `checkpoint/` directory of a run.
24+
2. Configure a restart in the GUI (checkpoint path, or automatic mode) and understand that the iteration count is absolute.
25+
3. Split a transient calculation into successive runs with named result directories.
26+
4. Verify that a restarted calculation reproduces the uninterrupted one.
27+
28+
## Prerequisites
29+
30+
| Requirement | Detail |
31+
|---|---|
32+
| code_saturne | **v9.1** |
33+
| Background | Any transient code_saturne case |
34+
35+
If code_saturne is not yet installed, build it from the
36+
[official homepage](https://code-saturne.org/), pull a
37+
ready-to-use Singularity image from the
38+
[Open Simulation Center](https://open-simulation-center.org/downloads/code_saturne/code_saturne),
39+
or pull the
40+
[Simvia Docker image](https://hub.docker.com/r/Simvia/code_saturne) before continuing.
41+
42+
## Case files
43+
44+
```text
45+
Inc_Checkpoint_Restart/
46+
├── CASE/
47+
│ └── DATA/
48+
│ ├── setup.xml # pre-configured GUI case (continuous reference)
49+
│ └── inlet_velocity.csv # time table driving the inlet ramps
50+
├── FIGURES/ # figures used in this README
51+
└── README.md
52+
```
53+
54+
There is no mesh file: the channel grid is built by code_saturne's internal
55+
Cartesian mesher, directly from `setup.xml`.
56+
57+
## Physical model
58+
59+
The flow is laminar, incompressible and truly transient
60+
($\Delta t=0.01\ \mathrm{s}$, 3000 steps, 30 s): a viscous fluid
61+
($\rho=900\ \mathrm{kg\,m^{-3}}$, $\mu=0.09\ \mathrm{Pa\,s}$) enters a plane
62+
channel ($L=1\ \mathrm{m}$, $H=0.02\ \mathrm{m}$, $Re_{D_h}=40$ to $200$) with a
63+
velocity that ramps between plateaus (0.1, 0.5 and 0.25 m/s). The physics is
64+
deliberately simple: the subject of the tutorial is the calculation workflow,
65+
not the flow.
66+
67+
<p align="center">
68+
<img src="FIGURES/mesh_boundary_conditions.png"
69+
alt="Transient channel, and the timeline of the three runs: part1, restarted part2, and the continuous reference."
70+
width="1000"/>
71+
<br>
72+
<em>Figure 1: (a) The transient channel. (b) The three runs: part1 stops at
73+
step 1200 and writes a checkpoint; part2 restarts from it and continues to
74+
step 3000; the continuous run is the reference.</em>
75+
</p>
76+
77+
## The checkpoint (the feature)
78+
79+
Every run writes a `checkpoint/` directory inside its result directory
80+
(`RESU/<id>/checkpoint/`), containing the mesh (`mesh_input.csm`), the main
81+
variables (`main.csc`), auxiliary data (`auxiliary.csc`) and, when relevant,
82+
notebook and time-table state. By default it is written at the end of the run
83+
and periodically during long calculations.
84+
85+
A restart is configured in the GUI under **Calculation management, Start/Restart**
86+
by pointing to a previous checkpoint, which stores in `setup.xml`:
87+
88+
```xml
89+
<start_restart>
90+
<restart path="RESU/part1/checkpoint"/>
91+
</start_restart>
92+
```
93+
94+
(`path="*"` selects the most recent checkpoint automatically.) Two important
95+
behaviours:
96+
97+
- The **iteration count is absolute**: with 3000 iterations requested, a restart
98+
from step 1200 performs steps 1201 to 3000.
99+
- Time-dependent inputs (time tables, notebook values saved in the checkpoint)
100+
resume at the restart time.
101+
102+
## Running the simulation
103+
104+
The shipped `setup.xml` is the continuous reference (3000 steps, no restart).
105+
The split workflow changes one setting between runs:
106+
107+
```bash
108+
cd CASE
109+
110+
# run A: set iterations to 1200 in the GUI, then
111+
code_saturne run --n 4 --id part1
112+
113+
# run B: set iterations back to 3000 and select the restart
114+
# (Calculation management > Start/Restart > RESU/part1/checkpoint), then
115+
code_saturne run --n 4 --id part2
116+
117+
# run C (reference): iterations 3000, restart disabled
118+
code_saturne run --n 4 --id continuous
119+
```
120+
121+
Each run creates its own `CASE/RESU/<id>/` with `run_solver.log`, `monitoring/`
122+
(probe histories recorded at every step) and `checkpoint/`. The `part2` log
123+
confirms the restart (`Reading file: restart/main.csc`).
124+
125+
## Results and verification
126+
127+
<p align="center">
128+
<img src="FIGURES/restart_superposition.png"
129+
alt="Restarted history on top of the continuous reference, and their pointwise difference."
130+
width="1000"/>
131+
<br>
132+
<em>Figure 2: (a) The outlet velocity history of part1 and of the restarted
133+
part2, on top of the continuous reference. (b) Pointwise difference between
134+
part2 and the reference: zero at most steps, with isolated points at the
135+
$10^{-8}$ write precision of the probe files.</em>
136+
</p>
137+
138+
| Comparison | Max difference |
139+
|---|---:|
140+
| part1 vs continuous (steps 1 to 1200) | 0 (bitwise identical) |
141+
| part2 (restarted) vs continuous (steps 1201 to 3000) | $10^{-8}\ \mathrm{m\,s^{-1}}$ (probe-file precision) |
142+
143+
The split calculation is therefore indistinguishable from the uninterrupted one:
144+
the checkpoint stores the complete solver state. The restart happened in the
145+
middle of the inlet ramp scenario and the time table resumed exactly.
146+
147+
## Summary
148+
149+
This tutorial split a 3000-step transient calculation into two runs: a first run
150+
stopped at step 1200 (writing its `checkpoint/`), and a second run restarted
151+
from that checkpoint through the GUI setting
152+
(`start_restart/restart path`), continuing to the absolute iteration target. The
153+
restarted history matches the uninterrupted reference exactly, at the write
154+
precision of the probe files. Checkpointing is the standard way to handle long
155+
calculations (job time limits, staged convergence, model changes on a converged
156+
state) and works identically for every code_saturne physics.
157+
158+
## References
159+
160+
1. code_saturne documentation: <https://code-saturne.org/doc/>.
161+
162+
## Authors
163+
164+
[Simvia](https://Simvia.tech/fr) - Questions, remarks and requests are welcome.

catalog/tutorials.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
tutorials:
1313

1414
# ---- 00_foundations ----
15+
- path: 00_foundations/Inc_Checkpoint_Restart
16+
title: Checkpoint and Restart (Splitting a Transient Calculation)
17+
topic: Foundations
18+
module: base
19+
regime: laminar
20+
physics: []
21+
cs_version: "9.1"
22+
difficulty: beginner
23+
tags: [checkpoint, restart, workflow, transient, time-table]
24+
1525
- path: 00_foundations/Inc_Fan_Duct
1626
title: Fan in a Duct (Actuator Disk with a Fan Curve)
1727
topic: Foundations

0 commit comments

Comments
 (0)