diff --git a/two-scale-heat-conduction/micro-dumux/appl/micro_sim.cpp b/two-scale-heat-conduction/micro-dumux/appl/micro_sim.cpp index f29161c86..ed36b2044 100644 --- a/two-scale-heat-conduction/micro-dumux/appl/micro_sim.cpp +++ b/two-scale-heat-conduction/micro-dumux/appl/micro_sim.cpp @@ -63,8 +63,8 @@ class MicroSimulation { using SolutionVector = Dumux::GetPropType; public: - MicroSimulation(); - void initialize(); + MicroSimulation(int simulationID); + py::dict initialize(); // solve takes python dict for macro_write data, dt, and returns python dict for macro_read data py::dict solve(py::dict macro_write_data, double dt); @@ -104,7 +104,7 @@ class MicroSimulation { }; // Constructor -MicroSimulation::MicroSimulation() +MicroSimulation::MicroSimulation(int simulationID) { using namespace Dumux; @@ -180,9 +180,34 @@ MicroSimulation::MicroSimulation() _timeLoop->start(); }; -// Initialize -void MicroSimulation::initialize() +// Initialize micro-data to be used in initial adaptivity +py::dict MicroSimulation::initialize() { + //update Phi in the cell problem + _cpProblem->spatialParams().updatePhi(_phi); + + // solve the cell problems + _cpLinearPDESolver->solve(_psi); + + // calculate porosity + _porosity = _acProblem->calculatePorosity(_phi); + + //compute the psi derivatives (required for conductivity tensor) + _cpProblem->computePsiDerivatives(*_cpProblem, *_cpAssembler, *_cpGridVariables, _psi); + + //calculate the conductivity tensor + _k_00 = _cpProblem->calculateConductivityTensorComponent(0, 0); + _k_11 = _cpProblem->calculateConductivityTensorComponent(1, 1); + + // create python dict for micro_write_data + py::dict micro_write_data; + + // add micro_scalar_data and micro_vector_data to micro_write_data + micro_write_data["k_00"] = _k_00; + micro_write_data["k_11"] = _k_11; + micro_write_data["porosity"] = _porosity; + + return micro_write_data; } // Solve diff --git a/two-scale-heat-conduction/micro-nutils/micro.py b/two-scale-heat-conduction/micro-nutils/micro.py index 7097a5781..a4ab412b2 100644 --- a/two-scale-heat-conduction/micro-nutils/micro.py +++ b/two-scale-heat-conduction/micro-nutils/micro.py @@ -13,7 +13,7 @@ class MicroSimulation: - def __init__(self): + def __init__(self, sim_id): """ Constructor of MicroSimulation class. """ @@ -43,6 +43,7 @@ def __init__(self): self._initial_condition_is_set = False self._k_nm1 = None # Average effective conductivity of last time step + def initialize(self): # Define initial namespace self._ns = function.Namespace() self._ns.x = self._geom @@ -85,6 +86,17 @@ def __init__(self): self._solphi = solphi # Save solution of phi self._psi_nm1 = psi # Average porosity value of last time step + # Solve the heat cell problem + solu = self._solve_heat_cell_problem(self._topo, solphi) + k = self._get_eff_conductivity(self._topo, solu, solphi) + + output_data = dict() + output_data["k_00"] = k[0][0] + output_data["k_11"] = k[1][1] + output_data["porosity"] = psi + + return output_data + def _reinitialize_namespace(self, topo): self._ns = None # Clear old namespace self._ns = function.Namespace() @@ -112,7 +124,7 @@ def _reinitialize_namespace(self, topo): @staticmethod def _analytical_phasefield(x, y, r, lam): - return 1. / (1. + function.exp(-4. / lam * (function.sqrt(x ** 2 + y ** 2) - r + 0.001))) + return 1. / (1. + np.exp(-4. / lam * (np.sqrt(x ** 2 + y ** 2) - r + 0.001))) @staticmethod def _get_analytical_phasefield(topo, ns, degree_phi, lam, r): @@ -263,7 +275,7 @@ def solve(self, macro_data, dt): def main(): - micro_problem = MicroSimulation() + micro_problem = MicroSimulation(0) dt = 1e-3 micro_problem.initialize() concentrations = [0.5, 0.4] diff --git a/two-scale-heat-conduction/micro-nutils/run.sh b/two-scale-heat-conduction/micro-nutils/run.sh index 8edbe9445..317881929 100755 --- a/two-scale-heat-conduction/micro-nutils/run.sh +++ b/two-scale-heat-conduction/micro-nutils/run.sh @@ -10,16 +10,16 @@ pip install -r requirements.txt # Check if no input argument was provided if [ -z "$*" ] ; then echo "No input argument provided. Micro Manager is launched in serial" - python3 run-micro-problems.py + python3 run_micro_manager.py fi while getopts ":sp" opt; do case ${opt} in s) - python3 run-micro-problems.py + python3 run_micro_manager.py ;; p) - mpiexec -n "$2" python3 run-micro-problems.py + mpiexec -n "$2" python3 run_micro_manager.py ;; *) usage diff --git a/two-scale-heat-conduction/micro-nutils/run-micro-problems.py b/two-scale-heat-conduction/micro-nutils/run_micro_manager.py similarity index 100% rename from two-scale-heat-conduction/micro-nutils/run-micro-problems.py rename to two-scale-heat-conduction/micro-nutils/run_micro_manager.py