@@ -108,8 +108,7 @@ int main(int argc, char **argv)
108108 // verify that dimensions match
109109 const int preciceDim = couplingParticipant.getMeshDimensions (meshName);
110110 const int dim = int (leafGridView.dimension );
111- std::cout << " coupling Dims = " << dim << " , leafgrid dims = " << dim
112- << std::endl;
111+ std::cout << " Coupling dims = " << preciceDim << " , leafgrid dims = " << dim << std::endl;
113112 if (preciceDim != dim)
114113 DUNE_THROW (Dune::InvalidStateException, " Dimensions do not match" );
115114 }
@@ -135,11 +134,15 @@ int main(int argc, char **argv)
135134 }
136135 }
137136
138- std::cout << " Number of Coupled Cells:" << coupledElementIdxs.size ()
139- << std::endl;
137+ std::cout << " Number of Coupled Cells:" << coupledElementIdxs.size () << std::endl;
138+
139+ int numberOfElements;
140+ if (runWithCoupling) {
141+ numberOfElements = coords.size () / couplingParticipant.getMeshDimensions (meshName);
142+ } else {
143+ numberOfElements = coupledElementIdxs.size ();
144+ }
140145
141- auto numberOfElements =
142- coords.size () / couplingParticipant.getMeshDimensions (meshName);
143146 if (runWithCoupling) {
144147 couplingParticipant.setMesh (meshName, coords);
145148
@@ -228,14 +231,15 @@ int main(int argc, char **argv)
228231 }
229232
230233 // time loop parameters
231- const auto tEnd = getParam<Scalar>(" TimeLoop.TEnd" );
232- double preciceDt = couplingParticipant. getMaxTimeStepSize () ;
234+ const auto tEnd = getParam<Scalar>(" TimeLoop.TEnd" );
235+ double preciceDt;
233236 double solverDt;
234237 double dt;
235238
236239 if (runWithCoupling) {
237- solverDt = getParam<Scalar>(" TimeLoop.InitialDt" );
238- dt = std::min (preciceDt, solverDt);
240+ preciceDt = couplingParticipant.getMaxTimeStepSize ();
241+ solverDt = getParam<Scalar>(" TimeLoop.InitialDt" );
242+ dt = std::min (preciceDt, solverDt);
239243 } else {
240244 dt = getParam<Scalar>(" TimeLoop.InitialDt" );
241245 }
@@ -266,7 +270,7 @@ int main(int argc, char **argv)
266270 NewtonSolver nonLinearSolver (assembler, linearSolver);
267271
268272 // time loop
269- int n = 0 ; // counts timesteps for the output interval
273+ int n_out = 0 ; // counts timesteps for the output interval
270274 std::cout << " Time Loop starts" << std::endl;
271275 timeLoop->start ();
272276 do {
@@ -305,7 +309,7 @@ int main(int argc, char **argv)
305309 // set new dt as suggested by the Newton solver or by preCICE
306310 timeLoop->setTimeStepSize (dt);
307311
308- std::cout << " Solver starts with target dt: " << dt << std::endl;
312+ std::cout << " nonLinearSolver starts with target dt: " << dt << std::endl;
309313
310314 // linearize & solve
311315 nonLinearSolver.solve (x, *timeLoop);
@@ -319,15 +323,6 @@ int main(int argc, char **argv)
319323 timeLoop->reportTimeStep ();
320324 xOld = x;
321325
322- // Vtk output
323- // TODO: output interval does not work seamlessly when subcycling
324- n += 1 ;
325- if (n == vtkOutputInterval) {
326- problem->updateVtkOutput (x);
327- vtkWriter.write (timeLoop->time ());
328- n = 0 ;
329- }
330-
331326 if (runWithCoupling) {
332327 int solIdx = 0 ;
333328 for (const auto &element : elements (leafGridView, Dune::Partitions::interior)) {
@@ -363,6 +358,25 @@ int main(int argc, char **argv)
363358 }
364359 }
365360
361+ if (runWithCoupling) {
362+ // if coupling, write VTK output only when time window is complete
363+ if (couplingParticipant.isTimeWindowComplete ()) {
364+ n_out += 1 ;
365+ if (n_out == vtkOutputInterval) {
366+ problem->updateVtkOutput (x);
367+ vtkWriter.write (timeLoop->time ());
368+ n_out = 0 ;
369+ }
370+ }
371+ } else {
372+ n_out += 1 ;
373+ if (n_out == vtkOutputInterval) {
374+ problem->updateVtkOutput (x);
375+ vtkWriter.write (timeLoop->time ());
376+ n_out = 0 ;
377+ }
378+ }
379+
366380 std::cout << " Time: " << timeLoop->time () << std::endl;
367381
368382 } while (!timeLoop->finished ());
0 commit comments