FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
WakeCaster.h
1#pragma once
2
156#include <algorithm>
157#include <fhsim/ISimObjectLogger.h>
158#include <fhsim_environment/WakeSchedule.h>
159#include <fhsim_environment/WakeSourceSet.h>
160#include <marenv/wake/LumpedSource.h>
161#include <marenv/wake/WakeField.h>
162#include <marenv/wake/WakeRegistry.h> // WakeQuery
163#include <marenv/wake/WakeSelection.h>
164#include <marenv/wake/WakeTypes.h>
165#include <memory>
166#include <string>
167#include <vector>
168
169class ISimObjectCreator;
170
171namespace marenv::wake
172{
173class GriddedWake;
174class SourceSetWake;
175class WakeBuilder;
176} // namespace marenv::wake
177
178namespace environment
179{
180class EnvironmentProvider;
181} // namespace environment
182
183namespace environment::wake
184{
185
187namespace detail
188{
189
191struct RebuildSource;
193struct PrivateSources;
194
202{
203public:
211 WakeCaster(std::string name, const SourceSetWakeSettings& settings, double rho);
212 ~WakeCaster();
213
218 void Register(EnvironmentProvider& environment);
219
231 void Update(double T, const double* X, const WakeSourceSet& set, ISimObjectLogger& logger);
232
234 std::shared_ptr<marenv::wake::WakeField> Field() const;
236 std::shared_ptr<marenv::wake::WakeField> PrivateField() const { return m_privateField; }
239
247 const OwnSourceMap& OwnSources() const { return m_ownSources; }
248
256 void ExcludeJet(const marenv::wake::JetField* jet) { m_excludeJet = jet; }
257
259 const marenv::wake::LumpedSourceInput& LastLumpedInput() const { return m_lastLumpedInput; }
261 const marenv::wake::LumpedSourceResult& LastSource() const { return m_lastLumpedSource; }
263 const WakeSchedule& Schedule() const { return m_schedule; }
265 double LastRebuildSeconds() const { return m_lastRebuildSeconds; }
267 const double* SourceVelocity() const { return m_sourceVelocity; }
269 const marenv::wake::WakeFrame& LastFrame() const { return m_lastFrame; }
271 const marenv::wake::GridSpec& LastGrid() const { return m_lastGrid; }
273 double LastGridCutoff() const { return m_lastGridCutoff; }
274
275private:
277 bool SkipMalformedSource(double T, const WakeSourceSet& set, ISimObjectLogger& logger);
279 bool SkipNonFiniteCarrier(double T, const WakeSourceSet& set, ISimObjectLogger& logger);
281 bool RecheckMalformedSource(double T, const WakeSourceSet& set, ISimObjectLogger& logger);
283 static void CarrierVelocities(const WakeSourceSet& set, const double* X, std::vector<double>& velocities);
284 void FilterCarrierVelocities(double T, const WakeSourceSet& set);
286 void SourcePosition(double source[3]) const;
288 bool AmbientCurrentAtSource(double T, const double source[3], double current[3]) const;
290 void Rebuild(double T, const double* X, const WakeSourceSet& set, bool lookupFailed, ISimObjectLogger& logger);
297 std::vector<RebuildSource> CollectSources(double T, const double* X, const WakeSourceSet& set, marenv::wake::HeldWakes& others) const;
299 marenv::wake::WakeFrame MakeFrame(double T, const std::vector<RebuildSource>& sources, const std::vector<double>& weights, int numCarriers, double meanRelativeFlow[3]);
301 PrivateSources MarchPrivateSources(double T, const double* X, const WakeSourceSet& set, const std::vector<RebuildSource>& sources, const marenv::wake::HeldWakes& others, marenv::wake::WakeBuilder* builder) const;
303 std::string PublishPrivate(double T, marenv::wake::SourceSet sources, marenv::wake::WakeBuilder* builder, const double published[3], double blendTime);
308 bool CurrentLookupFails(double T, const WakeSourceSet& set, double failedAt[3]) const;
314 void PublishWithoutLumpedWake(double T, marenv::wake::SourceSet sources, marenv::wake::WakeBuilder* builder, const double frameOrigin[3]);
316 void HoldForFailedLookup(double T, const double* X, const WakeSourceSet& set, const double failedAt[3], ISimObjectLogger& logger);
318 void HoldLumpedWakeForFailedLookup(double T, const double failedAt[3], ISimObjectLogger& logger);
320 struct BuildChange
321 {
322 double ratio = -1.0;
323 double momentum = -1.0;
325 double Measure() const { return std::max(ratio, momentum); }
326 };
328 BuildChange MeasureChange(const std::vector<double>& ratios) const;
330 void PublishLumped(double T, const double published[3], const double frameOrigin[3]);
332 std::string LumpedRebuildLine(double T, double flowSpeed) const;
334 void LogRebuild(double T, const double* X, const WakeSourceSet& set, int numCast, int numSources, double meanFlowSpeed, const BuildChange& change, const std::string& warning,
335 ISimObjectLogger& logger);
337 void BuildLumped(const marenv::wake::LumpedSourceInput& input);
339 std::string LumpedDescription() const;
340
341 std::string m_name;
342 SourceSetWakeSettings m_settings;
343 double m_rho;
344 marenv::wake::KernelParams m_privateKernel;
345 marenv::wake::KernelParams m_lumpedKernel;
346 WakeSchedule m_schedule;
347 EnvironmentProvider* m_environment = nullptr;
348 std::shared_ptr<marenv::wake::SourceSetWake> m_lumpedField;
349 std::shared_ptr<marenv::wake::WakeField> m_privateField;
350 std::shared_ptr<marenv::wake::GriddedWake> m_griddedField;
351 std::shared_ptr<marenv::wake::SourceSetWake> m_directField;
352 const marenv::wake::JetField* m_excludeJet = nullptr;
353 OwnSourceMap m_ownSources;
354
355 std::vector<double> m_filteredCarrierVel;
356 double m_sourceVelocity[3] = {0.0, 0.0, 0.0};
357 std::vector<double> m_carrierWeights;
358 std::vector<double> m_carrierPositions;
359 std::vector<double> m_carrierVelocities;
360
361 std::string m_lastWarning;
362 double m_lastRebuildSeconds = 0.0;
363 marenv::wake::WakeFrame m_lastFrame {};
364 marenv::wake::GridSpec m_lastGrid {};
365 double m_lastGridCutoff = 0.0;
366 std::vector<double> m_previousRatios;
367 std::vector<double> m_previousDeficits;
368 double m_previousMomentum = 0.0;
369 marenv::wake::LumpedSourceInput m_lastLumpedInput {};
370 marenv::wake::LumpedSourceResult m_lastLumpedSource {};
371 bool m_hasLumped = false;
372 bool m_skippingNonFinite = false;
373 bool m_skippingMalformed = false;
374 bool m_topologyVerified = false;
375 int m_verifiedSources = -1;
376 int m_verifiedCarriers = -1;
377};
378
379} // namespace detail
380
381} // namespace environment::wake
Definition WakeCaster.h:202
double LastGridCutoff() const
The cutoff of the last Grid rebuild's private grid; 0 before the first.
Definition WakeCaster.h:273
const marenv::wake::GridSpec & LastGrid() const
The private grid of the last Grid rebuild; all zero before the first.
Definition WakeCaster.h:271
void Update(double T, const double *X, const WakeSourceSet &set, ISimObjectLogger &logger)
const marenv::wake::LumpedSourceResult & LastSource() const
The lumped source of the last rebuild, after relaxation; casts is false once a failed current lookup ...
Definition WakeCaster.h:261
const double * SourceVelocity() const
The filtered source velocity u_s, m/s, NED.
Definition WakeCaster.h:267
const marenv::wake::WakeFrame & LastFrame() const
The frame of the last rebuild; all zero before the first.
Definition WakeCaster.h:269
marenv::wake::WakeQuery Query() const
The query of the object's own sources: skip the lumped field, compose the private field in (C5); no o...
std::shared_ptr< marenv::wake::WakeField > Field() const
The registered lumped field; null before Register().
WakeCaster(std::string name, const SourceSetWakeSettings &settings, double rho)
void ExcludeJet(const marenv::wake::JetField *jet)
Definition WakeCaster.h:256
double LastRebuildSeconds() const
Wall-clock duration of the last rebuild, s.
Definition WakeCaster.h:265
const marenv::wake::LumpedSourceInput & LastLumpedInput() const
The lumped-source input of the last rebuild: summed source force, U_ref, ρ, rear-face centre and W·H.
Definition WakeCaster.h:259
const OwnSourceMap & OwnSources() const
Definition WakeCaster.h:247
const WakeSchedule & Schedule() const
The schedule: rebuild count, Freeze state and the last change, the larger of max|ΔR| of the private f...
Definition WakeCaster.h:263
void Register(EnvironmentProvider &environment)
std::shared_ptr< marenv::wake::WakeField > PrivateField() const
The unregistered private per-source field; null before Register() and with WakeEvaluation::None.
Definition WakeCaster.h:236
Definition WakeSelection.h:62
Definition JetField.h:134
Definition WakeBuilder.h:46
Definition FlukeAnchor.h:124
Definition WakeTypes.h:83
Definition WakeTypes.h:104
Definition LumpedSource.h:16
Definition LumpedSource.h:86
Definition WakeTypes.h:120
Definition WakeTypes.h:72
Definition WakeSelection.h:33