FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
TransitioningWaveField.h
1#pragma once
2
3#include <atomic>
4#include <marenv/AtomicSharedPtr.h>
5#include <marenv/wave/WaveField.h>
6#include <memory>
7#include <string>
8
9namespace marenv::wave
10{
11
42{
43public:
49 explicit TransitioningWaveField(std::shared_ptr<WaveField> initial);
50
51 ~TransitioningWaveField() override = default;
52
71 void StartTransition(std::shared_ptr<WaveField> newField,
72 double startTime,
73 double duration);
74
83 [[nodiscard]] std::shared_ptr<WaveField> GetCurrentField() const;
84
89 [[nodiscard]] bool IsSettled(double time) const;
90
91 // --- WaveField interface ---
92 // During a transition, each Compute* method evaluates both wave fields and
93 // returns the linearly interpolated result. Outside a transition, calls
94 // delegate directly to the current (destination) field.
95
97 [[nodiscard]] std::string SpectrumName() const override;
99 [[nodiscard]] std::string WaveTheoryName() const override;
100
102 marenv::Status ComputeSurfaceElevation(double time, const double pos[2], double& elevationOut) override;
103
109 [[nodiscard]] double MaxWaveElevation() const override;
111 marenv::Status ComputeSurfaceUnitNormal(double time, const double pos[2], double unitNormalOut[3]) override;
113 marenv::Status ComputeParticleVelocity(double time, const double pos[3], double velOut[3]) override;
115 marenv::Status ComputeParticleAcceleration(double time, const double pos[3], double accOut[3]) override;
117 marenv::Status ComputeDynamicPressure(double time, const double pos[3], double& pressureOut) override;
119 marenv::Status ComputeTotalPressure(double time, const double pos[3], double& pressureOut) override;
121 marenv::Status ComputePointQuery(double time, const double pos[3], double& surface_elevation, // clang-format off
122 double surface_unit_normal[3], double particle_velocity[3],
123 double particle_acceleration[3], double& pressure) override; // clang-format on
124
132 [[nodiscard]] InsecureDatapointers GetWaveComponents() const override;
133
138
145 [[nodiscard]] marenv::wave::WaveComponentData GetWaveComponentsCopy(double time, size_t maxComponents = 0) const override;
146
147private:
149 struct TransitionSnapshot
150 {
151 std::shared_ptr<WaveField> from;
152 std::shared_ptr<WaveField> to;
153 double t0 = 0.0;
154 double t1 = 0.0;
155 bool transitioning = false;
156 bool frozen = false;
157 double frozenAlpha = 0.0;
158 };
159
160 [[nodiscard]] std::shared_ptr<TransitionSnapshot> LoadSnapshot() const
161 {
162 return m_snapshot.load();
163 }
164
165 void StoreSnapshot(std::shared_ptr<TransitionSnapshot> snap)
166 {
167 m_snapshot.store(std::move(snap));
168 }
169
179 static double ComputeAlpha(const TransitionSnapshot& snap, double time);
180
186 static std::shared_ptr<WaveField> SourceAt(const TransitionSnapshot& snap, double time);
187
189 TransitioningWaveField(std::shared_ptr<WaveField> from, std::shared_ptr<WaveField> to, double alpha);
190
192};
193
194} // namespace marenv::wave
Definition AtomicSharedPtr.h:19
void store(std::shared_ptr< T > ptr)
Publishes ptr; readers that loaded the previous one keep it alive.
Definition AtomicSharedPtr.h:35
std::shared_ptr< T > load() const
The current pointer; null before the first store.
Definition AtomicSharedPtr.h:22
Definition TransitioningWaveField.h:42
marenv::Status ComputeTotalPressure(double time, const double pos[3], double &pressureOut) override
Computes total pressure; interpolates between source and destination during a transition.
marenv::Status ComputeDynamicPressure(double time, const double pos[3], double &pressureOut) override
Computes dynamic pressure; interpolates between source and destination during a transition.
double MaxWaveElevation() const override
marenv::Status ComputeParticleVelocity(double time, const double pos[3], double velOut[3]) override
Computes particle velocity; interpolates between source and destination during a transition.
marenv::Status ComputeParticleAcceleration(double time, const double pos[3], double accOut[3]) override
Computes particle acceleration; interpolates between source and destination during a transition.
marenv::Status ComputeSurfaceUnitNormal(double time, const double pos[2], double unitNormalOut[3]) override
Computes surface unit normal; interpolates component-wise and renormalises during a transition.
bool IsSettled(double time) const
std::shared_ptr< WaveField > GetCurrentField() const
marenv::wave::WaveComponentData GetWaveComponentsCopy(double time, size_t maxComponents=0) const override
marenv::Status ComputePointQuery(double time, const double pos[3], double &surface_elevation, double surface_unit_normal[3], double particle_velocity[3], double particle_acceleration[3], double &pressure) override
Computes a full point query; all outputs are interpolated during a transition.
marenv::Status ComputeSurfaceElevation(double time, const double pos[2], double &elevationOut) override
Computes surface elevation; interpolates between source and destination during a transition.
InsecureDatapointers GetWaveComponents() const override
void StartTransition(std::shared_ptr< WaveField > newField, double startTime, double duration)
TransitioningWaveField(std::shared_ptr< WaveField > initial)
marenv::wave::WaveComponentData GetWaveComponentsCopy() const override
std::string WaveTheoryName() const override
Returns the wave theory name of the current destination wave field.
std::string SpectrumName() const override
Returns the spectrum name of the current destination wave field.
Definition WaveField.h:41
Status
Definition marenv.h:44
Details of a wave component.
Definition WaveField.h:23
Pointers to wave component details.
Definition WaveField.h:46