Skip to content

Commit c964086

Browse files
committed
Clean up hydro_forces public header and make Chrono dependencies explicit
1 parent 7b12d0d commit c964086

13 files changed

Lines changed: 96 additions & 28 deletions

include/hydroc/hydro_forces.h

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,12 @@
5858
#include <Eigen/Dense>
5959

6060
// Chrono library includes
61-
#include <chrono/solver/ChIterativeSolverLS.h>
62-
#include <chrono/solver/ChSolverPMINRES.h>
63-
#include <chrono/timestepper/ChTimestepper.h>
64-
#include <chrono/timestepper/ChTimestepperHHT.h>
65-
61+
// Note: We include only the headers strictly necessary for the types used in this header.
62+
// Implementation-only Chrono headers are included in hydro_forces.cpp.
63+
// ChForce.h includes ChFunction internally, so we don't need a separate include.
6664
#include <chrono/physics/ChBody.h>
67-
#include <chrono/physics/ChBodyEasy.h>
6865
#include <chrono/physics/ChForce.h>
69-
#include <chrono/physics/ChLoad.h>
7066
#include <chrono/physics/ChLoadContainer.h>
71-
#include <chrono/physics/ChLoadsBody.h>
72-
#include <chrono/physics/ChSystemNSC.h>
73-
#include <chrono/physics/ChSystemSMC.h>
74-
75-
// Chrono FEA includes
76-
#include <chrono/fea/ChMeshFileLoader.h>
7767

7868
// Hydroc library includes
7969
#include <hydroc/io/h5_reader.h>
@@ -97,13 +87,16 @@ class ChronoHydroCoupler;
9787
// Types GeneralizedForce and BodyForces are defined in hydro_types.h (included above)
9888
}
9989

100-
using namespace chrono;
101-
using namespace chrono::fea;
102-
10390
class ForceFunc6d;
10491
class TestHydro;
10592

106-
class ComponentFunc : public ChFunction {
93+
/**
94+
* @brief Per-DOF force function for Chrono's ChForce system.
95+
*
96+
* Inherits from chrono::ChFunction to provide time-dependent force values.
97+
* Each instance represents a single degree of freedom (surge, sway, heave, roll, pitch, yaw).
98+
*/
99+
class ComponentFunc : public chrono::ChFunction {
107100
public:
108101
/**
109102
* @brief Default constructor.
@@ -162,7 +155,7 @@ class ForceFunc6d {
162155
* @param object The body in the system to which this 6-dimensional force is being applied.
163156
* @param all_hydro_forces_user The TestHydro class where the total force on all bodies is calculated.
164157
*/
165-
ForceFunc6d(std::shared_ptr<ChBody> object, TestHydro* all_hydro_forces_user);
158+
ForceFunc6d(std::shared_ptr<chrono::ChBody> object, TestHydro* all_hydro_forces_user);
166159

167160
/**
168161
* @brief Copy constructor that ensures the force is only added to a body once.
@@ -199,15 +192,16 @@ class ForceFunc6d {
199192
*/
200193
void ApplyForceAndTorqueToBody();
201194

202-
std::shared_ptr<ChBody> body_; ///< Pointer to the body this force is applied to.
195+
std::shared_ptr<chrono::ChBody> body_; ///< Pointer to the body this force is applied to.
203196
int b_num_; ///< Body's index in the system. Currently 1-indexed.
204197
ComponentFunc forces_[6]; ///< Forces for each degree of freedom.
205198
std::shared_ptr<ComponentFunc> force_ptrs_[6]; ///< Pointers to the forces.
206-
std::shared_ptr<ChForce> chrono_force_; ///< Chrono force for the body.
207-
std::shared_ptr<ChForce> chrono_torque_; ///< Chrono torque for the body.
199+
std::shared_ptr<chrono::ChForce> chrono_force_; ///< Chrono force for the body.
200+
std::shared_ptr<chrono::ChForce> chrono_torque_; ///< Chrono torque for the body.
208201
TestHydro* all_hydro_forces_; ///< Pointer to TestHydro for calculations.
209202
};
210203

204+
// Forward declaration of ChLoadAddedMass (defined in added_mass.h, included in .cpp)
211205
class ChLoadAddedMass;
212206

213207
// Lightweight hydrodynamics profiling stats
@@ -236,7 +230,7 @@ class TestHydro {
236230
* @param h5_file_name Name of the h5 file where hydro data is stored.
237231
* @param waves WaveBase object. Defaults to NoWave if not provided.
238232
*/
239-
TestHydro(std::vector<std::shared_ptr<ChBody>> user_bodies,
233+
TestHydro(std::vector<std::shared_ptr<chrono::ChBody>> user_bodies,
240234
std::string h5_file_name,
241235
std::shared_ptr<WaveBase> waves = std::make_shared<NoWave>());
242236

@@ -364,7 +358,7 @@ class TestHydro {
364358

365359
private:
366360
// Class properties related to the body and hydrodynamics
367-
std::vector<std::shared_ptr<ChBody>> bodies_;
361+
std::vector<std::shared_ptr<chrono::ChBody>> bodies_;
368362
int num_bodies_;
369363
HydroData file_info_;
370364
std::vector<ForceFunc6d> force_per_body_;
@@ -390,7 +384,7 @@ class TestHydro {
390384
double cached_state_time_ = std::numeric_limits<double>::quiet_NaN();
391385

392386
// Added mass related properties
393-
std::shared_ptr<ChLoadContainer> my_loadcontainer;
387+
std::shared_ptr<chrono::ChLoadContainer> my_loadcontainer;
394388
std::shared_ptr<ChLoadAddedMass> my_loadbodyinertia;
395389

396390
/**

src/hydro/hydro_forces.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,18 @@
6767
#include <hydroc/coupling/chrono_coupler.h>
6868
#include "radiation/radiation_rirf_processing.h"
6969

70+
// Chrono includes needed for implementation (not exposed in public header)
7071
#include <chrono/physics/ChLoad.h>
72+
#include <chrono/physics/ChBodyEasy.h>
73+
#include <chrono/physics/ChLoadsBody.h>
74+
#include <chrono/physics/ChSystemNSC.h>
75+
#include <chrono/physics/ChSystemSMC.h>
76+
#include <chrono/solver/ChIterativeSolverLS.h>
77+
#include <chrono/solver/ChSolverPMINRES.h>
78+
#include <chrono/timestepper/ChTimestepper.h>
79+
#include <chrono/timestepper/ChTimestepperHHT.h>
80+
#include <chrono/fea/ChMeshFileLoader.h>
81+
7182
#include <unsupported/Eigen/Splines>
7283

7384
#include <Eigen/Dense>
@@ -87,6 +98,17 @@
8798
#include <omp.h>
8899
#endif
89100

101+
// Local using declarations for Chrono types (implementation only - not leaked to users)
102+
// These provide convenience within this translation unit while keeping the public header clean.
103+
using chrono::ChBody;
104+
using chrono::ChBodyEasyMesh;
105+
using chrono::ChForce;
106+
using chrono::ChFunction;
107+
using chrono::ChLoadContainer;
108+
using chrono::ChSolver;
109+
using chrono::ChSystem;
110+
using chrono::ChVector3d;
111+
90112
const int kDofPerBody = 6;
91113
const int kDofLinOrRot = 3;
92114

@@ -158,8 +180,8 @@ ForceFunc6d::ForceFunc6d() : forces_{{this, 0}, {this, 1}, {this, 2}, {this, 3},
158180
// default deletion logic to do nothing
159181
// Also! don't need to worry about deleting this later, because stack arrays are always deleted automatically
160182
}
161-
chrono_force_ = chrono_types::make_shared<ChForce>();
162-
chrono_torque_ = chrono_types::make_shared<ChForce>();
183+
chrono_force_ = std::make_shared<ChForce>();
184+
chrono_torque_ = std::make_shared<ChForce>();
163185
chrono_force_->SetAlign(ChForce::AlignmentFrame::WORLD_DIR);
164186
chrono_torque_->SetAlign(ChForce::AlignmentFrame::WORLD_DIR);
165187
chrono_force_->SetName("hydroforce");
@@ -297,15 +319,15 @@ TestHydro::TestHydro(std::vector<std::shared_ptr<ChBody>> user_bodies,
297319
}
298320

299321
// Handle added mass info (applied via Chrono load system)
300-
my_loadcontainer = chrono_types::make_shared<ChLoadContainer>();
322+
my_loadcontainer = std::make_shared<ChLoadContainer>();
301323

302324
std::vector<std::shared_ptr<ChLoadable>> loadables(bodies_.size());
303325
for (int i = 0; i < static_cast<int>(bodies_.size()); ++i) {
304326
loadables[i] = bodies_[i];
305327
}
306328

307329
my_loadbodyinertia =
308-
chrono_types::make_shared<ChLoadAddedMass>(file_info_.GetBodyInfos(), loadables, bodies_[0]->GetSystem());
330+
std::make_shared<ChLoadAddedMass>(file_info_.GetBodyInfos(), loadables, bodies_[0]->GetSystem());
309331

310332
bodies_[0]->GetSystem()->Add(my_loadcontainer);
311333
my_loadcontainer->Add(my_loadbodyinertia);

tests/regression/f3of/f3of_dt1_test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#include <hydroc/hydro_forces.h>
33

44
#include <chrono/core/ChRealtimeStep.h>
5+
#include <chrono/physics/ChSystemSMC.h>
6+
#include <chrono/physics/ChBodyEasy.h>
7+
#include <chrono/physics/ChLinkLock.h>
8+
#include <chrono/physics/ChLinkTSDA.h>
9+
#include <chrono/solver/ChSolver.h>
510

611
#include <chrono> // std::chrono::high_resolution_clock::now
712
#include <iomanip> // std::setprecision

tests/regression/f3of/f3of_dt2_test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#include <hydroc/hydro_forces.h>
33

44
#include <chrono/core/ChRealtimeStep.h>
5+
#include <chrono/physics/ChSystemSMC.h>
6+
#include <chrono/physics/ChBodyEasy.h>
7+
#include <chrono/physics/ChLinkLock.h>
8+
#include <chrono/physics/ChLinkTSDA.h>
9+
#include <chrono/solver/ChSolver.h>
510

611
#include <chrono> // std::chrono::high_resolution_clock::now
712
#include <iomanip> // std::setprecision

tests/regression/f3of/f3of_dt3_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
#include <hydroc/hydro_forces.h>
44

55
#include <chrono/core/ChRealtimeStep.h>
6+
#include <chrono/physics/ChSystemSMC.h>
7+
#include <chrono/physics/ChBodyEasy.h>
8+
#include <chrono/physics/ChLinkLock.h>
69
#include <chrono/physics/ChLinkMate.h> // fixed body uses link
10+
#include <chrono/solver/ChSolver.h>
711

812
#include <chrono> // std::chrono::high_resolution_clock::now
913
#include <iomanip> // std::setprecision

tests/regression/oswec/oswec_decay_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
#include <hydroc/hydro_forces.h>
44

55
#include <chrono/core/ChRealtimeStep.h>
6+
#include <chrono/physics/ChSystemNSC.h>
7+
#include <chrono/physics/ChBodyEasy.h>
8+
#include <chrono/physics/ChLinkLock.h>
69
#include <chrono/physics/ChLinkMate.h> // fixed body uses link
10+
#include <chrono/solver/ChSolver.h>
711

812
#include <chrono> // std::chrono::high_resolution_clock::now
913
#include <iomanip> // std::setprecision

tests/regression/oswec/oswec_reg_waves_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
#include <hydroc/hydro_forces.h>
44

55
#include <chrono/core/ChRealtimeStep.h>
6+
#include <chrono/physics/ChSystemNSC.h>
7+
#include <chrono/physics/ChBodyEasy.h>
8+
#include <chrono/physics/ChLinkLock.h>
69
#include <chrono/physics/ChLinkMate.h> // fixed body uses link
10+
#include <chrono/solver/ChSolver.h>
711

812
#include <chrono> // std::chrono::high_resolution_clock::now
913
#include <iomanip> // std::setprecision

tests/regression/rm3/rm3_decay_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#include <hydroc/hydro_forces.h>
44

55
#include <chrono/core/ChRealtimeStep.h>
6+
#include <chrono/physics/ChSystemNSC.h>
7+
#include <chrono/physics/ChBodyEasy.h>
8+
#include <chrono/physics/ChLinkLock.h>
9+
#include <chrono/physics/ChLinkTSDA.h>
10+
#include <chrono/solver/ChSolver.h>
11+
#include <chrono/timestepper/ChTimestepper.h>
612

713
#include <chrono> // std::chrono::high_resolution_clock::now
814
#include <iomanip> // std::setprecision

tests/regression/rm3/rm3_reg_waves_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
#include <hydroc/logging.h>
55

66
#include <chrono/core/ChRealtimeStep.h>
7+
#include <chrono/physics/ChSystemNSC.h>
8+
#include <chrono/physics/ChBodyEasy.h>
9+
#include <chrono/physics/ChLinkLock.h>
10+
#include <chrono/physics/ChLinkTSDA.h>
11+
#include <chrono/solver/ChSolver.h>
12+
#include <chrono/timestepper/ChTimestepper.h>
713

814
#include <chrono> // std::chrono::high_resolution_clock::now
915
#include <iomanip> // std::setprecision

tests/regression/sphere/demo_sphere_decay.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include <hydroc/hydro_forces.h>
44

55
#include <chrono/core/ChRealtimeStep.h>
6+
#include <chrono/physics/ChSystemNSC.h>
7+
#include <chrono/physics/ChBodyEasy.h>
8+
#include <chrono/solver/ChSolver.h>
69

710
#include <chrono> // std::chrono::high_resolution_clock::now
811
#include <filesystem> // c++17 only

0 commit comments

Comments
 (0)