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
9#include <array>
10#include <cstddef>
11#include <cstdint>
12#include <span>
13
14namespace marenv::wake
15{
20{
21 double velocity[3];
22};
23
30{
31 bool inside = false;
32 double velocity[3] = {0.0, 0.0, 0.0};
33
35 void Add(double share, const JetSample& sample)
36 {
37 inside = true;
38 for (int i = 0; i < 3; ++i)
39 velocity[i] += share * sample.velocity[i];
40 }
41
43 void Add(double share, const JetBlendSum& part)
44 {
45 inside = true;
46 for (int i = 0; i < 3; ++i)
47 velocity[i] += share * part.velocity[i];
48 }
49
54 {
55 for (int i = 0; i < 3; ++i)
56 out.velocity[i] = inside ? velocity[i] : 0.0;
58 }
59};
60
65{
66 bool currentInside = false;
69 double start = 0.0;
70 double time = 0.0;
71
73 JetBlendSum At(double t) const
74 {
75 JetBlendSum sum;
76 const double weight = BlendWeight(t, start, time);
77 if (weight > 0.0 && currentInside)
78 sum.Add(weight, current);
79 if (weight < 1.0 && previous.inside)
80 sum.Add(1.0 - weight, previous);
81 return sum;
82 }
83};
84
92{
93 bool blending = false;
97
102 Status At(double t, JetSample& out) const
103 {
104 if (!blending) {
105 out = sample;
106 return status;
107 }
108 return blend.At(t).ToSample(out);
109 }
110};
111
116{
117 double pos[3];
118 double shaftDir[3];
122 double rho;
123};
124
134{
135public:
136 virtual ~JetField() = default;
137
146 virtual Status Sample(double t, const double pos[3], JetSample& out) const = 0;
147
152 virtual JetSampleParts SampleParts(double t, const double pos[3]) const
153 {
154 JetSampleParts parts;
155 parts.status = Sample(t, pos, parts.sample);
156 return parts;
157 }
158
168 virtual bool MayReach(const WakeQueryRegion& region) const
169 {
170 (void)region;
171 return true;
172 }
173
175 virtual std::uint64_t Revision() const { return 0; }
176
178 virtual bool StaticFrom(double t) const
179 {
180 (void)t;
181 return false;
182 }
183
185 virtual void SampleMany(double t, std::span<const std::array<double, 3>> positions, std::span<JetSample> out, std::span<Status> status) const
186 {
187 for (std::size_t i = 0; i < positions.size(); ++i)
188 status[i] = Sample(t, positions[i].data(), out[i]);
189 }
190
192 virtual void Sketch(double t, FieldSketch& out) const
193 {
194 (void)t;
195 (void)out;
196 }
197
198protected:
199 JetField() = default;
200};
201} // namespace marenv::wake
Definition JetField.h:134
virtual std::uint64_t Revision() const
The change signal of the jet, as WakeField::Revision(); the default, for a field that cannot tell,...
Definition JetField.h:175
virtual void Sketch(double t, FieldSketch &out) const
Appends the jet's axis at t for a visualiser, as JetField::Sketch(); the default appends nothing.
Definition JetField.h:192
virtual bool MayReach(const WakeQueryRegion &region) const
Definition JetField.h:168
virtual JetSampleParts SampleParts(double t, const double pos[3]) const
Definition JetField.h:152
virtual Status Sample(double t, const double pos[3], JetSample &out) const =0
virtual bool StaticFrom(double t) const
Whether Sample() stays the same from t on until Revision() changes, as WakeField::StaticFrom(); the d...
Definition JetField.h:178
virtual void SampleMany(double t, std::span< const std::array< double, 3 > > positions, std::span< JetSample > out, std::span< Status > status) const
Samples many points at one time, as WakeField::SampleMany(); the default calls Sample() at each point...
Definition JetField.h:185
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 FieldSketch.h:16
Definition JetField.h:65
JetBlendSum previous
The state blended from at full weight (a single snapshot, R22); not inside without one.
Definition JetField.h:68
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:73
JetSample current
The snapshot blended to, unweighted.
Definition JetField.h:67
double time
Duration of the blend, s.
Definition JetField.h:70
bool currentInside
The snapshot blended to has extent at the point.
Definition JetField.h:66
double start
Start of the blend, s.
Definition JetField.h:69
Definition JetField.h:30
Status ToSample(JetSample &out) const
Definition JetField.h:53
void Add(double share, const JetSample &sample)
Adds a snapshot's sample with its share of the blend.
Definition JetField.h:35
double velocity[3]
Sum of share Δu, m/s, NED.
Definition JetField.h:32
void Add(double share, const JetBlendSum &part)
Adds the sum of a state blended from with its share of the blend.
Definition JetField.h:43
bool inside
True once a snapshot contributed.
Definition JetField.h:31
Definition JetField.h:92
JetBlendSamples blend
Blending: the samples of the blend's snapshots at the sample time.
Definition JetField.h:96
bool blending
True: the field blends at or after the sample time and At(t) weighs the blend at t.
Definition JetField.h:93
Status status
Not blending: the status of JetField::Sample() at the sample time.
Definition JetField.h:94
Status At(double t, JetSample &out) const
Definition JetField.h:102
JetSample sample
Not blending: JetField::Sample() at the sample time.
Definition JetField.h:95
Definition JetField.h:20
double velocity[3]
Excess velocity Δu, m/s, NED.
Definition JetField.h:21
Definition JetField.h:116
double rho
Water density, kg/m^3, > 0.
Definition JetField.h:122
double pos[3]
Propeller centre p₀, m, NED.
Definition JetField.h:117
double propellerDiameter
D_p, m, > 0.
Definition JetField.h:119
double advanceSpeed
u_a, the body's speed through the water along shaftDir, m/s; clamped to U = max(u_a,...
Definition JetField.h:121
double shaftDir[3]
Direction of the thrust on the body (forward for a ship going ahead), NED; normalised by the field....
Definition JetField.h:118
double effectiveThrust
T_eff = T (1 - t), N; nothing is cast for T_eff <= 0.
Definition JetField.h:120
Definition WakeField.h:23