Skip to content

Commit eb3daf5

Browse files
Several compatibility updates to the two-scale-heat-conduction tutorial (#460)
* Make Nutils micro simulation compatible with Nutils v8.5 and the latest Micro Manager * Make run scripts consistent * initialize micro-data and accept sim_id in constructor * Do not pass initial data which is not relevant for adaptivity * Formatting --------- Co-authored-by: Mathis Kelm <[email protected]>
1 parent ac3ff00 commit eb3daf5

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

two-scale-heat-conduction/micro-dumux/appl/micro_sim.cpp

+30-5
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ class MicroSimulation {
6363
using SolutionVector = Dumux::GetPropType<CellProblemTypeTag, Dumux::Properties::SolutionVector>;
6464

6565
public:
66-
MicroSimulation();
67-
void initialize();
66+
MicroSimulation(int simulationID);
67+
py::dict initialize();
6868

6969
// solve takes python dict for macro_write data, dt, and returns python dict for macro_read data
7070
py::dict solve(py::dict macro_write_data, double dt);
@@ -104,7 +104,7 @@ class MicroSimulation {
104104
};
105105

106106
// Constructor
107-
MicroSimulation::MicroSimulation()
107+
MicroSimulation::MicroSimulation(int simulationID)
108108
{
109109
using namespace Dumux;
110110

@@ -180,9 +180,34 @@ MicroSimulation::MicroSimulation()
180180
_timeLoop->start();
181181
};
182182

183-
// Initialize
184-
void MicroSimulation::initialize()
183+
// Initialize micro-data to be used in initial adaptivity
184+
py::dict MicroSimulation::initialize()
185185
{
186+
//update Phi in the cell problem
187+
_cpProblem->spatialParams().updatePhi(_phi);
188+
189+
// solve the cell problems
190+
_cpLinearPDESolver->solve(_psi);
191+
192+
// calculate porosity
193+
_porosity = _acProblem->calculatePorosity(_phi);
194+
195+
//compute the psi derivatives (required for conductivity tensor)
196+
_cpProblem->computePsiDerivatives(*_cpProblem, *_cpAssembler, *_cpGridVariables, _psi);
197+
198+
//calculate the conductivity tensor
199+
_k_00 = _cpProblem->calculateConductivityTensorComponent(0, 0);
200+
_k_11 = _cpProblem->calculateConductivityTensorComponent(1, 1);
201+
202+
// create python dict for micro_write_data
203+
py::dict micro_write_data;
204+
205+
// add micro_scalar_data and micro_vector_data to micro_write_data
206+
micro_write_data["k_00"] = _k_00;
207+
micro_write_data["k_11"] = _k_11;
208+
micro_write_data["porosity"] = _porosity;
209+
210+
return micro_write_data;
186211
}
187212

188213
// Solve

two-scale-heat-conduction/micro-nutils/micro.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class MicroSimulation:
1515

16-
def __init__(self):
16+
def __init__(self, sim_id):
1717
"""
1818
Constructor of MicroSimulation class.
1919
"""
@@ -43,6 +43,7 @@ def __init__(self):
4343
self._initial_condition_is_set = False
4444
self._k_nm1 = None # Average effective conductivity of last time step
4545

46+
def initialize(self):
4647
# Define initial namespace
4748
self._ns = function.Namespace()
4849
self._ns.x = self._geom
@@ -85,6 +86,17 @@ def __init__(self):
8586
self._solphi = solphi # Save solution of phi
8687
self._psi_nm1 = psi # Average porosity value of last time step
8788

89+
# Solve the heat cell problem
90+
solu = self._solve_heat_cell_problem(self._topo, solphi)
91+
k = self._get_eff_conductivity(self._topo, solu, solphi)
92+
93+
output_data = dict()
94+
output_data["k_00"] = k[0][0]
95+
output_data["k_11"] = k[1][1]
96+
output_data["porosity"] = psi
97+
98+
return output_data
99+
88100
def _reinitialize_namespace(self, topo):
89101
self._ns = None # Clear old namespace
90102
self._ns = function.Namespace()
@@ -112,7 +124,7 @@ def _reinitialize_namespace(self, topo):
112124

113125
@staticmethod
114126
def _analytical_phasefield(x, y, r, lam):
115-
return 1. / (1. + function.exp(-4. / lam * (function.sqrt(x ** 2 + y ** 2) - r + 0.001)))
127+
return 1. / (1. + np.exp(-4. / lam * (np.sqrt(x ** 2 + y ** 2) - r + 0.001)))
116128

117129
@staticmethod
118130
def _get_analytical_phasefield(topo, ns, degree_phi, lam, r):
@@ -263,7 +275,7 @@ def solve(self, macro_data, dt):
263275

264276

265277
def main():
266-
micro_problem = MicroSimulation()
278+
micro_problem = MicroSimulation(0)
267279
dt = 1e-3
268280
micro_problem.initialize()
269281
concentrations = [0.5, 0.4]

two-scale-heat-conduction/micro-nutils/run.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ pip install -r requirements.txt
1010
# Check if no input argument was provided
1111
if [ -z "$*" ] ; then
1212
echo "No input argument provided. Micro Manager is launched in serial"
13-
python3 run-micro-problems.py
13+
python3 run_micro_manager.py
1414
fi
1515

1616
while getopts ":sp" opt; do
1717
case ${opt} in
1818
s)
19-
python3 run-micro-problems.py
19+
python3 run_micro_manager.py
2020
;;
2121
p)
22-
mpiexec -n "$2" python3 run-micro-problems.py
22+
mpiexec -n "$2" python3 run_micro_manager.py
2323
;;
2424
*)
2525
usage

0 commit comments

Comments
 (0)