pub const RULE_APPLICATION: &str = r#"
struct GpuCellData {
scalar: f32,
e1: f32,
e2: f32,
e3: f32,
e12: f32,
e13: f32,
e23: f32,
e123: f32,
generation: f32,
neighborhood_size: f32,
rule_type: f32,
boundary_condition: f32,
padding: array<f32, 4>,
}
struct GpuRuleConfig {
rule_type: f32,
threshold: f32,
damping_factor: f32,
energy_conservation: f32,
time_step: f32,
spatial_scale: f32,
geometric_weight: f32,
nonlinear_factor: f32,
boundary_type: f32,
neighborhood_radius: f32,
evolution_speed: f32,
stability_factor: f32,
padding: array<f32, 4>,
}
@group(0) @binding(0) var<storage, read> cells: array<GpuCellData>;
@group(0) @binding(1) var<storage, read> rules: array<GpuRuleConfig>;
@group(0) @binding(2) var<storage, read_write> output: array<GpuCellData>;
@compute @workgroup_size(256)
fn rule_application_main(@builtin(global_invocation_id) global_id: vec3<u32>) {
let idx = global_id.x;
if (idx >= arrayLength(&cells)) {
return;
}
let cell = cells[idx];
let rule = rules[0]; // Use first rule for now
var new_cell = cell;
// Apply damping factor
new_cell.scalar = cell.scalar * (1.0 - rule.damping_factor);
new_cell.e1 = cell.e1 * (1.0 - rule.damping_factor);
new_cell.e2 = cell.e2 * (1.0 - rule.damping_factor);
new_cell.e3 = cell.e3 * (1.0 - rule.damping_factor);
new_cell.e12 = cell.e12 * (1.0 - rule.damping_factor);
new_cell.e13 = cell.e13 * (1.0 - rule.damping_factor);
new_cell.e23 = cell.e23 * (1.0 - rule.damping_factor);
new_cell.e123 = cell.e123 * (1.0 - rule.damping_factor);
// Apply threshold
if (abs(new_cell.scalar) < rule.threshold) {
new_cell.scalar = 0.0;
}
output[idx] = new_cell;
}
"#;Expand description
Rule application for geometric algebra cellular automata