Repository navigation
Improve stellarator angular sampling with radius-dependent cell bounds - #4207
paulromano wants to merge 15 commits into
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Angular bounds and distributions include/openmc/source.h, src/source.cpp |
The sampler computes positive and negative density bounds for angular cells and uses the radial Bernstein controls to build cell-selection distributions. The previous scalar envelope setup is removed. |
Cell sampling and validation include/openmc/source.h, src/source.cpp, openmc/source.py, tests/unit_tests/test_source_stellarator.py |
At a sampled radius, the sampler selects a Bernstein component and angular cell, proposes angles within that cell, and checks density against the cell bound. It then selects a field period uniformly. The tests check tube containment and analytic sample moments across field-period counts and orientations. |
Source sampling documentation docs/source/methods/index.rst, docs/source/methods/source_sampling.rst |
The methods documentation now includes a source sampling page covering source types, distributions, sampling procedures, constraints, and biasing. |
Priority:
Estimated code review effort: 4 (Complex) | ~40 minutes
Change: Bug fix
Merge Risk: 
Minimal · up to 17765
-
No issue requiring a fix before merge was identified.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The description explains the motivation, implementation, performance results, memory impact, AI assistance, testing, documentation changes, and completed checklist items. No issue number is provided, but the template marks issue linkage as applicable only when relevant.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Description
The recently added
StellaratorSourcecurrently proposes both angles uniformly and rejects against one constant bound for each radial interval. A localized peak therefore increases rejection throughout the interval. The existing bound uses an angular-grid maximum with a 5% margin, which can miss peaks between grid points.This PR introduces an improved method for the angular sampling by partitioning one field period into 32x32 angular cells and constructing a radius-dependent bound for each cell. It samples cells in proportion to their bounds, proposes angles uniformly inside the selected cell, and accepts by rejection sampling. A runtime check detects invalid densities and encountered bound violations.
Additionally, I've put together a new "Source Sampling" section of our Theory and Methodology documentation which goes through the derivation of the radial and angular algorithms for StellaratorSource and also includes all of our other source classes.
Testing Results
I carried out some measurements using the W7-X, HSX, and NCSX examples bundled with DESC ($S(\rho)=(1-\rho^2)^2$ . Measurements used a single thread on an Intel Core Ultra 7 258V and sampling 500,000 source site via
desc.examples.get(name)), which have 288, 179, and 196 retained Fourier modes, respectively. Each uses the analytic benchmark emission profileopenmc_sample_external_source. Based on the results below, you can see that throughput improves by 17–26%, with 0.09–0.47 s of additional initialization in these runs.The additional memory requirements are approximately 72 KiB per radial interval: 2.25 MiB at 33 surfaces and 7.03 MiB at 101 surfaces, plus small bookkeeping overhead.
AI Assistance
Checklist
Summary by CodeRabbit