|
FhSim
3.1.0
Marine systems simulation
|
#include <GriddedWake.h>
Inheritance diagram for marenv::wake::GriddedWake:
Collaboration diagram for marenv::wake::GriddedWake:Public Member Functions | |
| void | Publish (std::shared_ptr< const GriddedSnapshot > snapshot, double blendTime=0.0) |
| Status | Sample (double t, const double pos[3], WakeSample &out) const override |
| WakeSampleParts | SampleParts (double t, const double pos[3]) const override |
Public Member Functions inherited from marenv::wake::WakeField | |
| virtual bool | MayReach (const WakeQueryRegion ®ion) const |
Wake field of many sources, superposed once into a grid in a moving frame (contract C4).
A casting structure builds a GriddedSnapshot with WakeBuilder and publishes it here. Sample() extrapolates the snapshot's frame to pose(t) = origin + velocity (t - t0), interpolates the grid trilinearly in the frame and returns the snapshot's source velocity.
Blending (plan B4, review B-4; the weights and state are WakeBlend): Publish() cross-fades from the field in use to the new snapshot over a blend time that starts at the new snapshot's frame.t0, with the C1 smoothstep s = 3 tau^2 - 2 tau^3, tau = (t - t0) / blendTime. The weights act on the waked velocity: d = (1 - s) d_old + s d_new, and d u_s is blended the same way, so the waked flow u_amb + d (u_s - u_amb) is the cross-fade of the two waked flows. The blend depends on t only, never on the state, so a multistep integrator sees a C1 right-hand side. The first snapshot fades in from no wake. Publish() refuses a new blend while the previous one is still running (lead ruling R22, WakeBlend::Publish(), as SourceSetWake), so a state never holds more than two snapshots: keep the blend time at or below the publish interval.
History (MENV-0011): Sample() is defined for t at or after the newest published t0. A later Publish() trims an ended blend, or with blendTime 0 drops the previous state, so a query for an earlier t may return a different deficit afterwards. Publish at the current time and do not query back in time.
Thread safety (see WakeField::Sample): register the field during setup only. After that one writer thread may call Publish() concurrently with readers; Sample() is const and thread-safe. Publish() builds a new immutable BlendState (the new snapshot and the state it blends from; trimming an ended blend makes a new state, it never edits a published one) and swaps it in through std::atomic<std::shared_ptr<const ...>>, the pattern of marenv::wave::LinearWaveTheory. A query running concurrently with Publish() evaluates either the old or the new state, never a mix. Publish() reads the current state and then stores the new one, so two concurrent writers could drop one of the two snapshots: keep to one writer. Sample() takes no mutex; the libstdc++ spin bit of the atomic shared pointer is the known caveat.
| void marenv::wake::GriddedWake::Publish | ( | std::shared_ptr< const GriddedSnapshot > | snapshot, |
| double | blendTime = 0.0 |
||
| ) |
Publishes a snapshot to subsequent queries.
| [in] | snapshot | The new snapshot, from WakeBuilder::Finish. |
| [in] | blendTime | Duration of the cross-fade from the field in use, s, starting at snapshot->frame.t0; 0 replaces the field in use at once, for every t (also before t0), without blending. |
| std::invalid_argument | for a null snapshot, a non-finite snapshot->frame.t0 or a negative blend time. |
| std::logic_error | if the previous blend has not ended by snapshot->frame.t0 (R22, WakeBlend::Publish()); the field in use stays. |
|
overridevirtual |
Returns the deficit and source velocity at pos (see WakeField::Sample).
| [in] | t | Simulation time, s. |
| [in] | pos | Position (x,y,z) to query, m, NED. |
| [out] | out | Deficit in [0, 1] and deficit-weighted source velocity. |
Implements marenv::wake::WakeField.
|
overridevirtual |
Returns the sample split into the parts the blend weighs (see WakeField::SampleParts; owner ruling R136).
While the published state blends at t or later, the parts hold the samples of the snapshot blended to and of the snapshot blended from at (t, pos); otherwise Sample(t, pos).
Reimplemented from marenv::wake::WakeField.