mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-05 12:24:25 +01:00
Phase 4: ray-traced acoustic propagation
Add src/sonar/raytrace.py: a vectorized 48-ray Snell fan through the Mackenzie sound-speed profile with turning points, rough-surface (Beckmann-Spizzichino) and lossy Rayleigh bottom reflections (complex sediment index), summed incoherently into TL(range, depth) tables for the four bands. Tables are pure functions of a quantized environment key (sensor depth, mixed layer, SST, water depth, sediment, wind) behind a bounded LRU, so the cache never affects results or save/load continuation. Surface duct, shadow zone, bottom bounce and deep-water convergence emerge from the profile. Own, dipping and NPC passive sonars use the ray excess (reciprocity: sensor is the source), anchored at a reference environment so the 20 NM reference range holds. Cross-layer and cavitating-speed range deviations are recorded with their physical reasons. Manual EN/DE updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4cd903a58a
commit
5c9199e569
10 files changed
+482
-45
No files matched your search
@@ -44,8 +44,8 @@ Im Remote-Crew-Browser (Commander, `F9`) werden Stationen mit Schaltflächen bed
|
||||
- **Passives Sonar liefert nur Peilung.** Jeder Kontakt beginnt als Peillinie. Entfernung liefern aktiver Ping, TMA, Sonarbojen oder Kreuzpeilung.
|
||||
- **Ortung heißt Signal gegen Rauschen.** Es entscheidet die passive Sonargleichung SE = SL - TL - NL + DI - DT: Quellpegel des Ziels (lauter = weiter), Übertragungsverlust (Ausbreitung, Absorption, Schicht- und Pfadverluste), Rauschen (eigenes Rauschen plus Wind, Regen und Schiffsverkehr in der Nähe) und Gewinn der Antenne. Ab SE >= 0 dB gilt ein Kontakt als geortet. Wind und Regen wirken am stärksten, wenn Sie langsam und leise fahren; bei hoher Eigenfahrt dominiert das eigene Rauschen.
|
||||
- **Eigene Fahrt ist eigener Lärm.** Der Eigenlärm steigt von 4 kn bis 25 kn. Ab 15 kn kavitieren die Schrauben, die Passivreichweite fällt auf etwa ein Drittel.
|
||||
- **Die Sprungschicht (Thermokline) teilt das Wasser.** Liegen Sensor und Ziel auf verschiedenen Seiten, gehen etwa 6,5 dB verloren. Ein Ping in die Schattenzone unter der Schicht erreicht nur 35 % seiner Reichweite.
|
||||
- **Konvergenzzonen** bei etwa 40-70 sm und 90-130 sm bringen Schall aus großer Entfernung zurück (+8 dB).
|
||||
- **Die Sprungschicht (Thermokline) beugt den Schall.** Die passive Ausbreitung wird als Strahlverfolgung durch das echte Schallgeschwindigkeitsprofil gerechnet: über der Schicht trägt ein Oberflächenkanal den Schall weit, darunter liegt eine einige Meilen breite Schattenzone. In tiefem Wasser ist der Schatten stark; in einigen hundert Metern Wassertiefe füllen Bodenreflexionen und Mehrwege ihn ab etwa 10 sm auf, das Verstecken unter der Schicht wirkt dort vor allem auf kurze Distanz. Ein Ping in die Schattenzone erreicht nur 35 % seiner Reichweite.
|
||||
- **Meeresboden und Oberfläche zählen.** Fels und Kies reflektieren gut, Schluff und Schlick schlucken; rauer Seegang streut hohe Frequenzen. **Konvergenzzonen** entstehen nur dort, wo das Wasser tief genug ist, damit die Strahlen wieder nach oben umkehren.
|
||||
- **Baffles:** Eigenlärm ist eine weiche 70-Grad-Keule achteraus der Bugsonaranlage (beim Schleppsonar entlang des Kabels). Sie überdeckt, sie blendet nicht vollständig aus.
|
||||
|
||||
```text
|
||||
|
||||
@@ -44,8 +44,8 @@ In the Remote Crew browser (Commander, `F9`) stations are operated with buttons;
|
||||
- **Passive sonar gives bearing only.** Every contact starts as a line of bearing. Range comes from active ping, TMA, sonobuoys or a cross-fix.
|
||||
- **Detection is signal against noise.** The passive sonar equation SE = SL - TL - NL + DI - DT decides: the target's source level (louder = farther), transmission loss (spreading, absorption, layer and path losses), noise (own self noise plus wind, rain and nearby shipping), and the array gain. A contact is detected at SE >= 0 dB. Wind and rain matter most when you run slow and quiet; at high own speed your own noise dominates.
|
||||
- **Own speed is own noise.** Self-noise rises from 4 kn to 25 kn. Above 15 kn the propellers cavitate and passive range drops to about a third.
|
||||
- **The layer (thermocline) splits the water.** Sensor and target on different sides of the layer lose about 6.5 dB. A ping into the shadow zone below the layer reaches only 35 % of its range.
|
||||
- **Convergence zones** at roughly 40-70 NM and 90-130 NM return sound from far away (+8 dB).
|
||||
- **The layer (thermocline) bends sound.** Passive propagation is ray traced through the real sound-speed profile: above the layer a surface duct carries sound far, below it lies a shadow zone a few miles wide. In deep water the shadow is strong; in water of a few hundred metres, bottom bounce and multipath fill it beyond about 10 NM, so hiding below the layer mainly works close in. A ping into the shadow zone reaches only 35 % of its range.
|
||||
- **Seabed and surface matter.** Rock and gravel reflect sound well, silt and mud absorb it; a rough sea scatters high frequencies. **Convergence zones** appear only where the water is deep enough for rays to turn back up.
|
||||
- **Baffles:** own-ship noise is a soft 70 degree lobe astern of the hull array (and along the cable of the towed array). It masks, it does not blank.
|
||||
|
||||
```text
|
||||
|
||||
@@ -267,8 +267,8 @@ Scope: Ship dynamics, weapons, enemy AI, air, sonar/sensors, world/environment.
|
||||
| ~~**No source-level model**~~ | **Closed (Phase 3; speed/cavitation terms Phase 6).** Source level in dB from the catalog quietness; NPC passive sonars hear loud targets farther (up to +5 dB). | — |
|
||||
| ~~**No receiver noise model**~~ | **Closed (Phase 3).** Wenz/Knudsen wind noise (flat below 500 Hz), distant shipping from nearby merchant count, heavy-rain noise, thermal floor, hull-array self-noise floor plus speed/cavitation self noise, own wake astern; NPC receiver sensitivity from the catalog. | — |
|
||||
| ~~**No target strength (TS)**~~ | **Closed (Phase 3).** Aspect- and length-dependent target strength (beam highlight ~20 log(L/10)+8 dB, bow/stern 15 dB lower). | — |
|
||||
| **Propagation: fixed 4 paths** | Direct, refracted (thermocline midpoint), surface, bottom — no full ray tracing | Multi-path with reflection/refraction at boundaries; mode propagation; no normal-mode solution needed but more rays |
|
||||
| **Propagation: no frequency dependence in path loss** | Absorption is per-band constant; path geometry is frequency-independent | Frequency-dependent ray paths (higher freq → less refracted); dispersion |
|
||||
| ~~**Propagation: fixed 4 paths**~~ | **Closed (Phase 4).** `src/sonar/raytrace.py`: 48-ray Snell fan through the Mackenzie profile (turning points, surface duct, shadow zone, convergence where deep enough), rough-surface and lossy Rayleigh bottom reflections, incoherent flux summation into TL(range, depth) tables per band; pure functions of a quantized environment key with a bounded LRU cache (purity keeps save/load deterministic). Own, dipping and NPC passive sonars use it via reciprocity (sensor = source). | — |
|
||||
| ~~**Propagation: no frequency dependence in path loss**~~ | **Closed (Phases 3-4).** Francois-Garrison absorption per band; boundary losses (surface roughness k-dependence) per band in the ray tables. | — |
|
||||
| **No Doppler** | Bearing measurements have no Doppler shift information | Doppler = f₀ · (v·r̂)/c; useful for speed estimation and classification |
|
||||
| ~~**No interference / clutter**~~ | **Closed (Phase 3).** Boundary (Lambert bottom by sediment, wind-dependent surface) and volume reverberation with absorption; CW Doppler rejection grows with radial speed; charted wrecks return unassociated echoes (saved pending clutter). | — |
|
||||
| ~~**Ping: no pulse parameters**~~ | **Closed (Phase 3).** Selectable CW (1 s) / LFM (1 s, 100 Hz) pulse (`W`, saved): resolution c*tau/2 or c/2B, Cramer-Rao range accuracy, LFM processing gain against noise, CW Doppler against reverberation. | — |
|
||||
|
||||
@@ -293,15 +293,20 @@ class PlatformSensorSuite:
|
||||
owner_noise = (owner.noise_level() if hasattr(owner, "noise_level")
|
||||
else 1.0 - getattr(owner, "quiet_factor",
|
||||
lambda: 1.0)())
|
||||
ray = propagation.ray_excess_db(
|
||||
world, owner.x, owner.y, source_depth, candidate.x,
|
||||
candidate.y, target_depth, frequency)
|
||||
terms = equation.passive_terms(
|
||||
frequency_hz=frequency, distance_nm=distance,
|
||||
target_bonus=1.0 + 0.8 * config.clamp(source_noise, 0.0, 1.0),
|
||||
excess_path_loss_db=(result.best_path.loss_db
|
||||
excess_path_loss_db=(ray if ray is not None else
|
||||
result.best_path.loss_db
|
||||
- 20.0 * math.log10(1.0 + distance)),
|
||||
absorption_db_per_km=equation.francois_garrison_db_per_km(
|
||||
frequency, 10.0, min(water_depth, 200.0)),
|
||||
legacy_absorption_db=result.best_path.distance_nm
|
||||
* propagation.ABSORPTION_DB_PER_NM[frequency],
|
||||
legacy_absorption_db=(0.0 if ray is not None else
|
||||
result.best_path.distance_nm
|
||||
* propagation.ABSORPTION_DB_PER_NM[frequency]),
|
||||
# The catalog range already includes self noise at a
|
||||
# typical operating level; only louder operation deafens.
|
||||
own_range_factor=min(1.0, (1.0 - 0.8 * config.clamp(
|
||||
|
||||
@@ -260,3 +260,80 @@ def passive_range_factor(result: PropagationResult, direct_range_nm: float) -> f
|
||||
baseline_loss = 20.0 * math.log10(1.0 + distance)
|
||||
excess_loss = max(0.0, result.best_path.loss_db - baseline_loss)
|
||||
return 10.0 ** (-excess_loss / 20.0)
|
||||
|
||||
|
||||
# --- ray-traced transmission loss (physics upgrade, phase 4) -----------------
|
||||
|
||||
RAY_REFERENCE_KEY = (5.0, 60.0, 13.0, 1000.0, "sand", 10.0)
|
||||
RAY_REFERENCE_RECEIVER_M = 50.0
|
||||
RAY_REFERENCE_RANGE_NM = 20.0
|
||||
_ray_anchor_db: float | None = None
|
||||
|
||||
|
||||
def _profile_from_key(key: tuple):
|
||||
from src.world.ocean import (
|
||||
SALINITY_PSU, mackenzie_sound_speed, temperature_profile_c)
|
||||
|
||||
_sensor, mld, sst, depth, _sediment, _wind = key
|
||||
maximum = min(depth, PROFILE_MAX_DEPTH_M)
|
||||
depths = [maximum * index / (PROFILE_SAMPLES - 1)
|
||||
for index in range(PROFILE_SAMPLES)]
|
||||
speeds = [mackenzie_sound_speed(temperature_profile_c(z, mld, sst),
|
||||
SALINITY_PSU, z) for z in depths]
|
||||
return depths, speeds
|
||||
|
||||
|
||||
def _spherical_db(distance_nm: float) -> float:
|
||||
return 20.0 * math.log10(max(1.0, distance_nm * 1852.0))
|
||||
|
||||
|
||||
def ray_anchor_db() -> float:
|
||||
"""Excess of the reference environment at the reference range; the
|
||||
passive figure of merit is anchored there so 1.0.0 ranges hold."""
|
||||
global _ray_anchor_db
|
||||
if _ray_anchor_db is None:
|
||||
from src.sonar import raytrace
|
||||
|
||||
table = raytrace.cached_table(RAY_REFERENCE_KEY, _profile_from_key)
|
||||
_ray_anchor_db = raytrace.lookup_tl_db(
|
||||
table, REPRESENTATIVE_PASSIVE_BAND_HZ, RAY_REFERENCE_RANGE_NM,
|
||||
RAY_REFERENCE_RECEIVER_M, RAY_REFERENCE_KEY[3]) - _spherical_db(
|
||||
RAY_REFERENCE_RANGE_NM)
|
||||
return _ray_anchor_db
|
||||
|
||||
|
||||
def ray_environment_key(world, sensor_depth_m: float, mid_x: float,
|
||||
mid_y: float) -> tuple | None:
|
||||
"""Quantized environment at the path midpoint (None without an ocean)."""
|
||||
from src.sonar.raytrace import quantize
|
||||
|
||||
ocean = getattr(world, "ocean", None)
|
||||
if ocean is None:
|
||||
return None
|
||||
depth = max(10.0, float(world.depth_m(mid_x, mid_y)))
|
||||
return (quantize(sensor_depth_m, 10.0 if sensor_depth_m > 30.0 else 5.0) or 5.0,
|
||||
max(10.0, quantize(world.thermocline_depth_m(mid_x, mid_y), 10.0)),
|
||||
quantize(ocean.sea_surface_temperature_c(getattr(world, "hour", 12.0)), 1.0),
|
||||
quantize(depth, 25.0 if depth < 1000.0 else 100.0) or 25.0,
|
||||
world.seabed_at(mid_x, mid_y),
|
||||
quantize(float(getattr(world, "wind_speed_kn", 10.0)), 5.0))
|
||||
|
||||
|
||||
def ray_excess_db(world, sensor_x: float, sensor_y: float, sensor_depth_m: float,
|
||||
target_x: float, target_y: float, target_depth_m: float,
|
||||
frequency_hz: float) -> float | None:
|
||||
"""Ray-traced loss beyond spherical spreading, relative to the anchor.
|
||||
|
||||
Reciprocity: the own sensor is the ray source, the target the receiver,
|
||||
so one cached table serves every target seen by that sensor."""
|
||||
from src.sonar import raytrace
|
||||
|
||||
mid_x, mid_y = (sensor_x + target_x) * .5, (sensor_y + target_y) * .5
|
||||
key = ray_environment_key(world, sensor_depth_m, mid_x, mid_y)
|
||||
if key is None:
|
||||
return None
|
||||
table = raytrace.cached_table(key, _profile_from_key)
|
||||
distance = math.hypot(target_x - sensor_x, target_y - sensor_y)
|
||||
tl = raytrace.lookup_tl_db(table, frequency_hz, distance,
|
||||
min(target_depth_m, key[3]), key[3])
|
||||
return tl - _spherical_db(distance) - ray_anchor_db()
|
||||
@@ -0,0 +1,198 @@
|
||||
"""Bounded, vectorized acoustic ray tracing and transmission-loss tables.
|
||||
|
||||
A fan of rays leaves the source with launch angles within +/-FAN_DEG. Each
|
||||
ray obeys Snell's law in the range-independent sound-speed profile
|
||||
(``cos(theta)/c = const``), turns where the invariant demands it, reflects
|
||||
at the surface (Beckmann-Spizzichino roughness loss) and at the seabed
|
||||
(Rayleigh fluid-fluid loss of the local sediment). Ray energy is summed
|
||||
incoherently on a (range x depth) grid with the geometric flux through each
|
||||
cell, giving transmission loss ``TL(r, z)`` per canonical band. Surface
|
||||
ducts, shadow zones, bottom bounce and convergence zones emerge from the
|
||||
profile instead of being prescribed.
|
||||
|
||||
Tables are pure functions of a quantized environment key and are cached in
|
||||
a bounded LRU; a table costs one vectorized trace (48 rays x 370 range
|
||||
steps) and is rebuilt only when the quantized environment changes.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
from collections import OrderedDict
|
||||
|
||||
import numpy as np
|
||||
|
||||
from src.world.ocean import rayleigh_bottom_loss_db
|
||||
|
||||
BANDS_HZ = (100.0, 400.0, 1600.0, 6400.0)
|
||||
NM_M = 1852.0
|
||||
FAN_DEG = 20.0
|
||||
RAYS = 48
|
||||
MAX_BOUNCES = 12
|
||||
MAX_RANGE_NM = 80.0
|
||||
RANGE_STEP_M = 400.0
|
||||
FINE_BINS = 16 # upper water column (to 400 m)
|
||||
COARSE_BINS = 4 # below 400 m
|
||||
FINE_DEPTH_M = 400.0
|
||||
CACHE_SIZE = 64
|
||||
# Loss beyond which a cell counts as insonified by nothing (shadow).
|
||||
SHADOW_TL_DB = 200.0
|
||||
|
||||
_cache: "OrderedDict[tuple, np.ndarray]" = OrderedDict()
|
||||
build_count = 0
|
||||
|
||||
|
||||
def _surface_loss_db(grazing_rad: np.ndarray, wind_kn: float,
|
||||
frequency_hz: float) -> np.ndarray:
|
||||
"""Coherent surface reflection loss for a rough (wind-driven) sea."""
|
||||
# RMS wave height of a fully developed sea, Hs ~ 0.0214 U^2 (U m/s).
|
||||
wind = wind_kn * 0.5144
|
||||
hs = 0.0214 * wind * wind
|
||||
k = 2.0 * math.pi * frequency_hz / 1500.0
|
||||
rayleigh = 2.0 * k * (hs / 4.0) * np.sin(grazing_rad)
|
||||
coefficient = np.exp(-0.5 * rayleigh ** 2)
|
||||
return np.minimum(20.0, -20.0 * np.log10(np.maximum(coefficient, 1e-3)))
|
||||
|
||||
|
||||
def quantize(value: float, step: float) -> float:
|
||||
return round(value / step) * step
|
||||
|
||||
|
||||
def depth_edges(water_depth_m: float) -> np.ndarray:
|
||||
bottom = max(float(water_depth_m), 5.0)
|
||||
fine = np.linspace(0.0, min(bottom, FINE_DEPTH_M), FINE_BINS + 1)
|
||||
if bottom <= FINE_DEPTH_M:
|
||||
return fine
|
||||
return np.concatenate([fine, np.linspace(FINE_DEPTH_M, bottom,
|
||||
COARSE_BINS + 1)[1:]])
|
||||
|
||||
|
||||
def _profile_speed(depths: np.ndarray, speeds: np.ndarray,
|
||||
z: np.ndarray) -> np.ndarray:
|
||||
return np.interp(z, depths, speeds)
|
||||
|
||||
|
||||
def trace_table(source_depth_m: float, profile_depths_m, profile_m_s,
|
||||
water_depth_m: float, sediment: str, wind_kn: float) -> np.ndarray:
|
||||
"""Return TL[band, range_bin, depth_bin] in dB (without absorption)."""
|
||||
global build_count
|
||||
build_count += 1
|
||||
depths = np.asarray(profile_depths_m, dtype=float)
|
||||
speeds = np.asarray(profile_m_s, dtype=float)
|
||||
bottom = max(float(water_depth_m), 5.0)
|
||||
if depths[-1] < bottom:
|
||||
# Below the sampled profile the pressure term dominates (+0.017 1/s).
|
||||
depths = np.append(depths, bottom)
|
||||
speeds = np.append(speeds, speeds[-1] + 0.017 * (bottom - depths[-2]))
|
||||
source = min(max(float(source_depth_m), 0.5), bottom - 0.5)
|
||||
angles = np.radians(np.linspace(-FAN_DEG, FAN_DEG, RAYS))
|
||||
d_theta = abs(angles[1] - angles[0])
|
||||
c0 = float(_profile_speed(depths, speeds, np.array([source]))[0])
|
||||
xi = np.cos(angles) / c0 # Snell invariant
|
||||
z = np.full(RAYS, source)
|
||||
direction = np.sign(np.sin(angles)) # +1 downward
|
||||
direction[direction == 0] = 1.0
|
||||
energy = np.cos(angles) * d_theta # 2D fan energy weights
|
||||
losses = np.zeros((len(BANDS_HZ), RAYS))
|
||||
bounces = np.zeros(RAYS, dtype=int)
|
||||
alive = np.ones(RAYS, dtype=bool)
|
||||
n_range = int(MAX_RANGE_NM * NM_M / RANGE_STEP_M)
|
||||
bin_edges = depth_edges(bottom)
|
||||
widths = np.diff(bin_edges)
|
||||
centres = 0.5 * (bin_edges[:-1] + bin_edges[1:])
|
||||
intensity = np.zeros((len(BANDS_HZ), n_range, len(centres)))
|
||||
sediment_loss_cache = {}
|
||||
for step in range(n_range):
|
||||
r = (step + 1) * RANGE_STEP_M
|
||||
c = _profile_speed(depths, speeds, z)
|
||||
cos_t = np.clip(xi * c, 0.0, 1.0)
|
||||
sin_t = np.sqrt(np.maximum(0.0, 1.0 - cos_t * cos_t))
|
||||
# Turning point: the ray becomes horizontal and reverses.
|
||||
turning = cos_t >= 0.999999
|
||||
direction = np.where(turning, -direction, direction)
|
||||
sin_t = np.where(turning, 1e-3, sin_t)
|
||||
dz = direction * RANGE_STEP_M * sin_t / np.maximum(cos_t, 1e-3)
|
||||
z = z + dz
|
||||
hit_surface = z < 0.0
|
||||
hit_bottom = z > bottom
|
||||
if hit_surface.any():
|
||||
z = np.where(hit_surface, -z, z)
|
||||
direction = np.where(hit_surface, 1.0, direction)
|
||||
grazing = np.arcsin(np.clip(sin_t, 0.0, 1.0))
|
||||
for band_index, frequency in enumerate(BANDS_HZ):
|
||||
losses[band_index] += np.where(
|
||||
hit_surface, _surface_loss_db(grazing, wind_kn, frequency), 0.0)
|
||||
bounces += hit_surface
|
||||
if hit_bottom.any():
|
||||
z = np.where(hit_bottom, 2.0 * bottom - z, z)
|
||||
direction = np.where(hit_bottom, -1.0, direction)
|
||||
grazing_deg = np.degrees(np.arcsin(np.clip(sin_t, 0.0, 1.0)))
|
||||
key = np.round(grazing_deg, 1)
|
||||
loss = np.array([sediment_loss_cache.setdefault(
|
||||
(sediment, float(value)), rayleigh_bottom_loss_db(sediment, float(value)))
|
||||
for value in key])
|
||||
for band_index in range(len(BANDS_HZ)):
|
||||
losses[band_index] += np.where(hit_bottom, loss, 0.0)
|
||||
bounces += hit_bottom
|
||||
z = np.clip(z, 0.0, bottom)
|
||||
alive &= bounces <= MAX_BOUNCES
|
||||
# Incoherent flux into depth bins with a Gaussian beam footprint;
|
||||
# each ray's energy is shared over the bins and divided by bin height.
|
||||
width = max(widths[0], 0.5 * r * d_theta)
|
||||
weights = np.exp(-0.5 * ((centres[None, :] - z[:, None]) / width) ** 2)
|
||||
norm = weights.sum(axis=1, keepdims=True)
|
||||
weights = np.where(norm > 0, weights / np.maximum(norm, 1e-12), 0.0)
|
||||
weights = weights / widths[None, :]
|
||||
flux = energy / (r * np.maximum(cos_t, 1e-3))
|
||||
for band_index in range(len(BANDS_HZ)):
|
||||
ray_power = np.where(alive, flux * 10.0 ** (-losses[band_index] / 10.0),
|
||||
0.0)
|
||||
intensity[band_index, step] = ray_power @ weights
|
||||
with np.errstate(divide="ignore"):
|
||||
table = -10.0 * np.log10(np.maximum(intensity, 10.0 ** (-SHADOW_TL_DB / 10.0)))
|
||||
return table
|
||||
|
||||
|
||||
def cached_table(key: tuple, profile_builder) -> np.ndarray:
|
||||
"""TL table for a quantized environment ``key``.
|
||||
|
||||
The result is a pure function of the key, so the cache only saves time:
|
||||
save/load, evaluation order or an empty cache never change results.
|
||||
``key`` = (sensor depth, mixed-layer depth, SST, water depth, sediment,
|
||||
wind); ``profile_builder(key)`` returns (depths, speeds)."""
|
||||
table = _cache.get(key)
|
||||
if table is not None:
|
||||
_cache.move_to_end(key)
|
||||
return table
|
||||
depths, speeds = profile_builder(key)
|
||||
table = trace_table(key[0], depths, speeds, key[3], key[4], key[5])
|
||||
_cache[key] = table
|
||||
while len(_cache) > CACHE_SIZE:
|
||||
_cache.popitem(last=False)
|
||||
return table
|
||||
|
||||
|
||||
def lookup_tl_db(table: np.ndarray, band_hz: float, range_nm: float,
|
||||
receiver_depth_m: float, water_depth_m: float) -> float:
|
||||
"""Interpolated TL (dB) for one receiver; beyond the table, cylindrical."""
|
||||
band_index = BANDS_HZ.index(band_hz)
|
||||
n_range = table.shape[1]
|
||||
r_m = max(range_nm * NM_M, RANGE_STEP_M)
|
||||
edges = depth_edges(water_depth_m)
|
||||
depth_index = int(min(len(edges) - 2, max(0, np.searchsorted(
|
||||
edges, receiver_depth_m, side="right") - 1)))
|
||||
position = r_m / RANGE_STEP_M - 1.0
|
||||
if position >= n_range - 1:
|
||||
last = table[band_index, n_range - 1, depth_index]
|
||||
edge = n_range * RANGE_STEP_M
|
||||
return float(last + 10.0 * math.log10(r_m / edge))
|
||||
low = int(position)
|
||||
fraction = position - low
|
||||
return float(table[band_index, low, depth_index] * (1.0 - fraction)
|
||||
+ table[band_index, low + 1, depth_index] * fraction)
|
||||
|
||||
|
||||
def clear_cache() -> None:
|
||||
global build_count
|
||||
_cache.clear()
|
||||
build_count = 0
|
||||
+13
-3
@@ -961,6 +961,11 @@ class SonarSystem:
|
||||
excess = result.best_path.loss_db - 20.0 * math.log10(1.0 + dist_nm)
|
||||
legacy_absorption = result.best_path.distance_nm \
|
||||
* propagation.ABSORPTION_DB_PER_NM[frequency]
|
||||
ray = propagation.ray_excess_db(
|
||||
world, frigate.x, frigate.y, sensor_depth, tgt.x, tgt.y,
|
||||
float(getattr(tgt, "depth", 0.0)), frequency)
|
||||
if ray is not None:
|
||||
excess, legacy_absorption = ray, 0.0
|
||||
absorption = equation.francois_garrison_db_per_km(
|
||||
frequency, _surface_temperature(world),
|
||||
min(water_depth, 200.0))
|
||||
@@ -1003,16 +1008,21 @@ class SonarSystem:
|
||||
terrain_blocked=getattr(world, "sonar_path_blocked", None))
|
||||
if result.best_path is None:
|
||||
continue
|
||||
ray = propagation.ray_excess_db(
|
||||
world, helicopter.x, helicopter.y, sensor_depth, tgt.x, tgt.y,
|
||||
float(getattr(tgt, "depth", 0.0)), frequency)
|
||||
terms = equation.passive_terms(
|
||||
frequency_hz=frequency, distance_nm=distance,
|
||||
target_bonus=target_bonus,
|
||||
excess_path_loss_db=(result.best_path.loss_db
|
||||
excess_path_loss_db=(ray if ray is not None else
|
||||
result.best_path.loss_db
|
||||
- 20.0 * math.log10(1.0 + distance)),
|
||||
absorption_db_per_km=equation.francois_garrison_db_per_km(
|
||||
frequency, _surface_temperature(world),
|
||||
min(water_depth, 200.0)),
|
||||
legacy_absorption_db=result.best_path.distance_nm
|
||||
* propagation.ABSORPTION_DB_PER_NM[frequency],
|
||||
legacy_absorption_db=(0.0 if ray is not None else
|
||||
result.best_path.distance_nm
|
||||
* propagation.ABSORPTION_DB_PER_NM[frequency]),
|
||||
own_range_factor=1.0,
|
||||
array_range_factor=(config.HELO_DIP_PASSIVE_RANGE_NM
|
||||
/ config.SONAR_PASSIVE_BASE_NM) * range_factor,
|
||||
|
||||
+24
-21
@@ -88,24 +88,31 @@ def mackenzie_sound_speed(temperature_c: float, salinity_psu: float,
|
||||
- 1.025e-2 * t * (s - 35.0) - 7.139e-13 * t * d ** 3)
|
||||
|
||||
|
||||
def temperature_profile_c(depth_m: float, mld_m: float, sst_c: float) -> float:
|
||||
"""Isothermal mixed layer over an exponential thermocline."""
|
||||
if depth_m <= mld_m:
|
||||
return sst_c - 0.002 * depth_m
|
||||
surface = sst_c - 0.002 * mld_m
|
||||
return DEEP_TEMPERATURE_C + (surface - DEEP_TEMPERATURE_C) * math.exp(
|
||||
-(depth_m - mld_m) / THERMOCLINE_SCALE_M)
|
||||
|
||||
|
||||
def rayleigh_bottom_loss_db(sediment: str, grazing_deg: float) -> float:
|
||||
"""Plane-wave fluid-fluid reflection loss at a sediment interface (dB)."""
|
||||
"""Plane-wave fluid-fluid reflection loss of a lossy sediment (dB).
|
||||
|
||||
R = (m sin t - sqrt(n^2 - cos^2 t)) / (m sin t + sqrt(n^2 - cos^2 t))
|
||||
with density ratio m, and a complex index of refraction
|
||||
n = (c1/c2) / (1 + i delta) from the sediment attenuation (dB per
|
||||
wavelength), so reflection below the critical angle is not lossless.
|
||||
"""
|
||||
rho, nu, attenuation, _mu = SEDIMENTS[sediment]
|
||||
theta = math.radians(max(0.01, min(90.0, grazing_deg)))
|
||||
cos_t, sin_t = math.cos(theta), math.sin(theta)
|
||||
# R = (m sin t - sqrt(n^2 - cos^2 t)) / (m sin t + sqrt(n^2 - cos^2 t))
|
||||
# with m = rho2/rho1 and n = c1/c2; below the critical grazing angle
|
||||
# (cos t > n) the reflection is total.
|
||||
n = 1.0 / nu
|
||||
radicand = n * n - cos_t * cos_t
|
||||
if radicand <= 0.0:
|
||||
loss = 0.0
|
||||
else:
|
||||
root = math.sqrt(radicand)
|
||||
r = abs((rho * sin_t - root) / (rho * sin_t + root))
|
||||
loss = -20.0 * math.log10(max(r, 1e-6))
|
||||
# Sediment absorption adds a small grazing-dependent loss.
|
||||
return loss + 0.35 * attenuation * math.sin(theta)
|
||||
delta = attenuation / (40.0 * math.pi * math.log10(math.e))
|
||||
n = (1.0 / nu) / complex(1.0, delta)
|
||||
root = (n * n - cos_t * cos_t) ** 0.5 # principal branch, Re >= 0
|
||||
r = abs((rho * sin_t - root) / (rho * sin_t + root))
|
||||
return -20.0 * math.log10(max(min(r, 1.0), 1e-6))
|
||||
|
||||
|
||||
class OceanEnvironment:
|
||||
@@ -245,13 +252,9 @@ class OceanEnvironment:
|
||||
2.0 * math.pi * (hour - MLD_DIURNAL_PEAK_HOUR) / 24.0)
|
||||
return SST_MEAN_C + seasonal + diurnal
|
||||
|
||||
def temperature_c(self, depth_m: float, mld_m: float, sst_c: float) -> float:
|
||||
if depth_m <= mld_m:
|
||||
# Nearly isothermal surface layer.
|
||||
return sst_c - 0.002 * depth_m
|
||||
surface = sst_c - 0.002 * mld_m
|
||||
return DEEP_TEMPERATURE_C + (surface - DEEP_TEMPERATURE_C) * math.exp(
|
||||
-(depth_m - mld_m) / THERMOCLINE_SCALE_M)
|
||||
@staticmethod
|
||||
def temperature_c(depth_m: float, mld_m: float, sst_c: float) -> float:
|
||||
return temperature_profile_c(depth_m, mld_m, sst_c)
|
||||
|
||||
def sound_speed_m_s(self, depth_m: float, mld_m: float, hour: float) -> float:
|
||||
sst = self.sea_surface_temperature_c(hour)
|
||||
|
||||
@@ -19,24 +19,79 @@
|
||||
"reason": "Phase 2: first-order Nomoto steering, r = K (V/L) delta, makes the steady turn rate linear in speed, so the turning circle is nearly constant; calibrated at FULL (1.2 deg/s), HALF becomes 0.75 deg/s.",
|
||||
"value": 0.75
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea1.own12.d150": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation (Snell rays, lossy Rayleigh bottom, rough surface) replaces the fixed 6.5 dB layer penalty. In ~800 m of water over sand bottom-bounce and multipath fill the region below the layer beyond ~10 NM, so cross-layer ranges roughly double; the shadow zone remains at short range and in deep water.",
|
||||
"value": 23.403145
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea1.own18.d30": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation is near spherical at short range, while the figure of merit is anchored at 20 NM where multipath already gains ~13 dB; short, self-noise-limited detections at cavitating speed become shorter.",
|
||||
"value": 6.418866
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea1.own25.d150": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation is near spherical at short range, while the figure of merit is anchored at 20 NM where multipath already gains ~13 dB; short, self-noise-limited detections at cavitating speed become shorter.",
|
||||
"value": 2.101524
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea1.own25.d30": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation is near spherical at short range, while the figure of merit is anchored at 20 NM where multipath already gains ~13 dB; short, self-noise-limited detections at cavitating speed become shorter.",
|
||||
"value": 4.461446
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea1.own6.d150": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation (Snell rays, lossy Rayleigh bottom, rough surface) replaces the fixed 6.5 dB layer penalty. In ~800 m of water over sand bottom-bounce and multipath fill the region below the layer beyond ~10 NM, so cross-layer ranges roughly double; the shadow zone remains at short range and in deep water.",
|
||||
"value": 23.934195
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea4.own12.d150": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation (Snell rays, lossy Rayleigh bottom, rough surface) replaces the fixed 6.5 dB layer penalty. In ~800 m of water over sand bottom-bounce and multipath fill the region below the layer beyond ~10 NM, so cross-layer ranges roughly double; the shadow zone remains at short range and in deep water.",
|
||||
"value": 19.257926
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea4.own18.d150": {
|
||||
"phase": 3,
|
||||
"reason": "Phase 3: the passive sonar equation power-sums wind/shipping ambient noise with own-ship self noise. At cavitating own speeds self noise dominates, so a higher sea state costs less range than the flat 1.0.0 sea-state factor.",
|
||||
"value": 3.576355
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation is near spherical at short range, while the figure of merit is anchored at 20 NM where multipath already gains ~13 dB; short, self-noise-limited detections at cavitating speed become shorter.",
|
||||
"value": 4.28814
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea4.own18.d30": {
|
||||
"phase": 3,
|
||||
"reason": "Phase 3: the passive sonar equation power-sums wind/shipping ambient noise with own-ship self noise. At cavitating own speeds self noise dominates, so a higher sea state costs less range than the flat 1.0.0 sea-state factor.",
|
||||
"value": 7.554507
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation is near spherical at short range, while the figure of merit is anchored at 20 NM where multipath already gains ~13 dB; short, self-noise-limited detections at cavitating speed become shorter.",
|
||||
"value": 6.239193
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea4.own25.d150": {
|
||||
"phase": 3,
|
||||
"reason": "Phase 3: the passive sonar equation power-sums wind/shipping ambient noise with own-ship self noise. At cavitating own speeds self noise dominates, so a higher sea state costs less range than the flat 1.0.0 sea-state factor.",
|
||||
"value": 2.831818
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation is near spherical at short range, while the figure of merit is anchored at 20 NM where multipath already gains ~13 dB; short, self-noise-limited detections at cavitating speed become shorter.",
|
||||
"value": 2.037872
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea4.own25.d30": {
|
||||
"phase": 3,
|
||||
"reason": "Phase 3: the passive sonar equation power-sums wind/shipping ambient noise with own-ship self noise. At cavitating own speeds self noise dominates, so a higher sea state costs less range than the flat 1.0.0 sea-state factor.",
|
||||
"value": 5.983241
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation is near spherical at short range, while the figure of merit is anchored at 20 NM where multipath already gains ~13 dB; short, self-noise-limited detections at cavitating speed become shorter.",
|
||||
"value": 4.350308
|
||||
},
|
||||
"sonar.passive_nm.BOW.sea4.own6.d150": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation (Snell rays, lossy Rayleigh bottom, rough surface) replaces the fixed 6.5 dB layer penalty. In ~800 m of water over sand bottom-bounce and multipath fill the region below the layer beyond ~10 NM, so cross-layer ranges roughly double; the shadow zone remains at short range and in deep water.",
|
||||
"value": 19.75497
|
||||
},
|
||||
"sonar.passive_nm.TOWED.sea1.own12.d30": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation (Snell rays, lossy Rayleigh bottom, rough surface) replaces the fixed 6.5 dB layer penalty. In ~800 m of water over sand bottom-bounce and multipath fill the region below the layer beyond ~10 NM, so cross-layer ranges roughly double; the shadow zone remains at short range and in deep water.",
|
||||
"value": 25.974515
|
||||
},
|
||||
"sonar.passive_nm.TOWED.sea1.own6.d30": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation (Snell rays, lossy Rayleigh bottom, rough surface) replaces the fixed 6.5 dB layer penalty. In ~800 m of water over sand bottom-bounce and multipath fill the region below the layer beyond ~10 NM, so cross-layer ranges roughly double; the shadow zone remains at short range and in deep water.",
|
||||
"value": 30.470364
|
||||
},
|
||||
"sonar.passive_nm.TOWED.sea4.own12.d30": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation (Snell rays, lossy Rayleigh bottom, rough surface) replaces the fixed 6.5 dB layer penalty. In ~800 m of water over sand bottom-bounce and multipath fill the region below the layer beyond ~10 NM, so cross-layer ranges roughly double; the shadow zone remains at short range and in deep water.",
|
||||
"value": 20.833156
|
||||
},
|
||||
"sonar.passive_nm.TOWED.sea4.own6.d30": {
|
||||
"phase": 4,
|
||||
"reason": "Phase 4: ray-traced propagation (Snell rays, lossy Rayleigh bottom, rough surface) replaces the fixed 6.5 dB layer penalty. In ~800 m of water over sand bottom-bounce and multipath fill the region below the layer beyond ~10 NM, so cross-layer ranges roughly double; the shadow zone remains at short range and in deep water.",
|
||||
"value": 24.435873
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
"""Phase 4: ray-traced transmission loss."""
|
||||
|
||||
import math
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from src.sonar import propagation, raytrace
|
||||
from src.world.ocean import rayleigh_bottom_loss_db
|
||||
from src.world.world import World
|
||||
|
||||
|
||||
def spherical(nm):
|
||||
return 20.0 * math.log10(nm * 1852.0)
|
||||
|
||||
|
||||
def test_homogeneous_deep_water_is_spherical_plus_surface_image():
|
||||
table = raytrace.trace_table(50.0, [0.0, 4000.0], [1500.0, 1500.0],
|
||||
4000.0, "mud", 0.0)
|
||||
for nm in (1.0, 5.0, 10.0):
|
||||
excess = raytrace.lookup_tl_db(table, 100.0, nm, 50.0, 4000.0) - spherical(nm)
|
||||
# Incoherent sum with the surface-reflected image: up to ~3 dB gain.
|
||||
assert -5.0 < excess < 1.0
|
||||
|
||||
|
||||
def _mixed_layer_profile(mld=60.0):
|
||||
from src.world.ocean import mackenzie_sound_speed, temperature_profile_c
|
||||
depths = np.linspace(0.0, 400.0, 21)
|
||||
return depths, [mackenzie_sound_speed(temperature_profile_c(z, mld, 14.0), 35.0, z)
|
||||
for z in depths]
|
||||
|
||||
|
||||
def test_surface_duct_and_shadow_zone_emerge_in_deep_water():
|
||||
depths, speeds = _mixed_layer_profile(60.0)
|
||||
table = raytrace.trace_table(5.0, depths, speeds, 3000.0, "mud", 5.0)
|
||||
in_duct = raytrace.lookup_tl_db(table, 100.0, 3.0, 30.0, 3000.0)
|
||||
shadow = raytrace.lookup_tl_db(table, 100.0, 3.0, 250.0, 3000.0)
|
||||
assert shadow - in_duct > 8.0
|
||||
|
||||
|
||||
def test_bottom_reflection_depends_on_sediment():
|
||||
assert rayleigh_bottom_loss_db("rock", 10.0) < rayleigh_bottom_loss_db("sand", 10.0)
|
||||
assert rayleigh_bottom_loss_db("sand", 10.0) < rayleigh_bottom_loss_db("silt", 10.0)
|
||||
depths, speeds = _mixed_layer_profile(60.0)
|
||||
hard = raytrace.trace_table(5.0, depths, speeds, 300.0, "gravel", 5.0)
|
||||
soft = raytrace.trace_table(5.0, depths, speeds, 300.0, "silt", 5.0)
|
||||
assert raytrace.lookup_tl_db(hard, 100.0, 20.0, 100.0, 300.0) < \
|
||||
raytrace.lookup_tl_db(soft, 100.0, 20.0, 100.0, 300.0) - 1.0
|
||||
|
||||
|
||||
def test_rough_surface_costs_high_frequencies_more():
|
||||
depths, speeds = _mixed_layer_profile(80.0)
|
||||
calm = raytrace.trace_table(5.0, depths, speeds, 3000.0, "mud", 0.0)
|
||||
windy = raytrace.trace_table(5.0, depths, speeds, 3000.0, "mud", 30.0)
|
||||
loss = lambda table, band: raytrace.lookup_tl_db(table, band, 15.0, 30.0, 3000.0)
|
||||
assert loss(windy, 6400.0) - loss(calm, 6400.0) > loss(windy, 100.0) - loss(calm, 100.0)
|
||||
|
||||
|
||||
def test_ray_excess_is_pure_and_cache_bounded():
|
||||
world = World(seed=41)
|
||||
raytrace.clear_cache()
|
||||
first = propagation.ray_excess_db(world, 200.0, 200.0, 5.0, 212.0, 203.0, 80.0, 100.0)
|
||||
raytrace.clear_cache()
|
||||
second = propagation.ray_excess_db(world, 200.0, 200.0, 5.0, 212.0, 203.0, 80.0, 100.0)
|
||||
assert first == second
|
||||
assert raytrace.build_count >= 1
|
||||
for index in range(raytrace.CACHE_SIZE + 5):
|
||||
raytrace.cached_table((5.0, 10.0 * index, 12.0, 500.0, "sand", 5.0),
|
||||
propagation._profile_from_key)
|
||||
assert len(raytrace._cache) <= raytrace.CACHE_SIZE
|
||||
|
||||
|
||||
def test_anchor_makes_reference_environment_zero_at_reference_range():
|
||||
table = raytrace.cached_table(propagation.RAY_REFERENCE_KEY,
|
||||
propagation._profile_from_key)
|
||||
excess = raytrace.lookup_tl_db(
|
||||
table, 100.0, propagation.RAY_REFERENCE_RANGE_NM,
|
||||
propagation.RAY_REFERENCE_RECEIVER_M, propagation.RAY_REFERENCE_KEY[3]) \
|
||||
- spherical(propagation.RAY_REFERENCE_RANGE_NM) - propagation.ray_anchor_db()
|
||||
assert excess == pytest.approx(0.0, abs=1e-9)
|
||||
|
||||
|
||||
def test_lookup_extends_cylindrically_beyond_the_table():
|
||||
depths, speeds = _mixed_layer_profile(60.0)
|
||||
table = raytrace.trace_table(5.0, depths, speeds, 500.0, "sand", 5.0)
|
||||
edge = raytrace.MAX_RANGE_NM
|
||||
near = raytrace.lookup_tl_db(table, 100.0, edge * 1.001, 50.0, 500.0)
|
||||
far = raytrace.lookup_tl_db(table, 100.0, edge * 2.0, 50.0, 500.0)
|
||||
assert far - near == pytest.approx(10.0 * math.log10(2.0 / 1.001), abs=0.2)
|
||||
Reference in new issue
Block a user