Skip to content

Commit 24f6874

Browse files
committed
Fix build: adopt Chrono Mbs YAML parser, drop MoorDyn parsing, make project.meta optional
CMakeLists.txt: Guard reading project.meta Add fallback include paths for Chrono Parsers src/hydro_yaml_parser.cpp: Remove unused MoorDyn parsing src/hydrochrono_runner/run_hydrochrono_from_yaml.cpp: Update to Chrono’s renamed YAML parser: (now ChParserMbsYAML instead of ChParserYAML
1 parent 690cd23 commit 24f6874

3 files changed

Lines changed: 69 additions & 49 deletions

File tree

CMakeLists.txt

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,46 @@ project(HydroChrono
2727
# ─── 2.1. Parse Project Metadata ──────────────────────────────────────────────
2828
# ═══════════════════════════════════════════════════════════════════════════════
2929

30-
# Read and parse project.meta file
31-
file(READ "${CMAKE_SOURCE_DIR}/project.meta" PROJECT_META_CONTENT)
32-
string(REPLACE "\n" ";" PROJECT_META_LINES "${PROJECT_META_CONTENT}")
33-
34-
# Parse each line and extract key-value pairs
35-
foreach(line ${PROJECT_META_LINES})
36-
if(line MATCHES "^([^=]+)=([^=]+)$")
37-
string(STRIP "${CMAKE_MATCH_1}" key)
38-
string(STRIP "${CMAKE_MATCH_2}" value)
39-
if(key STREQUAL "name")
40-
set(HYDROCHRONO_NAME "${value}")
41-
elseif(key STREQUAL "version")
42-
set(HYDROCHRONO_VERSION "${value}")
43-
elseif(key STREQUAL "description")
44-
set(HYDROCHRONO_DESCRIPTION "${value}")
45-
elseif(key STREQUAL "author")
46-
set(HYDROCHRONO_AUTHOR "${value}")
47-
elseif(key STREQUAL "maintainer")
48-
set(HYDROCHRONO_MAINTAINER "${value}")
49-
elseif(key STREQUAL "url")
50-
set(HYDROCHRONO_URL "${value}")
51-
elseif(key STREQUAL "license")
52-
set(HYDROCHRONO_LICENSE "${value}")
53-
elseif(key STREQUAL "status")
54-
set(HYDROCHRONO_STATUS "${value}")
30+
# Read and parse project.meta file if present; otherwise provide sensible defaults
31+
if(EXISTS "${CMAKE_SOURCE_DIR}/project.meta")
32+
file(READ "${CMAKE_SOURCE_DIR}/project.meta" PROJECT_META_CONTENT)
33+
string(REPLACE "\n" ";" PROJECT_META_LINES "${PROJECT_META_CONTENT}")
34+
35+
# Parse each line and extract key-value pairs
36+
foreach(line ${PROJECT_META_LINES})
37+
if(line MATCHES "^([^=]+)=([^=]+)$")
38+
string(STRIP "${CMAKE_MATCH_1}" key)
39+
string(STRIP "${CMAKE_MATCH_2}" value)
40+
if(key STREQUAL "name")
41+
set(HYDROCHRONO_NAME "${value}")
42+
elseif(key STREQUAL "version")
43+
set(HYDROCHRONO_VERSION "${value}")
44+
elseif(key STREQUAL "description")
45+
set(HYDROCHRONO_DESCRIPTION "${value}")
46+
elseif(key STREQUAL "author")
47+
set(HYDROCHRONO_AUTHOR "${value}")
48+
elseif(key STREQUAL "maintainer")
49+
set(HYDROCHRONO_MAINTAINER "${value}")
50+
elseif(key STREQUAL "url")
51+
set(HYDROCHRONO_URL "${value}")
52+
elseif(key STREQUAL "license")
53+
set(HYDROCHRONO_LICENSE "${value}")
54+
elseif(key STREQUAL "status")
55+
set(HYDROCHRONO_STATUS "${value}")
56+
endif()
5557
endif()
56-
endif()
57-
endforeach()
58+
endforeach()
59+
else()
60+
# Defaults when meta file is not present
61+
set(HYDROCHRONO_NAME "${PROJECT_NAME}")
62+
set(HYDROCHRONO_VERSION "${PROJECT_VERSION}")
63+
set(HYDROCHRONO_DESCRIPTION "${PROJECT_DESCRIPTION}")
64+
set(HYDROCHRONO_AUTHOR "")
65+
set(HYDROCHRONO_MAINTAINER "")
66+
set(HYDROCHRONO_URL "")
67+
set(HYDROCHRONO_LICENSE "")
68+
set(HYDROCHRONO_STATUS "")
69+
endif()
5870

5971
# Display parsed metadata
6072
message(STATUS "Project: ${HYDROCHRONO_NAME} v${HYDROCHRONO_VERSION}")
@@ -295,6 +307,10 @@ if(HYDROCHRONO_ENABLE_YAML_RUNNER)
295307
PRIVATE
296308
${PROJECT_SOURCE_DIR}/include
297309
${PROJECT_SOURCE_DIR}/src/utils
310+
# Fallback include paths for Chrono Parsers when using a build-tree Chrono_DIR
311+
$<IF:$<BOOL:${Chrono_DIR}>,${Chrono_DIR}/../../install/include,>
312+
$<IF:$<BOOL:${Chrono_DIR}>,${Chrono_DIR}/../include,>
313+
$<IF:$<BOOL:${Chrono_DIR}>,${Chrono_DIR}/../../src,>
298314
)
299315

300316
set_target_properties(run_hydrochrono PROPERTIES

src/hydro_yaml_parser.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ YAMLHydroData ReadHydroYAML(const std::string& hydro_file_path) {
262262
// - Body properties at indent == 6
263263
// - Wave properties at indent == 4
264264
// - Nested period block under waves at indent >= period_block_indent + 2 when in_period_block
265-
if ((in_body && indent == 6) || (in_waves && (indent == 4 || (in_period_block && indent >= period_block_indent + 2))) || (in_moordyn && indent == 4)) {
266-
std::string key, value;
267-
if (ParseYAMLLine(line, key, value)) {
265+
{
266+
std::string key;
267+
std::string value;
268+
bool should_parse = ( (in_body && indent == 6) || (in_waves && (indent == 4 || (in_period_block && indent >= period_block_indent + 2))) );
269+
if (should_parse && ParseYAMLLine(line, key, value)) {
268270
if (in_body) {
269271
// Parse body properties
270272
if (key == "name") {
@@ -318,18 +320,21 @@ YAMLHydroData ReadHydroYAML(const std::string& hydro_file_path) {
318320
} else if (in_period_block && key == "values") {
319321
// period:\n values: [a, b, c]
320322
auto lb = value.find('['); auto rb = value.find(']');
321-
if (lb == std::string::npos || rb == std::string::npos || rb <= lb) continue;
322-
std::string inner = value.substr(lb + 1, rb - lb - 1);
323-
for (char& ch : inner) if (ch == ',') ch = ' ';
324-
std::istringstream iss(inner);
325-
double v; data.waves.period_values.clear();
326-
while (iss >> v) data.waves.period_values.push_back(v);
327-
if (!data.waves.period_values.empty()) {
328-
data.waves.period = data.waves.period_values.front();
329-
if (period_form_linspace || period_form_range) {
330-
throw std::runtime_error("waves.period: multiple forms specified (values + other)");
323+
if (lb == std::string::npos || rb == std::string::npos || rb <= lb) {
324+
// invalid list, ignore
325+
} else {
326+
std::string inner = value.substr(lb + 1, rb - lb - 1);
327+
for (char& ch : inner) if (ch == ',') ch = ' ';
328+
std::istringstream iss(inner);
329+
double v; data.waves.period_values.clear();
330+
while (iss >> v) data.waves.period_values.push_back(v);
331+
if (!data.waves.period_values.empty()) {
332+
data.waves.period = data.waves.period_values.front();
333+
if (period_form_linspace || period_form_range) {
334+
throw std::runtime_error("waves.period: multiple forms specified (values + other)");
335+
}
336+
period_form_values = true;
331337
}
332-
period_form_values = true;
333338
}
334339
} else if (in_period_block && key == "linspace") {
335340
// linspace: { start: a, stop: b, num: n }
@@ -405,14 +410,13 @@ YAMLHydroData ReadHydroYAML(const std::string& hydro_file_path) {
405410
} else if (!in_period_block && key == "seed") {
406411
try { data.waves.seed = std::stoi(value); } catch (...) { data.waves.seed = -1; }
407412
}
408-
}
409413
}
410414
}
415+
}
411416
// Detect leaving the period block when indentation reduces back to waves level
412-
if (in_period_block && indent <= period_block_indent && key != "period") {
417+
if (in_period_block && indent <= period_block_indent) {
413418
in_period_block = false;
414419
}
415-
}
416420
}
417421

418422
// Don't forget to add the last body

src/hydrochrono_runner/run_hydrochrono_from_yaml.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "../hydro_yaml_parser.h"
66
#include <hydroc/hydro_forces.h>
77

8-
#include <chrono_parsers/ChParserYAML.h>
8+
#include <chrono_parsers/yaml/ChParserMbsYAML.h>
99
#include <chrono/physics/ChSystem.h>
1010
#include <chrono/physics/ChBody.h>
1111
#include <chrono/core/ChRealtimeStep.h>
@@ -151,7 +151,7 @@ std::shared_ptr<chrono::ChSystem> InitializeChronoSystem(const std::string& mode
151151

152152
try {
153153
hydroc::debug::LogDebug("Creating Chrono YAML parser");
154-
auto parser = chrono::parsers::ChParserYAML();
154+
auto parser = chrono::parsers::ChParserMbsYAML();
155155

156156
hydroc::debug::LogDebug(std::string("Loading simulation file: ") + sim_file);
157157
parser.LoadSimulationFile(sim_file);
@@ -311,9 +311,9 @@ int RunHydroChronoFromYAML(int argc, char* argv[]) {
311311
log_cfg.enable_file_output = !log_file_path.empty();
312312
log_cfg.enable_debug_logging = debug_mode; // gate dev logs
313313
// Console threshold: Debug if --debug, else Info. File threshold: always Debug to capture details.
314-
log_cfg.console_level = debug_mode ? hydroc::LoggingConfig::Level::Debug
315-
: hydroc::LoggingConfig::Level::Info;
316-
log_cfg.file_level = hydroc::LoggingConfig::Level::Debug;
314+
log_cfg.console_level = debug_mode ? hydroc::LogLevel::Debug
315+
: hydroc::LogLevel::Info;
316+
log_cfg.file_level = hydroc::LogLevel::Debug;
317317
hydroc::Initialize(log_cfg);
318318
hydroc::cli::ShowBanner();
319319

0 commit comments

Comments
 (0)