Skip to content

Commit dc9752e

Browse files
authored
Add function get_global_id to micro-dumux (#756)
* Add function get_global_id to micro-dumux * Fix get_global_id function in micro-dumux and add a changelog entry
1 parent 231b05d commit dc9752e

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

changelog-entries/756.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added the function `get_global_id` to micro-dumux in the two-scale heat conduction tutorial.

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ class MicroSimulation {
6868
// solve takes python dict for macro_write data, dt, and returns python dict for macro_read data
6969
py::dict solve(py::dict macro_write_data, double dt);
7070

71-
// void save_checkpoint();
72-
// void reload_checkpoint();
73-
7471
void setState(py::tuple phi);
7572
py::tuple getState() const;
7673

74+
int get_global_id() const;
75+
7776
private:
7877
const double pi_ = 3.14159265358979323846;
7978
double _k_00;
8079
double _k_01;
8180
double _k_10;
8281
double _k_11;
8382
double _porosity;
83+
int sim_id;
8484

8585
ACSolutionVector _phi; // Solution of Allen Cahn Problem
8686
ACSolutionVector _phiOld; // for checkpointing
@@ -107,7 +107,7 @@ MicroSimulation::MicroSimulation(int simulationID)
107107
{
108108
using namespace Dumux;
109109

110-
std::cout << "Initialize micro problem \n";
110+
int sim_id = simulationID;
111111

112112
// parse the input file
113113
Parameters::init("params.input");
@@ -198,18 +198,14 @@ py::dict MicroSimulation::initialize()
198198
_k_00 = _cpProblem->calculateConductivityTensorComponent(0, 0);
199199
_k_11 = _cpProblem->calculateConductivityTensorComponent(1, 1);
200200

201-
// create python dict for micro_write_data
202201
py::dict micro_write_data;
203-
204-
// add micro_scalar_data and micro_vector_data to micro_write_data
205202
micro_write_data["K00"] = _k_00;
206203
micro_write_data["K11"] = _k_11;
207204
micro_write_data["Porosity"] = _porosity;
208205

209206
return micro_write_data;
210207
}
211208

212-
// Solve
213209
py::dict MicroSimulation::solve(py::dict macro_write_data, double dt)
214210
{
215211
// call leafgridView and point gridGeometry to it
@@ -218,15 +214,13 @@ py::dict MicroSimulation::solve(py::dict macro_write_data, double dt)
218214

219215
std::cout << "Solve timestep of micro problem \n";
220216

221-
// assert(dt != 0);
222217
if (dt == 0) {
223218
std::cout << "dt is zero\n";
224219
exit(1);
225220
}
226221

227222
_timeLoop->setTimeStepSize(dt);
228223

229-
// read concentration from preCICE
230224
double conc = macro_write_data["Concentration"].cast<double>();
231225

232226
// input macro concentration into allen-cahn problem
@@ -235,15 +229,14 @@ py::dict MicroSimulation::solve(py::dict macro_write_data, double dt)
235229
// linearize & solve the allen cahn problem
236230
_acNonLinearSolver->solve(_phi, *_timeLoop);
237231

238-
// u pdate Phi in the cell problem
232+
// update Phi in the cell problem
239233
_cpProblem->spatialParams().updatePhi(_phi);
240234

241235
// solve the cell problems
242236
_cpLinearPDESolver->solve(_psi);
243237

244238
std::cout << "Compute upscaled quantities \n";
245239

246-
// calculate porosity
247240
_porosity = _acProblem->calculatePorosity(_phi);
248241

249242
// compute the psi derivatives (required for conductivity tensor)
@@ -255,7 +248,6 @@ py::dict MicroSimulation::solve(py::dict macro_write_data, double dt)
255248
_k_01 = _cpProblem->calculateConductivityTensorComponent(0, 1);
256249
_k_11 = _cpProblem->calculateConductivityTensorComponent(1, 1);
257250

258-
// create python dict for micro_write_data
259251
py::dict micro_write_data;
260252

261253
// add micro_scalar_data and micro_vector_data to micro_write_data
@@ -273,7 +265,6 @@ py::dict MicroSimulation::solve(py::dict macro_write_data, double dt)
273265
return micro_write_data;
274266
}
275267

276-
// This function needs to set the complete state of a micro simulation
277268
void MicroSimulation::setState(py::tuple phi)
278269
{
279270
py::list phi_py = phi[0];
@@ -288,7 +279,6 @@ void MicroSimulation::setState(py::tuple phi)
288279
_acGridVariables->update(_phi);
289280
}
290281

291-
// This function needs to return variables which can fully define the state of a micro simulation
292282
py::tuple MicroSimulation::getState() const
293283
{
294284
py::list phi_py;
@@ -305,6 +295,11 @@ py::tuple MicroSimulation::getState() const
305295
return py::make_tuple(phi_py, phiOld_py);
306296
}
307297

298+
int MicroSimulation::get_global_id() const
299+
{
300+
return sim_id;
301+
}
302+
308303
PYBIND11_MODULE(micro_sim, m)
309304
{
310305
m.doc() = "pybind11 example plugin"; // optional module docstring
@@ -313,10 +308,9 @@ PYBIND11_MODULE(micro_sim, m)
313308
.def(py::init<int>())
314309
.def("initialize", &MicroSimulation::initialize)
315310
.def("solve", &MicroSimulation::solve)
316-
//.def("save_checkpoint", &MicroSimulation::save_checkpoint)
317-
//.def("reload_checkpoint", &MicroSimulation::reload_checkpoint)
318311
.def("get_state", &MicroSimulation::getState)
319312
.def("set_state", &MicroSimulation::setState)
313+
.def("get_global_id", &MicroSimulation::get_global_id)
320314
.def(py::pickle(
321315
[](const MicroSimulation &ms) { // __getstate__
322316
/* Return a tuple that fully encodes the state of the object */

0 commit comments

Comments
 (0)