FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
JetField.h
1#pragma once
4
5#include <marenv/marenv.h>
6#include <marenv/wake/WakeField.h> // WakeQueryRegion
7#include <marenv/wake/WakeSampleParts.h> // BlendWeight
8
9namespace marenv::wake
10{
15{
16 double velocity[3];
17};
18
25{
26 bool inside = false;
27 double velocity[3] = {0.0, 0.0, 0.0};
28
30 void Add(double share, const JetSample& sample)
31 {
32 inside = true;
33 for (int i = 0; i < 3; ++i)
34 velocity[i] += share * sample.velocity[i];
35 }
36
38 void Add(double share, const JetBlendSum& part)
39 {
40 inside = true;
41 for (int i = 0; i < 3; ++i)
42 velocity[i] += share * part.velocity[i];
43 }
44
49 {
50 for (int i = 0; i < 3; ++i)
51 out.velocity[i] = inside ? velocity[i] : 0.0;
53 }
54};
55
60{
61 bool currentInside = false;
64 double start = 0.0;
65 double time = 0.0;
66
68 JetBlendSum At(double t) const
69 {
70 JetBlendSum sum;
71 const double weight = BlendWeight(t, start, time);
72 if (weight > 0.0 && currentInside)
73 sum.Add(weight, current);
74 if (weight < 1.0 && previous.inside)
75 sum.Add(1.0 - weight, previous);
76 return sum;
77 }
78};
79
87{
88 bool blending = false;
92
97 Status At(double t, JetSample& out) const
98 {
99 if (!blending) {
100 out = sample;
101 return status;
102 }
103 return blend.At(t).ToSample(out);
104 }
105};
106
111{
112 double pos[3];
113 double shaftDir[3];
117 double rho;
118};
119
129{
130public:
131 virtual ~JetField() = default;
132
141 virtual Status Sample(double t, const double pos[3], JetSample& out) const = 0;
142
147 virtual JetSampleParts SampleParts(double t, const double pos[3]) const
148 {
149 JetSampleParts parts;
150 parts.status = Sample(t, pos, parts.sample);
151 return parts;
152 }
153
163 virtual bool MayReach(const WakeQueryRegion& region) const
164 {
165 (void)region;
166 return true;
167 }
168
169protected:
170 JetField() = default;
171};
172} // namespace marenv::wake
Definition JetField.h:129
virtual bool MayReach(const WakeQueryRegion &region) const
Definition JetField.h:163
virtual JetSampleParts SampleParts(double t, const double pos[3]) const
Definition JetField.h:147
virtual Status Sample(double t, const double pos[3], JetSample &out) const =0
Status
Definition marenv.h:40
@ ERROR_NOT_SET
No valid data (outside a field's horizontal extent, a NaN position, no field); the value is not set (...
@ OK
The value is valid.
double BlendWeight(double t, double start, double time)
Definition WakeSampleParts.h:13
Policy mixin: this type is neither copyable nor movable.
Definition marenv.h:96
Definition JetField.h:60
JetBlendSum previous
The state blended from at full weight (a single snapshot, R22); not inside without one.
Definition JetField.h:63
JetBlendSum At(double t) const
The sum at t: the snapshot blended to with BlendWeight(t), the state blended from with 1 - BlendWeigh...
Definition JetField.h:68
JetSample current
The snapshot blended to, unweighted.
Definition JetField.h:62
double time
Duration of the blend, s.
Definition JetField.h:65
bool currentInside
The snapshot blended to has extent at the point.
Definition JetField.h:61
double start
Start of the blend, s.
Definition JetField.h:64
Definition JetField.h:25
Status ToSample(JetSample &out) const
Definition JetField.h:48
void Add(double share, const JetSample &sample)
Adds a snapshot's sample with its share of the blend.
Definition JetField.h:30
double velocity[3]
Sum of share Δu, m/s, NED.
Definition JetField.h:27
void Add(double share, const JetBlendSum &part)
Adds the sum of a state blended from with its share of the blend.
Definition JetField.h:38
bool inside
True once a snapshot contributed.
Definition JetField.h:26
Definition JetField.h:87
JetBlendSamples blend
Blending: the samples of the blend's snapshots at the sample time.
Definition JetField.h:91
bool blending
True: the field blends at or after the sample time and At(t) weighs the blend at t.
Definition JetField.h:88
Status status
Not blending: the status of JetField::Sample() at the sample time.
Definition JetField.h:89
Status At(double t, JetSample &out) const
Definition JetField.h:97
JetSample sample
Not blending: JetField::Sample() at the sample time.
Definition JetField.h:90
Definition JetField.h:15
double velocity[3]
Excess velocity Δu, m/s, NED.
Definition JetField.h:16
Definition JetField.h:111
double rho
Water density, kg/m^3, > 0.
Definition JetField.h:117
double pos[3]
Propeller centre p₀, m, NED.
Definition JetField.h:112
double propellerDiameter
D_p, m, > 0.
Definition JetField.h:114
double advanceSpeed
u_a, the body's speed through the water along shaftDir, m/s; clamped to U = max(u_a,...
Definition JetField.h:116
double shaftDir[3]
Direction of the thrust on the body (forward for a ship going ahead), NED; normalised by the field....
Definition JetField.h:113
double effectiveThrust
T_eff = T (1 - t), N; nothing is cast for T_eff <= 0.
Definition JetField.h:115
Definition WakeField.h:17