-
-
Notifications
You must be signed in to change notification settings - Fork 164
Add micro-dumux-surrogate participant to two-scale heat conduction #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
9953198
0ed5449
3f8ffe8
65f8145
e4ed0db
79081bd
776655a
7b5c53f
dae606f
2d6df8b
8ffbc3c
79b8c46
53d9b2b
4cf8e2d
bf4cfa2
f6e6af4
8ca17c8
770dc18
67f6029
60f3ad2
0943901
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
| 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,22 @@ | ||
| { | ||
| "micro_file_names": ["micro_sim_sur", "micro_sim"], | ||
| "coupling_params": { | ||
| "precice_config_file_name": "../precice-config.xml", | ||
| "macro_mesh_name": "Macro-Mesh", | ||
| "write_data_names": ["K00", "K11", "Porosity"], | ||
| "read_data_names": ["Concentration"] | ||
| }, | ||
| "simulation_params": { | ||
| "micro_dt": 0.01, | ||
| "macro_domain_bounds": [0.0, 1.0, 0.0, 0.5], | ||
| "decomposition": [2, 1], | ||
| "adaptivity": false, | ||
| "model_adaptivity": true, | ||
| "model_adaptivity_settings": { | ||
| "switching_function": "switch-model" | ||
| } | ||
| }, | ||
| "diagnostics": { | ||
| "data_from_micro_sims": ["grain_size"] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "micro_file_names": ["micro_sim"], | ||
| "coupling_params": { | ||
| "parameter_file_name": "macro-concentration-samples.hdf5", | ||
| "write_data_names": ["K00", "K11", "Porosity"], | ||
| "read_data_names": ["Concentration"] | ||
| }, | ||
| "simulation_params": { | ||
| "micro_dt": 0.01 | ||
| }, | ||
| "snapshot_params": { | ||
| "output_file_name": "micro-dumux-snapshots", | ||
| "initialize_once": false | ||
| } | ||
| } |
| 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} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """ | ||
| Micro simulation Surrogate, requrie previous computation of surrogate model | ||
| """ | ||
| import joblib | ||
| import numpy as np | ||
| import math | ||
|
|
||
|
|
||
| class MicroSimulation: | ||
|
|
||
| def __init__(self, sim_id): | ||
| """ | ||
| Get the micro-scale model from the BayesValidRox surrogate model. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| sim_id : int | ||
| The simulation ID for the micro-scale simulation. | ||
| """ | ||
| 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["K00"] = 0.4912490635619572 | ||
| output_data["K11"] = 0.4912490635989945 | ||
| output_data["Porosity"] = 0.4933482661391027 | ||
|
|
||
| if self._sim_id == 0: | ||
| output_data["K00"] = 0.4912490640081466 | ||
| output_data["K11"] = 0.4912490640081367 | ||
|
|
||
| return output_data | ||
|
|
||
| def get_state(self): | ||
| """ | ||
| Get the current state of the micro-scale simulation. | ||
|
|
||
| Returns | ||
| ------- | ||
| state : dict | ||
| The current state of the micro-scale simulation. | ||
| """ | ||
| return self._state | ||
|
|
||
| def set_state(self, state): | ||
| """ | ||
| Set the current state of the micro-scale simulation. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| state : dict | ||
| The state to set for the micro-scale simulation. | ||
| """ | ||
| self._state = state | ||
|
|
||
| def solve(self, macro_data, dt): | ||
| """ | ||
| Solve the micro-scale simulation using the surrogate model. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| macro_data : dict | ||
| The macro-scale data required for the micro-scale simulation. | ||
| dt : float | ||
| The time step for the micro-scale simulation. | ||
|
|
||
| Returns | ||
| ------- | ||
| output_data : dict | ||
| The output data from the micro-scale simulation. | ||
| """ | ||
| model_eval, _ = self._model.eval_metamodel(np.array([macro_data["Concentration"]])[:, np.newaxis]) | ||
| output_data = dict() | ||
| output_data["K00"] = model_eval["K00"][0][0] | ||
| output_data["K11"] = model_eval["K11"][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 |
| 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 |
| 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,4 @@ | ||
| numpy | ||
| bayesvalidrox | ||
| pyprecice | ||
| micro-manager-precice | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recent update: Please also add |
||
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #680 for some updates (or directly copy from other |
||
|
|
||
| python surrogate_workflow.py | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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-model-switching-config.json | ||
| fi | ||
|
|
||
| while getopts ":sp" opt; do | ||
| case ${opt} in | ||
| s) | ||
| micro-manager-precice micro-manager-model-switching-config.json | ||
| ;; | ||
| p) | ||
| mpiexec -n "$2" micro-manager-precice micro-manager-model-switching-config.json | ||
| ;; | ||
| *) | ||
| usage | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| close_log |
There was a problem hiding this comment.
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?