Skip to content
Draft
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
40 changes: 39 additions & 1 deletion packages/class/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const untypedSchema = {
title: "Mixed-layer switch",
default: true,
},
sw_dc: {
type: "boolean",
"ui:group": "Diurnal cycle",
title: "Diurnal cycle switch",
default: false,
},
sw_wind: {
type: "boolean",
"ui:group": "Wind",
Expand Down Expand Up @@ -263,6 +269,29 @@ const untypedSchema = {
],
},
},
{
if: {
properties: {
sw_dc: {
const: true,
},
},
},
// biome-ignore lint/suspicious/noThenProperty: <explanation>
then: {
properties: {
t_dc: {
symbol: "T<sub>diurnal</sub>",
type: "number",
unit: "h",
default: 13,
title: "Period of diurnal cycle",
"ui:group": "Diurnal cycle",
},
},
required: ["t_dc"],
},
},
{
if: {
properties: {
Expand Down Expand Up @@ -532,6 +561,14 @@ type NoMixedLayerConfig = {
sw_ml?: false;
};

export type DiurnalCycleConfig = {
sw_dc: true;
t_dc: number;
};
export type NoDiurnalCycleConfig = {
sw_dc?: false;
};

export type FireConfig = {
sw_fire: true;
L: number;
Expand All @@ -551,7 +588,8 @@ export type NoFireConfig = {
export type Config = GeneralConfig &
(MixedLayerConfig | NoMixedLayerConfig) &
(WindConfig | NoWindConfig) &
(FireConfig | NoFireConfig);
(FireConfig | NoFireConfig) &
(DiurnalCycleConfig | NoDiurnalCycleConfig);

export type JsonSchemaOfConfig = JSONSchemaType<Config>;
export const jsonSchemaOfConfig =
Expand Down
75 changes: 44 additions & 31 deletions packages/class/src/config_utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,87 @@
import assert from "node:assert";
import test, { describe } from "node:test";
import type { Config } from "./config.js";
import { pruneConfig } from "./config_utils.js";

describe("pruneConfig()", () => {
test("given 3 real configs", () => {
const preset = {
const preset: Config = {
name: "Default",
description: "Default configuration",
t0: "2025-09-08T14:30:00Z",
theta_0: 323,
h_0: 200,
dtheta_0: 1,
q_0: 0.008,
dq_0: -0.001,
theta: 323,
h: 200,
dtheta: 1,
qt: 0.008,
dqt: -0.001,
dt: 60,
runtime: 4320,
wtheta: 0.1,
wtheta: [0.1],
advtheta: 0,
gamma_theta: 0.006,
wq: 0.0001,
gamma_theta: [0.006],
wq: [0.0001],
advq: 0,
gamma_qt: 0,
gamma_qt: [0],
divU: 0,
beta: 0.2,
sw_ml: true,
p0: 101300,
z_theta: [5000],
z_qt: [5000],
};
const reference = {
const reference: Config = {
name: "Higher and Hotter",
description: "Higher h_0",
t0: "2025-09-08T14:30:00Z",
h_0: 211,
theta_0: 323,
dtheta_0: 1,
q_0: 0.008,
dq_0: -0.001,
h: 211,
theta: 323,
dtheta: 1,
qt: 0.008,
dqt: -0.001,
dt: 60,
runtime: 4320,
wtheta: 0.1,
wtheta: [0.1],
advtheta: 0,
gamma_theta: 0.006,
wq: 0.0001,
gamma_theta: [0.006],
wq: [0.0001],
advq: 0,
gamma_qt: 0,
gamma_qt: [0],
divU: 0,
beta: 0.2,
sw_ml: true,
p0: 101300,
z_theta: [5000],
z_qt: [5000],
};
const permutation = {
const permutation: Config = {
name: "Higher",
description: "",
t0: "2025-09-08T14:30:00Z",
h_0: 222,
theta_0: 323,
dtheta_0: 1,
q_0: 0.008,
dq_0: -0.001,
h: 222,
theta: 323,
dtheta: 1,
qt: 0.008,
dqt: -0.001,
dt: 60,
runtime: 4320,
wtheta: 0.1,
wtheta: [0.1],
advtheta: 0,
gamma_theta: 0.006,
wq: 0.0001,
gamma_theta: [0.006],
wq: [0.0001],
advq: 0,
gamma_qt: 0,
gamma_qt: [0],
divU: 0,
beta: 0.212,
sw_ml: true,
p0: 101300,
z_theta: [5000],
z_qt: [5000],
};
const result = pruneConfig(permutation, reference, preset);
const expected = {
name: "Higher",
description: "",
h_0: 222,
h: 222,
beta: 0.212,
};
assert.deepEqual(result, expected);
Expand Down
2 changes: 2 additions & 0 deletions packages/class/src/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ describe("parse", () => {
sw_ml: true,
sw_wind: false,
sw_fire: false,
sw_dc: false,
t_dc: 13,
};
assert.deepEqual(output, expected);
});
Expand Down