Introduction

Lecture 01 · Modern Simulation Software Development

Dr. Lambert Theisen & Dr. Georgii Oblapenko

ACoM · RWTH Aachen University

Motivation

Scientists spend an increasing amount of time building and using software. However, most scientists are never taught how to do this efficiently!

  • What method do I use?
  • Do I implement it myself or use an open-source solution?
  • How do I verify that my results are correct?
  • How do I balance research and code development?

Goals of the course

  • Introduce modern numerical methods actively used in cutting-edge research
  • Introduce modern software development practices
  • Provide experience with open-source frameworks implementing various numerical methods
  • Give new knowledge in various areas of engineering: thermal transfer, fluid mechanics, gas dynamics, UQ

In the end, you should be able to…

implement a simulation code for various PDEs, and understand the underlying numerical methods and software development practices.

Who are we?

  • Dr. Lambert Theisen (PhD 2024)
    • BSc: Simulation/Meshing in OpenFOAM
    • MSc: FEM for rarefied gas flows
    • PhD: FEM and DD for Schrödinger EVPs
    • PostDoc: Moment models, battery simulations, FEM for non-newtonian fluids
  • Dr. Georgii Oblapenko (PhD 2017)
    • Models for multi-species reacting flows
    • FVM, DG, particle methods for rarefied flows
    • Radiative heat transfer
    • UQ, SA for supersonic flows

Curriculum

Organizational aspects

  • Lectures: every Wednesday, 10:30 - 12:00
  • Exercises: every 2nd week 14:30 - 16:00
    • Wednesday?
    • Thursday?

Course website (slides, notes, projects, skills):

https://rwth-acom.pages.git.nrw/teaching/mssd, please register on the Git NRW platform.

  • 3 projects throughout semester
    • FEniCSx (FEM)
    • OpenFoam (FVM)
    • Trixi.jl + SPARTA (DG, DSMC)
  • Moodle access?

Exam format

  • 10-minute presentation of one of the projects
  • 15-minute question round on numerical methods, simulation frameworks and related skills (list of questions published before exam)

Icebreaker

What is “Modern” simulation software development?

AI-driven development

What is “Modern simulation software”

%%{init: {'theme': 'base', 'htmlLabels': 'true', 'themeVariables': { 'fontSize': '28px'}}}%%
flowchart TD
    A[Simulation Software] --> B[<center>Capabilities</center>
                                        Modern simulation]
    A --> C[Software aspects
            Modern software]
    style B shape: paper-tape
    style C shape: paper-tape
    classDef default text-align\:center;

Capabilities

  • Multi-physics
  • High-order
  • Hybrid methods
  • Uncertainty quantification

Software aspects

  • Unit tests
  • Reproducible research
  • Modular design (linear solvers, …)
  • “Exascale-ready” (MPI, GPU support)
  • Mixed precision
  • Automated code generation (AD)

Verification and Validation

  • Verification: Solving the equations correctly
    • Issue of mathematics (correct method) and programming (correct implementation)
  • Validation: Solving the correct equations
    • Issue of physics/engineering

Code verification

  • Unit testing: test individual units (functions, classes, structs) of code
  • Integration testing: test that combinations of units work as intended
  • Regression testing: test that existing functionality is working as expected

Code verification: unit testing

  • Test individual units (functions, classes, structs) of code
    • Example:
    E0 = energy(particles)  # assumes energy has already been tested
    collide_2particles!(particles, collision_parameters, i1, i2)
    @test isapprox(energy(particles), E0; atol=eps(), rtol=eps()) == true

Code verification: integration testing

  • Test that combinations of units work as intended
    • Example:
    E0 = energy(particles)  # assumes energy has already been tested
    collide_all_particles!(particles, collision_parameters)
    @test isapprox(energy(particles), E0; atol=eps(), rtol=eps()) == true

Code verification: regression testing

  • Test that existing functionality is working as expected
    • Example 1:
    heat_flux = simulation_result()
    reference_heat_flux = parse(Float64, read("reference_q.txt", String))
    @test isapprox(heat_flux, reference_heat_flux; atol=eps(), rtol=eps()) == true
    • Example 2: run simulation, check that performance has not degraded

Continuous integration (CI)

  • Integration triggers an automated build and test suite
  • CI pipelines work seamlessly with version control systems

CI pipeline

CI setup example

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        julia-version: ['lts', '1', 'pre']
        julia-arch: [x64, x86]
        os: [ubuntu-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4
      - uses: julia-actions/setup-julia@v2
        with:
          version: ${{ matrix.julia-version }}
          arch: ${{ matrix.julia-arch }}
      - uses: julia-actions/cache@v2
      - uses: julia-actions/julia-buildpkg@v1
      - uses: julia-actions/julia-runtest@v1
      - uses: julia-actions/julia-processcoverage@v1
      - name: Upload results to Codecov
        uses: codecov/codecov-action@v5
        with:
            fail_ci_if_error: true
            token: ${{ secrets.CODECOV_TOKEN }}

Continuous deployment (CD)

  • Frequent, reliable releases of new features or bug fixes without manual intervention
  • Automatic
    • Deployment of documentation website
    • Analysis of code coverage
    • Archiving to Zenodo (persistent DOI)

CD is only as good as your tests!

Examples of own codes

  • Lambert Theisen: fenicsR13
    • FEM code based on FEniCS for the linear R13 equations
    • Python, Gitlab CI, Sphinx documentation, Zenodo archive
  • Georgii Oblapenko: Merzbild.jl
    • DSMC code for variable-weight particles
    • Julia, Github CI, Documenter.jl, Zenodo archive

Examples of other codes that do it “right”

  • Deal.II - highly scalable FEM code
  • AMReX - block-structured meshes with adaptive mesh refinement
  • t8code - hybrid meshes with adaptive mesh refinement
  • DifferentialEquations.jl - library for ODE solvers
  • Trixi.jl - DGSEM code for solving hyperbolic PDEs
  • DFTK.jl - plane-wave density-functional theory (DFT)

Sustainable Computational Engineering

  • Course from MBD
  • 42.00019: Sustainable Computational Engineering
  • Focus on CI, RDM, licensing, reproducibility, etc.

Key Take-Aways

  1. “The worst you code you’ll ever write is your second one - because you have learnt from your mistakes and you want to do everything right this time”
  2. Testing, documentation should not be an afterthought!
  3. Modularization - solve!() with 10k lines in a single function is not a good way to approach things

Questions?

References