55#include " ../hydro_yaml_parser.h"
66#include < hydroc/hydro_forces.h>
77#include < hydroc/simulation_exporter.h>
8+ #include < hydroc/wave_types.h>
89
910#include < chrono_parsers/yaml/ChParserMbsYAML.h>
1011#include < chrono/physics/ChSystem.h>
2324#include < sstream>
2425#include < chrono>
2526#include < iomanip>
27+ #include < cmath>
2628
2729#ifdef _WIN32
2830#include < windows.h>
@@ -449,8 +451,10 @@ int RunHydroChronoFromYAML(int argc, char* argv[]) {
449451
450452 // Setup hydrodynamic forces
451453 hydroc::debug::LogDebug (" Initializing TestHydro..." );
452- // Provide a neutral horizon (Chrono governs runtime via YAML/UI)
453- test_hydro = SetupHydroFromYAML (hydro_data, bodies, loop_dt, /* time_end_hint*/ 0.0 , 0.0 );
454+ // Provide simulation horizon from YAML end_time (important for irregular waves spectrum)
455+ double sim_duration_hint = 0.0 ;
456+ TryFindYamlDouble (sim_file, " end_time" , sim_duration_hint);
457+ test_hydro = SetupHydroFromYAML (hydro_data, bodies, loop_dt, sim_duration_hint, 0.0 );
454458 hydroc::debug::LogDebug (" Hydrodynamic forces initialized successfully" );
455459
456460 // Inform location for diagnostics CSVs: write to hydro file directory
@@ -656,9 +660,23 @@ int RunHydroChronoFromYAML(int argc, char* argv[]) {
656660 exporter = std::make_unique<hydroc::SimulationExporter>(exp_opts);
657661
658662 // Write static info and model before stepping
659- exporter->WriteSimulationInfo (system.get (), std::string (" " ), std::filesystem::path (model_file).filename ().generic_string (), loop_dt, /* duration_seconds*/ 0.0 );
663+ double duration_hint = 0.0 ; TryFindYamlDouble (sim_file, " end_time" , duration_hint);
664+ exporter->WriteSimulationInfo (system.get (), std::string (" " ), std::filesystem::path (model_file).filename ().generic_string (), loop_dt, duration_hint);
660665 exporter->WriteModel (system.get ());
661666 exporter->BeginResults (system.get (), /* expected_steps*/ 0 );
667+
668+ // If irregular waves are configured, persist spectrum and eta(t) inputs to HDF5
669+ if (test_hydro) {
670+ auto wave_ptr = test_hydro->GetWave ();
671+ if (wave_ptr && wave_ptr->GetWaveMode () == WaveMode::irregular) {
672+ auto irreg = std::static_pointer_cast<IrregularWaves>(wave_ptr);
673+ std::vector<double > f = irreg->GetFrequenciesHz ();
674+ std::vector<double > S = irreg->GetSpectrum ();
675+ std::vector<double > tvec = irreg->GetFreeSurfaceTime ();
676+ std::vector<double > eta = irreg->GetFreeSurfaceElevation ();
677+ exporter->WriteIrregularInputs (f, S, tvec, eta);
678+ }
679+ }
662680 } catch (const std::exception& e) {
663681 hydroc::cli::LogWarning (std::string (" HDF5 exporter disabled: " ) + e.what ());
664682 exporter.reset ();
@@ -697,6 +715,14 @@ int RunHydroChronoFromYAML(int argc, char* argv[]) {
697715
698716 if (nogui) {
699717 const double end_time_bound = (yaml_end_time > 0.0 ) ? yaml_end_time : 40.0 ;
718+ // Estimate total steps for progress bar; ensure at least 1
719+ const double remaining_time = std::max (0.0 , end_time_bound - initial_time);
720+ const size_t total_steps_est = static_cast <size_t >(std::max (1.0 , std::ceil (remaining_time / std::max (1e-12 , loop_dt))));
721+ size_t last_progress_step = 0 ;
722+
723+ // Initial progress line
724+ hydroc::cli::ShowProgress (0 , total_steps_est, std::string (" t=" ) + hydroc::FormatNumber (initial_time, 2 ) + " / " + hydroc::FormatNumber (end_time_bound, 2 ) + " s" );
725+
700726 while (system->GetChTime () < end_time_bound) {
701727 double current_time = system->GetChTime ();
702728 try {
@@ -709,18 +735,33 @@ int RunHydroChronoFromYAML(int argc, char* argv[]) {
709735 exporter->RecordStep (system.get ());
710736 if (profile_mode) { prof_export_seconds += std::chrono::duration_cast<std::chrono::duration<double >>(std::chrono::steady_clock::now () - t).count (); }
711737 }
738+ // Update progress periodically to reduce console churn
739+ if (step_count == 1 || step_count - static_cast <int >(last_progress_step) >= 25 ) {
740+ const size_t current_steps = static_cast <size_t >(std::min<double >(total_steps_est, std::ceil ((system->GetChTime () - initial_time) / std::max (1e-12 , loop_dt))));
741+ std::string msg = std::string (" t=" ) + hydroc::FormatNumber (system->GetChTime (), 2 ) + " / " + hydroc::FormatNumber (end_time_bound, 2 ) + " s" ;
742+ hydroc::cli::ShowProgress (current_steps, total_steps_est, msg);
743+ last_progress_step = static_cast <size_t >(step_count);
744+ }
712745 previous_time = current_time;
713746 } catch (const std::exception& e) {
747+ hydroc::cli::StopProgress ();
714748 hydroc::cli::LogError (std::string (" 🔥 Exception during DoStepDynamics at step " ) + std::to_string (step_count) + " : " + e.what ());
715749 hydroc::cli::LogError (std::string (" Simulation time: " ) + hydroc::FormatNumber (current_time, 6 ) + " s" );
716750 hydroc::cli::LogError (std::string (" Step size: " ) + hydroc::FormatNumber (loop_dt, 6 ) + " s" );
717751 break ;
718752 } catch (...) {
753+ hydroc::cli::StopProgress ();
719754 hydroc::cli::LogError (std::string (" 🔥 Unknown exception during DoStepDynamics at step " ) + std::to_string (step_count));
720755 hydroc::cli::LogError (std::string (" Simulation time: " ) + hydroc::FormatNumber (current_time, 6 ) + " s" );
721756 break ;
722757 }
723758 }
759+ // Finalize progress line
760+ if (system->GetChTime () >= end_time_bound - 1e-9 ) {
761+ hydroc::cli::ShowProgress (total_steps_est, total_steps_est, " Completed" );
762+ } else {
763+ hydroc::cli::StopProgress ();
764+ }
724765 } else {
725766 // GUI-driven loop: respects pause via ui.simulationStarted and closes when window stops
726767 while (ui.IsRunning (loop_dt)) {
0 commit comments