@@ -90,6 +90,12 @@ class ChronoHydroCoupler;
9090class ForceFunc6d ;
9191class TestHydro ;
9292
93+ // ─────────────────────────────────────────────────────────────────────────────
94+ // Degrees of Freedom Constant
95+ // ─────────────────────────────────────────────────────────────────────────────
96+ // / Number of degrees of freedom per rigid body: surge, sway, heave, roll, pitch, yaw.
97+ constexpr int kDofPerBody = 6 ;
98+
9399/* *
94100 * @brief Per-DOF force function for Chrono's ChForce system.
95101 *
@@ -193,9 +199,13 @@ class ForceFunc6d {
193199 void ApplyForceAndTorqueToBody ();
194200
195201 std::shared_ptr<chrono::ChBody> body_; // /< Pointer to the body this force is applied to.
196- int b_num_; // /< Body's index in the system. Currently 1-indexed.
197- ComponentFunc forces_[6 ]; // /< Forces for each degree of freedom.
198- std::shared_ptr<ComponentFunc> force_ptrs_[6 ]; // /< Pointers to the forces.
202+
203+ // / Body index in the system (1-indexed, parsed from Chrono body name "bodyN").
204+ // / This matches Chrono's body naming convention where bodies are named body1, body2, etc.
205+ int b_num_;
206+
207+ ComponentFunc forces_[kDofPerBody ]; // /< Forces for each degree of freedom.
208+ std::shared_ptr<ComponentFunc> force_ptrs_[kDofPerBody ]; // /< Pointers to the forces.
199209 std::shared_ptr<chrono::ChForce> chrono_force_; // /< Chrono force for the body.
200210 std::shared_ptr<chrono::ChForce> chrono_torque_; // /< Chrono torque for the body.
201211 TestHydro* all_hydro_forces_; // /< Pointer to TestHydro for calculations.
@@ -214,8 +224,65 @@ struct HydroProfileStats {
214224 int waves_calls = 0 ;
215225};
216226
217- // TODO: Rename TestHydro for clarity, perhaps to HydroForces?
218- // TODO: Split TestHydro class from its helper classes for clearer code structure.
227+ // ═══════════════════════════════════════════════════════════════════════════════
228+ //
229+ // TestHydro — Primary Hydrodynamics Façade / Adapter
230+ //
231+ // ═══════════════════════════════════════════════════════════════════════════════
232+ /* *
233+ * @brief Primary hydrodynamics façade for HydroChrono applications.
234+ *
235+ * TestHydro is the main user-facing object for attaching hydrodynamic forces to
236+ * Chrono bodies. Despite its name (a historical artifact), it is NOT a test-only
237+ * class — it is the production hydrodynamics adapter used by all workflows.
238+ *
239+ * @note The name "TestHydro" is retained for backward compatibility. New code
240+ * may use the alias `HydroForces` for clarity (see below).
241+ *
242+ * ## What It Does
243+ *
244+ * TestHydro bridges three layers:
245+ * 1. **Chrono bodies** — The physical bodies in the Chrono simulation.
246+ * 2. **HydroSystem (core)** — Chrono-free hydrodynamic force computation.
247+ * 3. **Chrono force callbacks** — ChForce functions that Chrono calls each timestep.
248+ *
249+ * ## Typical Usage
250+ *
251+ * @code{.cpp}
252+ * // Create Chrono bodies
253+ * auto body1 = chrono_types::make_shared<ChBody>();
254+ * body1->SetName("body1");
255+ * system.Add(body1);
256+ *
257+ * // Attach hydrodynamic forces (with or without waves)
258+ * std::vector<std::shared_ptr<ChBody>> bodies = {body1};
259+ * TestHydro hydro(bodies, "path/to/hydro_data.h5");
260+ * hydro.AddWaves(std::make_shared<RegularWave>(...));
261+ *
262+ * // Run simulation — Chrono automatically queries TestHydro for forces
263+ * @endcode
264+ *
265+ * ## Used By
266+ *
267+ * - **C++ tests and demos** — Directly instantiate TestHydro with bodies and H5 file.
268+ * - **YAML runner (hydrochrono.exe)** — SetupHydroFromYAML creates TestHydro internally.
269+ *
270+ * ## Architecture Notes
271+ *
272+ * - Internally delegates to HydroSystem + ChronoHydroCoupler for force computation.
273+ * - Maintains velocity history for radiation damping convolution.
274+ * - Caches forces per timestep to avoid redundant computation.
275+ *
276+ * ## Body Indexing Convention
277+ *
278+ * Chrono bodies must be named "body1", "body2", etc. The numeric suffix is parsed
279+ * to determine body order. Internally, body indices are **1-based** in the callback
280+ * interface (CoordinateFuncForBody) to match this naming convention.
281+ *
282+ * @see HydroForces (alias below)
283+ * @see HydroSystem (Chrono-free hydrodynamic core)
284+ * @see ChronoHydroCoupler (extracts state from Chrono bodies)
285+ */
219286class TestHydro {
220287 public:
221288 TestHydro () = delete ;
@@ -328,13 +395,20 @@ class TestHydro {
328395 /* *
329396 * @brief Calculates or retrieves the total force on a specific body in a particular degree of freedom.
330397 *
331- * If the total force for the body and DOF was computed for the current timestep, it's retrieved.
332- * Otherwise, the function calculates it. Note: Body index is 1-based here due to its origin from ForceFunc6d.
398+ * This is the main entry point called by Chrono's ChForce callbacks during simulation.
399+ * Forces are computed once per timestep and cached; subsequent calls within the same
400+ * timestep return the cached value.
401+ *
402+ * @note **1-Based Body Indexing**: The body index `b` is 1-based (body1 → b=1, body2 → b=2, etc.)
403+ * to match Chrono's body naming convention. This is intentional and matches how
404+ * ForceFunc6d parses body names like "body1", "body2", etc.
333405 *
334- * @param b Body index (1-based due to source from ForceFunc6d ).
335- * @param i Degree of Freedom (DOF) index, ranging from [0,...5] .
406+ * @param b Body index (1-based: valid range is [1, num_bodies] ).
407+ * @param i Degree of Freedom (DOF) index (0-based: 0=surge, 1=sway, 2=heave, 3=roll, 4=pitch, 5=yaw) .
336408 *
337- * @return Component of the force vector for body 'b' and DOF 'i'.
409+ * @return Force component for body 'b' in DOF 'i' (Newtons for forces, Newton-meters for torques).
410+ *
411+ * @throws std::out_of_range if b or i are out of valid range.
338412 */
339413 double CoordinateFuncForBody (int b, int i);
340414
@@ -459,4 +533,21 @@ class TestHydro {
459533 void EnsureHydroSystemAndCoupler ();
460534};
461535
536+ // ─────────────────────────────────────────────────────────────────────────────
537+ // Public Alias for Clarity
538+ // ─────────────────────────────────────────────────────────────────────────────
539+ /* *
540+ * @brief Alias for TestHydro — the primary hydrodynamics façade.
541+ *
542+ * HydroForces is the recommended name for new code. The underlying class
543+ * is TestHydro (historical name retained for backward compatibility).
544+ *
545+ * Usage:
546+ * @code{.cpp}
547+ * HydroForces hydro(bodies, "hydro_data.h5");
548+ * hydro.AddWaves(my_waves);
549+ * @endcode
550+ */
551+ using HydroForces = TestHydro;
552+
462553#endif
0 commit comments