@@ -100,7 +100,8 @@ int main(int argc, char **argv)
100100
101101 auto &couplingParticipant = Dumux::Precice::CouplingAdapter::getInstance ();
102102
103- if (getParam<bool >(" Precice.RunWithCoupling" ) == true ) {
103+ const auto runWithCoupling = getParam<bool >(" Precice.RunWithCoupling" );
104+ if (runWithCoupling) {
104105 couplingParticipant.announceSolver (" macro-heat" , preciceConfigFilename,
105106 mpiHelper.rank (), mpiHelper.size ());
106107 // verify that dimensions match
@@ -138,7 +139,7 @@ int main(int argc, char **argv)
138139 // initialize preCICE
139140 auto numberOfElements =
140141 coords.size () / couplingParticipant.getMeshDimensions (meshName);
141- if (getParam< bool >( " Precice.RunWithCoupling " ) == true ) {
142+ if (runWithCoupling ) {
142143 couplingParticipant.setMesh (meshName, coords);
143144
144145 // couples between dumux element indices and preciceIndices;
@@ -154,7 +155,7 @@ int main(int argc, char **argv)
154155 const std::string writeDataConcentration = " concentration" ;
155156 // const std::string writeDataTemperature = "temperature";
156157
157- if (getParam< bool >( " Precice.RunWithCoupling " ) == true ) {
158+ if (runWithCoupling ) {
158159 couplingParticipant.announceQuantity (meshName, readDatak00);
159160 couplingParticipant.announceQuantity (meshName, readDatak01);
160161 couplingParticipant.announceQuantity (meshName, readDatak10);
@@ -181,7 +182,7 @@ int main(int argc, char **argv)
181182 temperatures.push_back (x[solIdx][problem->returnTemperatureIdx ()]);
182183 };
183184
184- if (getParam< bool >( " Precice.RunWithCoupling " ) == true ) {
185+ if (runWithCoupling ) {
185186 couplingParticipant.writeQuantityVector (meshName, writeDataConcentration,
186187 temperatures);
187188 if (couplingParticipant
@@ -233,7 +234,7 @@ int main(int argc, char **argv)
233234 double solverDt;
234235 double dt;
235236
236- if (getParam< bool >( " Precice.RunWithCoupling " ) == true ) {
237+ if (runWithCoupling ) {
237238 solverDt = getParam<Scalar>(" TimeLoop.InitialDt" );
238239 dt = std::min (preciceDt, solverDt);
239240 } else {
@@ -265,7 +266,7 @@ int main(int argc, char **argv)
265266 std::cout << " Time Loop starts" << std::endl;
266267 timeLoop->start ();
267268 do {
268- if (getParam< bool >( " Precice.RunWithCoupling " ) == true ) {
269+ if (runWithCoupling ) {
269270 if (couplingParticipant.isCouplingOngoing () == false )
270271 break ;
271272
@@ -277,11 +278,13 @@ int main(int argc, char **argv)
277278 }
278279
279280 preciceDt = couplingParticipant.getMaxTimeStepSize ();
280- solverDt = std::min (nonLinearSolver.suggestTimeStepSize (timeLoop->timeStepSize ()), timeLoop->maxTimeStepSize ());
281+ solverDt = std::min (nonLinearSolver.suggestTimeStepSize (timeLoop->timeStepSize ()),
282+ timeLoop->maxTimeStepSize ());
281283 dt = std::min (preciceDt, solverDt);
282- timeLoop->setTimeStepSize (dt);
283284
284285 // read porosity and conductivity data from other solver
286+ // TODO: data needs to be updated if Newton solver adapts time-step size
287+ // and coupling data is interpolated in time
285288 couplingParticipant.readQuantityFromOtherSolver (meshName, readDatak00,
286289 dt);
287290 couplingParticipant.readQuantityFromOtherSolver (meshName, readDatak01,
@@ -292,80 +295,71 @@ int main(int argc, char **argv)
292295 dt);
293296 couplingParticipant.readQuantityFromOtherSolver (meshName,
294297 readDataPorosity, dt);
295- // store coupling data in problem
298+ // store coupling data in spatial params, exchange with MPI
296299 problem->spatialParams ().updateCouplingData ();
297300 } else {
298301 dt = std::min (
299302 nonLinearSolver.suggestTimeStepSize (timeLoop->timeStepSize ()),
300- getParam<Scalar>(" TimeLoop.MaxDt" ));
301- timeLoop->setTimeStepSize (dt);
303+ timeLoop->maxTimeStepSize ());
302304 }
305+ // set new dt as suggested by the newton solver or by preCICE
306+ timeLoop->setTimeStepSize (dt);
303307
304- std::cout << " Solver starts" << std::endl;
308+ std::cout << " Solver starts with Target dt: " << dt << std::endl;
305309
306- std::cout << " Using dt: " << dt << std::endl;
307310 // linearize & solve
308311 nonLinearSolver.solve (x, *timeLoop);
309312 // save actual time-step size
310313 dt = timeLoop->timeStepSize ();
314+
311315 // DuMux advance + report
312316 gridVariables->advanceTimeStep ();
313317 timeLoop->advanceTimeStep ();
314318 timeLoop->reportTimeStep ();
319+ xOld = x;
320+
321+ // Vtk output
322+ // TODO: output interval doesn't work easily with subcycling
323+ n += 1 ;
324+ if (n == vtkOutputInterval) {
325+ problem->updateVtkOutput (x);
326+ vtkWriter.write (timeLoop->time ());
327+ n = 0 ;
328+ }
315329
316- for (int solIdx = 0 ; solIdx < numberOfElements; ++solIdx)
317- temperatures[solIdx] = x[solIdx][problem->returnTemperatureIdx ()];
330+ if (runWithCoupling) {
331+ // write coupling data to preCICE
332+ for (int solIdx = 0 ; solIdx < numberOfElements; ++solIdx)
333+ temperatures[solIdx] = x[solIdx][problem->returnTemperatureIdx ()];
318334
319- if (getParam<bool >(" Precice.RunWithCoupling" ) == true ) {
320335 couplingParticipant.writeQuantityVector (meshName,
321336 writeDataConcentration, temperatures);
322337 couplingParticipant.writeQuantityToOtherSolver (meshName,
323338 writeDataConcentration);
324- }
325-
326- // advance precice
327- if (getParam<bool >(" Precice.RunWithCoupling" ) == true ) {
328339
340+ // advance precice
329341 if ((!fabs (preciceDt - dt)) < 1e-14 ) {
330342 std::cout << " dt from preCICE is different than dt from DuMuX."
331343 << " preCICE dt = " << preciceDt
332- << " and DuMuX dt =" << solverDt
344+ << " and DuMuX dt = " << solverDt
333345 << " resulted in dt = " << dt
334346 << std::endl;
335347 }
348+ std::flush (std::cout);
336349 couplingParticipant.advance (dt);
337- }
338350
339- if (getParam< bool >( " Precice.RunWithCoupling " ) == true ) {
351+ // reset to checkpoint if not converged
340352 if (couplingParticipant.requiresToReadCheckpoint ()) {
341353 x = xCheckpoint;
342354 xOld = x;
343355 timeLoop->setTime (timeCheckpoint, timeStepCheckpoint);
356+ // TODO: previousTimeStep might be more appropriate, last one could be small
344357 timeLoop->setTimeStepSize (dt);
345358 gridVariables->update (x);
346359 gridVariables->advanceTimeStep ();
347- } else // coupling successful OR not at time window!!
348- {
349- xOld = x;
350- n += 1 ;
351- if (n == vtkOutputInterval) {
352- problem->updateVtkOutput (x);
353- vtkWriter.write (timeLoop->time ());
354- n = 0 ;
355- }
356- }
357- } else {
358- xOld = x;
359- // output every outputinterval steps
360- n += 1 ;
361- if (n == vtkOutputInterval) {
362- problem->updateVtkOutput (x);
363- vtkWriter.write (timeLoop->time ());
364- n = 0 ;
360+ continue ;
365361 }
366362 }
367- // set new dt as suggested by the newton solver or by preCICE
368- timeLoop->setTimeStepSize (dt);
369363
370364 std::cout << " Time: " << timeLoop->time () << std::endl;
371365
@@ -376,7 +370,7 @@ int main(int argc, char **argv)
376370 // //////////////////////////////////////////////////////////
377371 // finalize, print dumux message to say goodbye
378372 // //////////////////////////////////////////////////////////
379- if (getParam< bool >( " Precice.RunWithCoupling " ) == true ) {
373+ if (runWithCoupling ) {
380374 couplingParticipant.finalize ();
381375 }
382376 // print dumux end message
0 commit comments