Skip to main content

Module builder

Module builder 

Source
Expand description

Type-state simulation builder for spintronics simulations

This module provides a SimulationBuilder that uses the type-state pattern to enforce, at compile time, that all required configuration (material, external field, solver) is present before a Simulation can be built.

§Type-State Pattern

The builder carries three phantom type parameters <M, F, S> that track whether a material, an external field, and a solver have been configured. The .build() method is only available when all three parameters are in their “configured” state, so forgetting a required parameter is a compile-time error rather than a runtime one.

§Examples

use spintronics::prelude::*;
use spintronics::builder::SimulationBuilder;

let result = SimulationBuilder::new()
    .material(Ferromagnet::yig())
    .external_field(Vector3::new(0.0, 0.0, 0.1))
    .solver_rk4()
    .num_steps(100)
    .build();
assert!(result.is_ok());

§Compile-time safety

The following code would not compile because no material has been set:

use spintronics::prelude::*;
use spintronics::builder::SimulationBuilder;

// ERROR: `build()` is not available on SimulationBuilder<NoMaterial, ...>
let _ = SimulationBuilder::new()
    .external_field(Vector3::new(0.0, 0.0, 0.1))
    .solver_rk4()
    .build();

Modules§

states
Type-state markers for compile-time builder validation

Structs§

Simulation
A fully configured simulation ready to run.
SimulationBuilder
A type-state builder for constructing Simulation instances.
SimulationResult
Results from a completed simulation run.

Enums§

SolverKind
Which integration method to use for the LLG equation.