FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
NetWaveKc.h
1#pragma once
2
8#include <marenv/wave/WaveField.h>
9
10#include <algorithm>
11#include <cmath>
12#include <cstdlib>
13#include <limits>
14#include <numbers>
15#include <string>
16
17namespace net_wave_kc
18{
19
29inline double HorizontalAmplitude(const marenv::wave::WaveField& waves, double z)
30{
31 const auto components = waves.GetWaveComponents();
32 const double depth = std::max(z, 0.0);
33 double sumSquares = 0.0;
34 for (int i = 0; i < components.numWaves; i++) {
35 const double k = components.waveNumber[i];
36 const double h = components.depth[i];
37 const double decay = std::isinf(h) ? std::exp(-k * depth) : std::cosh(k * (h - depth)) / std::sinh(k * h);
38 const double amplitude = components.omega[i] * components.zetaA[i] * decay;
39 sumSquares += amplitude * amplitude;
40 }
41 return std::sqrt(sumSquares);
42}
43
45inline double PeakPeriod(const marenv::wave::WaveField& waves)
46{
47 const auto components = waves.GetWaveComponents();
48 int peak = -1;
49 for (int i = 0; i < components.numWaves; i++) {
50 if (peak < 0 || components.zetaA[i] > components.zetaA[peak])
51 peak = i;
52 }
53 return peak < 0 ? 0.0 : 2.0 * std::numbers::pi / components.omega[peak];
54}
55
57inline constexpr const char* kDefaultWaveEffectMaxDepth = "Auto";
58
65{
66 bool automatic = false;
67 double depth = std::numeric_limits<double>::infinity();
68};
69
75inline bool ParseWaveEffectMaxDepth(const std::string& text, WaveEffectDepth& setting)
76{
77 if (text == "Inf") {
78 setting = WaveEffectDepth {};
79 return true;
80 }
81 if (text == "Auto") {
82 setting = WaveEffectDepth {true, std::numeric_limits<double>::infinity()};
83 return true;
84 }
85 if (text.empty())
86 return false;
87 char* end = nullptr;
88 const double depth = std::strtod(text.c_str(), &end);
89 if (end != text.c_str() + text.size() || !std::isfinite(depth) || depth < 0.0)
90 return false;
91 setting = WaveEffectDepth {false, depth};
92 return true;
93}
94
100inline double MaxDepth(const WaveEffectDepth& setting, const marenv::wave::WaveField& waves)
101{
102 if (!setting.automatic)
103 return setting.depth;
104 const auto components = waves.GetWaveComponents();
105 if (components.numWaves <= 0)
106 return std::numeric_limits<double>::infinity();
107 double smallest = components.waveNumber[0];
108 double bottom = components.depth[0];
109 for (int i = 1; i < components.numWaves; i++) {
110 smallest = std::min(smallest, components.waveNumber[i]);
111 bottom = std::min(bottom, components.depth[i]);
112 }
113 if (!(smallest > 0.0))
114 return std::numeric_limits<double>::infinity();
115 const double depth = std::log(100.0) / smallest;
116 return depth >= bottom ? std::numeric_limits<double>::infinity() : depth;
117}
118
119} // namespace net_wave_kc
Definition WaveField.h:50
virtual InsecureDatapointers GetWaveComponents() const =0
const double *RESTRICT omega
Pointer to wave frequency array.
Definition WaveField.h:58
Definition NetWaveKc.h:65
bool automatic
"Auto": the depth follows the wave field.
Definition NetWaveKc.h:66
double depth
The depth [m] if not automatic; +infinity is no cut.
Definition NetWaveKc.h:67