Files
Ymir/tests/naval/TestRudderForces.cpp
T
vinihcrosaandClaude Sonnet 4.6 dd4e79cbd6 feat(naval): add naval domain module (M2)
NavalForceModel bridge pattern keeps core::ForceModel interface intact
while providing NavalContext (environment, speedToWater, speedToWind,
EMA q_avg) to all naval models via bindContext.

Force models: Inertial (Coriolis), Restoring (hydrostatic spring),
Damping (potential + linear/quadratic), Squat (ICORELS shallow-water),
Wind (REGULAR/ACSINKAGE), Current (OBOKATA section-integration and
REGULAR with Van der Pol VIM RK4), Thrust (open-water Kt), Rudder
(Prandtl lift), Tug (PUSH/PULL/ESCORTING with bilinear table).

Wave engine: JONSWAP/PIERSON/REGULAR spectrum, Mitsuyasu cos-2S
directional spreading, WAMIT RAO interpolation in WaveForces.

NavalSimulation wraps core::Simulation, rebuilds NavalContext each
step, maintains EMA (tau=16.5s). 63/63 tests pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-22 01:14:23 -03:00

60 lines
1.5 KiB
C++

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_approx.hpp>
#include <ymir/naval/forces/RudderForces.h>
#include <ymir/naval/NavalContext.h>
#include <ymir/core/BodyState.h>
using Catch::Approx;
using namespace ymir::naval;
static NavalContext makeCtx(double u = 5.0)
{
ymir::Vector6 q{};
ymir::Vector6 qdot{};
qdot[0] = u;
ymir::BodyState bs(q, qdot, 0.0, 0.1);
NavalContext ctx{};
ctx.state = bs;
ctx.speedToWater[0] = u;
return ctx;
}
TEST_CASE("RudderForces zero angle produces no lateral force")
{
RudderForces::Config cfg{};
RudderForces::RudderConfig r{};
r.position = {-50.0, 0.0, -3.0};
r.area = 20.0;
r.aspectRatio = 2.0;
r.angle_deg = 0.0;
cfg.rudders.push_back(r);
RudderForces model(cfg);
NavalContext ctx = makeCtx(5.0);
model.bindContext(&ctx);
auto forces = model.compute(ctx.state);
REQUIRE(forces.f[1] == Approx(0.0).margin(1e-6));
REQUIRE(forces.f[5] == Approx(0.0).margin(1e-6));
}
TEST_CASE("RudderForces positive angle produces sway force and yaw moment")
{
RudderForces::Config cfg{};
RudderForces::RudderConfig r{};
r.position = {-50.0, 0.0, -3.0};
r.area = 20.0;
r.aspectRatio = 2.0;
r.angle_deg = 20.0; // 20 degree rudder
cfg.rudders.push_back(r);
RudderForces model(cfg);
NavalContext ctx = makeCtx(5.0);
model.bindContext(&ctx);
auto forces = model.compute(ctx.state);
REQUIRE(forces.f[1] != Approx(0.0).margin(1e-3));
REQUIRE(forces.f[5] != Approx(0.0).margin(1e-3));
}