diff --git a/.github/issue_template.md b/.github/issue_template.md index 79b7996..c146a9b 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -12,12 +12,12 @@ Please provide information about the operating system and relevant versions of the software. Example: -Ubuntu 20.04 LTS, preCICE 2.3.0, DuMuX 3.4, DuMuX-preCICE 0.1 +Ubuntu 22.04 LTS, preCICE 3.0.0, DuMuX 3.7, DuMuX-preCICE 2.0.0 ---> ## Steps to reproduce - + ### Expected behavior diff --git a/.github/workflows/build-and-test-dumux-master.yml b/.github/workflows/build-and-test-dumux-master.yml index cec69bd..57680d2 100644 --- a/.github/workflows/build-and-test-dumux-master.yml +++ b/.github/workflows/build-and-test-dumux-master.yml @@ -11,38 +11,38 @@ jobs: strategy: max-parallel: 1 matrix: - precice_version: [2.4.0, 2.5.0] - dune_version: [2.8] + precice_version: [develop] + dune_version: [2.9] container: image: precice/dune-precice:${{ matrix.dune_version }}-${{ matrix.precice_version }} runs-on: ubuntu-latest steps: - - name: Print python3 version - run: python3 --version - - name: Print python3 version (/usr/bin/env python3) - run: /usr/bin/env python3 --version - - name: Build DuMuX master - run: | - ls -lah - git clone --depth 1 https://git.iws.uni-stuttgart.de/dumux-repositories/dumux.git -b master - ls -lah - export DUNE_CONTROL_PATH=${DUNE_CONTROL_PATH}:${PWD}/dumux/dune.module - dunecontrol --opts=/opt/DUMUX/cmake-test.opts --only=dumux all - - name: Check out code - uses: actions/checkout@v3 - with: - path: dumux-precice - - name: Build code - run: | - ls -lah - export DUNE_CONTROL_PATH=${PWD}/dumux:${PWD}/dumux-precice:${DUNE_CONTROL_PATH} - echo $DUNE_CONTROL_PATH - dunecontrol --only=dumux-precice --opts=./dumux-precice/test/cmake-test.opts all - cd dumux-precice/build-cmake/ - make -j2 build_tests - - name: Run tests - run: | - export DUNE_CONTROL_PATH=${PWD}/dumux:${PWD}/dumux-precice:${DUNE_CONTROL_PATH} - cd dumux-precice/build-cmake/ - export PYTHONPATH=${PWD}/dumux/bin/testing:${PYTHONPATH} - CTEST_OUTPUT_ON_FAILURE=1 ctest -j1 + - name: Print python3 version + run: python3 --version + - name: Print python3 version (/usr/bin/env python3) + run: /usr/bin/env python3 --version + - name: Build DuMuX master + run: | + ls -lah + git clone --depth 1 https://git.iws.uni-stuttgart.de/dumux-repositories/dumux.git -b master + ls -lah + export DUNE_CONTROL_PATH=${DUNE_CONTROL_PATH}:${PWD}/dumux/dune.module + dunecontrol --opts=/opt/DUMUX/cmake-test.opts --only=dumux all + - name: Check out code + uses: actions/checkout@v3 + with: + path: dumux-precice + - name: Build code + run: | + ls -lah + export DUNE_CONTROL_PATH=${PWD}/dumux:${PWD}/dumux-precice:${DUNE_CONTROL_PATH} + echo $DUNE_CONTROL_PATH + dunecontrol --only=dumux-precice --opts=./dumux-precice/test/cmake-test.opts all + cd dumux-precice/build-cmake/ + make -j2 build_tests + - name: Run tests + run: | + export DUNE_CONTROL_PATH=${PWD}/dumux:${PWD}/dumux-precice:${DUNE_CONTROL_PATH} + cd dumux-precice/build-cmake/ + export PYTHONPATH=${PWD}/dumux/bin/testing:${PYTHONPATH} + CTEST_OUTPUT_ON_FAILURE=1 ctest -j1 diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 85cf3a2..2bc3bc4 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -11,30 +11,30 @@ jobs: strategy: max-parallel: 2 matrix: - dumux_version: [3.4, 3.5] - precice_version: [2.3.0, 2.4.0, 2.5.0] + dumux_version: [3.7, 3.8] + precice_version: [develop] container: image: precice/dumux-precice:${{ matrix.dumux_version }}-${{ matrix.precice_version }} runs-on: ubuntu-latest steps: - - name: Print python3 version - run: python3 --version - - name: Print python3 version (/usr/bin/env python3) - run: /usr/bin/env python3 --version - - name: Check out code - uses: actions/checkout@v3 - with: - path: dumux-precice - - name: Build code - run: | - ls -lah - export DUNE_CONTROL_PATH=${PWD}/dumux-precice:${DUNE_CONTROL_PATH} - echo $DUNE_CONTROL_PATH - dunecontrol --only=dumux-precice --opts=./dumux-precice/test/cmake-test.opts all - cd dumux-precice/build-cmake/ - make -j2 build_tests - - name: Run tests - run: | - export DUNE_CONTROL_PATH=${PWD}/dumux-precice:${DUNE_CONTROL_PATH} - cd dumux-precice/build-cmake/ - CTEST_OUTPUT_ON_FAILURE=1 ctest -j1 + - name: Print python3 version + run: python3 --version + - name: Print python3 version (/usr/bin/env python3) + run: /usr/bin/env python3 --version + - name: Check out code + uses: actions/checkout@v3 + with: + path: dumux-precice + - name: Build code + run: | + ls -lah + export DUNE_CONTROL_PATH=${PWD}/dumux-precice:${DUNE_CONTROL_PATH} + echo $DUNE_CONTROL_PATH + dunecontrol --only=dumux-precice --opts=./dumux-precice/test/cmake-test.opts all + cd dumux-precice/build-cmake/ + make -j2 build_tests + - name: Run tests + run: | + export DUNE_CONTROL_PATH=${PWD}/dumux-precice:${DUNE_CONTROL_PATH} + cd dumux-precice/build-cmake/ + CTEST_OUTPUT_ON_FAILURE=1 ctest -j1 diff --git a/.github/workflows/build-docker-containers.yml b/.github/workflows/build-docker-containers.yml index 55a3485..ab7e16c 100644 --- a/.github/workflows/build-docker-containers.yml +++ b/.github/workflows/build-docker-containers.yml @@ -17,8 +17,8 @@ jobs: dockerhub_username: precice strategy: matrix: - dumux_version: [3.4, 3.5] - precice_version: [2.3.0, 2.4.0, 2.5.0] + dumux_version: [3.7, 3.8] + precice_version: [develop] steps: - name: Checkout Repository uses: actions/checkout@v3 @@ -37,10 +37,10 @@ jobs: file: "./dockerfile.slim" tags: ${{ env.dockerhub_username }}/dumux-precice:${{ matrix.dumux_version }}-${{ matrix.precice_version }} build-args: | - DUNE_VERSION=2.8 - PRECICEUBUNTU=focal - DUMUX_VERSION=${{ matrix.dumux_version }} - PRECICE_VERSION=${{ matrix.precice_version }} + DUNEVERSION=2.9 + PRECICEUBUNTU=jammy + DUMUXVERSION=${{ matrix.dumux_version }} + PRECICEVERSION=${{ matrix.precice_version }} build-dune-precice: name: Builds a Docker container for testing the DuMuX preCICE adapter (DUNE and preCICE) runs-on: ubuntu-latest @@ -48,8 +48,8 @@ jobs: dockerhub_username: precice strategy: matrix: - dune_version: [2.8] - precice_version: [2.3.0, 2.4.0, 2.5.0] + dune_version: [2.9] + precice_version: [develop] steps: - name: Checkout Repository uses: actions/checkout@v3 @@ -68,6 +68,6 @@ jobs: file: "./dockerfile_dune-precice.slim" tags: ${{ env.dockerhub_username }}/dune-precice:${{ matrix.dune_version }}-${{ matrix.precice_version }} build-args: | - DUNE_VERSION=#{{ matrix.dune_version }} - PRECICEUBUNTU=focal - PRECICE_VERSION=${{ matrix.precice_version }} + DUNEVERSION=${{ matrix.dune_version }} + PRECICEUBUNTU=jammy + PRECICEVERSION=${{ matrix.precice_version }} diff --git a/.github/workflows/style-checking.yml b/.github/workflows/style-checking.yml index 8324925..e5cc9e9 100644 --- a/.github/workflows/style-checking.yml +++ b/.github/workflows/style-checking.yml @@ -20,9 +20,9 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: '3.8.10' + python-version: '3.10.10' - name: "Install style checker" - run: pip install --user black + run: pip install --user black~=22.12 - name: "Run style check" run: black --check . cpp_linting: @@ -31,5 +31,5 @@ jobs: - uses: actions/checkout@v2 - name: Run format check run: | - sudo apt-get install clang-format-10 + sudo apt-get install clang-format-14 ./scripts/format/run-clang-format.sh diff --git a/.gitlab/issue_templates/template.md b/.gitlab/issue_templates/template.md deleted file mode 100644 index 79b7996..0000000 --- a/.gitlab/issue_templates/template.md +++ /dev/null @@ -1,28 +0,0 @@ -## Description - - - -### Environment - - - -## Steps to reproduce - - - -### Expected behavior - - - -### Actual behavior - - diff --git a/.gitlab/merge_request_templates/template.md b/.gitlab/merge_request_templates/template.md deleted file mode 100644 index 1bd4dd9..0000000 --- a/.gitlab/merge_request_templates/template.md +++ /dev/null @@ -1,24 +0,0 @@ -## Description - - - -## Checklist - - - -- [ ] I made sure that the source files are formatted properly. -- [ ] I added my changes to the changelog (`CHANGELOG.md`) -- [ ] I updated the documentation. - - - -- [ ] I added a test for the new feature. diff --git a/CHANGELOG.md b/CHANGELOG.md index fac7c03..964988b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # DuMuX-preCICE change log -## Not released yet +## v2.0.0 + +- 2023-08-10: Updated the adapter to be compatible with preCICE v3.0.0. Updated the examples too. ## v1.0.0 @@ -47,6 +49,7 @@ - The configuration of tests has been changed such that it is possible to build all tests using the `build_tests` target. For details check out the merge request [!18 Restructure repository and tests](https://git.iws.uni-stuttgart.de/dumux-appl/dumux-precice/-/merge_requests/18) + - 2022-01-10: Add license file. The code is licensed under GPLv3 without template exception. - 2022-01-10: Tests run by the CI on DuMuX `master` are allowed to fail. - 2022-01-10: Added `CHANGELOG.md` to track changes of the adapter. diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bbabec..3dd40bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ endif() #find dune-common and set the module path find_package(dune-common REQUIRED) # Find preCICE library -find_package(precice 2 REQUIRED CONFIG) +find_package(precice 3.0.0 REQUIRED CONFIG) list(APPEND CMAKE_MODULE_PATH ${dune-common_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules") @@ -24,7 +24,7 @@ include(DuneMacros) # start a dune project with information from dune.module dune_project() -dune_enable_all_packages() +dune_enable_all_packages(MODULE_LIBRARIES dumux-precice) # enforce C++-17 dune_require_cxx_standard(MODULE "DuMuX-preCICE" VERSION 17) diff --git a/README.md b/README.md index 55e682c..273d98e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![build and test develop](https://github.com/precice/dumux-adapter/actions/workflows/build-and-test.yml/badge.svg) ![build and test develop with DuMuX masters](https://github.com/precice/dumux-adapter/actions/workflows/build-and-test-dumux-master.yml/badge.svg) -This repository provides a [DuMuX](https://dumux.org/)-specific adapter to couple to other codes using [preCICE](https://www.precice.org/). You can find the source code of this adapter [on GitHub](https://github.com/precice/dumux-adapter). The source code of the adapter was formerly stored [in a repository on the IWS GitLab](https://git.iws.uni-stuttgart.de/dumux-appl/dumux-precice). +This repository provides a [DuMuX](https://dumux.org/)-specific adapter to couple to other codes using [preCICE](https://www.precice.org/). The source code of the adapter was formerly stored [in a repository on the IWS GitLab](https://git.iws.uni-stuttgart.de/dumux-appl/dumux-precice). ## Structure of the repository @@ -23,13 +23,13 @@ The DuMuX-preCICE adapter is a DUNE module named `dumux-precice` which can be bu ### Prerequisites -- DuMuX **newer** than 3.2 +- DuMuX >= than 3.7 - Builds using the current `master` branch of DuMuX might fail. - If you run into trouble with a new DuMuX release, please open an issue in the repository and add the error message that you receive. - Needs UMFPack (available via SuiteSparse) as solver for linear systems of equations. This is needed to run the examples included in the adapter. Otherwise you can skip UMFPack. -- preCICE >=2.0.0 +- preCICE >=3.0.0 - The adapter is build via the DUNE build system that is based on CMake. Thus, the CMake [link instructions for preCICE](https://precice.org/installation-linking.html#cmake) apply. @@ -42,54 +42,54 @@ The DuMuX-preCICE adapter should build fine if DuMuX, preCICE and their dependen ### Detailed installation steps -1. Install [DuMuX](https://dumux.org/) and the needed dependencies. The easiest way is to follow [DuMuX's installation instructions](https://dumux.org/installation/). The DuMuX project provides a script that installs and DuMuX and the DUNE modules required by DuMuX. This means, after installing DuMuX via the provided script you should be good to go to use the DuMuX-preCICE adapter. +1. Install [DuMuX](https://dumux.org/) and the needed dependencies. The easiest way is to follow [DuMuX's installation instructions](https://dumux.org/docs/doxygen/master/installation.html). The DuMuX project provides a script that installs and DuMuX and the DUNE modules required by DuMuX. This means, after installing DuMuX via the provided script you should be good to go to use the DuMuX-preCICE adapter. After the installation you should have a root directory that contains the base DUNE modules, i.e. a number of directories named like `dune-common`, `dune-geometry` etc., and a directory called `dumux`. - Note that extended features of DuMuX or the DuMuX-preCICE adapter may need additional DUNE modules. -2. Download the DuMuX-preCICE adapter to the same directory as the DUNE modules and the `dumux` folder. At the moment there are no adapter releases, besides an outdated `v0.1` release, such the best way is to checkout the `develop` branch of the adapter. +2. Download the DuMuX-preCICE adapter to the same directory as the DUNE modules and the `dumux` folder. It is recommended to use the latest release of the adapter, which can be found by checking out the relevant release tag. ```text - git clone -b develop https://github.com/precice/dumux-adapter.git + git clone -b v2.0.0 https://github.com/precice/dumux-adapter.git ``` You can also try to clone the repository via SSH: ```text - git clone -b develop git@github.com:precice/dumux-adapter.git + git clone -b v2.0.0 git@github.com:precice/dumux-adapter.git ``` -3. Verify that the `dumux-precice` folder is in the same directory as the DUNE module folders and the `dumux` folder. +3. Verify that the `dumux-adapter` folder is in the same directory as the DUNE module folders and the `dumux` folder. 4. Build and configure the adapter using `dunecontrol`. While being in the directory mentioned in the previous step via calling ```text - dunecontrol --only=dumux-precice all + ./dune-common/bin/dunecontrol --only=dumux-precice all ``` - After the build and configure step a new directory `build-cmake` was created inside the `dumux-precice` directory. + After the build and configure step a new directory `build-cmake` was created inside the `dumux-adapter` directory. You can configure the build and configuration process using advanced options by manipulating CMake variables. `dunecontrol` allows to pass an options file for that ```bash - dunecontrol --opts=OPTSFILE.opts --only=dumux-precice all + ./dune-common/bin/dunecontrol --opts=OPTSFILE.opts --only=dumux-precice all ``` There is an `opts`-file provided by the adapter that resides in `test/`. You can use it as ```bash - dunecontrol --opts=dumux-precice/test/cmake-test.opts --only=dumux-precice all + ./dune-common/bin/dunecontrol --opts=dumux-precice/test/cmake-test.opts --only=dumux-precice all ``` This provided `cmake-test.opts` file turns off some system-dependent optimizations such that the tests create comparable results on different computers. - For more ways do manipulate/adapt the build and configuration step, please consult the `dunecontrol` documentation. + For more ways to manipulate/adapt the build and configuration step, please consult the `dunecontrol` documentation. 5. Optional, but recommended: Build all tests to verify the installation. For this navigate in the `build-cmake/` directory and build the `build_tests` target. ```bash - cd dumux-precice/build-cmake + cd dumux-adapter/build-cmake make -j1 build_tests ``` @@ -131,4 +131,3 @@ There is no publication related to this code available yet. ### Publications using dumux-precice - Jaust A., Weishaupt K., Mehl M., Flemisch B. (2020) Partitioned Coupling Schemes for Free-Flow and Porous-Media Applications with Sharp Interfaces. In: Klöfkorn R., Keilegavlen E., Radu F., Fuhrmann J. (eds) Finite Volumes for Complex Applications IX - Methods, Theoretical Aspects, Examples. FVCA 2020. Springer Proceedings in Mathematics & Statistics, vol 323. Springer, Cham. - - Code can be found at: diff --git a/doc/user/docs/example-usage.md b/doc/user/docs/example-usage.md index adc6a34..8cabeb6 100644 --- a/doc/user/docs/example-usage.md +++ b/doc/user/docs/example-usage.md @@ -1,3 +1,5 @@ # Adapter usage -Please check out the examples in the `examples/` directory to get an idea on how to use the adapter. \ No newline at end of file +Please check out the examples in the `examples/` directory to get an idea on how to use the adapter. + +To use the adapter in a separate DUNE module, call `dune_enable_all_packages()` in the root `CMakeLists.txt` of the application module. If `libdumux-precice` is built as a static library, preCICE needs to be explicitly discovered with `find_package` as done in the root `CMakeLists.txt` of the adapter. To build the adapter library as a dynamic library, use the CMake option `-DBUILD_SHARED_LIBS=ON` to build `dumux-precice` and upstream modules. diff --git a/doc/user/docs/installation.md b/doc/user/docs/installation.md index 68dea37..84821b7 100644 --- a/doc/user/docs/installation.md +++ b/doc/user/docs/installation.md @@ -4,12 +4,12 @@ The DuMuX-preCICE adapter is a DUNE module named `dumux-precice` which can be bu ## Prerequisites -- DuMuX **newer** than 3.2 +- DuMuX >= 3.7 - Builds using the current `master` branch of DuMuX might fail. - If you run into trouble with a new DuMuX release, please open an issue in the repository and add the error message that you receive. -- preCICE >=2.0.0 +- preCICE >=3.0.0 - The adapter is build via the DUNE build system that is based on CMake. Thus, the CMake [link instructions for preCICE](https://precice.org/installation-linking.html#cmake) apply. @@ -20,7 +20,7 @@ The DuMuX-preCICE adapter should build fine if DuMuX, preCICE and their dependen ## Detailed installation steps -1. Install [DuMuX](https://dumux.org/) and the needed dependencies. The easiest way is to follow [DuMuX's installation instructions](https://dumux.org/installation/). The DuMuX project provides a script that installs and DuMuX and the DUNE modules required by DuMuX. This means, after installing DuMuX via the provided script you should be good to go to use the DuMuX-preCICE adapter. +1. Install [DuMuX](https://dumux.org/) and the needed dependencies. The easiest way is to follow [DuMuX's installation instructions](https://dumux.org/docs/doxygen/master/installation.html). The DuMuX project provides a script that installs and DuMuX and the DUNE modules required by DuMuX. This means, after installing DuMuX via the provided script you should be good to go to use the DuMuX-preCICE adapter. After the installation you should have a root directory that contains the base DUNE modules, i.e. a number of directories named like `dune-common`, `dune-geometry` etc., and a directory called `dumux`. @@ -38,36 +38,39 @@ The DuMuX-preCICE adapter should build fine if DuMuX, preCICE and their dependen git clone -b develop git@github.com:precice/dumux-adapter.git ``` -3. Verify that the `dumux-precice` folder is in the same directory as the DUNE module folders and the `dumux` folder. +3. Verify that the `dumux-adapter` folder is in the same directory as the DUNE module folders and the `dumux` folder. 4. Build and configure the adapter using `dunecontrol`. While being in the directory mentioned in the previous step via calling ```text - dunecontrol --only=dumux-precice all + dune-common/bin/dunecontrol --only=dumux-precice all ``` - After the build and configure step a new directory `build-cmake` was created inside the `dumux-precice` directory. + After the build and configure step a new directory `build-cmake` was created inside the `dumux-adapter` directory. You can configure the build and configuration process using advanced options by manipulating CMake variables. `dunecontrol` allows to pass an options file for that ```bash - dunecontrol --opts=OPTSFILE.opts --only=dumux-precice all + dune-common/bin/dunecontrol --opts=OPTSFILE.opts --only=dumux-precice all ``` There is an `opts`-file provided by the adapter that resides in `test/`. You can use it as ```bash - dunecontrol --opts=dumux-precice/test/cmake-test.opts --only=dumux-precice all + dune-common/bin/dunecontrol --opts=dumux-adapter/test/cmake-test.opts --only=dumux-precice all ``` This provided `cmake-test.opts` file turns off some system-dependent optimizations such that the tests create comparable results on different computers. - For more ways do manipulate/adapt the build and configuration step, please consult the `dunecontrol` documentation. + To use the adapter in a separate DUNE module, we recommend building the adapter as a shared library. To do so, use the CMake option `-DBUILD_SHARED_LIBS=ON` to build the adapter and upstream modules. The DuMux install script uses `dumux/cmake.opts`, which already sets this option. + Note that to change this setting it may be required to clear the CMake caches in `build-cmake/CMakeCache.txt`. + + For more ways to manipulate/adapt the build and configuration step, please consult the `dunecontrol` documentation. 5. Optional, but recommended: Build all tests to verify the installation. For this navigate in the `build-cmake/` directory and build the `build_tests` target. ```bash - cd dumux-precice/build-cmake + cd dumux-adapter/build-cmake make -j1 build_tests ``` @@ -81,4 +84,4 @@ The DuMuX-preCICE adapter should build fine if DuMuX, preCICE and their dependen If any tests fails, you should verify if something went wrong with the installation. -There are advanced ways of managing DUNE modules, e.g. using the environment variable `DUNE_CONTROL_PATH`, that are beyond the scope of this short documentation. You can find more information in the [DUNE FAQ](https://www.dune-project.org/doc/installation/#faq). \ No newline at end of file +There are advanced ways of managing DUNE modules, e.g. using the environment variable `DUNE_CONTROL_PATH`, that are beyond the scope of this short documentation. You can find more information in the [DUNE FAQ](https://www.dune-project.org/doc/installation/#faq). diff --git a/doc/user/docs/overview.md b/doc/user/docs/overview.md index 7d0e50c..4fcf684 100644 --- a/doc/user/docs/overview.md +++ b/doc/user/docs/overview.md @@ -8,4 +8,4 @@ Note that the DuMuX-preCICE adapter is a [DUNE module](https://www.dune-project. - `docker/`: A Docker recipe that creates a container with DUNE, DuMuX and preCICE. The recipe is mainly used for the automated tests. Check the `README.md` in the subdirectory for more details. - `dumux-precice/`: The preCICE adapter source code and further code for some of the tests and examples. - `scripts/`: Contains useful scripts to run simulations and for checking the code's formatting. -- `test/`: Contains test cases and reference solutions (`reference-solutions/`). The directory also contains several DUNE configuration files (`.opts` files) for configuring the project. \ No newline at end of file +- `test/`: Contains test cases and reference solutions (`reference-solutions/`). The directory also contains several DUNE configuration files (`.opts` files) for configuring the project. diff --git a/docker/README.md b/docker/README.md index 0ed0d4c..2cb2fc6 100644 --- a/docker/README.md +++ b/docker/README.md @@ -19,15 +19,15 @@ For more details on what is installed, please check the `Dockerfile`. The versions of the main dependencies can be manipulated when building the Docker image via the arguments with given default values -- `ARG DUNEVERSION=2.7`: DUNE version. Available in all recipes. -- `ARG DUMUXVERSION=3.4`: DuMuX version. Available in all recipes. -- `ARG PRECICEVERSION=2.2.1`: preCICE version. Available only in "large" and "slim" recipes. -- `ARG PRECICEUBUNTU=focal`: preCICE target platform (here, Ubuntu Focal Fossa). Available only in "large" recipe. +- `ARG DUNEVERSION=2.9`: DUNE version. Available in all recipes. +- `ARG DUMUXVERSION=3.7`: DuMuX version. Available in all recipes. +- `ARG PRECICEVERSION=3.0.0`: preCICE version. Available only in "large" and "slim" (use branch name e.g. "v3.0.0" or "develop") recipes. +- `ARG PRECICEUBUNTU=jammy`: preCICE target platform (here, Ubuntu Jammy Jellyfish). Available only in "large" recipe. -If one wants to build a "slim" image using DUNE 2.8, DuMuX from the current master branch and preCICE 2.4.0 one could call it with the following command: +If one wants to build a "slim" image using DUNE 2.9, DuMuX from the current master branch and preCICE 3.0.0 one could call it with the following command: ```text -sudo docker build --build-arg DUNEVERSION=2.8 --build-arg DUMUXVERSION=master --build-arg PRECICEVERSION=2.4.0 -t ajaust/dumux-precice:master-2.4.0 --file dockerfile.slim . +sudo docker build --build-arg DUNEVERSION=2.9 --build-arg DUMUXVERSION=master --build-arg PRECICEVERSION=v3.0.0 -t precice/dumux-precice:master-v3.0.0 --file dockerfile.slim . ``` The script `rebuild-docker-images.sh` can be used to rebuild the Docker images locally. diff --git a/docker/checkout_repositories.sh b/docker/checkout_repositories.sh index 9808522..98dddbf 100644 --- a/docker/checkout_repositories.sh +++ b/docker/checkout_repositories.sh @@ -15,7 +15,7 @@ for module in 'common' 'geometry' 'grid' 'localfunctions' 'istl' 'subgrid' do echo "Checking out module: ${module}" if [[ ${module} == 'subgrid' ]]; then - git clone --depth 1 https://git.imp.fu-berlin.de/agnumpde/dune-${module}.git -b releases/$DUNEVERSION + git clone --depth 1 https://gitlab.dune-project.org/extensions/dune-${module}.git -b releases/$DUNEVERSION else git clone --depth 1 https://gitlab.dune-project.org/core/dune-${module}.git -b releases/$DUNEVERSION fi diff --git a/docker/cmake-test.opts b/docker/cmake-test.opts index baa143d..c310d33 100644 --- a/docker/cmake-test.opts +++ b/docker/cmake-test.opts @@ -54,4 +54,6 @@ CMAKE_FLAGS="$SPECIFIC_COMPILER $SPECIFIC_GENERATOR $OPM_FLAGS -DCMAKE_BUILD_TYPE=Release -DENABLE_HEADERCHECK=$DUMUX_ENABLE_HEADERCHECK -DDUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS:BOOL=TRUE +-DDUNE_ENABLE_PYTHONBINDINGS=0 +-DDUNE_PYTHON_USE_VENV=0 " diff --git a/docker/dockerfile.base b/docker/dockerfile.base index a0363d6..26fd30f 100644 --- a/docker/dockerfile.base +++ b/docker/dockerfile.base @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 ENV DEBIAN_FRONTEND noninteractive @@ -13,8 +13,8 @@ ARG DUMUXINSTALLPATH=/opt/DUMUX WORKDIR ${DUMUXINSTALLPATH} # Obtain DuMuX and Dune repositories -ARG DUNEVERSION=2.8 -ARG DUMUXVERSION=3.5 +ARG DUNEVERSION=2.9 +ARG DUMUXVERSION=3.7 COPY checkout_repositories.sh . RUN bash checkout_repositories.sh ${DUNEVERSION} ${DUMUXVERSION} diff --git a/docker/dockerfile.large b/docker/dockerfile.large index 0e4c5c6..4ad9162 100644 --- a/docker/dockerfile.large +++ b/docker/dockerfile.large @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 # Install DUNE and DuMuX in /home/dumux WORKDIR ${USER_HOME} @@ -14,8 +14,8 @@ RUN apt-get install -y apt-utils vim htop git RUN apt-get install -y openmpi-bin libopenmpi-dev git gcc g++ wget cmake sudo libboost-all-dev pkg-config python3 # Obtain DuMuX and Dune repositories -ARG DUNEVERSION=2.7 -ARG DUMUXVERSION=3.4 +ARG DUNEVERSION=2.9 +ARG DUMUXVERSION=3.7 COPY checkout_repositories.sh . RUN bash checkout_repositories.sh ${DUNEVERSION} ${DUMUXVERSION} @@ -31,9 +31,9 @@ ENV DUNE_CONTROL_PATH=${USER_HOME}/dune-common/dune.module:${USER_HOME}/dune-geo ENV PYTHONPATH ${USER_HOME}/dumux/bin/testing:${PYTHONPATH} #Install preCICE -ARG PRECICEVERSION=2.2.1 -ARG PRECICEUBUNTU=focal -RUN wget https://github.com/precice/precice/releases/download/v${PRECICEVERSION}/libprecice2_${PRECICEVERSION}_${PRECICEUBUNTU}.deb -O libprecice${PRECICEVERSION}-${PRECICEUBUNTU}.deb \ +ARG PRECICEVERSION=3.0.0 +ARG PRECICEUBUNTU=jammy +RUN wget https://github.com/precice/precice/releases/download/v${PRECICEVERSION}/libprecice3_${PRECICEVERSION}_${PRECICEUBUNTU}.deb -O libprecice${PRECICEVERSION}-${PRECICEUBUNTU}.deb \ && apt install -y ./libprecice${PRECICEVERSION}-${PRECICEUBUNTU}.deb \ && rm -f ./libprecice${PRECICEVERSION}-${PRECICEUBUNTU}.deb diff --git a/docker/dockerfile.slim b/docker/dockerfile.slim index cc6b3cc..0c2ea18 100644 --- a/docker/dockerfile.slim +++ b/docker/dockerfile.slim @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 ENV DEBIAN_FRONTEND noninteractive @@ -7,14 +7,14 @@ ADD 01_nodoc /etc/dpkg/dpkg.cfg.d/01_nodoc # Install dependencies from RUN apt-get update -RUN apt-get install -y git gcc g++ gfortran cmake pkg-config libboost-log1.71.0 libboost-thread1.71.0 libboost-system1.71.0 libboost-filesystem1.71.0 libboost-program-options1.71.0 libboost-test1.71.0 libboost-container1.71.0 libeigen3-dev libxml2 libboost-log-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev libboost-container-dev libeigen3-dev libxml2-dev libsuitesparse-dev python3 +RUN apt-get install -y git gcc g++ gfortran cmake pkg-config libboost-log1.74.0 libboost-thread1.74.0 libboost-system1.74.0 libboost-filesystem1.74.0 libboost-program-options1.74.0 libboost-test1.74.0 libboost-container1.74.0 libeigen3-dev libxml2 libboost-log-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev libboost-container-dev libeigen3-dev libxml2-dev libsuitesparse-dev python3 ARG DUMUXINSTALLPATH=/opt/DUMUX WORKDIR ${DUMUXINSTALLPATH} # Obtain DuMuX and Dune repositories -ARG DUNEVERSION=2.8 -ARG DUMUXVERSION=3.5 +ARG DUNEVERSION=2.9 +ARG DUMUXVERSION=3.7 COPY checkout_repositories.sh . RUN bash checkout_repositories.sh ${DUNEVERSION} ${DUMUXVERSION} @@ -30,11 +30,11 @@ ENV DUNE_CONTROL_PATH=${DUMUXINSTALLPATH}/dune-common/dune.module:${DUMUXINSTALL ENV PYTHONPATH ${DUMUXINSTALLPATH}/dumux/bin/testing:${PYTHONPATH} # Compile minmum version of preCICE -ARG PRECICEVERSION=2.4.0 -ARG PRECICEUBUNTU=focal -RUN git clone --depth 1 -b v${PRECICEVERSION} https://github.com/precice/precice.git precice-${PRECICEVERSION} && cd precice-${PRECICEVERSION} && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=ON -DPRECICE_MPICommunication=OFF -DPRECICE_PETScMapping=OFF -DPRECICE_PythonActions=OFF -DCMAKE_INSTALL_PREFIX=/usr && make -j 4 && make test && make install && cd ../../ && rm -rf precice-${PRECICEVERSION} +ARG PRECICEVERSION=v3.0.0 +ARG PRECICEUBUNTU=jammy +RUN git clone --depth 1 -b ${PRECICEVERSION} https://github.com/precice/precice.git precice-${PRECICEVERSION} && cd precice-${PRECICEVERSION} && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DPRECICE_FEATURE_MPI_COMMUNICATION=OFF -DPRECICE_FEATURE_PETSC_MAPPING=OFF -DPRECICE_FEATURE_PYTHON_ACTIONS=OFF -DCMAKE_INSTALL_PREFIX=/usr && make -j 4 && make test && make install && cd ../../ && rm -rf precice-${PRECICEVERSION} -RUN apt-get purge -y libboost-log-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev libboost-container-dev libxml2-dev && binprecice md +RUN apt-get purge -y libboost-log-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev libboost-container-dev libxml2-dev # Cleanup RUN apt-get autoremove -y && apt-get clean diff --git a/docker/dockerfile_dune-precice.slim b/docker/dockerfile_dune-precice.slim index 853ecb9..8c2d334 100644 --- a/docker/dockerfile_dune-precice.slim +++ b/docker/dockerfile_dune-precice.slim @@ -1,4 +1,4 @@ -FROM ubuntu:20.04 +FROM ubuntu:22.04 ENV DEBIAN_FRONTEND noninteractive @@ -7,13 +7,13 @@ ADD 01_nodoc /etc/dpkg/dpkg.cfg.d/01_nodoc # Install dependencies from RUN apt-get update -RUN apt-get install -y git gcc g++ gfortran cmake pkg-config libboost-log1.71.0 libboost-thread1.71.0 libboost-system1.71.0 libboost-filesystem1.71.0 libboost-program-options1.71.0 libboost-test1.71.0 libboost-container1.71.0 libeigen3-dev libxml2 libboost-log-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev libboost-container-dev libeigen3-dev libxml2-dev libsuitesparse-dev python3 +RUN apt-get install -y git gcc g++ gfortran cmake pkg-config libboost-log1.74.0 libboost-thread1.74.0 libboost-system1.74.0 libboost-filesystem1.74.0 libboost-program-options1.74.0 libboost-test1.74.0 libboost-container1.74.0 libeigen3-dev libxml2 libboost-log-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev libboost-container-dev libeigen3-dev libxml2-dev libsuitesparse-dev python3 ARG DUMUXINSTALLPATH=/opt/DUMUX WORKDIR ${DUMUXINSTALLPATH} # Obtain DuMuX and Dune repositories -ARG DUNEVERSION=2.8 +ARG DUNEVERSION=2.9 COPY checkout_repositories.sh . RUN bash checkout_repositories.sh ${DUNEVERSION} none @@ -27,11 +27,11 @@ RUN dunecontrol --opts=cmake-test.opts all ENV DUNE_CONTROL_PATH=${DUMUXINSTALLPATH}/dune-common/dune.module:${DUMUXINSTALLPATH}/dune-geometry/dune.module:${DUMUXINSTALLPATH}/dune-grid/dune.module:${DUMUXINSTALLPATH}/dune-localfunctions/dune.module:${DUMUXINSTALLPATH}/dune-istl/dune.module:${DUMUXINSTALLPATH}/dune-subgrid/dune.module # Compile minmum version of preCICE -ARG PRECICEVERSION=2.4.0 -ARG PRECICEUBUNTU=focal -RUN git clone --depth 1 -b v${PRECICEVERSION} https://github.com/precice/precice.git precice-${PRECICEVERSION} && cd precice-${PRECICEVERSION} && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=ON -DPRECICE_MPICommunication=OFF -DPRECICE_PETScMapping=OFF -DPRECICE_PythonActions=OFF -DCMAKE_INSTALL_PREFIX=/usr && make -j 4 && make test && make install && cd ../../ && rm -rf precice-${PRECICEVERSION} +ARG PRECICEVERSION=v3.0.0 +ARG PRECICEUBUNTU=jammy +RUN git clone --depth 1 -b ${PRECICEVERSION} https://github.com/precice/precice.git precice-${PRECICEVERSION} && cd precice-${PRECICEVERSION} && mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DPRECICE_FEATURE_MPI_COMMUNICATION=OFF -DPRECICE_FEATURE_PETSC_MAPPING=OFF -DPRECICE_FEATURE_PYTHON_ACTIONS=OFF -DCMAKE_INSTALL_PREFIX=/usr && make -j 4 && make test && make install && cd ../../ && rm -rf precice-${PRECICEVERSION} -RUN apt-get purge -y libboost-log-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev libboost-container-dev libxml2-dev && binprecice md +RUN apt-get purge -y libboost-log-dev libboost-thread-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-test-dev libboost-container-dev libxml2-dev # Cleanup RUN apt-get autoremove -y && apt-get clean diff --git a/docker/rebuild-docker-images.sh b/docker/rebuild-docker-images.sh index 26e457d..0d86af9 100755 --- a/docker/rebuild-docker-images.sh +++ b/docker/rebuild-docker-images.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -DUNE_VERSION="2.8" -DUMUX_VERSIONS=("3.4" "3.5") -PRECICE_VERSIONS=("2.4.0" "2.3.0") +DUNE_VERSION="2.9" +DUMUX_VERSIONS=("3.7" "3.8") +PRECICE_VERSIONS=("develop") for dumux_version in ${DUMUX_VERSIONS[@]}; do for precice_version in ${PRECICE_VERSIONS[@]}; do @@ -13,8 +13,8 @@ for dumux_version in ${DUMUX_VERSIONS[@]}; do done done -PRECICE_VERSION="2.4.0" +PRECICE_VERSION="develop" echo "Building dune-precice:${dumux_version}-${precice_version}" docker build --build-arg DUNEVERSION=${DUNE_VERSION} --build-arg PRECICEVERSION=${PRECICE_VERSION} -t precice/dune-precice:${DUNE_VERSION}-${PRECICE_VERSION} --file dockerfile_dune-precice.slim . docker push precice/dune-precice:${DUNE_VERSION}-${PRECICE_VERSION} -yes | docker image prune \ No newline at end of file +yes | docker image prune diff --git a/dumux-precice/CMakeLists.txt b/dumux-precice/CMakeLists.txt index 0a4fb70..c1e9dda 100644 --- a/dumux-precice/CMakeLists.txt +++ b/dumux-precice/CMakeLists.txt @@ -2,5 +2,5 @@ install(FILES couplingadapter.hh DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux-precice) -add_library(dumux-precice STATIC couplingadapter.cc dumuxpreciceindexmapper.cc) +dune_library_add_sources(dumux-precice SOURCES couplingadapter.cc dumuxpreciceindexmapper.cc) target_link_libraries(dumux-precice PRIVATE precice::precice) diff --git a/dumux-precice/couplingadapter.cc b/dumux-precice/couplingadapter.cc index d8e70e2..d8ed375 100644 --- a/dumux-precice/couplingadapter.cc +++ b/dumux-precice/couplingadapter.cc @@ -13,12 +13,8 @@ CouplingAdapter::CouplingAdapter() meshWasCreated_(false), preciceWasInitialized_(false), hasIndexMapper_(false), - meshID_(0), timeStepSize_(0.) { - preciceDataID_.reserve(reserveSize_); - dataNames_.reserve(reserveSize_); - dataVectors_.reserve(reserveSize_); } CouplingAdapter &CouplingAdapter::getInstance() @@ -28,102 +24,72 @@ CouplingAdapter &CouplingAdapter::getInstance() } void CouplingAdapter::announceSolver(const std::string &name, - const std::string configurationFileName, + const std::string &configurationFileName, const int rank, const int size) { assert(precice_ == nullptr); - precice_ = std::make_unique( + precice_ = std::make_unique( name, configurationFileName, rank, size); wasCreated_ = true; } -size_t CouplingAdapter::announceQuantity(const std::string &name, - const QuantityType quantity_type) +void CouplingAdapter::announceQuantity(const std::string &meshName, + const std::string &dataName) { assert(meshWasCreated_); - auto it = std::find(dataNames_.begin(), dataNames_.end(), name); - if (it != dataNames_.end()) { + const std::string key = meshAndDataKey(meshName, dataName); + if (dataMap_.find(key) != dataMap_.end()) { throw(std::runtime_error(" Error! Duplicate quantity announced! ")); } - dataNames_.push_back(name); - preciceDataID_.push_back(precice_->getDataID(name, meshID_)); - const int quantity_dimension = - (quantity_type == QuantityType::Scalar) ? 1 : getDimensions(); - dataVectors_.push_back( - std::vector(vertexIDs_.size() * quantity_dimension)); - return getNumberOfQuantities() - 1; + int dataDimension = precice_->getDataDimensions(meshName, dataName); + std::vector dataValues(vertexIDs_.size() * dataDimension); + dataMap_.insert(std::make_pair(key, dataValues)); } -size_t CouplingAdapter::announceScalarQuantity(const std::string &name) -{ - return announceQuantity(name, QuantityType::Scalar); -} - -size_t CouplingAdapter::announceVectorQuantity(const std::string &name) -{ - return announceQuantity(name, QuantityType::Vector); -} - -int CouplingAdapter::getDimensions() const +int CouplingAdapter::getMeshDimensions(const std::string &meshName) const { assert(wasCreated_); - return precice_->getDimensions(); -} -/* -void CouplingAdapter::setMeshName(const std::string& meshName) -{ - assert( wasCreated_ ); - meshID_ = precice_->getMeshID(meshName); + return precice_->getMeshDimensions(meshName); } -*/ void CouplingAdapter::setMesh(const std::string &meshName, - const size_t numPoints, - std::vector &coordinates) + const std::vector &positions) { assert(wasCreated_); - assert(numPoints == coordinates.size() / getDimensions()); - meshID_ = precice_->getMeshID(meshName); - vertexIDs_.resize(numPoints); - precice_->setMeshVertices(meshID_, numPoints, coordinates.data(), - vertexIDs_.data()); + vertexIDs_ = + std::vector(positions.size() / getMeshDimensions(meshName)); + vertexIDsSpan_ = precice::span(vertexIDs_); + precice_->setMeshVertices(meshName, positions, vertexIDsSpan_); meshWasCreated_ = true; } -double CouplingAdapter::initialize() +void CouplingAdapter::initialize() { assert(wasCreated_); assert(meshWasCreated_); assert(!preciceWasInitialized_); - timeStepSize_ = precice_->initialize(); + precice_->initialize(); + timeStepSize_ = precice_->getMaxTimeStepSize(); assert(timeStepSize_ > 0); preciceWasInitialized_ = true; - return timeStepSize_; -} - -void CouplingAdapter::createIndexMapping(const std::vector &dumuxFaceIDs) -{ - assert(meshWasCreated_); - indexMapper_.createMapping(dumuxFaceIDs, vertexIDs_); - hasIndexMapper_ = true; + assert(preciceWasInitialized_); } -double CouplingAdapter::setMeshAndInitialize(const std::string &meshName, - const size_t numPoints, - std::vector &coordinates) +double CouplingAdapter::getMaxTimeStepSize() const { - setMesh(meshName, numPoints, coordinates); - return initialize(); + return precice_->getMaxTimeStepSize(); } -void CouplingAdapter::initializeData() +void CouplingAdapter::createIndexMapping( + const std::vector &dumuxFaceIndices) { - assert(preciceWasInitialized_); - precice_->initializeData(); + assert(meshWasCreated_); + indexMapper_.createMapping(dumuxFaceIndices, vertexIDs_); + hasIndexMapper_ = true; } void CouplingAdapter::finalize() @@ -133,10 +99,10 @@ void CouplingAdapter::finalize() precice_->finalize(); } -double CouplingAdapter::advance(const double computedTimeStepLength) +void CouplingAdapter::advance(const double computedTimeStepLength) { assert(wasCreated_); - return precice_->advance(computedTimeStepLength); + precice_->advance(computedTimeStepLength); } bool CouplingAdapter::isCouplingOngoing() @@ -151,8 +117,9 @@ size_t CouplingAdapter::getNumberOfVertices() return vertexIDs_.size(); } -double CouplingAdapter::getScalarQuantityOnFace(const size_t dataID, - const int faceID) const +double CouplingAdapter::getScalarQuantityOnFace(const std::string &meshName, + const std::string &dataName, + const int faceID) { assert(wasCreated_); assert(hasIndexMapper_); @@ -162,45 +129,13 @@ double CouplingAdapter::getScalarQuantityOnFace(const size_t dataID, "created!"); } const auto idx = indexMapper_.getPreciceId(faceID); - assert(dataID < dataVectors_.size()); - const std::vector &quantityVector = dataVectors_[dataID]; - assert(idx < quantityVector.size()); - return quantityVector[idx]; + std::vector &dataVector = getQuantityVector(meshName, dataName); + assert(idx < dataVector.size()); + return dataVector[idx]; } -// std::vector getVectorQuantityOnFace(const size_t dataID, const int faceID) const -// { -// assert(wasCreated_); -// assert(hasIndexMapper_); -// if (!hasIndexMapper_) { -// throw std::runtime_error( -// "Reading quantity using faceID, but index mapping was not " -// "created!"); -// } -// const auto idx = indexMapper_.getPreciceId(faceID); -// assert(dataID < dataVectors_.size()); -// const std::vector &quantityVector = dataVectors_[dataID]; -// assert(idx+getDimension()-1 < quantityVector.size()); -// std::vector vector_quantity( quantityVector.begin(), quantityVector.begin()+getDimension()-1 ); -// return vector_quantity; -// } -// void getQuantityVector(const size_t dataID, std::vector& quantity_vector) const -// { -// assert(wasCreated_); -// assert(hasIndexMapper_); -// if (!hasIndexMapper_) { -// throw std::runtime_error( -// "Reading quantity using faceID, but index mapping was not " -// "created!"); -// } -// const auto idx = indexMapper_.getPreciceId(faceID); -// const std::vector& data_vector = dataVectors_[dataID]; -// assert(dataID < data_vector.size()); -// quantity_vector.resize( data_vector.size() ); -// std::copy( data_vector.begin(), data_vector.end(), quantity_vector.begin() ); -// } - -void CouplingAdapter::writeScalarQuantityOnFace(const size_t dataID, +void CouplingAdapter::writeScalarQuantityOnFace(const std::string &meshName, + const std::string &dataName, const int faceID, const double value) { @@ -212,96 +147,27 @@ void CouplingAdapter::writeScalarQuantityOnFace(const size_t dataID, "created!"); } const auto idx = indexMapper_.getPreciceId(faceID); - assert(dataID < dataVectors_.size()); - std::vector &quantityVector = dataVectors_[dataID]; - assert(idx < quantityVector.size()); - quantityVector[idx] = value; + std::vector &dataVector = getQuantityVector(meshName, dataName); + assert(idx < dataVector.size()); + dataVector[idx] = value; } -//void CouplingAdapter::writeVectorQuantityOnFace(const size_t dataID, -// const int faceID, -// const double* value, -// const size_t size) -//{ -// assert( wasCreated_ ); -// assert( hasIndexMapper_ ); -// assert( size == getDimensions() ); -// if ( !hasIndexMapper_ ) -// { -// throw std::runtime_error("Writing quantity using faceID, but index mapping was not created!"); -// } -// const auto idx = indexMapper_.getPreciceId( faceID ) * size; -// assert( dataID < dataVectors_.size() ); -// std::vector& quantityVector = dataVectors_[ dataID ]; -// assert( idx < quantityVector.size() ); -// //quantityVector[idx] = value; -// std::copy_n( value, size, quantityVector[idx] ); -//} - -std::vector &CouplingAdapter::getQuantityVector(const size_t dataID) +std::vector &CouplingAdapter::getQuantityVector( + const std::string &meshName, + const std::string &dataName) { - assert(wasCreated_); - assert(dataID < dataVectors_.size()); - return dataVectors_[dataID]; + std::string key = meshAndDataKey(meshName, dataName); + assert(dataMap_.find(key) != dataMap_.end()); + return dataMap_[key]; } -const std::vector &CouplingAdapter::getQuantityVector( - const size_t dataID) const +void CouplingAdapter::writeQuantityVector(const std::string &meshName, + const std::string &dataName, + const std::vector &values) { - assert(wasCreated_); - return getQuantityVector(dataID); -} - -// void CouplingAdapter::writeScalarQuantityVector(const size_t dataID, -// std::vector &values) -// { -// assert(wasCreated_); -// assert(dataID < dataVectors_.size()); -// assert(dataVectors_[dataID].size() == values.size()); -// dataVectors_[dataID] = values; -// } - -void CouplingAdapter::writeQuantityVector(const size_t dataID, - std::vector &values) -{ - assert(wasCreated_); - assert(dataID < dataVectors_.size()); - assert(dataVectors_[dataID].size() == values.size()); - dataVectors_[dataID] = values; -} - -void CouplingAdapter::writeQuantityToOtherSolver( - const size_t dataID, - const QuantityType quantity_type) -{ - assert(wasCreated_); - assert(dataID < dataVectors_.size()); - assert(dataID < preciceDataID_.size()); - assert(dataID < std::numeric_limits::max()); - writeBlockDataToPrecice(preciceDataID_[dataID], dataVectors_[dataID], - quantity_type); -} - -void CouplingAdapter::readQuantityFromOtherSolver( - const size_t dataID, - const QuantityType quantity_type) -{ - assert(wasCreated_); - assert(dataID < dataVectors_.size()); - assert(dataID < preciceDataID_.size()); - assert(dataID < std::numeric_limits::max()); - readBlockDataFromPrecice(preciceDataID_[dataID], dataVectors_[dataID], - quantity_type); -} - -void CouplingAdapter::writeScalarQuantityToOtherSolver(const size_t dataID) -{ - writeQuantityToOtherSolver(dataID, QuantityType::Scalar); -} - -void CouplingAdapter::readScalarQuantityFromOtherSolver(const size_t dataID) -{ - readQuantityFromOtherSolver(dataID, QuantityType::Scalar); + std::vector &dataVector = getQuantityVector(meshName, dataName); + assert(dataVector.size() == values.size()); + dataVector = values; } bool CouplingAdapter::isCoupledEntity(const int faceID) const @@ -310,23 +176,21 @@ bool CouplingAdapter::isCoupledEntity(const int faceID) const return indexMapper_.isDumuxIdMapped(faceID); } -size_t CouplingAdapter::getIdFromName(const std::string &dataName) const +std::string CouplingAdapter::meshAndDataKey(const std::string &meshName, + const std::string &dataName) const { assert(wasCreated_); - const auto it = std::find(dataNames_.begin(), dataNames_.end(), dataName); - if (it == dataNames_.end()) { - throw(std::runtime_error(" Error! Name of data not found! ")); + std::string combinedKey; + int length = meshName.size() + 1 + dataName.size(); + for (int i = 0; i < length; i++) { + if (i < meshName.size()) + combinedKey += meshName[i]; + else if (i == meshName.size()) + combinedKey += ":"; + else + combinedKey += dataName[i - meshName.size() - 1]; } - const auto idx = std::distance(dataNames_.begin(), it); - assert(idx > -1); - return size_t(idx); -} - -std::string CouplingAdapter::getNameFromId(const size_t dataID) const -{ - assert(wasCreated_); - assert(dataID < dataNames_.size()); - return dataNames_[dataID]; + return combinedKey; } void CouplingAdapter::print(std::ostream &os) @@ -334,87 +198,38 @@ void CouplingAdapter::print(std::ostream &os) os << indexMapper_; } -bool CouplingAdapter::checkIfActionIsRequired(const std::string &condition) -{ - assert(wasCreated_); - return precice_->isActionRequired(condition); -} - -void CouplingAdapter::actionIsFulfilled(const std::string &condition) -{ - assert(wasCreated_); - precice_->markActionFulfilled(condition); -} - -void CouplingAdapter::readBlockDataFromPrecice(const int dataID, - std::vector &data, - const QuantityType quantity_type) +void CouplingAdapter::readQuantityFromOtherSolver(const std::string &meshName, + const std::string &dataName, + double relativeReadTime) { - assert(wasCreated_); - if (quantity_type == QuantityType::Scalar) { - assert(vertexIDs_.size() == data.size()); - precice_->readBlockScalarData(dataID, vertexIDs_.size(), - vertexIDs_.data(), data.data()); - } else { - assert(vertexIDs_.size() * getDimensions() == data.size()); - precice_->readBlockVectorData(dataID, vertexIDs_.size(), - vertexIDs_.data(), data.data()); - } + precice::span dataValuesSpan(getQuantityVector(meshName, dataName)); + precice_->readData(meshName, dataName, vertexIDsSpan_, relativeReadTime, + dataValuesSpan); } -void CouplingAdapter::writeBlockDataToPrecice(const int dataID, - std::vector &data, - const QuantityType quantity_type) +void CouplingAdapter::writeQuantityToOtherSolver(const std::string &meshName, + const std::string &dataName) { - assert(wasCreated_); - if (quantity_type == QuantityType::Scalar) { - assert(vertexIDs_.size() == data.size()); - precice_->writeBlockScalarData(dataID, vertexIDs_.size(), - vertexIDs_.data(), data.data()); - } else { - assert(vertexIDs_.size() * getDimensions() == data.size()); - precice_->writeBlockVectorData(dataID, vertexIDs_.size(), - vertexIDs_.data(), data.data()); - } + precice::span dataValuesSpan( + getQuantityVector(meshName, dataName)); + precice_->writeData(meshName, dataName, vertexIDsSpan_, dataValuesSpan); } -bool CouplingAdapter::hasToWriteInitialData() +bool CouplingAdapter::requiresToWriteInitialData() { assert(wasCreated_); - return checkIfActionIsRequired( - precice::constants::actionWriteInitialData()); + return precice_->requiresInitialData(); } -void CouplingAdapter::announceInitialDataWritten() +bool CouplingAdapter::requiresToReadCheckpoint() { assert(wasCreated_); - precice_->markActionFulfilled(precice::constants::actionWriteInitialData()); + return precice_->requiresReadingCheckpoint(); } -bool CouplingAdapter::hasToReadIterationCheckpoint() +bool CouplingAdapter::requiresToWriteCheckpoint() { assert(wasCreated_); - return checkIfActionIsRequired( - precice::constants::actionReadIterationCheckpoint()); + return precice_->requiresWritingCheckpoint(); } - -void CouplingAdapter::announceIterationCheckpointRead() -{ - assert(wasCreated_); - actionIsFulfilled(precice::constants::actionReadIterationCheckpoint()); -} - -bool CouplingAdapter::hasToWriteIterationCheckpoint() -{ - assert(wasCreated_); - return checkIfActionIsRequired( - precice::constants::actionWriteIterationCheckpoint()); -} - -void CouplingAdapter::announceIterationCheckpointWritten() -{ - assert(wasCreated_); - actionIsFulfilled(precice::constants::actionWriteIterationCheckpoint()); -} - CouplingAdapter::~CouplingAdapter() {} diff --git a/dumux-precice/couplingadapter.hh b/dumux-precice/couplingadapter.hh index 946170d..7632cf9 100644 --- a/dumux-precice/couplingadapter.hh +++ b/dumux-precice/couplingadapter.hh @@ -2,7 +2,7 @@ #define PRECICEWRAPPER_HH #include -#include +#include #include #include "dumuxpreciceindexmapper.hh" @@ -13,8 +13,6 @@ */ namespace Dumux::Precice { -enum class QuantityType { Scalar, Vector }; - /*! * @brief A DuMuX-preCICE coupling adapter class * @@ -32,66 +30,23 @@ private: //! True if preCICE instance was initiated bool wasCreated_; //! Pointer to preCICE instance - std::unique_ptr precice_; - //! Constructor - CouplingAdapter(); - /*! - * @brief Checks whether an action predefined by preCICE - * needs to be carried out. - * - * @param[in] condition Name of the action. - * @return true Action must be carried out. - * @return false Action must not be carried out. - */ - bool checkIfActionIsRequired(const std::string &condition); - /*! - * @brief Announce to preCICE that an action was carried out. - * - * @param[in] condition Name of the action. - */ - void actionIsFulfilled(const std::string &condition); - /*! - * @brief Reads full block of data from preCICE. - * - * @param[in] dataID Identifier of dataset to read. - * @param[out] data Vector to store the read data to. - */ - void readBlockDataFromPrecice(const int dataID, - std::vector &data, - const QuantityType quantity_type); - /*! - * @brief Writes full block of data to preCICE. - * - * @param[in] dataID Identifier of dataset to read. - * @param[in] data Vector containing data to write into preCICE's buffer. - */ - void writeBlockDataToPrecice(const int dataID, - std::vector &data, - const QuantityType quantity_type); - /*! - * @brief Gives the number of quantities/datasets defined on coupling interface. - * - * @return size_t Number of quantities defined on the coupling interface. - */ - size_t numberOfQuantities() const { return dataNames_.size(); } + std::unique_ptr precice_; //! True if the coupling mesh was created. bool meshWasCreated_; - //! True if precice::SolverInterface.initialize() has been called. + //! True if precice::Participant.initialize() has been called. bool preciceWasInitialized_; //! True if instance owns an instance of DumuxPreciceIndexMapper. bool hasIndexMapper_; - //! Stores identifier of the coupling mesh provided by preCICE. - int meshID_; //! Time step size. double timeStepSize_; - //! Vector of names of data exchanged over coupling interface. - std::vector dataNames_; - //! Vector of identifiers of data exchanged over coupling interface. - std::vector preciceDataID_; - //! Vector storing data vectors of the data exchanged over the coupling interface. - std::vector > dataVectors_; - //! Vector of identifiers of the vertices of the coupling mesh. + //! Map storing meshName:dataName and data vectors + std::map> dataMap_; + //! Vector of identifiers (in preCICE) of the vertices of the coupling mesh. std::vector vertexIDs_; //should be size_t + //! Span of the precice vertex indices vector vertexIDs_ + precice::span vertexIDsSpan_; + //! Constructor + CouplingAdapter(); /*! * @brief Instance of DumuxPreciceIndexMapper that translates between * DuMuX' identifiers of vertices and preCICE's identifiers. @@ -99,13 +54,11 @@ private: */ Internal::DumuxPreciceIndexMapper indexMapper_; /*! - * @brief Get the of quantities exchanged. + * @brief Get the number of quantities exchanged. * * @return size_t Number of quantities defined on coupling interface. */ - size_t getNumberOfQuantities() const { return dataNames_.size(); } - //! Number of expected quantities on the coupling interface. - static constexpr size_t reserveSize_ = 4; + size_t getNumberOfQuantities() const { return dataMap_.size(); } /*! * @brief Destroy the CouplingAdapter object * @@ -115,7 +68,6 @@ private: public: CouplingAdapter(const CouplingAdapter &) = delete; void operator=(const CouplingAdapter &) = delete; - /*! * @brief Get the instance of the CouplingAdapter * @@ -131,82 +83,63 @@ public: * @param[in] size Total number of processes of the DuMuX solver. */ void announceSolver(const std::string &name, - const std::string configurationFileName, + const std::string &configurationFileName, const int rank, const int size); /*! - * @brief Announces an additional quantity on the coupling interface. + * @brief Announces a quantity on the coupling interface. * * Internally, the quantity is announced to preCICE and the corresponding * data structures are initilized to store information about the quantity. * - * @param[in] name Name of the scalar quantity. - * @param[in] quantity_type Type (Scalar or Vector) of the quantity - * @return size_t Number of currently announced quantities. - */ - size_t announceQuantity(const std::string &name, - const QuantityType quantity_type); - - /*! - * @brief Announces an additional scalar quantity on the coupling interface. - * - * Internally, the scalar quantity is announced to preCICE and the corresponding - * data structures are initilized to store information about the quantity. - * - * @param[in] name Name of the scalar quantity. - * @return size_t Number of currently announced quantities. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. */ - size_t announceScalarQuantity(const std::string &name); + void announceQuantity(const std::string &meshName, + const std::string &dataName); /*! - * @brief Announces an additional vector quantity on the coupling interface. - * - * Internally, the vector quantity is announced to preCICE and the corresponding - * data structures are initilized to store information about the quantity. + * @brief Get the number of spatial dimensions * - * @param[in] name Name of the vector quantity. - * @return size_t Number of currently announced quantities. + * @param[in] meshName Name of the mesh + * @return int Number of space dimensions. */ - size_t announceVectorQuantity(const std::string &name); + int getMeshDimensions(const std::string &meshName) const; /*! - * @brief Get the number of spatial dimensions + * @brief Get the maximum time step size from preCICE * - * @return int Number of space dimensions. Legal values are 2 and 3. + * @return double time step size */ - int getDimensions() const; + double getMaxTimeStepSize() const; /*! - * @brief Checks if simulation checkpoint needs to be restored. + * @brief Checks if the participant is required to read an iteration checkpoint. If true, the participant is required to read an iteration checkpoint before calling advance(). * * @return true Simulation checkpoint has to be restored. * @return false No further action is needed. */ - bool hasToReadIterationCheckpoint(); - //! Announce that the simulation checkpoint was read. - void announceIterationCheckpointRead(); + bool requiresToReadCheckpoint(); + /*! - * @brief Checks if simulation checkpoint needs to be saved. + * @brief Checks if the participant is required to write an iteration checkpoint. If true, the participant is required to write an iteration checkpoint before calling advance(). * * @return true Simulation checkpoints needs to be stored. * @return false No further action is needed. */ - bool hasToWriteIterationCheckpoint(); - //! Announce that the simulation checkpoint was written. - void announceIterationCheckpointWritten(); + bool requiresToWriteCheckpoint(); + /*! - * @brief Checks if initial coupling data has to be wrutten. + * @brief Checks if the participant is required to provide initial data. If true, the participant needs to write initial data to defined vertices prior to calling initialize(). * * @return true Initial coupling data has to be provided. * @return false No further action is needed. */ - bool hasToWriteInitialData(); - //! Announce that the initial coupling data has been written. - void announceInitialDataWritten(); + bool requiresToWriteInitialData(); + /*! * @brief Adds mesh for coupling of solvers. * - * @param[in] meshName Name of the mesh. - * @param[in] numPoints Number of points/vertices. - * @param[in] coordinates Coordinates of the points. - * + * @param[in] meshName The name of the mesh to add the vertices to. + * @param[in] positions A span to the coordinates of the vertices. + * * \note The coordinates need to be stored consecutively * according to their spatial coordinates as.\n * Example 2D:\n @@ -215,17 +148,15 @@ public: * [x_1, y_1, z_1, x_2, y_2, z_2,...x_numPoints, y_numPoints, z_numPoints] */ void setMesh(const std::string &meshName, - const size_t numPoints, - std::vector &coordinates); + const std::vector &positions); /*! * @brief Initializes the coupling * * The coupling needs be initialized after all quantities/datasets and coupling meshes * are known. * - * @return double Maximum allowed time step size. */ - double initialize(); + void initialize(); /*! * @brief Creates mapping between DuMuX' face identifiers and preCICE's * vertex identifiers. @@ -236,29 +167,6 @@ public: * passed in setMesh. */ void createIndexMapping(const std::vector &dumuxFaceIDs); - /*! - * @brief Sets the coupling mesh and initializes coupling. - * - * This is a convenience function that sets the coupling mesh using setMesh. - * Afterwards, the coupling is initialized via initialzie. - * - * @param[in] meshName Name of the mesh. - * @param[in] numPoints Number of points/vertices. - * @param[in] coordinates Coordinates of the points. - * @return double Maximum allowed time step size. - */ - double setMeshAndInitialize(const std::string &meshName, - const size_t numPoints, - std::vector &coordinates); - - /*! - * @brief Initializes the coupling data. - * - * If one wants to set non-zero data, one has to write data to the - * corresponding quantities via one of the `write` functions first. - * - */ - void initializeData(); /*! * @brief Destroys the coupling. * @@ -272,7 +180,7 @@ public: * @param[in] computedTimeStepLength Time step lengths of the current simulation stel. * @return double Maximum time step length for successive time steps. */ - double advance(const double computedTimeStepLength); + void advance(const double computedTimeStepLength); /*! * @brief Checks whether the coupling is still ongoing. * @@ -287,97 +195,66 @@ public: */ size_t getNumberOfVertices(); /*! - * @brief Gets value of a scalar quantity. + * @brief Reads full block of data from preCICE. * - * @param[in] dataID Identifier of the quantity. - * @param[in] faceID Identifier of the face according to DuMuX' numbering. - * @return double Value of scalar quantity. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. + * @param[in] relativeReadTime The relative time tagged to the data to be read. + */ + void readQuantityFromOtherSolver(const std::string &meshName, + const std::string &dataName, + double relativeReadTime); + /*! + * @brief Writes full block of data to preCICE. + * + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. */ - double getScalarQuantityOnFace(const size_t dataID, const int faceID) const; - // /*! - // * @brief Gets value of a vector quantity. - // * - // * @param[in] dataID Identifier of the quantity. - // * @param[in] faceID Identifier of the face according to DuMuX' numbering. - // * @return std::vector Value of vector quantity. - // */ - // std::vector getVectorQuantityOnFace(const size_t dataID, const int faceID) const; - // std::vector getVectorQuantity(const size_t dataID) const; + void writeQuantityToOtherSolver(const std::string &meshName, + const std::string &dataName); /*! - * @brief Gets value of a vector quantity. + * @brief Gets value of a scalar quantity on a finite volume face. * - * @param[in] dataID Identifier of the quantity. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. * @param[in] faceID Identifier of the face according to DuMuX' numbering. - * @return const std::vector& Value of vector quantity. + * @return double Value of scalar quantity. */ - const std::vector &getVectorScalarQuantityOnFace( - const size_t dataID, - const int faceID) const; + double getScalarQuantityOnFace(const std::string &meshName, + const std::string &dataName, + const int faceID); /*! - * @brief Writes value of scalar quantity on given face. + * @brief Writes value of scalar quantity on a given finite volume face to data map. * - * @param[in] dataID Identifier of the quantity. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. * @param[in] faceID Identifier of the face according to DuMuX' numbering. * @param[in] value Value of scalar quantity. */ - void writeScalarQuantityOnFace(const size_t dataID, + void writeScalarQuantityOnFace(const std::string &meshName, + const std::string &dataName, const int faceID, const double value); - /*! - * @brief Returns reference to data vector of quantity with given identifier. + * @brief Gets the quantity value vector from the data map according to the mesh and data name. * - * @param dataID Identifier of the quantity. - * @return[in] std::vector& Reference to data vector. - */ - std::vector &getQuantityVector(const size_t dataID); - /*! - * @brief Returns const reference to data vector of quantity with given identifier. - * - * @param[in] dataID Identifier of the quantity. - * @return std::vector& Const reference to data vector. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. + * @return The value vector of the quantity. */ - const std::vector &getQuantityVector(const size_t dataID) const; - + std::vector &getQuantityVector(const std::string &meshName, + const std::string &dataName); /*! - * @brief Writes value of scalar or vector quantity on all vertices. + * @brief Writes the quantity value vector into the data map. * - * @param[in] dataID Identifier of the quantity. + * @param[in] meshName Name of the mesh. + * @param[in] dataName Name of the data. * @param[in] values Value of the scalar or vector quantity. */ - void writeQuantityVector(const size_t dataID, std::vector &values); - /*! - * @brief Writes data from adapter's buffer into preCICE's communication buffer. - * - * @param[in] dataID Identifier of the quantity to write into communication buffer. - */ - void writeQuantityToOtherSolver(const size_t dataID, - const QuantityType quantity_type); - /*! - * @brief Reads data from preCICE's communication buffer and puts it into adapter's buffer. - * - * @param dataID Identifier of the quantity to read into adapter buffer. - */ - void readQuantityFromOtherSolver(const size_t dataID, - const QuantityType quantity_type); - /*! - * @brief Writes data from adapter's buffer into preCICE's communication buffer. - * - * @param[in] dataID Identifier of the quantity to write into communication buffer. - */ - void writeScalarQuantityToOtherSolver(const size_t dataID); - /*! - * @brief Reads data from preCICE's communication buffer and puts it into adapter's buffer. - * - * @param dataID Identifier of the quantity to read into adapter buffer. - */ - void readScalarQuantityFromOtherSolver(const size_t dataID); - /*! - * @brief Writes data from adapter's buffer into preCICE's communication buffer. - * - * @param[in] dataID Identifier of the quantity to write into communication buffer. - */ - /*! + void writeQuantityVector(const std::string &meshName, + const std::string &dataName, + const std::vector &values); + /*! * @brief Checks whether face with given identifier is part of coupling interface. * * @param[in] faceID Identifier of the face according to DuMuX' numbering. @@ -386,19 +263,14 @@ public: */ bool isCoupledEntity(const int faceID) const; /*! - * @brief Get a quantity's numeric identifier from its name. + * @brief Get a quantity's identifier from its name. * + * @param[in] meshName Name of the mesh. * @param[in] dataName Name of the quantity. * @return size_t Numeric identifier of quantity. */ - size_t getIdFromName(const std::string &dataName) const; - /*! - * @brief Get a quantitiy's name from its numeric identifier. - * - * @param dataID Identifier of the quantity to read into adapter buffer. - * @return std::string Name of the quantity. - */ - std::string getNameFromId(const size_t dataID) const; + std::string meshAndDataKey(const std::string &meshName, + const std::string &dataName) const; /*! * @brief Prints status of coupling adapter to given output stream. * diff --git a/dune.module b/dune.module index 694e26c..e3f8732 100644 --- a/dune.module +++ b/dune.module @@ -4,9 +4,9 @@ #Name of the module Module: dumux-precice -Version: 1.0.0 +Version: 2.0.0 Maintainer: ishaan.desai@ipvs.uni-stuttgart.de # Required build dependencies -Depends: dumux (>=3.2) +Depends: dumux (>=3.7) # Optional build dependencies Suggests: dune-subgrid diff --git a/examples/README.md b/examples/README.md index 2019bfa..b198428 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,4 +2,3 @@ - `dummysolver/` contains a dummy solver similar to the dummy solver provided by preCICE. However, the included dummy solver uses the DuMuX-preCICE adapter. - `ff-pm/` contains examples of coupled free flow (`ff`) and porous medium (`pm`) flow - diff --git a/examples/dummysolver/CMakeLists.txt b/examples/dummysolver/CMakeLists.txt index f590201..b6f3d53 100644 --- a/examples/dummysolver/CMakeLists.txt +++ b/examples/dummysolver/CMakeLists.txt @@ -1,7 +1,5 @@ add_executable(dumuxprecice_dummysolver EXCLUDE_FROM_ALL main_dummysolver.cc) -target_link_libraries(dumuxprecice_dummysolver PRIVATE dumux-precice) - dune_symlink_to_source_files(FILES precice-dummy-solver-config.xml) dune_symlink_to_source_files(FILES Allrun.sh) diff --git a/examples/dummysolver/main_dummysolver.cc b/examples/dummysolver/main_dummysolver.cc index 5e8808d..e3e8dbc 100644 --- a/examples/dummysolver/main_dummysolver.cc +++ b/examples/dummysolver/main_dummysolver.cc @@ -36,7 +36,6 @@ try { // - Name of solver // - Configuration file name // - Solver rank - const std::string solverName = getParamFromGroup("preCICE", "SolverName"); const std::string preciceConfigFilename = @@ -44,22 +43,20 @@ try { const std::string meshName = getParamFromGroup("preCICE", "MeshName"); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver(solverName, preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); - + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver(solverName, preciceConfigFilename, + mpiHelper.rank(), mpiHelper.size()); std::cout << "DUMMY (" << mpiHelper.rank() << "): Running solver dummy with preCICE config file \"" << preciceConfigFilename << "\", participant name \"" << solverName << "\", and mesh name \"" << meshName << "\".\n"; - const int dimensions = couplingInterface.getDimensions(); + const int dimensions = couplingParticipant.getMeshDimensions(meshName); assert(dimensions == 3); const std::string scalarDataWriteName = (solverName == "SolverOne") ? "scalarDataOne" : "scalarDataTwo"; const std::string scalarDataReadName = (solverName == "SolverOne") ? "scalarDataTwo" : "scalarDataOne"; - const std::string vectorDataWriteName = (solverName == "SolverOne") ? "vectorDataOne" : "vectorDataTwo"; const std::string vectorDataReadName = @@ -68,9 +65,11 @@ try { const int numberOfVertices = 3; std::vector writeScalarData(numberOfVertices); + std::vector readScalarData(numberOfVertices); std::vector writeVectorData(numberOfVertices * dimensions); - std::vector vertices(numberOfVertices * dimensions); - std::vector preciceVertexIDs(numberOfVertices); + std::vector readVectorData(numberOfVertices * dimensions); + + std::vector vertices(numberOfVertices * dimensions); // coordinates std::vector dumuxVertexIDs(numberOfVertices); for (int i = 0; i < numberOfVertices; i++) { @@ -84,50 +83,44 @@ try { std::cout << "DUMMY (" << mpiHelper.rank() << "): Initialize preCICE and set mesh\n"; - double preciceDt = couplingInterface.setMeshAndInitialize( - meshName, numberOfVertices, vertices); + couplingParticipant.setMesh(meshName, vertices); // Create index mapping between DuMuX's index numbering and preCICE's numbering std::cout << "DUMMY (" << mpiHelper.rank() << "): Create index mapping\n"; - couplingInterface.createIndexMapping(dumuxVertexIDs); - - const int readScalarDataID = - couplingInterface.announceScalarQuantity(scalarDataReadName); - const int writeScalarDataID = - couplingInterface.announceScalarQuantity(scalarDataWriteName); - const int readVectorDataID = - couplingInterface.announceVectorQuantity(vectorDataReadName); - const int writeVectorDataID = - couplingInterface.announceVectorQuantity(vectorDataWriteName); - - if (couplingInterface.hasToWriteInitialData()) { + couplingParticipant.createIndexMapping(dumuxVertexIDs); + + couplingParticipant.announceQuantity(meshName, scalarDataWriteName); + couplingParticipant.announceQuantity(meshName, scalarDataReadName); + couplingParticipant.announceQuantity(meshName, vectorDataWriteName); + couplingParticipant.announceQuantity(meshName, vectorDataReadName); + + if (couplingParticipant.requiresToWriteInitialData()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Writing initial data\n"; - // Scalar data - couplingInterface.writeQuantityVector(writeScalarDataID, - writeScalarData); - couplingInterface.writeScalarQuantityToOtherSolver(writeScalarDataID); - // Vector data - couplingInterface.writeQuantityVector(writeVectorDataID, - writeVectorData); - couplingInterface.writeQuantityToOtherSolver( - writeVectorDataID, Dumux::Precice::QuantityType::Vector); - couplingInterface.announceInitialDataWritten(); + couplingParticipant.writeQuantityVector(meshName, scalarDataWriteName, + writeScalarData); + couplingParticipant.writeQuantityToOtherSolver(meshName, + scalarDataWriteName); + couplingParticipant.writeQuantityVector(meshName, vectorDataWriteName, + writeVectorData); + couplingParticipant.writeQuantityToOtherSolver(meshName, + vectorDataWriteName); } std::cout << "DUMMY (" << mpiHelper.rank() << "): Exchange initial\n"; - couplingInterface.initializeData(); + couplingParticipant.initialize(); + double preciceDt = 0; // Check exchanged initial data if (solverName == "SolverOne") { std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading initial data\n"; - couplingInterface.readQuantityFromOtherSolver( - readScalarDataID, Dumux::Precice::QuantityType::Scalar); - couplingInterface.readQuantityFromOtherSolver( - readVectorDataID, Dumux::Precice::QuantityType::Vector); + couplingParticipant.readQuantityFromOtherSolver( + meshName, scalarDataReadName, preciceDt); + couplingParticipant.readQuantityFromOtherSolver( + meshName, vectorDataReadName, preciceDt); const std::vector &readScalarQuantity = - couplingInterface.getQuantityVector(readScalarDataID); + couplingParticipant.getQuantityVector(meshName, scalarDataReadName); std::cout << "DUMMY (" << mpiHelper.rank() << "): Scalar data\n"; for (const double &value : readScalarQuantity) @@ -135,7 +128,7 @@ try { std::cout << "\n"; const std::vector &readVectorQuantity = - couplingInterface.getQuantityVector(readVectorDataID); + couplingParticipant.getQuantityVector(meshName, vectorDataReadName); std::cout << "DUMMY (" << mpiHelper.rank() << "): Vector data\n"; for (const double &value : readVectorQuantity) @@ -170,28 +163,29 @@ try { int iter = 0; - while (couplingInterface.isCouplingOngoing()) { - if (couplingInterface.hasToWriteIterationCheckpoint()) { + while (couplingParticipant.isCouplingOngoing()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Writing iteration checkpoint\n"; - couplingInterface.announceIterationCheckpointWritten(); } //Read data std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading data\n"; - couplingInterface.readQuantityFromOtherSolver( - readScalarDataID, Dumux::Precice::QuantityType::Scalar); - couplingInterface.readQuantityFromOtherSolver( - readVectorDataID, Dumux::Precice::QuantityType::Vector); + couplingParticipant.readQuantityFromOtherSolver( + meshName, scalarDataReadName, preciceDt); + couplingParticipant.readQuantityFromOtherSolver( + meshName, vectorDataReadName, preciceDt); // Check data if (iter > 0) { int offset = (solverName == "SolverOne") ? 0 : 1; - const std::vector &readScalarQuantity = - couplingInterface.getQuantityVector(readScalarDataID); + const std::vector &readScalarQuantity = + couplingParticipant.getQuantityVector(meshName, + scalarDataReadName); const std::vector &readVectorQuantity = - couplingInterface.getQuantityVector(readVectorDataID); + couplingParticipant.getQuantityVector(meshName, + vectorDataReadName); for (int i = 0; i < numberOfVertices; i++) { if (readScalarQuantity.at(i) != @@ -236,24 +230,23 @@ try { // Write scalar data via DuMuX ID <-> preCICE ID mapping for (int i = 0; i < numberOfVertices; i++) { const double value = i + iter; - couplingInterface.writeScalarQuantityOnFace( - writeScalarDataID, dumuxVertexIDs[i], value); + couplingParticipant.writeScalarQuantityOnFace( + meshName, scalarDataWriteName, dumuxVertexIDs[i], value); } - couplingInterface.writeQuantityToOtherSolver( - writeScalarDataID, Dumux::Precice::QuantityType::Scalar); + couplingParticipant.writeQuantityToOtherSolver(meshName, + scalarDataWriteName); // Write vector data - couplingInterface.writeQuantityVector(writeVectorDataID, - writeVectorData); - couplingInterface.writeQuantityToOtherSolver( - writeVectorDataID, Dumux::Precice::QuantityType::Vector); - - preciceDt = couplingInterface.advance(preciceDt); - - if (couplingInterface.hasToReadIterationCheckpoint()) { + couplingParticipant.writeQuantityVector(meshName, vectorDataWriteName, + writeVectorData); + couplingParticipant.writeQuantityToOtherSolver(meshName, + vectorDataWriteName); + preciceDt = couplingParticipant.getMaxTimeStepSize(); + couplingParticipant.advance(preciceDt); + + if (couplingParticipant.requiresToReadCheckpoint()) { std::cout << "DUMMY (" << mpiHelper.rank() << "): Reading iteration checkpoint\n"; - couplingInterface.announceIterationCheckpointRead(); } else { std::cout << "DUMMY (" << mpiHelper.rank() << "): Advancing in time\n"; @@ -263,7 +256,7 @@ try { // finalize, print dumux message to say goodbye //////////////////////////////////////////////////////////// - couplingInterface.finalize(); + couplingParticipant.finalize(); std::cout << "DUMMY (" << mpiHelper.rank() << "): Closing C++ solver dummy...\n"; @@ -275,6 +268,7 @@ try { return 0; } // end main + catch (Dumux::ParameterException &e) { std::cerr << std::endl << e << " ---> Abort!" << std::endl; return 1; diff --git a/examples/dummysolver/precice-dummy-solver-config.xml b/examples/dummysolver/precice-dummy-solver-config.xml index 4cd2a69..80379d0 100644 --- a/examples/dummysolver/precice-dummy-solver-config.xml +++ b/examples/dummysolver/precice-dummy-solver-config.xml @@ -5,62 +5,57 @@ + + - + + - - + + + - - + + + - - - + + + - - - + + + - - - + + - - - + + + + + - - + + + - - - - - + + - - - + + + + + - - - - - - - - - - + - - @@ -68,6 +63,4 @@ - - diff --git a/examples/dummysolver/test.xml b/examples/dummysolver/test.xml index 4d46857..106fae0 100644 --- a/examples/dummysolver/test.xml +++ b/examples/dummysolver/test.xml @@ -6,47 +6,43 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/ff-pm/flow-over-cube-3d/1pspatialparams.hh b/examples/ff-pm/flow-over-cube-3d/1pspatialparams.hh index ef81c28..e7855f2 100644 --- a/examples/ff-pm/flow-over-cube-3d/1pspatialparams.hh +++ b/examples/ff-pm/flow-over-cube-3d/1pspatialparams.hh @@ -24,11 +24,7 @@ #ifndef DUMUX_1P_TEST_SPATIALPARAMS_HH #define DUMUX_1P_TEST_SPATIALPARAMS_HH -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 #include -#else -#include -#endif namespace Dumux { @@ -39,30 +35,16 @@ namespace Dumux * 1p cc model */ template -class OnePSpatialParams -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 - : public FVPorousMediumFlowSpatialParamsOneP< - FVGridGeometry, - Scalar, - OnePSpatialParams> -#else - : public FVSpatialParamsOneP> -#endif +class OnePSpatialParams : public FVPorousMediumFlowSpatialParamsOneP< + FVGridGeometry, + Scalar, + OnePSpatialParams> { using GridView = typename FVGridGeometry::GridView; - using ParentType = -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 - FVPorousMediumFlowSpatialParamsOneP< - FVGridGeometry, - Scalar, - OnePSpatialParams>; -#else - FVSpatialParamsOneP>; -#endif + using ParentType = FVPorousMediumFlowSpatialParamsOneP< + FVGridGeometry, + Scalar, + OnePSpatialParams>; using Element = typename GridView::template Codim<0>::Entity; using GlobalPosition = typename Element::Geometry::GlobalCoordinate; @@ -108,7 +90,6 @@ public: return alphaBJ_; } -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR > 4 /*! * \brief Return the temperature within the domain in [K]. * @@ -118,7 +99,6 @@ public: { return 273.15 + 10; // 10°C } -#endif private: Scalar permeability_; diff --git a/examples/ff-pm/flow-over-cube-3d/CMakeLists.txt b/examples/ff-pm/flow-over-cube-3d/CMakeLists.txt index d341da6..051cfad 100644 --- a/examples/ff-pm/flow-over-cube-3d/CMakeLists.txt +++ b/examples/ff-pm/flow-over-cube-3d/CMakeLists.txt @@ -1,9 +1,6 @@ add_executable(ff_flow_over_cube_3d EXCLUDE_FROM_ALL main_ff-reversed.cc) add_executable(pm_flow_over_cube_3d EXCLUDE_FROM_ALL main_pm-reversed.cc) -target_link_libraries(ff_flow_over_cube_3d PRIVATE dumux-precice) -target_link_libraries(pm_flow_over_cube_3d PRIVATE dumux-precice) - # add a symlink for each input file add_input_file_links() # add a symlink for each preCICE configuration file @@ -19,13 +16,6 @@ dumux_add_test(NAME dummytarget_to_build_pm_flow_over_cube_3d COMMAND ${CMAKE_SOURCE_DIR}/test/return-test-passed.sh ) -#dumux_add_test(NAME dummytarget_to_build_ff_flow_over_cube_3d -# TARGET ff_flow_over_cube_3d -# LABELS freeflow stokes precice darcy 3d -# TIMEOUT 5 -# COMMAND ${CMAKE_SOURCE_DIR}/test/return-test-passed.sh -#) - dumux_add_test(NAME test_ff_pm_flow_over_cube_3d TARGET ff_flow_over_cube_3d @@ -48,4 +38,4 @@ dumux_add_test(NAME test_ff_pm_flow_over_cube_3d --zeroThreshold {"velocity_liq \(m/s\)":1e-14,"p":1e-12} ) set_tests_properties(test_ff_pm_flow_over_cube_3d PROPERTIES - ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR}/test:$ENV{PYTHONPATH}) \ No newline at end of file + ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR}/test:$ENV{PYTHONPATH}) diff --git a/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh b/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh index 9513357..cc782b6 100644 --- a/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh +++ b/examples/ff-pm/flow-over-cube-3d/ffproblem-reversed.hh @@ -25,16 +25,14 @@ #include -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 4 #include -#endif #include #include #include #include -#include +#include #include @@ -94,9 +92,9 @@ struct EnableGridVolumeVariablesCache { * \brief The free flow sub problem */ template -class StokesSubProblem : public NavierStokesProblem +class StokesSubProblem : public NavierStokesStaggeredProblem { - using ParentType = NavierStokesProblem; + using ParentType = NavierStokesStaggeredProblem; using GridGeometry = GetPropType; using GridView = typename GridGeometry::GridView; @@ -116,26 +114,17 @@ class StokesSubProblem : public NavierStokesProblem using GlobalPosition = typename Element::Geometry::GlobalCoordinate; using PrimaryVariables = GetPropType; -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 4 using NumEqVector = Dumux::NumEqVector; -#else - using NumEqVector = GetPropType; -#endif using FluidSystem = GetPropType; public: StokesSubProblem(std::shared_ptr gridGeometry) : ParentType(gridGeometry, "FreeFlow"), eps_(1e-6), - couplingInterface_(Dumux::Precice::CouplingAdapter::getInstance()), - pressureId_(0), - velocityId_(0), - dataIdsWereSet_(false) + couplingParticipant_(Dumux::Precice::CouplingAdapter::getInstance()) { deltaP_ = getParamFromGroup(this->paramGroup(), "Problem.PressureDifference"); - // pressureId_ = couplingInterface_.getIdFromName( "Pressure" ); - // velocityId_ = couplingInterface_.getIdFromName( "Velocity" ); } /*! @@ -143,15 +132,6 @@ public: */ // \{ -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR < 5 - /*! - * \brief Return the temperature within the domain in [K]. - * - * This problem assumes a temperature of 10 degrees Celsius. - */ - Scalar temperature() const { return 273.15 + 10; } // 10°C -#endif - /*! * \brief Return the sources within the domain. * @@ -188,16 +168,8 @@ public: values.setDirichlet(Indices::pressureIdx); } // coupling interface - else if (couplingInterface_.isCoupledEntity(faceId)) { - // // TODO do preCICE stuff in analogy to heat transfer - assert(dataIdsWereSet_setBeaversJoseph); - //TODO What do I want to do here? - // values.setCouplingNeumann(Indices::conti0EqIdx); - // values.setCouplingNeumann(Indices::momentumYBalanceIdx); + else if (couplingParticipant_.isCoupledEntity(faceId)) { values.setDirichlet(Indices::velocityYIdx); - - // values.setNeumann(Indices::conti0EqIdx); - // values.setNeumann(Indices::momentumYBalanceIdx); values.setBeaversJoseph(Indices::momentumXBalanceIdx); values.setBeaversJoseph(Indices::momentumZBalanceIdx); } else { @@ -222,9 +194,10 @@ public: values = initialAtPos(scvf.center()); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) { values[Indices::velocityYIdx] = - couplingInterface_.getScalarQuantityOnFace(velocityId_, faceId); + couplingParticipant_.getScalarQuantityOnFace( + "FreeFlowMesh", "Velocity", faceId); } return values; @@ -248,9 +221,8 @@ public: { NumEqVector values(0.0); - assert(dataIdsWereSet_); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) { const Scalar density = 1000; // TODO how to handle compressible fluids? values[Indices::conti0EqIdx] = density * @@ -258,8 +230,8 @@ public: scvf.directionSign(); values[Indices::momentumYBalanceIdx] = scvf.directionSign() * - (couplingInterface_.getScalarQuantityOnFace(pressureId_, - faceId) - + (couplingParticipant_.getScalarQuantityOnFace( + "FreeFlowMesh", "Pressure", faceId) - initialAtPos(scvf.center())[Indices::pressureIdx]); } return values; @@ -316,11 +288,7 @@ public: using std::sqrt; const Scalar dPdX = -deltaP_ / (this->gridGeometry().bBoxMax()[0] - this->gridGeometry().bBoxMin()[0]); -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR > 4 static const Scalar mu = FluidSystem::viscosity(273.15 + 10, 1e5); -#else - static const Scalar mu = FluidSystem::viscosity(temperature(), 1e5); -#endif static const Scalar alpha = getParam("Darcy.SpatialParams.AlphaBeaversJoseph"); static const Scalar K = @@ -358,13 +326,6 @@ public: return analyticalVelocityX_; } - void updatePreciceDataIds() - { - pressureId_ = couplingInterface_.getIdFromName("Pressure"); - velocityId_ = couplingInterface_.getIdFromName("Velocity"); - dataIdsWereSet_ = true; - } - // \} private: @@ -391,10 +352,7 @@ private: Scalar eps_; Scalar deltaP_; - Dumux::Precice::CouplingAdapter &couplingInterface_; - size_t pressureId_; - size_t velocityId_; - bool dataIdsWereSet_; + Dumux::Precice::CouplingAdapter &couplingParticipant_; mutable std::vector analyticalVelocityX_; }; diff --git a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc index 8eb87eb..8dc80e4 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_ff-reversed.cc @@ -40,13 +40,18 @@ #include #include #include -#include + +#include +#include +#include #include #include #include "ffproblem-reversed.hh" +#include "dumux-precice/couplingadapter.hh" + //TODO // Helper function to put pressure on interface @@ -89,7 +94,9 @@ template void setInterfacePressures(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const std::string meshName, + const std::string dataName) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); @@ -97,8 +104,7 @@ void setInterfacePressures(const Problem &problem, auto elemFaceVars = localView(gridVars.curGridFaceVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto pressureId = couplingInterface.getIdFromName("Pressure"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bind(element); @@ -107,13 +113,13 @@ void setInterfacePressures(const Problem &problem, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const auto p = pressureAtInterface( problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(pressureId, - scvf.index(), p); + couplingParticipant.writeScalarQuantityOnFace( + meshName, dataName, scvf.index(), p); } } } @@ -122,15 +128,16 @@ void setInterfacePressures(const Problem &problem, template void setInterfaceVelocities(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const std::string meshName, + const std::string dataName) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFaceVars = localView(gridVars.curGridFaceVars()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto velocityId = couplingInterface.getIdFromName("Velocity"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bindElement(element); @@ -138,12 +145,12 @@ void setInterfaceVelocities(const Problem &problem, elemFaceVars.bindElement(element, fvGeometry, sol); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const auto v = velocityAtInterface(elemFaceVars, scvf)[scvf.directionIndex()]; - couplingInterface.writeScalarQuantityOnFace(velocityId, - scvf.index(), v); + couplingParticipant.writeScalarQuantityOnFace( + meshName, dataName, scvf.index(), v); } } } @@ -151,6 +158,7 @@ void setInterfaceVelocities(const Problem &problem, template std::tuple writeVelocitiesOnInterfaceToFile( + const std::string &meshName, const std::string &filename, const Problem &problem, const GridVariables &gridVars, @@ -161,13 +169,13 @@ std::tuple writeVelocitiesOnInterfaceToFile( auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFaceVars = localView(gridVars.curGridFaceVars()); - const auto &couplingInterface = + const auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); std::ofstream ofs(filename + ".csv", std::ofstream::out | std::ofstream::trunc); ofs << "x,y,"; - if (couplingInterface.getDimensions() == 3) + if (couplingParticipant.getMeshDimensions(meshName) == 3) ofs << "z,"; ofs << "velocityY" << "\n"; @@ -181,9 +189,10 @@ std::tuple writeVelocitiesOnInterfaceToFile( elemFaceVars.bindElement(element, fvGeometry, sol); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingInterface.getDimensions(); ++i) { + for (int i = 0; + i < couplingParticipant.getMeshDimensions(meshName); ++i) { ofs << pos[i] << ","; } const double v = problem.dirichlet(element, scvf)[1]; @@ -209,7 +218,8 @@ template -void writePressuresOnInterfaceToFile(const std::string &filename, +void writePressuresOnInterfaceToFile(const std::string &meshName, + const std::string &filename, const Problem &problem, const GridVariables &gridVars, const SolutionVector &sol) @@ -220,13 +230,13 @@ void writePressuresOnInterfaceToFile(const std::string &filename, auto elemFaceVars = localView(gridVars.curGridFaceVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - const auto &couplingInterface = + const auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); std::ofstream ofs(filename + ".csv", std::ofstream::out | std::ofstream::trunc); ofs << "x,y,"; - if (couplingInterface.getDimensions() == 3) + if (couplingParticipant.getMeshDimensions(meshName) == 3) ofs << "z,"; ofs << "pressure" << "\n"; @@ -237,9 +247,10 @@ void writePressuresOnInterfaceToFile(const std::string &filename, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingInterface.getDimensions(); ++i) { + for (int i = 0; + i < couplingParticipant.getMeshDimensions(meshName); ++i) { ofs << pos[i] << ","; } const double p = pressureAtInterface( @@ -284,11 +295,7 @@ try { GetPropType; auto freeFlowGridGeometry = std::make_shared(freeFlowGridView); -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 freeFlowGridGeometry->update(freeFlowGridManager.grid().leafGridView()); -#else - freeFlowGridGeometry->update(); -#endif // the problem (initial and boundary conditions) using FreeFlowProblem = GetPropType; @@ -306,18 +313,19 @@ try { // - Name of solver // - What rank of how many ranks this instance is // Configure preCICE. For now the config file is hardcoded. - //couplingInterface.createInstance( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); + //couplingParticipant.createInstance( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); std::string preciceConfigFilename = "precice-config.xml"; // if (argc == 3) // preciceConfigFilename = argv[2]; if (argc > 2) preciceConfigFilename = argv[argc - 1]; - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver("FreeFlow", preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver("FreeFlow", preciceConfigFilename, + mpiHelper.rank(), mpiHelper.size()); - const int dim = couplingInterface.getDimensions(); + const std::string meshName("FreeFlowMesh"); + const int dim = couplingParticipant.getMeshDimensions(meshName); std::cout << dim << " " << int(FreeFlowGridGeometry::GridView::dimension) << std::endl; if (dim != int(FreeFlowGridGeometry::GridView::dimension)) @@ -348,17 +356,13 @@ try { } } - const auto numberOfPoints = coords.size() / dim; - const double preciceDt = couplingInterface.setMeshAndInitialize( - "FreeFlowMesh", numberOfPoints, coords); - couplingInterface.createIndexMapping(coupledScvfIndices); - - const auto velocityId = - couplingInterface.announceScalarQuantity("Velocity"); - const auto pressureId = - couplingInterface.announceScalarQuantity("Pressure"); + couplingParticipant.setMesh(meshName, coords); + couplingParticipant.createIndexMapping(coupledScvfIndices); - freeFlowProblem->updatePreciceDataIds(); + const std::string dataNameV("Velocity"); + const std::string dataNameP("Pressure"); + couplingParticipant.announceQuantity(meshName, dataNameV); + couplingParticipant.announceQuantity(meshName, dataNameP); // apply initial solution for instationary problems freeFlowProblem->applyInitialSolution(sol); @@ -382,24 +386,12 @@ try { using FluxVariables = GetPropType; - if (couplingInterface.hasToWriteInitialData()) { - //TODO - // couplingInterface.writeQuantityVector( pressureId ); - - setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol); - //For testing - // { - // std::cout << "Pressures to be sent to pm" << std::endl; - // const auto p = couplingInterface.getQuantityVector( pressureId ); - // for (size_t i = 0; i < p.size(); ++i) { - // std::cout << "p[" << i << "]=" <( + *freeFlowProblem, *freeFlowGridVariables, sol, meshName, dataNameP); + couplingParticipant.writeQuantityToOtherSolver(meshName, dataNameP); } - couplingInterface.initializeData(); + couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = @@ -408,62 +400,47 @@ try { freeFlowProblem, freeFlowGridGeometry, freeFlowGridVariables); // the linear solver - using LinearSolver = UMFPackBackend; + using LinearSolver = + UMFPackIstlSolver>; auto linearSolver = std::make_shared(); // the non-linear solver using NewtonSolver = NewtonSolver; NewtonSolver nonLinearSolver(assembler, linearSolver); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); auto dt = preciceDt; auto sol_checkpoint = sol; double vtkTime = 1.0; size_t iter = 0; - while (couplingInterface.isCouplingOngoing()) { - if (couplingInterface.hasToWriteIterationCheckpoint()) { + while (couplingParticipant.isCouplingOngoing()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; - couplingInterface.announceIterationCheckpointWritten(); } - // TODO - couplingInterface.readScalarQuantityFromOtherSolver(velocityId); - // // For testing - // { - // const auto v = couplingInterface.getQuantityVector( velocityId ); - // const double sum = std::accumulate( v.begin(), v.end(), 0. ); - // std::cout << "Sum of velocities over boundary to pm: \n" << sum << std::endl; - // } - + couplingParticipant.readQuantityFromOtherSolver(meshName, dataNameV, + dt); // solve the non-linear system nonLinearSolver.solve(sol); // TODO - setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol); - // For testing - // { - // const auto p = couplingInterface.getQuantityVector( pressureId ); - // const double sum = std::accumulate( p.begin(), p.end(), 0. ); - // std::cout << "Pressures to be sent to pm" << std::endl; - //// for (size_t i = 0; i < p.size(); ++i) { - //// std::cout << "p[" << i << "]=" << p[i] << std::endl; - //// } - // std::cout << "Sum of pressures over boundary to pm: \n" << sum << std::endl; - // } - couplingInterface.writeScalarQuantityToOtherSolver(pressureId); - + setInterfacePressures( + *freeFlowProblem, *freeFlowGridVariables, sol, meshName, dataNameP); + couplingParticipant.writeQuantityToOtherSolver(meshName, dataNameP); //Read checkpoint freeFlowVtkWriter.write(vtkTime); vtkTime += 1.; - const double preciceDt = couplingInterface.advance(dt); + couplingParticipant.advance(dt); + preciceDt = couplingParticipant.getMaxTimeStepSize(); dt = std::min(preciceDt, dt); ++iter; - if (couplingInterface.hasToReadIterationCheckpoint()) { + if (couplingParticipant.requiresToReadCheckpoint()) { // //Read checkpoint // freeFlowVtkWriter.write(vtkTime); // vtkTime += 1.; @@ -471,7 +448,6 @@ try { freeFlowGridVariables->update(sol); freeFlowGridVariables->advanceTimeStep(); //freeFlowGridVariables->init(sol); - couplingInterface.announceIterationCheckpointRead(); } else // coupling successful { // write vtk output @@ -482,7 +458,7 @@ try { // finalize, print dumux message to say goodbye //////////////////////////////////////////////////////////// - couplingInterface.finalize(); + couplingParticipant.finalize(); // print dumux end message if (mpiHelper.rank() == 0) { diff --git a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc index 378ca1e..55e0092 100644 --- a/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc +++ b/examples/ff-pm/flow-over-cube-3d/main_pm-reversed.cc @@ -42,7 +42,10 @@ bool printstuff = false; #include #include -#include +#include +#include +#include + #include #include @@ -55,6 +58,8 @@ bool printstuff = false; #include "pmproblem-reversed.hh" +#include "dumux-precice/couplingadapter.hh" + /*! * \brief Returns the pressure at the interface using Darcy's law for reconstruction */ @@ -105,15 +110,16 @@ auto pressureAtInterface(const Problem &problem, template void setInterfacePressures(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const std::string meshName, + const std::string dataName) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto pressureId = couplingInterface.getIdFromName("Pressure"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bindElement(element); @@ -121,13 +127,13 @@ void setInterfacePressures(const Problem &problem, //sstd::cout << "Pressure by reconstruction" << std::endl; for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const double p = pressureAtInterface(problem, element, gridGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(pressureId, - scvf.index(), p); + couplingParticipant.writeScalarQuantityOnFace( + meshName, dataName, scvf.index(), p); } } } @@ -168,15 +174,16 @@ template void setInterfaceVelocities(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const std::string meshName, + const std::string dataName) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto velocityId = couplingInterface.getIdFromName("Velocity"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bind(element); @@ -184,13 +191,13 @@ void setInterfaceVelocities(const Problem &problem, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const double v = velocityAtInterface( problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(velocityId, - scvf.index(), v); + couplingParticipant.writeScalarQuantityOnFace( + meshName, dataName, scvf.index(), v); } } } @@ -201,6 +208,7 @@ template std::tuple writeVelocitiesOnInterfaceToFile( + const std::string &meshName, const std::string &filename, const Problem &problem, const GridVariables &gridVars, @@ -211,13 +219,13 @@ std::tuple writeVelocitiesOnInterfaceToFile( auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - const auto &couplingInterface = + const auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); std::ofstream ofs(filename + ".csv", std::ofstream::out | std::ofstream::trunc); ofs << "x,y,"; - if (couplingInterface.getDimensions() == 3) + if (couplingParticipant.getMeshDimensions(meshName) == 3) ofs << "z,"; ofs << "velocityY" << "\n"; @@ -231,9 +239,10 @@ std::tuple writeVelocitiesOnInterfaceToFile( elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingInterface.getDimensions(); ++i) { + for (int i = 0; + i < couplingParticipant.getMeshDimensions(meshName); ++i) { ofs << pos[i] << ","; } const double v = velocityAtInterface( @@ -256,7 +265,8 @@ std::tuple writeVelocitiesOnInterfaceToFile( } template -void writePressuresOnInterfaceToFile(const std::string &filename, +void writePressuresOnInterfaceToFile(const std::string &meshName, + const std::string &filename, const Problem &problem, const GridVariables &gridVars, const SolutionVector &sol) @@ -266,13 +276,13 @@ void writePressuresOnInterfaceToFile(const std::string &filename, auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - const auto &couplingInterface = + const auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); std::ofstream ofs(filename + ".csv", std::ofstream::out | std::ofstream::trunc); ofs << "x,y,"; - if (couplingInterface.getDimensions() == 3) + if (couplingParticipant.getMeshDimensions(meshName) == 3) ofs << "z,"; ofs << "pressure" << "\n"; @@ -282,9 +292,10 @@ void writePressuresOnInterfaceToFile(const std::string &filename, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { const auto &pos = scvf.center(); - for (int i = 0; i < couplingInterface.getDimensions(); ++i) { + for (int i = 0; + i < couplingParticipant.getMeshDimensions(meshName); ++i) { ofs << pos[i] << ","; } const double p = @@ -326,11 +337,7 @@ try { using DarcyGridGeometry = GetPropType; auto darcyGridGeometry = std::make_shared(darcyGridView); -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 darcyGridGeometry->update(darcyGridManager.grid().leafGridView()); -#else - darcyGridGeometry->update(); -#endif using DarcyProblem = GetPropType; auto darcyProblem = std::make_shared(darcyGridGeometry); @@ -343,18 +350,19 @@ try { // - Name of solver // - What rank of how many ranks this instance is // Configure preCICE. For now the config file is hardcoded. - //couplingInterface.createInstance( "darcy", mpiHelper.rank(), mpiHelper.size() ); + //couplingParticipant.createInstance( "darcy", mpiHelper.rank(), mpiHelper.size() ); std::string preciceConfigFilename = "precice-config.xml"; // if (argc == 3) // preciceConfigFilename = argv[2]; if (argc > 2) preciceConfigFilename = argv[argc - 1]; - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver("Darcy", preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver("Darcy", preciceConfigFilename, + mpiHelper.rank(), mpiHelper.size()); - const int dim = couplingInterface.getDimensions(); + const std::string meshName("DarcyMesh"); + const int dim = couplingParticipant.getMeshDimensions(meshName); std::cout << dim << " " << int(DarcyGridGeometry::GridView::dimension) << std::endl; if (dim != int(DarcyGridGeometry::GridView::dimension)) @@ -385,17 +393,13 @@ try { } } - const auto numberOfPoints = coords.size() / dim; - const double preciceDt = couplingInterface.setMeshAndInitialize( - "DarcyMesh", numberOfPoints, coords); - couplingInterface.createIndexMapping(coupledScvfIndices); + couplingParticipant.setMesh(meshName, coords); + couplingParticipant.createIndexMapping(coupledScvfIndices); - const auto velocityId = - couplingInterface.announceScalarQuantity("Velocity"); - const auto pressureId = - couplingInterface.announceScalarQuantity("Pressure"); - - darcyProblem->updatePreciceDataIds(); + const std::string dataNameV("Velocity"); + const std::string dataNameP("Pressure"); + couplingParticipant.announceQuantity(meshName, dataNameP); + couplingParticipant.announceQuantity(meshName, dataNameV); darcyProblem->applyInitialSolution(sol); @@ -422,26 +426,13 @@ try { darcyVtkWriter.write(0.0); using FluxVariables = GetPropType; - if (couplingInterface.hasToWriteInitialData()) { + if (couplingParticipant.requiresToWriteInitialData()) { //TODO - //couplingInterface.writeQuantityVector(velocityId); - setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol); - // For testing - { - const auto v = couplingInterface.getQuantityVector(velocityId); - std::cout << "velocities to be sent to ff" << std::endl; - for (size_t i = 0; i < v.size(); ++i) { - for (size_t d = 0; d < dim; ++d) { - std::cout << coords[i * dim + d] << " "; - } - std::cout << "| v[" << i << "]=" << v[i] << std::endl; - } - } - couplingInterface.writeScalarQuantityToOtherSolver(velocityId); - couplingInterface.announceInitialDataWritten(); + setInterfaceVelocities( + *darcyProblem, *darcyGridVariables, sol, meshName, dataNameV); + couplingParticipant.writeQuantityToOtherSolver(meshName, dataNameV); } - couplingInterface.initializeData(); + couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = FVAssembler; @@ -449,84 +440,50 @@ try { darcyProblem, darcyGridGeometry, darcyGridVariables); // the linear solver - using LinearSolver = UMFPackBackend; + using LinearSolver = + UMFPackIstlSolver>; auto linearSolver = std::make_shared(); // the non-linear solver using NewtonSolver = Dumux::NewtonSolver; NewtonSolver nonLinearSolver(assembler, linearSolver); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); auto dt = preciceDt; auto sol_checkpoint = sol; double vtkTime = 1.0; size_t iter = 0; - while (couplingInterface.isCouplingOngoing()) { - if (couplingInterface.hasToWriteIterationCheckpoint()) { + while (couplingParticipant.isCouplingOngoing()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; - couplingInterface.announceIterationCheckpointWritten(); } - // TODO - couplingInterface.readScalarQuantityFromOtherSolver(pressureId); - // For testing - { - const auto p = couplingInterface.getQuantityVector(pressureId); - for (size_t i = 0; i < p.size(); ++i) { - for (size_t d = 0; d < dim; ++d) { - std::cout << coords[i * dim + d] << " "; - } - std::cout << "| p[" << i << "]=" << p[i] << std::endl; - } - const double sum = std::accumulate(p.begin(), p.end(), 0.); - std::cout << "Sum of pressures over boundary to ff: \n" - << sum << std::endl; - std::cout << "Pressure received from ff" << std::endl; - // for (size_t i = 0; i < p.size(); ++i) { - // std::cout << "p[" << i << "]=" << p[i] << std::endl; - // } - } + couplingParticipant.readQuantityFromOtherSolver(meshName, dataNameP, + dt); // solve the non-linear system nonLinearSolver.solve(sol); - setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol); - // For testing - { - const auto v = couplingInterface.getQuantityVector(velocityId); - for (size_t i = 0; i < v.size(); ++i) { - for (size_t d = 0; d < dim; ++d) { - std::cout << coords[i * dim + d] << " "; - } - std::cout << "| v[" << i << "]=" << v[i] << std::endl; - } - - const double sum = std::accumulate(v.begin(), v.end(), 0.); - std::cout << "Velocities to be sent to ff" << std::endl; - // for (size_t i = 0; i < v.size(); ++i) { - // std::cout << "v[" << i << "]=" << v[i] << std::endl; - // } - std::cout << "Sum of velocities over boundary to ff: \n" - << sum << std::endl; - } - couplingInterface.writeScalarQuantityToOtherSolver(velocityId); + setInterfaceVelocities( + *darcyProblem, *darcyGridVariables, sol, meshName, dataNameV); + couplingParticipant.writeQuantityToOtherSolver(meshName, dataNameV); - const double preciceDt = couplingInterface.advance(dt); + couplingParticipant.advance(dt); + preciceDt = couplingParticipant.getMaxTimeStepSize(); dt = std::min(preciceDt, dt); ++iter; - if (couplingInterface.hasToReadIterationCheckpoint()) { + if (couplingParticipant.requiresToReadCheckpoint()) { //Read checkpoint darcyVtkWriter.write(vtkTime); vtkTime += 1.; sol = sol_checkpoint; darcyGridVariables->update(sol); darcyGridVariables->advanceTimeStep(); - //darcyGridVariables->init(sol); - couplingInterface.announceIterationCheckpointRead(); } else // coupling successful { // write vtk output @@ -536,7 +493,7 @@ try { // write vtk output darcyVtkWriter.write(1.0); - couplingInterface.finalize(); + couplingParticipant.finalize(); //////////////////////////////////////////////////////////// // finalize, print dumux message to say goodbye diff --git a/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh b/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh index c28ecc7..e4e1c5a 100644 --- a/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh +++ b/examples/ff-pm/flow-over-cube-3d/pmproblem-reversed.hh @@ -26,9 +26,7 @@ #include -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 4 #include -#endif #include @@ -97,11 +95,7 @@ class DarcySubProblem : public PorousMediumFlowProblem typename GetPropType::GridView; using Scalar = GetPropType; using PrimaryVariables = GetPropType; -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 4 using NumEqVector = Dumux::NumEqVector; -#else - using NumEqVector = GetPropType; -#endif using BoundaryTypes = Dumux::BoundaryTypes< GetPropType::numEq()>; using VolumeVariables = GetPropType; @@ -122,10 +116,7 @@ public: DarcySubProblem(std::shared_ptr fvGridGeometry) : ParentType(fvGridGeometry, "Darcy"), eps_(1e-7), - couplingInterface_(Dumux::Precice::CouplingAdapter::getInstance()), - pressureId_(0), - velocityId_(0), - dataIdsWereSet_(false) + couplingParticipant_(Dumux::Precice::CouplingAdapter::getInstance()) { } @@ -134,15 +125,6 @@ public: */ // \{ -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR < 5 - /*! - * \brief Return the temperature within the domain in [K]. - * - */ - Scalar temperature() const { return 273.15 + 10; } // 10°C - // \} -#endif - /*! * \name Boundary conditions */ @@ -164,7 +146,7 @@ public: values.setAllNeumann(); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) + if (couplingParticipant_.isCoupledEntity(faceId)) values.setAllDirichlet(); return values; } @@ -185,9 +167,9 @@ public: values = initial(element); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) - values = - couplingInterface_.getScalarQuantityOnFace(pressureId_, faceId); + if (couplingParticipant_.isCoupledEntity(faceId)) + values = couplingParticipant_.getScalarQuantityOnFace( + "DarcyMesh", "Pressure", faceId); return values; } @@ -211,15 +193,6 @@ public: { // no-flow everywhere ... NumEqVector values(0.0); - - // assert( dataIdsWereSet_ ); - // const auto faceId = scvf.index(); - // if ( couplingInterface_.isCoupledEntity(faceId) ) - // { - // const Scalar density = 1000.; - // values[Indices::conti0EqIdx] = density * couplingInterface_.getScalarQuantityOnFace( velocityId_, faceId ); - // std::cout << "pm: values[Indices::conti0EqIdx] = " << values << std::endl; - // } return values; } @@ -276,13 +249,6 @@ public: // \} - void updatePreciceDataIds() - { - pressureId_ = couplingInterface_.getIdFromName("Pressure"); - velocityId_ = couplingInterface_.getIdFromName("Velocity"); - dataIdsWereSet_ = true; - } - private: bool onLeftBoundary_(const GlobalPosition &globalPos) const { @@ -306,10 +272,7 @@ private: Scalar eps_; - Dumux::Precice::CouplingAdapter &couplingInterface_; - size_t pressureId_; - size_t velocityId_; - bool dataIdsWereSet_; + Dumux::Precice::CouplingAdapter &couplingParticipant_; }; } // namespace Dumux diff --git a/examples/ff-pm/flow-over-cube-3d/precice-config.xml b/examples/ff-pm/flow-over-cube-3d/precice-config.xml index 6d4c872..d21621d 100644 --- a/examples/ff-pm/flow-over-cube-3d/precice-config.xml +++ b/examples/ff-pm/flow-over-cube-3d/precice-config.xml @@ -6,55 +6,53 @@ - - - + + - - - - + + + + - - - - + + + + - - - + + + - - + + - - + + + - + + - - + + + - - - + - + + + + - - - - + + + - - - - - - + + - - - - - - - - - + + + + + + + - - + diff --git a/examples/ff-pm/flow-over-square-2d/1pspatialparams.hh b/examples/ff-pm/flow-over-square-2d/1pspatialparams.hh index ef81c28..e7855f2 100644 --- a/examples/ff-pm/flow-over-square-2d/1pspatialparams.hh +++ b/examples/ff-pm/flow-over-square-2d/1pspatialparams.hh @@ -24,11 +24,7 @@ #ifndef DUMUX_1P_TEST_SPATIALPARAMS_HH #define DUMUX_1P_TEST_SPATIALPARAMS_HH -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 #include -#else -#include -#endif namespace Dumux { @@ -39,30 +35,16 @@ namespace Dumux * 1p cc model */ template -class OnePSpatialParams -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 - : public FVPorousMediumFlowSpatialParamsOneP< - FVGridGeometry, - Scalar, - OnePSpatialParams> -#else - : public FVSpatialParamsOneP> -#endif +class OnePSpatialParams : public FVPorousMediumFlowSpatialParamsOneP< + FVGridGeometry, + Scalar, + OnePSpatialParams> { using GridView = typename FVGridGeometry::GridView; - using ParentType = -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 - FVPorousMediumFlowSpatialParamsOneP< - FVGridGeometry, - Scalar, - OnePSpatialParams>; -#else - FVSpatialParamsOneP>; -#endif + using ParentType = FVPorousMediumFlowSpatialParamsOneP< + FVGridGeometry, + Scalar, + OnePSpatialParams>; using Element = typename GridView::template Codim<0>::Entity; using GlobalPosition = typename Element::Geometry::GlobalCoordinate; @@ -108,7 +90,6 @@ public: return alphaBJ_; } -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR > 4 /*! * \brief Return the temperature within the domain in [K]. * @@ -118,7 +99,6 @@ public: { return 273.15 + 10; // 10°C } -#endif private: Scalar permeability_; diff --git a/examples/ff-pm/flow-over-square-2d/CMakeLists.txt b/examples/ff-pm/flow-over-square-2d/CMakeLists.txt index 7c8db8a..8831104 100644 --- a/examples/ff-pm/flow-over-square-2d/CMakeLists.txt +++ b/examples/ff-pm/flow-over-square-2d/CMakeLists.txt @@ -1,9 +1,6 @@ add_executable(ff_flow_over_square_2d EXCLUDE_FROM_ALL main_ff.cc) add_executable(pm_flow_over_square_2d EXCLUDE_FROM_ALL main_pm.cc) -target_link_libraries(ff_flow_over_square_2d PRIVATE dumux-precice) -target_link_libraries(pm_flow_over_square_2d PRIVATE dumux-precice) - add_input_file_links() add_precice_file_links() diff --git a/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh b/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh index 5b31c62..4be7f23 100644 --- a/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh +++ b/examples/ff-pm/flow-over-square-2d/ffproblem-reversed.hh @@ -24,16 +24,15 @@ #define DUMUX_STOKES_SUBPROBLEM_HH #include -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 4 + #include -#endif #include #include #include #include -#include +#include #include @@ -93,9 +92,9 @@ struct EnableGridVolumeVariablesCache { * \brief The free flow sub problem */ template -class StokesSubProblem : public NavierStokesProblem +class StokesSubProblem : public NavierStokesStaggeredProblem { - using ParentType = NavierStokesProblem; + using ParentType = NavierStokesStaggeredProblem; using GridGeometry = GetPropType; using GridView = typename GridGeometry::GridView; @@ -116,11 +115,7 @@ class StokesSubProblem : public NavierStokesProblem using PrimaryVariables = GetPropType; -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 4 using NumEqVector = Dumux::NumEqVector; -#else - using NumEqVector = GetPropType; -#endif using FluidSystem = GetPropType; @@ -128,10 +123,7 @@ public: StokesSubProblem(std::shared_ptr gridGeometry) : ParentType(gridGeometry, "FreeFlow"), eps_(1e-6), - couplingInterface_(Dumux::Precice::CouplingAdapter::getInstance()), - pressureId_(0), - velocityId_(0), - dataIdsWereSet_(false) + couplingParticipant_(Dumux::Precice::CouplingAdapter::getInstance()) { deltaP_ = getParamFromGroup(this->paramGroup(), "Problem.PressureDifference"); @@ -142,15 +134,6 @@ public: */ // \{ -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR < 5 - /*! - * \brief Return the temperature within the domain in [K]. - * - * This problem assumes a temperature of 10 degrees Celsius. - */ - Scalar temperature() const { return 273.15 + 10; } // 10°C -#endif - /*! * \brief Return the sources within the domain. * @@ -187,9 +170,7 @@ public: values.setDirichlet(Indices::pressureIdx); } // coupling interface - else if (couplingInterface_.isCoupledEntity(faceId)) { - assert(dataIdsWereSet_); - + else if (couplingParticipant_.isCoupledEntity(faceId)) { values.setDirichlet(Indices::velocityYIdx); values.setBeaversJoseph(Indices::momentumXBalanceIdx); } else { @@ -213,9 +194,10 @@ public: values = initialAtPos(scvf.center()); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) { values[Indices::velocityYIdx] = - couplingInterface_.getScalarQuantityOnFace(velocityId_, faceId); + couplingParticipant_.getScalarQuantityOnFace( + "FreeFlowMesh", "Velocity", faceId); } return values; @@ -239,9 +221,8 @@ public: { NumEqVector values(0.0); - assert(dataIdsWereSet_); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { + if (couplingParticipant_.isCoupledEntity(faceId)) { const Scalar density = 1000; // TODO how to handle compressible fluids? values[Indices::conti0EqIdx] = density * @@ -249,8 +230,8 @@ public: scvf.directionSign(); values[Indices::momentumYBalanceIdx] = scvf.directionSign() * - (couplingInterface_.getScalarQuantityOnFace(pressureId_, - faceId) - + (couplingParticipant_.getScalarQuantityOnFace( + "FreeFlowMesh", "Pressure", faceId) - initialAtPos(scvf.center())[Indices::pressureIdx]); } return values; @@ -307,11 +288,7 @@ public: using std::sqrt; const Scalar dPdX = -deltaP_ / (this->gridGeometry().bBoxMax()[0] - this->gridGeometry().bBoxMin()[0]); -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR > 4 static const Scalar mu = FluidSystem::viscosity(273.15 + 10, 1e5); -#else - static const Scalar mu = FluidSystem::viscosity(temperature(), 1e5); -#endif static const Scalar alpha = getParam("Darcy.SpatialParams.AlphaBeaversJoseph"); static const Scalar K = @@ -349,13 +326,6 @@ public: return analyticalVelocityX_; } - void updatePreciceDataIds() - { - pressureId_ = couplingInterface_.getIdFromName("Pressure"); - velocityId_ = couplingInterface_.getIdFromName("Velocity"); - dataIdsWereSet_ = true; - } - // \} private: @@ -382,10 +352,7 @@ private: Scalar eps_; Scalar deltaP_; - Dumux::Precice::CouplingAdapter &couplingInterface_; - size_t pressureId_; - size_t velocityId_; - bool dataIdsWereSet_; + Dumux::Precice::CouplingAdapter &couplingParticipant_; mutable std::vector analyticalVelocityX_; }; diff --git a/examples/ff-pm/flow-over-square-2d/main_ff.cc b/examples/ff-pm/flow-over-square-2d/main_ff.cc index 849e631..042f21e 100644 --- a/examples/ff-pm/flow-over-square-2d/main_ff.cc +++ b/examples/ff-pm/flow-over-square-2d/main_ff.cc @@ -40,7 +40,10 @@ #include #include #include -#include + +#include +#include +#include #include #include @@ -91,7 +94,9 @@ template void setInterfacePressures(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const std::string meshName, + const std::string dataName) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); @@ -99,8 +104,7 @@ void setInterfacePressures(const Problem &problem, auto elemFaceVars = localView(gridVars.curGridFaceVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto pressureId = couplingInterface.getIdFromName("Pressure"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bind(element); @@ -109,13 +113,13 @@ void setInterfacePressures(const Problem &problem, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const auto p = pressureAtInterface( problem, element, scvf, fvGeometry, elemVolVars, elemFaceVars, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(pressureId, - scvf.index(), p); + couplingParticipant.writeScalarQuantityOnFace( + meshName, dataName, scvf.index(), p); } } } @@ -124,15 +128,16 @@ void setInterfacePressures(const Problem &problem, template void setInterfaceVelocities(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const std::string meshName, + const std::string dataName) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFaceVars = localView(gridVars.curGridFaceVars()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto velocityId = couplingInterface.getIdFromName("Velocity"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bindElement(element); @@ -140,12 +145,12 @@ void setInterfaceVelocities(const Problem &problem, elemFaceVars.bindElement(element, fvGeometry, sol); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const auto v = velocityAtInterface(elemFaceVars, scvf)[scvf.directionIndex()]; - couplingInterface.writeScalarQuantityOnFace(velocityId, - scvf.index(), v); + couplingParticipant.writeScalarQuantityOnFace( + meshName, dataName, scvf.index(), v); } } } @@ -182,11 +187,7 @@ try { GetPropType; auto freeFlowGridGeometry = std::make_shared(freeFlowGridView); -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 freeFlowGridGeometry->update(freeFlowGridManager.grid().leafGridView()); -#else - freeFlowGridGeometry->update(); -#endif // the problem (initial and boundary conditions) using FreeFlowProblem = GetPropType; @@ -204,18 +205,19 @@ try { // - Name of solver // - What rank of how many ranks this instance is // Configure preCICE. For now the config file is hardcoded. - //couplingInterface.createInstance( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); + //couplingParticipant.createInstance( "FreeFlow", mpiHelper.rank(), mpiHelper.size() ); std::string preciceConfigFilename = "precice-config.xml"; // if (argc == 3) // preciceConfigFilename = argv[2]; if (argc > 2) preciceConfigFilename = argv[argc - 1]; - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver("FreeFlow", preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver("FreeFlow", preciceConfigFilename, + mpiHelper.rank(), mpiHelper.size()); - const int dim = couplingInterface.getDimensions(); + const std::string meshName("FreeFlowMesh"); // mesh name + const int dim = couplingParticipant.getMeshDimensions(meshName); std::cout << dim << " " << int(FreeFlowGridGeometry::GridView::dimension) << std::endl; if (dim != int(FreeFlowGridGeometry::GridView::dimension)) @@ -246,17 +248,13 @@ try { } } - const auto numberOfPoints = coords.size() / dim; - const double preciceDt = couplingInterface.setMeshAndInitialize( - "FreeFlowMesh", numberOfPoints, coords); - couplingInterface.createIndexMapping(coupledScvfIndices); - - const auto velocityId = - couplingInterface.announceScalarQuantity("Velocity"); - const auto pressureId = - couplingInterface.announceScalarQuantity("Pressure"); + couplingParticipant.setMesh(meshName, coords); + couplingParticipant.createIndexMapping(coupledScvfIndices); - freeFlowProblem->updatePreciceDataIds(); + const std::string dataNameV("Velocity"); + const std::string dataNameP("Pressure"); + couplingParticipant.announceQuantity(meshName, dataNameV); + couplingParticipant.announceQuantity(meshName, dataNameP); // apply initial solution for instationary problems freeFlowProblem->applyInitialSolution(sol); @@ -280,13 +278,12 @@ try { using FluxVariables = GetPropType; - if (couplingInterface.hasToWriteInitialData()) { - setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol); - couplingInterface.writeScalarQuantityToOtherSolver(pressureId); - couplingInterface.announceInitialDataWritten(); + if (couplingParticipant.requiresToWriteInitialData()) { + setInterfacePressures( + *freeFlowProblem, *freeFlowGridVariables, sol, meshName, dataNameP); + couplingParticipant.writeQuantityToOtherSolver(meshName, dataNameP); } - couplingInterface.initializeData(); + couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = @@ -295,44 +292,47 @@ try { freeFlowProblem, freeFlowGridGeometry, freeFlowGridVariables); // the linear solver - using LinearSolver = UMFPackBackend; + using LinearSolver = + UMFPackIstlSolver>; auto linearSolver = std::make_shared(); // the non-linear solver using NewtonSolver = NewtonSolver; NewtonSolver nonLinearSolver(assembler, linearSolver); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); auto dt = preciceDt; auto sol_checkpoint = sol; double vtkTime = 1.0; size_t iter = 0; - while (couplingInterface.isCouplingOngoing()) { - if (couplingInterface.hasToWriteIterationCheckpoint()) { + while (couplingParticipant.isCouplingOngoing()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; - couplingInterface.announceIterationCheckpointWritten(); } - couplingInterface.readScalarQuantityFromOtherSolver(velocityId); + couplingParticipant.readQuantityFromOtherSolver(meshName, dataNameV, + dt); // solve the non-linear system nonLinearSolver.solve(sol); // TODO - setInterfacePressures(*freeFlowProblem, - *freeFlowGridVariables, sol); - couplingInterface.writeScalarQuantityToOtherSolver(pressureId); - + setInterfacePressures( + *freeFlowProblem, *freeFlowGridVariables, sol, meshName, dataNameP); + couplingParticipant.writeQuantityToOtherSolver(meshName, dataNameP); //Read checkpoint freeFlowVtkWriter.write(vtkTime); vtkTime += 1.; - const double preciceDt = couplingInterface.advance(dt); + couplingParticipant.advance(dt); + preciceDt = couplingParticipant.getMaxTimeStepSize(); dt = std::min(preciceDt, dt); ++iter; - if (couplingInterface.hasToReadIterationCheckpoint()) { + if (couplingParticipant.requiresToReadCheckpoint()) { // //Read checkpoint // freeFlowVtkWriter.write(vtkTime); // vtkTime += 1.; @@ -340,7 +340,6 @@ try { freeFlowGridVariables->update(sol); freeFlowGridVariables->advanceTimeStep(); //freeFlowGridVariables->init(sol); - couplingInterface.announceIterationCheckpointRead(); } else // coupling successful { // write vtk output @@ -351,7 +350,7 @@ try { // finalize, print dumux message to say goodbye //////////////////////////////////////////////////////////// - couplingInterface.finalize(); + couplingParticipant.finalize(); // print dumux end message if (mpiHelper.rank() == 0) { diff --git a/examples/ff-pm/flow-over-square-2d/main_pm.cc b/examples/ff-pm/flow-over-square-2d/main_pm.cc index 415111b..66d428e 100644 --- a/examples/ff-pm/flow-over-square-2d/main_pm.cc +++ b/examples/ff-pm/flow-over-square-2d/main_pm.cc @@ -42,7 +42,10 @@ bool printstuff = false; #include #include -#include +#include +#include +#include + #include #include @@ -107,15 +110,16 @@ auto pressureAtInterface(const Problem &problem, template void setInterfacePressures(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const std::string meshName, + const std::string dataName) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto pressureId = couplingInterface.getIdFromName("Pressure"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bindElement(element); @@ -123,13 +127,13 @@ void setInterfacePressures(const Problem &problem, //sstd::cout << "Pressure by reconstruction" << std::endl; for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const double p = pressureAtInterface(problem, element, gridGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(pressureId, - scvf.index(), p); + couplingParticipant.writeScalarQuantityOnFace( + meshName, dataName, scvf.index(), p); } } } @@ -170,15 +174,16 @@ template void setInterfaceVelocities(const Problem &problem, const GridVariables &gridVars, - const SolutionVector &sol) + const SolutionVector &sol, + const std::string meshName, + const std::string dataName) { const auto &gridGeometry = problem.gridGeometry(); auto fvGeometry = localView(gridGeometry); auto elemVolVars = localView(gridVars.curGridVolVars()); auto elemFluxVarsCache = localView(gridVars.gridFluxVarsCache()); - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - const auto velocityId = couplingInterface.getIdFromName("Velocity"); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); for (const auto &element : elements(gridGeometry.gridView())) { fvGeometry.bind(element); @@ -186,13 +191,13 @@ void setInterfaceVelocities(const Problem &problem, elemFluxVarsCache.bind(element, fvGeometry, elemVolVars); for (const auto &scvf : scvfs(fvGeometry)) { - if (couplingInterface.isCoupledEntity(scvf.index())) { + if (couplingParticipant.isCoupledEntity(scvf.index())) { //TODO: What to do here? const double v = velocityAtInterface( problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache); - couplingInterface.writeScalarQuantityOnFace(velocityId, - scvf.index(), v); + couplingParticipant.writeScalarQuantityOnFace( + meshName, dataName, scvf.index(), v); } } } @@ -226,11 +231,7 @@ try { using DarcyGridGeometry = GetPropType; auto darcyGridGeometry = std::make_shared(darcyGridView); -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 5 darcyGridGeometry->update(darcyGridManager.grid().leafGridView()); -#else - darcyGridGeometry->update(); -#endif using DarcyProblem = GetPropType; auto darcyProblem = std::make_shared(darcyGridGeometry); @@ -243,18 +244,19 @@ try { // - Name of solver // - What rank of how many ranks this instance is // Configure preCICE. For now the config file is hardcoded. - //couplingInterface.createInstance( "darcy", mpiHelper.rank(), mpiHelper.size() ); + //couplingParticipant.createInstance( "darcy", mpiHelper.rank(), mpiHelper.size() ); std::string preciceConfigFilename = "precice-config.xml"; // if (argc == 3) // preciceConfigFilename = argv[2]; if (argc > 2) preciceConfigFilename = argv[argc - 1]; - auto &couplingInterface = Dumux::Precice::CouplingAdapter::getInstance(); - couplingInterface.announceSolver("Darcy", preciceConfigFilename, - mpiHelper.rank(), mpiHelper.size()); + auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance(); + couplingParticipant.announceSolver("Darcy", preciceConfigFilename, + mpiHelper.rank(), mpiHelper.size()); - const int dim = couplingInterface.getDimensions(); + const std::string meshName("DarcyMesh"); + const int dim = couplingParticipant.getMeshDimensions(meshName); std::cout << dim << " " << int(DarcyGridGeometry::GridView::dimension) << std::endl; if (dim != int(DarcyGridGeometry::GridView::dimension)) @@ -285,17 +287,13 @@ try { } } - const auto numberOfPoints = coords.size() / dim; - const double preciceDt = couplingInterface.setMeshAndInitialize( - "DarcyMesh", numberOfPoints, coords); - couplingInterface.createIndexMapping(coupledScvfIndices); - - const auto velocityId = - couplingInterface.announceScalarQuantity("Velocity"); - const auto pressureId = - couplingInterface.announceScalarQuantity("Pressure"); + couplingParticipant.setMesh(meshName, coords); + couplingParticipant.createIndexMapping(coupledScvfIndices); - darcyProblem->updatePreciceDataIds(); + const std::string dataNameV("Velocity"); + const std::string dataNameP("Pressure"); + couplingParticipant.announceQuantity(meshName, dataNameP); + couplingParticipant.announceQuantity(meshName, dataNameV); darcyProblem->applyInitialSolution(sol); @@ -322,25 +320,13 @@ try { darcyVtkWriter.write(0.0); using FluxVariables = GetPropType; - if (couplingInterface.hasToWriteInitialData()) { + if (couplingParticipant.requiresToWriteInitialData()) { //TODO - setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol); - // For testing - // { - // const auto v = couplingInterface.getQuantityVector(velocityId); - // std::cout << "velocities to be sent to ff" << std::endl; - // for (size_t i = 0; i < v.size(); ++i) { - // for (size_t d = 0; d < dim; ++d) { - // std::cout << coords[i * dim + d] << " "; - // } - // std::cout << "| v[" << i << "]=" << v[i] << std::endl; - // } - // } - couplingInterface.writeScalarQuantityToOtherSolver(velocityId); - couplingInterface.announceInitialDataWritten(); + setInterfaceVelocities( + *darcyProblem, *darcyGridVariables, sol, meshName, dataNameV); + couplingParticipant.writeQuantityToOtherSolver(meshName, dataNameV); } - couplingInterface.initializeData(); + couplingParticipant.initialize(); // the assembler for a stationary problem using Assembler = FVAssembler; @@ -348,48 +334,50 @@ try { darcyProblem, darcyGridGeometry, darcyGridVariables); // the linear solver - using LinearSolver = UMFPackBackend; + using LinearSolver = + UMFPackIstlSolver>; auto linearSolver = std::make_shared(); // the non-linear solver using NewtonSolver = Dumux::NewtonSolver; NewtonSolver nonLinearSolver(assembler, linearSolver); + double preciceDt = couplingParticipant.getMaxTimeStepSize(); auto dt = preciceDt; auto sol_checkpoint = sol; double vtkTime = 1.0; size_t iter = 0; - while (couplingInterface.isCouplingOngoing()) { - if (couplingInterface.hasToWriteIterationCheckpoint()) { + while (couplingParticipant.isCouplingOngoing()) { + if (couplingParticipant.requiresToWriteCheckpoint()) { //DO CHECKPOINTING sol_checkpoint = sol; - couplingInterface.announceIterationCheckpointWritten(); } - couplingInterface.readScalarQuantityFromOtherSolver(pressureId); + couplingParticipant.readQuantityFromOtherSolver(meshName, dataNameP, + dt); // solve the non-linear system nonLinearSolver.solve(sol); - setInterfaceVelocities(*darcyProblem, - *darcyGridVariables, sol); - couplingInterface.writeScalarQuantityToOtherSolver(velocityId); + setInterfaceVelocities( + *darcyProblem, *darcyGridVariables, sol, meshName, dataNameV); + couplingParticipant.writeQuantityToOtherSolver(meshName, dataNameV); - const double preciceDt = couplingInterface.advance(dt); + couplingParticipant.advance(dt); + preciceDt = couplingParticipant.getMaxTimeStepSize(); dt = std::min(preciceDt, dt); ++iter; - if (couplingInterface.hasToReadIterationCheckpoint()) { + if (couplingParticipant.requiresToReadCheckpoint()) { //Read checkpoint darcyVtkWriter.write(vtkTime); vtkTime += 1.; sol = sol_checkpoint; darcyGridVariables->update(sol); darcyGridVariables->advanceTimeStep(); - //darcyGridVariables->init(sol); - couplingInterface.announceIterationCheckpointRead(); } else // coupling successful { // write vtk output @@ -399,7 +387,7 @@ try { // write vtk output darcyVtkWriter.write(1.0); - couplingInterface.finalize(); + couplingParticipant.finalize(); //////////////////////////////////////////////////////////// // finalize, print dumux message to say goodbye diff --git a/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh b/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh index 43af5d3..76bc0d3 100644 --- a/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh +++ b/examples/ff-pm/flow-over-square-2d/pmproblem-reversed.hh @@ -26,9 +26,7 @@ #include -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 4 #include -#endif #include #include @@ -96,11 +94,7 @@ class DarcySubProblem : public PorousMediumFlowProblem using Scalar = GetPropType; using PrimaryVariables = GetPropType; -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR >= 4 using NumEqVector = Dumux::NumEqVector; -#else - using NumEqVector = GetPropType; -#endif using BoundaryTypes = Dumux::BoundaryTypes< GetPropType::numEq()>; @@ -122,10 +116,7 @@ public: DarcySubProblem(std::shared_ptr fvGridGeometry) : ParentType(fvGridGeometry, "Darcy"), eps_(1e-7), - couplingInterface_(Dumux::Precice::CouplingAdapter::getInstance()), - pressureId_(0), - velocityId_(0), - dataIdsWereSet_(false) + couplingParticipant_(Dumux::Precice::CouplingAdapter::getInstance()) { } @@ -134,14 +125,6 @@ public: */ // \{ -#if DUMUX_VERSION_MAJOR >= 3 & DUMUX_VERSION_MINOR < 5 - /*! - * \brief Return the temperature within the domain in [K]. - * - */ - Scalar temperature() const { return 273.15 + 10; } // 10°C - // \} -#endif /*! * \name Boundary conditions */ @@ -163,7 +146,7 @@ public: values.setAllNeumann(); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) + if (couplingParticipant_.isCoupledEntity(faceId)) values.setAllDirichlet(); return values; } @@ -184,11 +167,9 @@ public: values = initial(element); const auto faceId = scvf.index(); - if (couplingInterface_.isCoupledEntity(faceId)) { - values = - couplingInterface_.getScalarQuantityOnFace(pressureId_, faceId); - //std::cout << "Pressure on face " << faceId << " is " << couplingInterface_.getScalarQuantityOnFace(pressureId_, faceId) << std::endl; - } + if (couplingParticipant_.isCoupledEntity(faceId)) + values = couplingParticipant_.getScalarQuantityOnFace( + "DarcyMesh", "Pressure", faceId); return values; } @@ -258,13 +239,6 @@ public: // \} - void updatePreciceDataIds() - { - pressureId_ = couplingInterface_.getIdFromName("Pressure"); - velocityId_ = couplingInterface_.getIdFromName("Velocity"); - dataIdsWereSet_ = true; - } - private: bool onLeftBoundary_(const GlobalPosition &globalPos) const { @@ -288,10 +262,7 @@ private: Scalar eps_; - Dumux::Precice::CouplingAdapter &couplingInterface_; - size_t pressureId_; - size_t velocityId_; - bool dataIdsWereSet_; + Dumux::Precice::CouplingAdapter &couplingParticipant_; }; } // namespace Dumux diff --git a/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml b/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml index d72d2ad..853e4ae 100644 --- a/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml +++ b/examples/ff-pm/flow-over-square-2d/precice-config-pi.xml @@ -6,79 +6,75 @@ - - - + + - - - - + + + + - - - - + + + + - - - + + + - - + + - - + + - + - - + + - - - + + + - + - - - - + + + + - - - + + + - - + + - - + + - + - + + + + + + + + + - - - - - - - - - - - - + diff --git a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml index ad4fa10..54197b5 100644 --- a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml +++ b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-first.xml @@ -6,78 +6,74 @@ - - - + + - - - - + + + + - - - - + + + + - - - + + + - - + + - - + + - + - - + + - - - + + + - + - - - - + + + + - - - + + + - - + + - - + + - + - + + + + + + + + - - - - - - - - - - - + diff --git a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml index 6e325f9..1d15bd7 100644 --- a/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml +++ b/examples/ff-pm/flow-over-square-2d/precice-config-si-free-flow-second.xml @@ -6,78 +6,73 @@ - + + - - + + + + - - - - + + + + - - - - + + + - - - + + - - + + - - + - + + - - + + + - - - + - + + + + - - - - + + + - - - + + - - + + - - + - + + + + + + + + - - - - - - - - - - - - - + diff --git a/scripts/format/run-clang-format.sh b/scripts/format/run-clang-format.sh index 7fdce5c..b69e41f 100755 --- a/scripts/format/run-clang-format.sh +++ b/scripts/format/run-clang-format.sh @@ -6,7 +6,7 @@ for DIRECTORY in "${DIRECTORIES[@]}"; do #echo "Check files in ${DIRECTORY}" for FILE in $(find "${DIRECTORY}" -regex '.*\.\(cc\|hh\)' ); do #echo "$FILE" - clang-format-10 --dry-run -style=file -Werror -i ${FILE} + clang-format-14 --dry-run -style=file -Werror -i ${FILE} done if [ $? -ne 0 ]; then exit $?