This repository showcases two-scale coupling of DuMux simulations with preCICE, using a two-scale coupled heat conduction problem in 2D as an example. The DuMux simulations can also be coupled with their respective counterparts in Nutils.
Being an example, this repository is sensitive to versioning, so make sure to get the correct versions of the involved software packages. TLDRs might be sufficient for quick setup, but they ignore all dependencies and will almost certainly fail or create conflicts for any system without previous configuration. Consulting the full setup instructions for each software component is very much recommended.
After following the steps below, your repository structure should look like this:
|-- dumux
|-- dumux
|-- dumux-adapter
|--examples
|--macro-micro
...
|-- dumux-phasefield
|-- dune-common
|-- dune-geometry
|-- dune-grid
|-- dune-istl
|-- dune-localfunctions
|-- dune-spgridApart from DuMux and preCICE, this project relies on three other software components: the DuMux-preCICE adapter, the Micro Manager and the (currently still private) DuMuX module dumux-phasefield.
Version: develop branch
Follow the installation instructions for the Micro Manager. This also lists the necessary dependencies such as preCICE.
Note: Currently (at the time of precice-micro-manager v.0.2.1), this code relies on the develop branch, so make sure to follow the steps for manual installation and use the develop branch.
TLDR:
git clone -b develop https://github.com/precice/micro-manager
cd micro-manager
pip install --user .Version: DuMux 3.6, DUNE 2.8
Follow the installation instructions for DuMuX. Using the install script is recommended, but check that it contains the correct versions. This creates the following directory structure:
|-- dumux
|-- dumux
|-- dune-common
|-- dune-geometry
|-- dune-grid
|-- dune-istl
|-- dune-localfunctions
In the following, dumux always refers to the outer dumux folder.
TLDR:
Download the install script and run it with python installdumux.py.
Version: precice/dumux-adapter v.1.0.0
Follow the installation instructions for the DuMux adapter.
TLDR:
cd dumux
git clone -b v1.0.0 https://github.com/precice/dumux-adapter.git
./dune-common/bin/dunecontrol --only=dumux-adapter/dumux-precice allVersion: dune-spgrid 2.6, dumux-phasefield cell_problems branch
Steps to download and build the modules:
- Clone
dumux-phasefieldanddune-spgridinto the dumux folder.
cd dumux
git clone -b cell_problems https://git.iws.uni-stuttgart.de/dumux-appl/dumux-phasefield/
python3 dumux/bin/installexternal.py spgridNote: dumux-phasefield is still private!
- Clean the CMake cache.
./dune-common/bin/dunecontrol bexec rm -r CMakeFiles CMakeCache.txt- Reconfigure and build DuMux via dunecontrol.
./dune-common/bin/dunecontrol --opts=./dumux/cmake.opts allVersion: macro-micro main branch , pybind11 v2.10
- Navigate into
dumux-adapter/examples/and clone this repo.
cd dumux/dumux-adapter/examples/
git clone https://github.com/HelenaKschidock/macro-micro-
Add the line
add_subdirectory(macro-micro)todumux-adapter/examples/CMakeLists.txt. This integrates the example into the overall cmake build structure. -
Add
dumux-phasefieldtodumux-adapter/dune.moduleas a required build dependency. The line should then look like this:
# Required build dependencies
Depends: dumux (>=3.2) dumux-phasefield
- Navigate into the
micro-heatdirectory and clone and build pybind11 there. For more information, see also https://github.com/pybind/cmake_example.
cd macro-micro/micro-heat
git clone -b v2.10 https://github.com/pybind/pybind11
cd pybind11
pip install --user .- Rebuild the DuMux-preCICE adapter.
cd dumux
./dune-common/bin/dunecontrol --only=dumux-precice allTo build the macro and micro executables, simply rebuild the dumux-adapter using dunecontrol:
cd dumux
./dune-common/bin/dunecontrol --only=dumux-precice allThe executables are built into dumux/dumux-adapter/build-cmake/examples/macro-micro.
In case you want to rebuild only the macro executable, this can also be done directly via:
cd dumux/dumux-adapter/build-cmake/examples/macro-micro/macro-heat
make test_macro_heat-
Open two terminals.
-
In one of them, run the macro simulation via
cd dumux/dumux-adapter/build-cmake/examples/macro-micro/macro-heat
./test_macro_heat- In the other shell, run the micro simulation via
cd dumux/dumux-adapter/build-cmake/examples/macro-micro/micro-heat
python3 run_micro_manager.py To run the micro code in parallel, use mpirun -n <NThreads> python3 run-micro-manager.py instead. (not tested yet)
For the same problem, similar macro and micro simulations have also been implemented in Nutils, which can be coupled with their DuMux counterparts. To do so:
-
Clone the coupled-heat-conduction git into your macro-micro directory.
cd dumux-adapter/examples/macro-micro
git clone https://github.com/IshaanDesai/coupled-heat-conduction-
Add the line
add_subdirectory(coupled-heat-conduction)tomacro-micro/CMakeLists.txtto link it to CMake. -
To make the coupled-heat-conduction code available in your build directory, create a new empty
CMakeLists.txtfile within your sourcecoupled-heat-conductiondirectory and add the following code:
add_custom_target(copy_nutils_all ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})This simply copies it to the build directory and time you execute the copy_nutils_all command or anytime you rebuild the entire dumux-precice module.
- Modify the
coupled-heat-conduction/precice-config.xmlfile such that it reads
<m2n:sockets from="Micro-Manager" to="Macro-heat" network="lo" exchange-directory="../"/>This allows the macro and micro simulations to find each other.
- Rebuild the adapter.
dunecontrol --only=dumux-precice allYou can couple the Nutils simulations with each other or with their counterpart in DuMux, as long as one participant is the macro simulation and the other the micro simulation/micro manager. To do so, simply execute your chosen participants in separate shells.
- Run the Nutils macro simulation via
cd build-cmake/examples/macro-micro/coupled-heat-conduction
python3 macro-heat.py- Run the micro simulation via
cd build-cmake/examples/macro-micro/coupled-heat-conduction
python3 run-micro-manager.pyor in parallel via
mpirun -n <num_procs> python3 run-micro-manager.pyIn order to modify the simulation parameters, modify params.input.
The parameters are currently tuned to the dimensionless micro-simulation. When modifying these, note the following:
- The domain is defined by its
LowerLeftandUpperRightcorners and split into[nx ny] Cells. - Set
RunWithCouplingtofalseto run the macro simulation independently or totrueto run the coupled simulation. The independent simulation usesSolidThermalConductivityandDefaultPorosity, respectively, as its conductivity tensor and porosity. - Set
BcTypeLeft/Right/Top/Bottomtodirichletorneumann, and the corresponding value inBcLeft/Right/Top/Bottom. Note that Neumann boundary conditions are currently hardcoded to 0.0. - To run the hardcoded asymmetric case with a heat source in the bottom left, set
UseHeatSourceBottomLefttotrue, else tofalse. The corresponding value can be set viaHeatSourceBottomLeft.