@@ -262,28 +262,29 @@ int main(int argc, char **argv)
262262
263263 // time loop
264264 int n = 0 ; // counts timesteps for the output interval
265+ const auto runWithCoupling = getParam<bool >(" Precice.RunWithCoupling" );
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
272273 // write checkpoint
273274 if (couplingParticipant.requiresToWriteCheckpoint ()) {
274- // TODO
275- // xOld = x;
276275 xCheckpoint = x;
277276 timeCheckpoint = timeLoop->time ();
278277 timeStepCheckpoint = timeLoop->timeStepIndex ();
279278 }
280279
281280 preciceDt = couplingParticipant.getMaxTimeStepSize ();
282- solverDt = std::min (nonLinearSolver.suggestTimeStepSize (timeLoop->timeStepSize ()), timeLoop->maxTimeStepSize ());
281+ solverDt = std::min (nonLinearSolver.suggestTimeStepSize (timeLoop->timeStepSize ()),
282+ timeLoop->maxTimeStepSize ());
283283 dt = std::min (preciceDt, solverDt);
284- timeLoop->setTimeStepSize (dt);
285284
286285 // 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
287288 couplingParticipant.readQuantityFromOtherSolver (meshName, readDatak00,
288289 dt);
289290 couplingParticipant.readQuantityFromOtherSolver (meshName, readDatak01,
@@ -294,95 +295,71 @@ int main(int argc, char **argv)
294295 dt);
295296 couplingParticipant.readQuantityFromOtherSolver (meshName,
296297 readDataPorosity, dt);
297- // store coupling data in problem
298+ // store coupling data in spatial params, exchange with MPI
298299 problem->spatialParams ().updateCouplingData ();
299300 } else {
300301 dt = std::min (
301302 nonLinearSolver.suggestTimeStepSize (timeLoop->timeStepSize ()),
302- getParam<Scalar>(" TimeLoop.MaxDt" ));
303- timeLoop->setTimeStepSize (dt);
303+ timeLoop->maxTimeStepSize ());
304304 }
305+ // set new dt as suggested by the newton solver or by preCICE
306+ timeLoop->setTimeStepSize (dt);
305307
306- std::cout << " Solver starts" << std::endl;
308+ std::cout << " Solver starts with Target dt: " << dt << std::endl;
307309
308- std::cout << " Using dt: " << dt << std::endl;
309310 // linearize & solve
310311 nonLinearSolver.solve (x, *timeLoop);
311312 // save actual time-step size
312313 dt = timeLoop->timeStepSize ();
314+
313315 // DuMux advance + report
314316 gridVariables->advanceTimeStep ();
315317 timeLoop->advanceTimeStep ();
316318 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+ }
317329
318- for (int solIdx = 0 ; solIdx < numberOfElements; ++solIdx)
319- 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 ()];
320334
321- if (getParam<bool >(" Precice.RunWithCoupling" ) == true ) {
322335 couplingParticipant.writeQuantityVector (meshName,
323336 writeDataConcentration, temperatures);
324337 couplingParticipant.writeQuantityToOtherSolver (meshName,
325338 writeDataConcentration);
326- }
327-
328- // advance precice
329- if (getParam<bool >(" Precice.RunWithCoupling" ) == true ) {
330339
340+ // advance precice
331341 if ((!fabs (preciceDt - dt)) < 1e-14 ) {
332342 std::cout << " dt from preCICE is different than dt from DuMuX."
333343 << " preCICE dt = " << preciceDt
334344 << " and DuMuX dt =" << solverDt
335345 << " resulted in dt = " << dt
336346 << std::endl;
337347 }
348+ std::flush (std::cout);
338349 couplingParticipant.advance (dt);
339- }
340350
341- if (getParam< bool >( " Precice.RunWithCoupling " ) == true ) {
351+ // reset to checkpoint if not converged
342352 if (couplingParticipant.requiresToReadCheckpoint ()) {
343- // make the new solution the old solution
344- // TODO
345- // x = xOld;
346353 x = xCheckpoint;
347354 xOld = x;
348355 timeLoop->setTime (timeCheckpoint, timeStepCheckpoint);
356+ // TODO: previousTimeStep might be more appropriate, last one could be small
349357 timeLoop->setTimeStepSize (dt);
350358 gridVariables->update (x);
351359 gridVariables->advanceTimeStep ();
352- } else // coupling successful OR not at time window!!
353- {
354- // TODO
355- xOld = x;
356- n += 1 ;
357- if (n == vtkOutputInterval) {
358- problem->updateVtkOutput (x);
359- vtkWriter.write (timeLoop->time ());
360- n = 0 ;
361- }
362- // gridVariables->advanceTimeStep();
363- // // advance the time loop to the next step
364- // timeLoop->advanceTimeStep();
365- // // report statistics of this time step
366- // timeLoop->reportTimeStep();
367- }
368- } else {
369- xOld = x;
370- // gridVariables->advanceTimeStep();
371- // // advance the time loop to the next step
372- // timeLoop->advanceTimeStep();
373- // // report statistics of this time step
374- // timeLoop->reportTimeStep();
375-
376- // output every outputinterval steps
377- n += 1 ;
378- if (n == vtkOutputInterval) {
379- problem->updateVtkOutput (x);
380- vtkWriter.write (timeLoop->time ());
381- n = 0 ;
360+ continue ;
382361 }
383362 }
384- // set new dt as suggested by the newton solver or by preCICE
385- timeLoop->setTimeStepSize (dt);
386363
387364 std::cout << " Time: " << timeLoop->time () << std::endl;
388365
@@ -393,7 +370,7 @@ int main(int argc, char **argv)
393370 // //////////////////////////////////////////////////////////
394371 // finalize, print dumux message to say goodbye
395372 // //////////////////////////////////////////////////////////
396- if (getParam< bool >( " Precice.RunWithCoupling " ) == true ) {
373+ if (runWithCoupling ) {
397374 couplingParticipant.finalize ();
398375 }
399376 // print dumux end message
0 commit comments