@@ -197,19 +197,52 @@ bool ResolveInputFiles(const std::filesystem::path& input_dir,
197197 return true ;
198198}
199199
200+ // ---------------------------------------------------------------------------
201+ // Thin subclass of ChParserMbsYAML that exposes the protected
202+ // m_script_directory member. When HydroChrono loads model and solver
203+ // data from separate YAML files (rather than via ChParserMbsYAML::LoadFile),
204+ // this directory is never set, which breaks relative-path resolution for
205+ // mesh files referenced in model YAML (e.g. "../../assets/geometry/flap.obj").
206+ // ---------------------------------------------------------------------------
207+ namespace {
208+ class HCParser : public chrono ::parsers::ChParserMbsYAML {
209+ public:
210+ HCParser () : ChParserMbsYAML() {}
211+ // / Set the base directory used by GetDatafilePath() when data_path is RELATIVE.
212+ void SetScriptDir (const std::string& dir) { m_script_directory = dir; }
213+ };
214+ } // namespace
215+
200216std::shared_ptr<chrono::ChSystem> InitializeChronoSystem (const std::string& model_file, const std::string& sim_file) {
201217 hydroc::debug::LogDebug (" Initializing Chrono system from YAML inputs..." );
202218
203219 try {
204220 hydroc::debug::LogDebug (" Creating Chrono YAML parser" );
205- auto parser = chrono::parsers::ChParserMbsYAML ();
221+ HCParser parser;
222+
223+ // Tell the parser where the model file lives so that relative mesh
224+ // paths (data_path type: RELATIVE) are resolved correctly.
225+ std::filesystem::path model_dir = std::filesystem::path (model_file).parent_path ();
226+ parser.SetScriptDir (model_dir.generic_string ());
227+ hydroc::debug::LogDebug (std::string (" Script directory set to: " ) + model_dir.generic_string ());
206228
207- // Load simulation settings (solver, integrator , visualization, etc.)
229+ // Load simulation settings (end_time, gravity , visualization, etc.)
208230 hydroc::debug::LogDebug (std::string (" Loading simulation file: " ) + sim_file);
209231 auto sim_yaml = YAML::LoadFile (sim_file);
210232 parser.LoadSimData (sim_yaml);
211- if (sim_yaml[" solver" ])
212- parser.LoadSolverData (sim_yaml);
233+
234+ // Load solver/integrator/contact-method settings.
235+ // HydroChrono nests these under the "simulation" key, while the Chrono
236+ // parser's LoadSolverData() expects them as direct children of the node.
237+ // Additionally, HydroChrono puts time_step at the simulation level,
238+ // while Chrono expects it inside the integrator block.
239+ auto sim_node = sim_yaml[" simulation" ];
240+ if (sim_node && sim_node[" contact_method" ]) {
241+ // Promote time_step into the integrator block if needed
242+ if (sim_node[" time_step" ] && sim_node[" integrator" ] && !sim_node[" integrator" ][" time_step" ])
243+ sim_node[" integrator" ][" time_step" ] = sim_node[" time_step" ];
244+ parser.LoadSolverData (sim_node);
245+ }
213246
214247 hydroc::debug::LogDebug (" Creating system" );
215248 auto system = parser.CreateSystem ();
@@ -220,7 +253,6 @@ std::shared_ptr<chrono::ChSystem> InitializeChronoSystem(const std::string& mode
220253 parser.LoadModelData (model_yaml);
221254
222255 hydroc::debug::LogDebug (" Analyzing mesh files referenced in YAML model" );
223- std::filesystem::path model_dir = std::filesystem::path (model_file).parent_path ();
224256 hydroc::debug::LogDebug (std::string (" Model directory: " ) + model_dir.generic_string ());
225257
226258 hydroc::debug::LogDebug (" Populating system" );
0 commit comments