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 double weightedShading = 0.0;
34 double weightedRatio = 0.0;
35
37 void Add(double share, const WakeSample& sample)
38 {
39 inside = true;
40 deficit += share * sample.deficit;
41 for (int i = 0; i < 3; ++i)
42 weightedVelocity[i] += share * sample.deficit * sample.sourceVelocity[i];
43 weightedShading += share * sample.deficit * sample.shading;
44 weightedRatio += share * sample.deficit * sample.inflowRatio;
45 }
46
48 void Add(double share, const WakeBlendSum& part)
49 {
50 inside = true;
51 deficit += share * part.deficit;
52 for (int i = 0; i < 3; ++i)
53 weightedVelocity[i] += share * part.weightedVelocity[i];
54 weightedShading += share * part.weightedShading;
55 weightedRatio += share * part.weightedRatio;
56 }
57
64 Status ToSample(const double zeroDeficitVelocity[3], WakeSample& out) const
65 {
66 if (!inside) {
67 out = WakeSample {0.0, {0.0, 0.0, 0.0}};
69 }
70 out.deficit = deficit;
71 for (int i = 0; i < 3; ++i)
72 out.sourceVelocity[i] = deficit > 0.0 ? weightedVelocity[i] / deficit : zeroDeficitVelocity[i];
73 out.shading = deficit > 0.0 ? weightedShading / deficit : 0.0;
74 out.inflowRatio = deficit > 0.0 ? weightedRatio / deficit : 1.0;
75 return Status::OK;
76 }
77};
78
87{
88 bool currentInside = false;
91 double start = 0.0;
92 double time = 0.0;
93
95 WakeBlendSum At(double t) const
96 {
97 WakeBlendSum sum;
98 const double weight = BlendWeight(t, start, time);
99 if (weight > 0.0 && currentInside)
100 sum.Add(weight, current);
101 if (weight < 1.0 && previous.inside)
102 sum.Add(1.0 - weight, previous);
103 return sum;
104 }
105};
106
119{
120 bool blending = false;
124 double zeroDeficitVelocity[3] = {0.0, 0.0, 0.0};
125
132 Status At(double t, WakeSample& out) const
133 {
134 if (!blending) {
135 out = sample;
136 return status;
137 }
138 return blend.At(t).ToSample(zeroDeficitVelocity, out);
139 }
140};
141} // namespace marenv::wake
Status
Definition marenv.h:44
@ 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:87
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:95
WakeSample current
The snapshot blended to, unweighted.
Definition WakeSampleParts.h:89
bool currentInside
The snapshot blended to has extent at the point.
Definition WakeSampleParts.h:88
double time
Duration of the blend, s.
Definition WakeSampleParts.h:92
WakeBlendSum previous
The state blended from at full weight (a single snapshot, R22); not inside without one.
Definition WakeSampleParts.h:90
double start
Start of the blend, s.
Definition WakeSampleParts.h:91
Definition WakeSampleParts.h:29
double weightedRatio
Sum of share d m, m the inflow ratio of the snapshot (MENV-0097).
Definition WakeSampleParts.h:34
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:37
Status ToSample(const double zeroDeficitVelocity[3], WakeSample &out) const
Definition WakeSampleParts.h:64
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:48
double weightedShading
Sum of share d w_e, w_e the effective shading weight of the snapshot's sample (MENV-0097).
Definition WakeSampleParts.h:33
double weightedVelocity[3]
Sum of share d u_s, m/s, NED.
Definition WakeSampleParts.h:32
Definition WakeSampleParts.h:119
bool blending
True: the field blends at or after the sample time and At(t) weighs blend at t.
Definition WakeSampleParts.h:120
Status status
Not blending: the status of WakeField::Sample() at the sample time.
Definition WakeSampleParts.h:121
double zeroDeficitVelocity[3]
Blending: the source velocity the field reports where d = 0, m/s, NED.
Definition WakeSampleParts.h:124
WakeBlendSamples blend
Blending: the samples of the blend's snapshots at the sample time.
Definition WakeSampleParts.h:123
Status At(double t, WakeSample &out) const
Definition WakeSampleParts.h:132
WakeSample sample
Not blending: WakeField::Sample() at the sample time.
Definition WakeSampleParts.h:122
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 shading
Effective shading weight w_e in [0, 1] at the point (MENV-0097): the weight w of the field's lumped s...
Definition WakeTypes.h:24
double inflowRatio
Ratio m in (0, 1] of the shaded to the ambient mean square inflow of the field's lumped source (MENV-...
Definition WakeTypes.h:25
double deficit
Combined velocity deficit d in [0, 1]; the velocity ratio is r = 1 - d.
Definition WakeTypes.h:22