FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
WakeSampleParts.h
1#pragma once
4
5#include <marenv/marenv.h>
6#include <marenv/wake/WakeTypes.h>
7
8namespace marenv::wake
9{
13inline double BlendWeight(double t, double start, double time)
14{
15 if (!(time > 0.0))
16 return 1.0;
17 const double tau = (t - start) / time;
18 if (tau <= 0.0)
19 return 0.0;
20 if (tau >= 1.0)
21 return 1.0;
22 return tau * tau * (3.0 - 2.0 * tau);
23}
24
29{
30 bool inside = false;
31 double deficit = 0.0;
32 double weightedVelocity[3] = {0.0, 0.0, 0.0};
33
35 void Add(double share, const WakeSample& sample)
36 {
37 inside = true;
38 deficit += share * sample.deficit;
39 for (int i = 0; i < 3; ++i)
40 weightedVelocity[i] += share * sample.deficit * sample.sourceVelocity[i];
41 }
42
44 void Add(double share, const WakeBlendSum& part)
45 {
46 inside = true;
47 deficit += share * part.deficit;
48 for (int i = 0; i < 3; ++i)
49 weightedVelocity[i] += share * part.weightedVelocity[i];
50 }
51
58 Status ToSample(const double zeroDeficitVelocity[3], WakeSample& out) const
59 {
60 if (!inside) {
61 out = WakeSample {0.0, {0.0, 0.0, 0.0}};
63 }
64 out.deficit = deficit;
65 for (int i = 0; i < 3; ++i)
66 out.sourceVelocity[i] = deficit > 0.0 ? weightedVelocity[i] / deficit : zeroDeficitVelocity[i];
67 return Status::OK;
68 }
69};
70
79{
80 bool currentInside = false;
83 double start = 0.0;
84 double time = 0.0;
85
87 WakeBlendSum At(double t) const
88 {
89 WakeBlendSum sum;
90 const double weight = BlendWeight(t, start, time);
91 if (weight > 0.0 && currentInside)
92 sum.Add(weight, current);
93 if (weight < 1.0 && previous.inside)
94 sum.Add(1.0 - weight, previous);
95 return sum;
96 }
97};
98
111{
112 bool blending = false;
116 double zeroDeficitVelocity[3] = {0.0, 0.0, 0.0};
117
124 Status At(double t, WakeSample& out) const
125 {
126 if (!blending) {
127 out = sample;
128 return status;
129 }
130 return blend.At(t).ToSample(zeroDeficitVelocity, out);
131 }
132};
133} // namespace marenv::wake
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
Definition WakeSampleParts.h:79
WakeBlendSum At(double t) const
The sums at t: the snapshot blended to with BlendWeight(t), the state blended from with 1 - BlendWeig...
Definition WakeSampleParts.h:87
WakeSample current
The snapshot blended to, unweighted.
Definition WakeSampleParts.h:81
bool currentInside
The snapshot blended to has extent at the point.
Definition WakeSampleParts.h:80
double time
Duration of the blend, s.
Definition WakeSampleParts.h:84
WakeBlendSum previous
The state blended from at full weight (a single snapshot, R22); not inside without one.
Definition WakeSampleParts.h:82
double start
Start of the blend, s.
Definition WakeSampleParts.h:83
Definition WakeSampleParts.h:29
double deficit
Sum of share d.
Definition WakeSampleParts.h:31
void Add(double share, const WakeSample &sample)
Adds a snapshot's sample with its share of the blend.
Definition WakeSampleParts.h:35
Status ToSample(const double zeroDeficitVelocity[3], WakeSample &out) const
Definition WakeSampleParts.h:58
bool inside
True once a snapshot contributed.
Definition WakeSampleParts.h:30
void Add(double share, const WakeBlendSum &part)
Adds the sums of a state blended from with its share of the blend.
Definition WakeSampleParts.h:44
double weightedVelocity[3]
Sum of share d u_s, m/s, NED.
Definition WakeSampleParts.h:32
Definition WakeSampleParts.h:111
bool blending
True: the field blends at or after the sample time and At(t) weighs blend at t.
Definition WakeSampleParts.h:112
Status status
Not blending: the status of WakeField::Sample() at the sample time.
Definition WakeSampleParts.h:113
double zeroDeficitVelocity[3]
Blending: the source velocity the field reports where d = 0, m/s, NED.
Definition WakeSampleParts.h:116
WakeBlendSamples blend
Blending: the samples of the blend's snapshots at the sample time.
Definition WakeSampleParts.h:115
Status At(double t, WakeSample &out) const
Definition WakeSampleParts.h:124
WakeSample sample
Not blending: WakeField::Sample() at the sample time.
Definition WakeSampleParts.h:114
Definition WakeTypes.h:21
double sourceVelocity[3]
Deficit-weighted source velocity u_s of the contributing sources, m/s, NED.
Definition WakeTypes.h:23
double deficit
Combined velocity deficit d in [0, 1]; the velocity ratio is r = 1 - d.
Definition WakeTypes.h:22