diff --git a/tests/regression/rm3/test_rm3_reg_waves.cpp b/tests/regression/rm3/test_rm3_reg_waves.cpp index 6998356..00ccacf 100644 --- a/tests/regression/rm3/test_rm3_reg_waves.cpp +++ b/tests/regression/rm3/test_rm3_reg_waves.cpp @@ -8,6 +8,7 @@ #include #include +#include #include // std::chrono::high_resolution_clock::now #include // std::setprecision @@ -56,6 +57,23 @@ int main(int argc, char* argv[]) { double timestep = 0.01; system.SetTimestepperType(ChTimestepper::Type::HHT); system.SetSolverType(ChSolver::Type::GMRES); + auto integrator = std::dynamic_pointer_cast(system.GetTimestepper()); + if (!integrator) { + std::cerr << "ERROR: the time stepper is not an implicit integrator" << std::endl; + return 1; + } + // Absolute tolerance on the constraint reactions [N, N m] in the Newton + // convergence test of the integrator. The waves travel along x, so the sway + // force, roll moment and yaw moment in the prismatic joint are close to zero + // (about 1e-3 N m in yaw, against 1e6 N m in pitch). With Chrono's default + // of 1e-10, such a component has to converge to about 1e-10 when it passes + // through zero, which the iterative solver does not reach. The step is then + // halved, and after enough halvings the run stops with "Reached minimum + // allowable step size". The tolerance on the accelerations keeps Chrono's + // default value. + integrator->SetAbsTolerances(1e-10, 1e-2); + // Newton iterations allowed in one attempt at a step. + const unsigned max_iterations = static_cast(integrator->GetMaxIters()); double simulationDuration = seastack::chrono::GetSimDuration(40.0, 200.0); // Output timeseries @@ -134,6 +152,17 @@ int main(int argc, char* argv[]) { while (system.GetChTime() <= simulationDuration) { system.DoStepDynamics(timestep); + // One attempt at a step takes at most max_iterations Newton iterations. + // More in one call means that an attempt did not converge and the + // integrator repeated it with a smaller step. This case should never + // need that (see the tolerance above). + if (integrator->GetNumStepIterations() > max_iterations) { + std::cerr << "ERROR: the integrator cut its step at t = " << system.GetChTime() << " s (" + << integrator->GetNumStepIterations() << " Newton iterations in one call, at most " + << max_iterations << " per attempt)" << std::endl; + return 1; + } + // append data to output vector time_vector.push_back(system.GetChTime()); float_heave_position.push_back(float_body1->GetPos().z());