Skip to content
Draft
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9953198
Initial code to add micro-dumux surrogate for two-scale-heat-conduction
IshaanDesai Aug 6, 2025
0ed5449
Add mechanism to create snapshots using the Micro Manager
IshaanDesai Aug 6, 2025
3f8ffe8
Add more functionality related to creation and training of the surrogate
IshaanDesai Aug 6, 2025
65f8145
Add first working version of the complete surrogate workflow
IshaanDesai Aug 6, 2025
e4ed0db
Pass validation data to the validation of the surrogate
IshaanDesai Aug 7, 2025
79081bd
bugfixes and add runnable surrogate model
Snapex2409 Nov 7, 2025
776655a
add config for model adaptivity
Snapex2409 Nov 7, 2025
7b5c53f
Merge branch 'precice:develop' into micro-dumux-surrogate
IshaanDesai Dec 1, 2025
dae606f
update to new mm version
Snapex2409 Dec 1, 2025
2d6df8b
Merge remote-tracking branch 'origin/micro-dumux-surrogate' into micr…
Snapex2409 Dec 1, 2025
8ffbc3c
Merge branch 'develop' into micro-dumux-surrogate
IshaanDesai Dec 28, 2025
79b8c46
Add changelog entry
IshaanDesai Dec 28, 2025
53d9b2b
autopep8 formatting
IshaanDesai Dec 28, 2025
4cf8e2d
Merge branch 'develop' into micro-dumux-surrogate
IshaanDesai Jan 23, 2026
bf4cfa2
Merge branch 'develop' into micro-dumux-surrogate
IshaanDesai Jul 9, 2026
f6e6af4
Merge branch 'precice:develop' into micro-dumux-surrogate
IshaanDesai Aug 7, 2026
8ca17c8
Remove folder micro-dumux-mada because the new files are accommodated…
IshaanDesai Aug 7, 2026
770dc18
Give files appropriate names
IshaanDesai Aug 7, 2026
67f6029
Working state in folder micro-dumux-surrogate
IshaanDesai Aug 7, 2026
60f3ad2
Changing switching function file name
IshaanDesai Aug 8, 2026
0943901
Compute snapshots in parallel
IshaanDesai Aug 8, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog-entries/684.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added PCE-base surrogate for micro-dumux in two-scale heat conduction [#684](https://github.com/precice/tutorials/pull/684)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README.md file of the tutorial also needs to document this alternative and what kind of surrogate it is.

In other cases (e.g., perpendicular-flap), we had participants named -fake? Is this case doing something similar?

24 changes: 24 additions & 0 deletions two-scale-heat-conduction/micro-dumux-mada/mada_switcher.py
Comment thread
IshaanDesai marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy as np


def switching_function(resolution, location, t, input, prev_output):
result = 0
# in the beginning we only want FOM
if t == 0.0:
if resolution > 0:
result = -1
else:
result = 0
# after small init phase, we want dynamic model selection
# for test purposes we say ROM is accurate in range
else:
concentration = input['concentration']
is_valid_range = 0.45 < concentration < 0.55
is_fom = resolution == 0

if is_fom and is_valid_range:
result = 1
if not is_fom and not is_valid_range:
result = -1

return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"micro_file_name": "micro_sim",
"coupling_params": {
"participant_name": "Micro-Manager",
"precice_config_file_name": "../precice-config.xml",
"macro_mesh_name": "macro-mesh",
"write_data_names": ["k_00", "k_01", "k_10", "k_11", "porosity"],
"read_data_names": ["concentration"]
},
"simulation_params": {
"micro_dt": 0.01,
"macro_domain_bounds": [0.0, 1.0, 0.0, 0.5],
"decomposition": [1, 1],
"adaptivity": "True",
"adaptivity_settings": {
"type": "global",
"data": ["k_00", "k_11", "porosity", "concentration"],
"history_param": 0.1,
"coarsening_constant": 0.2,
"refining_constant": 0.05,
"every_implicit_iteration": "False",
"similarity_measure": "L2rel"
},
"model_adaptivity": true,
"model_adaptivity_settings": {
"micro_file_names": ["micro_sim", "micro_sim_sur"],
"data": [],
"thresholds": [1.0, 1.0],
"switching_function": "mada_switcher"
}
},
"diagnostics": {
"data_from_micro_sims": ["grain_size"]
}
}
15 changes: 15 additions & 0 deletions two-scale-heat-conduction/micro-dumux-mada/micro_sim.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
CXX=@CXX@
CC=@CC@
DEPENDENCIES=@REQUIRES@

Name: @PACKAGE_NAME@
Version: @VERSION@
Description: micro_sim module
URL: http://dune-project.org/
Requires: dumux-phasefield dumux-precice
Libs: -L${libdir}
Cflags: -I${includedir}
56 changes: 56 additions & 0 deletions two-scale-heat-conduction/micro-dumux-mada/micro_sim_sur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Micro simulation Surrogate, requrie previous computation of surrogate model
Comment thread
IshaanDesai marked this conversation as resolved.
Outdated
"""
import os
import subprocess
from bayesvalidrox import PyLinkForwardModel, Input, PCE, ExpDesigns, Engine
import h5py
import joblib
import numpy as np
import math


class MicroSimulation:

def __init__(self, sim_id):
"""
Constructor of MicroSimulation class.
"""
self._sim_id = sim_id
self._state = None

self._model = None
with open('micro-dumux-surrogate.pkl', 'rb') as input:
self._model = joblib.load(input)
if self._model is None:
raise RuntimeError("Failed to load model.")

def initialize(self):
output_data = dict()
output_data["k_00"] = 0.4912490635619572
output_data["k_11"] = 0.4912490635989945
output_data["porosity"] = 0.4933482661391027

if self._sim_id == 0:
output_data["k_00"] = 0.4912490640081466
output_data["k_11"] = 0.4912490640081367

return output_data

def get_state(self):
return self._state

def set_state(self, state):
self._state = state

def solve(self, macro_data, dt):
model_eval, _ = self._model.eval_metamodel(np.array([macro_data["concentration"]])[:, np.newaxis])
output_data = dict()
output_data["k_00"] = model_eval["k_00"][0][0]
output_data["k_01"] = model_eval["k_01"][0][0]
output_data["k_10"] = model_eval["k_10"][0][0]
output_data["k_11"] = model_eval["k_11"][0][0]
output_data["porosity"] = model_eval["porosity"][0][0]
output_data["grain_size"] = math.sqrt((1 - model_eval["porosity"][0][0]) / math.pi)

return output_data
25 changes: 25 additions & 0 deletions two-scale-heat-conduction/micro-dumux-mada/params.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[Assembly]
Multithreading = false

[TimeLoop]
TEnd = 0.25 # end time of the simulation
DtInitial = 0.01 # initial time step size
MaxTimeStepSize = 0.01 # maximal time step size

[Grid]
LowerLeft = 0.0 0.0 # lower left (front) corner of the domain (keep this fixed at 0 0!)
UpperRight = 1.0 1.0 # upper right (back) corner of the domain
Cells = 80 80 # grid resolution in each coordinate direction
Periodic = 1 1 # Periodic Boundary conditions in both dimensions

[Problem]
xi = 0.08 # phasefield parameter (lambda, set to around 4/Ncells)
omega = 0.01 # phasefield diffusivity/surface tension parameter (gamma)
kt = 1.0 # constant deciding speed of expansion/contraction
eqconc = 0.5 # equilibrium concentration
ks = 1.0 # conductivity of sand material
kg = 0.0 # conductivity of void material
Name = cell_phase # base name for VTK output files
Radius = 0.4 # initial radius of the grain
PhasefieldICScaling = 4.0 # factor in initial phasefield function
MaxPorosity = 0.9686 # porosity cap
6 changes: 6 additions & 0 deletions two-scale-heat-conduction/micro-dumux-surrogate/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
set -e -u

. ../../tools/cleaning-tools.sh

clean_dumux .
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e -u

. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

usage() { echo "Usage: cmd [-s] [-p n]" 1>&2; exit 1; }

# Check if no input argument was provided
if [ -z "$*" ] ; then
echo "No input argument provided. Micro Manager for snapshot computation is launched in serial"
micro-manager-precice --snapshot micro-manager-snapshot-config.json
fi

while getopts ":sp" opt; do
case ${opt} in
s)
micro-manager-precice --snapshot micro-manager-snapshot-config.json
;;
p)
mpiexec -n "$2" micro-manager-precice --snapshot micro-manager-snapshot-config.json
;;
*)
usage
;;
esac
done

close_log
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"micro_file_name": "micro_sim",
"coupling_params": {
"parameter_file_name": "input_samples.hdf5",
"read_data_names": ["concentration"],
"write_data_names": ["k_00", "k_01", "k_10", "k_11", "porosity"]
},
"simulation_params": {
"micro_dt": 0.01
},
"snapshot_params": {
"initialize_once": false
},
"output_directory": "output"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"micro_file_name": "micro_sim_sur",
"coupling_params": {
"participant_name": "Micro-Manager",
"precice_config_file_name": "../precice-config.xml",
"macro_mesh_name": "macro-mesh",
"write_data_names": ["k_00", "k_01", "k_10", "k_11", "porosity"],
"read_data_names": ["concentration"]
},
"simulation_params": {
"micro_dt": 0.01,
"macro_domain_bounds": [0.0, 1.0, 0.0, 0.5],
"decomposition": [1, 1],
"adaptivity": "True",
"adaptivity_settings": {
"type": "global",
"data": ["k_00", "k_11", "porosity", "concentration"],
"history_param": 0.1,
"coarsening_constant": 0.2,
"refining_constant": 0.05,
"every_implicit_iteration": "False",
"similarity_measure": "L2rel"
}
},
"diagnostics": {
"data_from_micro_sims": ["grain_size"]
}
}
15 changes: 15 additions & 0 deletions two-scale-heat-conduction/micro-dumux-surrogate/micro_sim.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
CXX=@CXX@
CC=@CC@
DEPENDENCIES=@REQUIRES@

Name: @PACKAGE_NAME@
Version: @VERSION@
Description: micro_sim module
URL: http://dune-project.org/
Requires: dumux-phasefield dumux-precice
Libs: -L${libdir}
Cflags: -I${includedir}
56 changes: 56 additions & 0 deletions two-scale-heat-conduction/micro-dumux-surrogate/micro_sim_sur.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Micro simulation Surrogate, requrie previous computation of surrogate model
"""
import os
import subprocess
from bayesvalidrox import PyLinkForwardModel, Input, PCE, ExpDesigns, Engine
import h5py
import joblib
import numpy as np
import math


class MicroSimulation:

def __init__(self, sim_id):
"""
Constructor of MicroSimulation class.
"""
self._sim_id = sim_id
self._state = None

self._model = None
with open('micro-dumux-surrogate.pkl', 'rb') as input:
self._model = joblib.load(input)
if self._model is None:
raise RuntimeError("Failed to load model.")

def initialize(self):
output_data = dict()
output_data["k_00"] = 0.4912490635619572
output_data["k_11"] = 0.4912490635989945
output_data["porosity"] = 0.4933482661391027

if self._sim_id == 0:
output_data["k_00"] = 0.4912490640081466
output_data["k_11"] = 0.4912490640081367

return output_data

def get_state(self):
return self._state

def set_state(self, state):
self._state = state

def solve(self, macro_data, dt):
model_eval, _ = self._model.eval_metamodel(np.array([macro_data["concentration"]])[:, np.newaxis])
output_data = dict()
output_data["k_00"] = model_eval["k_00"][0][0]
output_data["k_01"] = model_eval["k_01"][0][0]
output_data["k_10"] = model_eval["k_10"][0][0]
output_data["k_11"] = model_eval["k_11"][0][0]
output_data["porosity"] = model_eval["porosity"][0][0]
output_data["grain_size"] = math.sqrt((1 - model_eval["porosity"][0][0]) / math.pi)

return output_data
5 changes: 5 additions & 0 deletions two-scale-heat-conduction/micro-dumux-surrogate/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dummy model function for the micro-dumux surrogate.
# We do not wrap the original DuMuX model because we will directly provide
# snapshots (computed by the Micro Manager) to BayesValidRox.
def model(samples):
return None
25 changes: 25 additions & 0 deletions two-scale-heat-conduction/micro-dumux-surrogate/params.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[Assembly]
Multithreading = false

[TimeLoop]
TEnd = 0.25 # end time of the simulation
DtInitial = 0.01 # initial time step size
MaxTimeStepSize = 0.01 # maximal time step size

[Grid]
LowerLeft = 0.0 0.0 # lower left (front) corner of the domain (keep this fixed at 0 0!)
UpperRight = 1.0 1.0 # upper right (back) corner of the domain
Cells = 80 80 # grid resolution in each coordinate direction
Periodic = 1 1 # Periodic Boundary conditions in both dimensions

[Problem]
xi = 0.08 # phasefield parameter (lambda, set to around 4/Ncells)
omega = 0.01 # phasefield diffusivity/surface tension parameter (gamma)
kt = 1.0 # constant deciding speed of expansion/contraction
eqconc = 0.5 # equilibrium concentration
ks = 1.0 # conductivity of sand material
kg = 0.0 # conductivity of void material
Name = cell_phase # base name for VTK output files
Radius = 0.4 # initial radius of the grain
PhasefieldICScaling = 4.0 # factor in initial phasefield function
MaxPorosity = 0.9686 # porosity cap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
numpy
bayesvalidrox
micro-manager-precice

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recent update: Please also add pyprecice here, even if implied by the micro-manager-precice.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e -u

python3 -m venv .venv
. .venv/bin/activate

pip install -r requirements.txt
Comment on lines +4 to +7

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #680 for some updates (or directly copy from other run.sh in the same tutorial).


python surrogate_workflow.py
29 changes: 29 additions & 0 deletions two-scale-heat-conduction/micro-dumux-surrogate/run.sh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recent: This will need some updates regarding the venv setup. See how the other tutorials now (consistently) handle that.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -e -u

. ../../tools/log.sh
exec > >(tee --append "$LOGFILE") 2>&1

usage() { echo "Usage: cmd [-s] [-p n]" 1>&2; exit 1; }

# Check if no input argument was provided
if [ -z "$*" ] ; then
echo "No input argument provided. Micro Manager is launched in serial"
micro-manager-precice micro-manager-surrogate-config.json
fi

while getopts ":sp" opt; do
case ${opt} in
s)
micro-manager-precice micro-manager-surrogate-config.json
;;
p)
mpiexec -n "$2" micro-manager-precice micro-manager-surrogate-config.json
;;
*)
usage
;;
esac
done

close_log
Loading