Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/DeepCWind/demo_DeepCWind_decay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int main(int argc, char* argv[]) {
// set up hydro forces
std::vector<std::shared_ptr<ChBody>> bodies;
bodies.push_back(base);
TestHydro hydroforces(bodies, h5fname);
HydroForces hydroforces(bodies, h5fname);

// for profiling
auto start = std::chrono::high_resolution_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion demos/f3of/demo_F3OF_DT1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int main(int argc, char* argv[]) {
bodies.push_back(base);
bodies.push_back(flapFore);
bodies.push_back(flapAft);
TestHydro hydroforces(bodies, h5fname, default_dont_add_waves);
HydroForces hydroforces(bodies, h5fname, default_dont_add_waves);

// for profiling
auto start = std::chrono::high_resolution_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion demos/f3of/demo_F3OF_DT2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ int main(int argc, char* argv[]) {
bodies.push_back(flapFore);
bodies.push_back(flapAft);

TestHydro hydroforces(bodies, h5fname, default_dont_add_waves);
HydroForces hydroforces(bodies, h5fname, default_dont_add_waves);

// for profiling
auto start = std::chrono::high_resolution_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion demos/f3of/demo_F3OF_DT3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int main(int argc, char* argv[]) {
bodies.push_back(base);
bodies.push_back(flapFore);
bodies.push_back(flapAft);
TestHydro hydroforces(bodies, h5fname, default_dont_add_waves);
HydroForces hydroforces(bodies, h5fname, default_dont_add_waves);

// for profiling
auto start = std::chrono::high_resolution_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion demos/oswec/demo_oswec_decay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ int main(int argc, char* argv[]) {
std::vector<std::shared_ptr<ChBody>> bodies;
bodies.push_back(flap_body);
bodies.push_back(base_body);
TestHydro blah(bodies, h5fname, default_dont_add_waves);
HydroForces blah(bodies, h5fname, default_dont_add_waves);

// for profiling
auto start = std::chrono::high_resolution_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion demos/oswec/demo_oswec_reg_waves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ int main(int argc, char* argv[]) {
/*std::vector<std::shared_ptr<ChBody>> bodies;
bodies.push_back(flap_body);
bodies.push_back(base_body);*/
TestHydro hydro_forces(bodies, h5fname);
HydroForces hydro_forces(bodies, h5fname);
hydro_forces.AddWaves(my_hydro_inputs);

// for profiling
Expand Down
2 changes: 1 addition & 1 deletion demos/rm3/demo_rm3_decay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ int main(int argc, char* argv[]) {
bodies.push_back(float_body1);
bodies.push_back(plate_body2);

TestHydro hydroForces(bodies, h5fname, default_dont_add_waves);
HydroForces hydroForces(bodies, h5fname, default_dont_add_waves);

//// Debug printing added mass matrix and system mass matrix
// ChSparseMatrix M;
Expand Down
2 changes: 1 addition & 1 deletion demos/rm3/demo_rm3_reg_waves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int main(int argc, char* argv[]) {
std::vector<std::shared_ptr<ChBody>> bodies;
bodies.push_back(float_body1);
bodies.push_back(plate_body2);
TestHydro hydro_forces(bodies, h5fname);
HydroForces hydro_forces(bodies, h5fname);
hydro_forces.AddWaves(my_hydro_inputs);

// for profiling
Expand Down
4 changes: 2 additions & 2 deletions demos/sphere/demo_sphere_decay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) {
system.Add(sphereBody);

// define wave parameters (not used in this demo)
// Todo define a way to use TestHydro without hydro_inputs/waves
// Todo define a way to use HydroForces without hydro_inputs/waves
//HydroInputs my_hydro_inputs;
//my_hydro_inputs.mode = WaveMode::noWaveCIC;
// my_hydro_inputs.regular_wave_amplitude = 0.022;
Expand All @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) {
std::vector<std::shared_ptr<ChBody>> bodies;
bodies.push_back(sphereBody);

TestHydro hydro_forces(bodies, h5fname);
HydroForces hydro_forces(bodies, h5fname);
hydro_forces.AddWaves(default_dont_add_waves);


Expand Down
4 changes: 2 additions & 2 deletions demos/sphere/demo_sphere_irreg_waves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ int main(int argc, char* argv[]) {

std::vector<std::shared_ptr<ChBody>> bodies;
bodies.push_back(sphereBody);
// TestHydro hydro_forces(bodies, h5fname, my_hydro_inputs);
TestHydro hydro_forces(bodies, h5fname);
// HydroForces hydro_forces(bodies, h5fname, my_hydro_inputs);
HydroForces hydro_forces(bodies, h5fname);
hydro_forces.AddWaves(my_hydro_inputs);

// set up free surface from a mesh
Expand Down
2 changes: 1 addition & 1 deletion demos/sphere/demo_sphere_reg_waves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ int main(int argc, char* argv[]) {

std::vector<std::shared_ptr<ChBody>> bodies;
bodies.push_back(sphereBody);
TestHydro hydro_forces(bodies, h5fname);
HydroForces hydro_forces(bodies, h5fname);
hydro_forces.AddWaves(my_hydro_inputs);
// for profiling
auto start = std::chrono::high_resolution_clock::now();
Expand Down
33 changes: 16 additions & 17 deletions include/hydroc/hydro_forces.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*********************************************************************
* @file hydro_forces.h
*
* @brief header file of TestHydro main class and helper classes \
* @brief header file of HydroForces main class and helper classes \
* ComponentFunc and ForceFunc6d.
*********************************************************************/
// TODO: clean up include statements
Expand Down Expand Up @@ -31,7 +31,7 @@ using namespace chrono;
using namespace chrono::fea;

class ForceFunc6d;
class TestHydro;
class HydroForces;

class ComponentFunc : public ChFunction {
public:
Expand Down Expand Up @@ -93,10 +93,10 @@ class ForceFunc6d {
* from H5FileInfo, also initializes ChBody that this force will be applied to.
*
* @param object which body in system this 6 dimensional force is being applied to
* @param all_hydro_forces_user gets TestHydro class where total force on all bodies \
* @param all_hydro_forces_user gets HydroForces class where total force on all bodies \
* in the system is calculated so the components can be passed to ForceFunc6d to apply
*/
ForceFunc6d(std::shared_ptr<ChBody> object, TestHydro* all_hydro_forces_user);
ForceFunc6d(std::shared_ptr<ChBody> object, HydroForces* all_hydro_forces_user);

/**
* @brief copy constructor should check to see if this force has been added to this body yet
Expand Down Expand Up @@ -148,19 +148,18 @@ class ForceFunc6d {
std::shared_ptr<ComponentFunc> force_ptrs[6];
std::shared_ptr<ChForce> chrono_force;
std::shared_ptr<ChForce> chrono_torque;
TestHydro* all_hydro_forces; // pointer up to TestHydro object so coordinateFunc() knows where to go for calcs
HydroForces* all_hydro_forces; // pointer up to HydroForces object so coordinateFunc() knows where to go for calcs
};

class ChLoadAddedMass;

// TODO give TestHydro a better name, perhaps HydroForces ?
// TODO split TestHydro class from its helper classes into new file above for clearer code
class TestHydro {
// TODO split HydroForces class from its helper classes into new file above for clearer code
class HydroForces {
public:
bool printed = false;
TestHydro() = delete;
HydroForces() = delete;
/**
* @brief main constructor for TestHydro class, sets up vector of bodies, h5 file info, and hydro inputs.
* @brief main constructor for HydroForces class, sets up vector of bodies, h5 file info, and hydro inputs.
*
* Also initializes many persistent variables for force calculations from h5 file.
*
Expand All @@ -169,12 +168,12 @@ class TestHydro {
* @param h5_file_name name of h5 file where hydro data is stored
* @param waves optional Wavebase parameter if using regular or irregular waves
*/
TestHydro(std::vector<std::shared_ptr<ChBody>> user_bodies,
HydroForces(std::vector<std::shared_ptr<ChBody>> user_bodies,
std::string h5_file_name,
std::shared_ptr<WaveBase> waves);

/**
* @brief alternate constructor for TestHydro class, sets up vector of bodies, h5 file info, and hydro inputs.
* @brief alternate constructor for HydroForces class, sets up vector of bodies, h5 file info, and hydro inputs.
*
* Also initializes many persistent variables for force calculations from h5 file.
* If no waves are given in main constructor, this constructor makes NoWave object and calls main constructor \
Expand All @@ -186,13 +185,13 @@ class TestHydro {
* must be added to system in same order as provided here
* @param h5_file_name name of h5 file where hydro data is stored
*/
TestHydro(std::vector<std::shared_ptr<ChBody>> user_bodies, std::string h5_file_name)
: TestHydro(user_bodies, h5_file_name, std::static_pointer_cast<WaveBase>(std::make_shared<NoWave>())) {}
HydroForces(std::vector<std::shared_ptr<ChBody>> user_bodies, std::string h5_file_name)
: HydroForces(user_bodies, h5_file_name, std::static_pointer_cast<WaveBase>(std::make_shared<NoWave>())) {}

// should only ever have 1 TestHydro object in a system to calc all the forces on all hydro bodies
// should only ever have 1 HydroForces object in a system to calc all the forces on all hydro bodies
// don't try copying or moving this, many issues will arrise.
TestHydro(const TestHydro& old) = delete;
TestHydro operator=(const TestHydro& rhs) = delete;
HydroForces(const HydroForces& old) = delete;
HydroForces operator=(const HydroForces& rhs) = delete;

/**
* @brief Adds waves class to force calculations depending on if regular or irregular waves.
Expand Down
2 changes: 2 additions & 0 deletions src/h5fileinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ HydroData H5FileInfo::readH5Data() {
Init1D(userH5File, "simulation_parameters/w", data_to_init.reg_wave_data[i].freq_list);
Init3D(userH5File, bodyName + "/hydro_coeffs/excitation/mag",
data_to_init.reg_wave_data[i].excitation_mag_matrix);
// TODO does excitation_mag_matrix need to be squeezed to 2d data as well?

// scale by rho * g
data_to_init.reg_wave_data[i].excitation_mag_matrix =
Expand All @@ -89,6 +90,7 @@ HydroData H5FileInfo::readH5Data() {
Init3D(userH5File, bodyName + "/hydro_coeffs/excitation/phase",
data_to_init.reg_wave_data[i]
.excitation_phase_matrix); // TODO does this also need to be scaled by rho * g?
//TODO does excitation_phase_matrix also need to be squeezed to 2d data?

// irreg wave
// Init3D(userH5File, bodyName + "/hydro_coeffs/excitation/re", excitation_re_matrix, re_dims);
Expand Down
28 changes: 14 additions & 14 deletions src/hydro_forces.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*********************************************************************
* @file hydro_forces.cpp
*
* @brief Implementation of TestHydro main class and helper classes
* @brief Implementation of HydroForces main class and helper classes
* ComponentFunc and ForceFunc6d.
*********************************************************************/

Expand Down Expand Up @@ -149,7 +149,7 @@ ForceFunc6d::ForceFunc6d() : forces{{this, 0}, {this, 1}, {this, 2}, {this, 3},
chrono_torque->SetNameString("hydrotorque");
}

ForceFunc6d::ForceFunc6d(std::shared_ptr<ChBody> object, TestHydro* user_all_forces) : ForceFunc6d() {
ForceFunc6d::ForceFunc6d(std::shared_ptr<ChBody> object, HydroForces* user_all_forces) : ForceFunc6d() {
body = object;
std::string temp = body->GetNameString(); // remove "body" from "bodyN", convert N to int, get body num
b_num = stoi(temp.erase(0, 4)); // 1 indexed TODO: fix b_num starting here to be 0 indexed
Expand Down Expand Up @@ -215,8 +215,8 @@ void ForceFunc6d::ApplyForceAndTorqueToBody() {
body->AddForce(chrono_torque);
}

// TODO reorder TestHydro function ordering to match header file order
TestHydro::TestHydro(std::vector<std::shared_ptr<ChBody>> user_bodies,
// TODO reorder HydroForces function ordering to match header file order
HydroForces::HydroForces(std::vector<std::shared_ptr<ChBody>> user_bodies,
std::string h5_file_name,
std::shared_ptr<WaveBase> waves)
: bodies(user_bodies), num_bodies(bodies.size()), file_info(H5FileInfo(h5_file_name, num_bodies).readH5Data()) {
Expand Down Expand Up @@ -275,7 +275,7 @@ TestHydro::TestHydro(std::vector<std::shared_ptr<ChBody>> user_bodies,
AddWaves(user_waves);
}

void TestHydro::AddWaves(std::shared_ptr<WaveBase> waves) {
void HydroForces::AddWaves(std::shared_ptr<WaveBase> waves) {
user_waves = waves;
if (user_waves->GetWaveMode() == WaveMode::regular) {
std::shared_ptr<RegularWave> reg = std::static_pointer_cast<RegularWave>(user_waves);
Expand All @@ -287,7 +287,7 @@ void TestHydro::AddWaves(std::shared_ptr<WaveBase> waves) {
user_waves->Initialize();
}

double TestHydro::getVelHistoryVal(int step, int c) const {
double HydroForces::getVelHistoryVal(int step, int c) const {
if (step < 0 || step >= file_info.GetRIRFDims(2) || c < 0 || c >= num_bodies * 6) {
std::cout << "wrong vel history index " << std::endl;
return 0;
Expand All @@ -302,7 +302,7 @@ double TestHydro::getVelHistoryVal(int step, int c) const {
return velocity_history[index + (6 * b) + (6 * num_bodies * step)];
}

double TestHydro::setVelHistory(double val, int step, int b_num, int index) {
double HydroForces::setVelHistory(double val, int step, int b_num, int index) {
if (step < 0 || step >= file_info.GetRIRFDims(2) || b_num < 1 || b_num > num_bodies || index < 0 || index >= 6) {
std::cout << "bad set vel history indexing" << std::endl;
return 0;
Expand All @@ -316,7 +316,7 @@ double TestHydro::setVelHistory(double val, int step, int b_num, int index) {
return val;
}

std::vector<double> TestHydro::ComputeForceHydrostatics() {
std::vector<double> HydroForces::ComputeForceHydrostatics() {
assert(num_bodies > 0);

for (int b = 0; b < num_bodies; b++) {
Expand Down Expand Up @@ -367,7 +367,7 @@ std::vector<double> TestHydro::ComputeForceHydrostatics() {
return force_hydrostatic;
}

std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
std::vector<double> HydroForces::ComputeForceRadiationDampingConv() {
int size = file_info.GetRIRFDims(2);
int nDoF = 6;
// "shift" everything left 1
Expand Down Expand Up @@ -396,7 +396,7 @@ std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
}
int vi;
//#pragma omp parallel for
if (convTrapz == true) { // TODO add public function to TestHydro for users to change the value of convTrapz from
if (convTrapz == true) { // TODO add public function to HydroForces for users to change the value of convTrapz from
// main simulation
// convolution integral using trapezoidal rule
for (int row = 0; row < numRows; row++) { // row goes to 6N
Expand Down Expand Up @@ -450,10 +450,10 @@ std::vector<double> TestHydro::ComputeForceRadiationDampingConv() {
return force_radiation_damping;
}

double TestHydro::GetRIRFval(int row, int col, int st) {
double HydroForces::GetRIRFval(int row, int col, int st) {
if (row < 0 || row >= 6 * num_bodies || col < 0 || col >= 6 * num_bodies || st < 0 ||
st >= file_info.GetRIRFDims(2)) {
std::cout << "rirfval index bad from testhydro" << std::endl;
std::cout << "rirfval index bad from HydroForces" << std::endl;
return 0;
}
int b = row / 6; // 0 indexed, which body to get matrix info from
Expand All @@ -462,15 +462,15 @@ double TestHydro::GetRIRFval(int row, int col, int st) {
return file_info.GetRIRFVal(b, r, col, st);
}

Eigen::VectorXd TestHydro::ComputeForceWaves() {
Eigen::VectorXd HydroForces::ComputeForceWaves() {
Eigen::VectorXd wf(num_bodies * 6);
// TODO: check size of force calculated against wf (this could help catch/fix NoWave multibody issue)
wf = user_waves->GetForceAtTime(bodies[0]->GetChTime());
force_waves = wf;
return force_waves;
}

double TestHydro::coordinateFunc(int b, int i) {
double HydroForces::coordinateFunc(int b, int i) {
int body_num_offset = 6 * (b - 1); // b_num from ForceFunc6d is 1 indexed, TODO: make all b_num 0 indexed
int total_dofs = 6 * num_bodies;
if (i < 0 || i > 5 || b < 1 || b > num_bodies) {
Expand Down