Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
26a657c
ci: Add GitHub Actions workflow (gemini generated from gitlab-ci.yaml)
Nov 26, 2025
92f13aa
ci: Appy clang-format
Nov 27, 2025
d2cec94
Fixed clang-format to version 18
Dec 3, 2025
b3f19b6
.
Dec 3, 2025
1fa4256
.
Dec 6, 2025
da67d47
.
Dec 6, 2025
68bdbaa
.
Dec 6, 2025
25e59ed
ci: Add ccache to GitHub Actions workflow for faster builds
Dec 6, 2025
d577935
.
Dec 6, 2025
2383e2f
.
Dec 6, 2025
8ce99e3
.
Dec 6, 2025
2d0ca87
fixing double linking errors
Dec 6, 2025
af07b9d
fixing double linking errors
Dec 6, 2025
9e1923b
fixing double linking errors
Dec 6, 2025
1ee325e
fixing double linking errors
Dec 7, 2025
41121f2
fixing double linking errors
Dec 7, 2025
6e25f61
fixing double linking warnings
Dec 7, 2025
6716848
reducing double linking warnings
Dec 7, 2025
acebb15
include with .h and not .cc
Dec 7, 2025
3abe116
made a default descovery of sources
Dec 7, 2025
7031f9f
redeployed
Dec 7, 2025
3325544
removed residual debug printing
Dec 7, 2025
0bb1291
fix the wrong linking error introduced earlier for the tests
Dec 7, 2025
fbad196
fix the wrong linking error introduced earlier for the tests (second …
Dec 7, 2025
7e10043
.
Dec 7, 2025
5682f90
fix compilation on linux
Dec 7, 2025
5aca981
update readme
Dec 7, 2025
69ecb65
.
Dec 7, 2025
7d4b63e
some updated test result (assuming the functions were correct)
Dec 7, 2025
dc59c2e
some updated test result (assuming the functions were correct)
Dec 7, 2025
8c10cbd
some updated test result (assuming the functions were correct)
Dec 7, 2025
a03aaf2
deployement and clang-format
Dec 7, 2025
7a2f6f2
.
Dec 8, 2025
2f4df82
leap of faith
Dec 13, 2025
fb608ce
Making problem and test linking consistent
Dec 14, 2025
998aded
Made tests non-blocking to see the full difference between mac and linux
Dec 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# We'll mostly use the Google style
# IMPORTANT: This project uses clang-format version 18
# Install: Ubuntu: apt-get install clang-format-18
# macOS: brew install llvm@18
BasedOnStyle: Google
CommentPragmas: '^ NOLINT'
QualifierAlignment: Left
4 changes: 2 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Checks: '
readability-enum-initial-value,
readability-inconsistent-declaration-parameter-name,
readability-make-member-function-const,
readability-math-missing-parentheses,
# readability-math-missing-parentheses, # DISABLED: Too pedantic, complains about standard math precedence (e.g., 1 + x*x)
readability-non-const-parameter,
readability-redundant-access-specifiers,
readability-redundant-declaration,
Expand All @@ -83,7 +83,7 @@ Checks: '
# due to them causing unavoidable warnings (esp. with Eigen)

WarningsAsErrors: '*' # treat all warnings as errors
HeaderFilterRegex: '(include|developers)/.*\.h$' # tells clang-tidy which header files should have unsupressed warnings (ony ours)
HeaderFilterRegex: '.*/(include|developers|homeworks|lecturecodes)/.*' # tells clang-tidy which header files should have unsupressed warnings (ony ours)
FormatStyle: file # format from .clang-format file
UseColor: true
ExtraArgs: ['-DEIGEN_INTERNAL_DEBUGGING'] # was there before, unsure what it does
Expand Down
191 changes: 191 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
name: C++ CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
HUNTER_ROOT: ${{ github.workspace }}/hunter

jobs:
# Format check disabled - can be re-enabled later if needed
# format:
# name: clang-format-18
# runs-on: ubuntu-22.04
# steps:
# - uses: actions/checkout@v4
#
# - name: Install clang-format-18
# run: |
# wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
# sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main"
# sudo apt-get update
# sudo apt-get install -y clang-format-18
#
# - name: Check formatting
# run: |
# echo "Checking if the code is well formatted"
# clang-format-18 --version
# echo "Checking developers folder"
# ./scripts/ci/run-clang-format.py -r --clang-format-executable clang-format-18 --color always developers/
# echo "Checking include folder"
# ./scripts/ci/run-clang-format.py -r --clang-format-executable clang-format-18 --color always include/
# echo "Checking lecturecodes folder"
# ./scripts/ci/run-clang-format.py -r --clang-format-executable clang-format-18 --color always lecturecodes/

build-linux:
name: Build & Test (Linux)
runs-on: ubuntu-24.04
env:
CXX: g++
CXXFLAGS: "-Werror=cpp"
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v4

- name: Cache Hunter packages
uses: actions/cache@v4
with:
path: ${{ env.HUNTER_ROOT }}
key: hunter-linux-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
hunter-linux-

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip ccache
pip3 install matplotlib numpy

- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ccache-linux-${{ github.sha }}
restore-keys: ccache-linux-
max-size: 2G

- name: Configure CMake
run: |
mkdir -p build
cd build
cmake -DHOMEWORKS=OFF -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DHUNTER_CONFIGURATION_TYPES=$BUILD_TYPE -DCMAKE_CXX_FLAGS_DEBUG="$CXXFLAGS" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..

- name: Build
run: |
cd build
make -j $(nproc)

- name: Test
continue-on-error: true
run: |
cd build
echo "Testing developer folder master solutions"
../scripts/ci/test_developers.sh
echo "Testing lecture codes"
../scripts/ci/run_lecturecodes.sh

build-macos:
name: Build & Test (macOS ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-14, macos-15]
env:
CXX: clang++
CXXFLAGS: "-Werror=#warnings"
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v4

- name: Cache Hunter packages
uses: actions/cache@v4
with:
path: ${{ env.HUNTER_ROOT }}
key: hunter-${{ matrix.os }}-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
hunter-${{ matrix.os }}-

- name: Install dependencies
run: |
brew install ccache
pip3 install --break-system-packages matplotlib numpy

- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ccache-${{ matrix.os }}-${{ github.sha }}
restore-keys: ccache-${{ matrix.os }}-
max-size: 2G

- name: Configure CMake
run: |
mkdir -p build
cd build
cmake -DHOMEWORKS=OFF -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DHUNTER_CONFIGURATION_TYPES=$BUILD_TYPE -DCMAKE_CXX_FLAGS_DEBUG="$CXXFLAGS" -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ..

- name: Build
run: |
cd build
make -j $(sysctl -n hw.ncpu)

- name: Test
continue-on-error: true
run: |
cd build
echo "Testing developer folder master solutions"
../scripts/ci/test_developers.sh
echo "Testing lecture codes"
../scripts/ci/run_lecturecodes.sh

tidy:
name: clang-tidy-21
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Install clang-tidy-21
run: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-21 main"
sudo apt-get update
sudo apt-get install -y clang-tidy-21

- name: Cache Hunter packages
uses: actions/cache@v4
with:
path: ${{ env.HUNTER_ROOT }}
key: hunter-tidy-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
hunter-tidy-

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip
pip3 install matplotlib numpy

- name: Configure CMake
run: |
mkdir -p build
cd build
cmake -DHOMEWORKS=OFF -DCMAKE_BUILD_TYPE=Release -DHUNTER_CONFIGURATION_TYPES=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DMYSOLUTION=OFF ..

- name: Run clang-tidy on developers folder
run: |
cd build
echo "Running clang-tidy on developers folder"
clang-tidy-21 --version
../scripts/ci/run-clang-tidy.py -clang-tidy-binary clang-tidy-21 -p . -config-file ../.clang-tidy "../developers/.*\.cc"

- name: Check for std::system usage
run: |
echo "Checking if std::system is used in developers folder"
./scripts/ci/forbid_stdsystem.sh ./developers/

- name: Run clang-tidy on lecturecodes folder
run: |
cd build
echo "Running clang-tidy on lecturecodes folder"
../scripts/ci/run-clang-tidy.py -clang-tidy-binary clang-tidy-21 -p . -config-file ../.clang-tidy "../lecturecodes/.*\.cc"
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ if(COMPILER_SUPPORTS_WCONVERSION)
target_compile_options(warning_flags INTERFACE -Wconversion)
endif()

# Suppress duplicate library warnings on Apple linker
if(APPLE)
add_link_options(-Wl,-no_warn_duplicate_libraries)
endif()

# Add switches
###############################################################################
option(HOMEWORKS "usage: cmake -DHOMEWORKS=ON/OFF .." ON)
Expand Down Expand Up @@ -68,6 +73,25 @@ find_package(Eigen3 CONFIG REQUIRED)
hunter_add_package(lehrfempp)
find_package(lehrfempp CONFIG REQUIRED)

# Create INTERFACE library that wraps all LehrFEM++ modules
# Only link top-level modules and let lower-level dependencies come in transitively
# Dependency hierarchy: uscalfe → fe → assemble → mesh → geometry → base
#
# Note: Some duplicates are unavoidable when multiple independent modules share dependencies:
# - Both lf.refinement and lf.mesh.test_utils depend on lf.mesh.utils → mesh.utils appears 2x
# - All mesh modules (hybrid2d, test_utils, refinement) depend on lf.mesh → mesh appears 2x
# The linker automatically deduplicates these - warnings are informational only
add_library(LF_ALL INTERFACE)
target_link_libraries(LF_ALL INTERFACE
LF::lf.uscalfe
LF::lf.io
LF::lf.mesh.hybrid2d
LF::lf.fe.test_utils
LF::lf.geometry.test_utils
LF::lf.refinement
LF::lf.mesh.test_utils
)

# Get Google Test
hunter_add_package(GTest)
find_package(GTest CONFIG REQUIRED)
Expand Down
98 changes: 77 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This repository contains the codes for the homework problems of the recurring co

Moreover, enrolled students can access the [moodle](https://moodle-app2.let.ethz.ch/course/view.php?id=12060) page of the course.

# For Students

## Requirements
Currently, only UNIX based operating systems are supported. Moreover, you need to have the following installed on your machine:
* C++20 compiler (e.g. gcc, clang)
Expand All @@ -22,7 +24,40 @@ mkdir build
cd build/
cmake ..
```
This will install LehrFEM++ and its dependencies into a folder `~/.hunter/`. To build a specific problem, say `TestQuadratureRules`, proceed as follows:
This will install LehrFEM++ and its dependencies into a folder `~/.hunter/`.

**Note**: The first compilation can take a significant amount of time. It is highly recommended to use parallel compilation with the `-j` flag. To use all available cores, you can use the following commands:

* **On macOS:**
```bash
make -j $(sysctl -n hw.ncpu)
```
* **On Linux:**
```bash
make -j $(nproc)
```

This will significantly speed up the build process.

### Build Configurations

For optimal performance, always specify the build type during the `cmake` configuration step.

* **Release Build (Optimized & Fast):**
```bash
# Inside your build directory
cmake -DCMAKE_BUILD_TYPE=Release ..
```
This is recommended for running computationally intensive problems and matches the CI pipeline's configuration.

* **Debug Build (For Development & Debugging):**
```bash
# Inside your build directory
cmake -DCMAKE_BUILD_TYPE=Debug ..
```
This builds with debug symbols and no optimizations, making it suitable for use with a debugger.

To build a specific problem, say `TestQuadratureRules`, proceed as follows:
```
cd homeworks/TestQuadratureRules/
make
Expand Down Expand Up @@ -71,26 +106,8 @@ cmake ..
```
The first four lines are due to limited resources on the student computers. Setting the environment variable `HUNTER_ROOT` tells CMake where to look for the preinstalled libraries. This environment variable is local to your terminal, i.e. has to be redefined if you start a new terminal. Apart from this, you can use the folder `~/NPDERepo` in the same way you would for the approach in the previous section. However, you have only very little memory available on the student computers. We therefore recommend to only build one problem at a time.

## FAQ
# For Developers

### clang: error: unknown argument: '-fcoalesce-templates'
Mac users, after updating to macOS Catalina 10.15.4, are receiving this error. The workaround is as follows: Navigate your terminal into the folder `NPDECODES/` and type:
```
brew install gcc@8 #install gcc version 8, needs brew to be installed first...
gcc-8 --version #check if gcc-8 was installed properly
g++-8 --version #check if g++-8 was installed properly
rm -rf build #delete the old build folder
mkdir build #recreate it
```
If this has succeeded, you need to build the codes using the gcc compiler by defining the environment variables `CC` and `CXX`. This is done by navigating a terminal into `NPDECODES/build/` and running:
```
export CC=gcc-8
export CXX=g++-8
cmake ..
```
If the installation is successful, you can than build your codes using `make` as before. Note that the gcc version under OSX usulally just links to clang. However, the procedure above installs the actual gcc compiler.

# Notes for Developers
## Creating a new Homework
New homeworks should be created in the `developers` folder. When the homework is ready to be deployed,
it can be done by running `scripts/deploy_npde.py`.
Expand All @@ -111,6 +128,26 @@ ProblemName/
└── README.md
```
You can create a template using `scripts/python/new_problem.py <Problemname> <problemname>`. Feel free to delete any folders you don't need.

### Build System and Dependencies
The build system automatically discovers source files (`.cc` and `.h`) in the problem directory and provides default libraries (`Eigen3::Eigen` and `LF_ALL` for main sources, `GTest::gtest_main` for tests). In most cases, you don't need to specify dependencies manually.

However, if your problem requires:
- Additional libraries (e.g., `Boost::program_options` in `LeapfrogDissipativeWave`)
- Source files from subdirectories (e.g., `meshes/mesh.cc` in `ElementMatrixComputation`)
- Exclusion of certain files from compilation (e.g., `GaussLobattoParabolic`)

you can create a `dependencies.cmake` file in your `mastersolution/` directory with:
```cmake
set(SOURCES
${DIR}/problemname_main.cc
${DIR}/problemname.cc
meshes/mesh.cc
)
set(LIBRARIES Eigen3::Eigen LF_ALL Boost::program_options)
```
Similarly, for tests, create `mastersolution/test/dependencies.cmake` if needed.

### Solution Tags

In the files of `./developers/mastersolution/` we put the following tags
Expand Down Expand Up @@ -202,4 +239,23 @@ int n = 1; // NOLINT(<check>)
// NOLINTNEXTLINE(<check>)
int n = 1;
```
**But note** that sometimes `clang-format` will force a single line statement onto two lines, making the single line `NOLINT` not work!
**But note** that sometimes `clang-format` will force a single line statement onto two lines, making the single line `NOLINT` not work!

# Archived FAQs

## clang: error: unknown argument: '-fcoalesce-templates'
Mac users, after updating to macOS Catalina 10.15.4, are receiving this error. The workaround is as follows: Navigate your terminal into the folder `NPDECODES/` and type:
```
brew install gcc@8 #install gcc version 8, needs brew to be installed first...
gcc-8 --version #check if gcc-8 was installed properly
g++-8 --version #check if g++-8 was installed properly
rm -rf build #delete the old build folder
mkdir build #recreate it
```
If this has succeeded, you need to build the codes using the gcc compiler by defining the environment variables `CC` and `CXX`. This is done by navigating a terminal into `NPDECODES/build/` and running:
```
export CC=gcc-8
export CXX=g++-8
cmake ..
```
If the installation is successful, you can than build your codes using `make` as before. Note that the gcc version under OSX usulally just links to clang. However, the procedure above installs the actual gcc compiler.
Loading
Loading