| Crates.io | neutron-diffusion-dd |
| lib.rs | neutron-diffusion-dd |
| version | 0.1.0 |
| created_at | 2025-12-11 04:11:35.524753+00 |
| updated_at | 2025-12-11 04:11:35.524753+00 |
| description | A high-performance neutron transport solver using the S_N (Discrete Ordinates) method with domain decomposition. Solves the 1D neutron diffusion equation with automatic or manual configuration. |
| homepage | https://github.com/yourusername/neutron-diffusion-dd |
| repository | https://github.com/yourusername/neutron-diffusion-dd |
| max_upload_size | |
| id | 1979118 |
| size | 86,524 |
A high-performance Rust library for solving one-dimensional neutron transport problems using the Discrete Ordinates (S_N) method with domain decomposition techniques.
This crate provides a robust solver for the linear Boltzmann equation in one spatial dimension, implementing the S_N discretization method with reflective boundary conditions. It's designed for nuclear physics simulations, reactor analysis, and neutron transport research.
Add this to your Cargo.toml:
[dependencies]
neutron-diffusion-dd = "0.1"
cargo run -- --input data/input.json --epsilon 1e-5 --max-iterations 2000
cargo run
The program will prompt you interactively for all configuration parameters.
use neutron_diffusion_dd::algorithm::{Config, Runner};
// Load configuration from JSON
let config = Config::new_auto(1e-5, 2000, "data/input.json")?;
// Create solver and run
let mut runner = Runner::new(config);
let result = runner.run();
// Access results
println!("Converged: {}", result.converged);
println!("Iterations: {}", result.iteration);
println!("Computation time: {:?}", result.elapsed);
Create a data/input.json file with the following structure:
{
"num_regions": 3,
"num_zones": 3,
"NC": [10, 15, 10],
"HR": [0.5, 0.5, 0.5],
"IZL": [1, 2, 3],
"SCT": [1.0, 1.5, 1.0],
"SCS": [0.8, 1.2, 0.8],
"Q": [1.0, 0.5, 0.3],
"N": 8,
"reflex_izq": 1,
"reflex_der": 0,
"bound_left": [0.1, 0.05, 0.02, 0.01],
"bound_right": [0.0, 0.0, 0.0, 0.0]
}
| Parameter | Type | Description |
|---|---|---|
num_regions |
usize | Number of spatial regions |
num_zones |
usize | Number of material zones |
NC |
Vec<usize> | Number of cells in each region |
HR |
Vec<f64> | Cell width (mesh spacing) in each region |
IZL |
Vec<usize> | Material zone index for each region (1-indexed) |
SCT |
Vec<f64> | Macroscopic total cross-section for each zone |
SCS |
Vec<f64> | Macroscopic scattering cross-section for each zone |
Q |
Vec<f64> | External neutron source in each region |
N |
usize | Number of ordinates (must be even; ≥ 2) |
reflex_izq |
i32 | 1 = reflective left boundary, 0 = vacuum |
reflex_der |
i32 | 1 = reflective right boundary, 0 = vacuum |
bound_left |
Vec<f64> | Incident flux at left boundary (N/2 values, only if reflex_izq=0) |
bound_right |
Vec<f64> | Incident flux at right boundary (N/2 values, only if reflex_der=0) |
The S_N method discretizes the angular variable using Gaussian quadrature. The solution vector is composed of angular fluxes ψ(x, μ) evaluated at N/2 quadrature points for positive and negative cosines.
Iteration stops when: $$\max_i \frac{|\phi_i^{n+1} - \phi_i^n|}{\max(|\phi_i^{n+1}|, 1.0)} < \epsilon$$
where ε is the convergence tolerance.
Results are saved to a timestamped output file (e.g., data_1765423402.out) containing the scalar neutron flux distribution across all spatial cells.
use neutron_diffusion_dd::algorithm::{Config, Runner};
fn main() {
let config = Config::new_auto(1e-5, 500, "data/input.json")
.expect("Failed to load configuration");
let mut runner = Runner::new(config);
let result = runner.run();
if result.converged {
println!("Solution converged in {} iterations", result.iteration);
println!("Final scalar flux range: {:.6} to {:.6}",
result.scalar_flux.min(),
result.scalar_flux.max());
} else {
println!("Warning: Maximum iterations reached");
}
}
Run the program without arguments:
cargo run
The program will guide you through entering:
Run the full test suite:
cargo test
Run tests with output:
cargo test -- --nocapture
The test suite includes:
Generate and view the API documentation:
cargo doc --open
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit issues or pull requests.
The implementation follows standard practices in neutron transport theory:
Carlos - Nuclear Physics & Scientific Computing