Matrix-free geometric multigrid for rectangular 2D diffusion-reaction problems
moon add jqlssg/moonmultigrid@0.1.0fn main raise {
let grid = @mg.Grid::new(32, 32)
let op = @mg.Operator::constant(grid)
let source = @mg.Field::sample(grid, fn(_x, _y) { 1.0 })
let boundary = @mg.Field::zeros(grid)
let problem = @mg.Problem::new(op, source, boundary)
let hierarchy = @mg.Hierarchy::new(op)
let report = hierarchy.pcg(problem)
assert_true(report.converged())
println(report.relative_residual())
}| User | Input and processing | Output / runnable integration |
|---|---|---|
| Thermal/diffusion simulation author | Positive conductivity field, source and arbitrary edge temperatures; FMG warm start then MG-PCG | Temperature field, true residual and oriented face fluxes; moon run cmd/heat --target js |
| Imaging developer | Source and destination rectangular channel patches; source or mixed forward gradients plus destination Dirichlet edges | Unclipped Poisson-edited patch, pasted into a new image field; moon run cmd/edit --target js |
| Numerical ecosystem author | Analytic/discrete manufactured equation; compare CG versus MG-PCG and export interior COO | Convergence history, discretization error, sparse/vector bridge; moon run cmd/compare --target js |
moon info
moon fmt --check
moon check --deny-warn
moon test --target wasm-gc --deny-warn
moon test --target wasm --deny-warn
moon test --target js --deny-warn
moon test --target native --deny-warn
moon build --target js --deny-warn
python scripts/differential.py --target js
python scripts/audit.pyfn CycleConfig::new(kind? : CycleKind, smoother? : Smoother, sweeps? : Int) -> CycleConfig raise SolverErrorfn Field::patch(self : Field, left : Int, bottom : Int, nx : Int, ny : Int) -> Field raise SolverErrorfn Hierarchy::cycle(self : Hierarchy, rhs : Field, initial : Field, config? : CycleConfig) -> Field raise SolverErrorfn Hierarchy::full_multigrid(self : Hierarchy, problem : Problem, cycles_per_level? : Int, config? : CycleConfig) -> Field raise SolverErrorfn Hierarchy::pcg(self : Hierarchy, problem : Problem, options? : SolveOptions, config? : CycleConfig, initial? : Field?, preconditioned? : Bool) -> SolveReport raise SolverErrorfn Hierarchy::precondition(self : Hierarchy, rhs : Field, config? : CycleConfig) -> Field raise SolverErrorfn Hierarchy::solve(self : Hierarchy, problem : Problem, options? : SolveOptions, config? : CycleConfig, initial? : Field?) -> SolveReport raise SolverErrorfn InteriorMatrix::multiply(self : InteriorMatrix, values : Array[Double]) -> Array[Double] raise SolverErrorfn Operator::constant(grid : Grid, conductivity? : Double, reaction? : Double) -> Operator raise SolverErrorfn Operator::interior_matrix(self : Operator, max_entries? : Int) -> InteriorMatrix raise SolverErrorfn Operator::stencil(self : Operator, i : Int, j : Int) -> (Double, Double, Double, Double, Double) raise SolverErrorpub struct SolveOptions {
rtol : Double
atol : Double
max_iterations : Int
work_budget : Int
}fn SolveOptions::new(rtol? : Double, atol? : Double, max_iterations? : Int, work_budget? : Int) -> SolveOptions raise SolverErrorpub struct SolveReport {
solution : Field
reason : StopReason
iterations : Int
work_units : Int
rhs_norm : Double
residuals : Array[Double]
}fn poisson_edit(source : Field, target : Field, mixed? : Bool, options? : SolveOptions) -> SolveReport raise SolverErrorfn refinement_order(coarse_error : Double, fine_error : Double, ratio? : Double) -> Double raise SolverErrorfn smooth_gauss_seidel(operator : Operator, rhs : Field, initial : Field, sweeps : Int, reverse? : Bool) -> Field raise SolverErrorfn smooth_jacobi(operator : Operator, rhs : Field, initial : Field, sweeps : Int, omega? : Double) -> Field raise SolverErrorfn smooth_symmetric(operator : Operator, rhs : Field, initial : Field, pairs : Int) -> Field raise SolverErrorfn solve(problem : Problem, options? : SolveOptions, config? : CycleConfig, initial? : Field?) -> SolveReport raise SolverErrorInstall
Download zipMatrix-free geometric multigrid for rectangular 2D diffusion-reaction problems