Skip to main content

Case

Struct Case 

Source
pub struct Case {
Show 18 fields pub schema_version: String, pub name: String, pub domain: Domain, pub grid: GridSpec, pub boundaries: Boundaries, pub flow: Flow, pub geometry: Vec<Block>, pub building_roughness_m: Option<f64>, pub geometry_min_passage_cells: Option<usize>, pub moving_walls: Vec<MovingWall>, pub constituents: Vec<Constituent>, pub vegetation: Vec<Vegetation>, pub sources: Vec<Source>, pub initial_conditions: Vec<Initial>, pub receptors: Vec<Receptor>, pub numerics: Numerics, pub run: Run, pub output: Output,
}
Expand description

A complete native case, schema version cfd-craft.case/0.1. Nothing outside the case configures the solver. Unknown fields are rejected; the lists default to empty when omitted. Deserialization checks only the types: the semantic checks (ranges, units, budgets, geometry) are those of cfd-craft check, which reports coded diagnostics with field paths.

Fields§

§schema_version: String

Contract version; must be cfd-craft.case/0.1 (CFD-E001).

§name: String

Nonempty experiment label (CFD-E002), copied into the result. It is excluded from the physics hash, so renaming keeps checkpoints compatible.

§domain: Domain

Physical extent of the domain; see Domain.

§grid: GridSpec

Uniform cell counts per axis; see GridSpec.

§boundaries: Boundaries

Boundary condition per axis; see Boundaries.

§flow: Flow

Flow model; see Flow.

§geometry: Vec<Block>

Axis-aligned solid boxes (buildings, obstacles). A cell is solid when its center lies inside a box. Not allowed with prescribed_uniform flow (CFD-E013). Optional footprint_m selects polygon prisms. Masked multigrid is supported. Default: empty.

§building_roughness_m: Option<f64>

Optional aerodynamic roughness of building walls in meters, independent of cell width. Omission reproduces the legacy wall recipe (CFD-E085).

§geometry_min_passage_cells: Option<usize>

Warn if a represented street between solids is narrower than this number of horizontal cells. Omitted for legacy cases (CFD-W011).

§moving_walls: Vec<MovingWall>

Tangentially moving wall faces of the domain, such as a cavity lid; laminar flow only (CFD-E021). Default: empty.

§constituents: Vec<Constituent>

Passive gases transported by the flow. Default: empty, which solves the flow only.

§vegetation: Vec<Vegetation>

Opt-in porous canopy boxes; zero leaf density has no numerical effect.

§sources: Vec<Source>

Continuous emissions into the constituents. Default: empty.

§initial_conditions: Vec<Initial>

Initial concentration fields, at most one per constituent (CFD-E018); a constituent without one starts at zero. Default: empty.

§receptors: Vec<Receptor>

Named concentration samples, reported for every constituent in the result’s receptors_kg_m3 and in probes.csv. Default: empty.

§numerics: Numerics

Discretization choices, tolerances and the steady monitor window; see Numerics.

§run: Run

Mode, endpoint and execution budgets; see Run.

§output: Output

Artifact retention and output budget; see Output.

Implementations§

Source§

impl Case

Source

pub fn physics_hash(&self) -> String

SHA-256 (lowercase hex) of the case’s compact JSON without name, run and output: the identity of the physical and numerical problem. A checkpoint restarts only a case with the same physics hash (CFD-E060), so budgets, the endpoint and the output policy may change between a run and its restart, while grid, physics, sources, receptors and numerics may not.

use cfd_craft::case::{Case, Source};

let case: Case = serde_json::from_str(json).unwrap();
let mut longer = case.clone();
longer.name = "tiny, longer budget".into();
longer.run.max_steps *= 10;
assert_eq!(case.physics_hash(), longer.physics_hash());

let mut weaker = case.clone();
if let Source::Point { rate_kg_s, .. } = &mut weaker.sources[0] {
    *rate_kg_s *= 0.5;
}
assert_ne!(case.physics_hash(), weaker.physics_hash());
Source

pub fn check(&self) -> CheckReport

The semantic checks that need no grid: schema version, ranges and units, budgets, physical combinations, IDs, and that geometry, sources, receptors and initial conditions lie inside the domain. It also estimates peak memory and output size and checks them against run.memory_limit_mib (CFD-E006) and output.max_total_mib (CFD-E007).

Every problem is reported at once; the report is invalid when any diagnostic is an error. It never fails or allocates the grid. The checks that need the built grid are in input::full_check, which the CLI and the Python binding run, and are repeated by solver::run.

use cfd_craft::case::Case;

let mut case: Case = serde_json::from_str(json).unwrap();
case.numerics.advective_cfl_max = 0.9;
case.run.threads = 0;
let report = case.check();
assert!(!report.valid);
let found: Vec<_> = report
    .diagnostics
    .iter()
    .map(|d| (d.code.as_str(), d.path.as_str()))
    .collect();
assert!(found.contains(&("CFD-E010", "numerics.advective_cfl_max")));
assert!(found.contains(&("CFD-E008", "run.threads")));
Source

pub fn validate(&self) -> Result<CheckReport>

check as a Result: the report when the case is valid (it may still carry warnings), otherwise an error whose text is the report serialized as JSON, so its codes and paths can be parsed back.

use cfd_craft::case::{Case, CheckReport};

let mut case: Case = serde_json::from_str(json).unwrap();
assert!(case.validate().is_ok());
case.schema_version = "cfd-craft.case/9".into();
let error = case.validate().unwrap_err();
let report: CheckReport = serde_json::from_str(&error).unwrap();
assert_eq!(report.diagnostics[0].code, "CFD-E001");
assert_eq!(report.diagnostics[0].path, "schema_version");

Trait Implementations§

Source§

impl Clone for Case

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Case

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Case

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for Case

Source§

fn schema_name() -> String

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn is_referenceable() -> bool

Whether JSON Schemas generated for this type should be re-used where possible using the $ref keyword. Read more
Source§

impl Serialize for Case

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Forget for Case

§

impl Freeze for Case

§

impl Move for Case

§

impl RefUnwindSafe for Case

§

impl Send for Case

§

impl Sync for Case

§

impl Unpin for Case

§

impl UnsafeUnpin for Case

§

impl UnwindSafe for Case

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.