Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/regression/rm3/test_rm3_reg_waves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <chrono/physics/ChBodyEasy.h>
#include <chrono/physics/ChSystemNSC.h>
#include <chrono/timestepper/ChTimestepperImplicit.h>

#include <chrono> // std::chrono::high_resolution_clock::now
#include <iomanip> // std::setprecision
Expand Down Expand Up @@ -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<ChTimestepperImplicit>(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<unsigned>(integrator->GetMaxIters());
double simulationDuration = seastack::chrono::GetSimDuration(40.0, 200.0);

// Output timeseries
Expand Down Expand Up @@ -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());
Expand Down
Loading