N-body gravitational simulation using Barnes-Hut quadtree approximation. Groups distant particles into tree nodes for O(n log n) force computation per step. Balances accuracy and speed via configurable opening angle theta.
| 日期 | 适应度 | 安全分 | 调用数 |
|---|---|---|---|
| 3月17日 | 1.0000 | 1.00 | 1 |
Barnes-Hut quadtree N-body gravitational simulation — a pure-computation Native Gene for the Rotifer Protocol.
Builds a quadtree each step to hierarchically group distant particles. When computing the force on particle i:
(size / distance) < θ, approximate all particles in that node as a single body at its center of massWith θ = 0.5 (the default opening angle), this achieves O(n log n) force evaluations per step while maintaining good accuracy — typically within 1-2% of the exact brute-force solution.
Integration uses the symplectic leapfrog (kick-drift-kick) scheme.
# Solar system preset (64 particles)
rotifer run particle-barneshut --input '{"preset": "solar"}'
# Large cluster (512 particles, 200 steps)
rotifer run particle-barneshut --input '{"preset": "cluster", "count": 512, "steps": 200}'
# Binary star system
rotifer run particle-barneshut --input '{"preset": "binary", "count": 100}'
| Preset | Description |
|---|---|
solar |
Central massive body + orbiting lighter bodies with circular velocities |
binary |
Two equal-mass stars in mutual orbit + debris ring |
cluster |
Random particles in a disk with small random velocities |
collision |
Two groups of particles approaching head-on |
particles — final positions and velocities of all particlessteps_computed — number of simulation steps executedtotal_energy — total system energy (kinetic + potential) for conservation validationinteractions_computed — total tree-node force evaluations (fewer than brute-force)| Metric | Expected |
|---|---|
| Success Rate | 1.0 (deterministic, no failure mode) |
| Accuracy | High (θ=0.5: ~1-2% error vs brute-force) |
| Complexity | O(n log n × steps) |
| Interactions | ~O(n log n) per step (varies with particle distribution) |
| Best For | Medium-to-large N (64-2048), best accuracy/cost tradeoff |
| Weakness | Tree construction overhead for very small N |
{
"type": "object",
"required": [],
"properties": {
"G": {
"type": "number",
"default": 1,
"description": "Gravitational constant"
},
"dt": {
"type": "number",
"default": 0.01,
"description": "Time step size"
},
"seed": {
"type": "number",
"description": "Random seed for preset generation (deterministic output)"
},
"count": {
"type": "number",
"default": 64,
"maximum": 2048,
"minimum": 2,
"description": "Number of particles for preset generation"
},
"steps": {
"type": "number",
"default": 100,
"maximum": 10000,
"minimum": 1,
"description": "Number of simulation steps"
},
"preset": {
"enum": [
"solar",
"binary",
"cluster",
"collision"
],
"type": "string",
"description": "Preset particle configuration"
},
"particles": {
"type": "array",
"items": {
"type": "object",
"required": [
"x",
"y",
"vx",
"vy",
"mass"
],
"properties": {
"x": {
"type": "number"
},
"y": {
"type": "number"
},
"vx": {
"type": "number"
},
"vy": {
"type": "number"
},
"mass": {
"type": "number"
}
}
},
"description": "Initial particle states. Ignored if preset is provided."
},
"softening": {
"type": "number",
"default": 0.01,
"description": "Softening parameter to prevent singularity at close range"
}
}
} {
"type": "object",
"required": [
"particles",
"steps_computed",
"total_energy",
"interactions_computed"
],
"properties": {
"particles": {
"type": "array",
"items": {
"type": "object",
"properties": {
"x": {
"type": "number"
},
"y": {
"type": "number"
},
"vx": {
"type": "number"
},
"vy": {
"type": "number"
},
"mass": {
"type": "number"
}
}
},
"description": "Final particle states after simulation"
},
"total_energy": {
"type": "number",
"description": "Total system energy (kinetic + potential) at final state"
},
"steps_computed": {
"type": "number",
"description": "Actual number of simulation steps computed"
},
"interactions_computed": {
"type": "number",
"description": "Total pairwise force evaluations across all steps"
}
}
}