|
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) |
Public Member Functions inherited from marenv::wake::BlendedField< GriddedSnapshot > | |
| Status | Sample (double t, const double pos[3], Value &out) const override |
| Traits::Parts | SampleParts (double t, const double pos[3]) const override |
| bool | MayReach (const WakeQueryRegion ®ion) const override |
| std::uint64_t | Revision () const override |
| The number of publishes (see WakeField::Revision()). | |
| bool | StaticFrom (double t) const override |
| No blend at t or later and the published snapshot at rest (see WakeField::StaticFrom()). | |
| void | SampleMany (double t, std::span< const std::array< double, 3 > > positions, std::span< Value > out, std::span< Status > status) const override |
| Sample() at every point, the published state loaded once (see WakeField::SampleMany()). | |
| void | Sketch (double t, FieldSketch &out) const override |
| Appends the sketch of the snapshot blended to at t (see WakeField::Sketch()); nothing before the first publish. | |
Additional Inherited Members | |
Public Types inherited from marenv::wake::BlendedField< GriddedSnapshot > | |
| using | Value = typename Traits::Value |
| The sample type of the field, Traits::Value. | |
Protected Types inherited from marenv::wake::BlendedField< GriddedSnapshot > | |
| using | Blend = WakeBlend< GriddedSnapshot, Value, typename Traits::Sum, typename Traits::Samples > |
| The blend between the two published snapshots (WakeBlend). | |
Protected Member Functions inherited from marenv::wake::BlendedField< GriddedSnapshot > | |
| Status | SampleWith (double t, const double pos[3], const Sampler &sampler, Value &out) const |
| Traits::Parts | PartsWith (double t, const double pos[3], const Sampler &sampler) const |
| SampleParts() with each snapshot sampled by sampler, as SampleWith(). | |
Protected Attributes inherited from marenv::wake::BlendedField< GriddedSnapshot > | |
| Blend | m_blend |
| The published snapshots and the blend between them (single writer). | |
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.
Sample() returns Status::OK inside the grid of a contributing snapshot and Status::ERROR_NOT_SET outside all of them or before the first Publish(), with d = 0; where d = 0 it reports the snapshot's source velocity (WakeFieldTraits). MayReach() is false only if no snapshot sampled in the region's interval or later has the region inside its grid (the snapshot blended to counts from its publish instant on, the one blended from until the blend has ended by tBegin, WakeBlend::MayReach()); true before the first Publish(). The virtuals that only load the state and forward to the snapshot are those of BlendedField; Sketch() appends the box of the snapshot blended to at t.
| 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. |