diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 0ad40624..f97f5679 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -5,6 +5,7 @@ * [ ] I used the [`pre-commit` hook](https://precice.org/dev-docs-dev-tooling.html#setting-up-pre-commit) and used `pre-commit run --all` to apply all available hooks. * [ ] I added a test to cover the proposed changes in our test suite. * [ ] I updated the documentation in `docs/README.md`. +* [ ] I added a changelog entry in `./changelog-entries/` (create if necessary). * [ ] I updated potential breaking changes in the tutorial [`precice/tutorials/aste-turbine`](https://github.com/precice/tutorials/tree/develop/aste-turbine). diff --git a/.github/workflows/aste_ci.yml b/.github/workflows/aste_ci.yml index 437e9fbe..460824de 100644 --- a/.github/workflows/aste_ci.yml +++ b/.github/workflows/aste_ci.yml @@ -13,63 +13,93 @@ concurrency: cancel-in-progress: ${{github.event_name == 'pull_request'}} jobs: + vtk: + name: Build VTK from source + runs-on: ubuntu-latest + container: + image: precice/precice:nightly + options: --shm-size=2gb + env: + CMAKE_BUILD_PARALLEL_LEVEL: 4 + steps: + - name: Check VTK cache + id: cache-vtk + uses: actions/cache@v4 + with: + key: ${{ runner.os }}-aste-vtk + path: | + /usr/local/include/vtk-*/ + /usr/local/lib/libvtk* + /usr/local/lib/cmake/vtk-*/ + /usr/local/bin/vtk* + /usr/local/bin/pvtkpython + /usr/local/lib/python*/site-packages/vtk.py + /usr/local/lib/python*/site-packages/vtkmodules/* + /etc/profile.d/99-vtk.sh + - name: Build VTK + if: steps.cache-vtk.outputs.cache-hit != 'true' + run: | + git clone https://gitlab.kitware.com/vtk/vtk.git && cd vtk + git checkout v9.3.0 + mkdir build && cd build + cmake -DVTK_WRAP_PYTHON="ON" -DVTK_USE_MPI="ON" -DCMAKE_BUILD_TYPE=Release .. + cmake --build . && cmake --install . + echo 'export PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python3.10/site-packages/"' > /etc/profile.d/99-vtk.sh + build: + needs: vtk + name: ${{ format('{0} {1}', matrix.CXX, matrix.TYPE) }} runs-on: ubuntu-latest - container: precice/precice:nightly - timeout-minutes: 80 + container: + image: precice/precice:nightly + options: --shm-size=2gb + defaults: + run: + shell: "bash --login -eo pipefail {0}" + strategy: + fail-fast: false + matrix: + CXX: ["clang++", "g++"] + TYPE: ["Debug", "Release"] env: + CXX: ${{ matrix.CXX }} CXX_FLAGS: "-Werror -Wall -Wextra -Wno-unused-parameter" CTEST_OUTPUT_ON_FAILURE: "Yes" + CMAKE_BUILD_PARALLEL_LEVEL: 4 steps: + - name: Restore VTK from cache + uses: actions/cache@v4 + with: + fail-on-cache-miss: true + key: ${{ runner.os }}-aste-vtk + path: | + /usr/local/include/vtk-*/ + /usr/local/lib/libvtk* + /usr/local/lib/cmake/vtk-*/ + /usr/local/bin/vtk* + /usr/local/bin/pvtkpython + /usr/local/lib/python*/site-packages/vtk.py + /usr/local/lib/python*/site-packages/vtkmodules/* + /etc/profile.d/99-vtk.sh - name: setup system run: | apt-get -y update && apt-get -y upgrade - apt-get install -y python3-pip pkg-config time - pip3 install --upgrade pip - - name: install VTK - run: | - git clone https://gitlab.kitware.com/vtk/vtk.git && cd vtk - git checkout v9.3.0 - mkdir build && cd build - cmake -DVTK_WRAP_PYTHON="ON" -DVTK_USE_MPI="ON" -DCMAKE_BUILD_TYPE=Release .. - cmake --build . -j 2 && cmake --install . - echo "PYTHONPATH=/usr/local/lib/python3.10/site-packages/:${PYTHONPATH}" >> $GITHUB_ENV - cd + apt-get install -qq -y python3-pip python3-jinja2 python3-scipy python3-sympy libmetis-dev time clang - uses: actions/checkout@v4 - name: install example dependencies run: | python3 -m pip install -r requirements.txt - - name: prepare directories - run: | - mkdir build_gcc build_clang - - name: build aste gcc - working-directory: build_gcc - env: - CC: gcc - CXX: g++ - run: | - cmake .. - cmake --build . - - name: Adjust user rights - run: chown -R precice . - - name: run test gcc - working-directory: build_gcc - run: | - su -c "ctest" precice - - name: install clang + - name: prepare build directory run: | - apt-get -y install clang - - name: build aste clang - working-directory: build_clang - env: - CC: clang - CXX: clang++ + mkdir build + - name: build aste + working-directory: build run: | - cmake .. + cmake -DCMAKE_BUILD_TYPE=${{ matrix.TYPE }} .. cmake --build . - name: Adjust user rights run: chown -R precice . - - name: run test clang - working-directory: build_clang + - name: run test + working-directory: build run: | su -c "ctest" precice diff --git a/.github/workflows/aste_ci_mac.yml b/.github/workflows/aste_ci_mac.yml new file mode 100644 index 00000000..96099ff5 --- /dev/null +++ b/.github/workflows/aste_ci_mac.yml @@ -0,0 +1,73 @@ +name: ASTE macOS CI + +on: + push: + branches: [master, develop] + pull_request: + branches: [master, develop] + schedule: + - cron: '0 8 * * 2' # run once in a week (here Tue at 8am) + +concurrency: + group: ${ {github.event_name }}-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{github.event_name == 'pull_request'}} + +jobs: + build-macos: + runs-on: macos-latest + timeout-minutes: 20 + env: + CXX_FLAGS: "-Werror -Wall -Wextra -Wno-unused-parameter" + CTEST_OUTPUT_ON_FAILURE: "Yes" + steps: + - name: Setup system + run: | + brew update + brew install cmake eigen boost openmpi pkg-config ninja gnu-time vtk + - name: Install preCICE + run: | + git clone https://github.com/precice/precice.git + cd precice + mkdir build && cd build + cmake -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + -DPRECICE_FEATURE_MPI_COMMUNICATION=ON \ + -DPRECICE_FEATURE_PETSC_MAPPING=OFF \ + -DPRECICE_FEATURE_PYTHON_ACTIONS=OFF \ + -DBUILD_TESTING=OFF \ + -G Ninja .. + ninja + sudo ninja install + cd ../.. + - uses: actions/checkout@v4 + - name: Setup python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + check-latest: true + + - name: Set up environment and install dependencies + run: | + python3 -m venv --system-site-packages venv + source venv/bin/activate + python3 -m pip install --upgrade pip + pip install -r requirements.txt + pip install numpy polars vtk + echo "VIRTUAL_ENV=$(pwd)/venv" >> $GITHUB_ENV + echo "$VIRTUAL_ENV/bin" >> $GITHUB_PATH + + - name: Prepare build directory + run: mkdir build + - name: Build project with clang + working-directory: build + env: + CC: clang + CXX: clang++ + run: | + cmake .. + cmake --build . + - name: Run tests + working-directory: build + run: | + source ${{ env.VIRTUAL_ENV }}/bin/activate + ctest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7bdb457e..959e9567 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,6 +41,6 @@ repos: rev: v0.39.0 hooks: - id: markdownlint - exclude: changelog-entries + exclude: 'changelog-entries|^CHANGELOG\.md$' - id: markdownlint-fix - exclude: changelog-entries + exclude: 'changelog-entries|^CHANGELOG\.md$' diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..b1d72ce9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,129 @@ +# ASTE Change Log + +All notable changes to this project will be documented in this file. + +## [v3.3.0] - 2024-11-07 + +### Added + +- Added a code of conduct from Covenant (see `CODE_OF_CONDUCT.md`). [#205](https://github.com/precice/aste/pull/205) +- Added contributing guidelines (see `docs/CONTRIBUTING.md`). [#205](https://github.com/precice/aste/pull/205) +- Added documentation to the mapping tester. [#209](https://github.com/precice/aste/pull/209) +- Added scoping support to gathering events. [#207](https://github.com/precice/aste/pull/207) +- Added macOS continuous integration support for ASTE. [#202](https://github.com/precice/aste/pull/202) +- Added a cached VTK build in ASTE CI for faster build times. [#211](https://github.com/precice/aste/pull/211) + +### Changed + +- Changed CMake to always find Boost using its CMake Config. [#194](https://github.com/precice/aste/pull/194) +- Highlighted ASTE's dependency on preCICE more clearly in the documentation. [#206](https://github.com/precice/aste/pull/206) +- Made `run-all` script for examples more robust. [#201](https://github.com/precice/aste/pull/201) + +### Fixed + +- Fixed linker errors when FindBoost uses the CMake Config. [#194](https://github.com/precice/aste/pull/194) +- Fixed SEGFAULT in `precice-aste-run` if no mesh is found for the given name. [#196](https://github.com/precice/aste/pull/196) + +## [v3.2.0] - 2024-07-31 + +### Fixed + +- Fixed CMake installation for VTK 9 and higher. [#184](https://github.com/precice/aste/pull/184) + +### Changed + +- Updated documentation for current VTK issues. [#185](https://github.com/precice/aste/pull/185) +- Updated CI to use manual installation of VTK. [#187](https://github.com/precice/aste/pull/187) +- Cleaned up Python requirements. [#193](https://github.com/precice/aste/pull/193) + +## [v3.1.0] - 2024-03-22 + +### Added + +- Introduced a Halton Mesh Generator for improved mesh sampling. [#155](https://github.com/precice/aste/pull/155) +- Added a unit grid generator. [#154](https://github.com/precice/aste/pull/154) +- Added connectivity to the Halton Mesh Generator using Delaunay Triangulation. [#157](https://github.com/precice/aste/pull/157) +- Set up Dependabot for dependency updates. [#164](https://github.com/precice/aste/pull/164) +- Added pre-commit hooks for website linting. [#183](https://github.com/precice/aste/pull/183) + +### Changed + +- Updated codebase from C++14 to C++17 standard. [#138](https://github.com/precice/aste/pull/138) +- Replaced `boost::filesystem` with `std::filesystem`. [#160](https://github.com/precice/aste/pull/160) +- Updated ASTE for compatibility with preCICE version 3. [#161](https://github.com/precice/aste/pull/161) +- Merged `initialize` and `initializeData` functions. [#158](https://github.com/precice/aste/pull/158) +- Renamed test executable from `test` to `precice-aste-test`. [#175](https://github.com/precice/aste/pull/175) +- Updated preCICE packages in continuous integration. [#167](https://github.com/precice/aste/pull/167) + +### Fixed + +- Improved handling of ASTE and preCICE logging. [#136](https://github.com/precice/aste/pull/136) +- Fixed wrong variable in Franke3D function. [#173](https://github.com/precice/aste/pull/173) +- Fixed vertex resolution in partitioner and joiner. [#180](https://github.com/precice/aste/pull/180) +- Changed scripts to use `env time` to bypass built-in `time`. [#178](https://github.com/precice/aste/pull/178) + +### Released + +- Released ASTE version compatible with preCICE v3. [#182](https://github.com/precice/aste/pull/182) + +## [v3.0.0] - 2022-09-28 + +### Added + +- Fully ported ASTE to the VTK library, eliminating custom data structures. +- Unified user interface for the main C++ core (`precice-aste-run`) and Python tools. +- Introduced replay-mode to emulate participants in coupled simulations. +- Added support for `nearest-neighbor-gradient` and `linear-cell` interpolation mappings. +- Supported processing of tetrahedral meshes and gradient data. +- Created dedicated ASTE documentation and tutorial resources. + +### Changed + +- Improved logging for the C++ executable and Python tools. +- Renamed executables for consistency. +- Updated VTK version requirements and improved component detection. +- Switched to pre-commit hooks for code formatting. +- Refactored codebase for better performance and maintainability. + +### Fixed + +- Resolved compiler warnings and code style issues. +- Fixed MPI linking issues for test executables. +- Corrected logger names and typos in documentation. +- Fixed issues with `vtk_calculator` removing `diffdata` in diff mode. + +### Removed + +- Removed obsolete scripts and deprecated functions. + +## [v2.0.0] - 2020-02-10 + +### Added + +- Support for preCICE v2, including migration to the single-step setup. + +### Changed + +- Updated configuration files to be compatible with preCICE v2. + +## [v1.1.0] - 2019-11-20 + +### Added + +- Connectivity information to mesh creation and partition tools. +- Filter for cell types in mesh handling. + +### Changed + +- Sped up edge generation using `boost::flat_map` for better performance. +- Modernized CMake configurations for improved build process. +- Migrated `preciceMap`, `aste`, and `visualize_partition` tools to the new system. + +### Fixed + +- Issues with connectivity output ensuring correct data representation. +- Build issues in CMake configuration. + +### Removed + +- Dependency on the `prettyprint` library to reduce external dependencies. diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b42529d..15fa61a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,8 @@ cmake_minimum_required (VERSION 3.16.3) -project(ASTE) +project(ASTE VERSION 3.3.0) +message(STATUS "ASTE version: ${ASTE_VERSION_MAJOR}.${ASTE_VERSION_MINOR}.${ASTE_VERSION_PATCH}") list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") set (CMAKE_CXX_STANDARD 17) @@ -9,6 +10,10 @@ set (CMAKE_CXX_STANDARD_REQUIRED YES) set (CMAKE_CXX_EXTENSIONS NO) set (CMAKE_EXPORT_COMPILE_COMMANDS ON) +if(POLICY CMP0167) + cmake_policy(SET CMP0167 NEW) +endif() + if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui @@ -23,7 +28,7 @@ find_package (Threads REQUIRED) find_package(precice 3.0 REQUIRED) -find_package(Boost 1.71.0 REQUIRED COMPONENTS log log_setup system program_options unit_test_framework) +find_package(Boost 1.71.0 CONFIG REQUIRED COMPONENTS log log_setup system program_options unit_test_framework) # Initial attempt to find VTK without specifying components (only supported for VTK9) find_package(VTK QUIET) @@ -54,8 +59,14 @@ target_include_directories(precice-aste-run PRIVATE src thirdparty) target_link_libraries(precice-aste-run precice::precice Threads::Threads + Boost::boost + Boost::log + Boost::log_setup + Boost::program_options + Boost::system + Boost::thread + Boost::unit_test_framework MPI::MPI_CXX - ${Boost_LIBRARIES} ${VTK_LIBRARIES} ) @@ -71,7 +82,13 @@ endif() add_executable(test-precice-aste tests/testing.cpp tests/read_test.cpp tests/write_test.cpp src/mesh.cpp src/logger.cpp) target_include_directories(test-precice-aste PRIVATE src thirdparty) target_link_libraries(test-precice-aste - ${Boost_LIBRARIES} + Boost::boost + Boost::log + Boost::log_setup + Boost::program_options + Boost::system + Boost::thread + Boost::unit_test_framework MPI::MPI_CXX ${VTK_LIBRARIES} ) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..ad39c9fd --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,130 @@ +# Contributor Covenant Code of Conduct + + + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +info at precice.org. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md new file mode 100644 index 00000000..1c665b2a --- /dev/null +++ b/docs/CONTRIBUTING.md @@ -0,0 +1,31 @@ +# Contributing to ASTE + +**Thank you for considering contributing to our project! We welcome contributions of all kinds.** + +The documentation of ASTE is rendered on [the preCICE website](https://precice.org/tooling-aste.html) and hosted in this repository under `./docs/README.md`. + +## Reporting Bugs + +- Ensure the bug is not already reported by searching [in our GitHub issues](https://github.com/precice/aste/issues). +- Use a clear and descriptive title. +- Provide details on how to reproduce the specific bug. + +## Submitting Pull Requests + +See the [contribute to preCICE page](https://precice.org/community-contribute-to-precice.html) for general guidelines. + +### Testing + +ASTE uses [`CMake`](https://cmake.org/) as build system. Code changes can be tested using the command `ctest`, which is also run by a GitHub Action workflow. It executes unit tests located in `./tests/` and integration tests located in `./examples/`. Add tests for new features in your pull request. For unit tests, have a look at `./tests/read_test.cpp` as an example. To add an integration test, add a new directory in `./examples/` and include a `run.sh` script and a `clean.sh` script. For an integration test example, have a look at `./examples/nn`. + +### Changelog + +We curate a `CHANGELOG.md` file, which tracks notable changes of this project across releases. Add a changelog entry when contributing. However, instead of directly editing `CHANGELOG.md`, please add a file `123.md` in `changelog-entries`, where `123` is your pull request number. This helps reducing merge conflicts. We collect these files before releasing. + +### Code formatting + +Similar to [preCICE](https://precice.org/dev-docs-dev-tooling.html#setting-up-pre-commit), we use pre-commit to ensure consistent formatting of source code and documentation files. Under the hood, pre-commit uses clang-format and black as formatters. Install [pre-commit](https://pre-commit.com/) and then call `pre-commit install` at the root of this repository to setup the automation. + +## Contact + +For questions, reach out through the [preCICE community channels](https://precice.org/community-channels.html). diff --git a/docs/README.md b/docs/README.md index 9b792065..49e9c536 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,7 +19,16 @@ The core module, which interfaces with preCICE, is called `precice-aste-run` and ### Dependencies -The C++ core module of ASTE uses similar dependencies as preCICE itself. In particular, ASTE requires a C++ compiler, CMake, MPI and Boost. Have a look at the [corresponding preCICE documentation](https://precice.org/installation-source-dependencies.html) for required versions and on how to install these dependencies if needed. In addition, ASTE relies on preCICE (version >= 3.0) and the VTK library (version >= 7) in order to handle mesh files. The VTK library can be installed using the package manager (`libvtk-dev`), e.g., on Ubuntu +The C++ core module of ASTE depends on a C++ compiler, `CMake`, `MPI`, `Boost`, `VTK` and `preCICE`. Many of these dependencies are similar to dependencies of preCICE itself. In particular, the C++ compiler, `CMake`, `MPI` and `Boost`. Have a look at the [corresponding preCICE documentation](https://precice.org/installation-source-dependencies.html) for required versions and on how to install these dependencies if needed. In addition, ASTE relies on `preCICE` (version >= 3.0) and the `VTK` library (version >= 7) to handle mesh files. + +Detailed installation instructions for the preCICE library are available in the preCICE [installation documentation](https://precice.org/installation-overview.html). On Ubuntu, e.g., [system packages](https://precice.org/installation-packages.html#ubuntu) are availble through [GitHub releases](https://github.com/precice/precice/releases) and can be installed through the package manager, e.g., + +```bash +wget https://github.com/precice/precice/releases/download//libprecice.deb +sudo apt install ./libprecice.deb +``` + +The VTK library can be installed using the package manager directly (`libvtk-dev`), e.g., on Ubuntu ```bash sudo apt install libvtk9-dev diff --git a/examples/lci_2d/clean.sh b/examples/lci_2d/clean.sh index 9865414a..e2feb93d 100755 --- a/examples/lci_2d/clean.sh +++ b/examples/lci_2d/clean.sh @@ -2,8 +2,9 @@ set -e -x rm -f -r precice-run -rm -f precice-*-events*.json +rm -f -r precice-profiling +rm -f profiling.json +rm -f trace.json rm -f *.log rm -f map*.vtk rm -f fine_mesh_*.vtk -rm -f precice-*.json diff --git a/examples/lci_3d/clean.sh b/examples/lci_3d/clean.sh index eb71aca8..e2feb93d 100755 --- a/examples/lci_3d/clean.sh +++ b/examples/lci_3d/clean.sh @@ -2,7 +2,9 @@ set -e -x rm -f -r precice-run -rm -f precice-*-events*.json +rm -f -r precice-profiling +rm -f profiling.json +rm -f trace.json rm -f *.log rm -f map*.vtk rm -f fine_mesh_*.vtk diff --git a/examples/nn/clean.sh b/examples/nn/clean.sh index eb71aca8..e2feb93d 100755 --- a/examples/nn/clean.sh +++ b/examples/nn/clean.sh @@ -2,7 +2,9 @@ set -e -x rm -f -r precice-run -rm -f precice-*-events*.json +rm -f -r precice-profiling +rm -f profiling.json +rm -f trace.json rm -f *.log rm -f map*.vtk rm -f fine_mesh_*.vtk diff --git a/examples/nng_scalar/clean.sh b/examples/nng_scalar/clean.sh index eb71aca8..e2feb93d 100755 --- a/examples/nng_scalar/clean.sh +++ b/examples/nng_scalar/clean.sh @@ -2,7 +2,9 @@ set -e -x rm -f -r precice-run -rm -f precice-*-events*.json +rm -f -r precice-profiling +rm -f profiling.json +rm -f trace.json rm -f *.log rm -f map*.vtk rm -f fine_mesh_*.vtk diff --git a/examples/nng_vector/clean.sh b/examples/nng_vector/clean.sh index eb71aca8..e2feb93d 100755 --- a/examples/nng_vector/clean.sh +++ b/examples/nng_vector/clean.sh @@ -2,7 +2,9 @@ set -e -x rm -f -r precice-run -rm -f precice-*-events*.json +rm -f -r precice-profiling +rm -f profiling.json +rm -f trace.json rm -f *.log rm -f map*.vtk rm -f fine_mesh_*.vtk diff --git a/examples/run-all.sh b/examples/run-all.sh index f73ab420..2dbe6b75 100755 --- a/examples/run-all.sh +++ b/examples/run-all.sh @@ -1,33 +1,61 @@ #!/bin/bash set -e -u -# Print the problmatic case and increase error count -detect_error(){ - echo "Error while running case ${array[1]}" +if ! command -v precice-aste-run &> /dev/null || ! command -v precice-aste-evaluate &> /dev/null; then + echo "Error: It seems that ASTE is not installed or not discoverable in your PATH. See https://precice.org/tooling-aste.html#installation for more information." + exit 1 +fi + +# Get the absolute directory of where the script is located (execution from anywhere) +script_dir=$(dirname "$(readlink -f "$0")") + +# Function to handle errors +detect_error() { + echo "Error while running case $case_dir" err_count=$((err_count + 1)) } -echo "- Running all examples cases..." -test_cases=$(find . -maxdepth 2 -mindepth 2 -name run.sh) -number_of_cases=$(echo "$test_cases" | wc -w) -echo "- There are $number_of_cases case(s) found..." +# We only look for test cases one level lower since the mapping-tester generates additional run scripts +run_test_cases() { + local base_dir="$1" + + test_cases=$(find "$base_dir" -maxdepth 2 -mindepth 2 -name run.sh) + + # Check if there are any cases + number_of_cases=$(echo "$test_cases" | wc -w) + if [ "$number_of_cases" -eq 0 ]; then + echo "No test cases found in $base_dir." + return + fi + echo "- Found $number_of_cases case(s) in $base_dir..." + + for testcase in $test_cases; do + case_dir=$(dirname "$testcase") + echo "- Running test case in $case_dir ..." + + # Change to the test case directory + cd "$case_dir" + + # Run the test and check for errors + ./run.sh || detect_error + + # Return to the original directory + cd "$base_dir" + done +} + +echo "- Running all example cases from $script_dir..." -# Initial directory and error count -run_all_dir=$(pwd) +# Initialize error count err_count=0 -# Run all cases -for testcase in $test_cases; do - array=($(echo "$testcase" | tr "/" "\n")) - cd "${array[1]}" - echo "- Running test case ${array[1]}..." - ./run.sh || detect_error - cd "$run_all_dir" -done +# Run all test cases starting from the script's directory +run_test_cases "$script_dir" -if [ $err_count -eq 0 ]; then +# Report results +if [ "$err_count" -eq 0 ]; then echo "All tests passed" else - echo "$err_count out of $number_of_cases failed" + echo "$err_count test(s) failed." exit 1 fi diff --git a/src/modes.cpp b/src/modes.cpp index 02f7608b..97973ac6 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -200,6 +200,11 @@ void aste::runMapperMode(const aste::ExecutionContext &context, const OptionMap } auto asteInterface = asteConfiguration.asteInterfaces.front(); + if (asteInterface.meshes.empty()) { + ASTE_ERROR << "ERROR: Could not find meshes for name: " << meshname; + MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); + } + ASTE_INFO << "Loading mesh from " << asteInterface.meshes.front().filename(); const bool requireConnectivity = preciceInterface.requiresMeshConnectivityFor(asteInterface.meshName); const int dim = preciceInterface.getMeshDimensions(asteInterface.meshName); diff --git a/tools/mapping-tester/README.md b/tools/mapping-tester/README.md new file mode 100644 index 00000000..7e8bf619 --- /dev/null +++ b/tools/mapping-tester/README.md @@ -0,0 +1,69 @@ +# Mapping tester + +The mapping tester is a collection of scripts and templates that lets you generate, run, post-process and collect a huge catersian product of settings. + +Settings include: ranks, meshes, and mappings and their settings + +For performance profiling, it allows enabling synchronization and configuring repetitions +For mapping tests, it provides post-processing scripts and a configurable reference function + +## config-template.xml + +This is the setup of ASTE, which will be used. +This doesn't need to be changed for most scenarios. + +## setup.json + +This describes the setup including general information and execution groups. + +General information includes, repetitions, the function to generate data, the rank configuration, and solver meshes. + +Each execution group specifies which mapping and constraint to run using which meshes. +This is necessary for running a range of RBFs with mesh-specific configurations. + +## generate.py + +This generates all cases including run scripts in the given outdir based on `setup.json` and `config-template.xml`. +Meshes are prepared in the next step. + +## preparemeshes.py + +This looks up input meshes in the general section, evaluates the function to generate data and then partitions them for all requested rank configurations. +These meshes are the written to `outdir/meshes`. +When handling multiple cases, you can symlink them to a single directory to prevent duplication. + +## Running + +You can use environment variables `ASTE_A_MPIARGS` and `ASTE_B_MPIARGS` to pass custom arguments to `mpirun` for each solver. +This is useful to pin CPUs on a local node or pass hostfiles on a cluster / in a SLURM session. +See more information [on running simulations in our docs](https://precice.org/running-overview.html). + +Each case can be run individually using its `run.sh` or every case in sequence using `outdir/runall.sh`. + +A finished run generates a file called `done` in the case directory. This allows you to see the amount of finished jobs using: + +```bash +find -name done | wc -l +``` + +## Post processing + +This post-processes the mapped meshes and evaluates accuracy metrics of the mapping accuracy. +Hence, this step is only required if you are looking for mapping accuracy results. +Each case can be run individually using its `post.sh` or every case in sequence using `outdir/postprocessall.sh`. + +This however can take a very long time. Consider running all post-processing scripts in parallel using GNU parallel: + +```bash +find -name post.sh | parallel --bar bash {} +``` + +Use the saved time to cite the project. + +## gatherstats.py + +This generates various statistics for each case and aggregates them into a single CSV file. + +## plotconv.py + +This reads the stats file, averages the runs and plots various convergence statistics. diff --git a/tools/mapping-tester/config-template.xml b/tools/mapping-tester/config-template.xml index 83263438..4b64eb8a 100644 --- a/tools/mapping-tester/config-template.xml +++ b/tools/mapping-tester/config-template.xml @@ -20,7 +20,7 @@ - + diff --git a/tools/mapping-tester/gatherstats.py b/tools/mapping-tester/gatherstats.py index b99e4fab..b4477031 100755 --- a/tools/mapping-tester/gatherstats.py +++ b/tools/mapping-tester/gatherstats.py @@ -49,15 +49,19 @@ def statsFromTimings(dir): stats["globalTime"] = row[-1] if row[0] == "initialize": stats["initializeTime"] = row[-1] - if row[0].startswith("initialize/map") and row[0].endswith( - "computeMapping.FromA-MeshToB-Mesh" + parts = row[0].split("/") + event = parts[-1] + if ( + parts[0] == "initialize" + and event.startswith("map") + and event.endswith("computeMapping.FromA-MeshToB-Mesh") ): - computeMappingName = row[0] stats["computeMappingTime"] = row[-1] - if row[0].startswith("advance/map") and row[0].endswith( - "mapData.FromA-MeshToB-Mesh" + if ( + parts[0] == "advance" + and event.startswith("map") + and event.endswith("mapData.FromA-MeshToB-Mesh") ): - mapDataName = row[0] stats["mapDataTime"] = row[-1] except BaseException: pass diff --git a/tools/mapping-tester/generate.py b/tools/mapping-tester/generate.py index 7c09ddba..585368c6 100755 --- a/tools/mapping-tester/generate.py +++ b/tools/mapping-tester/generate.py @@ -3,6 +3,7 @@ import argparse import json import os +import sys from jinja2 import Template @@ -22,7 +23,7 @@ def as_iter(something): def generateCases(setup): meshes = setup["general"]["meshes"] - network = setup["general"].get("network", "lo") + network = setup["general"].get("network") syncmode = setup["general"].get("synchronize", "false") cases = [] @@ -165,10 +166,15 @@ def createRunScript(outdir, path, case): os.path.join(outdir, "meshes", amesh, str(aranks), amesh), path ) + # Detect the operating system and set the time command (brew install gnu-time) + if sys.platform.startswith("darwin"): + time_command = "gtime" + else: + time_command = "time" + # Generate runner script - acmd = 'env time -f %M -a -o memory-A.log precice-aste-run -v -a -p A --data "{}" --mesh {} || kill 0 &'.format( - case["function"], ameshLocation - ) + acmd = f'env {time_command} -f %M -a -o memory-A.log precice-aste-run -v -a -p A --data "{case["function"]}" --mesh {ameshLocation} || kill 0 &' + if aranks > 1: acmd = "mpirun -n {} $ASTE_A_MPIARGS {}".format(aranks, acmd) @@ -178,9 +184,8 @@ def createRunScript(outdir, path, case): os.path.join(outdir, "meshes", bmesh, str(branks), bmesh), path ) mapped_data_name = case["function"] + "(mapped)" - bcmd = 'env time -f %M -a -o memory-B.log precice-aste-run -v -a -p B --data "{}" --mesh {} --output mapped || kill 0 &'.format( - mapped_data_name, bmeshLocation - ) + bcmd = f'env {time_command} -f %M -a -o memory-B.log precice-aste-run -v -a -p B --data "{mapped_data_name}" --mesh {bmeshLocation} --output mapped || kill 0 &' + if branks > 1: bcmd = "mpirun -n {} $ASTE_B_MPIARGS {}".format(branks, bcmd)