Add Tutorial
Scaffold a new tutorial example following Fluca conventions.
Required Input
Ask the user for:
- •Module — tutorial subdirectory (e.g.,
fd) - •Description — what the tutorial demonstrates
- •Dependencies — which
fluca::*libraries to link
Steps
1. Determine next file number
bash
ls fluca/tutorials/<module>/ex*.c
2. Generate source
c
#include <flucasys.h>
/* Module headers as needed */
static const char help[] = "<Description>\n"
"Options:\n"
" -<opt> <type> : <desc>\n";
int main(int argc, char **argv)
{
/* Declarations at block top */
PetscCall(FlucaInitialize(&argc, &argv, NULL, help));
/* 1. Parse options
2. Create DM(s)
3. Create and configure objects
4. Solve / compute
5. Output results (ViewFromOptions or PetscPrintf)
6. Destroy in reverse creation order */
PetscCall(FlucaFinalize());
}
Tutorials differ from tests:
- •Use
/*TEST*/blocks with run-only semantics (exit code 0 = pass, no golden output files) - •Parsed by
fluca_parse_tutorial_file()inFlucaTestUtils.cmake, which callsRunTutorial.cmake - •Typically longer, with comments explaining each step
- •Use
SetFromOptions/ViewFromOptionsfor runtime configurability - •May use PETSc solvers (SNES, KSP) as part of the example
3. Add /*TEST*/ block
Append a /*TEST ... TEST*/ block at the end of the source file to register tutorial cases with ctest:
c
/*TEST
test:
suffix: default
nsize: 1
test:
suffix: high_peclet
nsize: 1
args: -gamma 0.01 -flucafd_limiter superbee
TEST*/
Each test: entry supports suffix (required), nsize (ignored), and args (optional). No output_file field — tutorials only check exit code.
4. Register in CMakeLists.txt
Add to TUTORIAL_SRCS in fluca/tutorials/<module>/CMakeLists.txt:
cmake
set(TUTORIAL_SRCS
ex1.c
...
ex<N>.c # <-- add here
)
The fluca_parse_tutorial_file() call in the foreach loop automatically picks up the new file.
For a new module, also:
- •Create
fluca/tutorials/<module>/CMakeLists.txtfollowing the pattern (includeFlucaTestUtilsand callfluca_parse_tutorial_file) - •Add
add_subdirectory(<module>)tofluca/tutorials/CMakeLists.txt
5. Build and verify
bash
cmake build # Re-configure to pick up new TEST blocks cmake --build build # Build ctest --test-dir build -R "tutorials_<module>" # Run tutorial test cases
Checklist
- • Help string documents all custom options
- • Key steps have explanatory comments
- •
/*TEST*/block with at least one test case - • Source added to
TUTORIAL_SRCSin CMakeLists.txt - • Builds and all tutorial test cases pass (exit code 0)