Skip to content

Commit

Permalink
Add DuMuX as a participant to the two-scale-heat-conduction tutorial (#…
Browse files Browse the repository at this point in the history
…376)

* port two-scale-heat-conduction case with DuMuX-DuMuX

* Initial folder restructuring for setting up a DUNE modules environment and running the DuMuX-DuMuX case

* Removing unnecessary CMake files

* [two-scale-heat-conduction] add dune module wrapper

* [two-scale-heat-conduction] macro-dumux as dune module

* [two-scale-heat-conduction] update macro-dumux to preCICE 3.0 and DuMux 3.8

* [two-scale-heat-conduction] remove dumux subdirectory

* Remove dune-wrapper folder and restructure macro-dumux

* [two-scale-heat-conduction] revert setup script to rebuild modules in working directory

* [two-scale-heat-conduction][tmp] change branch in dumux-adapter

* [two-scale-heat-conduction] fix macro participant

* Construct mesh name macro-mesh of 10 characters

* [two-scale-heat-conduction] fixes macro-dumux

* Formatting

* Formatting and use string literals

* PEP8 formatting

* Go back to cloning the develop branch of dumux-adapter in setup-dumux.sh

* Formatting

* Remove dumux-dumux because all the code in it is now ported

* Add appropriate run scripts

* Adding correct cleaning scripts and cleaning functions

* Remove unnecessary cleaning script

* Remove all references to clean-example.sh

* [two-scale-heat-conduction] update micro-dumux for DuMux 3.7

* restructured micro-dumux, added run.sh for macro-dumux

* repair communication of concentration

* add shebang for cleaning script

* customize cleaning file in micro-dumux

* modify cleaning file to delete log file

* add dumux-dumux method in README

* Make the execution level of Nutils and DuMuX participants consistent

* Add DuMuX information to README

* Minor edit in README

* Add cleaning script to micro-dumux and add DuMuX cleaning in the tools

* add image of results for dumux-dumux simulation

* Add information on which participants can be run in parallel

* Fix linting docs

* image modified

* image resized

* [two-scale-heat-conduction] cleanup

* [two-scale-heat-conduction] add compile-dumux-cases.sh

* Swapping maintainers of macro-dumux and micro-dumux

---------

Co-authored-by: Jun Chen <[email protected]>
Co-authored-by: Ishaan Desai <[email protected]>
Co-authored-by: Mathis Kelm <[email protected]>
  • Loading branch information
4 people authored Jan 29, 2024
1 parent edd58e0 commit b1e74d7
Show file tree
Hide file tree
Showing 46 changed files with 3,385 additions and 8 deletions.
12 changes: 12 additions & 0 deletions tools/cleaning-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,15 @@ clean_dune() {
clean_precice_logs .
)
}

clean_dumux() {
(
set -e -u
cd "$1"
echo "--- Cleaning up DuMuX case in $(pwd)"
rm -fv ./*.vtu
rm -fv ./*.pvd
clean_precice_logs .
)

}
6 changes: 6 additions & 0 deletions two-scale-heat-conduction/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dumux/
dumux-phasefield/
dumux-adapter/
dune-*
*/build-cmake/
install*
33 changes: 25 additions & 8 deletions two-scale-heat-conduction/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Two-scale heat conduction
permalink: tutorials-two-scale-heat-conduction.html
keywords: Macro-micro, Micro Manager, Nutils, Heat conduction
keywords: Macro-micro, Micro Manager, Nutils, DuMuX, Heat conduction
summary: We solve a two-scale heat conduction problem with a predefined micro structure of two materials. One macro simulation is coupled to several micro simulations using the Micro Manager.
---

Expand All @@ -21,27 +21,34 @@ At each Gauss point of the macro domain there exists a micro simulation. The mac

## Available solvers and dependencies

* Both the macro and micro simulations are solved using the finite element library [Nutils](https://nutils.org/install.html) v7.
* The macro simulation is written in Python, so it requires the [Python bindings of preCICE](https://precice.org/installation-bindings-python.html)
* Both the macro and micro simulations can be solved using the finite element library [Nutils](https://nutils.org/install.html) v7 or the simulation framework [DuMu<sup>x</sup>](https://git.iws.uni-stuttgart.de/dumux-repositories/dumux/).
* While using Nutils, the macro simulation is written in Python, so it requires the [Python bindings of preCICE](https://precice.org/installation-bindings-python.html).
* The [Micro Manager](https://precice.org/tooling-micro-manager-installation.html) controls all micro-simulations and facilitates coupling via preCICE. Use the [develop](https://github.com/precice/micro-manager/tree/develop) branch of the Micro Manager.
* To solve either the macro or micro simulations with the DuMu<sup>x</sup> framework, the necessary DUNE modules need to be downloaded and set up. Run `sh setup-dumux.sh` in the tutorial folder to set up the DUNE modules.

## Running the simulation

You can find the corresponding `run.sh`script for running the case in the folders corresponding to the solvers you want to use.

Run the macro problem:

```bash
cd macro-nutils
./run.sh
```

Check the Micro Manager [configuration](https://precice.org/tooling-micro-manager-configuration.html) and [running](https://precice.org/tooling-micro-manager-running.html) documentation to understand how to set it up and launch it. There is a Python script `run-micro-problems.py` in the tutorial directory to directly run the Micro Manager. This script imports the Micro Manager, and calls its `initialize()` and `solve()` methods. The Micro Manager can be run via this script in serial or parallel. Run it in serial:
Check the Micro Manager [configuration](https://precice.org/tooling-micro-manager-configuration.html) and [running](https://precice.org/tooling-micro-manager-running.html) documentation to understand how to set it up and launch it. There is a Python script `run-micro-problems.py` in the tutorial directory to directly run the Micro Manager. This script imports the Micro Manager, and calls its `solve()` method. The Micro Manager can be run via this script in serial or parallel. Run it in serial:

```bash
cd micro-nutils
./run.sh -s
```

Run it in parallel:
If you want to use DuMu<sup>x</sup>, use `cd macro-dumux` instead of `cd macro-nutils` and/or `cd micro-dumux` instead of `cd micro-nutils`.

## Running the simulation in parallel

Only the `micro-nutils` participant can be run in parallel. To run it in parallel, run:

```bash
cd micro-nutils
Expand All @@ -50,14 +57,24 @@ cd micro-nutils

The `num_procs` needs to fit the decomposition specified in the `micro-manager-config.json` (default: two ranks).

Even though the case setup and involved physics is simple, each micro simulation is an instance of Nutils, which usually has a moderately high computation time. If the Micro Manager is run on 2 processors, the total runtime is approximately 25-30 minutes. Do not run the Micro Manager in serial, because the runtime will be several hours.
**NOTE**: When running `micro-nutils`, even though the case setup and involved physics is simple, each micro simulation is an instance of Nutils, which usually has a moderately high computation time. If the Micro Manager is run on 2 processors, the total runtime is approximately 25-30 minutes. Do not run the Micro Manager in serial, because the runtime will be several hours.

Running `micro-dumux` is much faster. A serial simulation takes approximately 2 minutes to finish.

## Post-processing

![Results of two-scale-heat-conduction case](images/tutorials-two-scale-heat-conduction-results.png)
Here are the results from Nutils-Nutils and DuMu<sup>x</sup>-DuMu<sup>x</sup> combination:

<img src="images/tutorials-two-scale-heat-conduction-results.png" alt="Macro and micro data of macro-nutils - micro-nutils simulation" width=50% height=30%>

<img src="images/tutorials-two-scale-heat-conduction-results-du-du.png" alt="Macro and micro data of macro-nutils - micro-nutils simulation" width=50% height=30%>

The differences of the fields are mainly introduced in by the different numerical schemes in the two solvers.

The participant `macro-nutils` outputs `macro-*.vtk` files which can be viewed in ParaView to see the macro concentration field. The Micro Manager uses the [export functionality](https://precice.org/configuration-export.html#enabling-exporters) of preCICE to output micro simulation data and [adaptivity related data](https://precice.org/tooling-micro-manager-configuration.html#adding-adaptivity-in-the-precice-xml-configuration) to VTU files which can be viewed in ParaView. To view the data on each micro simulation, create a Glyph on the Micro Manager VTU data. In the figure above, micro-scale porosity is shown. For a lower concentration value, the porosity increases (in the lower left corner).

![Evolving micro simulations](images/tutorials-two-scale-heat-conduction-evolving-micro-simulations.png)
<img src="images/tutorials-two-scale-heat-conduction-evolving-micro-simulations.png" alt="Adaptive mesh refinement in the micro simulation" width=50% height=30%>

The micro simulations themselves have a circular micro structure which is resolved in every time step. To output VTK files for each micro simulation, uncomment the `output()` function in the file `micro-nutils/micro.py`. The figure above shows the changing phase field used to represent the circular micro structure and the diffuse interface width.

Similar to the output data files from simulation with Nutils, the `VTU` files from macro and micro solvers, that are written in DuMu<sup>x</sup>, could also be rendered and inspected with ParaView with the mentioned method.
12 changes: 12 additions & 0 deletions two-scale-heat-conduction/compile-dumux-cases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -e -u

cd macro-dumux/build-cmake/appl
make macro_dumux
cd ../../../micro-dumux/build-cmake/appl
make
cd ../../../

# Move macro-dumux and micro-dumux executables to the participant folder level
mv macro-dumux/build-cmake/appl/macro_dumux macro-dumux/
mv micro-dumux/build-cmake/appl/micro_sim.cpython-310-x86_64-linux-gnu.so micro-dumux/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions two-scale-heat-conduction/macro-dumux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.13)
project(macro-dumux CXX)

if(NOT (dune-common_DIR OR dune-common_ROOT OR
"${CMAKE_PREFIX_PATH}" MATCHES ".*dune-common.*"))
string(REPLACE ${PROJECT_NAME} dune-common dune-common_DIR
${PROJECT_BINARY_DIR})
endif()

#find dune-common and set the module path
find_package(dune-common REQUIRED)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules"
${dune-common_MODULE_PATH})

#include the dune macros
include(DuneMacros)

# start a dune project with information from dune.module
dune_project()

dune_enable_all_packages()

add_subdirectory(doc)
add_subdirectory(cmake/modules)
add_subdirectory(appl)

# finalize the dune project, e.g. generating config.h etc.
finalize_dune_project(GENERATE_CONFIG_H_CMAKE)
7 changes: 7 additions & 0 deletions two-scale-heat-conduction/macro-dumux/appl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_executable(macro_dumux main.cc)
target_compile_definitions(macro_dumux PUBLIC "ENABLEMONOLITHIC=0")
target_link_libraries(macro_dumux PRIVATE dumux-precice)
target_compile_definitions(macro_dumux PUBLIC TYPETAG=OnePNIConductionCCTpfa)

# add a symlink for each input file
add_input_file_links()
Loading

0 comments on commit b1e74d7

Please sign in to comment.