Skip to content

Commit ef5589a

Browse files
committed
formatted test syrope.cpp
1 parent 250b1e3 commit ef5589a

1 file changed

Lines changed: 40 additions & 35 deletions

File tree

tests/syrope.cpp

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/*
2-
* This file is based on the C++ driver to verify the Syrope implementation in MoorDyn-C,
3-
* which is available at https://github.com/zhilongwei/moordyn-syrope-tests.git.
4-
* A Python script is used there to check the L2-error and plot the results,
5-
* whereas here we use Catch2 to check the L2-error only.
2+
* This file is based on the C++ driver to verify the Syrope implementation in
3+
* MoorDyn-C, which is available at
4+
* https://github.com/zhilongwei/moordyn-syrope-tests.git. A Python script is
5+
* used there to check the L2-error and plot the results, whereas here we use
6+
* Catch2 to check the L2-error only.
67
*/
78

89
#define _USE_MATH_DEFINES
@@ -96,8 +97,8 @@ struct MoorDynRAII
9697

9798
double
9899
interpolate_clamped(double x,
99-
const Eigen::VectorXd& xdata,
100-
const Eigen::VectorXd& ydata)
100+
const Eigen::VectorXd& xdata,
101+
const Eigen::VectorXd& ydata)
101102
{
102103
if (xdata.size() != ydata.size()) {
103104
throw std::invalid_argument("interpolate_clamped: size mismatch");
@@ -143,11 +144,11 @@ interpolate_clamped(double x,
143144

144145
double
145146
find_mean_tension(double strain,
146-
double Tmean,
147-
double Tmax,
148-
const Eigen::VectorXd& owc_strains,
149-
const Eigen::VectorXd& owc_tensions,
150-
WorkingCurveForm wc_form)
147+
double Tmean,
148+
double Tmax,
149+
const Eigen::VectorXd& owc_strains,
150+
const Eigen::VectorXd& owc_tensions,
151+
WorkingCurveForm wc_form)
151152
{
152153
(void)Tmean;
153154

@@ -340,7 +341,8 @@ load_seg_te_column(const std::string& path)
340341
if (!(row >> v)) {
341342
throw std::runtime_error(
342343
"Row has fewer numeric columns than expected at line " +
343-
std::to_string(lineno) + " in " + path + ": '" + line + "'");
344+
std::to_string(lineno) + " in " + path + ": '" + line +
345+
"'");
344346
}
345347
}
346348
vals.push_back(v);
@@ -355,11 +357,11 @@ load_seg_te_column(const std::string& path)
355357

356358
double
357359
jonswap_psd(double Hs,
358-
double Tp,
359-
double gamma,
360-
double omega,
361-
double sigma_a = 0.07,
362-
double sigma_b = 0.09)
360+
double Tp,
361+
double gamma,
362+
double omega,
363+
double sigma_a = 0.07,
364+
double sigma_b = 0.09)
363365
{
364366
if (!(omega > 0.0) || !(Tp > 0.0) || !(gamma > 0.0) || !(Hs >= 0.0)) {
365367
return 0.0;
@@ -396,13 +398,13 @@ slow_strain(double t, double seg_dur, double eps0)
396398

397399
Eigen::VectorXd
398400
surface_elevation_from_jonswap(double Hs,
399-
double Tp,
400-
double gamma,
401-
const Eigen::VectorXd& times,
402-
unsigned int n_omega_edges,
403-
double omega_min,
404-
double omega_max,
405-
std::mt19937& rng)
401+
double Tp,
402+
double gamma,
403+
const Eigen::VectorXd& times,
404+
unsigned int n_omega_edges,
405+
double omega_min,
406+
double omega_max,
407+
std::mt19937& rng)
406408
{
407409
if (n_omega_edges < 2) {
408410
throw std::runtime_error("n_omega_edges must be >= 2");
@@ -452,8 +454,7 @@ line1_output_from_input(const std::string& input_path)
452454
}
453455

454456
SimulationResult
455-
run_case(const WcCase& c,
456-
bool superimpose_fast)
457+
run_case(const WcCase& c, bool superimpose_fast)
457458
{
458459
MoorDynRAII md(c.input_file);
459460

@@ -520,10 +521,9 @@ run_case(const WcCase& c,
520521
strain_slow[i] = slow_strain(times[i], seg_dur, c.eps_0);
521522
}
522523

523-
const Eigen::VectorXd strain = superimpose_fast
524-
? (strain_slow + scale_WF * eta_WF +
525-
scale_LF * eta_LF)
526-
: strain_slow;
524+
const Eigen::VectorXd strain =
525+
superimpose_fast ? (strain_slow + scale_WF * eta_WF + scale_LF * eta_LF)
526+
: strain_slow;
527527
const Eigen::VectorXd x =
528528
x0 * (Eigen::VectorXd::Ones(strain.size()) + strain);
529529

@@ -532,7 +532,8 @@ run_case(const WcCase& c,
532532
dr[1] = 0.0;
533533
dr[2] = 0.0;
534534

535-
check_md(MoorDyn_Init(md.sys, r, dr), "MoorDyn_Init failed for: " + c.input_file);
535+
check_md(MoorDyn_Init(md.sys, r, dr),
536+
"MoorDyn_Init failed for: " + c.input_file);
536537

537538
double t = 0.0;
538539
double f[3] = { 0.0, 0.0, 0.0 };
@@ -553,13 +554,15 @@ run_case(const WcCase& c,
553554
t = t_in;
554555
}
555556

556-
check_md(MoorDyn_Close(md.sys), "MoorDyn_Close failed for: " + c.input_file);
557+
check_md(MoorDyn_Close(md.sys),
558+
"MoorDyn_Close failed for: " + c.input_file);
557559
md.sys = nullptr;
558560

559561
SimulationResult out;
560562
out.times = times;
561563
out.strain = strain;
562-
out.tension_output = load_seg_te_column(line1_output_from_input(c.input_file));
564+
out.tension_output =
565+
load_seg_te_column(line1_output_from_input(c.input_file));
563566
return out;
564567
}
565568

@@ -613,7 +616,8 @@ TEST_CASE("Syrope tests", "[syrope][working-curve]")
613616
Eigen::VectorXd tmax_mean(n);
614617
tmax_mean[0] = kTmax0;
615618
for (Eigen::Index i = 1; i < n; ++i) {
616-
tmax_mean[i] = (std::max)(tmax_mean[i - 1], sim.tension_output[i]);
619+
tmax_mean[i] =
620+
(std::max)(tmax_mean[i - 1], sim.tension_output[i]);
617621
}
618622

619623
Eigen::VectorXd tension_analytical(n);
@@ -626,7 +630,8 @@ TEST_CASE("Syrope tests", "[syrope][working-curve]")
626630
c.form);
627631
}
628632

629-
const double l2 = relative_l2(tension_analytical, sim.tension_output);
633+
const double l2 =
634+
relative_l2(tension_analytical, sim.tension_output);
630635
INFO("Relative L2 error = " << l2);
631636
REQUIRE(l2 < kL2Tol);
632637
}

0 commit comments

Comments
 (0)