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 double* X, const WakeSourceSet& set, ISimObjectLogger& logger);
280 void FilterCarrierVelocities(double T, const double* X, const WakeSourceSet& set);
282 void SourcePosition(double source[3]) const;
284 bool AmbientCurrentAtSource(double T, const double source[3], double current[3]) const;
286 void Rebuild(double T, const double* X, const WakeSourceSet& set, bool lookupFailed, ISimObjectLogger& logger);
293 std::vector<RebuildSource> CollectSources(double T, const double* X, const WakeSourceSet& set, marenv::wake::HeldWakes& others) const;
295 marenv::wake::WakeFrame MakeFrame(double T, const std::vector<RebuildSource>& sources, const std::vector<double>& weights, int numCarriers, double meanRelativeFlow[3]);
297 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;
299 std::string PublishPrivate(double T, marenv::wake::SourceSet sources, marenv::wake::WakeBuilder* builder, const double published[3], double blendTime);
304 bool CurrentLookupFails(double T, const WakeSourceSet& set, double failedAt[3]) const;
310 void PublishWithoutLumpedWake(double T, marenv::wake::SourceSet sources, marenv::wake::WakeBuilder* builder, const double frameOrigin[3]);
312 void HoldForFailedLookup(double T, const double* X, const WakeSourceSet& set, const double failedAt[3], ISimObjectLogger& logger);
314 void HoldLumpedWakeForFailedLookup(double T, const double failedAt[3], ISimObjectLogger& logger);
316 struct BuildChange
317 {
318 double ratio = -1.0;
319 double momentum = -1.0;
321 double Measure() const { return std::max(ratio, momentum); }
322 };
324 BuildChange MeasureChange(const std::vector<double>& ratios) const;
326 void PublishLumped(double T, const double published[3], const double frameOrigin[3]);
328 std::string LumpedRebuildLine(double T, double flowSpeed) const;
330 void LogRebuild(double T, const double* X, const WakeSourceSet& set, int numCast, int numSources, double meanFlowSpeed, const BuildChange& change, const std::string& warning,
331 ISimObjectLogger& logger);
333 void BuildLumped(const marenv::wake::LumpedSourceInput& input);
335 std::string LumpedDescription() const;
336
337 std::string m_name;
338 SourceSetWakeSettings m_settings;
339 double m_rho;
340 marenv::wake::KernelParams m_privateKernel;
341 marenv::wake::KernelParams m_lumpedKernel;
342 WakeSchedule m_schedule;
343 EnvironmentProvider* m_environment = nullptr;
344 std::shared_ptr<marenv::wake::SourceSetWake> m_lumpedField;
345 std::shared_ptr<marenv::wake::WakeField> m_privateField;
346 std::shared_ptr<marenv::wake::GriddedWake> m_griddedField;
347 std::shared_ptr<marenv::wake::SourceSetWake> m_directField;
348 const marenv::wake::JetField* m_excludeJet = nullptr;
349 OwnSourceMap m_ownSources;
350
351 std::vector<double> m_filteredCarrierVel;
352 double m_sourceVelocity[3] = {0.0, 0.0, 0.0};
353 std::vector<double> m_carrierWeights;
354 std::vector<double> m_carrierPositions;
355
356 std::string m_lastWarning;
357 double m_lastRebuildSeconds = 0.0;
358 marenv::wake::WakeFrame m_lastFrame {};
359 marenv::wake::GridSpec m_lastGrid {};
360 double m_lastGridCutoff = 0.0;
361 std::vector<double> m_previousRatios;
362 std::vector<double> m_previousDeficits;
363 double m_previousMomentum = 0.0;
364 marenv::wake::LumpedSourceInput m_lastLumpedInput {};
365 marenv::wake::LumpedSourceResult m_lastLumpedSource {};
366 bool m_hasLumped = false;
367 bool m_skippingNonFinite = false;
368 bool m_skippingMalformed = false;
369};
370
371} // namespace detail
372
373} // 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 WakeTypes.h:81
Definition WakeTypes.h:102
Definition LumpedSource.h:16
Definition LumpedSource.h:66
Definition WakeTypes.h:118
Definition WakeTypes.h:70
Definition WakeSelection.h:31