Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions app/config/run.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,16 @@
},
"nowcast": {
"grid": {
"longitude": 96,
"latitude": 80,
"depth": 6
"longitude": 48,
"latitude": 40,
"depth": 26
},
"interval_ticks": 900,
"time_steps": 4,
"step_seconds": 3600
},
"departure": {
"grid": { "longitude": 48, "latitude": 40, "depth": 6 },
"grid": { "longitude": 48, "latitude": 40, "depth": 26 },
"time_steps": 12,
"step_seconds": 3600
},
Expand Down Expand Up @@ -403,7 +403,8 @@
"depth_m": 80,
"thickness_m": 30,
"temperature_drop_c": 4,
"salinity_rise_psu": 0.1
"salinity_rise_psu": 0.1,
"displacement_m_per_c": 20
},
"jitter": {
"depth_m": 15,
Expand Down
Binary file modified app/public/snapshots/arriving.snapshot
Binary file not shown.
Binary file modified app/public/snapshots/leaving.snapshot
Binary file not shown.
Binary file modified app/public/snapshots/loitering.snapshot
Binary file not shown.
Binary file modified app/public/snapshots/returning.snapshot
Binary file not shown.
3 changes: 2 additions & 1 deletion app/src/backend/advisories/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { Rng } from '../lib/rng.js';
import { configDigest } from '../lib/sha256.js';
import { HeartbeatEmitter } from '../lib/heartbeat.js';
import { isoPlusSeconds } from '../lib/sim-time.js';
import { backgroundTemperature, backgroundSalinity, soundSpeedMs } from '../env-generator/analytic.js';
import { backgroundTemperature, backgroundSalinity } from '../env-generator/analytic.js';
import { soundSpeedMs } from '../../seam/ocean-relations.js';
import type { EnvGenerator } from '../env-generator/generator.js';
import type { FeatureStore } from '../feature-store/store.js';

Expand Down
2 changes: 1 addition & 1 deletion app/src/backend/analyst/analyst.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
} from '../../generated/types.js';
import { createSeamValidator } from '../../seam/validate.js';
import { buildBackend, type BackendRuntime } from '../runtime/runtime.js';
import { soundSpeedMs } from '../env-generator/analytic.js';
import { soundSpeedMs } from '../../seam/ocean-relations.js';
import { driveUntil } from '../test-support/drive.js';

const validator = createSeamValidator();
Expand Down
12 changes: 11 additions & 1 deletion app/src/backend/analyst/analyst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,17 @@ export class Analyst {
const digest = `sha256:${sha256Hex(bytes)}`;
const manifest: Manifest = {
...baseManifest,
generator: { name: 'drogna-analyst', version: '2.0.0', analytic_form_version: 1 },
// The form version travels with the parameters, and the parameters come from the
// manifest spread above. Typed here it was correct only while there was one form:
// the moment the env-generator reached form 2 (#113) this document would have
// carried form 2's thermocline parameters under a form 1 label, telling a reader it
// could reconstruct a doming layer with the flat rule. Read from the base and it
// cannot drift again.
generator: {
name: 'drogna-analyst',
version: '2.0.0',
analytic_form_version: baseManifest.generator.analytic_form_version,
},
config_digest: configDigest(this.config),
generated_at: { sim_time: this.simTime.value, tick: this.simTime.tick },
grid: {
Expand Down
61 changes: 45 additions & 16 deletions app/src/backend/env-generator/analytic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import {
frontAnomalyT,
frontSignedDistanceKm,
movingCentreAt,
pressureDbar,
soundSpeedMs,
tauAt,
temperatureAt,
thermoclineAnomalyT,
thermoclineDepthAt,
type WorldParameters,
} from './analytic.js';

Expand Down Expand Up @@ -41,7 +40,7 @@ const world: WorldParameters = {
salinity_amplitude_psu: -0.2,
depth_scale_m: 250,
},
thermocline: { depth_m: 80, thickness_m: 30, temperature_drop_c: 4, salinity_rise_psu: 0.1 },
thermocline: { depth_m: 80, thickness_m: 30, temperature_drop_c: 4, salinity_rise_psu: 0.1, displacement_m_per_c: 20 },
moving: {
centre_latitude: 45,
centre_longitude: -12.5,
Expand All @@ -62,7 +61,7 @@ const tau = {
feature_seconds: { eddy: 432000, front: 172800, thermocline: 1209600, moving: 86400 },
};

describe('the analytic form (v1)', () => {
describe('the analytic form (v2)', () => {
it('background cools and freshens towards the deep, monotonically', () => {
let previous = Number.POSITIVE_INFINITY;
for (const depth of [0, 50, 100, 200, 400, 800, 1000]) {
Expand All @@ -89,12 +88,52 @@ describe('the analytic form (v1)', () => {
});

it('the thermocline realises its full drop across the layer', () => {
const above = thermoclineAnomalyT(world.thermocline, 0);
const below = thermoclineAnomalyT(world.thermocline, 400);
const above = thermoclineAnomalyT(world.thermocline, 0, world.thermocline.depth_m);
const below = thermoclineAnomalyT(world.thermocline, 400, world.thermocline.depth_m);
// Within the tanh tails: the surface sits 2.7 thicknesses above the layer.
expect(above - below).toBeCloseTo(4, 1);
});

it('the layer follows the features that displace it (analytic form 2)', () => {
/*
* Far from the eddy and the drifting feature the layer sits where it was authored: form 2
* reduces to form 1 wherever nothing local is acting, which is what makes the displacement a
* perturbation of the authored depth rather than a different depth scale.
*
* **The far field is quiet only because the front is not a displacement term**, which is
* this assertion's other job. An earlier version included it, and this test failed here at
* 63.9 m against 80 — the front's own saturated −1.2 °C times the coefficient, reaching the
* corner of the domain. A `tanh` never decays, so there is no "far" from a front, and the
* measurement in `thermoclineDepthAt`'s note is what that cost the drifting feature's
* recovery. Put the front back and this line fails first and cheapest.
*/
const far = thermoclineDepthAt(world, -13.9, 44.1, 0);
expect(far).toBeCloseTo(world.thermocline.depth_m, 1);

// The eddy is warm-cored (sign +1), so it presses the layer down beneath it.
const underEddy = thermoclineDepthAt(world, world.eddy.centre_longitude, world.eddy.centre_latitude, 0);
expect(underEddy).toBeGreaterThan(far + 10);

// The moving feature is cold-cored (sign -1), so it domes the layer, and it takes the dome
// with it: the dome is under the centre at each time, not under the initial centre.
const start = movingCentreAt(world.moving, 0);
const later = movingCentreAt(world.moving, 5 * 86400);
expect(thermoclineDepthAt(world, start.longitude, start.latitude, 0)).toBeLessThan(far - 10);
expect(thermoclineDepthAt(world, later.longitude, later.latitude, 5 * 86400)).toBeLessThan(far - 10);
expect(thermoclineDepthAt(world, start.longitude, start.latitude, 5 * 86400)).toBeGreaterThan(
thermoclineDepthAt(world, later.longitude, later.latitude, 5 * 86400),
);
});

it('a zero displacement coefficient reproduces the flat layer of analytic form 1', () => {
// The version bump's own boundary, so "form 2 is a superset of form 1" is a checked claim
// rather than a sentence in a comment.
const flat: WorldParameters = { ...world, thermocline: { ...world.thermocline, displacement_m_per_c: 0 } };
for (const [lon, lat] of [[-13.9, 44.1], [world.eddy.centre_longitude, world.eddy.centre_latitude], [-9.5, 47]]) {
expect(thermoclineDepthAt(flat, lon, lat, 0)).toBe(flat.thermocline.depth_m);
}
});

it('the moving feature advects as an exact affine map', () => {
const day = movingCentreAt(world.moving, 86400);
expect(day.latitude).toBeCloseTo(45 + 5 / 111.32, 6);
Expand All @@ -112,14 +151,4 @@ describe('the analytic form (v1)', () => {
const centreLater = movingCentreAt(world.moving, 10 * 86400);
expect(tauAt(world, tau, centreLater.longitude, centreLater.latitude, 100, 10 * 86400)).toBeCloseTo(86400, 0);
});

it('pressure and sound speed behave at their anchors', () => {
expect(pressureDbar(0)).toBe(0);
expect(pressureDbar(1000)).toBeCloseTo(1007.5, 6);
// Mackenzie's own anchor: 0°C, 35 psu, surface.
expect(soundSpeedMs(0, 35, 0)).toBeCloseTo(1448.96, 2);
const mid = soundSpeedMs(10, 35, 100);
expect(mid).toBeGreaterThan(1480);
expect(mid).toBeLessThan(1500);
});
});
Loading
Loading