FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
marenv::EnvironmentFacade Class Reference

#include <EnvironmentFacade.h>

+ Inheritance diagram for marenv::EnvironmentFacade:
+ Collaboration diagram for marenv::EnvironmentFacade:

Public Member Functions

 EnvironmentFacade ()
 
void SetWaves (std::shared_ptr< wave::WaveField > wave)
 
void SetWaves (const wave::WaveEnergySpectrum::SpectrumParameters &params, wave::WaveTheory waveTheory, int numWaves, uint32_t seed)
 
void TransitionSeaState (const wave::WaveEnergySpectrum::SpectrumParameters &params, wave::WaveTheory waveTheory, int numWaves, uint32_t seed, double startTime, double duration)
 
void TransitionSeaState (std::shared_ptr< wave::WaveField > newWaves, double startTime, double duration)
 
void SettleSeaState (double time)
 
void SetBathymetry (std::shared_ptr< seafloor::BathymetryField > bathymetry)
 
const std::shared_ptr< wave::WaveField > & GetWaves () const
 
double MaxWaveElevation () const
 
std::shared_ptr< seafloor::BathymetryField > GetBathymetry ()
 
void AddCurrentField (const std::string &id, std::shared_ptr< current::CurrentField > field)
 
void RemoveCurrentField (const std::string &id)
 
bool HasCurrentField (const std::string &id) const
 
std::shared_ptr< current::CurrentField > GetCurrentField (const std::string &id) const
 
void AddWakeField (const std::string &id, std::shared_ptr< wake::WakeField > field)
 
void RemoveWakeField (const std::string &id)
 
bool HasWakeField (const std::string &id) const
 
std::shared_ptr< wake::WakeField > GetWakeField (const std::string &id) const
 
void AddJetField (const std::string &id, std::shared_ptr< wake::JetField > field)
 
std::shared_ptr< wake::JetField > GetJetField (const std::string &id) const
 
std::vector< std::string > GetWakeFieldIds () const
 
std::vector< std::string > GetJetFieldIds () const
 
std::vector< std::string > GetCurrentFieldIds () const
 
Status GetSubmergence (double time, const double pos[3], double &submergence)
 
Status GetSurfaceElevation (double time, const double pos[2], double &elevationOut)
 
Status GetSurfaceUnitNormal (double time, const double pos[2], double *unitNormalOut)
 
Status GetParticleVelocity (double time, const double pos[3], double *velOut)
 
Status GetParticleAcceleration (double time, const double pos[3], double *accOut)
 
Status GetDynamicPressure (double time, const double pos[3], double &pressureOut)
 
Status GetTotalPressure (double time, const double pos[3], double &pressureOut)
 
Status GetSeaDepth (const double pos[2], double &depthOut)
 
Status ComputeRayIntersection (const double origin[3], const double direction[3], double &distanceOut, double maxSearchDistance=100, double startSearchDistance=-1, double stepSize=1.0, double convergenceTolerance=0.01)
 
Status GetCurrentVelocity (double time, const double pos[3], double *velOut)
 
Status GetDensity (double time, const double pos[3], double &density)
 
Status PointEnvironmentQuery (double time, const double pos[3], EnvironmentQuery &queryResult)
 
Status GetWaterVelocity (double time, const double pos[3], WaterVelocityTerms terms, double velOut[3]) const
 
Status GetWaterVelocity (double time, const double pos[3], const WaterVelocityParts &parts, double velOut[3]) const
 
Status GetWaterVelocity (double time, const double pos[3], const WaterVelocityParts &parts, const wake::HeldWakes &held, std::size_t point, double velOut[3]) const
 
void GetWaterVelocities (double time, std::span< const std::array< double, 3 > > positions, const WaterVelocityParts &parts, std::span< std::array< double, 3 > > velocities, std::span< Status > statuses) const
 
Status GetWaterVelocity (double time, const double pos[3], const WaterVelocityParts &parts, const wake::WakeQuery &query, const wake::HeldWakes *held, std::size_t point, double velOut[3], WakedFlow *detail=nullptr) const
 
Status GetWakedFlow (double time, const double pos[3], WakedFlow &out) const
 
Status GetWakedFlow (double time, const double pos[3], const wake::WakeQuery &query, WakedFlow &out) const
 
wake::WakeSelection SelectWakes (const wake::WakeQueryRegion &region, const wake::WakeQuery &query={}) const
 
wake::HeldWakes HoldWakes (std::span< const std::array< double, 3 > > positions, double T, const wake::WakeQuery &query={}, double cutoff=0.0, const wake::OwnTagsAt &ownTags={}) const
 
std::uint64_t GetWakeRevision () const
 A number that grows whenever a wake or jet field is registered, removed or published again: wake::WakeRegistry::Revision().
 
bool WakesStaticFrom (double t) const
 Whether the wake and jet fields stay the same from t on until GetWakeRevision() changes: wake::WakeRegistry::StaticFrom().
 
double GetWakeDeficit (double time, const double pos[3]) const
 
void GetWakeDeficits (double time, std::span< const std::array< double, 3 > > positions, std::span< double > deficits) const
 
marenv::Status GetAmbientCurrent (double time, const double pos[3], double vel[3]) const
 
marenv::Status GetWakedCurrent (double time, const double pos[3], const marenv::wake::WakeQuery &query, double vel[3]) const
 
double SeabedImageDepth (const double pos[3]) const
 

Detailed Description

Defines an environment.

The role of an environment is to answer all requests for information about the simulated environment. It is composed of several other classes which implement different aspects of the environment. Such aspects are waves, currents, sea floor and effects from e.g. ships in motion (wake fields). Wind is not implemented.

Constructor & Destructor Documentation

◆ EnvironmentFacade()

marenv::EnvironmentFacade::EnvironmentFacade ( )
inline

Default constructor. Initialises with null/default field implementations:

NullWaveField (no waves), FlatSeafloor (200 m flat bottom). No current fields are registered by default.

Member Function Documentation

◆ AddCurrentField()

void marenv::EnvironmentFacade::AddCurrentField ( const std::string &  id,
std::shared_ptr< current::CurrentField >  field 
)

Adds a current field with the given identifier. The velocities of all registered current fields are summed to produce the total ambient current.

Parameters
[in]idUnique identifier for this current field.
[in]fieldThe current field to add.
Exceptions
std::invalid_argumentif a current field with the given id already exists or the field is null.

Setup only (MENV-0096): AddCurrentField(), RemoveCurrentField(), SetWaves() and SetBathymetry() change plain members that the const queries read without a lock. Call them before the first query, or while no query runs; they are not thread safe against queries.

◆ AddJetField()

void marenv::EnvironmentFacade::AddJetField ( const std::string &  id,
std::shared_ptr< wake::JetField >  field 
)

Adds a jet field with the given identifier (ADR 0003).

The jets of every query that includes the wakes term (WaterVelocityTerms::Full, NoWaves) are summed and added after the deficit composition, u = u_amb + d_tot (u_s - u_amb) + sum Δu_j.

Parameters
[in]idUnique identifier among the wake and jet fields.
[in]fieldThe jet field to add.
Exceptions
std::invalid_argumentif a wake or jet field with the given id already exists.

◆ AddWakeField()

void marenv::EnvironmentFacade::AddWakeField ( const std::string &  id,
std::shared_ptr< wake::WakeField >  field 
)

Adds a wake field with the given identifier.

Parameters
[in]idUnique identifier for this wake field.
[in]fieldThe wake field to add.
Exceptions
std::invalid_argumentif a wake field with the given id already exists.

◆ ComputeRayIntersection()

Status marenv::EnvironmentFacade::ComputeRayIntersection ( const double  origin[3],
const double  direction[3],
double &  distanceOut,
double  maxSearchDistance = 100,
double  startSearchDistance = -1,
double  stepSize = 1.0,
double  convergenceTolerance = 0.01 
)

Returns the distance a ray must travel before intercepting the seafloor: the first crossing along the ray (owner ruling R132; see seafloor::BathymetryField::ComputeRayIntersection). An origin at the seafloor or inside it is a hit at distance 0 (owner ruling R133).

Parameters
[in]originPosition (x,y,z) of the origin of the ray
[in]directionThe unit direction (x,y,z) of the ray
[out]distanceOutThe distance the beam travelled before reaching the seabed; -1 without an intersection.
[in]maxSearchDistanceThe maximum distance from the origin to search for an intersection.
[in]startSearchDistanceThe distance that anchors the search grid; negative for the flat-seabed estimate. It does not move the result away from the first crossing.
[in]stepSizeThe search step size.
[in]convergenceToleranceThe vertical error tolerance between a computed point on the ray and a point on the seafloor to consider an intersection found.
Returns
marenv::Status::OK on success; marenv::Status::NOT_APPLICABLE_NOT_SET when the ray does not cross the seafloor within maxSearchDistance (owner ruling R134); marenv::Status::ERROR_NOT_SET for an invalid direction or range, or without a seafloor.

◆ GetAmbientCurrent()

marenv::Status marenv::EnvironmentFacade::GetAmbientCurrent ( double  time,
const double  pos[3],
double  vel[3] 
) const

Returns the ambient current at a point: the sum of all current fields, without any wake.

Parameters
[in]timeSimulation time [s].
[in]posPosition in NED frame [x, y, z] [m].
[out]velAmbient current [m/s], NED: the sum of the current fields whose status is usable (marenv::IsUsable); zero when no current field is registered.
Returns
The status of the first current field that is not usable (marenv::IsUsable), whose field is left out of the sum; else marenv::Status::OUT_OF_RANGE_INACCURATE when a field was clamped, e.g. a depth profile beyond its layers (owner ruling R122); else marenv::Status::OK.

A wake field that needs the flow at its own source uses this, since it samples no wake field and so cannot recurse into the caller. It is GetWaterVelocity(time, pos, marenv::WaterVelocityTerms::CurrentOnly, vel).

◆ GetBathymetry()

std::shared_ptr< seafloor::BathymetryField > marenv::EnvironmentFacade::GetBathymetry ( )

Gets the bathymetry to be used.

Returns
Bathymetry to be used.

◆ GetCurrentField()

std::shared_ptr< current::CurrentField > marenv::EnvironmentFacade::GetCurrentField ( const std::string &  id) const

Returns the current field with the given identifier.

Parameters
[in]idIdentifier of the current field.
Returns
Shared pointer to the current field.
Exceptions
std::invalid_argumentif the identifier does not exist.

◆ GetCurrentFieldIds()

std::vector< std::string > marenv::EnvironmentFacade::GetCurrentFieldIds ( ) const

Returns a list of all registered current field identifiers.

Returns
Vector of identifiers, in registration order.

◆ GetCurrentVelocity()

Status marenv::EnvironmentFacade::GetCurrentVelocity ( double  time,
const double  pos[3],
double *  velOut 
)

Returns the water current velocity at a specific position.

Parameters
[in]timeCurrent simulation time.
[in]posPosition (x,y,z) for which the current velocity is desired.
[out]velOutThe current velocity at pos.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

Includes effects of only currents, not waves, modified by any registered wake fields (composition in EnvironmentFacade).

The WaterVelocityTerms::NoWaves terms: current and wakes, no waves, GetWaterVelocity(time, pos, WaterVelocityTerms::NoWaves, velOut); new code asks GetWaterVelocity() (owner ruling O3a). The wake composition is u = u_amb + d_tot (u_s - u_amb) (see GetWakedFlow()). It runs also when no current field is registered: then u_amb = 0 and a moving wake source gives u = d_tot u_s. u_amb is the sum of the current fields whose status at pos is usable (IsUsable(): Status::OK, or Status::OUT_OF_RANGE_INACCURATE for a value clamped at the edge of a depth profile, owner ruling R122); the status is the worse of all current fields (marenv::Status operators, so it does not depend on the order of the fields): a status that is not usable, else Status::OUT_OF_RANGE_INACCURATE if a field returned it (MENV-0013, MENV-0053, MENV-0090). The value is unspecified when the status is not usable.

◆ GetDensity()

Status marenv::EnvironmentFacade::GetDensity ( double  time,
const double  pos[3],
double &  density 
)

Returns the water density at a specific position

Parameters
[in]timeCurrent simulation time.
[in]posPosition (x,y,z) for which the water density is desired.
[out]densityThe water density at given position and time.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

◆ GetDynamicPressure()

Status marenv::EnvironmentFacade::GetDynamicPressure ( double  time,
const double  pos[3],
double &  pressureOut 
)

Returns the dynamic pressure at a specific position.

Parameters
[in]timeCurrent simulation time.
[in]posPosition (x,y,z) for which the pressure is desired.
[out]pressureOutThe pressure at pos.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

◆ GetJetField()

std::shared_ptr< wake::JetField > marenv::EnvironmentFacade::GetJetField ( const std::string &  id) const

Returns the jet field with the given identifier.

Parameters
[in]idIdentifier of the jet field.
Returns
Shared pointer to the jet field.
Exceptions
std::invalid_argumentif no jet field has the identifier.

◆ GetJetFieldIds()

std::vector< std::string > marenv::EnvironmentFacade::GetJetFieldIds ( ) const

Returns a list of all registered jet field identifiers (ADR 0003).

Returns
Vector of identifiers, in registration order.

◆ GetParticleAcceleration()

Status marenv::EnvironmentFacade::GetParticleAcceleration ( double  time,
const double  pos[3],
double *  accOut 
)

Returns the particle acceleration at a specific position.

Parameters
[in]timeCurrent simulation time.
[in]posPosition (x,y,z) for which the particle acceleration is desired.
[out]accOutThe particle acceleration at pos.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

Wave particle acceleration only; the current is not included.

◆ GetParticleVelocity()

Status marenv::EnvironmentFacade::GetParticleVelocity ( double  time,
const double  pos[3],
double *  velOut 
)

Returns the particle velocity at a specific position.

Parameters
[in]timeCurrent simulation time.
[in]posPosition (x,y,z) for which the particle velocity is desired.
[out]velOutThe particle velocity at pos.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

Includes effects of both current and waves. The current part is modified by any registered wake fields (composition in EnvironmentFacade), as in GetCurrentVelocity.

The WaterVelocityTerms::Full terms: current, wakes and waves, GetWaterVelocity(time, pos, WaterVelocityTerms::Full, velOut). The current part is the ambient current with the wake composition applied (see GetWakedFlow()); the wave particle velocity is not waked. Equals GetWakedFlow().waked.

◆ GetSeaDepth()

Status marenv::EnvironmentFacade::GetSeaDepth ( const double  pos[2],
double &  depthOut 
)

Returns the sea depth at a specific position.

Parameters
[in]posPosition (x,y) for which sea depth is desired.
[out]depthOutThe sea depth at pos.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

◆ GetSubmergence()

Status marenv::EnvironmentFacade::GetSubmergence ( double  time,
const double  pos[3],
double &  submergence 
)

Calculates the submergence of a specific position.

Parameters
[in]timeTime
[in]posPosition
[out]submergenceThe submergence of the position
Returns
marenv::Status::OK on success. See marenv::Status for other values

◆ GetSurfaceElevation()

Status marenv::EnvironmentFacade::GetSurfaceElevation ( double  time,
const double  pos[2],
double &  elevationOut 
)

Returns the surface elevation at a specific position.

Parameters
[in]timeCurrent simulation time.
[in]posPosition (x,y) for which surface elevation is desired.
[out]elevationOutSurface elevation at pos.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

◆ GetSurfaceUnitNormal()

Status marenv::EnvironmentFacade::GetSurfaceUnitNormal ( double  time,
const double  pos[2],
double *  unitNormalOut 
)

Returns the unit normal vector of the surface at a specific position.

Parameters
[in]timeCurrent simulation time.
[in]posPosition (x,y) for which the unit normal surface vector is desired.
[out]unitNormalOutThe unit normal surface vector at pos.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

◆ GetTotalPressure()

Status marenv::EnvironmentFacade::GetTotalPressure ( double  time,
const double  pos[3],
double &  pressureOut 
)

Returns the total pressure at a specific position.

Parameters
[in]timeCurrent simulation time.
[in]posPosition (x,y,z) for which the pressure is desired.
[out]pressureOutThe pressure at pos.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

Includes both dynamic and static pressure. It is gauge pressure (owner ruling D8): rho g z in water below the free surface (z positive downward) plus the wave dynamic pressure, and 0 in air.

◆ GetWakedCurrent()

marenv::Status marenv::EnvironmentFacade::GetWakedCurrent ( double  time,
const double  pos[3],
const marenv::wake::WakeQuery &  query,
double  vel[3] 
) const

Returns the waked current at a point, without waves, composing the wake fields a query names.

Parameters
[in]timeSimulation time [s].
[in]posPosition in NED frame [x, y, z] [m].
[in]queryThe registered field to skip and the unregistered field to add (GetWakedFlow with a WakeQuery, contract C5).
[out]velu = u_amb + d_tot (u_s - u_amb) [m/s], NED, with u_amb the ambient current (GetAmbientCurrent: the sum of the usable current fields, R122 (i)) and the wake composition of the query.
Returns
The status of the first current field that is not usable (marenv::IsUsable), whose field is left out of the sum; else marenv::Status::OUT_OF_RANGE_INACCURATE when a field was clamped, e.g. a depth profile beyond its layers (owner ruling R122); else marenv::Status::OK.

The free stream a wake caster needs at its own source: the other wakes, never its own field (query.exclude) and never the waves (KF2012 §2.8). It equals the current part of GetWakedFlow(time, pos, query, out).waked bit for bit, whatever the current status (ENV-0064).

Note
Do not call this concurrently with wake-field registration.

◆ GetWakeDeficit()

double marenv::EnvironmentFacade::GetWakeDeficit ( double  time,
const double  pos[3] 
) const

Returns the combined wake deficit of all registered wake fields at a point.

Parameters
[in]timeSimulation time [s].
[in]posPosition in NED frame [x, y, z] [m].
Returns
d_tot in [0, 1], the fields composed by the momentum-flux rule (marenv R95): 0 is undisturbed flow, 1 moves the water with the sources. A field that returns a status other than OK contributes nothing. The waked current is u = u_amb + d_tot (u_s - u_amb); see GetWakedFlow. No jet is sampled: the jets add velocity, not a deficit.
Note
Do not call this concurrently with wake-field registration or current-field registration (the current is sampled too, its value is not used).

◆ GetWakeDeficits()

void marenv::EnvironmentFacade::GetWakeDeficits ( double  time,
std::span< const std::array< double, 3 > >  positions,
std::span< double >  deficits 
) const

GetWakeDeficit() at many points at one time, bit for bit, each wake field loaded once (marenv::wake::WakeRegistry::ComposeMany()).

Parameters
[in]timeSimulation time [s].
[in]positionsPositions in the NED frame [m].
[out]deficitsd_tot per position; as many as positions.

◆ GetWakedFlow() [1/2]

Status marenv::EnvironmentFacade::GetWakedFlow ( double  time,
const double  pos[3],
const wake::WakeQuery &  query,
WakedFlow &  out 
) const

Returns the ambient and the waked flow at a point, with one field excluded and one added (contract C5).

Parameters
[in]timeSimulation time, s.
[in]posPosition (x,y,z) to query, m, NED.
[in]queryThe registered field to skip and the unregistered field to add.
[out]outAmbient velocity, waked velocity, combined deficit and source count.
Returns
marenv::Status::OK on success.

As GetWakedFlow(time, pos, out), except that the registered field query.exclude and the registered jet query.excludeJet are not sampled and the field query.own is sampled after the registered ones and multiplied onto their composition D, d_tot = 1 - (1 - D) (1 - d_own) (R88, R95): the own field is a net's private per-panel field, whose sources are normalised by their local, already shaded inflow (doc/wake.md section 4). out.deficit and out.numSources include it. query.own must not be registered, or it counts twice. GetWakedFlow(time, pos, out) and GetParticleVelocity() equal this call with WakeQuery{}.

◆ GetWakedFlow() [2/2]

Status marenv::EnvironmentFacade::GetWakedFlow ( double  time,
const double  pos[3],
WakedFlow &  out 
) const

Returns the ambient and the waked flow at a point (contract C5).

Parameters
[in]timeSimulation time, s.
[in]posPosition (x,y,z) to query, m, NED.
[out]outAmbient velocity, waked velocity, combined deficit and source count.
Returns
marenv::Status::OK on success; else the worse (marenv::Status operators) of the wave status and the current status as GetCurrentVelocity() (a clamped depth profile gives Status::OUT_OF_RANGE_INACCURATE and is summed, a failing current field is skipped).

Every registered wake field is sampled at pos. A field that returns a status other than Status::OK (Status::ERROR_NOT_SET outside the field) contributes nothing; a returned deficit is clamped to [0, 1], and a NaN deficit contributes nothing. The fields compose by the momentum-flux rule, d_tot (1 - d_tot) = sum d_i (1 - d_i) where that has a root below the branch deficit, else the capped linear sum or 1/2 (owner ruling R95, replacing R88's min(1, sum d_i); wake::MomentumFluxSum), with the source velocity u_s the deficit-weighted mean of the u_s,i, and the waked current is u = u_amb + d_tot (u_s - u_amb). Every registered jet field is sampled too, and the jets are added after the deficits, u = u_amb + d_tot (u_s - u_amb) + sum Δu_j (ADR 0003; out.numJets counts them).

out.waked equals GetParticleVelocity(). The wake composition runs whether or not a current field is registered; with none, the ambient current is zero.

◆ GetWakeField()

std::shared_ptr< wake::WakeField > marenv::EnvironmentFacade::GetWakeField ( const std::string &  id) const

Returns the wake field with the given identifier.

Parameters
[in]idIdentifier of the wake field.
Returns
Shared pointer to the wake field.
Exceptions
std::invalid_argumentif the identifier does not exist.

◆ GetWakeFieldIds()

std::vector< std::string > marenv::EnvironmentFacade::GetWakeFieldIds ( ) const

Returns a list of all registered wake field identifiers.

Returns
Vector of identifiers, in registration order.

◆ GetWaterVelocities()

void marenv::EnvironmentFacade::GetWaterVelocities ( double  time,
std::span< const std::array< double, 3 > >  positions,
const WaterVelocityParts &  parts,
std::span< std::array< double, 3 > >  velocities,
std::span< Status >  statuses 
) const

GetWaterVelocity(time, pos, parts, vel) at many points, bit for bit, the wakes composed by wake::WakeRegistry::ComposeMany().

Parameters
[in]timeSimulation time, s.
[in]positionsThe points, m, NED.
[in]partsThe parts to sum.
[out]velocitiesOne water velocity per point, m/s, NED; as many as positions.
[out]statusesOne status per point; as many as positions.
Exceptions
std::invalid_argumentif velocities or statuses has fewer entries than positions.

The way to sample a grid from several threads: the wake and jet fields are loaded once per call, not once per point (see wake::WakeField::SampleMany()).

◆ GetWaterVelocity() [1/4]

Status marenv::EnvironmentFacade::GetWaterVelocity ( double  time,
const double  pos[3],
const WaterVelocityParts &  parts,
const wake::HeldWakes &  held,
std::size_t  point,
double  velOut[3] 
) const

Returns the sum of the given parts of the water velocity at a point, with a held wake composition (owner rulings R46, O2a).

Parameters
[in]timeSimulation time, s; the held composition is weighed at it (wake::HeldWakes::At()).
[in]posPosition (x,y,z) to query, m, NED.
[in]partsThe parts to sum; the wakes and the jets come from the held composition, the current and the waves are live.
[in]heldThe compositions held at the caller's points.
[in]pointThe index of the point in held.
[out]velOutWater velocity, m/s, NED.
Returns
As GetWaterVelocity(time, pos, parts, velOut).

With the composition the held selection gives at pos and time, bit for bit GetWaterVelocity(time, pos, parts, velOut). Thread-safe for different points (wake::HeldWakes::At()).

◆ GetWaterVelocity() [2/4]

Status marenv::EnvironmentFacade::GetWaterVelocity ( double  time,
const double  pos[3],
const WaterVelocityParts &  parts,
const wake::WakeQuery &  query,
const wake::HeldWakes *  held,
std::size_t  point,
double  velOut[3],
WakedFlow *  detail = nullptr 
) const
inline

The one water-velocity query: the given parts at a point, with the wakes of a query composed live or held (plan E1).

Parameters
[in]timeSimulation time, s; a held composition is weighed at it (wake::HeldWakes::At()).
[in]posPosition (x,y,z) to query, m, NED.
[in]partsThe parts to sum (WaterVelocityParts); they alone decide the terms, the jets included.
[in]queryThe wake query of the live composition (wake::WakeRegistry::Compose()); not read with held, whose selection applied it.
[in]heldThe compositions held at the caller's points (wake::WakeSelection::Hold()), or nullptr to compose the wakes live.
[in]pointThe index of the point in held; not read without it.
[out]velOutWater velocity, m/s, NED.
[out]detailIf not null, also the ambient current, velOut as waked, and the deficit and counts of the composition. Live, the composition holds only the asked parts; held, it holds what the take sampled (the velocity is the same, the counts may differ).
Returns
The worse (marenv::Status operators) of the wave status if the waves are asked and the current status if the current or the wakes are asked (the wakes act on the current), else Status::OK.

Every other water-velocity call of the facade is this query: GetWaterVelocity() of terms or parts with WakeQuery{} and no held composition, GetWaterVelocity(time, pos, parts, held, point, vel) with WakeQuery{}, GetWakedFlow() with every part. Only what the parts need is sampled: no wake field without parts.wakes, no jet without parts.jets. The current and the waves are always live. A held composition taken at pos and time gives the live query's velocity bit for bit. Thread-safe as GetWaterVelocity(time, pos, parts, velOut), and for different points of held (wake::HeldWakes::At()).

◆ GetWaterVelocity() [3/4]

Status marenv::EnvironmentFacade::GetWaterVelocity ( double  time,
const double  pos[3],
const WaterVelocityParts &  parts,
double  velOut[3] 
) const

Returns the sum of the given parts of the water velocity at a point.

Parameters
[in]timeSimulation time, s.
[in]posPosition (x,y,z) to query, m, NED.
[in]partsThe parts to sum (WaterVelocityParts).
[out]velOutWater velocity, m/s, NED.
Returns
The worse (marenv::Status operators) of the wave status if the waves are asked and the current status if the current or the wakes are asked (the wakes act on the current), else Status::OK.

Only what the parts need is sampled: no wake field without wakes, no jet without jets. Each WaterVelocityTerms selection is the parts selection with the jets going with the wakes, bit for bit (Full: all four; NoWaves: no waves; NoWakes: current and waves; CurrentOnly: current). Thread-safe as the queries it makes: the wake fields as WakeField::Sample(), the current and wave fields as CurrentField::GetCurrent() and WaveField's queries.

◆ GetWaterVelocity() [4/4]

Status marenv::EnvironmentFacade::GetWaterVelocity ( double  time,
const double  pos[3],
WaterVelocityTerms  terms,
double  velOut[3] 
) const

Returns the water velocity of the given terms at a point (owner rulings O1a, O2a).

Parameters
[in]timeSimulation time, s.
[in]posPosition (x,y,z) to query, m, NED.
[in]termsThe terms to include: current, wakes and/or waves.
[out]velOutWater velocity, m/s, NED.
Returns
With waves (Full, NoWakes) the worse of the wave status and the current status (marenv::Status operators); without waves (NoWaves, CurrentOnly) the current status (see GetCurrentVelocity()).

The one rule: the water velocity is the live ambient current, with the composition of every registered wake field applied, plus the live waves; terms drops the waves and/or the wakes. Full equals GetParticleVelocity() and NoWaves equals GetCurrentVelocity(), bit for bit; NoWakes and CurrentOnly apply no wake. The query is exact and live: every wake field is sampled, nothing is held. A receiver that must leave its own wake out holds a selection (SelectWakes()) and asks GetWaterVelocity(time, pos, parts, held, point, vel).

◆ GetWaves()

const std::shared_ptr< wave::WaveField > & marenv::EnvironmentFacade::GetWaves ( ) const

Gets the wave to be used.

Returns
Wave to be used: a reference to the held pointer, so a per-call user (GetWaves().get()) copies no shared_ptr. It stays valid until SetWaves() or a sea-state transition replaces the waves (setup only, MENV-0096); a caller that keeps the waves copies the pointer.

◆ HasCurrentField()

bool marenv::EnvironmentFacade::HasCurrentField ( const std::string &  id) const

Returns true if a current field with the given identifier exists.

Parameters
[in]idIdentifier to check.

◆ HasWakeField()

bool marenv::EnvironmentFacade::HasWakeField ( const std::string &  id) const

Returns true if a wake field with the given identifier exists.

Parameters
[in]idIdentifier to check.

◆ HoldWakes()

wake::HeldWakes marenv::EnvironmentFacade::HoldWakes ( std::span< const std::array< double, 3 > >  positions,
double  T,
const wake::WakeQuery &  query = {},
double  cutoff = 0.0,
const wake::OwnTagsAt &  ownTags = {} 
) const

Selects the wake fields and jets that may reach the points and holds them there at time T: SelectWakes(wake::EnclosingRegion(positions, T, cutoff), query).Hold(T, positions, ownTags).

Parameters
[in]positionsThe points, m, NED; at least one.
[in]TThe hold time, s.
[in]queryThe registered field and jet to skip, the own field to add.
[in]cutoff0 the exact tier, > 0 the cutoff tier (wake::WakeQueryRegion::cutoff).
[in]ownTagsThe own field's sources to leave out at each point (ENV-0107); empty leaves out the query's ownExcludedTags.
Exceptions
std::invalid_argumentif positions is empty. The held wakes count the selected fields and jets: wake::HeldWakes::NumFields(), NumJets().

◆ MaxWaveElevation()

double marenv::EnvironmentFacade::MaxWaveElevation ( ) const

Returns an upper bound of |wave elevation| at every position and time (owner ruling R66).

Returns
wave::WaveField::MaxWaveElevation() of the wave field set now, 0 without one.

A point at depth z > MaxWaveElevation() + h, h the half-size of a body around it, is submerged whatever the waves (GetSubmergence() > h), so a caller can skip the wave elevation there. The bound holds for the waves set and published at the call; SetWaves() or a blend of the wave components voids it.

0 means no waves: no wave elevation, particle velocity or particle acceleration anywhere (MENV-0064), so GetWaves()->ComputeParticleVelocity() and ComputeParticleAcceleration() need not be called.

◆ PointEnvironmentQuery()

Status marenv::EnvironmentFacade::PointEnvironmentQuery ( double  time,
const double  pos[3],
EnvironmentQuery &  queryResult 
)

Calculates multiple properties of the environment in one call.

Parameters
[in]timeSimulation time.
[in]posPosition.
[out]queryResultThe result of the query.
Returns
marenv::Status::OK on success. See marenv::Status for other values.

With a wave field set (the default is a NullWaveField), current_velocity is the waked current, as GetCurrentVelocity() (WaterVelocityTerms::NoWaves), particle_velocity is the wave particle velocity plus the waked current, as GetParticleVelocity() (WaterVelocityTerms::Full), and the status is the worse of that of GetCurrentVelocity() and that of the wave field's point query (marenv::Status operators; the current status if equal rank). The pressure is gauge pressure (WaveField::ComputeTotalPressure()). The density is marenv::seawaterDensity for a point below the free surface, 1.2 kg/m^3 above it, the rule of GetDensity(). Without a wave field (SetWaves() with a null pointer) the sea is calm (owner ruling 2026-11-04, MENV-0095): the wave field is a NullWaveField, so there is no wave elevation, velocity or acceleration, the pressure is the hydrostatic gauge pressure, and the status is that of the current.

◆ RemoveCurrentField()

void marenv::EnvironmentFacade::RemoveCurrentField ( const std::string &  id)

Removes the current field with the given identifier.

Parameters
[in]idIdentifier of the current field to remove.

Setup only, not thread safe with queries (see AddCurrentField()).

Exceptions
std::invalid_argumentif no current field with the given id exists.

◆ RemoveWakeField()

void marenv::EnvironmentFacade::RemoveWakeField ( const std::string &  id)

Removes the wake field with the given identifier.

Parameters
[in]idIdentifier of the wake field to remove.
Exceptions
std::invalid_argumentif no wake field with the given id exists.

◆ SeabedImageDepth()

double marenv::EnvironmentFacade::SeabedImageDepth ( const double  pos[3]) const

Returns the seabed depth for a wake kernel's seabed image below a point (owner ruling R53).

Parameters
[in]posPosition in NED frame [m].
Returns
The sea depth at pos [m] when the bathymetry answers with a usable (marenv::IsUsable, so a clamped depth counts) positive, finite depth; +infinity (no seabed image) otherwise.

◆ SelectWakes()

wake::WakeSelection marenv::EnvironmentFacade::SelectWakes ( const wake::WakeQueryRegion &  region,
const wake::WakeQuery &  query = {} 
) const

Selects the registered wake fields and jets that may reach a region, for a query (owner decision R47): wake::WakeRegistry::Select().

A structure selects once per step, after the fields have been published for the step, and holds the selection at its points (wake::WakeSelection::Hold()); GetWaterVelocity(time, pos, parts, held, point, vel) applies a held composition to the live current and waves.

◆ SetBathymetry()

void marenv::EnvironmentFacade::SetBathymetry ( std::shared_ptr< seafloor::BathymetryField >  bathymetry)

Sets the bathymetry to be used. Setup only, not thread safe with queries (see AddCurrentField()).

Parameters
[in]bathymetryBathymetry to be used.

◆ SettleSeaState()

void marenv::EnvironmentFacade::SettleSeaState ( double  time)

Drops the pass-through wrapper once a transition has ended, so the waves are queried without it.

Parameters
[in]timeSimulation time [s].

Does nothing unless the waves are a wave::TransitioningWaveField for which no blend is running or still to come at time (wave::TransitioningWaveField::IsSettled()); the field in force then answers directly, with the same bits. Environment::PreOdeFcn of fhsim_environment calls it every step, which runs serially. A later TransitionSeaState() wraps again.

◆ SetWaves() [1/2]

void marenv::EnvironmentFacade::SetWaves ( const wave::WaveEnergySpectrum::SpectrumParameters &  params,
wave::WaveTheory  waveTheory,
int  numWaves,
uint32_t  seed 
)

Creates the wave model based on spectrum parameters. Automatically selects between scalar and simd implementations for Airy waves.

Parameters
[in]paramsThe spectrum parameters.
[in]waveTheoryThe wave theory to use.
[in]numWavesThe number of waves to create.
[in]seedThe random seed to use.

◆ SetWaves() [2/2]

void marenv::EnvironmentFacade::SetWaves ( std::shared_ptr< wave::WaveField >  wave)

Sets the wave to be used. Setup only, not thread safe with queries (see AddCurrentField()).

Parameters
[in]waveWave to be used. A null pointer means no waves: a calm sea, with status Status::OK, for every query of the facade (elevation 0, wave velocity and acceleration 0, gauge total pressure rho g z in water and 0 in air, submergence and density from pos[2]); MENV-0095.

◆ TransitionSeaState() [1/2]

void marenv::EnvironmentFacade::TransitionSeaState ( const wave::WaveEnergySpectrum::SpectrumParameters &  params,
wave::WaveTheory  waveTheory,
int  numWaves,
uint32_t  seed,
double  startTime,
double  duration 
)

Starts a cross-fade transition from the current wave field to a new one.

Parameters
[in]paramsSpectrum parameters for the new wave field.
[in]waveTheoryWave theory to use for the new field.
[in]numWavesNumber of wave components.
[in]seedRandom seed.
[in]startTimeSimulation time [s] at which the transition begins.
[in]durationDuration of the cross-fade [s].

The new wave field is created from the given parameters and the transition interpolates computed outputs (not wave components) over the specified duration.

◆ TransitionSeaState() [2/2]

void marenv::EnvironmentFacade::TransitionSeaState ( std::shared_ptr< wave::WaveField >  newWaves,
double  startTime,
double  duration 
)

Starts a cross-fade transition from the current wave field to a given one.

Parameters
[in]newWavesThe target wave field. Must not be null.
[in]startTimeSimulation time [s] at which the transition begins. Must not be NaN.
[in]durationDuration of the cross-fade [s]. Must be >= 0.
Exceptions
std::invalid_argumentif newWaves is null, startTime is NaN, or duration is NaN or negative.

The documentation for this class was generated from the following file: